2
0
forked from Wavyzz/dolibarr

Fix: code more simple

This commit is contained in:
Regis Houssin
2009-12-23 01:12:47 +00:00
parent a58e465b27
commit 10ae9fe93b
14 changed files with 143 additions and 95 deletions

View File

@@ -265,12 +265,12 @@ function form_constantes($tableau)
{ {
$sql = "SELECT "; $sql = "SELECT ";
$sql.= "rowid"; $sql.= "rowid";
$sql.= ", ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as name"; $sql.= ", ".$db->decrypt('name')." as name";
$sql.= ", ".$db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; $sql.= ", ".$db->decrypt('value')." as value";
$sql.= ", type"; $sql.= ", type";
$sql.= ", note"; $sql.= ", note";
$sql.= " FROM ".MAIN_DB_PREFIX."const"; $sql.= " FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".$const."'"; $sql.= " WHERE ".$db->decrypt('name')." = '".$const."'";
$sql.= " AND entity = ".$conf->entity; $sql.= " AND entity = ".$conf->entity;
$result = $db->query($sql); $result = $db->query($sql);

View File

@@ -151,8 +151,8 @@ print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
# Affiche lignes des constantes # Affiche lignes des constantes
$sql = "SELECT"; $sql = "SELECT";
$sql.= " rowid"; $sql.= " rowid";
$sql.= ", ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as name"; $sql.= ", ".$db->decrypt('name')." as name";
$sql.= ", ".$db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; $sql.= ", ".$db->decrypt('value')." as value";
$sql.= ", type"; $sql.= ", type";
$sql.= ", note"; $sql.= ", note";
$sql.= ", entity"; $sql.= ", entity";

View File

@@ -49,7 +49,7 @@ if ($_POST["action"] == 'set')
if ($_GET["action"] == 'unset') if ($_GET["action"] == 'unset')
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey); $sql.= " WHERE ".$db->decrypt('name');
$sql.= " LIKE 'EDITEUR_LIVRE_FORMAT_%'"; $sql.= " LIKE 'EDITEUR_LIVRE_FORMAT_%'";
$sql.= " AND rowid='".$_GET["id"]."';"; $sql.= " AND rowid='".$_GET["id"]."';";
if ($db->query($sql)) if ($db->query($sql))
@@ -94,9 +94,9 @@ $var=true;
$sql = "SELECT"; $sql = "SELECT";
$sql.= " rowid"; $sql.= " rowid";
$sql.= ", ".$db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; $sql.= ", ".$db->decrypt('value')." as value";
$sql.= " FROM ".MAIN_DB_PREFIX."const"; $sql.= " FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey); $sql.= " WHERE ".$db->decrypt('name');
$sql.= " LIKE 'EDITEUR_LIVRE_FORMAT_%'"; $sql.= " LIKE 'EDITEUR_LIVRE_FORMAT_%'";
$result = $db->query($sql); $result = $db->query($sql);

View File

@@ -50,8 +50,8 @@ print "</tr>\n";
$sql = "SELECT"; $sql = "SELECT";
$sql.= " rowid"; $sql.= " rowid";
$sql.= ", ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as name"; $sql.= ", ".$db->decrypt('name')." as name";
$sql.= ", ".$db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; $sql.= ", ".$db->decrypt('value')." as value";
$sql.= ", type"; $sql.= ", type";
$sql.= ", note"; $sql.= ", note";
$sql.= ", entity"; $sql.= ", entity";

View File

@@ -91,8 +91,8 @@ class Conf
* - En constante php (TODO a virer) * - En constante php (TODO a virer)
* - En $this->global->key=value * - En $this->global->key=value
*/ */
$sql = "SELECT ".$db->decrypt('name',$this->db->dolibarr_main_db_encryption,$this->db->dolibarr_main_db_cryptkey)." as name"; $sql = "SELECT ".$db->decrypt('name')." as name";
$sql.= ",".$db->decrypt('value',$this->db->dolibarr_main_db_encryption,$this->db->dolibarr_main_db_cryptkey)." as value, entity"; $sql.= ",".$db->decrypt('value')." as value, entity";
$sql.= " FROM ".MAIN_DB_PREFIX."const"; $sql.= " FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE entity IN (0,".$this->entity.")"; $sql.= " WHERE entity IN (0,".$this->entity.")";
$sql.= " ORDER BY entity"; // This is to have entity 0 first, then entity 1 that overwrite. $sql.= " ORDER BY entity"; // This is to have entity 0 first, then entity 1 that overwrite.

View File

@@ -379,15 +379,15 @@ class DolibarrModules
$entity = ((! empty($this->always_enabled) || ! empty($this->core_enabled)) ? 0 : $conf->entity); $entity = ((! empty($this->always_enabled) || ! empty($this->core_enabled)) ? 0 : $conf->entity);
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".$this->const_name."'"; $sql.= " WHERE ".$this->db->decrypt('name')." = '".$this->const_name."'";
$sql.= " AND entity in (0, ".$entity.")"; $sql.= " AND entity in (0, ".$entity.")";
dol_syslog("DolibarrModules::_active sql=".$sql, LOG_DEBUG); dol_syslog("DolibarrModules::_active sql=".$sql, LOG_DEBUG);
$this->db->query($sql); $this->db->query($sql);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible,entity) VALUES"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible,entity) VALUES";
$sql.= " (".$this->db->encrypt($this->const_name,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); $sql.= " (".$this->db->encrypt($this->const_name,1);
$sql.= ",".$this->db->encrypt('1',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); $sql.= ",".$this->db->encrypt('1',1);
$sql.= ",0,".$entity.")"; $sql.= ",0,".$entity.")";
dol_syslog("DolibarrModules::_active sql=".$sql, LOG_DEBUG); dol_syslog("DolibarrModules::_active sql=".$sql, LOG_DEBUG);
@@ -414,7 +414,7 @@ class DolibarrModules
$entity = ((! empty($this->always_enabled) || ! empty($this->core_enabled)) ? 0 : $conf->entity); $entity = ((! empty($this->always_enabled) || ! empty($this->core_enabled)) ? 0 : $conf->entity);
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".$this->const_name."'"; $sql.= " WHERE ".$this->db->decrypt('name')." = '".$this->const_name."'";
$sql.= " AND entity in (0, ".$entity.")"; $sql.= " AND entity in (0, ".$entity.")";
dol_syslog("DolibarrModules::_unactive sql=".$sql); dol_syslog("DolibarrModules::_unactive sql=".$sql);
@@ -611,7 +611,7 @@ class DolibarrModules
if ($this->style_sheet) if ($this->style_sheet)
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".$this->const_name."_CSS'"; $sql.= " WHERE ".$this->db->decrypt('name')." = '".$this->const_name."_CSS'";
$sql.= " AND entity = ".$conf->entity; $sql.= " AND entity = ".$conf->entity;
dol_syslog("DolibarrModules::delete_style_sheet sql=".$sql); dol_syslog("DolibarrModules::delete_style_sheet sql=".$sql);
@@ -637,7 +637,7 @@ class DolibarrModules
$err=0; $err=0;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." like '".$this->const_name."_TABS_%'"; $sql.= " WHERE ".$this->db->decrypt('name')." like '".$this->const_name."_TABS_%'";
$sql.= " AND entity = ".$conf->entity; $sql.= " AND entity = ".$conf->entity;
dol_syslog("DolibarrModules::delete_tabs sql=".$sql); dol_syslog("DolibarrModules::delete_tabs sql=".$sql);
@@ -672,9 +672,9 @@ class DolibarrModules
$sql.= ", entity"; $sql.= ", entity";
$sql.= ")"; $sql.= ")";
$sql.= " VALUES ("; $sql.= " VALUES (";
$sql.= $this->db->encrypt($this->const_name."_CSS",$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); $sql.= $this->db->encrypt($this->const_name."_CSS",1);
$sql.= ", 'chaine'"; $sql.= ", 'chaine'";
$sql.= ", ".$this->db->encrypt($this->style_sheet,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); $sql.= ", ".$this->db->encrypt($this->style_sheet,1);
$sql.= ", 'Style sheet for module ".$this->name."'"; $sql.= ", 'Style sheet for module ".$this->name."'";
$sql.= ", '0'"; $sql.= ", '0'";
$sql.= ", ".$conf->entity; $sql.= ", ".$conf->entity;
@@ -719,9 +719,9 @@ class DolibarrModules
$sql.= ", entity"; $sql.= ", entity";
$sql.= ")"; $sql.= ")";
$sql.= " VALUES ("; $sql.= " VALUES (";
$sql.= $this->db->encrypt($this->const_name."_TABS_".$i,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); $sql.= $this->db->encrypt($this->const_name."_TABS_".$i,1);
$sql.= ", 'chaine'"; $sql.= ", 'chaine'";
$sql.= ", ".$this->db->encrypt($value,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); $sql.= ", ".$this->db->encrypt($value,1);
$sql.= ", null"; $sql.= ", null";
$sql.= ", '0'"; $sql.= ", '0'";
$sql.= ", ".$conf->entity; $sql.= ", ".$conf->entity;
@@ -764,7 +764,7 @@ class DolibarrModules
$sql = "SELECT count(*)"; $sql = "SELECT count(*)";
$sql.= " FROM ".MAIN_DB_PREFIX."const"; $sql.= " FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".$name."'"; $sql.= " WHERE ".$this->db->decrypt('name')." = '".$name."'";
$sql.= " AND entity = ".$entity; $sql.= " AND entity = ".$entity;
$result=$this->db->query($sql); $result=$this->db->query($sql);
@@ -779,9 +779,9 @@ class DolibarrModules
{ {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,value,note,visible,entity)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,value,note,visible,entity)";
$sql.= " VALUES ("; $sql.= " VALUES (";
$sql.= $this->db->encrypt($name,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); $sql.= $this->db->encrypt($name,1);
$sql.= ",'".$type."'"; $sql.= ",'".$type."'";
$sql.= ",".$this->db->encrypt($val,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); $sql.= ",".$this->db->encrypt($val,1);
$sql.= ",'".addslashes($note)."'"; $sql.= ",'".addslashes($note)."'";
$sql.= ",'".$visible."'"; $sql.= ",'".$visible."'";
$sql.= ",".$entity; $sql.= ",".$entity;
@@ -791,9 +791,9 @@ class DolibarrModules
{ {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,value,visible,entity)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,value,visible,entity)";
$sql.= " VALUES ("; $sql.= " VALUES (";
$sql.= $this->db->encrypt($name,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); $sql.= $this->db->encrypt($name,1);
$sql.= ",'".$type."'"; $sql.= ",'".$type."'";
$sql.= ",".$this->db->encrypt($val,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); $sql.= ",".$this->db->encrypt($val,1);
$sql.= ",'".$visible."'"; $sql.= ",'".$visible."'";
$sql.= ",".$entity; $sql.= ",".$entity;
$sql.= ")"; $sql.= ")";
@@ -802,7 +802,7 @@ class DolibarrModules
{ {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,visible,entity)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,visible,entity)";
$sql.= " VALUES ("; $sql.= " VALUES (";
$sql.= $this->db->encrypt($name,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); $sql.= $this->db->encrypt($name,1);
$sql.= ",'".$type."'"; $sql.= ",'".$type."'";
$sql.= ",'".$visible."'"; $sql.= ",'".$visible."'";
$sql.= ",".$entity; $sql.= ",".$entity;
@@ -843,9 +843,9 @@ class DolibarrModules
//print $this->rights_class." ".sizeof($this->rights)."<br>"; //print $this->rights_class." ".sizeof($this->rights)."<br>";
// Test si module actif // Test si module actif
$sql_del = "SELECT ".$this->db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; $sql_del = "SELECT ".$this->db->decrypt('value')." as value";
$sql_del.= " FROM ".MAIN_DB_PREFIX."const"; $sql_del.= " FROM ".MAIN_DB_PREFIX."const";
$sql_del.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".$this->const_name."'"; $sql_del.= " WHERE ".$this->db->decrypt('name')." = '".$this->const_name."'";
$sql_del.= " AND entity IN (0,".$conf->entity.")"; $sql_del.= " AND entity IN (0,".$conf->entity.")";
$resql=$this->db->query($sql_del); $resql=$this->db->query($sql_del);
@@ -1121,7 +1121,7 @@ class DolibarrModules
$sql = "SELECT count(*)"; $sql = "SELECT count(*)";
$sql.= " FROM ".MAIN_DB_PREFIX."const"; $sql.= " FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".$name."'"; $sql.= " WHERE ".$this->db->decrypt('name')." = '".$name."'";
$sql.= " AND entity = ".$conf->entity; $sql.= " AND entity = ".$conf->entity;
dol_syslog("DolibarrModules::insert_dirs sql=".$sql); dol_syslog("DolibarrModules::insert_dirs sql=".$sql);
@@ -1133,7 +1133,7 @@ class DolibarrModules
if ($row[0] == 0) if ($row[0] == 0)
{ {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,value,note,visible,entity)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,value,note,visible,entity)";
$sql.= " VALUES (".$this->db->encrypt($name,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",'chaine',".$this->db->encrypt($dir,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",'Directory for module ".$this->name."','0',".$conf->entity.")"; $sql.= " VALUES (".$this->db->encrypt($name,1).",'chaine',".$this->db->encrypt($dir,1).",'Directory for module ".$this->name."','0',".$conf->entity.")";
dol_syslog("DolibarrModules::insert_dirs sql=".$sql); dol_syslog("DolibarrModules::insert_dirs sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
@@ -1161,7 +1161,7 @@ class DolibarrModules
$err=0; $err=0;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." like '".$this->const_name."_DIR_%'"; $sql.= " WHERE ".$this->db->decrypt('name')." like '".$this->const_name."_DIR_%'";
$sql.= " AND entity = ".$conf->entity; $sql.= " AND entity = ".$conf->entity;
dol_syslog("DolibarrModules::delete_dirs sql=".$sql); dol_syslog("DolibarrModules::delete_dirs sql=".$sql);

View File

@@ -188,24 +188,24 @@ if ($_POST["action"] == "set" || preg_match('/upgrade/i',$_POST["action"]))
$db->begin(); $db->begin();
dolibarr_install_syslog('install/etape5.php set MAIN_VERSION_LAST_INSTALL const to '.$targetversion, LOG_DEBUG); dolibarr_install_syslog('install/etape5.php set MAIN_VERSION_LAST_INSTALL const to '.$targetversion, LOG_DEBUG);
$resql=$db->query("DELETE FROM llx_const WHERE ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)."='MAIN_VERSION_LAST_INSTALL'"); $resql=$db->query("DELETE FROM llx_const WHERE ".$db->decrypt('name')."='MAIN_VERSION_LAST_INSTALL'");
if (! $resql) dol_print_error($db,'Error in setup program'); if (! $resql) dol_print_error($db,'Error in setup program');
$resql=$db->query("INSERT INTO llx_const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_VERSION_LAST_INSTALL',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",".$db->encrypt($targetversion,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",'chaine',0,'Dolibarr version when install',0)"); $resql=$db->query("INSERT INTO llx_const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_VERSION_LAST_INSTALL',1).",".$db->encrypt($targetversion,1).",'chaine',0,'Dolibarr version when install',0)");
if (! $resql) dol_print_error($db,'Error in setup program'); if (! $resql) dol_print_error($db,'Error in setup program');
$conf->global->MAIN_VERSION_LAST_INSTALL=$targetversion; $conf->global->MAIN_VERSION_LAST_INSTALL=$targetversion;
if ($usedoliwamp) if ($usedoliwamp)
{ {
dolibarr_install_syslog('install/etape5.php set MAIN_REMOVE_INSTALL_WARNING const to 1', LOG_DEBUG); dolibarr_install_syslog('install/etape5.php set MAIN_REMOVE_INSTALL_WARNING const to 1', LOG_DEBUG);
$resql=$db->query("DELETE FROM llx_const WHERE ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)."='MAIN_REMOVE_INSTALL_WARNING'"); $resql=$db->query("DELETE FROM llx_const WHERE ".$db->decrypt('name')."='MAIN_REMOVE_INSTALL_WARNING'");
if (! $resql) dol_print_error($db,'Error in setup program'); if (! $resql) dol_print_error($db,'Error in setup program');
$resql=$db->query("INSERT INTO llx_const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_REMOVE_INSTALL_WARNING',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",".$db->encrypt(1,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",'chaine',1,'Disable install warnings',0)"); $resql=$db->query("INSERT INTO llx_const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_REMOVE_INSTALL_WARNING',1).",".$db->encrypt(1,1).",'chaine',1,'Disable install warnings',0)");
if (! $resql) dol_print_error($db,'Error in setup program'); if (! $resql) dol_print_error($db,'Error in setup program');
$conf->global->MAIN_REMOVE_INSTALL_WARNING=1; $conf->global->MAIN_REMOVE_INSTALL_WARNING=1;
} }
dolibarr_install_syslog('install/etape5.php Remove MAIN_NOT_INSTALLED const', LOG_DEBUG); dolibarr_install_syslog('install/etape5.php Remove MAIN_NOT_INSTALLED const', LOG_DEBUG);
$resql=$db->query("DELETE FROM llx_const WHERE ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)."='MAIN_NOT_INSTALLED'"); $resql=$db->query("DELETE FROM llx_const WHERE ".$db->decrypt('name')."='MAIN_NOT_INSTALLED'");
if (! $resql) dol_print_error($db,'Error in setup program'); if (! $resql) dol_print_error($db,'Error in setup program');
$db->commit(); $db->commit();
@@ -236,9 +236,9 @@ if ($_POST["action"] == "set" || preg_match('/upgrade/i',$_POST["action"]))
if ($tagdatabase) if ($tagdatabase)
{ {
dolibarr_install_syslog('install/etape5.php set MAIN_VERSION_LAST_UPGRADE const to value '.$targetversion, LOG_DEBUG); dolibarr_install_syslog('install/etape5.php set MAIN_VERSION_LAST_UPGRADE const to value '.$targetversion, LOG_DEBUG);
$resql=$db->query("DELETE FROM llx_const WHERE ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)."='MAIN_VERSION_LAST_UPGRADE'"); $resql=$db->query("DELETE FROM llx_const WHERE ".$db->decrypt('name')."='MAIN_VERSION_LAST_UPGRADE'");
if (! $resql) dol_print_error($db,'Error in setup program'); if (! $resql) dol_print_error($db,'Error in setup program');
$resql=$db->query("INSERT INTO llx_const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_VERSION_LAST_UPGRADE',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",".$db->encrypt($targetversion,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",'chaine',0,'Dolibarr version for last upgrade',0)"); $resql=$db->query("INSERT INTO llx_const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_VERSION_LAST_UPGRADE',1).",".$db->encrypt($targetversion,1).",'chaine',0,'Dolibarr version for last upgrade',0)");
if (! $resql) dol_print_error($db,'Error in setup program'); if (! $resql) dol_print_error($db,'Error in setup program');
$conf->global->MAIN_VERSION_LAST_UPGRADE=$targetversion; $conf->global->MAIN_VERSION_LAST_UPGRADE=$targetversion;
} }
@@ -258,7 +258,7 @@ if ($_POST["action"] == "set" || preg_match('/upgrade/i',$_POST["action"]))
} }
// May fail if parameter already defined // May fail if parameter already defined
$resql=$db->query("INSERT INTO llx_const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_LANG_DEFAULT',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",".$db->encrypt($setuplang,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1).",'chaine',0,'Default language',1)"); $resql=$db->query("INSERT INTO llx_const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_LANG_DEFAULT',1).",".$db->encrypt($setuplang,1).",'chaine',0,'Default language',1)");
//if (! $resql) dol_print_error($db,'Error in setup program'); //if (! $resql) dol_print_error($db,'Error in setup program');
print '</table>'; print '</table>';

View File

@@ -309,7 +309,7 @@ function dolibarr_del_const($db, $name, $entity=1)
global $conf; global $conf;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
$sql.=" WHERE (".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".addslashes($name)."' OR rowid = '".addslashes($name)."')"; $sql.=" WHERE (".$db->decrypt('name')." = '".addslashes($name)."' OR rowid = '".addslashes($name)."')";
if ($entity >= 0) $sql.= " AND entity = ".$entity; if ($entity >= 0) $sql.= " AND entity = ".$entity;
dol_syslog("admin.lib::dolibarr_del_const sql=".$sql); dol_syslog("admin.lib::dolibarr_del_const sql=".$sql);
@@ -339,9 +339,9 @@ function dolibarr_get_const($db, $name, $entity=1)
global $conf; global $conf;
$value=''; $value='';
$sql = "SELECT ".$db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; $sql = "SELECT ".$db->decrypt('value')." as value";
$sql.= " FROM ".MAIN_DB_PREFIX."const"; $sql.= " FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".addslashes($name)."'"; $sql.= " WHERE ".$db->decrypt('name')." = '".addslashes($name)."'";
$sql.= " AND entity = ".$entity; $sql.= " AND entity = ".$entity;
dol_syslog("admin.lib::dolibarr_get_const sql=".$sql); dol_syslog("admin.lib::dolibarr_get_const sql=".$sql);
@@ -381,7 +381,7 @@ function dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $not
//dol_syslog("dolibarr_set_const name=$name, value=$value"); //dol_syslog("dolibarr_set_const name=$name, value=$value");
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = '".addslashes($name)."'"; $sql.= " WHERE ".$db->decrypt('name')." = '".addslashes($name)."'";
$sql.= " AND entity = ".$entity; $sql.= " AND entity = ".$entity;
dol_syslog("admin.lib::dolibarr_set_const sql=".$sql, LOG_DEBUG); dol_syslog("admin.lib::dolibarr_set_const sql=".$sql, LOG_DEBUG);
@@ -391,8 +391,8 @@ function dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $not
{ {
$sql = "INSERT INTO llx_const(name,value,type,visible,note,entity)"; $sql = "INSERT INTO llx_const(name,value,type,visible,note,entity)";
$sql.= " VALUES ("; $sql.= " VALUES (";
$sql.= $db->encrypt($name,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); $sql.= $db->encrypt($name,1);
$sql.= ", ".$db->encrypt($value,$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey,1); $sql.= ", ".$db->encrypt($value,1);
$sql.= ",'".$type."',".$visible.",'".addslashes($note)."',".$entity.")"; $sql.= ",'".$type."',".$visible.",'".addslashes($note)."',".$entity.")";
dol_syslog("admin.lib::dolibarr_set_const sql=".$sql, LOG_DEBUG); dol_syslog("admin.lib::dolibarr_set_const sql=".$sql, LOG_DEBUG);

View File

@@ -705,27 +705,39 @@ class DoliDb
/** /**
* \brief Encrypt sensitive data in database * \brief Encrypt sensitive data in database
* \param fieldorvalue Field name or value to encrypt * \param fieldorvalue Field name or value to encrypt
* \param cryptType Type of encryption (2: AES (recommended), 1: DES , 0: no encryption)
* \param cryptKey Encryption key
* \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'
*/ */
function encrypt($fieldorvalue, $cryptType=0, $cryptKey='', $withQuotes=0) function encrypt($fieldorvalue, $withQuotes=0)
{ {
global $conf;
// Type of encryption (2: AES (recommended), 1: DES , 0: no encryption)
$cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0);
//Encryption key
$cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:'');
$return = $fieldorvalue; $return = $fieldorvalue;
return ($withQuotes?"'":"").$return.($withQuotes?"'":""); return ($withQuotes?"'":"").$return.($withQuotes?"'":"");
} }
/** /**
* \brief Decrypt sensitive data in database * \brief Decrypt sensitive data in database
* \param field Field name to decrypt * \param value Value to decrypt
* \param cryptType Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) * \return return Decrypted value if used
* \param cryptKey Encryption key
* \return return Field to decrypt if used
*/ */
function decrypt($field, $cryptType=0, $cryptKey='') function decrypt($value)
{ {
$return = $field; global $conf;
// Type of encryption (2: AES (recommended), 1: DES , 0: no encryption)
$cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0);
//Encryption key
$cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:'');
$return = $value;
return $return; return $return;
} }

View File

@@ -692,13 +692,19 @@ class DoliDb
/** /**
* \brief Encrypt sensitive data in database * \brief Encrypt sensitive data in database
* \param fieldorvalue Field name or value to encrypt * \param fieldorvalue Field name or value to encrypt
* \param cryptType Type of encryption (2: AES (recommended), 1: DES , 0: no encryption)
* \param cryptKey Encryption key
* \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'
*/ */
function encrypt($fieldorvalue, $cryptType=0, $cryptKey='', $withQuotes=0) function encrypt($fieldorvalue, $withQuotes=0)
{ {
global $conf;
// Type of encryption (2: AES (recommended), 1: DES , 0: no encryption)
$cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0);
//Encryption key
$cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:'');
$return = ($withQuotes?"'":"").addslashes($fieldorvalue).($withQuotes?"'":""); $return = ($withQuotes?"'":"").addslashes($fieldorvalue).($withQuotes?"'":"");
if ($cryptType && !empty($cryptKey)) if ($cryptType && !empty($cryptKey))
@@ -718,24 +724,30 @@ class DoliDb
/** /**
* \brief Decrypt sensitive data in database * \brief Decrypt sensitive data in database
* \param field Field name to decrypt * \param value Value to decrypt
* \param cryptType Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) * \return return Decrypted value if used
* \param cryptKey Encryption key
* \return return Field to decrypt if used
*/ */
function decrypt($field, $cryptType=0, $cryptKey='') function decrypt($value)
{ {
$return = $field; global $conf;
// Type of encryption (2: AES (recommended), 1: DES , 0: no encryption)
$cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0);
//Encryption key
$cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:'');
$return = $value;
if ($cryptType && !empty($cryptKey)) if ($cryptType && !empty($cryptKey))
{ {
if ($cryptType == 2) if ($cryptType == 2)
{ {
$return = 'AES_DECRYPT('.$field.',\''.$cryptKey.'\')'; $return = 'AES_DECRYPT('.$value.',\''.$cryptKey.'\')';
} }
else if ($cryptType == 1) else if ($cryptType == 1)
{ {
$return = 'DES_DECRYPT('.$field.',\''.$cryptKey.'\')'; $return = 'DES_DECRYPT('.$value.',\''.$cryptKey.'\')';
} }
} }

View File

@@ -702,13 +702,19 @@ class DoliDb
/** /**
* \brief Encrypt sensitive data in database * \brief Encrypt sensitive data in database
* \param fieldorvalue Field name or value to encrypt * \param fieldorvalue Field name or value to encrypt
* \param cryptType Type of encryption (2: AES (recommended), 1: DES , 0: no encryption)
* \param cryptKey Encryption key
* \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'
*/ */
function encrypt($fieldorvalue, $cryptType=0, $cryptKey='', $withQuotes=0) function encrypt($fieldorvalue, $withQuotes=0)
{ {
global $conf;
// Type of encryption (2: AES (recommended), 1: DES , 0: no encryption)
$cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0);
//Encryption key
$cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:'');
$return = ($withQuotes?"'":"").addslashes($fieldorvalue).($withQuotes?"'":""); $return = ($withQuotes?"'":"").addslashes($fieldorvalue).($withQuotes?"'":"");
if ($cryptType && !empty($cryptKey)) if ($cryptType && !empty($cryptKey))
@@ -728,24 +734,30 @@ class DoliDb
/** /**
* \brief Decrypt sensitive data in database * \brief Decrypt sensitive data in database
* \param field Field name to decrypt * \param value Value to decrypt
* \param cryptType Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) * \return return Decrypted value if used
* \param cryptKey Encryption key
* \return return Field to decrypt if used
*/ */
function decrypt($field, $cryptType=0, $cryptKey='') function decrypt($value)
{ {
$return = $field; global $conf;
// Type of encryption (2: AES (recommended), 1: DES , 0: no encryption)
$cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0);
//Encryption key
$cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:'');
$return = $value;
if ($cryptType && !empty($cryptKey)) if ($cryptType && !empty($cryptKey))
{ {
if ($cryptType == 2) if ($cryptType == 2)
{ {
$return = 'AES_DECRYPT('.$field.',\''.$cryptKey.'\')'; $return = 'AES_DECRYPT('.$value.',\''.$cryptKey.'\')';
} }
else if ($cryptType == 1) else if ($cryptType == 1)
{ {
$return = 'DES_DECRYPT('.$field.',\''.$cryptKey.'\')'; $return = 'DES_DECRYPT('.$value.',\''.$cryptKey.'\')';
} }
} }

View File

@@ -799,13 +799,19 @@ class DoliDb
/** /**
* \brief Encrypt sensitive data in database * \brief Encrypt sensitive data in database
* \param fieldorvalue Field name or value to encrypt * \param fieldorvalue Field name or value to encrypt
* \param cryptType Type of encryption (2: AES (recommended), 1: DES , 0: no encryption)
* \param cryptKey Encryption key
* \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'
*/ */
function encrypt($fieldorvalue, $cryptType=0, $cryptKey='', $withQuotes=0) function encrypt($fieldorvalue, $withQuotes=0)
{ {
global $conf;
// Type of encryption (2: AES (recommended), 1: DES , 0: no encryption)
$cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0);
//Encryption key
$cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:'');
$return = $fieldorvalue; $return = $fieldorvalue;
return ($withQuotes?"'":"").$return.($withQuotes?"'":""); return ($withQuotes?"'":"").$return.($withQuotes?"'":"");
} }
@@ -813,14 +819,20 @@ class DoliDb
/** /**
* \brief Decrypt sensitive data in database * \brief Decrypt sensitive data in database
* \param field Field name to decrypt * \param value Value to decrypt
* \param cryptType Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) * \return return Decrypted value if used
* \param cryptKey Encryption key
* \return return Field to decrypt if used
*/ */
function decrypt($field, $cryptType=0, $cryptKey='') function decrypt($value)
{ {
$return = $field; global $conf;
// Type of encryption (2: AES (recommended), 1: DES , 0: no encryption)
$cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0);
//Encryption key
$cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:'');
$return = $value;
return $return; return $return;
} }

