one table for the nationality is enough !
authorx2000habouzit <x2000habouzit>
Fri, 29 Oct 2004 01:24:20 +0000 (01:24 +0000)
committerx2000habouzit <x2000habouzit>
Fri, 29 Oct 2004 01:24:20 +0000 (01:24 +0000)
get rid of the old nationalites

htdocs/advanced_search.php
htdocs/fiche.php
htdocs/mescontacts.php
include/search.classes.inc.php
plugins/function.select_nat.php [new file with mode: 0644]
scripts/migration/0.9.2/nationalites.sql
templates/inscription/step2.tpl
templates/profil/general.tpl

index 170505a..71b24d8 100644 (file)
@@ -18,7 +18,7 @@
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: advanced_search.php,v 1.20 2004-10-24 14:21:30 x2000bedo Exp $
+        $Id: advanced_search.php,v 1.21 2004-10-29 01:24:20 x2000habouzit Exp $
  ***************************************************************************/
 
 require("auto.prepend.inc.php");
@@ -32,7 +32,7 @@ require_once("geoloc.inc.php");
 function form_prepare() {
     global $page,$globals;
     $page->assign('formulaire',1);
-    $sql = 'SELECT id,text FROM nationalites ORDER BY text';
+    $sql = 'SELECT a2 AS id,IF(nat=\'\',pays,nat) AS text FROM geoloc_pays ORDER BY text';
     $page->mysql_assign($sql,'choix_nationalites');
     $sql = 'SELECT id,text FROM binets_def ORDER BY text';
     $page->mysql_assign($sql,'choix_binets');
index 9a515ce..a9b96ce 100644 (file)
@@ -18,7 +18,7 @@
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: fiche.php,v 1.15 2004-10-27 18:02:29 x2000coic Exp $
+        $Id: fiche.php,v 1.16 2004-10-29 01:24:20 x2000habouzit Exp $
  ***************************************************************************/
 
 
@@ -43,15 +43,15 @@ if (isset($_REQUEST['user']))
 else
     $where_clause = " WHERE u.matricule = '{$_REQUEST['mat']}'";
 
-$reqsql = "SELECT  u.prenom, u.nom, u.epouse, nationalites.text,
+$reqsql = "SELECT  u.prenom, u.nom, u.epouse, IF(gp.nat='',gp.pays,gp.nat) AS text
                   u.user_id, a.alias, a2.alias, u.matricule, i.deces != 0 as dcd,
                   i.deces, u.date, u.cv, sections.text, u.mobile, u.web,
                   u.libre, u.promo, c.uid IS NOT NULL, p.x, p.y
             FROM  auth_user_md5 AS u
-       INNER JOIN  aliases       AS a ON (u.user_id=a.id AND a.type='a_vie')
+       INNER JOIN  aliases       AS a  ON (u.user_id=a.id AND a.type='a_vie')
        INNER JOIN  aliases       AS a2 ON (u.user_id=a2.id AND (a2.type='alias' OR a2.type='epouse') AND a2.alias LIKE '%.%')
-        LEFT JOIN  contacts      AS c ON (c.uid = {$_SESSION['uid']} and c.contact = u.user_id)
-       INNER JOIN  nationalites ON(nationalites.id = u.nationalite)
+        LEFT JOIN  contacts      AS c  ON (c.uid = {$_SESSION['uid']} and c.contact = u.user_id)
+       INNER JOIN  geoloc_pays   AS gp ON (gp.a2 = u.nationalite)
        INNER JOIN  sections ON(sections.id = u.section)
        INNER JOIN  identification AS i ON(u.matricule = i.matricule)
         LEFT JOIN  photo as p ON(p.uid = u.user_id)".$where_clause."
index cba0fb8..a6b71de 100644 (file)
@@ -18,7 +18,7 @@
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: mescontacts.php,v 1.19 2004-10-28 20:28:41 x2000habouzit Exp $
+        $Id: mescontacts.php,v 1.20 2004-10-29 01:24:20 x2000habouzit Exp $
  ***************************************************************************/
 
 require("auto.prepend.inc.php");
@@ -91,7 +91,7 @@ $sql = "SELECT contact AS id,
                a.*, l.alias AS forlife,
                i.deces != 0 AS dcd, i.deces, i.matricule_ax, FIND_IN_SET('femme', i.flags) AS sexe,
                e.entreprise, es.label AS secteur, ef.fonction_fr AS fonction,
-               n.text AS nat, n.iso3166,
+               IF(n.nat='',n.pays,n.nat) AS nat, n.a2 AS iso3166,
                ad0.text AS app0text, ad0.url AS app0url, ai0.type AS app0type,
                ad1.text AS app1text, ad1.url AS app1url, ai1.type AS app1type,
                adr.ville, gp.a2, gp.pays, gr.name AS region,
@@ -103,7 +103,7 @@ $sql = "SELECT contact AS id,
         LEFT  JOIN entreprises    AS e   ON (e.entrid = 0 AND e.uid = a.user_id)
         LEFT  JOIN emploi_secteur AS es  ON (e.secteur = es.id)
         LEFT  JOIN fonctions_def  AS ef  ON (e.fonction = ef.id)
-        LEFT  JOIN nationalites   AS n   ON (a.nationalite = n.id)
+        LEFT  JOIN geoloc_pays    AS n   ON (a.nationalite = n.a2)
         LEFT  JOIN applis_ins     AS ai0 ON (a.user_id = ai0.uid AND ai0.ordre = 0)
         LEFT  JOIN applis_def     AS ad0 ON (ad0.id = ai0.aid)
         LEFT  JOIN applis_ins     AS ai1 ON (a.user_id = ai1.uid AND ai1.ordre = 1)
index 9c5d561..ba2e116 100644 (file)
@@ -18,7 +18,7 @@
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: search.classes.inc.php,v 1.26 2004-10-28 12:20:59 x2000habouzit Exp $
+        $Id: search.classes.inc.php,v 1.27 2004-10-29 01:24:20 x2000habouzit Exp $
  ***************************************************************************/
 
 require_once("xorg.misc.inc.php");
@@ -33,7 +33,7 @@ $globals->search_result_fields = '
                 ad0.text AS app0text, ad0.url AS app0url, ai0.type AS app0type,
                 ad1.text AS app1text, ad1.url AS app1url, ai1.type AS app1type,
                 e.entreprise, es.label AS secteur, ef.fonction_fr AS fonction,
-                n.text AS nat, n.iso3166,
+                IF(n.nat=\'\',n.pays,n.nat) AS nat, n.a2 AS iso3166,
                 adr.ville, gp.pays, gr.name AS region,';
 $globals->search_result_where_statement = '
                 LEFT JOIN  applis_ins     AS ai0 ON (u.user_id = ai0.uid AND ai0.ordre = 0)
@@ -43,7 +43,7 @@ $globals->search_result_where_statement = '
                 LEFT JOIN  entreprises    AS e   ON (e.entrid = 0 AND e.uid = u.user_id)
                 LEFT JOIN  emploi_secteur AS es  ON (e.secteur = es.id)
                 LEFT JOIN  fonctions_def  AS ef  ON (e.fonction = ef.id)
-                LEFT JOIN  nationalites   AS n   ON (u.nationalite = n.id)
+                LEFT JOIN  geoloc_pays    AS n   ON (u.nationalite = n.a2)
                 LEFT JOIN  adresses       AS adr ON (u.user_id = adr.uid AND FIND_IN_SET(\'active\',adr.statut))
                 LEFT JOIN  geoloc_pays    AS gp  ON (adr.pays = gp.a2)
                 LEFT JOIN  geoloc_region  AS gr  ON (adr.pays = gr.a2 AND adr.region = gr.region)';
diff --git a/plugins/function.select_nat.php b/plugins/function.select_nat.php
new file mode 100644 (file)
index 0000000..8fd34e4
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2004 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                *
+ ***************************************************************************
+ $Id: function.select_nat.php,v 1.1 2004-10-29 01:24:21 x2000habouzit Exp $
+ ***************************************************************************/
+
+
+function select_nat($valeur,$pad=false) {
+    global $globals;
+    $sql = "SELECT a2 AS id,IF(nat='',pays,nat) AS text FROM geoloc_pays ORDER BY text";
+    $result = $globals->db->query($sql);
+
+    $sel = ' selected="selected"';
+
+    // on ajoute une entree vide si $pad est vrai
+    $html = "";
+    if ($pad)
+       $html.= '<option value="0"'.($valeur==0?$sel:"")."></option>\n";
+    while (list($my_id,$my_text) = mysql_fetch_row($result)) {
+       $html .= sprintf("<option value=\"%s\" %s>%s</option>\n",$my_id,($valeur==$my_id?$sel:""),$my_text);
+    }
+    mysql_free_result($result);
+    return $html;
+}
+
+function smarty_function_select_nat($params, &$smarty) {
+    if(empty($params['pad']) || !($params['pad']))
+       $pad = false;
+    else
+       $pad = true;
+    return select_nat($params['valeur'], $pad);
+}
+
+?>
index 17a5edf..395fab0 100644 (file)
@@ -22,6 +22,8 @@ replace INTO `nationalites` VALUES (18,'Canadien','CA');
 replace INTO `nationalites` VALUES (19,'Chilien','CL');
 replace INTO `nationalites` VALUES (20,'Chinois','CN');
 replace INTO `nationalites` VALUES (21,'Colombien','CO');
+replace INTO `nationalites` VALUES (22,'CorĂ©en','KR');
+replace INTO `nationalites` VALUES (86,'Costaricien','CR');
 replace INTO `nationalites` VALUES (80,'Croate','HR');
 replace INTO `nationalites` VALUES (23,'Cubain','CU');
 replace INTO `nationalites` VALUES (24,'Danois','DK');
@@ -83,3 +85,13 @@ replace INTO `nationalites` VALUES (77,'V
 replace INTO `nationalites` VALUES (78,'Vietnamien','VN');
 replace INTO `nationalites` VALUES (79,'Yougoslave','CS');
 
+alter table geoloc_pays add column nat varchar(100) not null;
+update geoloc_pays inner join nationalites ON iso3166=a2 set nat=text;
+update auth_user_md5 set nationalite='' where nationalite='0' or nationalite='36';
+alter table auth_user_md5 change column nationalite nationalite varchar(2) not null;
+update auth_user_md5        AS u
+    inner join nationalites AS n ON u.nationalite=n.id
+    inner join geoloc_pays  AS g ON iso3166=a2
+    set u.nationalite = a2;
+
+drop table nationalites;
index 1607010..07c5598 100644 (file)
@@ -17,7 +17,7 @@
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: step2.tpl,v 1.4 2004-10-24 14:41:13 x2000habouzit Exp $
+        $Id: step2.tpl,v 1.5 2004-10-29 01:24:21 x2000habouzit Exp $
  ***************************************************************************}
 
 
       </td>
       <td>
         <select name="nationalite">
-          {select_db_table table="nationalites" valeur=$smarty.request.nationalite}
+          {select_nat valeur=$smarty.request.nationalite}
         </select>
       </td>
     </tr>
index 9549734..7b6b856 100644 (file)
@@ -17,7 +17,7 @@
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: general.tpl,v 1.14 2004-10-09 05:57:48 x2000habouzit Exp $
+        $Id: general.tpl,v 1.15 2004-10-29 01:24:22 x2000habouzit Exp $
  ***************************************************************************}
 
 
@@ -70,7 +70,7 @@
       </td>
       <td class="cold">
         <select name="nationalite">
-          {select_db_table table="nationalites" valeur=$nationalite}
+          {select_nat valeur=$nationalite}
         </select>
       </td>
     </tr>