From e78a9b8a0116da9a9797566683404f94edc7ed7a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 4 Sep 2010 18:04:47 +0000 Subject: [PATCH] Fix: Do not use global variable to fix pb with autoload --- htdocs/compta/bank/bankid_fr.php | 2 +- htdocs/compta/bank/fiche.php | 2 +- htdocs/lib/company.lib.php | 38 ++++++++++++++++++-------------- htdocs/master.inc.php | 4 ++-- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/htdocs/compta/bank/bankid_fr.php b/htdocs/compta/bank/bankid_fr.php index 4eb83cb5e35..0aa01f5ff3c 100644 --- a/htdocs/compta/bank/bankid_fr.php +++ b/htdocs/compta/bank/bankid_fr.php @@ -215,7 +215,7 @@ if (($_GET["id"] || $_GET["ref"]) && $_GET["action"] != 'edit') print ''.$langs->trans("BankAccountCountry").''; $img=picto_from_langcode($account->pays_code); print $img?$img.' ':''; - print getCountry($account->getCountryCode()); + print getCountry($account->getCountryCode(),0,$db); print "\n"; print ''.$langs->trans("BankAccountOwner").''; diff --git a/htdocs/compta/bank/fiche.php b/htdocs/compta/bank/fiche.php index 17f65bf9571..1547c6a94f1 100644 --- a/htdocs/compta/bank/fiche.php +++ b/htdocs/compta/bank/fiche.php @@ -371,7 +371,7 @@ else { $img=picto_from_langcode($account->pays_code); print $img?$img.' ':''; - print getCountry($account->getCountryCode()); + print getCountry($account->getCountryCode(),0,$db); } print ''; diff --git a/htdocs/lib/company.lib.php b/htdocs/lib/company.lib.php index b29e4d0b6cf..5480da1c136 100644 --- a/htdocs/lib/company.lib.php +++ b/htdocs/lib/company.lib.php @@ -179,24 +179,27 @@ function societe_prepare_head2($objsoc) /** - * \brief Return country translated 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 - * \return string String with country code or translated country name + * Return country translated 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 + * @param dbtouse Database handler (using in global way may fail because of conflicts with some autoload features) + * @return string String with country code or translated country name */ -function getCountry($id,$withcode=0) +function getCountry($id,$withcode=0,$dbtouse=0) { global $db,$langs; + if (! is_object($dbtouse)) $dbtouse=$db; + $sql = "SELECT rowid, code, libelle FROM ".MAIN_DB_PREFIX."c_pays"; if (is_numeric($id)) $sql.= " WHERE rowid=".$id; else $sql.= " WHERE code='".$id."'"; dol_syslog("Company.lib::getCountry sql=".$sql); - $resql=$db->query($sql); + $resql=$dbtouse->query($sql); if ($resql) { - $obj = $db->fetch_object($resql); + $obj = $dbtouse->fetch_object($resql); if ($obj) { $label=((! empty($obj->libelle) && $obj->libelle!='-')?$obj->libelle:''); @@ -214,27 +217,30 @@ function getCountry($id,$withcode=0) return "NotDefined"; } } - else dol_print_error($db,''); + else dol_print_error($dbtouse,''); } /** - * \brief 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 - * \return string String with state code or translated state name + * 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 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) +function getState($id,$withcode=0,$dbtouse=0) { global $db,$langs; + if (! is_object($dbtouse)) $dbtouse=$db; + $sql = "SELECT rowid, code_departement as code, nom as label FROM ".MAIN_DB_PREFIX."c_departements"; $sql.= " WHERE rowid=".$id; dol_syslog("Company.lib::getState sql=".$sql); - $resql=$db->query($sql); + $resql=$dbtouse->query($sql); if ($resql) { - $obj = $db->fetch_object($resql); + $obj = $dbtouse->fetch_object($resql); if ($obj) { $label=$obj->label; @@ -247,7 +253,7 @@ function getState($id,$withcode=0) return $langs->trans("NotDefined"); } } - else dol_print_error($db,''); + else dol_print_error($dbtouse,''); } /** diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php index db6dd3f875b..e643c47a501 100644 --- a/htdocs/master.inc.php +++ b/htdocs/master.inc.php @@ -363,8 +363,8 @@ if (! defined('NOREQUIREDB') && ! defined('NOREQUIRESOC')) else // For backward compatibility { include_once(DOL_DOCUMENT_ROOT.'/lib/company.lib.php'); - $pays_code=getCountry($pays_id,2); // This need a SQL request, but it's the old feature - $pays_label=getCountry($pays_id,0); // This need a SQL request, but it's the old feature + $pays_code=getCountry($pays_id,2,$db); // This need a SQL request, but it's the old feature + $pays_label=getCountry($pays_id,0,$db); // This need a SQL request, but it's the old feature } $mysoc->pays_id=$pays_id; $mysoc->pays_code=$pays_code;