diff --git a/htdocs/lib/admin.lib.php b/htdocs/lib/admin.lib.php
index 00e62cc2ca5..6bcab638b91 100644
--- a/htdocs/lib/admin.lib.php
+++ b/htdocs/lib/admin.lib.php
@@ -31,11 +31,11 @@
*/
function versiontostring($versionarray)
{
- $string='?';
- if (isset($versionarray[0])) $string=$versionarray[0];
- if (isset($versionarray[1])) $string.='.'.$versionarray[1];
- if (isset($versionarray[2])) $string.='.'.$versionarray[2];
- return $string;
+ $string='?';
+ if (isset($versionarray[0])) $string=$versionarray[0];
+ if (isset($versionarray[1])) $string.='.'.$versionarray[1];
+ if (isset($versionarray[2])) $string.='.'.$versionarray[2];
+ return $string;
}
/**
@@ -49,28 +49,28 @@ function versiontostring($versionarray)
*/
function versioncompare($versionarray1,$versionarray2)
{
- $ret=0;
- $level=0;
- $count1=count($versionarray1);
- $count2=count($versionarray2);
- $maxcount=max($count1,$count2);
- while ($level < $maxcount)
- {
- $operande1=isset($versionarray1[$level])?$versionarray1[$level]:0;
- $operande2=isset($versionarray2[$level])?$versionarray2[$level]:0;
- if (preg_match('/alpha|dev/i',$operande1)) $operande1=-3;
- if (preg_match('/alpha|dev/i',$operande2)) $operande2=-3;
- if (preg_match('/beta/i',$operande1)) $operande1=-2;
- if (preg_match('/beta/i',$operande2)) $operande2=-2;
- if (preg_match('/rc/i',$operande1)) $operande1=-1;
- if (preg_match('/rc/i',$operande2)) $operande2=-1;
- $level++;
- //print 'level '.$level.' '.$operande1.'-'.$operande2.'
';
- if ($operande1 < $operande2) { $ret = -$level; break; }
- if ($operande1 > $operande2) { $ret = $level; break; }
- }
- //print join('.',$versionarray1).'('.count($versionarray1).') / '.join('.',$versionarray2).'('.count($versionarray2).') => '.$ret;
- return $ret;
+ $ret=0;
+ $level=0;
+ $count1=count($versionarray1);
+ $count2=count($versionarray2);
+ $maxcount=max($count1,$count2);
+ while ($level < $maxcount)
+ {
+ $operande1=isset($versionarray1[$level])?$versionarray1[$level]:0;
+ $operande2=isset($versionarray2[$level])?$versionarray2[$level]:0;
+ if (preg_match('/alpha|dev/i',$operande1)) $operande1=-3;
+ if (preg_match('/alpha|dev/i',$operande2)) $operande2=-3;
+ if (preg_match('/beta/i',$operande1)) $operande1=-2;
+ if (preg_match('/beta/i',$operande2)) $operande2=-2;
+ if (preg_match('/rc/i',$operande1)) $operande1=-1;
+ if (preg_match('/rc/i',$operande2)) $operande2=-1;
+ $level++;
+ //print 'level '.$level.' '.$operande1.'-'.$operande2.'
';
+ if ($operande1 < $operande2) { $ret = -$level; break; }
+ if ($operande1 > $operande2) { $ret = $level; break; }
+ }
+ //print join('.',$versionarray1).'('.count($versionarray1).') / '.join('.',$versionarray2).'('.count($versionarray2).') => '.$ret;
+ return $ret;
}
@@ -81,7 +81,7 @@ function versioncompare($versionarray1,$versionarray2)
*/
function versionphparray()
{
- return explode('.',PHP_VERSION);
+ return explode('.',PHP_VERSION);
}
/**
@@ -91,7 +91,7 @@ function versionphparray()
*/
function versiondolibarrarray()
{
- return explode('.',DOL_VERSION);
+ return explode('.',DOL_VERSION);
}
@@ -112,189 +112,189 @@ function versiondolibarrarray()
*/
function run_sql($sqlfile,$silent=1,$entity='',$usesavepoint=1,$handler='')
{
- global $db, $conf, $langs, $user;
+ global $db, $conf, $langs, $user;
- dol_syslog("Admin.lib::run_sql run sql file ".$sqlfile, LOG_DEBUG);
+ dol_syslog("Admin.lib::run_sql run sql file ".$sqlfile, LOG_DEBUG);
- $ok=0;
- $error=0;
- $i=0;
- $buffer = '';
- $arraysql = Array();
+ $ok=0;
+ $error=0;
+ $i=0;
+ $buffer = '';
+ $arraysql = Array();
- // Get version of database
- $versionarray=$db->getVersionArray();
+ // Get version of database
+ $versionarray=$db->getVersionArray();
- $fp = fopen($sqlfile,"r");
- if ($fp)
- {
- while (! feof($fp))
- {
- $buf = fgets($fp, 4096);
+ $fp = fopen($sqlfile,"r");
+ if ($fp)
+ {
+ while (! feof($fp))
+ {
+ $buf = fgets($fp, 4096);
- // Cas special de lignes autorisees pour certaines versions uniquement
- if (preg_match('/^--\sV([0-9\.]+)/i',$buf,$reg))
- {
- $versioncommande=explode('.',$reg[1]);
- //print var_dump($versioncommande);
- //print var_dump($versionarray);
- if (count($versioncommande) && count($versionarray)
- && versioncompare($versioncommande,$versionarray) <= 0)
- {
- // Version qualified, delete SQL comments
- $buf=preg_replace('/^--\sV([0-9\.]+)/i','',$buf);
- //print "Ligne $i qualifi?e par version: ".$buf.'
';
- }
- }
+ // Cas special de lignes autorisees pour certaines versions uniquement
+ if (preg_match('/^--\sV([0-9\.]+)/i',$buf,$reg))
+ {
+ $versioncommande=explode('.',$reg[1]);
+ //print var_dump($versioncommande);
+ //print var_dump($versionarray);
+ if (count($versioncommande) && count($versionarray)
+ && versioncompare($versioncommande,$versionarray) <= 0)
+ {
+ // Version qualified, delete SQL comments
+ $buf=preg_replace('/^--\sV([0-9\.]+)/i','',$buf);
+ //print "Ligne $i qualifi?e par version: ".$buf.'
';
+ }
+ }
- // Add line buf to buffer if not a comment
- if (! preg_match('/^--/',$buf))
- {
+ // Add line buf to buffer if not a comment
+ if (! preg_match('/^--/',$buf))
+ {
$buf=preg_replace('/--.*$/','',$buf); //remove comment from a line that not start with -- before add it to the buffer
- $buffer .= trim($buf);
- }
+ $buffer .= trim($buf);
+ }
- // print $buf.'
';
+ // print $buf.'
';
- if (preg_match('/;/',$buffer)) // If string contains ';', it's end of a request string, we save it in arraysql.
- {
- // Found new request
- if ($buffer) $arraysql[$i]=$buffer;
- $i++;
- $buffer='';
- }
- }
+ if (preg_match('/;/',$buffer)) // If string contains ';', it's end of a request string, we save it in arraysql.
+ {
+ // Found new request
+ if ($buffer) $arraysql[$i]=$buffer;
+ $i++;
+ $buffer='';
+ }
+ }
- if ($buffer) $arraysql[$i]=$buffer;
- fclose($fp);
- }
- else
- {
- dol_syslog("Admin.lib::run_sql failed to open file ".$sqlfile, LOG_ERR);
- }
+ if ($buffer) $arraysql[$i]=$buffer;
+ fclose($fp);
+ }
+ else
+ {
+ dol_syslog("Admin.lib::run_sql failed to open file ".$sqlfile, LOG_ERR);
+ }
- // Loop on each request to see if there is a __+MAX_table__ key
- $listofmaxrowid=array(); // This is a cache table
- foreach($arraysql as $i => $sql)
- {
- $newsql=$sql;
+ // Loop on each request to see if there is a __+MAX_table__ key
+ $listofmaxrowid=array(); // This is a cache table
+ foreach($arraysql as $i => $sql)
+ {
+ $newsql=$sql;
- // Replace __+MAX_table__ with max of table
- while (preg_match('/__\+MAX_([A-Za-z_]+)__/i',$newsql,$reg))
- {
- $table=$reg[1];
- if (! isset($listofmaxrowid[$table]))
- {
- //var_dump($db);
- $sqlgetrowid='SELECT MAX(rowid) as max from '.$table;
- $resql=$db->query($sqlgetrowid);
- if ($resql)
- {
- $obj=$db->fetch_object($resql);
- $listofmaxrowid[$table]=$obj->max;
- if (empty($listofmaxrowid[$table])) $listofmaxrowid[$table]=0;
- }
- else
- {
- dol_syslog('Admin.lib::run_sql Failed to get max rowid for '.$table.' '.$db->lasterror().' sql='.$sqlgetrowid, LOG_ERR);
- if (! $silent) print '
| ';
- if (! $silent) print ' '.$langs->trans("Failed to get max rowid for ".$table)." | ";
- if (! $silent) print '
';
- $error++;
- break;
- }
- }
- $from='__+MAX_'.$table.'__';
- $to='+'.$listofmaxrowid[$table];
- $newsql=str_replace($from,$to,$newsql);
- dol_syslog('Admin.lib::run_sql New Request '.($i+1).' (replacing '.$from.' to '.$to.') sql='.$newsql, LOG_DEBUG);
+ // Replace __+MAX_table__ with max of table
+ while (preg_match('/__\+MAX_([A-Za-z_]+)__/i',$newsql,$reg))
+ {
+ $table=$reg[1];
+ if (! isset($listofmaxrowid[$table]))
+ {
+ //var_dump($db);
+ $sqlgetrowid='SELECT MAX(rowid) as max from '.$table;
+ $resql=$db->query($sqlgetrowid);
+ if ($resql)
+ {
+ $obj=$db->fetch_object($resql);
+ $listofmaxrowid[$table]=$obj->max;
+ if (empty($listofmaxrowid[$table])) $listofmaxrowid[$table]=0;
+ }
+ else
+ {
+ dol_syslog('Admin.lib::run_sql Failed to get max rowid for '.$table.' '.$db->lasterror().' sql='.$sqlgetrowid, LOG_ERR);
+ if (! $silent) print '| ';
+ if (! $silent) print ' '.$langs->trans("Failed to get max rowid for ".$table)." | ";
+ if (! $silent) print '
';
+ $error++;
+ break;
+ }
+ }
+ $from='__+MAX_'.$table.'__';
+ $to='+'.$listofmaxrowid[$table];
+ $newsql=str_replace($from,$to,$newsql);
+ dol_syslog('Admin.lib::run_sql New Request '.($i+1).' (replacing '.$from.' to '.$to.') sql='.$newsql, LOG_DEBUG);
- $arraysql[$i]=$newsql;
- }
- }
+ $arraysql[$i]=$newsql;
+ }
+ }
- // Loop on each request to execute request
- $cursorinsert=0;
- $listofinsertedrowid=array();
- foreach($arraysql as $i => $sql)
- {
- if ($sql)
- {
- if (!empty($handler)) $sql=preg_replace('/__HANDLER__/i',"'".$handler."'",$sql);
+ // Loop on each request to execute request
+ $cursorinsert=0;
+ $listofinsertedrowid=array();
+ foreach($arraysql as $i => $sql)
+ {
+ if ($sql)
+ {
+ if (!empty($handler)) $sql=preg_replace('/__HANDLER__/i',"'".$handler."'",$sql);
- $newsql=preg_replace('/__ENTITY__/i',(!empty($entity)?$entity:$conf->entity),$sql);
+ $newsql=preg_replace('/__ENTITY__/i',(!empty($entity)?$entity:$conf->entity),$sql);
- // Ajout trace sur requete (eventuellement a commenter si beaucoup de requetes)
- if (! $silent) print '| '.$langs->trans("Request").' '.($i+1)." sql='".$newsql."' |
\n";
- dol_syslog('Admin.lib::run_sql Request '.($i+1).' sql='.$newsql, LOG_DEBUG);
+ // Ajout trace sur requete (eventuellement a commenter si beaucoup de requetes)
+ if (! $silent) print '| '.$langs->trans("Request").' '.($i+1)." sql='".$newsql."' |
\n";
+ dol_syslog('Admin.lib::run_sql Request '.($i+1).' sql='.$newsql, LOG_DEBUG);
- // Replace for encrypt data
- if (preg_match_all('/__ENCRYPT\(\'([^\,]+)\'\)__/i',$newsql,$reg))
- {
- $num=count($reg[0]);
+ // Replace for encrypt data
+ if (preg_match_all('/__ENCRYPT\(\'([^\,]+)\'\)__/i',$newsql,$reg))
+ {
+ $num=count($reg[0]);
- for($i=0;$i<$num;$i++)
- {
- $from = $reg[0][$i];
- $to = $db->encrypt($reg[1][$i],1);
- $newsql = str_replace($from,$to,$newsql);
- }
- }
+ for($i=0;$i<$num;$i++)
+ {
+ $from = $reg[0][$i];
+ $to = $db->encrypt($reg[1][$i],1);
+ $newsql = str_replace($from,$to,$newsql);
+ }
+ }
- // Replace for decrypt data
- if (preg_match_all('/__DECRYPT\(\'([^\,]+)\'\)__/i',$newsql,$reg))
- {
- $num=count($reg[0]);
+ // Replace for decrypt data
+ if (preg_match_all('/__DECRYPT\(\'([^\,]+)\'\)__/i',$newsql,$reg))
+ {
+ $num=count($reg[0]);
- for($i=0;$i<$num;$i++)
- {
- $from = $reg[0][$i];
- $to = $db->decrypt($reg[1][$i]);
- $newsql = str_replace($from,$to,$newsql);
- }
- }
+ for($i=0;$i<$num;$i++)
+ {
+ $from = $reg[0][$i];
+ $to = $db->decrypt($reg[1][$i]);
+ $newsql = str_replace($from,$to,$newsql);
+ }
+ }
- // Replace __x__ with rowid of insert nb x
- while (preg_match('/__([0-9]+)__/',$newsql,$reg))
- {
- $cursor=$reg[1];
- if (empty($listofinsertedrowid[$cursor]))
- {
- if (! $silent) print '| ';
- if (! $silent) print ' '.$langs->trans("FileIsNotCorrect")." | ";
- if (! $silent) print '
';
- $error++;
- break;
- }
- $from='__'.$cursor.'__';
- $to=$listofinsertedrowid[$cursor];
- $newsql=str_replace($from,$to,$newsql);
- dol_syslog('Admin.lib::run_sql New Request '.($i+1).' (replacing '.$from.' to '.$to.') sql='.$newsql, LOG_DEBUG);
- }
+ // Replace __x__ with rowid of insert nb x
+ while (preg_match('/__([0-9]+)__/',$newsql,$reg))
+ {
+ $cursor=$reg[1];
+ if (empty($listofinsertedrowid[$cursor]))
+ {
+ if (! $silent) print '| ';
+ if (! $silent) print ' '.$langs->trans("FileIsNotCorrect")." | ";
+ if (! $silent) print '
';
+ $error++;
+ break;
+ }
+ $from='__'.$cursor.'__';
+ $to=$listofinsertedrowid[$cursor];
+ $newsql=str_replace($from,$to,$newsql);
+ dol_syslog('Admin.lib::run_sql New Request '.($i+1).' (replacing '.$from.' to '.$to.') sql='.$newsql, LOG_DEBUG);
+ }
- $result=$db->query($newsql,$usesavepoint);
- if ($result)
- {
- if (! $silent) print ''."\n";
+ $result=$db->query($newsql,$usesavepoint);
+ if ($result)
+ {
+ if (! $silent) print ''."\n";
- if (preg_replace('/insert into ([^\s]+)/i',$newsql,$reg))
- {
- $cursorinsert++;
+ if (preg_replace('/insert into ([^\s]+)/i',$newsql,$reg))
+ {
+ $cursorinsert++;
- // It's an insert
- $table=preg_replace('/([^a-zA-Z_]+)/i','',$reg[1]);
- $insertedrowid=$db->last_insert_id($table);
- $listofinsertedrowid[$cursorinsert]=$insertedrowid;
- dol_syslog('Admin.lib::run_sql Insert nb '.$cursorinsert.', done in table '.$table.', rowid is '.$listofinsertedrowid[$cursorinsert], LOG_DEBUG);
- }
- // print 'OK | ';
- }
- else
- {
- $errno=$db->errno();
- if (! $silent) print ''."\n";
+ // It's an insert
+ $table=preg_replace('/([^a-zA-Z_]+)/i','',$reg[1]);
+ $insertedrowid=$db->last_insert_id($table);
+ $listofinsertedrowid[$cursorinsert]=$insertedrowid;
+ dol_syslog('Admin.lib::run_sql Insert nb '.$cursorinsert.', done in table '.$table.', rowid is '.$listofinsertedrowid[$cursorinsert], LOG_DEBUG);
+ }
+ // print 'OK | ';
+ }
+ else
+ {
+ $errno=$db->errno();
+ if (! $silent) print ''."\n";
- $okerror=array( 'DB_ERROR_TABLE_ALREADY_EXISTS',
+ $okerror=array( 'DB_ERROR_TABLE_ALREADY_EXISTS',
'DB_ERROR_COLUMN_ALREADY_EXISTS',
'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS', // PgSql use same code for table and key already exist
@@ -309,36 +309,36 @@ function run_sql($sqlfile,$silent=1,$entity='',$usesavepoint=1,$handler='')
);
if (in_array($errno,$okerror))
{
- //if (! $silent) print $langs->trans("OK");
+ //if (! $silent) print $langs->trans("OK");
}
else
{
- if (! $silent) print '| ';
- if (! $silent) print ' '.$langs->trans("Error")." ".$db->errno().": ".$newsql." ".$db->error()." | ";
- if (! $silent) print '
'."\n";
- dol_syslog('Admin.lib::run_sql Request '.($i+1)." Error ".$db->errno()." ".$newsql."
".$db->error(), LOG_ERR);
- $error++;
+ if (! $silent) print '| ';
+ if (! $silent) print ' '.$langs->trans("Error")." ".$db->errno().": ".$newsql." ".$db->error()." | ";
+ if (! $silent) print '
'."\n";
+ dol_syslog('Admin.lib::run_sql Request '.($i+1)." Error ".$db->errno()." ".$newsql."
".$db->error(), LOG_ERR);
+ $error++;
}
- }
+ }
- if (! $silent) print ''."\n";
- }
- }
+ if (! $silent) print ''."\n";
+ }
+ }
- if ($error == 0)
- {
- if (! $silent) print '| '.$langs->trans("ProcessMigrateScript").' | ';
- if (! $silent) print ''.$langs->trans("OK").' |
'."\n";
- $ok = 1;
- }
- else
- {
- if (! $silent) print '| '.$langs->trans("ProcessMigrateScript").' | ';
- if (! $silent) print ''.$langs->trans("KO").' |
'."\n";
- $ok = 0;
- }
+ if ($error == 0)
+ {
+ if (! $silent) print '| '.$langs->trans("ProcessMigrateScript").' | ';
+ if (! $silent) print ''.$langs->trans("OK").' |
'."\n";
+ $ok = 1;
+ }
+ else
+ {
+ if (! $silent) print '| '.$langs->trans("ProcessMigrateScript").' | ';
+ if (! $silent) print ''.$langs->trans("KO").' |
'."\n";
+ $ok = 0;
+ }
- return $ok;
+ return $ok;
}
@@ -354,26 +354,26 @@ function run_sql($sqlfile,$silent=1,$entity='',$usesavepoint=1,$handler='')
*/
function dolibarr_del_const($db, $name, $entity=1)
{
- global $conf;
+ global $conf;
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
- $sql.= " WHERE (".$db->decrypt('name')." = '".$db->escape($name)."'";
- if (is_numeric($name)) $sql.= " OR rowid = '".$db->escape($name)."'";
- $sql.= ")";
- if ($entity >= 0) $sql.= " AND entity = ".$entity;
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
+ $sql.= " WHERE (".$db->decrypt('name')." = '".$db->escape($name)."'";
+ if (is_numeric($name)) $sql.= " OR rowid = '".$db->escape($name)."'";
+ $sql.= ")";
+ if ($entity >= 0) $sql.= " AND entity = ".$entity;
- dol_syslog("admin.lib::dolibarr_del_const sql=".$sql);
- $resql=$db->query($sql);
- if ($resql)
- {
- $conf->global->$name='';
- return 1;
- }
- else
- {
- dol_print_error($db);
- return -1;
- }
+ dol_syslog("admin.lib::dolibarr_del_const sql=".$sql);
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $conf->global->$name='';
+ return 1;
+ }
+ else
+ {
+ dol_print_error($db);
+ return -1;
+ }
}
/**
@@ -388,22 +388,22 @@ function dolibarr_del_const($db, $name, $entity=1)
*/
function dolibarr_get_const($db, $name, $entity=1)
{
- global $conf;
- $value='';
+ global $conf;
+ $value='';
- $sql = "SELECT ".$db->decrypt('value')." as value";
- $sql.= " FROM ".MAIN_DB_PREFIX."const";
- $sql.= " WHERE name = ".$db->encrypt($name,1);
- $sql.= " AND entity = ".$entity;
+ $sql = "SELECT ".$db->decrypt('value')." as value";
+ $sql.= " FROM ".MAIN_DB_PREFIX."const";
+ $sql.= " WHERE name = ".$db->encrypt($name,1);
+ $sql.= " AND entity = ".$entity;
- dol_syslog("admin.lib::dolibarr_get_const sql=".$sql);
- $resql=$db->query($sql);
- if ($resql)
- {
- $obj=$db->fetch_object($resql);
- if ($obj) $value=$obj->value;
- }
- return $value;
+ dol_syslog("admin.lib::dolibarr_get_const sql=".$sql);
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $obj=$db->fetch_object($resql);
+ if ($obj) $value=$obj->value;
+ }
+ return $value;
}
@@ -423,57 +423,57 @@ function dolibarr_get_const($db, $name, $entity=1)
*/
function dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
{
- global $conf;
+ global $conf;
- // Clean parameters
- $name=trim($name);
+ // Clean parameters
+ $name=trim($name);
- // Check parameters
- if (empty($name))
- {
- dol_print_error($db,"Error: Call to function dolibarr_set_const with wrong parameters", LOG_ERR);
- exit;
- }
+ // Check parameters
+ if (empty($name))
+ {
+ dol_print_error($db,"Error: Call to function dolibarr_set_const with wrong parameters", LOG_ERR);
+ exit;
+ }
- //dol_syslog("dolibarr_set_const name=$name, value=$value type=$type, visible=$visible, note=$note entity=$entity");
+ //dol_syslog("dolibarr_set_const name=$name, value=$value type=$type, visible=$visible, note=$note entity=$entity");
- $db->begin();
+ $db->begin();
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
- $sql.= " WHERE name = ".$db->encrypt($name,1);
- if ($entity > 0) $sql.= " AND entity = ".$entity;
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
+ $sql.= " WHERE name = ".$db->encrypt($name,1);
+ if ($entity > 0) $sql.= " AND entity = ".$entity;
- dol_syslog("admin.lib::dolibarr_set_const sql=".$sql, LOG_DEBUG);
- $resql=$db->query($sql);
+ dol_syslog("admin.lib::dolibarr_set_const sql=".$sql, LOG_DEBUG);
+ $resql=$db->query($sql);
- if (strcmp($value,'')) // true if different. Must work for $value='0' or $value=0
- {
- $sql = "INSERT INTO llx_const(name,value,type,visible,note,entity)";
- $sql.= " VALUES (";
- $sql.= $db->encrypt($name,1);
- $sql.= ", ".$db->encrypt($value,1);
- $sql.= ",'".$type."',".$visible.",'".$db->escape($note)."',".$entity.")";
+ if (strcmp($value,'')) // true if different. Must work for $value='0' or $value=0
+ {
+ $sql = "INSERT INTO llx_const(name,value,type,visible,note,entity)";
+ $sql.= " VALUES (";
+ $sql.= $db->encrypt($name,1);
+ $sql.= ", ".$db->encrypt($value,1);
+ $sql.= ",'".$type."',".$visible.",'".$db->escape($note)."',".$entity.")";
- //print "sql".$value."-".pg_escape_string($value)."-".$sql;exit;
+ //print "sql".$value."-".pg_escape_string($value)."-".$sql;exit;
//print "xx".$db->escape($value);
//print $sql;exit;
- dol_syslog("admin.lib::dolibarr_set_const sql=".$sql, LOG_DEBUG);
- $resql=$db->query($sql);
- }
+ dol_syslog("admin.lib::dolibarr_set_const sql=".$sql, LOG_DEBUG);
+ $resql=$db->query($sql);
+ }
- if ($resql)
- {
- $db->commit();
- $conf->global->$name=$value;
- return 1;
- }
- else
- {
- $error=$db->lasterror();
- dol_syslog("admin.lib::dolibarr_set_const ".$error, LOG_ERR);
- $db->rollback();
- return -1;
- }
+ if ($resql)
+ {
+ $db->commit();
+ $conf->global->$name=$value;
+ return 1;
+ }
+ else
+ {
+ $error=$db->lasterror();
+ dol_syslog("admin.lib::dolibarr_set_const ".$error, LOG_ERR);
+ $db->rollback();
+ return -1;
+ }
}
@@ -484,31 +484,31 @@ function dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $not
*/
function security_prepare_head()
{
- global $langs, $conf, $user;
- $h = 0;
- $head = array();
+ global $langs, $conf, $user;
+ $h = 0;
+ $head = array();
$head[$h][0] = DOL_URL_ROOT."/admin/proxy.php";
$head[$h][1] = $langs->trans("ExternalAccess");
$head[$h][2] = 'proxy';
$h++;
- $head[$h][0] = DOL_URL_ROOT."/admin/security_other.php";
- $head[$h][1] = $langs->trans("Miscellanous");
- $head[$h][2] = 'misc';
- $h++;
+ $head[$h][0] = DOL_URL_ROOT."/admin/security_other.php";
+ $head[$h][1] = $langs->trans("Miscellanous");
+ $head[$h][2] = 'misc';
+ $h++;
$head[$h][0] = DOL_URL_ROOT."/admin/security.php";
$head[$h][1] = $langs->trans("Passwords");
$head[$h][2] = 'passwords';
$h++;
- $head[$h][0] = DOL_URL_ROOT."/admin/events.php";
- $head[$h][1] = $langs->trans("Audit");
- $head[$h][2] = 'audit';
- $h++;
+ $head[$h][0] = DOL_URL_ROOT."/admin/events.php";
+ $head[$h][1] = $langs->trans("Audit");
+ $head[$h][2] = 'audit';
+ $h++;
- $head[$h][0] = DOL_URL_ROOT."/admin/perms.php";
+ $head[$h][0] = DOL_URL_ROOT."/admin/perms.php";
$head[$h][1] = $langs->trans("DefaultRights");
$head[$h][2] = 'default';
$h++;
@@ -524,44 +524,44 @@ function security_prepare_head()
*/
function listOfSessions()
{
- global $conf;
+ global $conf;
- $arrayofSessions = array();
- $sessPath = ini_get("session.save_path").'/';
- dol_syslog('admin.lib:listOfSessions sessPath='.$sessPath);
+ $arrayofSessions = array();
+ $sessPath = ini_get("session.save_path").'/';
+ dol_syslog('admin.lib:listOfSessions sessPath='.$sessPath);
- $dh = @opendir($sessPath);
- if ($dh)
- {
- while(($file = @readdir($dh)) !== false)
- {
- if (preg_match('/^sess_/i',$file) && $file != "." && $file != "..")
- {
- $fullpath = $sessPath.$file;
- if(! @is_dir($fullpath) && is_readable($fullpath))
- {
- $sessValues = file_get_contents($fullpath); // get raw session data
+ $dh = @opendir(dol_osencode($sessPath));
+ if ($dh)
+ {
+ while(($file = @readdir($dh)) !== false)
+ {
+ if (preg_match('/^sess_/i',$file) && $file != "." && $file != "..")
+ {
+ $fullpath = $sessPath.$file;
+ if(! @is_dir($fullpath) && is_readable($fullpath))
+ {
+ $sessValues = file_get_contents($fullpath); // get raw session data
- if (preg_match('/dol_login/i',$sessValues) && // limit to dolibarr session
- preg_match('/dol_entity\|s:([0-9]+):"('.$conf->entity.')"/i',$sessValues) && // limit to current entity
- preg_match('/dol_company\|s:([0-9]+):"('.$conf->global->MAIN_INFO_SOCIETE_NOM.')"/i',$sessValues)) // limit to company name
- {
- $tmp=explode('_', $file);
- $idsess=$tmp[1];
- $login = preg_match('/dol_login\|s:[0-9]+:"([A-Za-z0-9]+)"/i',$sessValues,$regs);
- $arrayofSessions[$idsess]["login"] = $regs[1];
- $arrayofSessions[$idsess]["age"] = time()-filectime($fullpath);
- $arrayofSessions[$idsess]["creation"] = filectime($fullpath);
- $arrayofSessions[$idsess]["modification"] = filemtime($fullpath);
- $arrayofSessions[$idsess]["raw"] = $sessValues;
- }
- }
- }
- }
- @closedir($dh);
- }
+ if (preg_match('/dol_login/i',$sessValues) && // limit to dolibarr session
+ preg_match('/dol_entity\|s:([0-9]+):"('.$conf->entity.')"/i',$sessValues) && // limit to current entity
+ preg_match('/dol_company\|s:([0-9]+):"('.$conf->global->MAIN_INFO_SOCIETE_NOM.')"/i',$sessValues)) // limit to company name
+ {
+ $tmp=explode('_', $file);
+ $idsess=$tmp[1];
+ $login = preg_match('/dol_login\|s:[0-9]+:"([A-Za-z0-9]+)"/i',$sessValues,$regs);
+ $arrayofSessions[$idsess]["login"] = $regs[1];
+ $arrayofSessions[$idsess]["age"] = time()-filectime($fullpath);
+ $arrayofSessions[$idsess]["creation"] = filectime($fullpath);
+ $arrayofSessions[$idsess]["modification"] = filemtime($fullpath);
+ $arrayofSessions[$idsess]["raw"] = $sessValues;
+ }
+ }
+ }
+ }
+ @closedir($dh);
+ }
- return $arrayofSessions;
+ return $arrayofSessions;
}
/**
@@ -572,43 +572,43 @@ function listOfSessions()
*/
function purgeSessions($mysessionid)
{
- global $conf;
+ global $conf;
- $arrayofSessions = array();
- $sessPath = ini_get("session.save_path")."/";
- dol_syslog('admin.lib:purgeSessions mysessionid='.$mysessionid.' sessPath='.$sessPath);
+ $arrayofSessions = array();
+ $sessPath = ini_get("session.save_path")."/";
+ dol_syslog('admin.lib:purgeSessions mysessionid='.$mysessionid.' sessPath='.$sessPath);
- $error=0;
- $dh = @opendir($sessPath);
- while(($file = @readdir($dh)) !== false)
- {
- if ($file != "." && $file != "..")
- {
- $fullpath = $sessPath.$file;
- if(! @is_dir($fullpath))
- {
- $sessValues = file_get_contents($fullpath); // get raw session data
+ $error=0;
+ $dh = @opendir(dol_osencode($sessPath));
+ while(($file = @readdir($dh)) !== false)
+ {
+ if ($file != "." && $file != "..")
+ {
+ $fullpath = $sessPath.$file;
+ if(! @is_dir($fullpath))
+ {
+ $sessValues = file_get_contents($fullpath); // get raw session data
- if (preg_match('/dol_login/i',$sessValues) && // limit to dolibarr session
- preg_match('/dol_entity\|s:([0-9]+):"('.$conf->entity.')"/i',$sessValues) && // limit to current entity
- preg_match('/dol_company\|s:([0-9]+):"('.$conf->global->MAIN_INFO_SOCIETE_NOM.')"/i',$sessValues)) // limit to company name
- {
- $tmp=explode('_', $file);
- $idsess=$tmp[1];
- // We remove session if it's not ourself
- if ($idsess != $mysessionid)
- {
- $res=@unlink($fullpath);
- if (! $res) $error++;
- }
- }
- }
- }
- }
- @closedir($dh);
+ if (preg_match('/dol_login/i',$sessValues) && // limit to dolibarr session
+ preg_match('/dol_entity\|s:([0-9]+):"('.$conf->entity.')"/i',$sessValues) && // limit to current entity
+ preg_match('/dol_company\|s:([0-9]+):"('.$conf->global->MAIN_INFO_SOCIETE_NOM.')"/i',$sessValues)) // limit to company name
+ {
+ $tmp=explode('_', $file);
+ $idsess=$tmp[1];
+ // We remove session if it's not ourself
+ if ($idsess != $mysessionid)
+ {
+ $res=@unlink($fullpath);
+ if (! $res) $error++;
+ }
+ }
+ }
+ }
+ }
+ @closedir($dh);
- if (! $error) return 1;
- else return -$error;
+ if (! $error) return 1;
+ else return -$error;
}
@@ -634,37 +634,37 @@ function Activate($value,$withdeps=1)
// Loop on each directory
$found=false;
- foreach ($conf->file->dol_document_root as $type => $dirroot)
+ foreach ($conf->file->dol_document_root as $type => $dirroot)
{
$modulesdir[] = $dirroot."/includes/modules/";
if ($type == 'alt')
- {
- $handle=@opendir($dirroot);
- if (is_resource($handle))
- {
- while (($file = readdir($handle))!==false)
- {
- if (is_dir($dirroot.'/'.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && $file != 'includes')
- {
- if (is_dir($dirroot . '/' . $file . '/includes/modules/'))
- {
- $modulesdir[] = $dirroot . '/' . $file . '/includes/modules/';
- }
- }
- }
- closedir($handle);
- }
- }
+ {
+ $handle=@opendir(dol_osencode($dirroot));
+ if (is_resource($handle))
+ {
+ while (($file = readdir($handle))!==false)
+ {
+ if (is_dir($dirroot.'/'.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && $file != 'includes')
+ {
+ if (is_dir($dirroot . '/' . $file . '/includes/modules/'))
+ {
+ $modulesdir[] = $dirroot . '/' . $file . '/includes/modules/';
+ }
+ }
+ }
+ closedir($handle);
+ }
+ }
}
foreach ($modulesdir as $dir)
{
- if (file_exists($dir.$modFile))
- {
- $found=@include_once($dir.$modFile);
- if ($found) break;
- }
+ if (file_exists($dir.$modFile))
+ {
+ $found=@include_once($dir.$modFile);
+ if ($found) break;
+ }
}
$objMod = new $modName($db);
@@ -748,38 +748,38 @@ function UnActivate($value, $requiredby=1)
$modulesdir=array();
// Loop on each directory
- $found=false;
+ $found=false;
foreach ($conf->file->dol_document_root as $type => $dirroot)
{
$modulesdir[] = $dirroot."/includes/modules/";
if ($type == 'alt')
- {
- $handle=@opendir($dirroot);
- if (is_resource($handle))
- {
- while (($file = readdir($handle))!==false)
- {
- if (is_dir($dirroot.'/'.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && $file != 'includes')
- {
- if (is_dir($dirroot . '/' . $file . '/includes/modules/'))
- {
- $modulesdir[] = $dirroot . '/' . $file . '/includes/modules/';
- }
- }
- }
- closedir($handle);
- }
- }
+ {
+ $handle=@opendir(dol_osencode($dirroot));
+ if (is_resource($handle))
+ {
+ while (($file = readdir($handle))!==false)
+ {
+ if (is_dir($dirroot.'/'.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && $file != 'includes')
+ {
+ if (is_dir($dirroot . '/' . $file . '/includes/modules/'))
+ {
+ $modulesdir[] = $dirroot . '/' . $file . '/includes/modules/';
+ }
+ }
+ }
+ closedir($handle);
+ }
+ }
}
foreach ($modulesdir as $dir)
{
- if (file_exists($dir.$modFile))
- {
- $found=@include_once($dir.$modFile);
- if ($found) break;
- }
+ if (file_exists($dir.$modFile))
+ {
+ $found=@include_once($dir.$modFile);
+ if ($found) break;
+ }
}
if ($found)
@@ -846,7 +846,7 @@ function complete_dictionnary_with_modules(&$taborder,&$tabname,&$tablib,&$tabsq
// Load modules attributes in arrays (name, numero, orders) from dir directory
//print $dir."\n
";
dol_syslog("Scan directory ".$dir." for modules");
- $handle=@opendir($dir);
+ $handle=@opendir(dol_osencode($dir));
if (is_resource($handle))
{
while (($file = readdir($handle))!==false)