Uniformize code

This commit is contained in:
Juanjo Menent 2011-09-02 14:31:53 +00:00
parent 0826cfdf97
commit 11802383f7
9 changed files with 402 additions and 494 deletions

View File

@ -261,7 +261,7 @@ if ($action == 'create')
if ($res) if ($res)
{ {
while ($menu = $db->fetch_array($res)) while ($menu = $db->fetch_array ($res))
{ {
$parent_rowid = $menu['rowid']; $parent_rowid = $menu['rowid'];
$parent_mainmenu = $menu['mainmenu']; $parent_mainmenu = $menu['mainmenu'];

View File

@ -300,7 +300,7 @@ if ($conf->use_javascript_ajax)
$num = $db->num_rows($res); $num = $db->num_rows($res);
$i = 1; $i = 1;
while ($menu = $db->fetch_array($res)) while ($menu = $db->fetch_array ($res))
{ {
if (! empty($menu['langs'])) $langs->load($menu['langs']); if (! empty($menu['langs'])) $langs->load($menu['langs']);
$titre = $langs->trans($menu['titre']); $titre = $langs->trans($menu['titre']);

View File

@ -32,7 +32,7 @@ if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1);
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1); if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1);
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
session_cache_limiter(FALSE); session_cache_limiter( FALSE );
require_once("../../master.inc.php"); require_once("../../master.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/functions.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/functions.lib.php");

View File

@ -40,11 +40,9 @@ $action = GETPOST("action");
if ($action == "set") if ($action == "set")
{ {
$db->begin();
for ($i = 0 ; $i < 2 ; $i++) for ($i = 0 ; $i < 2 ; $i++)
{ {
$res = dolibarr_set_const($db, $_POST["nom$i"], $_POST["value$i"],'chaine',0,'',$conf->entity); $res = dolibarr_set_const($db, $_POST["nom$i"], $_POST["value$i"],'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;
} }
$id=$_POST["PRELEVEMENT_ID_BANKACCOUNT"]; $id=$_POST["PRELEVEMENT_ID_BANKACCOUNT"];
@ -53,32 +51,23 @@ if ($action == "set")
if($account->fetch($id)>0) if($account->fetch($id)>0)
{ {
$res = dolibarr_set_const($db, "PRELEVEMENT_ID_BANKACCOUNT", $id,'chaine',0,'',$conf->entity); $res = dolibarr_set_const($db, "PRELEVEMENT_ID_BANKACCOUNT", $id,'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;
$res = dolibarr_set_const($db, "PRELEVEMENT_CODE_BANQUE", $account->code_banque,'chaine',0,'',$conf->entity); $res = dolibarr_set_const($db, "PRELEVEMENT_CODE_BANQUE", $account->code_banque,'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;
$res = dolibarr_set_const($db, "PRELEVEMENT_CODE_GUICHET", $account->code_guichet,'chaine',0,'',$conf->entity); $res = dolibarr_set_const($db, "PRELEVEMENT_CODE_GUICHET", $account->code_guichet,'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;
$res = dolibarr_set_const($db, "PRELEVEMENT_NUMERO_COMPTE", $account->number,'chaine',0,'',$conf->entity); $res = dolibarr_set_const($db, "PRELEVEMENT_NUMERO_COMPTE", $account->number,'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;
$res = dolibarr_set_const($db, "PRELEVEMENT_NUMBER_KEY", $account->cle_rib,'chaine',0,'',$conf->entity); $res = dolibarr_set_const($db, "PRELEVEMENT_NUMBER_KEY", $account->cle_rib,'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;
$res = dolibarr_set_const($db, "PRELEVEMENT_IBAN", $account->iban,'chaine',0,'',$conf->entity); $res = dolibarr_set_const($db, "PRELEVEMENT_IBAN", $account->iban,'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;
$res = dolibarr_set_const($db, "PRELEVEMENT_BIC", $account->bic,'chaine',0,'',$conf->entity); $res = dolibarr_set_const($db, "PRELEVEMENT_BIC", $account->bic,'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;
$res = dolibarr_set_const($db, "PRELEVEMENT_RAISON_SOCIALE", $account->proprio,'chaine',0,'',$conf->entity); $res = dolibarr_set_const($db, "PRELEVEMENT_RAISON_SOCIALE", $account->proprio,'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;
} }
else $error++;
if (! $res > 0) $error++;
if (! $error) if (! $error)
{ {
$db->commit();
$mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>"; $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
} }
else else
{ {
$db->rollback();
$mesg = "<font class=\"error\">".$langs->trans("Error")."</font>"; $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
} }
} }

View File

@ -72,18 +72,16 @@ class DoliDb
var $error; var $error;
/** /**
* Constructor. * Ouverture d'une connexion vers le serveur et eventuellement une database.
* This create an opened connexion to a database server and eventually to a database * @param type Type de base de donnees (mysql ou pgsql)
* * @param host Addresse de la base de donnees
* @param string $type Type of database (mysql, pgsql...) * @param user Nom de l'utilisateur autorise
* @param string $host Address of database server * @param pass Mot de passe
* @param string $user Nom de l'utilisateur autorise * @param name Nom de la database
* @param string $pass Mot de passe * @param port Port of database server
* @param string $name Nom de la database * @return int 1 en cas de succes, 0 sinon
* @param int $port Port of database server */
* @return int 1 if OK, 0 if not
*/
function DoliDb($type='mssql', $host, $user, $pass, $name='', $port=0) function DoliDb($type='mssql', $host, $user, $pass, $name='', $port=0)
{ {
global $conf,$langs; global $conf,$langs;
@ -155,11 +153,10 @@ class DoliDb
} }
/** /**
* Convert a SQL request in Mysql syntax to native syntax * Convert a SQL request in Mysql syntax to PostgreSQL syntax
* * @param line SQL request line to convert
* @param string $line SQL request line to convert * @param type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
* @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) * @return string SQL request line converted
* @return string SQL request line converted
*/ */
function convertSQLFromMysql($line,$type='ddl') function convertSQLFromMysql($line,$type='ddl')
{ {
@ -167,10 +164,9 @@ class DoliDb
} }
/** /**
* Select a database * Selectionne une database.
* * @param database Nom de la database
* @param string $database Name of database * @return boolean true si ok, false si ko
* @return boolean true if OK, false if KO
*/ */
function select_db($database) function select_db($database)
{ {
@ -178,15 +174,14 @@ class DoliDb
} }
/** /**
* Connexion to server * Connection vers le serveur
* * @param host addresse de la base de donnees
* @param string $host database server host * @param login nom de l'utilisateur autoris
* @param string $login login * @param passwd mot de passe
* @param string $passwd password * @param name nom de la database (ne sert pas sous mysql, sert sous pgsql)
* @param string $name name of database (not used for mysql, used for pgsql) * @param port Port of database server
* @param string $port Port of database server * @return resource handler d'acces a la base
* @return resource Database access handler * @see close
* @see close
*/ */
function connect($host, $login, $passwd, $name, $port=0) function connect($host, $login, $passwd, $name, $port=0)
{ {
@ -203,9 +198,8 @@ class DoliDb
} }
/** /**
* Return label of manager * \brief Return label of manager
* * \return string Label
* @return string Label
*/ */
function getLabel() function getLabel()
{ {
@ -213,9 +207,8 @@ class DoliDb
} }
/** /**
* Return version of database server * \brief Renvoie la version du serveur
* * \return string Chaine version
* @return string Version string
*/ */
function getVersion() function getVersion()
{ {
@ -226,9 +219,8 @@ class DoliDb
/** /**
* Return version of database server into an array * \brief Renvoie la version du serveur dans un tableau
* * \return array Tableau de chaque niveau de version
* @return array Version array
*/ */
function getVersionArray() function getVersionArray()
{ {
@ -238,7 +230,6 @@ class DoliDb
/** /**
* Close database connexion * Close database connexion
*
* @return boolean True if disconnect successfull, false otherwise * @return boolean True if disconnect successfull, false otherwise
* @see connect * @see connect
*/ */
@ -255,9 +246,8 @@ class DoliDb
/** /**
* Start transaction * \brief Debut d'une transaction.
* * \return int 1 si ouverture transaction ok ou deja ouverte, 0 en cas d'erreur
* @return int 1 if transaction successfuly opened or already opened, 0 if error
*/ */
function begin() function begin()
{ {
@ -280,11 +270,10 @@ class DoliDb
/** /**
* Validate a database transaction * Validate a database transaction
* * @param log Add more log to default log line
* @param $log Add more log to default log line
* @return int 1 if validation is OK or transaction level no started, 0 if ERROR * @return int 1 if validation is OK or transaction level no started, 0 if ERROR
*/ */
function commit($log='') function commit()
{ {
if ($this->transaction_opened <= 1) if ($this->transaction_opened <= 1)
{ {
@ -304,9 +293,8 @@ class DoliDb
} }
/** /**
* Annulation d'une transaction et retour aux anciennes valeurs * \brief Annulation d'une transaction et retour aux anciennes valeurs
* * \return int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur
* @return int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur
*/ */
function rollback() function rollback()
{ {
@ -326,7 +314,6 @@ class DoliDb
/** /**
* Execute a SQL request and return the resultset * Execute a SQL request and return the resultset
*
* @param query SQL query string * @param query SQL query string
* @param usesavepoint 0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions). * @param usesavepoint 0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions).
* Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints. * Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints.
@ -417,10 +404,9 @@ class DoliDb
} }
/** /**
* Renvoie la ligne courante (comme un objet) pour le curseur resultset * \brief Renvoie la ligne courante (comme un objet) pour le curseur resultset.
* * \param resultset Curseur de la requete voulue
* @param resultset Curseur de la requete voulue * \return object Object result line or false if KO or end of cursor
* @return object Object result line or false if KO or end of cursor
*/ */
function fetch_object($resultset) function fetch_object($resultset)
{ {
@ -430,10 +416,9 @@ class DoliDb
} }
/** /**
* Renvoie les donnees dans un tableau * \brief Renvoie les donnees dans un tableau.
* * \param resultset Curseur de la requete voulue
* @param resultset Curseur de la requete voulue * \return array
* @return array
*/ */
function fetch_array($resultset) function fetch_array($resultset)
{ {

View File

@ -72,16 +72,14 @@ class DoliDb
/** /**
* Constructor. * Ouverture d'une connexion vers le serveur et eventuellement une database.
* This create an opened connexion to a database server and eventually to a database * @param type Type de base de donnees (mysql ou pgsql)
* * @param host Addresse de la base de donnees
* @param string $type Type of database (mysql, pgsql...) * @param user Nom de l'utilisateur autorise
* @param string $host Address of database server * @param pass Mot de passe
* @param string $user Nom de l'utilisateur autorise * @param name Nom de la database
* @param string $pass Mot de passe * @param port Port of database server
* @param string $name Nom de la database * @return int 1 en cas de succes, 0 sinon
* @param int $port Port of database server
* @return int 1 if OK, 0 if not
*/ */
function DoliDb($type='mysql', $host, $user, $pass, $name='', $port=0) function DoliDb($type='mysql', $host, $user, $pass, $name='', $port=0)
{ {
@ -182,11 +180,10 @@ class DoliDb
/** /**
* Convert a SQL request in Mysql syntax to native syntax * Convert a SQL request in Mysql syntax to PostgreSQL syntax
* * @param line SQL request line to convert
* @param string $line SQL request line to convert * @param type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
* @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) * @return string SQL request line converted
* @return string SQL request line converted
*/ */
function convertSQLFromMysql($line,$type='ddl') function convertSQLFromMysql($line,$type='ddl')
{ {
@ -194,10 +191,9 @@ class DoliDb
} }
/** /**
* Select a database * \brief Selectionne une database.
* * \param database Nom de la database
* @param string $database Name of database * \return boolean true si ok, false si ko
* @return boolean true if OK, false if KO
*/ */
function select_db($database) function select_db($database)
{ {
@ -206,15 +202,14 @@ class DoliDb
} }
/** /**
* Connexion to server * \brief Connexion to server
* * \param host database server host
* @param string $host database server host * \param login login
* @param string $login login * \param passwd password
* @param string $passwd password * \param name nom de la database (ne sert pas sous mysql, sert sous pgsql)
* @param string $name name of database (not used for mysql, used for pgsql) * \param port Port of database server
* @param string $port Port of database server * \return resource Database access handler
* @return resource Database access handler * \seealso close
* @see close
*/ */
function connect($host, $login, $passwd, $name, $port=0) function connect($host, $login, $passwd, $name, $port=0)
{ {
@ -232,9 +227,8 @@ class DoliDb
} }
/** /**
* Return label of manager * \brief Return label of manager
* * \return string Label
* @return string Label
*/ */
function getLabel() function getLabel()
{ {
@ -242,9 +236,8 @@ class DoliDb
} }
/** /**
* Return version of database server * \brief Renvoie la version du serveur
* * \return string Chaine version
* @return string Version string
*/ */
function getVersion() function getVersion()
{ {
@ -252,9 +245,26 @@ class DoliDb
} }
/** /**
* Return version of database server into an array * \brief Renvoie la version du serveur sous forme de nombre
* * \return string Chaine version
* @return array Version array */
function getIntVersion()
{
$version= $this->getVersion();
$vlist=preg_split('/[.-]/',$version);
if (dol_strlen($vlist[1])==1){
$vlist[1]="0".$vlist[1];
}
if (dol_strlen($vlist[2])==1){
$vlist[2]="0".$vlist[2];
}
return $vlist[0].$vlist[1].$vlist[2];
}
/**
* \brief Renvoie la version du serveur dans un tableau
* \return array Tableau de chaque niveau de version
*/ */
function getVersionArray() function getVersionArray()
{ {
@ -264,7 +274,6 @@ class DoliDb
/** /**
* Close database connexion * Close database connexion
*
* @return boolean True if disconnect successfull, false otherwise * @return boolean True if disconnect successfull, false otherwise
* @see connect * @see connect
*/ */
@ -281,9 +290,8 @@ class DoliDb
/** /**
* Start transaction * \brief Debut d'une transaction.
* * \return int 1 si ouverture transaction ok ou deja ouverte, 0 en cas d'erreur
* @return int 1 if transaction successfuly opened or already opened, 0 if error
*/ */
function begin() function begin()
{ {
@ -306,8 +314,7 @@ class DoliDb
/** /**
* Validate a database transaction * Validate a database transaction
* * @param log Add more log to default log line
* @param $log Add more log to default log line
* @return int 1 if validation is OK or transaction level no started, 0 if ERROR * @return int 1 if validation is OK or transaction level no started, 0 if ERROR
*/ */
function commit($log='') function commit($log='')
@ -330,10 +337,9 @@ class DoliDb
} }
/** /**
* Annulation d'une transaction et retour aux anciennes valeurs * \brief Annulation d'une transaction et retour aux anciennes valeurs
* * \param log Add more log to default log line
* @param $log Add more log to default log line * \return int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur
* @return int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur
*/ */
function rollback($log='') function rollback($log='')
{ {
@ -353,7 +359,6 @@ class DoliDb
/** /**
* Execute a SQL request and return the resultset * Execute a SQL request and return the resultset
*
* @param query SQL query string * @param query SQL query string
* @param usesavepoint 0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions). * @param usesavepoint 0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions).
* Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints. * Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints.
@ -393,10 +398,9 @@ class DoliDb
} }
/** /**
* Renvoie la ligne courante (comme un objet) pour le curseur resultset * \brief Renvoie la ligne courante (comme un objet) pour le curseur resultset.
* * \param resultset Curseur de la requete voulue
* @param resultset Curseur de la requete voulue * \return object Object result line or false if KO or end of cursor
* @return object Object result line or false if KO or end of cursor
*/ */
function fetch_object($resultset) function fetch_object($resultset)
{ {
@ -406,10 +410,9 @@ class DoliDb
} }
/** /**
* Renvoie les donnees dans un tableau * \brief Renvoie les donnees dans un tableau.
* * \param resultset Curseur de la requete voulue
* @param resultset Curseur de la requete voulue * \return array
* @return array
*/ */
function fetch_array($resultset) function fetch_array($resultset)
{ {
@ -420,10 +423,9 @@ class DoliDb
/** /**
* Renvoie les donnees comme un tableau * \brief Renvoie les donnees comme un tableau.
* * \param resultset Curseur de la requete voulue
* @param resultset Curseur de la requete voulue * \return array
* @return array
*/ */
function fetch_row($resultset) function fetch_row($resultset)
{ {
@ -433,11 +435,10 @@ class DoliDb
} }
/** /**
* Renvoie le nombre de lignes dans le resultat d'une requete SELECT * \brief Renvoie le nombre de lignes dans le resultat d'une requete SELECT
* * \see affected_rows
* @see affected_rows * \param resultset Curseur de la requete voulue
* @param resultset Curseur de la requete voulue * \return int Nombre de lignes
* @return int Nombre de lignes
*/ */
function num_rows($resultset) function num_rows($resultset)
{ {
@ -447,11 +448,10 @@ class DoliDb
} }
/** /**
* Renvoie le nombre de lignes dans le resultat d'une requete INSERT, DELETE ou UPDATE * \brief Renvoie le nombre de lignes dans le resultat d'une requete INSERT, DELETE ou UPDATE
* * \see num_rows
* @see num_rows * \param resultset Curseur de la requete voulue
* @param resultset Curseur de la requete voulue * \return int Nombre de lignes
* @return int Nombre de lignes
*/ */
function affected_rows($resultset) function affected_rows($resultset)
{ {
@ -464,9 +464,8 @@ class DoliDb
/** /**
* Libere le dernier resultset utilise sur cette connexion. * \brief Libere le dernier resultset utilise sur cette connexion.
* * \param resultset Curseur de la requete voulue
* @param resultset Curseur de la requete voulue
*/ */
function free($resultset=0) function free($resultset=0)
{ {
@ -478,11 +477,10 @@ class DoliDb
/** /**
* Defini les limites de la requete * \brief Defini les limites de la requete.
* * \param limit nombre maximum de lignes retournees
* @param limit nombre maximum de lignes retournees * \param offset numero de la ligne a partir de laquelle recuperer les ligne
* @param offset numero de la ligne a partir de laquelle recuperer les ligne * \return string chaine exprimant la syntax sql de la limite
* @return string chaine exprimant la syntax sql de la limite
*/ */
function plimit($limit=0,$offset=0) function plimit($limit=0,$offset=0)
{ {
@ -495,7 +493,6 @@ class DoliDb
/** /**
* Define sort criteria of request * Define sort criteria of request
*
* @param sortfield List of sort fields * @param sortfield List of sort fields
* @param sortorder Sort order * @param sortorder Sort order
* @return string String to provide syntax of a sort sql string * @return string String to provide syntax of a sort sql string
@ -525,8 +522,7 @@ class DoliDb
/** /**
* Escape a string to insert data * Escape a string to insert data.
*
* @param stringtoencode String to escape * @param stringtoencode String to escape
* @return string String escaped * @return string String escaped
*/ */
@ -539,7 +535,6 @@ class DoliDb
/** /**
* Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field. * Convert (by PHP) a GM Timestamp date into a string date with PHP server TZ to insert into a date field.
* Function to use to build INSERT, UPDATE or WHERE predica * Function to use to build INSERT, UPDATE or WHERE predica
*
* @param param Date TMS to convert * @param param Date TMS to convert
* @return string Date in a string YYYYMMDDHHMMSS * @return string Date in a string YYYYMMDDHHMMSS
*/ */
@ -551,7 +546,6 @@ class DoliDb
/** /**
* Convert (by PHP) a PHP server TZ string date into a GM Timestamps date * Convert (by PHP) a PHP server TZ string date into a GM Timestamps date
* 19700101020000 -> 3600 with TZ+1 * 19700101020000 -> 3600 with TZ+1
*
* @param string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS) * @param string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
* @return date Date TMS * @return date Date TMS
*/ */
@ -565,7 +559,6 @@ class DoliDb
/** /**
* Formate a SQL IF * Formate a SQL IF
*
* @param test chaine test * @param test chaine test
* @param resok resultat si test egal * @param resok resultat si test egal
* @param resko resultat si test non egal * @param resko resultat si test non egal

View File

@ -73,16 +73,14 @@ class DoliDb
/** /**
* Constructor. * Ouverture d'une connexion vers le serveur et eventuellement une database.
* This create an opened connexion to a database server and eventually to a database * @param type Type de base de donnees (mysql ou pgsql)
* * @param host Addresse de la base de donnees
* @param string $type Type of database (mysql, pgsql...) * @param user Nom de l'utilisateur autorise
* @param string $host Address of database server * @param pass Mot de passe
* @param string $user Nom de l'utilisateur autorise * @param name Nom de la database
* @param string $pass Mot de passe * @param port Port of database server
* @param string $name Nom de la database * @return int 1 en cas de succes, 0 sinon
* @param int $port Port of database server
* @return int 1 if OK, 0 if not
*/ */
function DoliDb($type='mysqli', $host, $user, $pass, $name='', $port=0) function DoliDb($type='mysqli', $host, $user, $pass, $name='', $port=0)
{ {
@ -185,23 +183,21 @@ class DoliDb
/** /**
* Convert a SQL request in Mysql syntax to native syntax * Convert a SQL request in Mysql syntax to PostgreSQL syntax
* * @param line SQL request line to convert
* @param string $line SQL request line to convert * @param type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
* @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) * @return string SQL request line converted
* @return string SQL request line converted
*/ */
function convertSQLFromMysql($line,$type='ddl') function convertSQLFromMysql($line,$type='ddl')
{ {
return $line; return $line;
} }
/** /**
* Select a database * \brief Selectionne une database.
* * \param database Nom de la database
* @param string $database Name of database * \return boolean true si ok, false si ko
* @return boolean true if OK, false if KO */
*/
function select_db($database) function select_db($database)
{ {
dol_syslog("DoliDB::select_db database=".$database, LOG_DEBUG); dol_syslog("DoliDB::select_db database=".$database, LOG_DEBUG);
@ -210,15 +206,14 @@ class DoliDb
/** /**
* Connexion to server * \brief Connexion to server
* * \param host database server host
* @param string $host database server host * \param login login
* @param string $login login * \param passwd password
* @param string $passwd password * \param name nom de la database (ne sert pas sous mysql, sert sous pgsql)
* @param string $name name of database (not used for mysql, used for pgsql) * \param port Port of database server
* @param string $port Port of database server * \return resource Database access handler
* @return resource Database access handler * \seealso close
* @see close
*/ */
function connect($host, $login, $passwd, $name, $port=0) function connect($host, $login, $passwd, $name, $port=0)
{ {
@ -237,9 +232,8 @@ class DoliDb
} }
/** /**
* Return label of manager * \brief Return label of manager
* * \return string Label
* @return string Label
*/ */
function getLabel() function getLabel()
{ {
@ -247,9 +241,8 @@ class DoliDb
} }
/** /**
* Return version of database server * \brief Renvoie la version du serveur
* * \return string Chaine version
* @return string Version string
*/ */
function getVersion() function getVersion()
{ {
@ -259,11 +252,27 @@ class DoliDb
return mysqli_get_server_info($this->db); return mysqli_get_server_info($this->db);
} }
/** /**
* Return version of database server into an array * \brief Renvoie la version du serveur sous forme de nombre
* * \return string Chaine version
* @return array Version array */
*/ function getIntVersion()
{
$version= $this->getVersion();
$vlist=preg_split('/[.-]/',$version);
if (dol_strlen($vlist[1])==1){
$vlist[1]="0".$vlist[1];
}
if (dol_strlen($vlist[2])==1){
$vlist[2]="0".$vlist[2];
}
return $vlist[0].$vlist[1].$vlist[2];
}
/**
* \brief Renvoie la version du serveur dans un tableau
* \return array Tableau de chaque niveau de version
*/
function getVersionArray() function getVersionArray()
{ {
return explode('.',$this->getVersion()); return explode('.',$this->getVersion());
@ -271,10 +280,9 @@ class DoliDb
/** /**
* Close database connexion * Close database connexion
* * @return boolean True if disconnect successfull, false otherwise
* @return boolean True if disconnect successfull, false otherwise * @see connect
* @see connect
*/ */
function close() function close()
{ {
@ -289,9 +297,8 @@ class DoliDb
/** /**
* Start transaction * \brief Debut d'une transaction.
* * \return int 1 si ouverture transaction ok ou deja ouverte, 0 en cas d'erreur
* @return int 1 if transaction successfuly opened or already opened, 0 if error
*/ */
function begin() function begin()
{ {
@ -314,8 +321,7 @@ class DoliDb
/** /**
* Validate a database transaction * Validate a database transaction
* * @param log Add more log to default log line
* @param $log Add more log to default log line
* @return int 1 if validation is OK or transaction level no started, 0 if ERROR * @return int 1 if validation is OK or transaction level no started, 0 if ERROR
*/ */
function commit($log='') function commit($log='')
@ -338,10 +344,9 @@ class DoliDb
} }
/** /**
* Annulation d'une transaction et retour aux anciennes valeurs * \brief Annulation d'une transaction et retour aux anciennes valeurs
* * \param log Add more log to default log line
* @param $log Add more log to default log line * \return int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur
* @return int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur
*/ */
function rollback($log='') function rollback($log='')
{ {
@ -361,7 +366,6 @@ class DoliDb
/** /**
* Execute a SQL request and return the resultset * Execute a SQL request and return the resultset
*
* @param query SQL query string * @param query SQL query string
* @param usesavepoint 0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions). * @param usesavepoint 0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions).
* Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints. * Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints.
@ -399,10 +403,9 @@ class DoliDb
} }
/** /**
* Renvoie la ligne courante (comme un objet) pour le curseur resultset * \brief Renvoie la ligne courante (comme un objet) pour le curseur resultset.
* * \param resultset Curseur de la requete voulue
* @param resultset Curseur de la requete voulue * \return object Object result line or false if KO or end of cursor
* @return object Object result line or false if KO or end of cursor
*/ */
function fetch_object($resultset) function fetch_object($resultset)
{ {
@ -413,10 +416,9 @@ class DoliDb
/** /**
* Renvoie les donnees dans un tableau * \brief Renvoie les donnees dans un tableau.
* * \param resultset Curseur de la requete voulue
* @param resultset Curseur de la requete voulue * \return array
* @return array
*/ */
function fetch_array($resultset) function fetch_array($resultset)
{ {
@ -426,10 +428,9 @@ class DoliDb
} }
/** /**
* Renvoie les donnees comme un tableau * \brief Renvoie les donnees comme un tableau.
* * \param resultset Curseur de la requete voulue
* @param resultset Curseur de la requete voulue * \return array
* @return array
*/ */
function fetch_row($resultset) function fetch_row($resultset)
{ {
@ -447,11 +448,10 @@ class DoliDb
} }
/** /**
* Renvoie le nombre de lignes dans le resultat d'une requete SELECT * \brief Renvoie le nombre de lignes dans le resultat d'une requete SELECT
* * \see affected_rows
* @see affected_rows * \param resultset Curseur de la requete voulue
* @param resultset Curseur de la requete voulue * \return int Nombre de lignes
* @return int Nombre de lignes
*/ */
function num_rows($resultset) function num_rows($resultset)
{ {
@ -461,10 +461,10 @@ class DoliDb
} }
/** /**
* Renvoie le nombre de lignes dans le resultat d'une requete INSERT, DELETE ou UPDATE * \brief Renvoie le nombre de lignes dans le resultat d'une requete INSERT, DELETE ou UPDATE
* @see num_rows * \see num_rows
* @param resultset Curseur de la requete voulue * \param resultset Curseur de la requete voulue
* @return int Nombre de lignes * \return int Nombre de lignes
*/ */
function affected_rows($resultset) function affected_rows($resultset)
@ -478,9 +478,8 @@ class DoliDb
/** /**
* Libere le dernier resultset utilise sur cette connexion * \brief Libere le dernier resultset utilise sur cette connexion.
* * \param resultset Curseur de la requete voulue
* @param resultset Curseur de la requete voulue
*/ */
function free($resultset=0) function free($resultset=0)
{ {
@ -492,11 +491,10 @@ class DoliDb
/** /**
* Defini les limites de la requete * \brief Defini les limites de la requete.
* * \param limit nombre maximum de lignes retournees
* @param limit nombre maximum de lignes retournees * \param offset numero de la ligne a partir de laquelle recuperer les ligne
* @param offset numero de la ligne a partir de laquelle recuperer les ligne * \return string chaine exprimant la syntax sql de la limite
* @return string chaine exprimant la syntax sql de la limite
*/ */
function plimit($limit=0,$offset=0) function plimit($limit=0,$offset=0)
{ {
@ -509,7 +507,6 @@ class DoliDb
/** /**
* Define sort criteria of request * Define sort criteria of request
*
* @param sortfield List of sort fields * @param sortfield List of sort fields
* @param sortorder Sort order * @param sortorder Sort order
* @return string String to provide syntax of a sort sql string * @return string String to provide syntax of a sort sql string
@ -539,8 +536,7 @@ class DoliDb
/** /**
* Escape a string to insert data * Escape a string to insert data.
*
* @param stringtoencode String to escape * @param stringtoencode String to escape
* @return string String escaped * @return string String escaped
*/ */
@ -552,7 +548,6 @@ class DoliDb
/** /**
* Convert (by PHP) a GM Timestamp date into a PHP server TZ to insert into a date field. * Convert (by PHP) a GM Timestamp date into a PHP server TZ to insert into a date field.
* Function to use to build INSERT, UPDATE or WHERE predica * Function to use to build INSERT, UPDATE or WHERE predica
*
* @param param Date TMS to convert * @param param Date TMS to convert
* @return string Date in a string YYYYMMDDHHMMSS * @return string Date in a string YYYYMMDDHHMMSS
*/ */
@ -564,7 +559,6 @@ class DoliDb
/** /**
* Convert (by PHP) a PHP server TZ string date into a GM Timestamps date * Convert (by PHP) a PHP server TZ string date into a GM Timestamps date
* 19700101020000 -> 3600 with TZ+1 * 19700101020000 -> 3600 with TZ+1
*
* @param string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS) * @param string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
* @return date Date TMS * @return date Date TMS
*/ */
@ -578,7 +572,6 @@ class DoliDb
/** /**
* Formate a SQL IF * Formate a SQL IF
*
* @param test chaine test * @param test chaine test
* @param resok resultat si test egal * @param resok resultat si test egal
* @param resko resultat si test non egal * @param resko resultat si test non egal

View File

@ -62,16 +62,14 @@ class DoliDb
/** /**
* Constructor. * \brief Ouverture d'une connexion vers le serveur et une database.
* This create an opened connexion to a database server and eventually to a database * \param type type de base de donnees (mysql ou pgsql)
* * \param host addresse de la base de donnees
* @param string $type Type of database (mysql, pgsql...) * \param user nom de l'utilisateur autorise
* @param string $host Address of database server * \param pass mot de passe
* @param string $user Nom de l'utilisateur autorise * \param name nom de la database
* @param string $pass Mot de passe * \param port Port of database server
* @param string $name Nom de la database * \return int 1 en cas de succes, 0 sinon
* @param int $port Port of database server
* @return int 1 if OK, 0 if not
*/ */
function DoliDb($type='pgsql', $host, $user, $pass, $name='', $port=0) function DoliDb($type='pgsql', $host, $user, $pass, $name='', $port=0)
{ {
@ -148,13 +146,12 @@ class DoliDb
} }
/** /**
* Convert a SQL request in Mysql syntax to native syntax * Convert a SQL request in Mysql syntax to PostgreSQL syntax
* * @param line SQL request line to convert
* @param string $line SQL request line to convert * @param type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
* @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) * @return string SQL request line converted
* @return string SQL request line converted */
*/
function convertSQLFromMysql($line,$type='auto') function convertSQLFromMysql($line,$type='auto')
{ {
# Removed empty line if this is a comment line for SVN tagging # Removed empty line if this is a comment line for SVN tagging
@ -324,12 +321,11 @@ class DoliDb
} }
/** /**
* Select a database * Select a database.
* Ici postgresql n'a aucune fonction equivalente de mysql_select_db * Ici postgresql n'a aucune fonction equivalente de mysql_select_db
* On compare juste manuellement si la database choisie est bien celle activee par la connexion * On compare juste manuellement si la database choisie est bien celle activee par la connexion
* * @param database nom de la database
* @param string $database Name of database * @return boolean true si ok, false si ko
* @return boolean true if OK, false if KO
*/ */
function select_db($database) function select_db($database)
{ {
@ -338,15 +334,13 @@ class DoliDb
} }
/** /**
* Connexion to server * Connection vers le serveur
* * @param host addresse de la base de donnees
* @param string $host database server host * @param login nom de l'utilisateur autorise
* @param string $login login * @param passwd mot de passe
* @param string $passwd password * @param name nom de la database (ne sert pas sous mysql, sert sous pgsql)
* @param string $name name of database (not used for mysql, used for pgsql) * @param port Port of database server
* @param string $port Port of database server * @return resource handler d'acces a la base
* @return resource Database access handler
* @see close
*/ */
function connect($host, $login, $passwd, $name, $port=0) function connect($host, $login, $passwd, $name, $port=0)
{ {
@ -370,9 +364,8 @@ class DoliDb
} }
/** /**
* Return label of manager * \brief Return label of manager
* * \return string Label
* @return string Label
*/ */
function getLabel() function getLabel()
{ {
@ -380,9 +373,8 @@ class DoliDb
} }
/** /**
* Return version of database server * \brief Return version of server
* * \return string String with version
* @return string Version string
*/ */
function getVersion() function getVersion()
{ {
@ -396,9 +388,25 @@ class DoliDb
} }
/** /**
* Return version of database server into an array * \brief Renvoie la version du serveur sous forme de nombre
* * \return string Chaine version
* @return array Version array */
function getIntVersion()
{
$version = $this->getVersion();
$vlist = preg_split('/[.-]/',$version);
if (dol_strlen($vlist[1])==1){
$vlist[1]="0".$vlist[1];
}
if (dol_strlen($vlist[2])==1){
$vlist[2]="0".$vlist[2];
}
return $vlist[0].$vlist[1].$vlist[2];
}
/**
* \brief Renvoie la version du serveur dans un tableau
* \return array Tableau de chaque niveau de version
*/ */
function getVersionArray() function getVersionArray()
{ {
@ -407,7 +415,6 @@ class DoliDb
/** /**
* Close database connexion * Close database connexion
*
* @return boolean True if disconnect successfull, false otherwise * @return boolean True if disconnect successfull, false otherwise
* @see connect * @see connect
*/ */
@ -423,9 +430,8 @@ class DoliDb
} }
/** /**
* Start transaction * \brief Debut d'une transaction.
* * \return int 1 si ouverture transaction ok ou deja ouverte, 0 en cas d'erreur
* @return int 1 if transaction successfuly opened or already opened, 0 if error
*/ */
function begin() function begin()
{ {
@ -448,7 +454,6 @@ class DoliDb
/** /**
* Validate a database transaction * Validate a database transaction
*
* @param log Add more log to default log line * @param log Add more log to default log line
* @return int 1 if validation is OK or transaction level no started, 0 if ERROR * @return int 1 if validation is OK or transaction level no started, 0 if ERROR
*/ */
@ -472,8 +477,8 @@ class DoliDb
} }
/** /**
* Annulation d'une transaction et retour aux anciennes valeurs * \brief Annulation d'une transaction et retour aux anciennes valeurs
* @return int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur * \return int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur
*/ */
function rollback() function rollback()
{ {
@ -493,8 +498,7 @@ class DoliDb
/** /**
* Convert request to PostgreSQL syntax, execute it and return the resultset * Convert request to PostgreSQL syntax, execute it and return the resultset.
*
* @param query SQL query string * @param query SQL query string
* @param usesavepoint 0=Default mode, 1=Run a savepoint before and a rollback to savepoint if error (this allow to have some request with errors inside global transactions). * @param usesavepoint 0=Default mode, 1=Run a savepoint before and a rollback to savepoint if error (this allow to have some request with errors inside global transactions).
* @param type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) * @param type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
@ -551,10 +555,9 @@ class DoliDb
} }
/** /**
* Renvoie la ligne courante (comme un objet) pour le curseur resultset * \brief Renvoie la ligne courante (comme un objet) pour le curseur resultset.
* * \param resultset Curseur de la requete voulue
* @param resultset Curseur de la requete voulue * \return object Object result line or false if KO or end of cursor
* @return object Object result line or false if KO or end of cursor
*/ */
function fetch_object($resultset) function fetch_object($resultset)
{ {
@ -564,10 +567,9 @@ class DoliDb
} }
/** /**
* Renvoie les donnees dans un tableau * \brief Renvoie les donnees dans un tableau.
* * \param resultset Curseur de la requete voulue
* @param resultset Curseur de la requete voulue * \return array
* @return array
*/ */
function fetch_array($resultset) function fetch_array($resultset)
{ {
@ -577,10 +579,9 @@ class DoliDb
} }
/** /**
* Renvoie les donnees comme un tableau * \brief Renvoie les donnees comme un tableau.
* * \param resultset Curseur de la requete voulue
* @param resultset Curseur de la requete voulue * \return array
* @return array
*/ */
function fetch_row($resultset) function fetch_row($resultset)
{ {
@ -590,11 +591,10 @@ class DoliDb
} }
/** /**
* Renvoie le nombre de lignes dans le resultat d'une requete SELECT * \brief Renvoie le nombre de lignes dans le resultat d'une requete SELECT
* * \see affected_rows
* @see affected_rows * \param resultset Curseur de la requete voulue
* @param resultset Curseur de la requete voulue * \return int Nombre de lignes
* @return int Nombre de lignes
*/ */
function num_rows($resultset) function num_rows($resultset)
{ {
@ -604,11 +604,10 @@ class DoliDb
} }
/** /**
* Renvoie le nombre de lignes dans le resultat d'une requete INSERT, DELETE ou UPDATE * \brief Renvoie le nombre de lignes dans le resultat d'une requete INSERT, DELETE ou UPDATE
* * \see num_rows
* @see num_rows * \param resultset Curseur de la requete voulue
* @param resultset Curseur de la requete voulue * \return int Nombre de lignes
* @return int Nombre de lignes
*/ */
function affected_rows($resultset) function affected_rows($resultset)
{ {
@ -621,9 +620,8 @@ class DoliDb
/** /**
* Libere le dernier resultset utilise sur cette connexion * \brief Libere le dernier resultset utilise sur cette connexion.
* * \param resultset Curseur de la requete voulue
* @param resultset Curseur de la requete voulue
*/ */
function free($resultset=0) function free($resultset=0)
{ {
@ -635,11 +633,10 @@ class DoliDb
/** /**
* Defini les limites de la requete * \brief Defini les limites de la requete.
* * \param limit nombre maximum de lignes retournees
* @param limit nombre maximum de lignes retournees * \param offset numero de la ligne a partir de laquelle recuperer les lignes
* @param offset numero de la ligne a partir de laquelle recuperer les lignes * \return string chaine exprimant la syntax sql de la limite
* @return string chaine exprimant la syntax sql de la limite
*/ */
function plimit($limit=0,$offset=0) function plimit($limit=0,$offset=0)
{ {
@ -652,7 +649,6 @@ class DoliDb
/** /**
* Define sort criteria of request * Define sort criteria of request
*
* @param sortfield List of sort fields * @param sortfield List of sort fields
* @param sortorder Sort order * @param sortorder Sort order
* @return string String to provide syntax of a sort sql string * @return string String to provide syntax of a sort sql string
@ -682,8 +678,7 @@ class DoliDb
/** /**
* Escape a string to insert data * Escape a string to insert data.
*
* @param stringtoencode String to escape * @param stringtoencode String to escape
* @return string String escaped * @return string String escaped
*/ */
@ -695,7 +690,6 @@ class DoliDb
/** /**
* Convert (by PHP) a GM Timestamp date into a GM string date to insert into a date field. * Convert (by PHP) a GM Timestamp date into a GM string date to insert into a date field.
* Function to use to build INSERT, UPDATE or WHERE predica * Function to use to build INSERT, UPDATE or WHERE predica
*
* @param param Date TMS to convert * @param param Date TMS to convert
* @return string Date in a string YYYYMMDDHHMMSS * @return string Date in a string YYYYMMDDHHMMSS
*/ */
@ -707,7 +701,6 @@ class DoliDb
/** /**
* Convert (by PHP) a PHP server TZ string date into a GM Timestamps date * Convert (by PHP) a PHP server TZ string date into a GM Timestamps date
* 19700101020000 -> 3600 with TZ+1 * 19700101020000 -> 3600 with TZ+1
*
* @param string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS) * @param string Date in a string (YYYYMMDDHHMMSS, YYYYMMDD, YYYY-MM-DD HH:MM:SS)
* @return date Date TMS * @return date Date TMS
*/ */
@ -721,7 +714,6 @@ class DoliDb
/** /**
* Formate a SQL IF * Formate a SQL IF
*
* @param test chaine test * @param test chaine test
* @param resok resultat si test egal * @param resok resultat si test egal
* @param resko resultat si test non egal * @param resko resultat si test non egal
@ -734,9 +726,8 @@ class DoliDb
/** /**
* Renvoie la derniere requete soumise par la methode query() * \brief Renvoie la derniere requete soumise par la methode query()
* * \return lastquery
* @return lastquery
*/ */
function lastquery() function lastquery()
{ {
@ -744,9 +735,8 @@ class DoliDb
} }
/** /**
* Renvoie la derniere requete en erreur * \brief Renvoie la derniere requete en erreur
* * \return string lastqueryerror
* @return string lastqueryerror
*/ */
function lastqueryerror() function lastqueryerror()
{ {
@ -754,9 +744,8 @@ class DoliDb
} }
/** /**
* Renvoie le libelle derniere erreur * \brief Renvoie le libelle derniere erreur
* * \return string lasterror
* @return string lasterror
*/ */
function lasterror() function lasterror()
{ {
@ -764,9 +753,8 @@ class DoliDb
} }
/** /**
* Renvoie le code derniere erreur * \brief Renvoie le code derniere erreur
* * \return string lasterrno
* @return string lasterrno
*/ */
function lasterrno() function lasterrno()
{ {
@ -774,9 +762,8 @@ class DoliDb
} }
/** /**
* Renvoie le code erreur generique de l'operation precedente. * \brief Renvoie le code erreur generique de l'operation precedente.
* * \return error_num (Exemples: DB_ERROR_TABLE_ALREADY_EXISTS, DB_ERROR_RECORD_ALREADY_EXISTS...)
* @return error_num (Exemples: DB_ERROR_TABLE_ALREADY_EXISTS, DB_ERROR_RECORD_ALREADY_EXISTS...)
*/ */
function errno() function errno()
{ {
@ -840,9 +827,8 @@ class DoliDb
} }
/** /**
* Renvoie le texte de l'erreur pgsql de l'operation precedente * \brief Renvoie le texte de l'erreur pgsql de l'operation precedente.
* * \return error_text
* @return error_text
*/ */
function error() function error()
{ {
@ -850,10 +836,9 @@ class DoliDb
} }
/** /**
* Get last ID after an insert INSERT * \brief Get last ID after an insert INSERT.
* * \param tab Table name concerned by insert. Ne sert pas sous MySql mais requis pour compatibilite avec Postgresql
* @param tab Table name concerned by insert. Ne sert pas sous MySql mais requis pour compatibilite avec Postgresql * \return int id
* @return int id
*/ */
function last_insert_id($tab,$fieldid='rowid') function last_insert_id($tab,$fieldid='rowid')
{ {
@ -872,7 +857,6 @@ class DoliDb
/** /**
* Encrypt sensitive data in database * Encrypt sensitive data in database
* Warning: This function includes the escape, so it must use direct value * Warning: This function includes the escape, so it must use direct value
*
* @param fieldorvalue Field name or value to encrypt * @param fieldorvalue Field name or value to encrypt
* @param withQuotes Return string with quotes * @param withQuotes Return string with quotes
* @return return XXX(field) or XXX('value') or field or 'value' * @return return XXX(field) or XXX('value') or field or 'value'
@ -893,10 +877,9 @@ class DoliDb
/** /**
* Decrypt sensitive data in database * \brief Decrypt sensitive data in database
* * \param value Value to decrypt
* @param value Value to decrypt * \return return Decrypted value if used
* @return return Decrypted value if used
*/ */
function decrypt($value) function decrypt($value)
{ {
@ -918,9 +901,8 @@ class DoliDb
/** /**
* Renvoie l'id de la connexion * \brief Renvoie l'id de la connexion
* * \return string Id connexion
* @return string Id connexion
*/ */
function DDLGetConnectId() function DDLGetConnectId()
{ {
@ -930,14 +912,13 @@ class DoliDb
/** /**
* Create a new database * \brief Create a new database
* Ne pas utiliser les fonctions xxx_create_db (xxx=mysql, ...) car elles sont deprecated * \param database Database name to create
* * \param charset Charset used to store data
* @param database Database name to create * \param collation Charset used to sort data
* @param charset Charset used to store data * \param owner Username of database owner
* @param collation Charset used to sort data * \return resource resource defined if OK, null if KO
* @param owner Username of database owner * \remarks Ne pas utiliser les fonctions xxx_create_db (xxx=mysql, ...) car elles sont deprecated
* @return resource resource defined if OK, null if KO
*/ */
function DDLCreateDb($database,$charset='',$collation='',$owner='') function DDLCreateDb($database,$charset='',$collation='',$owner='')
{ {
@ -949,9 +930,9 @@ class DoliDb
} }
/** /**
* Liste des tables dans une database. * \brief Liste des tables dans une database.
* @param database Nom de la database * \param database Nom de la database
* @return resource * \return resource
*/ */
function DDLListTables($database, $table='') function DDLListTables($database, $table='')
{ {
@ -968,9 +949,9 @@ class DoliDb
} }
/** /**
* Liste les informations des champs d'une table. * \brief Liste les informations des champs d'une table.
* @param table Nom de la table * \param table Nom de la table
* @return array Tableau des informations des champs de la table * \return array Tableau des informations des champs de la table
* TODO modifier pour postgresql * TODO modifier pour postgresql
*/ */
function DDLInfoTable($table) function DDLInfoTable($table)
@ -992,16 +973,15 @@ class DoliDb
/** /**
* Cree une table * \brief Cree une table
* * \param table Nom de la table
* @param table Nom de la table * \param fields Tableau associatif [nom champ][tableau des descriptions]
* @param fields Tableau associatif [nom champ][tableau des descriptions] * \param primary_key Nom du champ qui sera la clef primaire
* @param primary_key Nom du champ qui sera la clef primaire * \param unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur
* @param unique_keys Tableau associatifs Nom de champs qui seront clef unique => valeur * \param fulltext Tableau des Nom de champs qui seront indexes en fulltext
* @param fulltext Tableau des Nom de champs qui seront indexes en fulltext * \param key Tableau des champs cles noms => valeur
* @param key Tableau des champs cles noms => valeur * \param type Type de la table
* @param type Type de la table * \return int <0 si KO, >=0 si OK
* @return int <0 si KO, >=0 si OK
* TODO * TODO
*/ */
function DDLCreateTable($table,$fields,$primary_key,$type,$unique_keys="",$fulltext_keys="",$keys="") function DDLCreateTable($table,$fields,$primary_key,$type,$unique_keys="",$fulltext_keys="",$keys="")
@ -1070,13 +1050,12 @@ class DoliDb
} }
/** /**
* Create a user * \brief Create a user
* * \param dolibarr_main_db_host Ip serveur
* @param dolibarr_main_db_host Ip serveur * \param dolibarr_main_db_user Nom user a creer
* @param dolibarr_main_db_user Nom user a creer * \param dolibarr_main_db_pass Mot de passe user a creer
* @param dolibarr_main_db_pass Mot de passe user a creer * \param dolibarr_main_db_name Database name where user must be granted
* @param dolibarr_main_db_name Database name where user must be granted * \return int <0 si KO, >=0 si OK
* @return int <0 si KO, >=0 si OK
*/ */
function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name) function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name)
{ {
@ -1093,11 +1072,10 @@ class DoliDb
} }
/** /**
* Decrit une table dans une database * \brief decrit une table dans une database.
* * \param table Nom de la table
* @param table Nom de la table * \param field Optionnel : Nom du champ si l'on veut la desc d'un champ
* @param field Optionnel : Nom du champ si l'on veut la desc d'un champ * \return resource
* @return resource
*/ */
function DDLDescTable($table,$field="") function DDLDescTable($table,$field="")
{ {
@ -1111,13 +1089,12 @@ class DoliDb
} }
/** /**
* Insert a new field in table * \brief Insert a new field in table
* * \param table Nom de la table
* @param table Nom de la table * \param field_name Nom du champ a inserer
* @param field_name Nom du champ a inserer * \param field_desc Tableau associatif de description du champ a inserer[nom du parametre][valeur du parametre]
* @param field_desc Tableau associatif de description du champ a inserer[nom du parametre][valeur du parametre] * \param field_position Optionnel ex.: "after champtruc"
* @param field_position Optionnel ex.: "after champtruc" * \return int <0 si KO, >0 si OK
* @return int <0 si KO, >0 si OK
*/ */
function DDLAddField($table,$field_name,$field_desc,$field_position="") function DDLAddField($table,$field_name,$field_desc,$field_position="")
{ {
@ -1149,7 +1126,6 @@ class DoliDb
/** /**
* Update format of a field into a table * Update format of a field into a table
*
* @param table Name of table * @param table Name of table
* @param field_name Name of field to modify * @param field_name Name of field to modify
* @param field_desc Array with description of field format * @param field_desc Array with description of field format
@ -1169,11 +1145,10 @@ class DoliDb
} }
/** /**
* Drop a field in table * \brief Drop a field in table
* * \param table Nom de la table
* @param table Nom de la table * \param field_name Nom du champ a inserer
* @param field_name Nom du champ a inserer * \return int <0 si KO, >0 si OK
* @return int <0 si KO, >0 si OK
*/ */
function DDLDropField($table,$field_name) function DDLDropField($table,$field_name)
{ {
@ -1188,9 +1163,8 @@ class DoliDb
} }
/** /**
* Return charset used to store data in database * \brief Return charset used to store data in database
* * \return string Charset
* @return string Charset
*/ */
function getDefaultCharacterSetDatabase() function getDefaultCharacterSetDatabase()
{ {
@ -1200,9 +1174,8 @@ class DoliDb
} }
/** /**
* Return list of available charset that can be used to store data in database * \brief Return list of available charset that can be used to store data in database
* * \return array List of Charset
* @return array List of Charset
*/ */
function getListOfCharacterSet() function getListOfCharacterSet()
{ {
@ -1225,9 +1198,8 @@ class DoliDb
} }
/** /**
* Return collation used in database * \brief Return collation used in database
* * \return string Collation value
* @return string Collation value
*/ */
function getDefaultCollationDatabase() function getDefaultCollationDatabase()
{ {
@ -1237,9 +1209,8 @@ class DoliDb
} }
/** /**
* Return list of available collation that can be used for database * \brief Return list of available collation that can be used for database
* * \return array Liste of Collation
* @return array Liste of Collation
*/ */
function getListOfCollation() function getListOfCollation()
{ {
@ -1262,7 +1233,6 @@ class DoliDb
/** /**
* Return full path of dump program * Return full path of dump program
*
* @return string Full path of dump program * @return string Full path of dump program
*/ */
function getPathOfDump() function getPathOfDump()
@ -1290,7 +1260,6 @@ class DoliDb
/** /**
* Return full path of restore program * Return full path of restore program
*
* @return string Full path of restore program * @return string Full path of restore program
*/ */
function getPathOfRestore() function getPathOfRestore()
@ -1317,10 +1286,9 @@ class DoliDb
} }
/** /**
* Return value of server parameters * \brief Return value of server parameters
* * \param filter Filter list on a particular value
* @param filter Filter list on a particular value * \return string Value for parameter
* @return string Value for parameter
*/ */
function getServerParametersValues($filter='') function getServerParametersValues($filter='')
{ {

View File

@ -58,10 +58,10 @@ function dol_shutdown()
/** /**
* Return value of a param into GET or POST supervariable * Return value of a param into GET or POST supervariable
* *
* @param string $paramname Name of parameter to found * @param paramname Name of parameter to found
* @param string $check Type of check (''=no check, 'int'=check it's numeric, 'alpha'=check it's alpha only) * @param check Type of check (''=no check, 'int'=check it's numeric, 'alpha'=check it's alpha only)
* @param int $method Type of method (0 = get then post, 1 = only get, 2 = only post, 3 = post then get) * @param method Type of method (0 = get then post, 1 = only get, 2 = only post, 3 = post then get)
* @return string Value found or '' if check fails * @return string Value found or '' if check fails
*/ */
function GETPOST($paramname,$check='',$method=0) function GETPOST($paramname,$check='',$method=0)
{ {
@ -88,7 +88,7 @@ function GETPOST($paramname,$check='',$method=0)
* This prefix is unique for instance and avoid conflict between multi-instances, * This prefix is unique for instance and avoid conflict between multi-instances,
* even when having two instances with one root dir or two instances in virtual servers * even when having two instances with one root dir or two instances in virtual servers
* *
* @return string A calculated prefix * @return string A calculated prefix
*/ */
function dol_getprefix() function dol_getprefix()
{ {
@ -102,8 +102,8 @@ function dol_getprefix()
* To link to a module file from a module file, use include('./mymodulefile'); * To link to a module file from a module file, use include('./mymodulefile');
* To link to a module file from a core file, then this function can be used * To link to a module file from a core file, then this function can be used
* *
* @param string $relpath Relative path to file (Ie: mydir/myfile, ../myfile, ...) * @param relpath Relative path to file (Ie: mydir/myfile, ../myfile, ...)
* @return int false if include fails. * @return int false if include fails.
*/ */
function dol_include_once($relpath) function dol_include_once($relpath)
{ {
@ -115,9 +115,9 @@ function dol_include_once($relpath)
/** /**
* Return path of url or filesystem. Return default_root or alternate root if file_exist fails * Return path of url or filesystem. Return default_root or alternate root if file_exist fails
* *
* @param string $path Relative path to file (if mode=0, ie: mydir/myfile, ../myfile, ...) or relative url (if mode=1). * @param path Relative path to file (if mode=0, ie: mydir/myfile, ../myfile, ...) or relative url (if mode=1).
* @param int $type 0=Used for a Filesystem path, 1=Used for an URL path (output relative), 2=Used for an URL path (output full path) * @param type 0=Used for a Filesystem path, 1=Used for an URL path (output relative), 2=Used for an URL path (output full path)
* @return string Full filsystem path (if mode=0), Full url path (if mode=1) * @return string Full filsystem path (if mode=0), Full url path (if mode=1)
*/ */
function dol_buildpath($path,$type=0) function dol_buildpath($path,$type=0)
{ {
@ -168,8 +168,8 @@ function dol_buildpath($path,$type=0)
* Create a clone of instance of object (new instance with same properties) * Create a clone of instance of object (new instance with same properties)
* This function works for both PHP4 and PHP5 * This function works for both PHP4 and PHP5
* *
* @param object $object Object to clone * @param object Object to clone
* @return object Object clone * @return date Timestamp
*/ */
function dol_clone($object) function dol_clone($object)
{ {
@ -187,11 +187,11 @@ function dol_clone($object)
/** /**
* Optimize a size for some browsers (phone, smarphone, ...) * Optimize a size for some browsers (phone, smarphone, ...)
* *
* @param int $size Size we want * @param size Size we want
* @param string $type Type of optimizing: * @param type Type of optimizing:
* '' = function used to define a size for truncation * '' = function used to define a size for truncation
* 'width' = function is used to define a width * 'width' = function is used to define a width
* @return int New size after optimizing * @return int New size after optimizing
*/ */
function dol_size($size,$type='') function dol_size($size,$type='')
{ {
@ -318,8 +318,8 @@ function dol_string_nospecial($str,$newstr='_',$badchars='')
/** /**
* Returns text escaped for inclusion into javascript code * Returns text escaped for inclusion into javascript code
* *
* @param string $stringtoescape String to escape * @param $stringtoescape String to escape
* @return string Escaped string * @return string Escaped string
*/ */
function dol_escape_js($stringtoescape) function dol_escape_js($stringtoescape)
{ {
@ -332,9 +332,9 @@ function dol_escape_js($stringtoescape)
/** /**
* Returns text escaped for inclusion in HTML alt or title tags * Returns text escaped for inclusion in HTML alt or title tags
* *
* @param string $stringtoescape String to escape * @param $stringtoescape String to escape
* @param int $keepb Do not clean b tags * @param $keepb Do not clean b tags
* @return string Escaped string * @return string Escaped string
*/ */
function dol_escape_htmltag($stringtoescape,$keepb=0) function dol_escape_htmltag($stringtoescape,$keepb=0)
{ {
@ -358,8 +358,8 @@ function dol_escape_htmltag($stringtoescape,$keepb=0)
* On Windows LOG_ERR=4, LOG_WARNING=5, LOG_NOTICE=LOG_INFO=6, LOG_DEBUG=6 si define_syslog_variables ou PHP 5.3+, 7 si dolibarr * On Windows LOG_ERR=4, LOG_WARNING=5, LOG_NOTICE=LOG_INFO=6, LOG_DEBUG=6 si define_syslog_variables ou PHP 5.3+, 7 si dolibarr
* On Linux LOG_ERR=3, LOG_WARNING=4, LOG_INFO=6, LOG_DEBUG=7 * On Linux LOG_ERR=3, LOG_WARNING=4, LOG_INFO=6, LOG_DEBUG=7
* *
* @param string $message Line to log. Ne doit pas etre traduit si level = LOG_ERR * @param string message Line to log. Ne doit pas etre traduit si level = LOG_ERR
* @param int $level Log level * @param int level Log level
*/ */
function dol_syslog($message, $level=LOG_INFO) function dol_syslog($message, $level=LOG_INFO)
{ {
@ -469,7 +469,6 @@ function dol_syslog($message, $level=LOG_INFO)
/** /**
* Show tab header of a card * Show tab header of a card
*
* @param links Array of tabs * @param links Array of tabs
* @param active Active tab name * @param active Active tab name
* @param title Title * @param title Title
@ -483,7 +482,6 @@ function dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto
/** /**
* Show tab header of a card * Show tab header of a card
*
* @param links Array of tabs * @param links Array of tabs
* @param active Active tab name * @param active Active tab name
* @param title Title * @param title Title
@ -550,8 +548,7 @@ function dol_get_fiche_head($links=array(), $active='0', $title='', $notab=0, $p
/** /**
* Show tab footer of a card * Show tab footer of a card
* * @param notab 0=Add tab footer, 1=no tab footer
* @param int $notab 0=Add tab footer, 1=no tab footer
*/ */
function dol_fiche_end($notab=0) function dol_fiche_end($notab=0)
{ {
@ -560,8 +557,7 @@ function dol_fiche_end($notab=0)
/** /**
* Return tab footer of a card * Return tab footer of a card
* * @param notab 0=Add tab footer, 1=no tab footer
* @param int $notab 0=Add tab footer, 1=no tab footer
*/ */
function dol_get_fiche_end($notab=0) function dol_get_fiche_end($notab=0)
{ {
@ -578,8 +574,7 @@ function dolibarr_print_date($time,$format='',$to_gmt=false,$outputlangs='',$enc
/** /**
* Output date in a string format according to outputlangs (or langs if not defined). * Output date in a string format according to outputlangs (or langs if not defined).
* Return charset is always UTF-8, except if encodetoouput is defined. In this cas charset is output charset * Return charset is always UTF-8, except if encodetoouput is defined. In this cas charset is output charset.
*
* @param time GM Timestamps date (or deprecated strings 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS') * @param time GM Timestamps date (or deprecated strings 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS')
* @param format Output date format * @param format Output date format
* "%d %b %Y", * "%d %b %Y",
@ -726,7 +721,6 @@ function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$e
/** /**
* Convert a string date into a GM Timestamps date * Convert a string date into a GM Timestamps date
*
* @param string Date in a string * @param string Date in a string
* YYYYMMDD * YYYYMMDD
* YYYYMMDDHHMMSS * YYYYMMDDHHMMSS
@ -777,8 +771,7 @@ function dol_stringtotime($string, $gm=1)
/** /**
* Return an array with date info * Return an array with date info
* PHP getdate is restricted to the years 1901-2038 on Unix and 1970-2038 on Windows * PHP getdate is restricted to the years 1901-2038 on Unix and 1970-2038 on Windows.
*
* @param timestamp Timestamp * @param timestamp Timestamp
* @param fast Fast mode * @param fast Fast mode
* @return array Array of informations * @return array Array of informations
@ -832,7 +825,6 @@ function dolibarr_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$chec
* Return a timestamp date built from detailed informations (by default a local PHP server timestamp) * Return a timestamp date built from detailed informations (by default a local PHP server timestamp)
* Replace function mktime not available under Windows if year < 1970 * Replace function mktime not available under Windows if year < 1970
* PHP mktime is restricted to the years 1901-2038 on Unix and 1970-2038 on Windows * PHP mktime is restricted to the years 1901-2038 on Unix and 1970-2038 on Windows
*
* @param hour Hour (can be -1 for undefined) * @param hour Hour (can be -1 for undefined)
* @param minute Minute (can be -1 for undefined) * @param minute Minute (can be -1 for undefined)
* @param second Second (can be -1 for undefined) * @param second Second (can be -1 for undefined)
@ -898,7 +890,6 @@ function dolibarr_date($fmt, $timestamp, $gm=false)
/** /**
* Returns formated date * Returns formated date
*
* @param fmt Format (Exemple: 'Y-m-d H:i:s') * @param fmt Format (Exemple: 'Y-m-d H:i:s')
* @param timestamp Date. Example: If timestamp=0 and gm=1, return 01/01/1970 00:00:00 * @param timestamp Date. Example: If timestamp=0 and gm=1, return 01/01/1970 00:00:00
* @param gm 1 if timestamp was built with gmmktime, 0 if timestamp was build with mktime * @param gm 1 if timestamp was built with gmmktime, 0 if timestamp was build with mktime
@ -926,7 +917,6 @@ function dol_date($fmt, $timestamp, $gm=false)
/** /**
* Return string with formated size * Return string with formated size
*
* @param size Size to print * @param size Size to print
* @param shortvalue Tell if we want long value to use another unit (Ex: 1.5Kb instead of 1500b) * @param shortvalue Tell if we want long value to use another unit (Ex: 1.5Kb instead of 1500b)
* @param shortunit Use short value of size unit * @param shortunit Use short value of size unit
@ -959,7 +949,6 @@ function dol_print_size($size,$shortvalue=0,$shortunit=0)
/** /**
* Show Url link * Show Url link
*
* @param url Url to show * @param url Url to show
* @param target Target for link * @param target Target for link
* @param max Max number of characters to show * @param max Max number of characters to show
@ -981,7 +970,6 @@ function dol_print_url($url,$target='_blank',$max=32)
/** /**
* Show EMail link * Show EMail link
*
* @param email EMail to show (only email, without 'Name of recipient' before) * @param email EMail to show (only email, without 'Name of recipient' before)
* @param cid Id of contact if known * @param cid Id of contact if known
* @param socid Id of third party if known * @param socid Id of third party if known
@ -1038,7 +1026,6 @@ function dolibarr_print_phone($phone,$country="FR",$cid=0,$socid=0,$addlink=0,$s
/** /**
* Format phone numbers according to country * Format phone numbers according to country
*
* @param phone Phone number to format * @param phone Phone number to format
* @param country Country to use for formatting * @param country Country to use for formatting
* @param cid Id of contact if known * @param cid Id of contact if known
@ -1117,7 +1104,6 @@ function dol_print_phone($phone,$country="FR",$cid=0,$socid=0,$addlink=0,$separ=
/** /**
* Return an IP formated to be shown on screen * Return an IP formated to be shown on screen
*
* @param ip IP * @param ip IP
* @param mode 1=return only country/flag,2=return only IP * @param mode 1=return only country/flag,2=return only IP
* @return string Formated IP, with country if GeoIP module is enabled * @return string Formated IP, with country if GeoIP module is enabled
@ -1157,7 +1143,6 @@ function dol_print_ip($ip,$mode=0)
/** /**
* Return country code for current user. * Return country code for current user.
* If software is used inside a local network, detection may fails (we need a public ip) * If software is used inside a local network, detection may fails (we need a public ip)
*
* @return string country code (fr, es, it, us, ...) * @return string country code (fr, es, it, us, ...)
*/ */
function dol_user_country() function dol_user_country()
@ -1182,7 +1167,6 @@ function dol_user_country()
/** /**
* Format address string * Format address string
*
* @param address Address * @param address Address
* @param htmlid Html ID * @param htmlid Html ID
* @param mode thirdparty|contact|member|other * @param mode thirdparty|contact|member|other
@ -1228,10 +1212,9 @@ function dol_print_address($address, $htmlid='gmap', $mode, $id)
/** /**
* Return true if email syntax is ok * Return true if email syntax is ok.
* * @param address email (Ex: "toto@titi.com", "John Do <johndo@titi.com>")
* @param string $address email (Ex: "toto@titi.com", "John Do <johndo@titi.com>") * @return boolean true if email syntax is OK, false if KO or empty string
* @return boolean true if email syntax is OK, false if KO or empty string
*/ */
function isValidEmail($address) function isValidEmail($address)
{ {
@ -1251,10 +1234,9 @@ function isValidEmail($address)
} }
/** /**
* Return true if phone number syntax is ok * Return true if phone number syntax is ok.
* * @param address phone (Ex: "0601010101")
* @param string $address phone (Ex: "0601010101") * @return boolean true if phone syntax is OK, false if KO or empty string
* @return boolean true if phone syntax is OK, false if KO or empty string
*/ */
function isValidPhone($address) function isValidPhone($address)
{ {
@ -1263,11 +1245,10 @@ function isValidPhone($address)
/** /**
* Make a strlen call. Works even if mbstring module not enabled * Make a strlen call. Works even if mbstring module not enabled.
* * @param $string
* @param string $string String to calculate length * @param $stringencoding
* @param string $stringencoding Encoding of string * @return int
* @return int Length of string
*/ */
function dol_strlen($string,$stringencoding='UTF-8') function dol_strlen($string,$stringencoding='UTF-8')
{ {
@ -1279,7 +1260,6 @@ function dol_strlen($string,$stringencoding='UTF-8')
/** /**
* Make a substring. Works even in mbstring module not enabled * Make a substring. Works even in mbstring module not enabled
*
* @param $string * @param $string
* @param $start * @param $start
* @param $length * @param $length
@ -2586,9 +2566,9 @@ function getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $m
{ {
global $conf; global $conf;
//print "$name, $file, $field, $begin, $options, $td, $sortfield, $sortorder<br>\n"; //print "$name, $file, $field, $begin, $options, $td, $sortfield, $sortorder<br>\n";
$out=''; $out='';
if ($thead) if ($thead)
{ {
$out.= '<th>'.$name.'</th>'; $out.= '<th>'.$name.'</th>';
@ -2606,7 +2586,7 @@ function getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $m
$out.= '<td class="liste_titre" '. $td.'>'; $out.= '<td class="liste_titre" '. $td.'>';
} }
$out.= $name; $out.= $name;
// If this is a sort field // If this is a sort field
if ($field) if ($field)
{ {
@ -2614,7 +2594,7 @@ function getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $m
$options=preg_replace('/sortorder=([a-zA-Z0-9,\s\.]+)/i','',$options); $options=preg_replace('/sortorder=([a-zA-Z0-9,\s\.]+)/i','',$options);
$options=preg_replace('/&+/i','&',$options); $options=preg_replace('/&+/i','&',$options);
if (! preg_match('/^&/',$options)) $options='&'.$options; if (! preg_match('/^&/',$options)) $options='&'.$options;
//print "&nbsp;"; //print "&nbsp;";
$out.= '<img width="2" src="'.DOL_URL_ROOT.'/theme/common/transparent.png" alt="">'; $out.= '<img width="2" src="'.DOL_URL_ROOT.'/theme/common/transparent.png" alt="">';
if (! $sortorder) if (! $sortorder)
@ -2644,7 +2624,7 @@ function getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $m
} }
$out.= "</td>"; $out.= "</td>";
} }
return $out; return $out;
} }