Welcome to the World of Tomorrow!
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 6 Jan 2009 22:05:39 +0000 (23:05 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 6 Jan 2009 22:05:39 +0000 (23:05 +0100)
Port profile edition form to be session independent. It uses a profile
object (and optionally a user object identifying the owner of the profile),
use SQL queries must be done using this profile object.

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
12 files changed:
core
include/emails.combobox.inc.php
modules/profile.php
modules/profile/addresses.inc.php
modules/profile/decos.inc.php
modules/profile/general.inc.php
modules/profile/groups.inc.php
modules/profile/jobs.inc.php
modules/profile/mentor.inc.php
modules/profile/page.inc.php
modules/profile/skills.inc.php
templates/profile/general.tpl

diff --git a/core b/core
index 179658e..66297a8 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 179658ec4de09ec088235d91977013f64eed49db
+Subproject commit 66297a8c8e4104f27ad2b3db4e35dc3cc77aa6db
index 31df31c..d575405 100644 (file)
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-function fill_email_combobox(PlPage& $page)
+function fill_email_combobox(PlPage& $page, $user = null, $profile = null)
 {
     global $globals;
 
-    $user = S::user();
+    if (is_null($user) && is_null($profile)) {
+        $user = S::user();
+        $profile = $user->profile();
+    }
     $email_type = "directory";
 
-    $res = XDB::query(
-            "SELECT  email_directory
-               FROM  profile_directory
-              WHERE  uid = {?}", $user->id());
-    $email_directory = $res->fetchOneCell();
-    if ($email_directory) {
-        $page->assign('email_directory', $email_directory);
-        list($alias, $domain) = explode('@', $email_directory);
-    } else {
-        $page->assign('email_directory', '');
-        $email_type = NULL;
-        $alias = $domain = '';
+    if ($profile) {
+        $res = XDB::query(
+                "SELECT  email_directory
+                   FROM  profile_directory
+                  WHERE  uid = {?}", $profile->id());
+        $email_directory = $res->fetchOneCell();
+        if ($email_directory) {
+            $page->assign('email_directory', $email_directory);
+            list($alias, $domain) = explode('@', $email_directory);
+        } else {
+            $page->assign('email_directory', '');
+            $email_type = NULL;
+            $alias = $domain = '';
+        }
     }
 
-    $res = XDB::query(
-            "SELECT  alias
-               FROM  virtual
-         INNER JOIN  virtual_redirect USING(vid)
-              WHERE  (redirect = {?} OR redirect = {?})
-                     AND alias LIKE '%@{$globals->mail->alias_dom}'",
-            $user->forlifeEmail(),
-            // TODO: remove this über-ugly hack. The issue is that you need
-            // to remove all @m4x.org addresses in virtual_redirect first.
-            $user->login() . '@' . $globals->mail->domain2);
-    $melix = $res->fetchOneCell();
-    if ($melix) {
-        list($melix) = explode('@', $melix);
-        $page->assign('melix', $melix);
-        if (($domain == $globals->mail->alias_dom) || ($domain == $globals->mail->alias_dom2)) {
-            $email_type = "melix";
+    if ($user) {
+        $melix = $user->emailAlias();
+        if ($melix) {
+            list($melix) = explode('@', $melix);
+            $page->assign('melix', $melix);
+            if (($domain == $globals->mail->alias_dom) || ($domain == $globals->mail->alias_dom2)) {
+                $email_type = "melix";
+            }
         }
-    }
 
-    $res = XDB::query(
-            "SELECT  alias
-               FROM  aliases
-              WHERE  id={?} AND (type='a_vie' OR type='alias')", $user->id());
-    $res = $res->fetchAllAssoc();
-    $page->assign('list_email_X', $res);
-    if (($domain == $globals->mail->domain) || ($domain == $globals->mail->domain2)) {
-        foreach ($res as $res_it) {
-            if ($alias == $res_it['alias']) {
-                $email_type = "X";
+        $res = XDB::query(
+                "SELECT  alias
+                   FROM  aliases
+                  WHERE  id={?} AND (type='a_vie' OR type='alias')", $user->id());
+        $res = $res->fetchAllAssoc();
+        $page->assign('list_email_X', $res);
+        if (($domain == $globals->mail->domain) || ($domain == $globals->mail->domain2)) {
+            foreach ($res as $res_it) {
+                if ($alias == $res_it['alias']) {
+                    $email_type = "X";
+                }
             }
         }
-    }
 
-    require_once 'emails.inc.php';
-    $redirect = new Redirect($user);
-    $redir    = array();
-    foreach ($redirect->emails as $redirect_it) {
-        if ($redirect_it instanceof EmailRedirection) {
-            $redir[] = $redirect_it->email;
-            if ($email_directory == $redirect_it->email) {
-                $email_type = "redir";
+        require_once 'emails.inc.php';
+        $redirect = new Redirect($user);
+        $redir    = array();
+        foreach ($redirect->emails as $redirect_it) {
+            if ($redirect_it instanceof EmailRedirection) {
+                $redir[] = $redirect_it->email;
+                if ($email_directory == $redirect_it->email) {
+                    $email_type = "redir";
+                }
             }
         }
-    }
-    $page->assign('list_email_redir', $redir);
+        $page->assign('list_email_redir', $redir);
 
-    $res = XDB::query(
-            "SELECT  email
-               FROM  profile_job
-              WHERE  uid = {?}", $user->id());
-    $res = $res->fetchAllAssoc();
-    $pro = array();
-    foreach ($res as $res_it) {
-        if ($res_it['email'] != '') {
-            $pro[] = $res_it['email'];
-            if ($email_directory == $res_it['email']) {
-                $email_type = "pro";
+        $res = XDB::query(
+                "SELECT  email
+                   FROM  profile_job
+                  WHERE  uid = {?}", $user->id());
+        $res = $res->fetchAllAssoc();
+        $pro = array();
+        foreach ($res as $res_it) {
+            if ($res_it['email'] != '') {
+                $pro[] = $res_it['email'];
+                if ($email_directory == $res_it['email']) {
+                    $email_type = "pro";
+                }
             }
         }
-    }
-    $page->assign('list_email_pro', $pro);
+        $page->assign('list_email_pro', $pro);
+        $page->assign('email_type', $email_type);
 
-    $page->assign('email_type', $email_type);
+    } else {
+        $page->assign('list_email_X', array());
+        $page->assign('list_email_redir', array());
+        $page->assign('list_email_pro', array());
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
index 7c27046..b4c4590 100644 (file)
@@ -367,7 +367,9 @@ class ProfileModule extends PLModule
         $page->addJsLink('grades.js');
         $page->addJsLink('profile.js');
         $page->addJsLink('jquery.autocomplete.js');
-        $wiz = new PlWizard('Profil', PlPage::getCoreTpl('plwizard.tpl'), true, true);
+        $wiz = new PlWizard('Profil', PlPage::getCoreTpl('plwizard.tpl'), true, true, false);
+        $wiz->addUserData('profile', $user);
+        $wiz->addUserData('owner', $user->owner());
         $this->load('page.inc.php');
         $wiz->addPage('ProfileGeneral', 'Général', 'general');
         $wiz->addPage('ProfileAddresses', 'Adresses personnelles', 'adresses');
index 7317c5d..d1bf103 100644 (file)
@@ -95,34 +95,14 @@ class ProfileAddress extends ProfileGeoloc
         return $value;
     }
 
-    private function saveTel($adrid, $telid, array &$tel)
-    {
-        XDB::execute("INSERT INTO  profile_phones (uid, link_type, link_id, tel_id, tel_type,
-                                              search_tel, display_tel, pub)
-                           VALUES  ({?}, 'address', {?}, {?}, {?},
-                                    {?}, {?}, {?})",
-                    S::i('uid'), $adrid, $telid, $tel['type'],
-                    format_phone_number($tel['tel']), $tel['tel'], $tel['pub']);
-    }
-
-    private function saveAddress($adrid, array &$address)
+    private function saveAddress($pid, $adrid, array &$address)
     {
         $flags = new PlFlagSet();
-        if ($address['secondaire']) {
-            $flags->addFlag('res-secondaire');
-        }
-        if ($address['mail']) {
-            $flags->addFlag('courrier');
-        }
-        if ($address['temporary']) {
-            $flags->addFlag('temporaire');
-        }
-        if ($address['current']) {
-            $flags->addFlag('active');
-        }
-        if ($address['checked']) {
-            $flags->addFlag('coord-checked');
-        }
+        $flags->addFlag('res-secondaire', $address['secondaire']);
+        $flags->addFlag('courrier', $address['mail']);
+        $flags->addFlag('temporaire', $address['temporary']);
+        $flags->addFlag('active', $address['current']);
+        $flags->addFlag('coord-checked', $address['checked']);
         XDB::execute("INSERT INTO  adresses (adr1, adr2, adr3,
                                               postcode, city, cityid,
                                               country, region, regiontxt,
@@ -137,21 +117,21 @@ class ProfileAddress extends ProfileGeoloc
                      $address['postcode'], $address['city'], $address['cityid'],
                      $address['country'], $address['region'], $address['regiontxt'],
                      $address['pub'], $address['datemaj'], $flags,
-                     S::i('uid'), $adrid, $address['precise_lat'], $address['precise_lon'], $address['comment']);
+                     $pid, $adrid, $address['precise_lat'], $address['precise_lon'], $address['comment']);
     }
 
     public function save(ProfilePage &$page, $field, $value)
     {
         XDB::execute("DELETE FROM  adresses
                             WHERE  uid = {?}",
-                     S::i('uid'));
+                     $page->pid());
         XDB::execute("DELETE FROM  profile_phones
                             WHERE  uid = {?} AND link_type = 'address'",
-                     S::i('uid'));
+                     $page->pid());
         foreach ($value as $adrid=>&$address) {
-            $this->saveAddress($adrid, $address);
+            $this->saveAddress($page->pid(), $adrid, $address);
             $profiletel = new ProfilePhones('address', $adrid);
-            $profiletel->saveTels('tel', $address['tel']);
+            $profiletel->saveTels($page->pid(), 'tel', $address['tel']);
         }
     }
 }
@@ -185,7 +165,7 @@ class ProfileAddresses extends ProfilePage
                        INNER JOIN  geoloc_pays AS gp ON(gp.a2 = a.country)
                             WHERE  uid = {?} AND NOT FIND_IN_SET('pro', statut)
                          ORDER BY  adrid",
-                           S::i('uid'));
+                           $this->pid());
         if ($res->numRows() == 0) {
             $this->values['addresses'] = array();
         } else {
@@ -196,7 +176,7 @@ class ProfileAddresses extends ProfilePage
                                 FROM  profile_phones
                                WHERE  uid = {?} AND link_type = 'address'
                             ORDER BY  link_id",
-                             S::i('uid'));
+                             $this->pid());
         $i = 0;
         $adrNb = count($this->values['addresses']);
         while ($tel = $res->next()) {
index 4a6bd69..418ad69 100644 (file)
@@ -30,7 +30,7 @@ class ProfileDeco implements ProfileSetting
                                    FROM  profile_medals_sub    AS s
                              INNER JOIN  profile_medals        AS m ON ( s.mid = m.id )
                                   WHERE  s.uid = {?}",
-                                S::i('uid'));
+                                $page->pid());
             $value = array();
             while (list($id, $grade) = $res->next()) {
                 $value[$id] = array('grade' => $grade,
@@ -63,7 +63,7 @@ class ProfileDeco implements ProfileSetting
                 if ($val['valid']) {
                     XDB::execute("DELETE FROM  profile_medals_sub
                                         WHERE  uid = {?} AND mid = {?}",
-                                 S::i('uid'), $id);
+                                 $page->pid(), $id);
                 } else {
                     $req = MedalReq::get_request(S::i('uid'), $id);
                     if ($req) {
@@ -98,20 +98,20 @@ class ProfileDecos extends ProfilePage
 
     protected function _fetchData()
     {
-        $res = XDB::query("SELECT  profile_medals_pub
-                             FROM  auth_user_quick
-                            WHERE  user_id = {?}",
-                          S::i('uid'));
+        $res = XDB::query("SELECT  medals_pub
+                             FROM  profiles
+                            WHERE  pid = {?}",
+                          $this->pid());
         $this->values['medals_pub'] = $res->fetchOneCell();
     }
 
     protected function _saveData()
     {
         if ($this->changed['medals_pub']) {
-            XDB::execute("UPDATE  auth_user_quick
-                             SET  profile_medals_pub = {?}
-                           WHERE  user_id = {?}",
-                         $this->values['medals_pub'], S::i('uid'));
+            XDB::execute("UPDATE  profiles
+                             SET  medals_pub = {?}
+                           WHERE  pid = {?}",
+                         $this->values['medals_pub'], $this->pid());
         }
     }
 
index 945c54f..2b49451 100644 (file)
@@ -21,7 +21,8 @@
 
 class ProfileNom implements ProfileSetting
 {
-    private function matchWord($old, $new, $newLen) {
+    private function matchWord($old, $new, $newLen)
+    {
         return ($i = strpos($old, $new)) !== false
             && ($i == 0 || $old{$i-1} == ' ')
             && ($i + $newLen == strlen($old) || $old{$i + $newLen} == ' ');
@@ -82,7 +83,8 @@ class ProfileSearchName implements ProfileSetting
 
 class ProfileEdu implements ProfileSetting
 {
-    public function __construct(){}
+    public function __construct() {
+    }
 
     static function sortByGradYear($line1, $line2) {
         $a = (int) $line1['grad_year'];
@@ -102,7 +104,7 @@ class ProfileEdu implements ProfileSetting
                                     FROM  profile_education
                                    WHERE  uid = {?} AND !FIND_IN_SET('primary', flags)
                                 ORDER BY  id",
-                                 S::v('uid'));
+                                 $page->pid());
             while($edu = $res->next()) {
                 $value[] = $edu;
             }
@@ -129,13 +131,13 @@ class ProfileEdu implements ProfileSetting
     {
         XDB::execute("DELETE FROM  profile_education
                             WHERE  uid = {?} AND !FIND_IN_SET('primary', flags)",
-                     S::i('uid'));
+                     $page->pid());
         foreach ($value as $eduid=>&$edu) {
             if ($edu['eduid'] != '') {
                 XDB::execute("INSERT INTO  profile_education
                                       SET  id = {?}, uid = {?}, eduid = {?}, degreeid = {?},
                                            fieldid = {?}, grad_year = {?}, program = {?}",
-                             $eduid, S::i('uid'), $edu['eduid'], $edu['degreeid'],
+                             $eduid, $page->pid(), $edu['eduid'], $edu['degreeid'],
                              $edu['fieldid'], $edu['grad_year'], $edu['program']);
             }
         }
@@ -190,7 +192,7 @@ class ProfileNetworking implements ProfileSetting
                                     FROM  profile_networking AS n
                               INNER JOIN  profile_networking_enum AS m ON (n.network_type = m.network_type)
                                    WHERE  n.uid = {?}",
-                                 S::i('uid'));
+                                 $page->pid());
             while($network = $res->next()) {
                 $value[] = $network;
             }
@@ -235,7 +237,7 @@ class ProfileNetworking implements ProfileSetting
     {
         XDB::execute("DELETE FROM profile_networking
                             WHERE uid = {?}",
-                     S::i('uid'));
+                     $page->pid());
         if (!count($value)) {
             return;
         }
@@ -243,7 +245,7 @@ class ProfileNetworking implements ProfileSetting
         foreach ($value as $id=>$network) {
             XDB::execute("INSERT INTO  profile_networking (uid, nwid, network_type, address, pub)
                                VALUES  ({?}, {?}, {?}, {?}, {?})",
-                         S::i('uid'), $id, $network['type'], $network['address'], $network['pub']);
+                         $page->pid(), $id, $network['type'], $network['address'], $network['pub']);
         }
     }
 }
@@ -257,14 +259,14 @@ class ProfileGeneral extends ProfilePage
         parent::__construct($wiz);
         $this->settings['nom']    = $this->settings['prenom']
                                   = new ProfileNom();
-        $this->settings['naissance'] = new ProfileDate();
+        $this->settings['birthdate'] = new ProfileDate();
         $this->settings['freetext_pub']
                                   = $this->settings['photo_pub']
                                   = new ProfilePub();
         $this->settings['freetext']
-                                  = $this->settings['nationalite']
-                                  = $this->settings['nationalite2']
-                                  = $this->settings['nationalite3']
+                                  = $this->settings['nationality1']
+                                  = $this->settings['nationality2']
+                                  = $this->settings['nationality3']
                                   = $this->settings['nick']
                                   = $this->settings['yourself']
                                   = $this->settings['display_name']
@@ -283,42 +285,44 @@ class ProfileGeneral extends ProfilePage
         $this->settings['edus']   = new ProfileEdu();
         $this->watched= array('nom' => true, 'freetext' => true, 'tels' => true,
                               'networking' => true, 'edus' => true,
-                              'nationalite' => true, 'nationalite2' => true,
-                              'nationalite3' => true, 'nick' => true);
+                              'nationality1' => true, 'nationality2' => true,
+                              'nationality3' => true, 'nick' => true);
     }
 
     protected function _fetchData()
     {
         // Checkout all data...
         $res = XDB::query("SELECT  p.promo AS promo_display, e.entry_year AS entry_year, e.grad_year AS grad_year,
-                                   u.nom_usage, u.nationalite, u.nationalite2, u.nationalite3, u.naissance,
+                                   pr.nationality1, pr.nationality2, pr.nationality3, pr.birthdate,
                                    t.display_tel as mobile, t.pub as mobile_pub,
                                    d.email_directory as email_directory,
-                                   q.profile_freetext as freetext, q.profile_freetext_pub as freetext_pub,
-                                   q.profile_nick as nick, q.profile_from_ax as synchro_ax, u.matricule_ax,
+                                   pr.freetext, pr.freetext_pub as freetext_pub,
                                    n.yourself, n.display AS display_name, n.sort AS sort_name,
                                    n.tooltip AS tooltip_name
-                             FROM  auth_user_md5         AS u
-                       INNER JOIN  auth_user_quick       AS q ON (u.user_id = q.user_id)
-                       INNER JOIN  profile_names_display AS n ON (n.user_id = u.user_id)
-                       INNER JOIN  profile_display       AS p ON (p.pid = u.user_id)
-                       INNER JOIN  profile_education     AS e ON (e.uid = u.user_id AND FIND_IN_SET('primary', e.flags))
-                        LEFT JOIN  profile_phones        AS t ON (u.user_id = t.uid AND link_type = 'user')
-                        LEFT JOIN  profile_directory     AS d ON (d.uid = u.user_id)
-                            WHERE  u.user_id = {?}", S::v('uid', -1));
+                             FROM  profiles              AS pr
+                       INNER JOIN  profile_names_display AS n ON (n.user_id = pr.pid)
+                       INNER JOIN  profile_display       AS p ON (p.pid = pr.pid)
+                       INNER JOIN  profile_education     AS e ON (e.uid = pr.pid AND FIND_IN_SET('primary', e.flags))
+                        LEFT JOIN  profile_phones        AS t ON (t.uid = pr.pid AND link_type = 'user')
+                        LEFT JOIN  profile_directory     AS d ON (d.uid = pr.pid)
+                            WHERE  pr.pid = {?}", $this->pid());
         $this->values = $res->fetchOneAssoc();
 
         // Retreive photo informations
         $res = XDB::query("SELECT  pub
                              FROM  photo
-                            WHERE  uid = {?}", S::v('uid'));
+                            WHERE  uid = {?}", $this->pid());
         $this->values['photo_pub'] = $res->fetchOneCell();
 
-        $res = XDB::query("SELECT  COUNT(*)
-                             FROM  requests
-                            WHERE  type='photo' AND user_id = {?}",
-                          S::v('uid'));
-        $this->values['nouvellephoto'] = $res->fetchOneCell();
+        if ($this->owner) {
+            $res = XDB::query("SELECT  COUNT(*)
+                                 FROM  requests
+                                WHERE  type='photo' AND user_id = {?}",
+                              $this->owner->id());
+            $this->values['nouvellephoto'] = $res->fetchOneCell();
+        } else {
+            $this->values['nouvellephoto'] = 0;
+        }
 
         // Retreive search names info
         $this->values['search_names'] = XDB::iterator("
@@ -326,7 +330,7 @@ class ProfileGeneral extends ProfilePage
                                 FROM  profile_names_search AS sn
                                WHERE  sn.user_id = {?}
                             ORDER BY  sn.name_type, search_score, search_name",
-                          S::v('uid'));
+                          $this->pid());
 
         // Proposes choice for promo_display
         if ($this->values['entry_year'] != $this->values['grad_year'] - 3) {
@@ -338,38 +342,30 @@ class ProfileGeneral extends ProfilePage
 
     protected function _saveData()
     {
-        if ($this->changed['nationalite'] || $this->changed['nationalite2'] || $this->changed['nationalite3']
-            || $this->changed['nom'] || $this->changed['prenom'] || $this->changed['naissance']) {
-            if ($this->values['nationalite3'] == "") {
-                $this->values['nationalite3'] = NULL;
+        if ($this->changed['nationality1'] || $this->changed['nationality2'] || $this->changed['nationality3']
+            || $this->changed['nom'] || $this->changed['prenom'] || $this->changed['naissance']
+            || $this->changed['freetext'] || $this->changed['freetext_pub']) {
+            if ($this->values['nationality3'] == "") {
+                $this->values['nationality3'] = NULL;
             }
-            if ($this->values['nationalite2'] == "") {
-                $this->values['nationalite2'] = $this->values['nationalite3'];
-                $this->values['nationalite3'] = NULL;
+            if ($this->values['nationality2'] == "") {
+                $this->values['nationality2'] = $this->values['nationality3'];
+                $this->values['nationality3'] = NULL;
             }
-            if ($this->values['nationalite'] == "") {
-                $this->values['nationalite']  = $this->values['nationalite2'];
-                $this->values['nationalite2'] = $this->values['nationalite3'];
-                $this->values['nationalite3'] = NULL;
+            if ($this->values['nationality1'] == "") {
+                $this->values['nationality1']  = $this->values['nationality2'];
+                $this->values['nationality2'] = $this->values['nationality3'];
+                $this->values['nationality3'] = NULL;
             }
 
-            XDB::execute("UPDATE  auth_user_md5
-                             SET  nationalite = {?}, nationalite2 = {?}, nationalite3 = {?}, nom={?}, prenom={?}, naissance={?}
+            XDB::execute("UPDATE  profiles
+                             SET  nationality1 = {?}, nationality2 = {?}, nationality3 = {?}, birthdate = {?},
+                                  freetext = {?}, freetext_pub = {?}
                            WHERE  user_id = {?}",
-                          $this->values['nationalite'], $this->values['nationalite2'], $this->values['nationalite3'],
-                          $this->values['nom'], $this->values['prenom'],
-                          preg_replace('@(\d{2})/(\d{2})/(\d{4})@', '\3-\2-\1', $this->values['naissance']),
-                          S::v('uid'));
-        }
-        if ($this->changed['nick'] || $this->changed['freetext'] || $this->changed['freetext_pub'] || $this->changed['synchro_ax']) {
-            XDB::execute("UPDATE  auth_user_quick
-                             SET  profile_nick= {?},
-                                  profile_freetext={?},
-                                  profile_freetext_pub={?}, profile_from_ax = {?} 
-                           WHERE  user_id = {?}", 
-                         $this->values['nick'],
-                         $this->values['freetext'], $this->values['freetext_pub'],
-                         $this->values['synchro_ax'], S::v('uid'));
+                          $this->values['nationality1'], $this->values['nationality2'], $this->values['nationality3'],
+                          preg_replace('@(\d{2})/(\d{2})/(\d{4})@', '\3-\2-\1', $this->values['birthdate']),
+                          $this->values['freetext'], $this->values['freetext_pub'],
+                          $this->pid());
         }
         if ($this->changed['email_directory']) {
             $new_email = ($this->values['email_directory'] == "new@example.org") ?
@@ -379,7 +375,7 @@ class ProfileGeneral extends ProfilePage
             }
             XDB::execute("REPLACE INTO  profile_directory (uid, email_directory)
                                 VALUES  ({?}, {?})",
-                         S::v('uid'), $new_email);
+                         $this->pid(), $new_email);
         }
         if ($this->changed['nick']) {
             require_once('user.func.inc.php');
@@ -389,7 +385,7 @@ class ProfileGeneral extends ProfilePage
             XDB::execute("UPDATE  photo
                              SET  pub = {?}
                            WHERE  uid = {?}",
-                         $this->values['photo_pub'], S::v('uid'));
+                         $this->values['photo_pub'], $this->pid());
         }
         if ($this->changed['yourself'] || $this->changed['sort_name'] ||
             $this-> changed['display_name'] || $this->changed['tooltip_name']) {
@@ -403,13 +399,13 @@ class ProfileGeneral extends ProfilePage
                          $this->values['sort_name'],
                          $this->values['display_name'],
                          $this->values['tooltip_name'],
-                         S::v('uid'));
+                         $this->pid());
         }
         if ($this->changed['promo_display']) {
             XDB::execute("UPDATE  profile_display
                              SET  promo = {?}
                            WHERE  pid = {?}",
-                         $this->values['promo_display'], S::v('uid'));
+                         $this->values['promo_display'], $this->pid());
         }
     }
 
@@ -423,7 +419,7 @@ class ProfileGeneral extends ProfilePage
         $page->assign('edu_fields', $res->fetchAllAssoc());
 
         require_once "emails.combobox.inc.php";
-        fill_email_combobox($page);
+        fill_email_combobox($page, $this->owner, $this->profile);
 
         $res = XDB::iterator("SELECT  nw.network_type AS type, nw.name
                                 FROM  profile_networking_enum AS nw
index cd2c447..0018f0b 100644 (file)
@@ -26,9 +26,9 @@ class ProfileSection implements ProfileSetting
         $success = true;
         if (is_null($value)) {
             $res = XDB::query("SELECT  section
-                                 FROM  auth_user_md5
-                                WHERE  user_id = {?}",
-                              S::i('uid'));
+                                 FROM  profiles
+                                WHERE  pid = {?}",
+                              $page->pid());
             return intval($res->fetchOneCell());
         }
         return intval($value);
@@ -36,10 +36,10 @@ class ProfileSection implements ProfileSetting
 
     public function save(ProfilePage &$page, $field, $value)
     {
-        XDB::execute("UPDATE  auth_user_md5
+        XDB::execute("UPDATE  profiles
                          SET  section = {?}
-                       WHERE  user_id = {?}",
-                     $value, S::i('uid'));
+                       WHERE  pid = {?}",
+                     $value, $page->pid());
     }
 }
 
@@ -64,7 +64,7 @@ class ProfileGroup implements ProfileSetting
                                    FROM  {$this->table}_def AS g
                              INNER JOIN  {$this->table}_ins AS i ON (i.{$this->group_field} = g.id)
                                   WHERE  i.{$this->user_field} = {?}",
-                                S::i('uid'));
+                                $page->pid());
             while (list($gid, $text) = $res->next()) {
                 $value[intval($gid)] = $text;
             }
@@ -81,13 +81,13 @@ class ProfileGroup implements ProfileSetting
     {
         XDB::execute("DELETE FROM  {$this->table}_ins
                             WHERE  {$this->user_field} = {?}",
-                     S::i('uid'));
+                     $page->pid());
         if (!count($value)) {
             return;
         }
         $insert = array();
         foreach ($value as $id=>$text) {
-            $insert[] = '(' . S::i('uid') . ", $id)";
+            $insert[] = XDB::format('({?}, {?})', $page->pid(), $id);
         }
         XDB::execute("INSERT INTO  {$this->table}_ins ({$this->user_field}, {$this->group_field})
                            VALUES  " . implode(',', $insert));
@@ -112,7 +112,7 @@ class ProfileGroups extends ProfilePage
                                                    FROM  groupex.asso    AS a
                                              INNER JOIN  groupex.membres AS m ON (m.asso_id = a.id)
                                                   WHERE  m.uid = {?} AND (a.cat = 'GroupesX' OR a.cat = 'Institutions')",
-                                                  S::i('uid')));
+                                                $this->pid()));
         $page->assign('listgroups', XDB::iterator("SELECT  a.nom, a.diminutif, a.sub_url,
                                                            IF (a.cat = 'Institutions', a.cat, d.nom) AS dom
                                                      FROM  groupex.asso  AS a
@@ -120,6 +120,7 @@ class ProfileGroups extends ProfilePage
                                                     WHERE  a.inscriptible != 0
                                                            AND (a.cat = 'GroupesX' OR a.cat = 'Institutions')
                                                  ORDER BY  a.cat, a.dom, a.nom"));
+        # XXX: FIXME: promo_sortie
         $page->assign('old', (int)date('Y') >= S::i('promo_sortie'));
     }
 }
index e392d46..79306f9 100644 (file)
@@ -193,9 +193,9 @@ class ProfileJobs extends ProfilePage
     {
         // Checkout the CV
         $res = XDB::query("SELECT  cv
-                             FROM  auth_user_md5
-                            WHERE  user_id = {?}",
-                          S::i('uid'));
+                             FROM  profiles
+                            WHERE  pid = {?}",
+                          $this->pid());
         $this->values['cv'] = $res->fetchOneCell();
 
         // Checkout the corps
@@ -203,7 +203,7 @@ class ProfileJobs extends ProfilePage
                                    rankid AS rank, corps_pub AS pub
                              FROM  profile_corps
                             WHERE  uid = {?}",
-                          S::i('uid'));
+                        $this->pid());
         $this->values['corps'] = $res->fetchOneAssoc();
 
         // Build the jobs tree
