Adds a common template to add phone numbers in the different pages of the profile
authorGuillaume Bandet <guillaume.bandet@polytechnique.org>
Wed, 25 Jun 2008 08:42:37 +0000 (10:42 +0200)
committerGuillaume Bandet <guillaume.bandet@polytechnique.org>
Thu, 10 Jul 2008 22:20:36 +0000 (00:20 +0200)
Improves the display of phone numbers in profile
Adds a comment field for phone numbers

17 files changed:
htdocs/javascript/profile.js
include/profil.func.inc.php
include/user.func.inc.php
modules/profile.php
modules/profile/addresses.inc.php
modules/profile/general.inc.php
modules/profile/jobs.inc.php
modules/profile/page.inc.php
plugins/function.display_address.php
plugins/function.display_phones.php [new file with mode: 0644]
templates/core/vcard.tpl
templates/profile/adresses.address.tpl
templates/profile/general.tpl
templates/profile/jobs.job.tpl
templates/profile/phone.tpl [moved from templates/profile/adresses.tel.tpl with 56% similarity]
templates/profile/profile.tpl
upgrade/fusionax-0.0.1/03_telephone.sql

index 4e16e29..d625bfb 100644 (file)
@@ -237,18 +237,34 @@ function addAddress()
     Ajax.update_html('addresses_' + i + '_cont', 'profile/ajax/address/' + i, checkCurrentAddress);
 }
 
