Qual: Clean code

Perf: Country id+code is now stored into MAIN_INFO_SOCIETE_PAYS instead of only id. This avoid a select to finf country code at each request.
This commit is contained in:
Laurent Destailleur
2010-08-21 15:30:17 +00:00
parent 7ee685640b
commit 1b9ee9c597
11 changed files with 769 additions and 750 deletions

View File

@@ -881,7 +881,7 @@ if ($action == 'create')
$adh->fk_departement = $_POST["departement_id"]; $adh->fk_departement = $_POST["departement_id"];
// We set pays_id, pays_code and label for the selected country // We set pays_id, pays_code and label for the selected country
$adh->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:$conf->global->MAIN_INFO_SOCIETE_PAYS; $adh->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id;
if ($adh->pays_id) if ($adh->pays_id)
{ {
$sql = "SELECT rowid, code, libelle"; $sql = "SELECT rowid, code, libelle";

File diff suppressed because it is too large Load Diff

View File

@@ -193,7 +193,7 @@ if ($_GET["action"] == 'create' || $_POST["action"] == 'create')
} }
// On positionne pays_id, pays_code et libelle du pays choisi // On positionne pays_id, pays_code et libelle du pays choisi
$address->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:$conf->global->MAIN_INFO_SOCIETE_PAYS; $address->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id;
if ($address->pays_id) if ($address->pays_id)
{ {
$sql = "SELECT code, libelle"; $sql = "SELECT code, libelle";
@@ -296,7 +296,7 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit')
$address->address = $_POST["address"]; $address->address = $_POST["address"];
$address->zip = $_POST["zip"]; $address->zip = $_POST["zip"];
$address->ville = $_POST["ville"]; $address->ville = $_POST["ville"];
$address->pays_id = $_POST["pays_id"]?$_POST["pays_id"]:$conf->global->MAIN_INFO_SOCIETE_PAYS; $address->pays_id = $_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id;
$address->tel = $_POST["tel"]; $address->tel = $_POST["tel"];
$address->fax = $_POST["fax"]; $address->fax = $_POST["fax"];
$address->note = $_POST["note"]; $address->note = $_POST["note"];

View File

@@ -276,7 +276,7 @@ if ($user->rights->societe->contact->creer)
$contact->fk_departement = $_POST["departement_id"]; $contact->fk_departement = $_POST["departement_id"];
// We set pays_id, pays_code and label for the selected country // We set pays_id, pays_code and label for the selected country
$contact->fk_pays=$_POST["pays_id"]?$_POST["pays_id"]:$conf->global->MAIN_INFO_SOCIETE_PAYS; $contact->fk_pays=$_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id;
if ($contact->fk_pays) if ($contact->fk_pays)
{ {
$sql = "SELECT code, libelle"; $sql = "SELECT code, libelle";

View File

@@ -228,7 +228,7 @@ class FormCompany
// Affiche la rupture si on est en mode liste multipays // Affiche la rupture si on est en mode liste multipays
if (! $pays_code && $obj->code_pays) if (! $pays_code && $obj->code_pays)
{ {
print '<option value="-1">----- '.$obj->libelle_pays." -----</option>\n"; print '<option value="-1" disabled="true">----- '.$obj->libelle_pays." -----</option>\n";
$pays=$obj->libelle_pays; $pays=$obj->libelle_pays;
} }
} }

View File

@@ -189,7 +189,6 @@ function getCountry($id,$withcode=0)
{ {
global $db,$langs; global $db,$langs;
// TODO Optimize: Try to translate and make SQL request only if it fails
$sql = "SELECT rowid, code, libelle FROM ".MAIN_DB_PREFIX."c_pays"; $sql = "SELECT rowid, code, libelle FROM ".MAIN_DB_PREFIX."c_pays";
if (is_numeric($id)) $sql.= " WHERE rowid=".$id; if (is_numeric($id)) $sql.= " WHERE rowid=".$id;
else $sql.= " WHERE code='".$id."'"; else $sql.= " WHERE code='".$id."'";

View File

@@ -244,6 +244,19 @@ function dol_mimetype($file,$default='application/octet-stream',$shortmime=0)
} }
/**
* \brief Test if filename is a directory
* \param folder Name of folder
* \return boolean True if it's a directory, False if not found
*/
function dol_is_dir($folder)
{
$newfolder=dol_osencode($folder);
if (is_dir($newfolder)) return true;
else return false;
}
/** /**
* \brief Test if a folder is empty * \brief Test if a folder is empty
* \param folder Name of folder * \param folder Name of folder

View File

@@ -569,6 +569,17 @@ function getIntegerInString(str,i,minlength,maxlength)
} }
/*=================================================================
Purpose: Clean string to have it url encoded
Input: s
Author: Laurent Destailleur
Licence: GPL
==================================================================*/
function urlencode(s) {
return s.replace(/\+/gi,'%2B');
}
/*================================================================= /*=================================================================
Purpose: Show a popup HTML page. Purpose: Show a popup HTML page.
Input: url,title Input: url,title
@@ -767,3 +778,5 @@ function uncheckBox(boxId) {
elementId.checked = false; elementId.checked = false;
} }
} }

View File

@@ -669,9 +669,6 @@ dol_syslog("--- Access to ".$_SERVER["PHP_SELF"]);
//Another call for easy debugg //Another call for easy debugg
//dol_syslog("Access to ".$_SERVER["PHP_SELF"].' GET='.join(',',array_keys($_GET)).'->'.join(',',$_GET).' POST:'.join(',',array_keys($_POST)).'->'.join(',',$_POST)); //dol_syslog("Access to ".$_SERVER["PHP_SELF"].' GET='.join(',',array_keys($_GET)).'->'.join(',',$_GET).' POST:'.join(',',array_keys($_POST)).'->'.join(',',$_POST));
// For backward compatibility
if (! defined('MAIN_INFO_SOCIETE_PAYS')) define('MAIN_INFO_SOCIETE_PAYS','1');
// Load main languages files // Load main languages files
if (! defined('NOREQUIRETRAN')) if (! defined('NOREQUIRETRAN'))
{ {

View File

@@ -362,7 +362,7 @@ if (! defined('NOREQUIREDB') && ! defined('NOREQUIRESOC'))
} }
else // For backward compatibility else // For backward compatibility
{ {
include(DOL_DOCUMENT_ROOT.'/lib/company.lib.php'); 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_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_label=getCountry($pays_id,0); // This need a SQL request, but it's the old feature
} }

View File

@@ -428,7 +428,7 @@ $_GET["action"] == 'create' || $_POST["action"] == 'create')
$soc->default_lang=$_POST["default_lang"]; $soc->default_lang=$_POST["default_lang"];
// We set pays_id, pays_code and label for the selected country // We set pays_id, pays_code and label for the selected country
$soc->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:$conf->global->MAIN_INFO_SOCIETE_PAYS; $soc->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id;
if ($soc->pays_id) if ($soc->pays_id)
{ {
$sql = "SELECT code, libelle"; $sql = "SELECT code, libelle";
@@ -802,7 +802,7 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit')
$soc->address=$_POST["adresse"]; $soc->address=$_POST["adresse"];
$soc->cp=$_POST["cp"]; $soc->cp=$_POST["cp"];
$soc->ville=$_POST["ville"]; $soc->ville=$_POST["ville"];
$soc->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:$conf->global->MAIN_INFO_SOCIETE_PAYS; $soc->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:$mysoc->pays_id;
$soc->departement_id=$_POST["departement_id"]; $soc->departement_id=$_POST["departement_id"];
$soc->tel=$_POST["tel"]; $soc->tel=$_POST["tel"];
$soc->fax=$_POST["fax"]; $soc->fax=$_POST["fax"];