@@ -221,7 +221,7 @@ class ProfileJobs extends ProfilePage
                           LEFT JOIN  geoloc_pays                   AS gp ON (gp.a2 = e.country)
                           LEFT JOIN  profile_job_subsubsector_enum AS s  ON (s.id = j.subsubsectorid)
                               WHERE  j.uid = {?}
-                           ORDER BY  entrid", S::i('uid'));
+                           ORDER BY  entrid", $this->pid());
         $this->values['jobs'] = array();
         while (list($id, $name, $function, $secteur, $ss_secteur, $sss_secteur, $description,
                     $w_adr1, $w_adr2, $w_adr3, $w_postcode, $w_city, $w_cityid,
@@ -262,7 +262,7 @@ class ProfileJobs extends ProfilePage
                                 FROM  profile_phones
                                WHERE  uid = {?} AND link_type = 'pro'
                             ORDER BY  link_id",
-                             S::i('uid'));
+                             $this->pid());
         $i = 0;
         $jobNb = count($this->values['jobs']);
         while ($tel = $res->next()) {
@@ -293,10 +293,10 @@ class ProfileJobs extends ProfilePage
     protected function _saveData()
     {
         if ($this->changed['cv']) {
-            XDB::execute("UPDATE  auth_user_md5
+            XDB::execute("UPDATE  profiles
                              SET  cv = {?}
-                           WHERE  user_id = {?}",
-                         $this->values['cv'], S::i('uid'));
+                           WHERE  pid = {?}",
+                         $this->values['cv'], $this->pid());
         }
 
         if ($this->changed['corps']) {
@@ -305,14 +305,14 @@ class ProfileJobs extends ProfilePage
                                   rankid = {?}, corps_pub = {?}
                            WHERE  uid = {?}",
                           $this->values['corps']['original'], $this->values['corps']['current'],
-                          $this->values['corps']['rank'], $this->values['corps']['pub'], S::i('uid'));
+                          $this->values['corps']['rank'], $this->values['corps']['pub'], $this->pid());
         }
     }
 
     public function _prepare(PlPage &$page, $id)
     {
         require_once "emails.combobox.inc.php";
-        fill_email_combobox($page);
+        fill_email_combobox($page, $this->owner, $this->profile);
 
         $res = XDB::query("SELECT  id, name AS label
                              FROM  profile_job_sector_enum");
index d8579e4..7fae8ec 100644 (file)
@@ -31,7 +31,7 @@ class ProfileSecteurs implements ProfileSetting
                              INNER JOIN  profile_job_sector_enum    AS s  ON (m.sectorid = s.id)
                              INNER JOIN  profile_job_subsector_enum AS ss ON (s.id = ss.sectorid AND m.subsectorid = ss.id)
                                   WHERE  m.uid = {?}",
-                                S::i('uid'));
+                                $page->pid());
             while (list($s, $ss, $ssname) = $res->next()) {
                 if (!isset($value[$s])) {
                     $value[$s] = array($ss => $ssname);
@@ -57,7 +57,7 @@ class ProfileSecteurs implements ProfileSetting
 
         XDB::execute("DELETE FROM  profile_mentor_sector
                             WHERE  uid = {?}",
-                     S::i('uid'));
+                     $page->pid());
         if (!count($value)) {
             return;
         }
@@ -65,7 +65,7 @@ class ProfileSecteurs implements ProfileSetting
             foreach ($sect as $sid=>&$name) {
                 XDB::execute("INSERT INTO  profile_mentor_sector (uid, sectorid, subsectorid)
                                    VALUES  ({?}, {?}, {?})",
-                             S::i('uid'), $id, $sid);
+                             $page->pid(), $id, $sid);
             }
         }
     }