-function addTel(id)
+function addTel(prefid, prefname)
 {
     var i = 0;
-    var adid = 'addresses_' + id;
-    var tel  = adid + '_tel_';
-    while (document.getElementById(tel + i) != null) {
+    var prefix  = prefid + '_';
+    while (document.getElementById(prefix + i) != null) {
         i++;
     }
-    $('#' + adid + '_add_tel').before('<div id="' + tel + i + '" style="clear: both"></div>');
-    Ajax.update_html(tel + i, 'profile/ajax/tel/' + id + '/' + i);
+    $('#' + prefix + 'add').before('<div id="' + prefix + i + '" style="clear: both; padding-top: 4px; padding-bottom: 4px"></div>');
+    Ajax.update_html(prefix + i, 'profile/ajax/tel/' + prefid + '/' + prefname + '/' + i);
 }
 
+function removeTel(id)
+{
+    $('#' + id).remove();
+}
+
+function addPhoneComment(id, pref)
+{
+    document.getElementById(id+'_comment').style.display = '';
+    document.getElementById(id+'_addComment').style.display = 'none';
+}
+
+function removePhoneComment(id, pref)
+{
+    document.getElementById(id+'_comment').style.display = 'none';
+    document.forms.prof_annu[pref+ '[comment]'].value = '';
+    document.getElementById(id+'_addComment').style.display = '';
+}
 
 // Geoloc
 
index 5e084be..24d5b7e 100644 (file)
@@ -76,15 +76,15 @@ function diff_user_details(&$a, &$b, $view = 'private') { // compute $c = $a - $
 }
 
 function same_tel(&$a, &$b) {
-    $numbera = preg_replace('/[^0-9]/', '', (string) $a);
-    $numberb = preg_replace('/[^0-9]/', '', (string) $b);
+    $numbera = format_phone_number((string) $a);
+    $numberb = format_phone_number((string) $b);
     return $numbera === $numberb;
 }
 function same_address(&$a, &$b) {
     return
         (same_field($a['adr1'],$b['adr1'])) &&
-        (same_field($a['adr1'],$b['adr1'])) &&
-        (same_field($a['adr1'],$b['adr1'])) &&
+        (same_field($a['adr2'],$b['adr2'])) &&
+        (same_field($a['adr3'],$b['adr3'])) &&
         (same_field($a['postcode'],$b['postcode'])) &&
         (same_field($a['city'],$b['city'])) &&
         (same_field($a['countrytxt'],$b['countrytxt'])) &&
@@ -322,7 +322,7 @@ function format_display_number($tel, &$error, $format = array('format'=>'','phon
                           substr($tel, 0, 1), substr($tel, 0, 2), substr($tel, 0, 3));
         if ($res->numRows() == 0) {
             $error = true;
-            return '*+' . $tel;
+            return '+' . $tel;
         }
         $format = $res->fetchOneAssoc();
     }
index 6ebfe8a..a12be69 100644 (file)
@@ -264,18 +264,14 @@ function get_user_details_pro($uid, $view = 'private')
 {
     $sql  = "SELECT  e.entreprise, s.label as secteur , ss.label as sous_secteur , f.fonction_fr as fonction,
                      e.poste, e.adr1, e.adr2, e.adr3, e.postcode, e.city, e.entrid,
-                     gp.pays AS countrytxt, gr.name AS region, tt.display_tel AS tel,
-                     tf.display_tel AS fax, tm.display_tel AS mobile, e.entrid,
-                     e.pub, e.adr_pub, tt.pub AS tel_pub, e.email, e.email_pub, e.web
+                     gp.pays AS countrytxt, gr.name AS region, e.entrid,
+                     e.pub, e.adr_pub, e.email, e.email_pub, e.web
                FROM  entreprises AS e
           LEFT JOIN  emploi_secteur AS s ON(e.secteur = s.id)
           LEFT JOIN  emploi_ss_secteur AS ss ON(e.ss_secteur = ss.id AND e.secteur = ss.secteur)
           LEFT JOIN  fonctions_def AS f ON(e.fonction = f.id)
           LEFT JOIN  geoloc_pays AS gp ON (gp.a2 = e.country)
           LEFT JOIN  geoloc_region AS gr ON (gr.a2 = e.country and gr.region = e.region)
-          LEFT JOIN  profile_phones AS tt ON(tt.uid = e.uid AND tt.link_type = 'pro' AND tt.link_id = entrid AND tt.tel_id = 0)
-          LEFT JOIN  profile_phones AS tf ON(tf.uid = e.uid AND tf.link_type = 'pro' AND tf.link_id = entrid AND tf.tel_id = 1)
-          LEFT JOIN  profile_phones AS tm ON(tm.uid = e.uid AND tm.link_type = 'pro' AND tm.link_id = entrid AND tm.tel_id = 2)
               WHERE  e.uid = {?}
            ORDER BY  e.entrid";
     $res  = XDB::query($sql, $uid);
@@ -303,16 +299,18 @@ function get_user_details_pro($uid, $view = 'private')
                     $all_pro[$i]['region'] = '';
                 }
             }
-            if (!has_user_right($pro['tel_pub'], $view)) {
-                // if no tel was defined, then the viewer will be able to write it
-                if ($pro['tel'] == '' &&
-                    $pro['fax'] == '' &&
-                    $pro['mobile'] == '') {
-                    $all_pro[$i]['tel_pub'] = $view;
-                } else {
-                    $all_pro[$i]['tel'] = '';
-                    $all_pro[$i]['fax'] = '';
-                    $all_pro[$i]['mobile'] = '';
+            $sql = "SELECT  pub AS tel_pub, tel_type, display_tel AS tel, comment
+                      FROM  profile_phones AS t
+                     WHERE  uid = {?} AND link_type = 'pro' AND link_id = {?}
+                  ORDER BY  link_id, tel_type DESC, tel_id";
+            $restel = XDB::iterator($sql, $uid, $pro['entrid']);
+            while ($nexttel = $restel->next()) {
+                if (has_user_right($nexttel['tel_pub'], $view)) {
+                    if (!isset($all_pro[$i]['tels'])) {
+                        $all_pro[$i]['tels'] = array($nexttel);
+                    } else {
+                        $all_pro[$i]['tels'][] = $nexttel;
+                    }
                 }
             }
             if (!has_user_right($pro['email_pub'], $view)) {
@@ -332,9 +330,7 @@ function get_user_details_pro($uid, $view = 'private')
                 $all_pro[$i]['fonction'] == '' &&
                 $all_pro[$i]['secteur'] == '' &&
                 $all_pro[$i]['poste'] == '' &&
-                $all_pro[$i]['tel'] == '' &&
-                $all_pro[$i]['fax'] == '' &&
-                $all_pro[$i]['mobile'] == '' &&
+                (!isset($all_pro[$i]['tels'])) &&
                 $all_pro[$i]['email'] == '')
                 unset($all_pro[$i]);
         }
@@ -366,7 +362,7 @@ function get_user_details_adr($uid, $view = 'private') {
             $adrid_index[$adr['adrid']] = $i;
     }
 
-    $sql = "SELECT  link_id AS adrid, pub AS tel_pub, tel_type, display_tel AS tel, tel_id AS telid
+    $sql = "SELECT  link_id AS adrid, pub AS tel_pub, tel_type, display_tel AS tel, tel_id AS telid, comment
               FROM  profile_phones AS t
              WHERE  uid = {?} AND link_type = 'address'
           ORDER BY  link_id, tel_type DESC, tel_id";
@@ -393,8 +389,8 @@ function &get_user_details($login, $from_uid = '', $view = 'private')
 {
     $reqsql = "SELECT  u.user_id, u.promo, u.promo_sortie, u.prenom, u.nom, u.nom_usage, u.date, u.cv,
                        u.perms IN ('admin','user','disabled') AS inscrit,  FIND_IN_SET('femme', u.flags) AS sexe, u.deces != 0 AS dcd, u.deces,
-                       q.profile_nick AS nickname, q.profile_from_ax, t.display_tel AS mobile, q.profile_freetext AS freetext,
-                       t.pub AS mobile_pub, q.profile_freetext_pub AS freetext_pub,
+                       q.profile_nick AS nickname, q.profile_from_ax, q.profile_freetext AS freetext,
+                       q.profile_freetext_pub AS freetext_pub,
                        q.profile_medals_pub AS medals_pub,
                        IF(gp.nat='',gp.pays,gp.nat) AS nationalite, gp.a2 AS iso3166,
                        a.alias AS forlife, a2.alias AS bestalias,
@@ -413,7 +409,6 @@ function &get_user_details($login, $from_uid = '', $view = 'private')
             LEFT JOIN  photo           AS p  ON (p.uid = u.user_id)
             LEFT JOIN  mentor          AS m  ON (m.uid = u.user_id)
             LEFT JOIN  emails          AS e  ON (e.uid = u.user_id AND e.flags='active')
-            LEFT JOIN  profile_phones  AS t  ON (t.uid = u.user_id AND link_type = 'user' AND link_id = 0 AND tel_id = 0)
                 WHERE  a.alias = {?}
              GROUP BY  u.user_id";
     $res  = XDB::query($reqsql, $from_uid, $login);
@@ -426,13 +421,6 @@ function &get_user_details($login, $from_uid = '', $view = 'private')
         $user['nickname'] = '';
         $user['section'] = '';
     }
-    // hide mobile
-    if (!has_user_right($user['mobile_pub'], $view)) {
-        if ($user['mobile'] == '')
-            $user['mobile_pub'] = $view;
-        else
-            $user['mobile'] = '';
-    }
 
     // hide freetext
     if (!has_user_right($user['freetext_pub'], $view)) {
@@ -442,6 +430,21 @@ function &get_user_details($login, $from_uid = '', $view = 'private')
             $user['freetext'] = '';
     }
 
+    $sql = "SELECT  pub AS tel_pub, tel_type, display_tel AS tel, comment
+              FROM  profile_phones AS t
+             WHERE  uid = {?} AND link_type = 'user'
+          ORDER BY  tel_type DESC, tel_id";
+    $restel = XDB::iterator($sql, $uid);
+    while ($nexttel = $restel->next()) {
+        if (has_user_right($nexttel['tel_pub'], $view)) {
+            if (!isset($user['tels'])) {
+                $user['tels'] = array($nexttel);
+            } else {
+                $user['tels'][] = $nexttel;
+            }
+        }
+    }
+
     $user['adr_pro'] = get_user_details_pro($uid, $view);
     $user['adr']     = get_user_details_adr($uid, $view);
 
index e3d86cd..c28ef27 100644 (file)
@@ -393,14 +393,13 @@ class ProfileModule extends PLModule
         $page->assign('adr', array());
     }
 
-    function handler_ajax_tel(&$page, $adid, $telid)
+    function handler_ajax_tel(&$page, $prefid, $prefname, $telid)
     {
         header('Content-Type: text/html; charset=utf-8');
-        $page->changeTpl('profile/adresses.tel.tpl', NO_SKIN);
-        $page->assign('i', $adid);
-        $page->assign('adid', "addresses_$adid");
-        $page->assign('adpref', "addresses[$adid]");
-        $page->assign('t', $telid);
+        $page->changeTpl('profile/phone.tpl', NO_SKIN);
+        $page->assign('prefid', $prefid);
+        $page->assign('prefname', $prefname);
+        $page->assign('telid', $telid);
         $page->assign('tel', array());
     }
 
index 6dfd2bb..ade256e 100644 (file)
@@ -23,38 +23,24 @@ class ProfileAddress extends ProfileGeoloc
 {
     private $bool;
     private $pub;
-    private $tel;
 
     public function __construct()
     {
         $this->bool = new ProfileBool();
         $this->pub  = new ProfilePub();
-        $this->tel  = new ProfileTel();
     }
 
-    private function cleanAddress(ProfilePage &$page, array &$address, &$success)
+    private function cleanAddress(ProfilePage &$page, $adrid, array &$address, &$success)
     {
         if (@$address['changed']) {
             $address['datemaj'] = time();
         }
         $success = true;
-        foreach ($address['tel'] as $t=>&$tel) {
-            if (@$tel['removed'] || !trim($tel['tel'])) {
-                unset($address['tel'][$t]);
-            } else {
-                $tel['pub'] = $this->pub->value($page, 'pub', $tel['pub'], $s);
-                $tel['tel'] = $this->tel->value($page, 'tel', $tel['tel'], $s);
-                if(!isset($tel['type']) || ($tel['type'] != 'fixed' && $tel['type'] != 'mobile' && $tel['type'] != 'fax')) {
-                    $tel['type'] = 'fixed';
-                    $s = false;
-                }
-                if (!$s) {
-                    $tel['error'] = true;
-                    $success = false;
-                }
-            }
-            unset($tel['removed']);
+        if (!isset($address['tel'])) {
+            $address['tel'] = array();
         }
+        $profiletel  = new ProfilePhones('address', $adrid);
+        $address['tel'] = $profiletel->value($page, 'tel', $address['tel'], $s);
         $address['checked'] = $this->bool->value($page, 'checked', $address['checked'], $s);
         $address['secondaire'] = $this->bool->value($page, 'secondaire', $address['secondaire'], $s);
         $address['mail'] = $this->bool->value($page, 'mail', $address['mail'], $s);
@@ -98,7 +84,7 @@ class ProfileAddress extends ProfileGeoloc
             $ls = true;
             $this->geolocAddress($adr, $s);
             $ls = ($ls && $s);
-            $this->cleanAddress($page, $adr, $s);
+            $this->cleanAddress($page, $key, $adr, $s);
             $ls = ($ls && $s);
             if (!trim($adr['text'])) {
                 unset($value[$key]);
@@ -153,9 +139,6 @@ class ProfileAddress extends ProfileGeoloc
                      $address['country'], $address['region'], $address['regiontxt'],
                      $address['pub'], $address['datemaj'], $flags,
                      S::i('uid'), $adrid, $address['precise_lat'], $address['precise_lon'], $address['comment']);
-        foreach ($address['tel'] as $telid=>&$tel) {
-            $this->saveTel($adrid, $telid, $tel);
-        }
     }
 
     public function save(ProfilePage &$page, $field, $value)
@@ -168,6 +151,8 @@ class ProfileAddress extends ProfileGeoloc
                      S::i('uid'));
         foreach ($value as $adrid=>&$address) {
             $this->saveAddress($adrid, $address);
+            $profiletel = new ProfilePhones('address', $adrid);
+            $profiletel->saveTels('tel', $address['tel']);
         }
     }
 }
