From bde2be3b1777bf1f66c6d2b2cdecc361d6191911 Mon Sep 17 00:00:00 2001 From: Guillaume Bandet Date: Wed, 25 Jun 2008 10:42:37 +0200 Subject: [PATCH] Adds a common template to add phone numbers in the different pages of the profile Improves the display of phone numbers in profile Adds a comment field for phone numbers --- htdocs/javascript/profile.js | 28 +++++-- include/profil.func.inc.php | 10 +-- include/user.func.inc.php | 63 +++++++-------- modules/profile.php | 11 ++- modules/profile/addresses.inc.php | 33 +++----- modules/profile/general.inc.php | 27 +++---- modules/profile/jobs.inc.php | 93 ++++++++++++----------- modules/profile/page.inc.php | 75 ++++++++++++++++++ plugins/function.display_address.php | 34 ++------- plugins/function.display_phones.php | 61 +++++++++++++++ templates/core/vcard.tpl | 21 ++--- templates/profile/adresses.address.tpl | 16 ++-- templates/profile/general.tpl | 28 +++++-- templates/profile/jobs.job.tpl | 43 +++++------ templates/profile/{adresses.tel.tpl => phone.tpl} | 39 ++++++---- templates/profile/profile.tpl | 8 +- upgrade/fusionax-0.0.1/03_telephone.sql | 1 + 17 files changed, 361 insertions(+), 230 deletions(-) create mode 100644 plugins/function.display_phones.php rename templates/profile/{adresses.tel.tpl => phone.tpl} (56%) diff --git a/htdocs/javascript/profile.js b/htdocs/javascript/profile.js index 4e16e29..d625bfb 100644 --- a/htdocs/javascript/profile.js +++ b/htdocs/javascript/profile.js @@ -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('
'); - Ajax.update_html(tel + i, 'profile/ajax/tel/' + id + '/' + i); + $('#' + prefix + 'add').before('
'); + 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 diff --git a/include/profil.func.inc.php b/include/profil.func.inc.php index 5e084be..24d5b7e 100644 --- a/include/profil.func.inc.php +++ b/include/profil.func.inc.php @@ -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(); } diff --git a/include/user.func.inc.php b/include/user.func.inc.php index 6ebfe8a..a12be69 100644 --- a/include/user.func.inc.php +++ b/include/user.func.inc.php @@ -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); diff --git a/modules/profile.php b/modules/profile.php index e3d86cd..c28ef27 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -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()); } diff --git a/modules/profile/addresses.inc.php b/modules/profile/addresses.inc.php index 6dfd2bb..ade256e 100644 --- a/modules/profile/addresses.inc.php +++ b/modules/profile/addresses.inc.php @@ -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", diff --git a/modules/profile/general.inc.php b/modules/profile/general.inc.php index 3c45445..8eb098e 100644 --- a/modules/profile/general.inc.php +++ b/modules/profile/general.inc.php @@ -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')); diff --git a/modules/profile/jobs.inc.php b/modules/profile/jobs.inc.php index ef5abff..652181d 100644 --- a/modules/profile/jobs.inc.php +++ b/modules/profile/jobs.inc.php @@ -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() diff --git a/modules/profile/page.inc.php b/modules/profile/page.inc.php index 64ba191..7b9de17 100644 --- a/modules/profile/page.inc.php +++ b/modules/profile/page.inc.php @@ -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) diff --git a/plugins/function.display_address.php b/plugins/function.display_address.php index 6a632ad..c699589 100644 --- a/plugins/function.display_address.php +++ b/plugins/function.display_address.php @@ -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 .= "".$line."
\n"; } - if ($param['adr']['tel']) - $txthtml .= "
\nTél : \n".$param['adr']['tel']."\n
\n"; - if ($param['adr']['fax']) - $txthtml .= "
\nFax : \n".$param['adr']['fax']."\n
\n"; - if ($param['adr']['mobile']) - $txthtml .= "
\nMob : \n".$param['adr']['mobile']."\n
\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 .= "
\n" . $tel_type . " : \n" . $tel['tel'] . "\n
\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 index 0000000..db21384 --- /dev/null +++ b/plugins/function.display_phones.php @@ -0,0 +1,61 @@ +\n" . $tel_type . " : \n" . $tel['tel'] . "\n"; + $comment = ""; + if ($tel['comment'] != "") { + $commentHtml = str_replace(array('&', '"'), array('&', '"'), $tel['comment']); + $commentJs = str_replace(array('\\', '\''), array('\\\\', '\\\''), $commentHtml); + $txthtml .= "\"Commentaire\"\n"; + } + $txthtml .= "\n"; + } + } + return $txthtml; +} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +?> diff --git a/templates/core/vcard.tpl b/templates/core/vcard.tpl index 53c720c..8faa8e3 100644 --- a/templates/core/vcard.tpl +++ b/templates/core/vcard.tpl @@ -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'} diff --git a/templates/profile/adresses.address.tpl b/templates/profile/adresses.address.tpl index 46d9dec..a778d8d 100644 --- a/templates/profile/adresses.address.tpl +++ b/templates/profile/adresses.address.tpl @@ -83,17 +83,17 @@ {foreach from=$adr.tel key=t item=tel} -
- {include file="profile/adresses.tel.tpl" t=$t tel=$tel} -
+
+ {include file="profile/phone.tpl" prefname="`$adpref`[tel]" prefid="`$adid`_tel" telid=$t tel=$tel} +
{/foreach} {if $adr.tel|@count eq 0} -
- {include file="profile/adresses.tel.tpl" t=0 tel=0} -
+
+ {include file="profile/phone.tpl" prefname="`$adpref`[tel]" prefid="`$adid`_tel" telid=0 tel=0} +
{/if} -
- + diff --git a/templates/profile/general.tpl b/templates/profile/general.tpl index 9eebac8..ab8b2d7 100644 --- a/templates/profile/general.tpl +++ b/templates/profile/general.tpl @@ -271,15 +271,27 @@ - - Téléphone mobile + + Téléphones personnels - - - - {include file="include/flags.radio.tpl" name="mobile_pub" val=$mobile_pub} - + + + + {foreach from=$tels key=telid item=tel} +
+ {include file="profile/phone.tpl" prefname='tels' prefid='tels' telid=$telid tel=$tel} +
+ {/foreach} + {if $tels|@count eq 0} +
+ {include file="profile/phone.tpl" prefname='tels' preid='tels' telid=0 tel=0} +
+ {/if} + {if $email_error} diff --git a/templates/profile/jobs.job.tpl b/templates/profile/jobs.job.tpl index 4f7813b..9d5e890 100644 --- a/templates/profile/jobs.job.tpl +++ b/templates/profile/jobs.job.tpl @@ -120,33 +120,24 @@ {include file="geoloc/form.address.tpl" name="`$jobpref`[adr]" id="`$jobid`_adr" adr=$job.adr}
-
-
Téléphone
-
- {include file="include/flags.radio.tpl" name="`$jobpref`[tel_pub]" val=$job.tel_pub} + + + + + {foreach from=$job.tel key=t item=tel} +
+ {include file="profile/phone.tpl" prefname="`$jobpref`[tel]" prefid="`$jobid`_tel" telid=$t tel=$tel} +
+ {/foreach} + {if $job.tel|@count eq 0} +
+ {include file="profile/phone.tpl" prefname="`$jobpref`[tel]" prefid="`$jobid`_tel" telid=0 tel=0}
- - - - - - - - - - - - - -
Bureau : - -
Fax : -
Mobile : - -
+ {/if} + diff --git a/templates/profile/adresses.tel.tpl b/templates/profile/phone.tpl similarity index 56% rename from templates/profile/adresses.tel.tpl rename to templates/profile/phone.tpl index f9922dc..40715be 100644 --- a/templates/profile/adresses.tel.tpl +++ b/templates/profile/phone.tpl @@ -20,21 +20,32 @@ {* *} {**************************************************************************} -{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`"} +
N°{$telid+1}
+
+ + + + + {icon name=cross title="Supprimer ce numéro de téléphone"} + + + {icon name=comments title="Ajouter un commentaire"} + +
{include file="include/flags.radio.tpl" name="`$telpref`[pub]" val=$tel.pub}
-N°{$t+1} - - - - - {icon name=cross title="Supprimer ce numéro de téléphone"} - - + {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/profile/profile.tpl b/templates/profile/profile.tpl index a9fd049..8b8aeee 100644 --- a/templates/profile/profile.tpl +++ b/templates/profile/profile.tpl @@ -101,7 +101,7 @@ function chgMainWinLoc(strPage) le {$x.date|date_format}
{/if} - {if $logged || $x.mobile} + {if $logged || $x.tels}
{if $logged} {/if} - {if $x.mobile} -
- Mobile : {$x.mobile} -
+ {if $x.tels} + {display_phones tels=$x.tels} {/if}
diff --git a/upgrade/fusionax-0.0.1/03_telephone.sql b/upgrade/fusionax-0.0.1/03_telephone.sql index aa27a27..f415a79 100644 --- a/upgrade/fusionax-0.0.1/03_telephone.sql +++ b/upgrade/fusionax-0.0.1/03_telephone.sql @@ -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`) ); -- 2.1.4