Moving to GitHub.
[platal.git] / plugins / function.select_nat.php
index 917d9b0..dd4f512 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
  ***************************************************************************/
 
 
-function select_nat($valeur,$pad=false) {
-    $sql = "SELECT a2 AS id,IF(nat='',pays,nat) AS text FROM geoloc_pays WHERE nat IS NOT NULL ORDER BY text";
-    $res = XDB::iterRow($sql);
+function select_nat($valeur, $pad=false) {
+    $res = XDB::iterRow("SELECT  iso_3166_1_a2 AS id, nationality AS text
+                           FROM  geoloc_countries
+                          WHERE  nationality IS NOT NULL
+                       ORDER BY  nationality");
     $sel = ' selected="selected"';
 
     // on ajoute une entree vide si $pad est vrai
     $html = "";
     if ($pad) {
-       $html.= '<option value="0"'.($valeur==0?$sel:"")."></option>\n";
+             $html .= sprintf("<option value=\"\"%s>&nbsp;</option>\n", ($valeur ? $sel : ""));
     }
-    while (list($my_id,$my_text) = $res->next()) {
-       $html .= sprintf("<option value=\"%s\" %s>%s</option>\n",$my_id,($valeur==$my_id?$sel:""),$my_text);
+    while (list($my_id, $my_text) = $res->next()) {
+        $html .= sprintf("<option value=\"%s\"%s>%s</option>\n", $my_id, ($valeur==$my_id ? $sel : ""), $my_text?$my_text:"&nbsp;");
     }
+
     return $html;
 }
 
-function smarty_function_select_nat($params, &$smarty) {
-    if(empty($params['pad']) || !($params['pad']))
-       $pad = false;
-    else
-       $pad = true;
+function smarty_function_select_nat($params, $smarty) {
+    if (empty($params['pad']) || !($params['pad'])) {
+             $pad = false;
+    } else {
+             $pad = true;
+    }
+
     return select_nat($params['valeur'], $pad);
 }
 
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
 ?>