@@ -82,7 +82,7 @@ class ProfileCountry implements ProfileSetting
                                    FROM  profile_mentor_country AS m
                              INNER JOIN  geoloc_pays            AS p ON (m.country = p.a2)
                                   WHERE  m.uid = {?}",
-                                S::i('uid'));
+                                $page->pid());
             while (list($id, $name) = $res->next()) {
                 $value[$id] = $name;
             }
@@ -100,11 +100,11 @@ class ProfileCountry implements ProfileSetting
     {
         XDB::execute("DELETE FROM  profile_mentor_country
                             WHERE  uid = {?}",
-                     S::i('uid'));
+                     $page->pid());
         foreach ($value as $id=>&$name) {
             XDB::execute("INSERT INTO  profile_mentor_country (uid, country)
                                VALUES  ({?}, {?})",
-                         S::i('uid'), $id);
+                         $page->pid(), $id);
         }
     }
 }
@@ -127,7 +127,7 @@ class ProfileMentor extends ProfilePage
         $res = XDB::query("SELECT  expertise
                              FROM  mentor
                             WHERE  uid = {?}",
-                          S::i('uid'));
+                          $this->pid());
         $this->values['expertise'] = $res->fetchOneCell();
     }
 
@@ -138,12 +138,12 @@ class ProfileMentor extends ProfilePage
             if (empty($expertise)) {
                 XDB::execute("DELETE FROM  mentor
                                     WHERE  uid = {?}",
-                             S::i('uid'));
+                             $this->pid());
                 $this->values['expertise'] = null;
             } else {
                 XDB::execute("REPLACE INTO  mentor (uid, expertise)
                                     VALUES  ({?}, {?})",
-                             S::i('uid'), $expertise);
+                             $this->pid(), $expertise);
                 $this->values['expertise'] = $expertise;
             }
         }