@@ -208,7 +193,7 @@ class ProfileAddresses extends ProfilePage
             $this->values['addresses'] = $res->fetchAllAssoc();
         }
 
-        $res = XDB::iterator("SELECT  link_id AS adrid, tel_type AS type, pub, display_tel AS tel
+        $res = XDB::iterator("SELECT  link_id AS adrid, tel_type AS type, pub, display_tel AS tel, comment
                                 FROM  profile_phones
                                WHERE  uid = {?} AND link_type = 'address'
                             ORDER BY  link_id",
index 3c45445..8eb098e 100644 (file)
@@ -231,8 +231,7 @@ class ProfileGeneral extends ProfilePage
         $this->settings['nom']    = $this->settings['prenom']
                                   = new ProfileNom();
         $this->settings['naissance'] = new ProfileDate();
-        $this->settings['mobile_pub']
-                                  = $this->settings['freetext_pub']
+        $this->settings['freetext_pub']
                                   = $this->settings['photo_pub']
                                   = new ProfilePub();
         $this->settings['freetext']
@@ -245,16 +244,16 @@ class ProfileGeneral extends ProfilePage
                                   = null;
         $this->settings['synchro_ax']
                                   = new ProfileBool();
-        $this->settings['mobile'] = new ProfileTel();
         $this->settings['email_directory']
                                   = new ProfileEmail();
         $this->settings['email_directory_new']
                                   = new ProfileEmailDirectory();
         $this->settings['networking'] = new ProfileNetworking();
+        $this->settings['tels'] = new ProfilePhones('user', 0);
         $this->settings['appli1']
                                   = $this->settings['appli2']
                                   = new ProfileAppli();
-        $this->watched= array('nom' => true, 'freetext' => true, 'mobile' => true,
+        $this->watched= array('nom' => true, 'freetext' => true, 'tels' => true,
                               'networking' => true, 'appli1' => true, 'appli2' => true,
                               'nationalite' => true, 'nick' => true);
     }
@@ -310,6 +309,14 @@ class ProfileGeneral extends ProfilePage
                                WHERE  sn.user_id = {?}
                             ORDER BY  sn.name_type, search_score, search_name",
                           S::v('uid'));
+
+        // Retreive phones
+        $res = XDB::iterator("SELECT t.display_tel AS tel, t.tel_type AS type, t.pub, t.comment
+                                FROM profile_phones AS t
+                               WHERE t.uid = {?} AND t.link_type = 'user'
+                            ORDER BY t.tel_id",
+                             S::v('uid'));
+        $this->values['tels'] = $res->fetchAllAssoc();
     }
 
     protected function _saveData()
