Port email/send
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 28 Feb 2010 17:12:14 +0000 (18:12 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 28 Feb 2010 17:12:14 +0000 (18:12 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/user.php
modules/email.php
templates/emails/send.tpl
upgrade/account/copy_tables.php

index 532b39e..7db7df4 100644 (file)
@@ -278,14 +278,6 @@ class User extends PlUser
         return $this->profile()->promo();
     }
 
-    public function yearpromo()
-    {
-        if (!$this->hasProfile()) {
-            return 0;
-        }
-        return $this->profile()->yearpromo();
-    }
-
     public function firstName()
     {
         if (!$this->hasProfile()) {
@@ -480,7 +472,7 @@ class User extends PlUser
 
     // Contacts
     private $contacts = null;
-    public function isContact(PlUser &$user)
+    private function fetchContacts()
     {
         if (is_null($this->contacts)) {
             $this->contacts = XDB::fetchAllAssoc('contact', 'SELECT  *
@@ -488,6 +480,23 @@ class User extends PlUser
                                                               WHERE  uid = {?}',
                                                  $this->id());
         }
+    }
+
+    public function iterContacts()
+    {
+        $this->fetchContacts();
+        return self::iterOverUIDs(array_keys($this->contacts));
+    }
+
+    public function getContacts()
+    {
+        $this->fetchContacts();
+        return self::getBulkUsersWithUIDs(array_keys($this->contacts));
+    }
+
+    public function isContact(PlUser &$user)
+    {
+        $this->fetchContacts();
         return isset($this->contacts[$user->id()]);
     }
 
index 057de8d..9a77979 100644 (file)
@@ -381,7 +381,8 @@ class EmailModule extends PLModule
                 $_POST['cc_contacts'] = explode(';', @$_POST['cc_contacts']);
                 $data = serialize($_POST);
                 XDB::execute("REPLACE INTO  email_send_save
-                                    VALUES  ({?}, {?})", S::i('uid'), $data);
+                                    VALUES  ({?}, {?})",
+                             S::user()->id('uid'), $data);
             }
             exit;
         } else if (Env::v('submit') == 'Envoyer') {
@@ -411,7 +412,8 @@ class EmailModule extends PLModule
 
             if (!$error) {
                 XDB::execute("DELETE FROM  email_send_save
-                                    WHERE  uid = {?}", S::i('uid'));
+                                    WHERE  uid = {?}",
+                             S::user()->id());
 
                 $to2  = getEmails(Env::v('to_contacts'));
                 $cc2  = getEmails(Env::v('cc_contacts'));
@@ -478,14 +480,8 @@ class EmailModule extends PLModule
             }
         }
 
-        $res = XDB::query(
-                "SELECT  ac.full_name, a.alias as forlife
-                   FROM  accounts      AS ac
-             INNER JOIN  contacts      AS c ON (ac.uid = c.contact)
-             INNER JOIN  aliases       AS a ON (ac.uid = a.uid AND FIND_IN_SET('bestalias', a.flags))
-                  WHERE  c.uid = {?}
-                 ORDER BY ac.full_name", S::i('uid'));
-        $page->assign('contacts', $res->fetchAllAssoc());
+        $contacts = S::user()->getContacts();
+        $page->assign('contacts', $contacts);
         $page->assign('maxsize', ini_get('upload_max_filesize') . 'o');
         $page->assign('user', S::user());
     }
index 3c5b88c..4e9b0d3 100644 (file)
         <div style="float: right; width: 40%;">
           <select id="to_contacts" name="to_contacts[]" multiple="multiple" style="width: 100%; height: 5em">
           {foreach key=key item=contact from=$contacts}
-          {if in_array($contact.forlife, $smarty.request.to_contacts)}
-          <option value="{$contact.forlife}">
-            {$contact.full_name}
+          {if in_array($contact->hruid,$smarty.request.to_contacts)}
+          <option value="{$contact->hruid}">
+            {$contact->full_name}
           </option>
           {/if}
           {/foreach}
           </select><br />
           <select id="cc_contacts" name="cc_contacts[]" multiple="multiple" style="width: 100%; height: 5em">
           {foreach key=key item=contact from=$contacts}
-          {if in_array($contact.forlife, $smarty.request.cc_contacts)}
-          <option value="{$contact.forlife}">
-            {$contact.full_name}
+          {if in_array($contact->forlife,$smarty.request.cc_contacts)}
+          <option value="{$contact->forlife}">
+            {$contact->full_name}
           </option>
           {/if}
           {/foreach}
         <div style="float: right; width: 40%">
           <select id="contacts" name="all_contacts[]" multiple="multiple" style="height: 10em; width: 100%">
             {foreach item=contact from=$contacts}
-            {if !in_array($contact.forlife, $smarty.request.to_contacts) && !in_array($contact.forlife, $smarty.request.cc_contacts)}
-            <option value="{$contact.forlife}">
-              {$contact.full_name}
+            {if !in_array($contact->hruid,$smarty.request.to_contacts) && !in_array($contact->hruid,$smarty.request.cc_contacts)}
+            <option value="{$contact->hruid}">
+              {$contact->full_name}
             </option>
             {/if}
             {/foreach}
           </select>
         </div>
         {foreach item=contact from=$contacts}
-        <input type="hidden" name="contacts[{$contact.forlife}]" value="{$contact.prenom} {$contact.nom} &lt;{$contact.forlife}@{#globals.mail.domain#}&gt;" />
+        <input type="hidden" name="contacts[{$contact->hruid}]" value="{$contact->display_name} &lt;{$contact->forlife}&gt;" />
         {/foreach}
       </td>
     </tr>
 {$smarty.request.contenu}
 {if !$smarty.request.contenu}
 -- 
-{$smarty.session.prenom} {$smarty.session.nom}
+{$smarty.session.user->full_name}
 {/if}</textarea>
     <script type="text/javascript">//<![CDATA[
       {literal}
index 1fd5fde..7ddd3f8 100755 (executable)
@@ -84,6 +84,7 @@ copyTable('#x4dat#.gapps_reporting', 'gapps_reporting');
 copyTable('#x4dat#.contacts', 'contacts');
 copyTable('#x4dat#.coupures', 'downtimes');
 copyTable('#x4dat#.emails_watch', 'email_watch');
+copyTable('#x4dat#.emails_send_save', 'email_send_save');
 copyTable('#x4dat#.homonymes', 'homonyms');
 copyTable('#x4dat#.ip_watch', 'ip_watch');
 copyTable('#x4dat#.mx_watch', 'mx_watch');