index 4599857..77cd2b7 100644 (file)
@@ -119,17 +119,11 @@ class ProfilePhones implements ProfileSetting
 {
     private $tel;
     private $pub;
-    protected $id;
     protected $link_type;
     protected $link_id;
 
-    public function __construct($type, $link_id, $id = 0)
+    public function __construct($type, $link_id)
     {
-        if ($id != 0) {
-            $this->id = $id;
-        } else {
-            $this->id = S::i('uid');
-        }
         $this->tel = new ProfileTel();
         $this->pub = new ProfilePub();
         $this->link_type = $type;
@@ -145,7 +139,7 @@ class ProfilePhones implements ProfileSetting
                                     FROM  profile_phones AS t
                                    WHERE  t.uid = {?} AND t.link_type = {?}
                                 ORDER BY  t.tel_id",
-                                 $this->id, $this->link_type);
+                                 $page->pid(), $this->link_type);
             $value = $res->fetchAllAssoc();
         }
         foreach ($value as $key=>&$phone) {
@@ -171,14 +165,14 @@ class ProfilePhones implements ProfileSetting
         return $value;
     }
 
-    private function saveTel($telid, array &$phone)
+    private function saveTel($pid, $telid, array &$phone)
     {
         if ($phone['tel'] != '') {
             XDB::execute("INSERT INTO  profile_phones (uid, link_type, link_id, tel_id, tel_type,
                                        search_tel, display_tel, pub, comment)
                                VALUES  ({?}, {?}, {?}, {?}, {?},
                                        {?}, {?}, {?}, {?})",
-                         $this->id, $this->link_type, $this->link_id, $telid, $phone['type'],
+                         $pid, $this->link_type, $this->link_id, $telid, $phone['type'],
                          format_phone_number($phone['tel']), $phone['tel'], $phone['pub'], $phone['comment']);
         }
     }
