diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 161d3ae0e57..0893b28d76a 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -254,11 +254,15 @@ class Form
function select_country($selected='',$htmlname='pays_id',$htmloption='')
{
global $conf,$langs;
+
$langs->load("dict");
$out='';
+ $countryArray=array();
+ $code_iso=array();
+ $label=array();
- $sql = "SELECT rowid, code, libelle, active";
+ $sql = "SELECT rowid, code as code_iso, libelle as label";
$sql.= " FROM ".MAIN_DB_PREFIX."c_pays";
$sql.= " WHERE active = 1";
$sql.= " ORDER BY code ASC";
@@ -273,25 +277,30 @@ class Form
if ($num)
{
$foundselected=false;
- while ($i < $num)
- {
+
+ while ($i < $num) {
$obj = $this->db->fetch_object($resql);
- if ($selected && $selected != '-1' &&
- ($selected == $obj->rowid || $selected == $obj->code || $selected == $obj->libelle) )
- {
- $foundselected=true;
- $out.= '';
+ $countryArray[$i]['rowid'] = $obj->rowid;
+ $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:' '));
+ $code_iso[$i] = $countryArray[$i]['code_iso'];
+ $label[$i] = $countryArray[$i]['label'];
$i++;
}
+
+ array_multisort($label, SORT_ASC, $countryArray);
+
+ foreach ($countryArray as $row) {
+ if ($selected && $selected != '-1' && ($selected == $row['rowid'] || $selected == $row['code_iso'] || $selected == $row['label']) ) {
+ $foundselected=true;
+ $out.= '';
+ }
}
$out.= '';
}
@@ -2356,7 +2365,8 @@ class Form
} else {
$out.= '';
}
}