Renames user_id to uid in requests related tables accordingly to our naming convention.
[platal.git] / modules / profile / general.inc.php
index 9856dc8..488d180 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2009 Polytechnique.org                              *
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -33,7 +33,7 @@ class ProfileSearchNames implements ProfileSetting
 
     private function prepareField($value)
     {
-        $value = strtoupper(replace_accent($value));
+        $value = mb_strtoupper($value);
         return preg_replace('/[^A-Z]/', ' ', $value);
     }
 
@@ -57,6 +57,7 @@ class ProfileSearchNames implements ProfileSetting
     {
         $success     = true;
         $success_tmp = true;
+
         if (is_null($value)) {
             $sn_all = XDB::iterator("SELECT  CONCAT(sn.particle, sn.name) AS name,
                                              sn.particle, sn.typeid, e.type, e.name AS type_name,
@@ -85,12 +86,14 @@ class ProfileSearchNames implements ProfileSetting
                         $sn = $sn_all->next();
                     }
                 } else {
-                    $value[] = array('typeid'    => $sn_type['id'],
-                                     'type'      => $sn_type['type'],
-                                     'type_name' => $sn_type['name'],
-                                     'pub'       => 1,
+                    $value[] = array('name'             => '',
+                                     'particle'         => '',
+                                     'typeid'           => $sn_type['id'],
+                                     'type'             => $sn_type['type'],
+                                     'type_name'        => $sn_type['name'],
                                      'has_particle'     => $sn_type['has_particle'],
-                                     'always_displayed' => 1);
+                                     'always_displayed' => 1,
+                                     'pub'              => 1);
                 }
             }
             if ($sn) {
@@ -162,6 +165,7 @@ class ProfileSearchNames implements ProfileSetting
             Platal::page()->assign('public_name', $public_name);
             Platal::page()->assign('private_name', $private_name);
         }
+
         return $value;
     }
 
