Fix order of countries

This commit is contained in:
Laurent Destailleur 2011-03-19 02:17:05 +00:00
parent 4f013c971a
commit cb6835eb19
3 changed files with 18 additions and 15 deletions

View File

@ -302,7 +302,7 @@ if ((isset($_GET["action"]) && $_GET["action"] == 'edit')
print '<tr '.$bc[$var].'><td class="fieldrequired">'.$langs->trans("Country").'</td><td>'; print '<tr '.$bc[$var].'><td class="fieldrequired">'.$langs->trans("Country").'</td><td>';
$pays_selected=$pays_id; $pays_selected=$pays_id;
//if (empty($pays_selected)) $pays_selected=substr($langs->defaultlang,-2); // Par defaut, pays de la localisation //if (empty($pays_selected)) $pays_selected=substr($langs->defaultlang,-2); // Par defaut, pays de la localisation
$form->select_pays($pays_selected,'pays_id'); print $form->select_country($pays_selected,'pays_id');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
print '</td></tr>'."\n"; print '</td></tr>'."\n";

View File

@ -248,6 +248,7 @@ class Form
* @param selected Id or Code or Label of preselected country * @param selected Id or Code or Label of preselected country
* @param htmlname Name of html select object * @param htmlname Name of html select object
* @param htmloption Options html on select object * @param htmloption Options html on select object
* @return string HTML string with select
*/ */
function select_country($selected='',$htmlname='pays_id',$htmloption='') function select_country($selected='',$htmlname='pays_id',$htmloption='')
{ {
@ -257,7 +258,7 @@ class Form
$out=''; $out='';
$countryArray=array(); $countryArray=array();
$code_iso=array(); //$code_iso=array();
$label=array(); $label=array();
$sql = "SELECT rowid, code as code_iso, libelle as label"; $sql = "SELECT rowid, code as code_iso, libelle as label";
@ -265,7 +266,7 @@ class Form
$sql.= " WHERE active = 1"; $sql.= " WHERE active = 1";
$sql.= " ORDER BY code ASC"; $sql.= " ORDER BY code ASC";
dol_syslog("Form::select_pays sql=".$sql); dol_syslog("Form::select_country sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -276,27 +277,29 @@ class Form
{ {
$foundselected=false; $foundselected=false;
while ($i < $num) { while ($i < $num)
{
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$countryArray[$i]['rowid'] = $obj->rowid; $countryArray[$i]['rowid'] = $obj->rowid;
$countryArray[$i]['code_iso'] = $obj->code_iso; $countryArray[$i]['code_iso'] = $obj->code_iso;
$countryArray[$i]['label'] = ($obj->code_iso && $langs->trans("Country".$obj->code_iso)!="Country".$obj->code_iso?$langs->trans("Country".$obj->code_iso):($obj->label!='-'?$obj->label:'&nbsp;')); $countryArray[$i]['label'] = ($obj->code_iso && $langs->trans("Country".$obj->code_iso)!="Country".$obj->code_iso?$langs->trans("Country".$obj->code_iso):($obj->label!='-'?$obj->label:''));
$code_iso[$i] = $countryArray[$i]['code_iso']; //$code_iso[$i] = $countryArray[$i]['code_iso'];
$label[$i] = $countryArray[$i]['label']; $label[$i] = $countryArray[$i]['label'];
$i++; $i++;
} }
array_multisort($label, SORT_ASC, $countryArray); array_multisort($label, SORT_ASC, $countryArray);
foreach ($countryArray as $row) { foreach ($countryArray as $row)
{
if ($selected && $selected != '-1' && ($selected == $row['rowid'] || $selected == $row['code_iso'] || $selected == $row['label']) ) { if ($selected && $selected != '-1' && ($selected == $row['rowid'] || $selected == $row['code_iso'] || $selected == $row['label']) ) {
$foundselected=true; $foundselected=true;
$out.= '<option value="'.$row['rowid'].'" selected="selected">'; $out.= '<option value="'.$row['rowid'].'" selected="selected">';
} else { } else {
$out.= '<option value="'.$row['rowid'].'">'; $out.= '<option value="'.$row['rowid'].'">';
} }
if ($row['code_iso']) $out.= $row['code_iso'] . ' - ';
$out.= $row['label']; $out.= $row['label'];
if ($row['code_iso']) $out.= ' ('.$row['code_iso'] . ')';
$out.= '</option>'; $out.= '</option>';
} }
} }

View File

@ -141,7 +141,7 @@ CountryLI=Liechtenstein
CountryLT=Lituanie CountryLT=Lituanie
CountryLU=Luxembourg CountryLU=Luxembourg
CountryMO=Macao CountryMO=Macao
CountryMK=ex-République yougoslave de Macédoine CountryMK=Macédoine (Ex-République yougoslave)
CountryMG=Madagascar CountryMG=Madagascar
CountryMW=Malawi CountryMW=Malawi
CountryMY=Malaisie CountryMY=Malaisie