@@ -187,15 +181,15 @@ class ProfilePhones implements ProfileSetting
     {
         XDB::execute("DELETE FROM  profile_phones
                             WHERE  uid = {?} AND link_type = {?} AND link_id = {?}",
-                            $this->id, $this->link_type, $this->link_id);
-        $this->saveTels($field, $value);
+                     $page->pid(), $this->link_type, $this->link_id);
+        $this->saveTels($page->pid(), $field, $value);
     }
 
     //Only saves phones without a delete operation
-    public function saveTels($field, $value)
+    public function saveTels($pid, $field, $value)
     {
         foreach ($value as $telid=>&$phone) {
-            $this->saveTel($telid, $phone);
+            $this->saveTel($pid, $telid, $phone);
         }
     }
 }
@@ -307,10 +301,14 @@ abstract class ProfilePage implements PlWizardPage
 
     public $orig     = array();
     public $values   = array();
+    public $profile  = null;
+    public $owner    = null;
 
     public function __construct(PlWizard &$wiz)
     {
         $this->wizard =& $wiz;
+        $this->profile = $this->wizard->getUserData('profile');
+        $this->owner   = $this->wizard->getUserData('owner');
     }
 
     protected function _fetchData()
@@ -349,19 +347,19 @@ abstract class ProfilePage implements PlWizardPage
                 $setting->save($this, $field, $this->values[$field]);
             }
             if ($this->changed[$field] && @$this->watched[$field]) {
-                register_profile_update(S::i('uid'), $field);
+                register_profile_update($profile->id(), $field);
             }
         }
         $this->_saveData();
 
         // Update the last modification date
         XDB::execute('REPLACE INTO  user_changes
-                               SET  user_id = {?}', S::v('uid'));
+                               SET  user_id = {?}', $profile->id());
         if (!S::suid()) {
-            register_watch_op(S::i('uid'), WATCH_FICHE);
+            register_watch_op($profile->id(), WATCH_FICHE);
         }
         global $platal;
-        S::logger()->log('profil', $platal->pl_self(1));
+        S::logger()->log('profil', $platal->pl_self(2));
     }
 
     protected function checkChanges()