@@ -340,18 +347,6 @@ class ProfileGeneral extends ProfilePage
                                 VALUES  ({?}, {?})",
                          S::v('uid'), $new_email);
         }
-        if ($this->changed['mobile'] || $this->changed['mobile_pub']) {
-            require_once('profil.func.inc.php');
-            $fmt_phone  = format_phone_number($this->values['mobile']);
-            XDB::execute("DELETE FROM profile_phones
-                                WHERE uid = {?} AND link_type = 'user'",
-                         S::v('uid'));
-            if ($fmt_phone != '') {
-                XDB::execute("INSERT INTO profile_phones (uid, link_type, link_id, tel_id, tel_type, search_tel, display_tel, pub)
-                                   VALUES ({?}, 'user', '0', '0', 'mobile', {?}, {?}, {?})",
-                             S::v('uid'), $fmt_phone, $this->values['mobile'], $this->values['mobile_pub']);
-            }
-        }
         if ($this->changed['nick']) {
             require_once('user.func.inc.php');
             user_reindex(S::v('uid'));
index ef5abff..652181d 100644 (file)
@@ -25,7 +25,6 @@ class ProfileJob extends ProfileGeoloc
     private $mail_new;
     private $mail;
     private $web;
-    private $tel;
     private $bool;
     private $checks;
 
@@ -36,16 +35,14 @@ class ProfileJob extends ProfileGeoloc
                     = $this->mail_new
                     = new ProfileEmail();
         $this->web  = new ProfileWeb();
-        $this->tel  = new ProfileTel();
         $this->bool = new ProfileBool();
         $this->checks = array('web' => array('web'),
                               'mail_new' => array('email_new'),
                               'mail' => array('email'),
-                              'tel' => array('tel', 'fax', 'mobile'),
-                              'pub' => array('pub', 'tel_pub', 'email_pub'));
+                              'pub' => array('pub', 'email_pub'));
     }
 
-    private function cleanJob(ProfilePage &$page, array &$job, &$success)
+    private function cleanJob(ProfilePage &$page,$jobid, array &$job, &$success)
     {
         $success = true;
         foreach ($this->checks as $obj=>&$fields) {
@@ -66,6 +63,11 @@ class ProfileJob extends ProfileGeoloc
         }
         $job['adr']['pub'] = $this->pub->value($page, 'adr_pub', @$job['adr']['pub'], $s);
         $job['adr']['checked'] = $this->bool->value($page, 'adr_checked', @$job['adr']['checked'], $s);
+        if (!isset($job['tel'])) {
+            $job['tel'] = array();
+        }
+        $profiletel = new ProfilePhones('pro', $jobid);
+        $job['tel'] = $profiletel->value($page, 'tel', $job['tel'], $s);
         unset($job['removed']);
         unset($job['new']);
         unset($job['adr']['changed']);
@@ -90,7 +92,7 @@ class ProfileJob extends ProfileGeoloc
             $ls = true;
             $this->geolocAddress($job['adr'], $s);
             $ls = ($ls && $s);
-            $this->cleanJob($page, $job, $s);
+            $this->cleanJob($page, $key, $job, $s);
             $ls = ($ls && $s);
             if (!$init) {
                 $success = ($success && $ls);
@@ -109,11 +111,10 @@ class ProfileJob extends ProfileGeoloc
                             WHERE  uid = {?} AND link_type = 'pro'",
                      S::i('uid'));
         $i = 0;
-        foreach ($value as &$job) {
+        foreach ($value as $jobid=>&$job) {
             if ($job['email'] == "new@new.new") {
                 $job['email'] = $job['email_new'];
             }
-
             XDB::execute("INSERT INTO  entreprises (uid, entrid, entreprise, secteur, ss_secteur,
                                                     fonction, poste, adr1, adr2, adr3, postcode,
                                                     city, cityid, country, region, regiontxt,
@@ -135,27 +136,8 @@ class ProfileJob extends ProfileGeoloc
                          $job['pub'], $job['adr']['pub'], $job['email_pub'],
                          $job['adr']['checked'] ? 'geoloc' : '', $job['adr']['precise_lat'],
                          $job['adr']['precise_lon']);
-            if ($job['tel'] != '') {
-                XDB::execute("INSERT INTO  profile_phones (uid, link_type, link_id, tel_id,
-                                                      tel_type, search_tel, display_tel, pub)
-                                   VALUES  ({?}, 'pro', {?}, 0,
-                                            'fixed', {?}, {?}, {?})",
-                             S::i('uid'), $i, format_phone_number($job['tel']), $job['tel'], $job['tel_pub']);
-            }
-            if ($job['fax'] != '') {
-                XDB::execute("INSERT INTO  profile_phones (uid, link_type, link_id, tel_id,
-                                                      tel_type, search_tel, display_tel, pub)
-                                   VALUES  ({?}, 'pro', {?}, 1,
-                                            'fax', {?}, {?}, {?})",
-                             S::i('uid'), $i, format_phone_number($job['fax']), $job['fax'], $job['tel_pub']);
-            }
-            if ($job['mobile'] != '') {
-                XDB::execute("INSERT INTO  profile_phones (uid, link_type, link_id, tel_id,
-                                                      tel_type, search_tel, display_tel, pub)
-                                   VALUES  ({?}, 'pro', {?}, 2,
-                                            'mobile', {?}, {?}, {?})",
-                             S::i('uid'), $i, format_phone_number($job['mobile']), $job['mobile'], $job['tel_pub']);
-            }
+            $profiletel = new ProfilePhones('pro', $jobid);
+            $profiletel->saveTels('tel', $job['tel']);
             $i++;
         }
     }
