From 8450c2aaa78121cc9385c670e78b3cc12c7f7f02 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Mon, 21 Jul 2008 01:13:34 +0200 Subject: [PATCH] Adds the possibility to fill in multiple nationalities. --- htdocs/javascript/profile.js | 18 +++++++++++++++++ modules/profile/general.inc.php | 30 +++++++++++++++++++++++------ plugins/function.select_nat.php | 19 ++++++++++-------- templates/profile/general.tpl | 21 +++++++++++++++++++- upgrade/fusionax-0.0.1/05_nationalities.sql | 11 +++++++++++ 5 files changed, 84 insertions(+), 15 deletions(-) create mode 100644 upgrade/fusionax-0.0.1/05_nationalities.sql diff --git a/htdocs/javascript/profile.js b/htdocs/javascript/profile.js index d625bfb..dafdeae 100644 --- a/htdocs/javascript/profile.js +++ b/htdocs/javascript/profile.js @@ -110,6 +110,24 @@ function removeSearchName(i) } } +function delNationality(i) +{ + $('#nationalite' + i).hide().find('select').val(''); +} + +function addNationality() +{ + var i = 0; + if ($('#nationalite2').find('select').val() == "") { + i = 2; + } else if ($('#nationalite3').find('select').val() == "") { + i = 3; + } + if ((i == 2) || (i == 3)) { + $('#nationalite' + i).show(); + } +} + function addNetworking() { var i = 0; diff --git a/modules/profile/general.inc.php b/modules/profile/general.inc.php index 8eb098e..aa0fe1c 100644 --- a/modules/profile/general.inc.php +++ b/modules/profile/general.inc.php @@ -236,6 +236,8 @@ class ProfileGeneral extends ProfilePage = new ProfilePub(); $this->settings['freetext'] = $this->settings['nationalite'] + = $this->settings['nationalite2'] + = $this->settings['nationalite3'] = $this->settings['nick'] = $this->settings['yourself'] = $this->settings['display_name'] @@ -255,13 +257,15 @@ class ProfileGeneral extends ProfilePage = new ProfileAppli(); $this->watched= array('nom' => true, 'freetext' => true, 'tels' => true, 'networking' => true, 'appli1' => true, 'appli2' => true, - 'nationalite' => true, 'nick' => true); + 'nationalite' => true, 'nationalite2' => true, + 'nationalite3' => true, 'nick' => true); } protected function _fetchData() { // Checkout all data... - $res = XDB::query("SELECT u.promo, u.promo_sortie, u.nom_usage, u.nationalite, u.naissance, + $res = XDB::query("SELECT u.promo, u.promo_sortie, u.nom_usage, u.nationalite, + u.nationalite2, u.nationalite3, u.naissance, 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, @@ -321,12 +325,26 @@ class ProfileGeneral extends ProfilePage protected function _saveData() { - if ($this->changed['nationalite'] || $this->changed['nom'] || $this->changed['prenom'] - || $this->changed['naissance']) { + 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->values['nationalite2'] == "") { + $this->values['nationalite2'] = $this->values['nationalite3']; + $this->values['nationalite3'] = NULL; + } + if ($this->values['nationalite'] == "") { + $this->values['nationalite'] = $this->values['nationalite2']; + $this->values['nationalite2'] = $this->values['nationalite3']; + $this->values['nationalite3'] = NULL; + } + XDB::execute("UPDATE auth_user_md5 - SET nationalite = {?}, nom={?}, prenom={?}, naissance={?} + SET nationalite = {?}, nationalite2 = {?}, nationalite3 = {?}, nom={?}, prenom={?}, naissance={?} WHERE user_id = {?}", - $this->values['nationalite'], $this->values['nom'], $this->values['prenom'], + $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')); } diff --git a/plugins/function.select_nat.php b/plugins/function.select_nat.php index bc0401c..60a9a8e 100644 --- a/plugins/function.select_nat.php +++ b/plugins/function.select_nat.php @@ -20,7 +20,7 @@ ***************************************************************************/ -function select_nat($valeur,$pad=false) { +function select_nat($valeur, $pad=false) { $sql = "SELECT a2 AS id,IF(nat='',pays,nat) AS text FROM geoloc_pays ORDER BY text"; $res = XDB::iterRow($sql); $sel = ' selected="selected"'; @@ -28,19 +28,22 @@ function select_nat($valeur,$pad=false) { // on ajoute une entree vide si $pad est vrai $html = ""; if ($pad) { - $html.= '\n"; + $html .= sprintf("\n", ($valeur ? $sel : "")); } - while (list($my_id,$my_text) = $res->next()) { - $html .= sprintf("\n",$my_id,($valeur==$my_id?$sel:""),$my_text); + while (list($my_id, $my_text) = $res->next()) { + $html .= sprintf("\n", $my_id, ($valeur==$my_id ? $sel : ""), $my_text); } + return $html; } function smarty_function_select_nat($params, &$smarty) { - if(empty($params['pad']) || !($params['pad'])) - $pad = false; - else - $pad = true; + if (empty($params['pad']) || !($params['pad'])) { + $pad = false; + } else { + $pad = true; + } + return select_nat($params['valeur'], $pad); } diff --git a/templates/profile/general.tpl b/templates/profile/general.tpl index b85bb41..f9ac3d6 100644 --- a/templates/profile/general.tpl +++ b/templates/profile/general.tpl @@ -79,8 +79,27 @@ + {icon name=add title="Ajouter une nationalité"} + + + + + + + {icon name=cross title="Supprimer cette nationalité"} + + + + + + + {icon name=cross title="Supprimer cette nationalité"} diff --git a/upgrade/fusionax-0.0.1/05_nationalities.sql b/upgrade/fusionax-0.0.1/05_nationalities.sql new file mode 100644 index 0000000..48fe5fd --- /dev/null +++ b/upgrade/fusionax-0.0.1/05_nationalities.sql @@ -0,0 +1,11 @@ +ALTER TABLE auth_user_md5 ADD COLUMN nationalite2 CHAR(2) DEFAULT NULL, + ADD COLUMN nationalite3 CHAR(2) DEFAULT NULL, + ADD KEY nationalite2 (nationalite2), + ADD KEY nationalite3 (nationalite3), + MODIFY nationalite CHAR(2) DEFAULT NULL; + +UPDATE auth_user_md5 SET nationalite=NULL WHERE nationalite="00" OR nationalite=''; + +DELETE FROM geoloc_pays WHERE a2="00"; + +# vim:set syntax=mysql: -- 2.1.4