@@ -180,7 +184,7 @@ class ProfileSearchNames implements ProfileSetting
         if ($has_new) {
             $new_names = new NamesReq(S::user(), $this->search_names, $this->private_name_end);
             $new_names->submit();
-            Platal::page()->trigWarning("La demande de modification de tes noms a bien été prises en compte." .
+            Platal::page()->trigWarning("La demande de modification de tes noms a bien été prise en compte." .
                                         " Tu recevras un email dès que ces changements auront été effectués.");
         } else {
             $display_names = array();
@@ -211,7 +215,7 @@ class ProfileEdu implements ProfileSetting
             $value = array();
             $value = XDB::fetchAllAssoc("SELECT  eduid, degreeid, fieldid, grad_year, program
                                            FROM  profile_education
-                                          WHERE  uid = {?} AND !FIND_IN_SET('primary', flags)
+                                          WHERE  pid = {?} AND !FIND_IN_SET('primary', flags)
                                        ORDER BY  id",
                                         $page->pid());
         } else {
@@ -236,12 +240,12 @@ class ProfileEdu implements ProfileSetting
     public function save(ProfilePage &$page, $field, $value)
     {
         XDB::execute("DELETE FROM  profile_education
-                            WHERE  uid = {?} AND !FIND_IN_SET('primary', flags)",
+                            WHERE  pid = {?} AND !FIND_IN_SET('primary', flags)",
                      $page->pid());
         foreach ($value as $eduid=>&$edu) {
             if ($edu['eduid'] != '') {
                 XDB::execute("INSERT INTO  profile_education
-                                      SET  id = {?}, uid = {?}, eduid = {?}, degreeid = {?},
+                                      SET  id = {?}, pid = {?}, eduid = {?}, degreeid = {?},
                                            fieldid = {?}, grad_year = {?}, program = {?}",
                              $eduid, $page->pid(), $edu['eduid'], $edu['degreeid'],
                              $edu['fieldid'], $edu['grad_year'], $edu['program']);
@@ -296,7 +300,7 @@ class ProfileNetworking implements ProfileSetting
             $value = XDB::fetchAllAssoc("SELECT  n.address, n.network_type AS type, n.pub, m.name
                                            FROM  profile_networking AS n
                                      INNER JOIN  profile_networking_enum AS m ON (n.network_type = m.network_type)
-                                          WHERE  n.uid = {?}",
+                                          WHERE  n.pid = {?}",
                                          $page->pid());
         }
         if (!is_array($value)) {
@@ -334,14 +338,14 @@ class ProfileNetworking implements ProfileSetting
     public function save(ProfilePage &$page, $field, $value)
     {
         XDB::execute("DELETE FROM profile_networking
-                            WHERE uid = {?}",
+                            WHERE pid = {?}",
                      $page->pid());
         if (!count($value)) {
             return;
         }
         $insert = array();
         foreach ($value as $id=>$network) {
-            XDB::execute("INSERT INTO  profile_networking (uid, nwid, network_type, address, pub)
+            XDB::execute("INSERT INTO  profile_networking (pid, nwid, network_type, address, pub)
                                VALUES  ({?}, {?}, {?}, {?}, {?})",
                          $page->pid(), $id, $network['type'], $network['address'], $network['pub']);
         }
@@ -368,8 +372,6 @@ class ProfileGeneral extends ProfilePage
                                   = $this->settings['yourself']
                                   = $this->settings['promo']
                                   = null;
-        $this->settings['synchro_ax']
-                                  = new ProfileBool();
         $this->settings['email_directory']
                                   = new ProfileEmail();
         $this->settings['email_directory_new']
@@ -389,13 +391,12 @@ class ProfileGeneral extends ProfilePage
         $res = XDB::query("SELECT  p.promo, e.entry_year AS entry_year, e.grad_year AS grad_year,
                                    pr.nationality1, pr.nationality2, pr.nationality3, pr.birthdate,
                                    t.display_tel as mobile, t.pub as mobile_pub,
-                                   d.email_directory as email_directory,
-                                   pr.freetext, pr.freetext_pub as freetext_pub
+                                   pr.email_directory as email_directory,
+                                   pr.freetext, pr.freetext_pub, pr.ax_id AS matricule_ax, p.yourself
                              FROM  profiles              AS pr
                        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)
+                       INNER JOIN  profile_education     AS e ON (e.pid = pr.pid AND FIND_IN_SET('primary', e.flags))
+                        LEFT JOIN  profile_phones        AS t ON (t.pid = pr.pid AND link_type = 'user')
                             WHERE  pr.pid = {?}", $this->pid());
         $this->values = $res->fetchOneAssoc();
         if ($this->owner) {
@@ -404,14 +405,14 @@ class ProfileGeneral extends ProfilePage
 
         // Retreive photo informations
         $res = XDB::query("SELECT  pub
-                             FROM  photo
-                            WHERE  uid = {?}", $this->pid());
+                             FROM  profile_photos
+                            WHERE  pid = {?}", $this->pid());
         $this->values['photo_pub'] = $res->fetchOneCell();
 
         if ($this->owner) {
             $res = XDB::query("SELECT  COUNT(*)
                                  FROM  requests
-                                WHERE  type='photo' AND user_id = {?}",
+                                WHERE  type = 'photo' AND uid = {?}",
                               $this->owner->id());
             $this->values['nouvellephoto'] = $res->fetchOneCell();
         } else {
@@ -429,7 +430,8 @@ class ProfileGeneral extends ProfilePage
     protected function _saveData()
     {
         if ($this->changed['nationality1'] || $this->changed['nationality2'] || $this->changed['nationality3']
-            || $this->changed['birthdate'] || $this->changed['freetext'] || $this->changed['freetext_pub']) {
+            || $this->changed['birthdate'] || $this->changed['freetext'] || $this->changed['freetext_pub']
+            || $this->changed['email_directory']) {
             if ($this->values['nationality3'] == "") {
                 $this->values['nationality3'] = NULL;
             }
@@ -442,30 +444,24 @@ class ProfileGeneral extends ProfilePage
                 $this->values['nationality2'] = $this->values['nationality3'];
                 $this->values['nationality3'] = NULL;
             }
-
-            XDB::execute("UPDATE  profiles
-                             SET  nationality1 = {?}, nationality2 = {?}, nationality3 = {?}, birthdate = {?},
-                                  freetext = {?}, freetext_pub = {?}
-                           WHERE  user_id = {?}",
-                          $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") ?
                 $this->values['email_directory_new'] : $this->values['email_directory'];
             if ($new_email == "") {
                 $new_email = NULL;
             }
-            XDB::execute("REPLACE INTO  profile_directory (uid, email_directory)
-                                VALUES  ({?}, {?})",
-                         $this->pid(), $new_email);
+
+            XDB::execute("UPDATE  profiles
+                             SET  nationality1 = {?}, nationality2 = {?}, nationality3 = {?}, birthdate = {?},
+                                  freetext = {?}, freetext_pub = {?}, email_directory = {?}
+                           WHERE  pid = {?}",
+                          $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'], $new_email, $this->pid());
         }
         if ($this->changed['photo_pub']) {
-            XDB::execute("UPDATE  photo
+            XDB::execute("UPDATE  profile_photos
                              SET  pub = {?}
-                           WHERE  uid = {?}",
+                           WHERE  pid = {?}",
                          $this->values['photo_pub'], $this->pid());
         }
         if ($this->changed['yourself']) {