@@ -183,31 +165,27 @@ class ProfileJobs extends ProfilePage
         $this->values['cv'] = $res->fetchOneCell();
 
         // Build the jobs tree
-        $res = XDB::iterRow("SELECT  e.entreprise, e.secteur, e.ss_secteur,
+        $res = XDB::iterRow("SELECT  e.entrid, e.entreprise, e.secteur, e.ss_secteur,
                                      e.fonction, e.poste, e.adr1, e.adr2, e.adr3,
                                      e.postcode, e.city, e.cityid, e.region, e.regiontxt,
                                      e.country, gp.pays, gp.display,
                                      FIND_IN_SET('geoloc', flags),
                                      e.email, e.web, e.pub,
                                      e.adr_pub, e.email_pub,
-                                     e.glat AS precise_lat, e.glng AS precise_lon,
-                                     tt.display_tel AS tel, tt.pub AS tel_pub,
-                                     tf.display_tel AS fax, tm.display_tel AS mobile
+                                     e.glat AS precise_lat, e.glng AS precise_lon
                                FROM  entreprises AS e
                           LEFT JOIN  geoloc_pays AS gp ON(gp.a2 = e.country)
-                          LEFT JOIN  profile_phones AS tt ON(tt.uid = e.uid AND tt.link_type = 'pro' AND tt.link_id = entrid AND tt.tel_id = 0)
-                          LEFT JOIN  profile_phones AS tf ON(tf.uid = e.uid AND tf.link_type = 'pro' AND tf.link_id = entrid AND tf.tel_id = 1)
-                          LEFT JOIN  profile_phones AS tm ON(tm.uid = e.uid AND tm.link_type = 'pro' AND tm.link_id = entrid AND tm.tel_id = 2)
                               WHERE  e.uid = {?} AND entreprise != ''
                            ORDER BY  entrid", S::i('uid'));
         $this->values['jobs'] = array();
-        while (list($name, $secteur, $ss_secteur, $fonction, $poste,
+        while (list($id, $name, $secteur, $ss_secteur, $fonction, $poste,
                     $adr1, $adr2, $adr3, $postcode, $city, $cityid,
                     $region, $regiontxt, $country, $countrytxt, $display,
                     $checked, $email, $web,
-                    $pub, $adr_pub, $email_pub, $glat, $glng,
-                    $tel, $tel_pub, $fax, $mobile) = $res->next()) {
-            $this->values['jobs'][] = array('name'       => $name,
+                    $pub, $adr_pub, $email_pub, $glat, $glng
+                   ) = $res->next()) {
+            $this->values['jobs'][] = array('id'         => $id,
+                                            'name'       => $name,
                                             'secteur'    => $secteur,
                                             'ss_secteur' => $ss_secteur,
                                             'fonction'   => $fonction,
@@ -227,15 +205,42 @@ class ProfileJobs extends ProfilePage
                                                                   'checked'    => $checked,
                                                                   'precise_lat'=> $glat,
                                                                   'precise_lon'=> $glng),
-                                            'tel'        => $tel,
-                                            'fax'        => $fax,
-                                            'mobile'     => $mobile,
                                             'email'      => $email,
                                             'web'        => $web,
                                             'pub'        => $pub,
-                                            'tel_pub'    => $tel_pub,
                                             'email_pub'  => $email_pub);
         }
+
+        $res = XDB::iterator("SELECT  link_id AS jobid, tel_type AS type, pub, display_tel AS tel, comment
+                                FROM  profile_phones
+                               WHERE  uid = {?} AND link_type = 'pro'
+                            ORDER BY  link_id",
+                             S::i('uid'));
+        $i = 0;
+        $jobNb = count($this->values['jobs']);
+        while ($tel = $res->next()) {
+            $jobid = $tel['jobid'];
+            unset($tel['jobid']);
+            while ($i < $jobNb && $this->values['jobs'][$i]['id'] < $jobid) {
+                $i++;
+            }
+            if ($i >= $jobNb) {
+                break;
+            }
+            $job =& $this->values['jobs'][$i];
+            if (!isset($job['tel'])) {
+                $job['tel'] = array();
+            }
+            if ($job['id'] == $jobid) {
+                $job['tel'][] = $tel;
+            }
+        }
+        foreach ($this->values['jobs'] as $id=>&$job) {
+            if (!isset($job['tel'])) {
+                $job['tel'] = array();
+            }
+            unset($job['id']);
+        }
     }
 
     protected function _saveData()
index 64ba191..7b9de17 100644 (file)
@@ -120,6 +120,81 @@ class ProfileTel extends ProfileNoSave
     }
 }
 