View File

@@ -97,10 +97,10 @@ class Multicompany
global $conf; global $conf;
$sql = "SELECT "; $sql = "SELECT ";
$sql.= $this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as name"; $sql.= $this->db->decrypt('name')." as name";
$sql.= ", ".$this->db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; $sql.= ", ".$this->db->decrypt('value')." as value";
$sql.= " FROM ".MAIN_DB_PREFIX."const"; $sql.= " FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." LIKE 'MAIN_%'"; $sql.= " WHERE ".$this->db->decrypt('name')." LIKE 'MAIN_%'";
$sql.= " AND entity = ".$id; $sql.= " AND entity = ".$id;
$result = $this->db->query($sql); $result = $this->db->query($sql);
@@ -152,7 +152,7 @@ class Multicompany
$sql = "UPDATE ".MAIN_DB_PREFIX."const"; $sql = "UPDATE ".MAIN_DB_PREFIX."const";
$sql.= " SET entity = ".$newid; $sql.= " SET entity = ".$newid;
$sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = 'MAIN_INFO_SOCIETE_NOM'"; $sql.= " WHERE ".$this->db->decrypt('name')." = 'MAIN_INFO_SOCIETE_NOM'";
$sql.= " AND entity = ".$id; $sql.= " AND entity = ".$id;
dol_syslog("Multicompany::setEntity sql=".$sql, LOG_DEBUG); dol_syslog("Multicompany::setEntity sql=".$sql, LOG_DEBUG);
@@ -168,10 +168,10 @@ class Multicompany
global $conf; global $conf;
$sql = "SELECT "; $sql = "SELECT ";
$sql.= $this->db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; $sql.= $this->db->decrypt('value')." as value";
$sql.= ", entity"; $sql.= ", entity";
$sql.= " FROM ".MAIN_DB_PREFIX."const"; $sql.= " FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." = 'MAIN_INFO_SOCIETE_NOM'"; $sql.= " WHERE ".$this->db->decrypt('name')." = 'MAIN_INFO_SOCIETE_NOM'";
$sql.= " ORDER BY value ASC"; $sql.= " ORDER BY value ASC";
$result = $this->db->query($sql); $result = $this->db->query($sql);

View File

@@ -576,9 +576,9 @@ class ProductLivre extends Product
$sql = "SELECT"; $sql = "SELECT";
$sql.= " rowid"; $sql.= " rowid";
$sql.= ", ".$this->db->decrypt('value',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey)." as value"; $sql.= ", ".$this->db->decrypt('value')." as value";
$sql.= " FROM ".MAIN_DB_PREFIX."const"; $sql.= " FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE ".$this->db->decrypt('name',$conf->db->dolibarr_main_db_encryption,$conf->db->dolibarr_main_db_cryptkey); $sql.= " WHERE ".$this->db->decrypt('name');
$sql.= " LIKE 'EDITEUR_LIVRE_FORMAT_%'"; $sql.= " LIKE 'EDITEUR_LIVRE_FORMAT_%'";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);