@@ -391,6 +389,16 @@ abstract class ProfilePage implements PlWizardPage
         return 'profile/base.tpl';
     }
 
+    public function pid()
+    {
+        return $this->profile->id();
+    }
+
+    public function hrpid()
+    {
+        return $this->profile->hrpid();
+    }
+
     protected function _prepare(PlPage &$page, $id)
     {
     }
@@ -404,6 +412,8 @@ abstract class ProfilePage implements PlWizardPage
             $page->assign($field, $value);
         }
         $this->_prepare($page, $id);
+        $page->assign('profile', $this->profile);
+        $page->assign('owner', $this->owner);
         $page->assign('profile_page', $this->pg_template);
         $page->assign('errors', $this->errors);
     }
index c3da4f9..c0f20e5 100644 (file)
@@ -40,7 +40,7 @@ class ProfileSkill implements ProfileSetting
                                    FROM  {$this->table}_def AS s
                              INNER JOIN  {$this->table}_ins AS i ON(s.id = i.{$this->skill_field})
                                   WHERE  i.uid = {?}",
-                                S::i('uid'));
+                                $page->pid());
             while (list($sid, $text, $level) = $res->next()) {
                 $value[$sid] = array('text' => $text, 'level' => $level);
             }
@@ -66,14 +66,14 @@ class ProfileSkill implements ProfileSetting
     {
         XDB::execute("DELETE FROM  {$this->table}_ins
                             WHERE  uid = {?}",
-                     S::i('uid'));
+                     $page->pid());
         if (!count($value)) {
             return;
         }
         foreach ($value as $id=>&$skill) {
             XDB::execute("INSERT INTO  {$this->table}_ins (uid, {$this->skill_field}, level)
                                VALUES  ({?}, {?}, {?})",
-                         S::i('uid'), $id, $skill['level']);
+                         $page->pid(), $id, $skill['level']);
         }
     }
 }