+class ProfilePhones implements ProfileSetting
+{
+    private $tel;
+    private $pub;
+    protected $link_type;
+    protected $link_id;
+
+    public function __construct($type, $id)
+    {
+        $this->tel = new ProfileTel();
+        $this->pub = new ProfilePub();
+        $this->link_type = $type;
+        $this->link_id = $id;
+    }
+
+    public function value(ProfilePage &$page, $field, $value, &$success)
+    {
+        $success = true;
+        if (is_null($value)) {
+            $value = isset($page->values[$field]) ? $page->values[$field] : array();
+        }
+        if (!is_array($value)) {
+            $value = array();
+        }
+        foreach ($value as $key=>&$phone) {
+            if (@$phone['removed']) {
+                unset($value[$key]);
+            } else {
+                $phone['pub'] = $this->pub->value($page, 'pub', $phone['pub'], $s);
+                $phone['tel'] = $this->tel->value($page, 'tel', $phone['tel'], $s);
+                if(!isset($phone['type']) || ($phone['type'] != 'fixed' && $phone['type'] != 'mobile' && $phone['type'] != 'fax')) {
+                    $phone['type'] = 'fixed';
+                    $s = false;
+                }
+                if (!$s) {
+                    $phone['error'] = true;
+                    $success = false;
+                }
+                if (!isset($phone['comment'])) {
+                    $phone['comment'] = '';
+                }
+            }
+        }
+        return $value;
+    }
+
+    private function saveTel($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  ({?}, {?}, {?}, {?}, {?},
+                                       {?}, {?}, {?}, {?})",
+                         S::i('uid'), $this->link_type, $this->link_id, $telid, $phone['type'],
+                        format_phone_number($phone['tel']), $phone['tel'], $phone['pub'], $phone['comment']);
+        }
+    }
+
+    public function save(ProfilePage &$page, $field, $value)
+    {
+        XDB::execute("DELETE FROM  profile_phones
+                            WHERE  uid = {?} AND link_type = {?} AND link_id = {?}",
+                            S::i('uid'), $this->link_type, $this->link_id);
+        $this->saveTels($field, $value);
+    }
+
+    //Only saves phones without a delete operation
+    public function saveTels($field, $value)
+    {
+        foreach ($value as $telid=>&$phone) {
+            $this->saveTel($telid, $phone);
+        }
+    }
+}
+
 class ProfilePub extends ProfileNoSave
 {
     public function value(ProfilePage &$page, $field, $value, &$success)
index 6a632ad..c699589 100644 (file)
@@ -40,11 +40,9 @@ function smarty_function_display_address($param, &$smarty)
 {
     require_once('geoloc.inc.php');
     $txtad = get_address_text($param['adr']);
-    if (!$txtad &&
-        !$param['adr']['tels'] && !count($param['adr']['tels']) &&
-        !$param['adr']['tel'] &&
-        !$param['adr']['fax'] &&
-        !$param['adr']['mobile']) return "";
+    if (!$txtad && !$param['adr']['tels'] && !count($param['adr']['tels'])) {
+        return "";
+    }
 
     $lines = explode("\n", $txtad);
     $idt   = array_shift($lines);
@@ -88,29 +86,9 @@ function smarty_function_display_address($param, &$smarty)
     {
         $txthtml .= "<strong>".$line."</strong><br/>\n";
     }
-    if ($param['adr']['tel'])
-        $txthtml .= "<div>\n<em>Tél : </em>\n<strong>".$param['adr']['tel']."</strong>\n</div>\n";
-    if ($param['adr']['fax'])
-        $txthtml .= "<div>\n<em>Fax : </em>\n<strong>".$param['adr']['fax']."</strong>\n</div>\n";
-    if ($param['adr']['mobile'])
-        $txthtml .= "<div>\n<em>Mob : </em>\n<strong>".$param['adr']['mobile']."</strong>\n</div>\n";
-    if ($param['adr']['tels'] && count($param['adr']['tels'])) {
-        foreach ($param['adr']['tels'] as $tel) {
-            switch ($tel['tel_type']) {
-            case 'fixed':
-                $tel_type = 'Tél';
-                break;
-            case 'fax':
-                $tel_type = 'Fax';
-                break;
-            case 'mobile':
-                $tel_type = 'Mob';
-                break;
-            default:
-                $tel_type = $tel['tel_type'];
-            }
-            $txthtml .= "<div>\n<em>" . $tel_type . "&nbsp;: </em>\n<strong>" . $tel['tel'] . "</strong>\n</div>\n";
-        }
+    if(isset($param['adr']['tels'])) {
+        require_once('function.display_phones.php');
+        $txthtml .= smarty_function_display_phones($param['adr'],$smarty);
     }
     if (!$param['nodiv']) {
         $pos = $param['pos'] ? " style='float: " . $param['pos'] . "'" : '';
diff --git a/plugins/function.display_phones.php b/plugins/function.display_phones.php
new file mode 100644 (file)
index 0000000..db21384
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2008 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************/
+
+function smarty_function_display_phones($param, &$smarty)
+{
+    $txthtml = "";
+    if (count($param['tels'])) {
+        foreach ($param['tels'] as $tel) {
+            switch ($tel['tel_type']) {
+            case 'fixed':
+                $tel_type = 'Tél';
+                break;
+            case 'fax':
+                $tel_type = 'Fax';
+                break;
+            case 'mobile':
+                $tel_type = 'Mob';
+                break;
+            default:
+                $tel_type = $tel['tel_type'];
+            }
+            $txthtml .= "<div>\n<em>" . $tel_type . "&nbsp;: </em>\n<strong>" . $tel['tel'] . "</strong>\n";
+            $comment = "";
+            if ($tel['comment'] != "") {
+                $commentHtml = str_replace(array('&', '"'), array('&amp;', '&quot;'), $tel['comment']);
+                $commentJs = str_replace(array('\\', '\''), array('\\\\', '\\\''), $commentHtml);
+                $txthtml .= "<img style=\"margin-left: 5px;\" src=\"images/icons/comments.gif\""
+                            . " onmouseover=\"return overlib('"
+                            . $commentJs
+                            . "',WIDTH,250);\""
+                            . " onmouseout=\"nd();\""
+                            . " alt=\"Commentaire\" title=\""
+                            . $commentHtml
+                            . "\"/>\n";
+            }
+            $txthtml .= "</div>\n";
+        }
+    }
+    return $txthtml;
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
index 53c720c..8faa8e3 100644 (file)
@@ -40,8 +40,10 @@ EMAIL;TYPE=internet:{$vcard.forlife}@{#globals.mail.domain2#}
 {if $vcard.virtualalias}
 EMAIL;TYPE=internet:{$vcard.virtualalias}
 {/if}
-{if $vcard.mobile}
-TEL;TYPE=cell:{$vcard.mobile|vcard_enc}
+{if $vcard.tels}
+{foreach item=tel from=$vcard.tels}
+{if $tel.tel_type eq 'mobile'}TEL;TYPE=cell{else}{if $tel.tel_type eq 'fax'}FAX{else}TEL{/if};TYPE=home{/if}:{$tel.tel|vcard_enc}
+{/foreach}
 {/if}
 {if $vcard.adr_pro}
 {if $vcard.adr_pro[0].entreprise}
@@ -53,21 +55,20 @@ TITLE:{$vcard.adr_pro[0].poste|vcard_enc}
 {if $vcard.adr_pro[0].fonction}
 ROLE:{$vcard.adr_pro[0].fonction|vcard_enc}
 {/if}
-{if $vcard.adr_pro[0].tel}
-TEL;TYPE=work:{$vcard.adr_pro[0].tel|vcard_enc}
-{/if}
-{if $vcard.adr_pro[0].fax}
-FAX;TYPE=work:{$vcard.adr_pro[0].fax|vcard_enc}
+{if $vcard.adr_pro[0].tels}
+{foreach item=tel from=$vcard.adr_pro[0].tels}
+{if $tel.tel_type eq 'mobile'}TEL;TYPE=cell,work{else}{if $tel.tel_type eq 'fax'}FAX{else}TEL{/if};TYPE=work{/if}:{$tel.tel|vcard_enc}
+{/foreach}
 {/if}
 ADR;TYPE=work:{format_adr adr=$vcard.adr_pro[0]}
 {/if}
 {foreach item=adr from=$vcard.adr}
 ADR;TYPE=home{if $adr.courier},postal{/if}:{format_adr adr=$adr}
+{if $adr.tels}
 {foreach item=tel from=$adr.tels}
-{if $tel.tel}
-{if $tel.tel_type neq 'fax'}TEL{else}FAX{/if};TYPE=home:{$tel.tel}
-{/if}
+{if $tel.tel_type eq 'mobile'}TEL;TYPE=cell,home{else}{if $tel.tel_type eq 'fax'}FAX{else}TEL{/if};TYPE=home{/if}:{$tel.tel|vcard_enc}
 {/foreach}
+{/if}
 {/foreach}
 {foreach from=$vcard.networking item=nw}
 {if $nw.filter eq 'web'}
index 46d9dec..a778d8d 100644 (file)
   <tr class="pair">
     <td>
       {foreach from=$adr.tel key=t item=tel}
-      <div id="{"`$adid`_tel_`$t`"}" style="clear: both">
-      {include file="profile/adresses.tel.tpl" t=$t tel=$tel}
-      </div>
+        <div id="{"`$adid`_tel_`$t`"}" style="clear: both">
+          {include file="profile/phone.tpl" prefname="`$adpref`[tel]" prefid="`$adid`_tel" telid=$t tel=$tel}
+        </div>
       {/foreach}
       {if $adr.tel|@count eq 0}
-      <div id="{"`$adid`_tel_0"}" style="clear: both">
-      {include file="profile/adresses.tel.tpl" t=0 tel=0}
-      </div>
+        <div id="{"`$adid`_tel_0"}" style="clear: both">
+          {include file="profile/phone.tpl" prefname="`$adpref`[tel]" prefid="`$adid`_tel" telid=0 tel=0}
+        </div>
       {/if}
-      <div id="{$adid}_add_tel" class="center" style="clear: both">
-        <a href="javascript:addTel({$i})">
+      <div id="{$adid}_tel_add" class="center" style="clear: both; padding-top: 4px">
+        <a href="javascript:addTel('{$adid}_tel', '{$adpref}[tel]')">
           {icon name=add title="Ajouter un numéro de téléphone"} Ajouter un numéro de téléphone
         </a>
       </div>
index 9eebac8..ab8b2d7 100644 (file)
     </th>
   </tr>
   <tr>
-    <td>
-      <span class="titre">Téléphone mobile</span>
+    <td colspan="2">
+      <span class="titre">Téléphones personnels</span>
     </td>
-    <td>
-      <input type="text" size="18" maxlength="18" name="mobile"
-             {if $errors.mobile}class="error"{/if} value="{$mobile}" />
-      <span class="flags">
-        {include file="include/flags.radio.tpl" name="mobile_pub" val=$mobile_pub}
-      </span>
+  </tr>
+  <tr>
+    <td colspan="2">
+      {foreach from=$tels key=telid item=tel}
+        <div id="tels_{$telid}" style="clear: both; padding-top: 4px; padding-bottom: 4px">
+          {include file="profile/phone.tpl" prefname='tels' prefid='tels' telid=$telid tel=$tel}
+        </div>
+      {/foreach}
+      {if $tels|@count eq 0}
+        <div id="tels_0" style="clear: both; padding-top: 4px; padding-bottom: 4px">
+          {include file="profile/phone.tpl" prefname='tels' preid='tels' telid=0 tel=0}
+        </div>
+      {/if}
+      <div id="tels_add" class="center" style="clear: both; padding-top: 4px;">
+        <a href="javascript:addTel('tels', 'tels');">
+          {icon name=add title="Ajouter un téléphone"}Ajouter un téléphone
+        </a>
+      </div>
     </td>
   </tr>
   {if $email_error}
index 4f7813b..9d5e890 100644 (file)
             {include file="geoloc/form.address.tpl" name="`$jobpref`[adr]" id="`$jobid`_adr" adr=$job.adr}
           </div>
         </div>
-        <div style="float: right; width: 50%">
-          <div class="titre">Téléphone</div>
-          <div class="flags">
-            {include file="include/flags.radio.tpl" name="`$jobpref`[tel_pub]" val=$job.tel_pub}
+      </td>
+    </tr>
+    <tr class="pair">
+      <td colspan="2">
+        {foreach from=$job.tel key=t item=tel}
+          <div id="{"`$jobid`_tel_`$t`"}" style="clear: both">
+            {include file="profile/phone.tpl" prefname="`$jobpref`[tel]" prefid="`$jobid`_tel" telid=$t tel=$tel}
+          </div>
+        {/foreach}
+        {if $job.tel|@count eq 0}
+          <div id="{"`$jobid`_tel_0"}" style="clear: both">
+            {include file="profile/phone.tpl" prefname="`$jobpref`[tel]" prefid="`$jobid`_tel" telid=0 tel=0}
           </div>
-          <table style="clear: both">
-            <tr>
-              <td>Bureau&nbsp;:</td>
-              <td>
-                <input type="text" size="18" maxlength="18" {if $job.tel_error}class="error"{/if}
-                       name="{$jobpref}[tel]" value="{$job.tel}" />
-              </td>
-            </tr>
-            <tr>
-              <td>Fax&nbsp;:</td>
-              <td>
-                <input type="text" size="18" maxlength="18" {if $job.fax_error}class="error"{/if}
-                       name="{$jobpref}[fax]" value="{$job.fax}" /></td>
-            </tr>
-            <tr>
-              <td>Mobile&nbsp;:</td>
-              <td>
-                <input type="text" size="18" maxlength="18" {if $job.mobile_error}class="error"{/if}
-                       name="{$jobpref}[mobile]" value="{$job.mobile}" />
-              </td>
-            </tr>
-          </table>
+        {/if}
+        <div id="{$jobid}_tel_add" class="center" style="clear: both; padding-top: 4px;">
+          <a href="javascript:addTel('{$jobid}_tel', '{$jobpref}[tel]')">
+            {icon name=add title="Ajouter un numéro de téléphone"} Ajouter un numéro de téléphone
+          </a>
         </div>
       </td>
     </tr>
similarity index 56%
rename from templates/profile/adresses.tel.tpl
rename to templates/profile/phone.tpl
index f9922dc..40715be 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-{assign var=telpref value="`$adpref`[tel][`$t`]"}
-{assign var=telid value="`$adid`_tel_`$t`"}
+{assign var=telpref value="`$prefname`[`$telid`]"}
+{assign var=id value="`$prefid`_`$telid`"}
+<div class="titre" style="float: left; width: 2.5em">N°{$telid+1}</div>
+<div style="float: left;">
+  <select name="{$telpref}[type]">
+    <option value="fixed"{if $tel.type eq 'fixed'} selected="selected"{/if}>Fixe</option>
+    <option value="mobile"{if $tel.type eq 'mobile'} selected="selected"{/if}>Mobile</option>
+    <option value="fax"{if $tel.type eq 'fax'} selected="selected"{/if}>Fax</option>
+  </select>
+  <input type="hidden" name="{$telpref}[removed]" value="0"/>
+  <input type="text" size="19" maxlength="28" name="{$telpref}[tel]" {if $tel.error}class="error"{/if} value="{$tel.tel}" />
+  <a href="javascript:removeTel('{$id}')">
+    {icon name=cross title="Supprimer ce numéro de téléphone"}
+  </a>
+  <a id="{$id}_addComment" href="javascript:addPhoneComment('{$id}', '{$telpref}')" {if $tel.comment neq ''}style="display:none" {/if}>
+    {icon name=comments title="Ajouter un commentaire"}
+  </a>
+</div>
 <div style="float: right" class="flags">
   {include file="include/flags.radio.tpl" name="`$telpref`[pub]" val=$tel.pub}
 </div>
-<span class="titre">N°{$t+1}</span>
-<input type="hidden" name="{$telpref}[removed]" value="0" />
-<select name="{$telpref}[type]">
-  <option value="fixed"{if $tel.type eq 'fixed'} selected="selected"{/if}>Fixe</option>
-  <option value="mobile"{if $tel.type eq 'mobile'} selected="selected"{/if}>Mobile</option>
-  <option value="fax"{if $tel.type eq 'fax'} selected="selected"{/if}>Fax</option>
-</select>
-<input type="text" size="19" maxlength="28" name="{$telpref}[tel]" {if $tel.error}class="error"{/if} value="{$tel.tel}" />
-<a href="javascript:removeObject('{$telid}', '{$telpref}')">
-  {icon name=cross title="Supprimer ce numéro de téléphone"}
-</a>
-
+<div id="{$id}_comment" style="clear: both;{if $tel.comment eq ''} display:none{/if}">
+  Commentaire :
+  <input type="text" size="45" maxlength="80" name="{$telpref}[comment]" {if $tel.error}class="error"{/if} value="{$tel.comment}"/>
+  <a href="javascript:removePhoneComment('{$id}', '{$telpref}')">
+    {icon name=cross title="Supprimer le commentaire"}
+  </a>
+</div>
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index a9fd049..8b8aeee 100644 (file)
@@ -101,7 +101,7 @@ function chgMainWinLoc(strPage)
       le {$x.date|date_format}
     </div>
     {/if}
-    {if $logged || $x.mobile}
+    {if $logged || $x.tels}
     <div class="contact">
       {if $logged}
       <div class='email'>
@@ -124,10 +124,8 @@ function chgMainWinLoc(strPage)
         {/if}
       </div>
       {/if}
-      {if $x.mobile}
-      <div class="mob">
-        <em class="intitule">Mobile&nbsp;: </em>{$x.mobile}
-      </div>
+      {if $x.tels}
+        {display_phones tels=$x.tels}
       {/if}
       <div class='spacer'></div>
     </div>
index aa27a27..f415a79 100644 (file)
@@ -7,6 +7,7 @@ CREATE TABLE IF NOT EXISTS `profile_phones` (
     `search_tel` varchar(25) NOT NULL COMMENT 'search number in an international format with only digits and the initial +',
     `display_tel` varchar(30) NOT NULL COMMENT 'display number',
     `pub` enum('private', 'ax', 'public') NOT NULL DEFAULT 'private',
+    `comment` varchar(80) NOT NULL,
     PRIMARY KEY(`uid`, `link_type`, `link_id`, `tel_id`),
     INDEX (`search_tel`)
 );