diff --git a/htdocs/lib/company.lib.php b/htdocs/lib/company.lib.php index c3e04945f18..7a9cac9064a 100644 --- a/htdocs/lib/company.lib.php +++ b/htdocs/lib/company.lib.php @@ -23,7 +23,7 @@ * \file htdocs/lib/company.lib.php * \brief Ensemble de fonctions de base pour le module societe * \ingroup societe - * \version $Id: company.lib.php,v 1.125 2011/08/24 12:18:56 eldy Exp $ + * \version $Id: company.lib.php,v 1.126 2011/08/24 18:05:58 eldy Exp $ */ /** @@ -210,14 +210,19 @@ function societe_admin_prepare_head($object) /** * Return country label, code or id from an id or a code + * * @param id Id or code of country - * @param withcode 0=Return label, 1=Return code + label, 2=Return code from id, 3=Return id from code + * @param withcode '0'=Return label, + * '1'=Return code + label, + * '2'=Return code from id, + * '3'=Return id from code, + * 'all'=Return array('id'=>,'code'=>,'label'=>) * @param dbtouse Database handler (using in global way may fail because of conflicts with some autoload features) * @param outputlangs Langs object for output translation * @param entconv 0=Return value without entities and not converted to output charset * @return string String with country code or translated country name */ -function getCountry($id,$withcode=0,$dbtouse=0,$outputlangs='',$entconv=1) +function getCountry($id,$withcode='',$dbtouse=0,$outputlangs='',$entconv=1) { global $db,$langs; @@ -242,9 +247,10 @@ function getCountry($id,$withcode=0,$dbtouse=0,$outputlangs='',$entconv=1) if ($entconv) $label=($obj->code && ($outputlangs->trans("Country".$obj->code)!="Country".$obj->code))?$outputlangs->trans("Country".$obj->code):$label; else $label=($obj->code && ($outputlangs->transnoentitiesnoconv("Country".$obj->code)!="Country".$obj->code))?$outputlangs->transnoentitiesnoconv("Country".$obj->code):$label; } - if ($withcode == 1) return $label?"$obj->code - $label":"$obj->code"; - else if ($withcode == 2) return $obj->code; - else if ($withcode == 3) return $obj->rowid; + if ($withcode == '1') return $label?"$obj->code - $label":"$obj->code"; + else if ($withcode == '2') return $obj->code; + else if ($withcode == '3') return $obj->rowid; + else if ($withcode == 'all') return array('id'=>$obj->rowid,'code'=>$obj->code,'label'=>$label); else return $label; } else @@ -257,12 +263,16 @@ function getCountry($id,$withcode=0,$dbtouse=0,$outputlangs='',$entconv=1) /** * Return state translated from an id + * * @param id id of state (province/departement) - * @param withcode 0=Return label, 1=Return code + label, 2=Return code + * @param withcode '0'=Return label, + * '1'=Return string code + label, + * '2'=Return code, + * 'all'=return array('id'=>,'code'=>,'label'=>) * @param dbtouse Database handler (using in global way may fail because of conflicts with some autoload features) * @return string String with state code or translated state name */ -function getState($id,$withcode=0,$dbtouse=0) +function getState($id,$withcode='',$dbtouse=0) { global $db,$langs; @@ -279,8 +289,9 @@ function getState($id,$withcode=0,$dbtouse=0) if ($obj) { $label=$obj->label; - if ($withcode == 1) return $label=$obj->code?"$obj->code":"$obj->code - $label"; - else if ($withcode == 2) return $label=$obj->code; + if ($withcode == '1') return $label=$obj->code?"$obj->code":"$obj->code - $label"; + else if ($withcode == '2') return $label=$obj->code; + else if ($withcode == 'all') return array('id'=>$obj->rowid,'code'=>$obj->code,'label'=>$label); else return $label; } else @@ -292,12 +303,13 @@ function getState($id,$withcode=0,$dbtouse=0) } /** - * \brief Retourne le nom traduit ou code+nom d'une devise - * \param code_iso Code iso de la devise - * \param withcode 1=affiche code + nom - * \return string Nom traduit de la devise + * Retourne le nom traduit ou code+nom d'une devise + * + * @param code_iso Code iso de la devise + * @param withcode '1'=affiche code + nom + * @return string Nom traduit de la devise */ -function currency_name($code_iso,$withcode=0) +function currency_name($code_iso,$withcode='') { global $langs,$db; @@ -333,6 +345,7 @@ function currency_name($code_iso,$withcode=0) /** * Retourne le nom traduit de la forme juridique + * * @param code Code de la forme juridique * @return string Nom traduit du pays */ @@ -369,6 +382,7 @@ function getFormeJuridiqueLabel($code) /** * Show html area for list of projects + * * @param conf Object conf * @param langs Object langs * @param db Database handler diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index b479f086740..9d004bd96c4 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -26,7 +26,7 @@ * \file htdocs/societe/class/societe.class.php * \ingroup societe * \brief File for third party class - * \version $Id: societe.class.php,v 1.101 2011/08/20 15:30:39 eldy Exp $ + * \version $Id: societe.class.php,v 1.102 2011/08/24 18:06:45 eldy Exp $ */ require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php"); @@ -696,7 +696,9 @@ class Societe extends CommonObject $this->country_code = $obj->fk_pays?$obj->pays_code:''; $this->pays = $obj->fk_pays?($langs->trans('Country'.$obj->pays_code)!='Country'.$obj->pays_code?$langs->trans('Country'.$obj->pays_code):$obj->pays):''; // TODO obsolete $this->country = $obj->fk_pays?($langs->trans('Country'.$obj->pays_code)!='Country'.$obj->pays_code?$langs->trans('Country'.$obj->pays_code):$obj->pays):''; - $this->state_id = $obj->fk_departement?$obj->departement:''; + $this->state_id = $obj->fk_departement; + $this->state_code = $obj->departement_code; + $this->state = $obj->departement; $transcode=$langs->trans('StatusProspect'.$obj->fk_stcomm); $libelle=($transcode!='StatusProspect'.$obj->fk_stcomm?$transcode:$obj->stcomm); diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index af540246329..121341e7759 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -25,7 +25,7 @@ * \file htdocs/societe/soc.php * \ingroup societe * \brief Third party card page - * \version $Id: soc.php,v 1.139 2011/08/22 22:04:28 eldy Exp $ + * \version $Id: soc.php,v 1.140 2011/08/24 18:06:11 eldy Exp $ */ require("../main.inc.php"); @@ -649,28 +649,16 @@ else } } - ### Gestion du logo de la société - // We set pays_id, pays_code and label for the selected country + // We set country_id, country_code and country for the selected country $object->country_id=$_POST["pays_id"]?$_POST["pays_id"]:$mysoc->country_id; $object->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:$mysoc->country_id; if ($object->pays_id) { - $sql = "SELECT code, libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_pays"; - $sql.= " WHERE rowid = ".$object->pays_id; - $resql=$db->query($sql); - if ($resql) - { - $obj = $db->fetch_object($resql); - } - else - { - dol_print_error($db); - } - $object->pays_code=$obj->code; - $object->pays=$obj->libelle; - $object->country_code=$obj->code; - $object->country=$obj->libelle; + $tmparray=getCountry($object->pays_id,'all',$db,$langs,0); + $object->pays_code=$tmparray['code']; + $object->pays=$tmparray['label']; + $object->country_code=$tmparray['code']; + $object->country=$tmparray['label']; } $object->forme_juridique_code=$_POST['forme_juridique_code']; /* Show create form */ @@ -1609,7 +1597,7 @@ else print ''; // State - if (empty($conf->global->SOCIETE_DISABLE_STATE)) print ''.$langs->trans('State').''.$object->departement.''; + if (empty($conf->global->SOCIETE_DISABLE_STATE)) print ''.$langs->trans('State').''.$object->state.''; print ''.$langs->trans('Phone').''.dol_print_phone($object->tel,$object->pays_code,0,$object->id,'AC_TEL').''; print ''.$langs->trans('Fax').''.dol_print_phone($object->fax,$object->pays_code,0,$object->id,'AC_FAX').''; @@ -1973,5 +1961,5 @@ else $db->close(); -llxFooter('$Date: 2011/08/22 22:04:28 $ - $Revision: 1.139 $'); +llxFooter('$Date: 2011/08/24 18:06:11 $ - $Revision: 1.140 $'); ?> \ No newline at end of file