index 9c2e580..1b16f1f 100644 (file)
     <td>
       <span class="titre">Date de naissance</span>
     </td>
-    <td><input type="text" {if $errors.naissance}class="error"{/if} name="naissance" value="{$naissance}" /></td>
+    <td><input type="text" {if $errors.birthdate}class="error"{/if} name="naissance" value="{$birthdate}" /></td>
   </tr>
   <tr>
     <td>
       <span class="titre">Nationalité</span>
     </td>
     <td>
-      <select name="nationalite">
-        {select_nat valeur=$nationalite pad=1}
+      <select name="nationality1">
+        {select_nat valeur=$nationality1 pad=1}
       </select>
       <a href="javascript:addNationality();">{icon name=add title="Ajouter une nationalité"}</a>
     </td>
   </tr>
-  <tr id="nationalite2" {if !$nationalite2}style="display: none"{/if}>
+  <tr id="nationality2" {if !$nationality2}style="display: none"{/if}>
     <td></td>
     <td>
-      <select name="nationalite2">
-        {select_nat valeur=$nationalite2 pad=1}
+      <select name="nationality2">
+        {select_nat valeur=$nationality2 pad=1}
       </select>
       <a href="javascript:delNationality('2');">{icon name=cross title="Supprimer cette nationalité"}</a>
     </td>
   </tr>
-  <tr id="nationalite3" {if !$nationalite3}style="display: none"{/if}>
+  <tr id="nationality3" {if !$nationality3}style="display: none"{/if}>
     <td></td>
     <td>
-      <select name="nationalite3">
-        {select_nat valeur=$nationalite3 pad=1}
+      <select name="nationality3">
+        {select_nat valeur=$nationality3 pad=1}
       </select>
       <a href="javascript:delNationality('3');">{icon name=cross title="Supprimer cette nationalité"}</a>
     </td>
   </tr>
  </table>
 
-{if !$no_private_key}
-<table class="bicol"  style="margin-bottom: 1em"
-  summary="Profil&nbsp;: Informations générales">
-  <tr>
-    <th>
-      Synchronisation avec l'AX
-    </th>
-  </tr>
-  <tr>
-    <td class="flags">
-      <input type="checkbox" name="synchro_ax" {if $synchro_ax}checked="checked" {/if}/>
-      {icon name="flag_orange" title="transmis à l'AX"}
-      <span class="texte">
-        Autoriser la synchronisation vers l'AX par des administrateurs ou des scripts automatiques.
-      </span>
-    </td>
-  </tr>
-  <tr>
-    <td>
-      <p>
-        Le service annuaire de l'<a href='http://www.polytechniciens.com'>AX</a> met à jour l'annuaire papier à partir des informations que tu lui fournis. Tu peux choisir ici d'envoyer directement les données de ta fiche Polytechnique.org vers ta <a href="http://www.polytechniciens.com/?page=AX_FICHE_ANCIEN&amp;anc_id={$matricule_ax}">fiche AX</a>.
-      </p>
-      <p>
-        L'opération de synchronisation prend en compte toutes les informations que tu as marquées comme transmises à l'AX (en orange ou en vert). Elle peut alors effacer, modifier ou rajouter des informations sur ta <a href="http://www.polytechniciens.com/?page=AX_FICHE_ANCIEN&amp;anc_id={$matricule_ax}">fiche AX</a> selon ce qui s'y trouve déjà.
-      </p>
-      <p class="center">
-        <a href="profile/edit/general?synchro_ax=confirm" onclick="return confirm('Es-tu sûr de vouloir lancer la synchronisation ?')"><input type="button" value="Synchroniser"/></a>
-      </p>
-    </td>
-  </tr>
-</table>
-{/if}
-
 <table class="bicol"  style="margin-bottom: 1em"
   summary="Profil&nbsp;: Trombinoscope">
   <tr>
   <tr>
     <td {if !$nouvellephoto}colspan="2"{/if} class="center" style="width: 49%">
       <div class="titre">Ta photo actuelle</div>
-      <img src="photo/{$smarty.session.hruid}" alt=" [ PHOTO ] " style="max-height: 250px; margin-top: 1em" />
+      <img src="photo/{$profile->hrid()}" alt=" [ PHOTO ] " style="max-height: 250px; margin-top: 1em" />
     </td>
     {if $nouvellephoto}
     <td class="center" style="width: 49%">
       <div class="titre">Photo en attente de validation</div>
       <div>
-        <a href="profile/{$smarty.session.hruid}?modif=new" class="popup2">
+        <a href="profile/{$profile->hrid()}?modif=new" class="popup2">
           Ta fiche avec cette photo
         </a>
       </div>
-      <img src="photo/{$smarty.session.hruid}/req" alt=" [ PHOTO ] " style="max-height: 250px; margin-top: 1em" />
+      <img src="photo/{$profile->hrid()}/req" alt=" [ PHOTO ] " style="max-height: 250px; margin-top: 1em" />
     </td>
     {/if}
   </tr>