2008-06-10 20:29:23 +02:00
< ? php
2015-08-31 17:42:08 +02:00
/* Copyright ( C ) 2008 - 2011 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2016 Regis Houssin < regis . houssin @ inodbox . com >
2015-08-31 17:42:08 +02:00
* Copyright ( C ) 2012 J . Fernando Lagrange < fernando @ demo - tic . org >
* Copyright ( C ) 2015 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
2008-06-10 20:29:23 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2008-06-10 20:29:23 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
* or see https :// www . gnu . org /
2008-06-10 20:29:23 +02:00
*/
/**
2011-10-24 11:25:54 +02:00
* \file htdocs / core / lib / admin . lib . php
2008-11-15 22:10:10 +01:00
* \brief Library of admin functions
*/
2008-06-10 20:29:23 +02:00
2015-08-31 17:42:08 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
2008-06-10 20:29:23 +02:00
/**
2011-09-16 20:25:10 +02:00
* Renvoi une version en chaine depuis une version en tableau
*
* @ param array $versionarray Tableau de version ( vermajeur , vermineur , autre )
* @ return string Chaine version
2019-03-11 01:01:15 +01:00
* @ see versioncompare ()
2009-01-26 22:57:14 +01:00
*/
2008-06-10 20:29:23 +02:00
function versiontostring ( $versionarray )
{
2011-09-21 17:53:54 +02:00
$string = '?' ;
if ( isset ( $versionarray [ 0 ])) $string = $versionarray [ 0 ];
if ( isset ( $versionarray [ 1 ])) $string .= '.' . $versionarray [ 1 ];
if ( isset ( $versionarray [ 2 ])) $string .= '.' . $versionarray [ 2 ];
return $string ;
2008-06-10 20:29:23 +02:00
}
/**
2015-07-27 17:09:16 +02:00
* Compare 2 versions ( stored into 2 arrays ) .
2016-03-25 17:14:20 +01:00
* To check if Dolibarr version is lower than ( x , y , z ), do " if versioncompare(versiondolibarrarray(), array(x.y.z)) <= 0 "
2016-07-12 13:03:56 +02:00
* For example : if ( versioncompare ( versiondolibarrarray (), array ( 4 , 0 , - 4 )) >= 0 ) is true if version is 4.0 alpha or higher .
2016-03-25 17:14:20 +01:00
* For example : if ( versioncompare ( versiondolibarrarray (), array ( 4 , 0 , 0 )) >= 0 ) is true if version is 4.0 final or higher .
* For example : if ( versioncompare ( versiondolibarrarray (), array ( 4 , 0 , 1 )) >= 0 ) is true if version is 4.0 . 1 or higher .
2016-07-12 13:03:56 +02:00
* Alternative way to compare : if (( float ) DOL_VERSION >= 4.0 ) is true if version is 4.0 alpha or higher ( works only to compare first and second level )
2011-09-16 20:25:10 +02:00
*
* @ param array $versionarray1 Array of version ( vermajor , verminor , patch )
* @ param array $versionarray2 Array of version ( vermajor , verminor , patch )
* @ return int - 4 , - 3 , - 2 , - 1 if versionarray1 < versionarray2 ( value depends on level of difference )
* 0 if same
* 1 , 2 , 3 , 4 if versionarray1 > versionarray2 ( value depends on level of difference )
2019-03-11 01:01:15 +01:00
* @ see versiontostring ()
2009-05-04 22:57:26 +02:00
*/
2019-01-27 15:20:16 +01:00
function versioncompare ( $versionarray1 , $versionarray2 )
2008-06-10 20:29:23 +02:00
{
2011-09-21 17:53:54 +02:00
$ret = 0 ;
$level = 0 ;
$count1 = count ( $versionarray1 );
$count2 = count ( $versionarray2 );
2019-01-27 11:55:16 +01:00
$maxcount = max ( $count1 , $count2 );
2011-09-21 17:53:54 +02:00
while ( $level < $maxcount )
{
$operande1 = isset ( $versionarray1 [ $level ]) ? $versionarray1 [ $level ] : 0 ;
$operande2 = isset ( $versionarray2 [ $level ]) ? $versionarray2 [ $level ] : 0 ;
2019-01-27 11:55:16 +01:00
if ( preg_match ( '/alpha|dev/i' , $operande1 )) $operande1 =- 5 ;
if ( preg_match ( '/alpha|dev/i' , $operande2 )) $operande2 =- 5 ;
if ( preg_match ( '/beta$/i' , $operande1 )) $operande1 =- 4 ;
if ( preg_match ( '/beta$/i' , $operande2 )) $operande2 =- 4 ;
if ( preg_match ( '/beta([0-9])+/i' , $operande1 )) $operande1 =- 3 ;
if ( preg_match ( '/beta([0-9])+/i' , $operande2 )) $operande2 =- 3 ;
if ( preg_match ( '/rc$/i' , $operande1 )) $operande1 =- 2 ;
if ( preg_match ( '/rc$/i' , $operande2 )) $operande2 =- 2 ;
if ( preg_match ( '/rc([0-9])+/i' , $operande1 )) $operande1 =- 1 ;
if ( preg_match ( '/rc([0-9])+/i' , $operande2 )) $operande2 =- 1 ;
2011-09-21 17:53:54 +02:00
$level ++ ;
//print 'level '.$level.' '.$operande1.'-'.$operande2.'<br>';
if ( $operande1 < $operande2 ) { $ret = - $level ; break ; }
if ( $operande1 > $operande2 ) { $ret = $level ; break ; }
}
2014-10-05 20:26:35 +02:00
//print join('.',$versionarray1).'('.count($versionarray1).') / '.join('.',$versionarray2).'('.count($versionarray2).') => '.$ret.'<br>'."\n";
2011-09-21 17:53:54 +02:00
return $ret ;
2008-02-01 01:09:23 +01:00
}
/**
2011-01-16 02:14:48 +01:00
* Return version PHP
2011-09-16 20:25:10 +02:00
*
2011-01-16 02:14:48 +01:00
* @ return array Tableau de version ( vermajeur , vermineur , autre )
2009-05-04 22:57:26 +02:00
*/
2008-06-10 20:29:23 +02:00
function versionphparray ()
{
2019-01-27 11:55:16 +01:00
return explode ( '.' , PHP_VERSION );
2008-06-10 20:29:23 +02:00
}
/**
2011-09-16 20:25:10 +02:00
* Return version Dolibarr
*
* @ return array Tableau de version ( vermajeur , vermineur , autre )
2009-05-04 22:57:26 +02:00
*/
2011-09-16 20:25:10 +02:00
function versiondolibarrarray ()
2010-04-30 19:31:46 +02:00
{
2019-01-27 11:55:16 +01:00
return explode ( '.' , DOL_VERSION );
2008-06-10 20:29:23 +02:00
}
/**
2018-08-16 21:48:16 +02:00
* Launch a sql file . Function is used by :
2010-09-29 01:17:31 +02:00
* - Migrate process ( dolibarr - xyz - abc . sql )
* - Loading sql menus ( auguria )
* - Running specific Sql by a module init
2018-08-16 21:48:16 +02:00
* - Loading sql file of website import package
2010-09-29 01:17:31 +02:00
* Install process however does not use it .
2018-08-16 21:48:16 +02:00
* Note that Sql files must have all comments at start of line . Also this function take ';' as the char to detect end of sql request
2011-09-16 20:25:10 +02:00
*
2018-08-16 21:48:16 +02:00
* @ param string $sqlfile Full path to sql file
* @ param int $silent 1 = Do not output anything , 0 = Output line for update page
* @ param int $entity Entity targeted for multicompany module
* @ param int $usesavepoint 1 = Run a savepoint before each request and a rollback to savepoint if error ( this allow to have some request with errors inside global transactions ) .
* @ param string $handler Handler targeted for menu ( replace __HANDLER__ with this value )
* @ param string $okerror Family of errors we accept ( 'default' , 'none' )
* @ param int $linelengthlimit Limit for length of each line ( Use 0 if unknown , may be faster if defined )
* @ param int $nocommentremoval Do no try to remove comments ( in such a case , we consider that each line is a request , so use also $linelengthlimit = 0 )
2018-09-17 21:02:07 +02:00
* @ param int $offsetforchartofaccount Offset to use to load chart of account table to update sql on the fly to add offset to rowid and account_parent value
2018-08-16 21:48:16 +02:00
* @ return int <= 0 if KO , > 0 if OK
2009-05-04 22:57:26 +02:00
*/
2019-01-27 15:20:16 +01:00
function run_sql ( $sqlfile , $silent = 1 , $entity = '' , $usesavepoint = 1 , $handler = '' , $okerror = 'default' , $linelengthlimit = 32768 , $nocommentremoval = 0 , $offsetforchartofaccount = 0 )
2008-06-10 20:29:23 +02:00
{
2011-09-21 17:53:54 +02:00
global $db , $conf , $langs , $user ;
2012-02-10 17:09:13 +01:00
dol_syslog ( " Admin.lib::run_sql run sql file " . $sqlfile . " silent= " . $silent . " entity= " . $entity . " usesavepoint= " . $usesavepoint . " handler= " . $handler . " okerror= " . $okerror , LOG_DEBUG );
2011-09-21 17:53:54 +02:00
2018-08-16 21:48:16 +02:00
if ( ! is_numeric ( $linelengthlimit ))
{
dol_syslog ( " Admin.lib::run_sql param linelengthlimit is not a numeric " , LOG_ERR );
return - 1 ;
}
2011-09-21 17:53:54 +02:00
$ok = 0 ;
$error = 0 ;
$i = 0 ;
$buffer = '' ;
2017-11-27 14:48:36 +01:00
$arraysql = array ();
2011-09-21 17:53:54 +02:00
// Get version of database
$versionarray = $db -> getVersionArray ();
2019-01-27 11:55:16 +01:00
$fp = fopen ( $sqlfile , " r " );
2011-09-21 17:53:54 +02:00
if ( $fp )
{
while ( ! feof ( $fp ))
{
2018-08-16 21:48:16 +02:00
// Warning fgets with second parameter that is null or 0 hang.
if ( $linelengthlimit > 0 ) $buf = fgets ( $fp , $linelengthlimit );
else $buf = fgets ( $fp );
2009-01-21 15:09:42 +01:00
2011-12-10 11:26:04 +01:00
// Test if request must be ran only for particular database or version (if yes, we must remove the -- comment)
2019-04-23 10:24:16 +02:00
$reg = array ();
2019-01-27 11:55:16 +01:00
if ( preg_match ( '/^--\sV(MYSQL|PGSQL)([^\s]*)/i' , $buf , $reg ))
2011-09-21 17:53:54 +02:00
{
2011-12-10 11:26:04 +01:00
$qualified = 1 ;
2011-12-13 00:30:54 +01:00
2011-12-10 11:26:04 +01:00
// restrict on database type
if ( ! empty ( $reg [ 1 ]))
{
2019-01-27 11:55:16 +01:00
if ( ! preg_match ( '/' . preg_quote ( $reg [ 1 ]) . '/i' , $db -> type )) $qualified = 0 ;
2011-12-10 11:26:04 +01:00
}
2011-12-13 00:30:54 +01:00
2011-12-10 11:26:04 +01:00
// restrict on version
if ( $qualified )
{
2017-08-04 21:23:40 +02:00
if ( ! empty ( $reg [ 2 ]))
{
if ( is_numeric ( $reg [ 2 ])) // This is a version
{
2019-01-27 11:55:16 +01:00
$versionrequest = explode ( '.' , $reg [ 2 ]);
2017-08-04 21:23:40 +02:00
//print var_dump($versionrequest);
//print var_dump($versionarray);
2019-01-27 11:55:16 +01:00
if ( ! count ( $versionrequest ) || ! count ( $versionarray ) || versioncompare ( $versionrequest , $versionarray ) > 0 )
2017-08-04 21:23:40 +02:00
{
$qualified = 0 ;
}
}
else // This is a test on a constant. For example when we have -- VMYSQLUTF8UNICODE, we test constant $conf->global->UTF8UNICODE
{
2017-08-29 12:59:13 +02:00
$dbcollation = strtoupper ( preg_replace ( '/_/' , '' , $conf -> db -> dolibarr_main_db_collation ));
//var_dump($reg[2]);
//var_dump($dbcollation);
if ( empty ( $conf -> db -> dolibarr_main_db_collation ) || ( $reg [ 2 ] != $dbcollation )) $qualified = 0 ;
//var_dump($qualified);
2017-08-04 21:23:40 +02:00
}
}
2011-12-10 11:26:04 +01:00
}
2011-12-13 00:30:54 +01:00
2011-12-10 11:26:04 +01:00
if ( $qualified )
2011-09-21 17:53:54 +02:00
{
// Version qualified, delete SQL comments
2019-01-27 11:55:16 +01:00
$buf = preg_replace ( '/^--\sV(MYSQL|PGSQL)([^\s]*)/i' , '' , $buf );
2011-09-21 17:53:54 +02:00
//print "Ligne $i qualifi?e par version: ".$buf.'<br>';
}
}
// Add line buf to buffer if not a comment
2019-01-27 11:55:16 +01:00
if ( $nocommentremoval || ! preg_match ( '/^\s*--/' , $buf ))
2011-09-21 17:53:54 +02:00
{
2019-01-27 11:55:16 +01:00
if ( empty ( $nocommentremoval )) $buf = preg_replace ( '/([,;ERLT\)])\s*--.*$/i' , '\1' , $buf ); //remove comment from a line that not start with -- before add it to the buffer
2011-09-21 17:53:54 +02:00
$buffer .= trim ( $buf );
}
2011-04-02 20:55:41 +02:00
2018-08-16 21:48:16 +02:00
//print $buf.'<br>';exit;
2011-03-29 22:41:57 +02:00
2019-01-27 11:55:16 +01:00
if ( preg_match ( '/;/' , $buffer )) // If string contains ';', it's end of a request string, we save it in arraysql.
2011-09-21 17:53:54 +02:00
{
// Found new request
if ( $buffer ) $arraysql [ $i ] = $buffer ;
$i ++ ;
$buffer = '' ;
}
}
2009-01-21 15:09:42 +01:00
2011-09-21 17:53:54 +02:00
if ( $buffer ) $arraysql [ $i ] = $buffer ;
fclose ( $fp );
}
else
{
dol_syslog ( " Admin.lib::run_sql failed to open file " . $sqlfile , LOG_ERR );
}
2010-04-05 21:24:23 +02:00
2011-09-21 17:53:54 +02:00
// 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
2019-01-27 11:55:16 +01:00
while ( preg_match ( '/__\+MAX_([A-Za-z0-9_]+)__/i' , $newsql , $reg ))
2011-09-21 17:53:54 +02:00
{
$table = $reg [ 1 ];
if ( ! isset ( $listofmaxrowid [ $table ]))
{
//var_dump($db);
2018-08-16 21:48:16 +02:00
$sqlgetrowid = 'SELECT MAX(rowid) as max from ' . preg_replace ( '/^llx_/' , MAIN_DB_PREFIX , $table );
2011-09-21 17:53:54 +02:00
$resql = $db -> query ( $sqlgetrowid );
if ( $resql )
{
$obj = $db -> fetch_object ( $resql );
$listofmaxrowid [ $table ] = $obj -> max ;
if ( empty ( $listofmaxrowid [ $table ])) $listofmaxrowid [ $table ] = 0 ;
}
else
{
if ( ! $silent ) print '<tr><td valign="top" colspan="2">' ;
if ( ! $silent ) print '<div class="error">' . $langs -> trans ( " Failed to get max rowid for " . $table ) . " </div></td> " ;
if ( ! $silent ) print '</tr>' ;
$error ++ ;
break ;
}
}
2018-08-16 21:48:16 +02:00
// Replace __+MAX_llx_table__ with +999
2011-09-21 17:53:54 +02:00
$from = '__+MAX_' . $table . '__' ;
$to = '+' . $listofmaxrowid [ $table ];
2018-08-16 21:48:16 +02:00
$newsql = str_replace ( $from , $to , $newsql );
2014-06-13 01:42:00 +02:00
dol_syslog ( 'Admin.lib::run_sql New Request ' . ( $i + 1 ) . ' (replacing ' . $from . ' to ' . $to . ')' , LOG_DEBUG );
2011-09-21 17:53:54 +02:00
$arraysql [ $i ] = $newsql ;
}
2018-09-17 21:02:07 +02:00
if ( $offsetforchartofaccount > 0 )
{
// Replace lines
// 'INSERT INTO llx_accounting_account (__ENTITY__, rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, active) VALUES (1401, 'PCG99-ABREGE','CAPIT', 'XXXXXX', '1', 0, '...', 1);'
// with
// 'INSERT INTO llx_accounting_account (__ENTITY__, rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, active) VALUES (1401 + 200100000, 'PCG99-ABREGE','CAPIT', 'XXXXXX', '1', 0, '...', 1);'
$newsql = preg_replace ( '/VALUES\s*\(__ENTITY__, \s*(\d+)\s*,(\s*\'[^\',]*\'\s*,\s*\'[^\',]*\'\s*,\s*\'[^\',]*\'\s*,\s*\'[^\',]*\'\s*),\s*\'?([^\',]*)\'?/ims' , 'VALUES (__ENTITY__, \1 + ' . $offsetforchartofaccount . ', \2, \3 + ' . $offsetforchartofaccount , $newsql );
$newsql = preg_replace ( '/([,\s])0 \+ ' . $offsetforchartofaccount . '/ims' , '\1 0' , $newsql );
//var_dump($newsql);
$arraysql [ $i ] = $newsql ;
}
2011-09-21 17:53:54 +02:00
}
// Loop on each request to execute request
$cursorinsert = 0 ;
$listofinsertedrowid = array ();
foreach ( $arraysql as $i => $sql )
{
if ( $sql )
{
2011-11-24 08:23:16 +01:00
// Replace the prefix tables
if ( MAIN_DB_PREFIX != 'llx_' )
{
2019-01-27 11:55:16 +01:00
$sql = preg_replace ( '/llx_/i' , MAIN_DB_PREFIX , $sql );
2011-11-24 08:23:16 +01:00
}
2011-12-02 23:23:07 +01:00
2019-01-27 11:55:16 +01:00
if ( ! empty ( $handler )) $sql = preg_replace ( '/__HANDLER__/i' , " ' " . $handler . " ' " , $sql );
2011-09-21 17:53:54 +02:00
2019-01-27 11:55:16 +01:00
$newsql = preg_replace ( '/__ENTITY__/i' , ( ! empty ( $entity ) ? $entity : $conf -> entity ), $sql );
2011-09-21 17:53:54 +02:00
// Ajout trace sur requete (eventuellement a commenter si beaucoup de requetes)
2019-01-27 11:55:16 +01:00
if ( ! $silent ) print '<tr><td class="tdtop">' . $langs -> trans ( " Request " ) . ' ' . ( $i + 1 ) . " sql=' " . dol_htmlentities ( $newsql , ENT_NOQUOTES ) . " '</td></tr> \n " ;
2014-06-13 01:42:00 +02:00
dol_syslog ( 'Admin.lib::run_sql Request ' . ( $i + 1 ), LOG_DEBUG );
2013-04-10 20:45:38 +02:00
$sqlmodified = 0 ;
2011-09-21 17:53:54 +02:00
// Replace for encrypt data
2019-01-27 11:55:16 +01:00
if ( preg_match_all ( '/__ENCRYPT\(\'([^\']+)\'\)__/i' , $newsql , $reg ))
2011-09-21 17:53:54 +02:00
{
$num = count ( $reg [ 0 ]);
2013-04-10 20:45:38 +02:00
for ( $j = 0 ; $j < $num ; $j ++ )
2011-09-21 17:53:54 +02:00
{
2013-04-10 20:45:38 +02:00
$from = $reg [ 0 ][ $j ];
2019-01-27 11:55:16 +01:00
$to = $db -> encrypt ( $reg [ 1 ][ $j ], 1 );
$newsql = str_replace ( $from , $to , $newsql );
2011-09-21 17:53:54 +02:00
}
2013-04-10 20:45:38 +02:00
$sqlmodified ++ ;
2011-09-21 17:53:54 +02:00
}
// Replace for decrypt data
2019-01-27 11:55:16 +01:00
if ( preg_match_all ( '/__DECRYPT\(\'([A-Za-z0-9_]+)\'\)__/i' , $newsql , $reg ))
2011-09-21 17:53:54 +02:00
{
$num = count ( $reg [ 0 ]);
2013-04-10 20:45:38 +02:00
for ( $j = 0 ; $j < $num ; $j ++ )
2011-09-21 17:53:54 +02:00
{
2013-04-10 20:45:38 +02:00
$from = $reg [ 0 ][ $j ];
$to = $db -> decrypt ( $reg [ 1 ][ $j ]);
2019-01-27 11:55:16 +01:00
$newsql = str_replace ( $from , $to , $newsql );
2011-09-21 17:53:54 +02:00
}
2013-04-10 20:45:38 +02:00
$sqlmodified ++ ;
2011-09-21 17:53:54 +02:00
}
// Replace __x__ with rowid of insert nb x
2019-01-27 11:55:16 +01:00
while ( preg_match ( '/__([0-9]+)__/' , $newsql , $reg ))
2011-09-21 17:53:54 +02:00
{
$cursor = $reg [ 1 ];
if ( empty ( $listofinsertedrowid [ $cursor ]))
{
if ( ! $silent ) print '<tr><td valign="top" colspan="2">' ;
if ( ! $silent ) print '<div class="error">' . $langs -> trans ( " FileIsNotCorrect " ) . " </div></td> " ;
if ( ! $silent ) print '</tr>' ;
$error ++ ;
break ;
}
$from = '__' . $cursor . '__' ;
$to = $listofinsertedrowid [ $cursor ];
2019-01-27 11:55:16 +01:00
$newsql = str_replace ( $from , $to , $newsql );
2013-04-10 20:45:38 +02:00
$sqlmodified ++ ;
2011-09-21 17:53:54 +02:00
}
2014-06-13 01:42:00 +02:00
if ( $sqlmodified ) dol_syslog ( 'Admin.lib::run_sql New Request ' . ( $i + 1 ), LOG_DEBUG );
2013-04-10 20:45:38 +02:00
2019-01-27 11:55:16 +01:00
$result = $db -> query ( $newsql , $usesavepoint );
2011-09-21 17:53:54 +02:00
if ( $result )
{
if ( ! $silent ) print '<!-- Result = OK -->' . " \n " ;
2019-01-27 11:55:16 +01:00
if ( preg_replace ( '/insert into ([^\s]+)/i' , $newsql , $reg ))
2011-09-21 17:53:54 +02:00
{
$cursorinsert ++ ;
// It's an insert
2019-01-27 11:55:16 +01:00
$table = preg_replace ( '/([^a-zA-Z_]+)/i' , '' , $reg [ 1 ]);
2011-09-21 17:53:54 +02:00
$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 );
}
2019-02-19 17:42:12 +01:00
// print '<td class="right">OK</td>';
2011-09-21 17:53:54 +02:00
}
else
{
$errno = $db -> errno ();
if ( ! $silent ) print '<!-- Result = ' . $errno . ' -->' . " \n " ;
2012-02-10 17:09:13 +01:00
// Define list of errors we accept (array $okerrors)
$okerrors = array ( // By default
'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
'DB_ERROR_RECORD_ALREADY_EXISTS' ,
'DB_ERROR_NOSUCHTABLE' ,
'DB_ERROR_NOSUCHFIELD' ,
'DB_ERROR_NO_FOREIGN_KEY_TO_DROP' ,
'DB_ERROR_NO_INDEX_TO_DROP' ,
'DB_ERROR_CANNOT_CREATE' , // Qd contrainte deja existante
'DB_ERROR_CANT_DROP_PRIMARY_KEY' ,
2016-04-28 13:56:17 +02:00
'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS' ,
'DB_ERROR_22P02'
2008-06-10 20:29:23 +02:00
);
2012-02-10 17:09:13 +01:00
if ( $okerror == 'none' ) $okerrors = array ();
// Is it an error we accept
2019-01-27 11:55:16 +01:00
if ( ! in_array ( $errno , $okerrors ))
2008-06-10 20:29:23 +02:00
{
2011-09-21 17:53:54 +02:00
if ( ! $silent ) print '<tr><td valign="top" colspan="2">' ;
if ( ! $silent ) print '<div class="error">' . $langs -> trans ( " Error " ) . " " . $db -> errno () . " : " . $newsql . " <br> " . $db -> error () . " </div></td> " ;
if ( ! $silent ) print '</tr>' . " \n " ;
dol_syslog ( 'Admin.lib::run_sql Request ' . ( $i + 1 ) . " Error " . $db -> errno () . " " . $newsql . " <br> " . $db -> error (), LOG_ERR );
$error ++ ;
2008-06-10 20:29:23 +02:00
}
2011-09-21 17:53:54 +02:00
}
if ( ! $silent ) print '</tr>' . " \n " ;
}
}
if ( $error == 0 )
{
if ( ! $silent ) print '<tr><td>' . $langs -> trans ( " ProcessMigrateScript " ) . '</td>' ;
2019-02-19 17:42:12 +01:00
if ( ! $silent ) print '<td class="right">' . $langs -> trans ( " OK " ) . '</td></tr>' . " \n " ;
2011-09-21 17:53:54 +02:00
$ok = 1 ;
}
else
{
if ( ! $silent ) print '<tr><td>' . $langs -> trans ( " ProcessMigrateScript " ) . '</td>' ;
2019-02-19 17:42:12 +01:00
if ( ! $silent ) print '<td class="right"><font class="error">' . $langs -> trans ( " KO " ) . '</font></td></tr>' . " \n " ;
2011-09-21 17:53:54 +02:00
$ok = 0 ;
}
return $ok ;
2008-06-10 20:29:23 +02:00
}
/**
2011-03-01 10:23:47 +01:00
* Effacement d ' une constante dans la base de donnees
2011-09-16 20:25:10 +02:00
*
* @ param DoliDB $db Database handler
* @ param string $name Name of constant or rowid of line
* @ param int $entity Multi company id , - 1 for all entities
* @ return int < 0 if KO , > 0 if OK
*
2019-03-11 01:01:15 +01:00
* @ see dolibarr_get_const (), dolibarr_set_const (), dol_set_user_param ()
2009-05-04 22:57:26 +02:00
*/
2019-01-27 15:20:16 +01:00
function dolibarr_del_const ( $db , $name , $entity = 1 )
2008-02-01 01:09:23 +01:00
{
2011-09-21 17:53:54 +02:00
global $conf ;
2015-03-18 21:44:57 +01:00
if ( empty ( $name ))
{
2019-01-27 11:55:16 +01:00
dol_print_error ( '' , 'Error call dolibar_del_const with parameter name empty' );
2015-03-18 21:44:57 +01:00
return - 1 ;
}
2011-09-21 17:53:54 +02:00
$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 ;
2014-06-12 11:31:53 +02:00
dol_syslog ( " admin.lib::dolibarr_del_const " , LOG_DEBUG );
2011-09-21 17:53:54 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$conf -> global -> $name = '' ;
return 1 ;
}
else
{
dol_print_error ( $db );
return - 1 ;
}
2008-02-01 01:09:23 +01:00
}
/**
2011-03-01 10:23:47 +01:00
* Recupere une constante depuis la base de donnees .
2011-09-16 20:25:10 +02:00
*
* @ param DoliDB $db Database handler
* @ param string $name Nom de la constante
* @ param int $entity Multi company id
* @ return string Valeur de la constante
*
2019-03-11 01:01:15 +01:00
* @ see dolibarr_del_const (), dolibarr_set_const (), dol_set_user_param ()
2009-05-04 22:57:26 +02:00
*/
2019-01-27 15:20:16 +01:00
function dolibarr_get_const ( $db , $name , $entity = 1 )
2008-02-01 01:09:23 +01:00
{
2011-09-21 17:53:54 +02:00
global $conf ;
$value = '' ;
$sql = " SELECT " . $db -> decrypt ( 'value' ) . " as value " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " const " ;
2019-01-27 11:55:16 +01:00
$sql .= " WHERE name = " . $db -> encrypt ( $name , 1 );
2011-09-21 17:53:54 +02:00
$sql .= " AND entity = " . $entity ;
2014-06-12 11:31:53 +02:00
dol_syslog ( " admin.lib::dolibarr_get_const " , LOG_DEBUG );
2011-09-21 17:53:54 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$obj = $db -> fetch_object ( $resql );
if ( $obj ) $value = $obj -> value ;
}
return $value ;
2008-02-01 01:09:23 +01:00
}
/**
2015-03-18 21:44:57 +01:00
* Insert a parameter ( key , value ) into database ( delete old key then insert it again ) .
2011-09-16 20:25:10 +02:00
*
* @ param DoliDB $db Database handler
* @ param string $name Name of constant
* @ param string $value Value of constant
* @ param string $type Type of constante ( chaine par defaut )
* @ param int $visible Is constant visible in Setup -> Other page ( 0 by default )
* @ param string $note Note on parameter
* @ param int $entity Multi company id ( 0 means all entities )
* @ return int - 1 if KO , 1 if OK
*
2019-03-11 01:01:15 +01:00
* @ see dolibarr_del_const (), dolibarr_get_const (), dol_set_user_param ()
2009-05-04 22:57:26 +02:00
*/
2019-01-27 15:20:16 +01:00
function dolibarr_set_const ( $db , $name , $value , $type = 'chaine' , $visible = 0 , $note = '' , $entity = 1 )
2008-02-01 01:09:23 +01:00
{
2011-09-21 17:53:54 +02:00
global $conf ;
2009-04-27 22:37:50 +02:00
2011-09-21 17:53:54 +02:00
// Clean parameters
$name = trim ( $name );
2010-01-13 11:55:23 +01:00
2011-09-21 17:53:54 +02:00
// Check parameters
if ( empty ( $name ))
{
2019-01-27 11:55:16 +01:00
dol_print_error ( $db , " Error: Call to function dolibarr_set_const with wrong parameters " , LOG_ERR );
2011-09-21 17:53:54 +02:00
exit ;
}
2009-04-27 22:37:50 +02:00
2011-09-21 17:53:54 +02:00
//dol_syslog("dolibarr_set_const name=$name, value=$value type=$type, visible=$visible, note=$note entity=$entity");
2010-01-21 23:44:57 +01:00
2011-09-21 17:53:54 +02:00
$db -> begin ();
2009-04-14 20:54:13 +02:00
2011-09-21 17:53:54 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " const " ;
2019-01-27 11:55:16 +01:00
$sql .= " WHERE name = " . $db -> encrypt ( $name , 1 );
2012-01-09 23:57:44 +01:00
if ( $entity >= 0 ) $sql .= " AND entity = " . $entity ;
2009-12-23 16:26:29 +01:00
2014-06-12 11:31:53 +02:00
dol_syslog ( " admin.lib::dolibarr_set_const " , LOG_DEBUG );
2011-09-21 17:53:54 +02:00
$resql = $db -> query ( $sql );
2008-02-01 01:09:23 +01:00
2019-01-27 11:55:16 +01:00
if ( strcmp ( $value , '' )) // true if different. Must work for $value='0' or $value=0
2011-09-21 17:53:54 +02:00
{
2011-11-23 21:43:25 +01:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " const(name,value,type,visible,note,entity) " ;
2011-09-21 17:53:54 +02:00
$sql .= " VALUES ( " ;
2019-01-27 11:55:16 +01:00
$sql .= $db -> encrypt ( $name , 1 );
$sql .= " , " . $db -> encrypt ( $value , 1 );
2018-03-16 09:52:45 +01:00
$sql .= " ,' " . $db -> escape ( $type ) . " ', " . $visible . " ,' " . $db -> escape ( $note ) . " ', " . $entity . " ) " ;
2010-08-18 16:01:23 +02:00
2011-09-21 17:53:54 +02:00
//print "sql".$value."-".pg_escape_string($value)."-".$sql;exit;
2010-09-02 00:45:10 +02:00
//print "xx".$db->escape($value);
2014-06-12 11:31:53 +02:00
dol_syslog ( " admin.lib::dolibarr_set_const " , LOG_DEBUG );
2011-09-21 17:53:54 +02:00
$resql = $db -> query ( $sql );
}
if ( $resql )
{
$db -> commit ();
$conf -> global -> $name = $value ;
return 1 ;
}
else
{
$error = $db -> lasterror ();
$db -> rollback ();
return - 1 ;
}
2008-02-01 01:09:23 +01:00
}
2008-06-10 20:29:23 +02:00
2017-08-22 14:47:01 +02:00
/**
* Prepare array with list of tabs
*
* @ return array Array of tabs to show
*/
function modules_prepare_head ()
{
global $langs , $conf , $user ;
$h = 0 ;
$head = array ();
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/modules.php?mode=common " ;
$head [ $h ][ 1 ] = $langs -> trans ( " AvailableModules " );
$head [ $h ][ 2 ] = 'common' ;
$h ++ ;
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/modules.php?mode=marketplace " ;
$head [ $h ][ 1 ] = $langs -> trans ( " ModulesMarketPlaces " );
$head [ $h ][ 2 ] = 'marketplace' ;
$h ++ ;
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/modules.php?mode=deploy " ;
$head [ $h ][ 1 ] = $langs -> trans ( " AddExtensionThemeModuleOrOther " );
$head [ $h ][ 2 ] = 'deploy' ;
$h ++ ;
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/modules.php?mode=develop " ;
$head [ $h ][ 1 ] = $langs -> trans ( " ModulesDevelopYourModule " );
$head [ $h ][ 2 ] = 'develop' ;
$h ++ ;
return $head ;
}
2008-06-10 20:29:23 +02:00
/**
2012-02-04 10:48:47 +01:00
* Prepare array with list of tabs
2011-09-16 20:25:10 +02:00
*
2014-08-30 05:30:37 +02:00
* @ return array Array of tabs to show
2008-11-26 20:37:25 +01:00
*/
2008-06-10 20:29:23 +02:00
function security_prepare_head ()
{
2018-01-25 12:06:22 +01:00
global $db , $langs , $conf , $user ;
2011-09-21 17:53:54 +02:00
$h = 0 ;
$head = array ();
2008-06-10 20:29:23 +02:00
2011-09-21 17:53:54 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/security_other.php " ;
2013-03-24 07:11:44 +01:00
$head [ $h ][ 1 ] = $langs -> trans ( " Miscellaneous " );
2011-09-21 17:53:54 +02:00
$head [ $h ][ 2 ] = 'misc' ;
$h ++ ;
2008-06-10 20:29:23 +02:00
2011-04-02 20:55:41 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/security.php " ;
$head [ $h ][ 1 ] = $langs -> trans ( " Passwords " );
$head [ $h ][ 2 ] = 'passwords' ;
$h ++ ;
2015-01-12 13:20:27 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/security_file.php " ;
2017-08-18 16:10:21 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( " Files " ) . ' (' . $langs -> trans ( " Upload " ) . ')' ;
2015-01-12 13:20:27 +01:00
$head [ $h ][ 2 ] = 'file' ;
$h ++ ;
2017-08-18 16:10:21 +02:00
/*
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/security_file_download.php " ;
$head [ $h ][ 1 ] = $langs -> trans ( " Files " ) . ' (' . $langs -> trans ( " Download " ) . ')' ;
$head [ $h ][ 2 ] = 'filedownload' ;
$h ++ ;
*/
2017-08-22 14:47:01 +02:00
2015-01-12 13:20:27 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/proxy.php " ;
$head [ $h ][ 1 ] = $langs -> trans ( " ExternalAccess " );
$head [ $h ][ 2 ] = 'proxy' ;
$h ++ ;
2011-09-21 17:53:54 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/events.php " ;
$head [ $h ][ 1 ] = $langs -> trans ( " Audit " );
$head [ $h ][ 2 ] = 'audit' ;
$h ++ ;
2009-01-21 15:09:42 +01:00
2018-01-25 12:06:22 +01:00
// Show permissions lines
2018-01-26 10:23:24 +01:00
$nbPerms = 0 ;
2018-01-25 12:06:22 +01:00
$sql = " SELECT COUNT(r.id) as nb " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " rights_def as r " ;
$sql .= " WHERE r.libelle NOT LIKE 'tou%' " ; // On ignore droits "tous"
$sql .= " AND entity = " . $conf -> entity ;
$sql .= " AND bydefault = 1 " ;
if ( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS )) $sql .= " AND r.perms NOT LIKE '%_advance' " ; // Hide advanced perms if option is not enabled
$resql = $db -> query ( $sql );
if ( $resql )
{
$obj = $db -> fetch_object ( $resql );
if ( $obj ) $nbPerms = $obj -> nb ;
}
else dol_print_error ( $db );
2011-09-21 17:53:54 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/perms.php " ;
2011-04-02 20:55:41 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( " DefaultRights " );
2019-11-04 18:25:32 +01:00
if ( $nbPerms > 0 ) $head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbPerms . '</span>' ;
2011-04-02 20:55:41 +02:00
$head [ $h ][ 2 ] = 'default' ;
$h ++ ;
return $head ;
2008-06-10 20:29:23 +02:00
}
2008-02-01 01:09:23 +01:00
2019-10-29 11:15:03 +01:00
/**
* Prepare array with list of tabs
2019-10-29 11:16:49 +01:00
* @ param object $object descriptor class
2019-10-29 11:15:03 +01:00
* @ return array Array of tabs to show
*/
function modulehelp_prepare_head ( $object )
{
global $langs , $conf , $user ;
$h = 0 ;
$head = array ();
2019-10-29 11:16:49 +01:00
// FIX for compatibity habitual tabs
$object -> id = $object -> numero ;
2019-10-29 11:15:03 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/modulehelp.php?id= " . $object -> id . '&mode=desc' ;
$head [ $h ][ 1 ] = $langs -> trans ( " Description " );
$head [ $h ][ 2 ] = 'desc' ;
$h ++ ;
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/modulehelp.php?id= " . $object -> id . '&mode=feature' ;
$head [ $h ][ 1 ] = $langs -> trans ( " TechnicalServicesProvided " );
$head [ $h ][ 2 ] = 'feature' ;
$h ++ ;
if ( $object -> isCoreOrExternalModule () == 'external' )
{
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/modulehelp.php?id= " . $object -> id . '&mode=changelog' ;
$head [ $h ][ 1 ] = $langs -> trans ( " ChangeLog " );
$head [ $h ][ 2 ] = 'changelog' ;
$h ++ ;
}
2019-10-29 11:16:49 +01:00
complete_head_from_modules ( $conf , $langs , null , $head , $h , 'modulehelp_admin' );
2009-09-02 00:20:55 +02:00
2019-10-29 11:16:49 +01:00
complete_head_from_modules ( $conf , $langs , null , $head , $h , 'modulehelp_admin' , 'remove' );
2019-10-29 11:15:03 +01:00
return $head ;
}
2016-09-03 18:47:04 +02:00
/**
* Prepare array with list of tabs
*
* @ return array Array of tabs to show
*/
function translation_prepare_head ()
{
global $langs , $conf , $user ;
$h = 0 ;
$head = array ();
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/translation.php?mode=overwrite " ;
2019-05-09 19:32:19 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( " TranslationOverwriteKey " ) . '<span class="fa fa-plus-circle valignmiddle paddingleft"></span>' ;
2016-09-03 18:47:04 +02:00
$head [ $h ][ 2 ] = 'overwrite' ;
$h ++ ;
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/translation.php?mode=searchkey " ;
$head [ $h ][ 1 ] = $langs -> trans ( " TranslationKeySearch " );
$head [ $h ][ 2 ] = 'searchkey' ;
$h ++ ;
2019-01-27 11:55:16 +01:00
complete_head_from_modules ( $conf , $langs , null , $head , $h , 'translation_admin' );
2016-09-03 18:47:04 +02:00
2019-01-27 11:55:16 +01:00
complete_head_from_modules ( $conf , $langs , null , $head , $h , 'translation_admin' , 'remove' );
2016-09-03 18:47:04 +02:00
return $head ;
}
2017-04-08 14:18:10 +02:00
/**
* Prepare array with list of tabs
*
* @ return array Array of tabs to show
*/
function defaultvalues_prepare_head ()
{
global $langs , $conf , $user ;
$h = 0 ;
$head = array ();
2017-04-10 12:51:52 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/defaultvalues.php?mode=createform " ;
$head [ $h ][ 1 ] = $langs -> trans ( " DefaultCreateForm " );
$head [ $h ][ 2 ] = 'createform' ;
$h ++ ;
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/defaultvalues.php?mode=filters " ;
$head [ $h ][ 1 ] = $langs -> trans ( " DefaultSearchFilters " );
$head [ $h ][ 2 ] = 'filters' ;
$h ++ ;
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/defaultvalues.php?mode=sortorder " ;
$head [ $h ][ 1 ] = $langs -> trans ( " DefaultSortOrder " );
$head [ $h ][ 2 ] = 'sortorder' ;
2017-04-08 14:18:10 +02:00
$h ++ ;
2018-11-20 21:26:22 +01:00
if ( ! empty ( $conf -> use_javascript_ajax ))
{
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/defaultvalues.php?mode=focus " ;
$head [ $h ][ 1 ] = $langs -> trans ( " DefaultFocus " );
$head [ $h ][ 2 ] = 'focus' ;
$h ++ ;
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/defaultvalues.php?mode=mandatory " ;
$head [ $h ][ 1 ] = $langs -> trans ( " DefaultMandatory " );
$head [ $h ][ 2 ] = 'mandatory' ;
$h ++ ;
}
2018-09-27 16:38:18 +02:00
2017-04-08 14:18:10 +02:00
/* $head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/translation.php?mode=searchkey " ;
$head [ $h ][ 1 ] = $langs -> trans ( " TranslationKeySearch " );
$head [ $h ][ 2 ] = 'searchkey' ;
$h ++ ; */
2019-01-27 11:55:16 +01:00
complete_head_from_modules ( $conf , $langs , null , $head , $h , 'defaultvalues_admin' );
2017-04-08 14:18:10 +02:00
2019-01-27 11:55:16 +01:00
complete_head_from_modules ( $conf , $langs , null , $head , $h , 'defaultvalues_admin' , 'remove' );
2017-04-08 14:18:10 +02:00
return $head ;
}
2016-09-03 18:47:04 +02:00
2009-09-02 00:20:55 +02:00
/**
* Return list of session
2011-09-16 20:25:10 +02:00
*
2009-09-02 00:20:55 +02:00
* @ return array Array list of sessions
*/
function listOfSessions ()
{
2011-09-21 17:53:54 +02:00
global $conf ;
2009-09-02 00:20:55 +02:00
2011-09-21 17:53:54 +02:00
$arrayofSessions = array ();
2014-01-20 02:21:30 +01:00
// session.save_path can be returned empty so we set a default location and work from there
$sessPath = '/tmp' ;
$iniPath = ini_get ( " session.save_path " );
if ( $iniPath ) {
$sessPath = $iniPath ;
}
$sessPath .= '/' ; // We need the trailing slash
2011-09-21 17:53:54 +02:00
dol_syslog ( 'admin.lib:listOfSessions sessPath=' . $sessPath );
$dh = @ opendir ( dol_osencode ( $sessPath ));
if ( $dh )
{
while (( $file = @ readdir ( $dh )) !== false )
{
2019-01-27 11:55:16 +01:00
if ( preg_match ( '/^sess_/i' , $file ) && $file != " . " && $file != " .. " )
2011-09-21 17:53:54 +02:00
{
$fullpath = $sessPath . $file ;
if ( ! @ is_dir ( $fullpath ) && is_readable ( $fullpath ))
{
$sessValues = file_get_contents ( $fullpath ); // get raw session data
2016-02-03 01:00:10 +01:00
// Example of possible value
2018-05-27 15:04:12 +02:00
//$sessValues = 'newtoken|s:32:"1239f7a0c4b899200fe9ca5ea394f307";dol_loginmesg|s:0:"";newtoken|s:32:"1236457104f7ae0f328c2928973f3cb5";dol_loginmesg|s:0:"";token|s:32:"123615ad8d650c5cc4199b9a1a76783f";
// dol_login|s:5:"admin";dol_authmode|s:8:"dolibarr";dol_tz|s:1:"1";dol_tz_string|s:13:"Europe/Berlin";dol_dst|i:0;dol_dst_observed|s:1:"1";dol_dst_first|s:0:"";dol_dst_second|s:0:"";dol_screenwidth|s:4:"1920";
// dol_screenheight|s:3:"971";dol_company|s:12:"MyBigCompany";dol_entity|i:1;mainmenu|s:4:"home";leftmenuopened|s:10:"admintools";idmenu|s:0:"";leftmenu|s:10:"admintools";';
2016-03-02 11:23:57 +01:00
2019-01-27 11:55:16 +01:00
if ( preg_match ( '/dol_login/i' , $sessValues ) && // limit to dolibarr session
( preg_match ( '/dol_entity\|i:' . $conf -> entity . ';/i' , $sessValues ) || 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
2011-09-21 17:53:54 +02:00
{
$tmp = explode ( '_' , $file );
$idsess = $tmp [ 1 ];
2019-04-23 10:24:16 +02:00
$regs = array ();
$loginfound = preg_match ( '/dol_login\|s:[0-9]+:"([A-Za-z0-9]+)"/i' , $sessValues , $regs );
if ( $loginfound ) $arrayofSessions [ $idsess ][ " login " ] = $regs [ 1 ];
2011-09-21 17:53:54 +02:00
$arrayofSessions [ $idsess ][ " age " ] = time () - filectime ( $fullpath );
$arrayofSessions [ $idsess ][ " creation " ] = filectime ( $fullpath );
$arrayofSessions [ $idsess ][ " modification " ] = filemtime ( $fullpath );
$arrayofSessions [ $idsess ][ " raw " ] = $sessValues ;
}
}
}
}
@ closedir ( $dh );
}
return $arrayofSessions ;
2009-09-02 00:20:55 +02:00
}
/**
* Purge existing sessions
2011-09-16 20:25:10 +02:00
*
* @ param int $mysessionid To avoid to try to delete my own session
* @ return int > 0 if OK , < 0 if KO
2009-09-02 00:20:55 +02:00
*/
function purgeSessions ( $mysessionid )
{
2011-09-21 17:53:54 +02:00
global $conf ;
$sessPath = ini_get ( " session.save_path " ) . " / " ;
dol_syslog ( 'admin.lib:purgeSessions mysessionid=' . $mysessionid . ' sessPath=' . $sessPath );
$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
2019-01-27 11:55:16 +01:00
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
2011-09-21 17:53:54 +02:00
{
$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 );
2009-09-02 00:20:55 +02:00
2011-09-21 17:53:54 +02:00
if ( ! $error ) return 1 ;
else return - $error ;
2009-09-02 00:20:55 +02:00
}
2010-11-13 19:57:10 +01:00
/**
* Enable a module
2011-09-16 20:25:10 +02:00
*
* @ param string $value Name of module to activate
* @ param int $withdeps Activate / Disable also all dependencies
2016-09-30 18:26:32 +02:00
* @ return array array ( 'nbmodules' => nb modules activated with success , 'errors=>array of error messages, ' nbperms ' => Nb permission added );
2010-11-13 19:57:10 +01:00
*/
2019-01-27 15:20:16 +01:00
function activateModule ( $value , $withdeps = 1 )
2010-11-13 19:57:10 +01:00
{
2019-04-23 10:24:16 +02:00
global $db , $langs , $conf , $mysoc ;
$ret = array ();
2010-11-13 19:57:10 +01:00
2016-10-11 10:24:10 +02:00
// Check parameters
if ( empty ( $value )) {
$ret [ 'errors' ][] = 'ErrorBadParameter' ;
return $ret ;
}
2010-11-13 19:57:10 +01:00
2016-09-30 18:26:32 +02:00
$ret = array ( 'nbmodules' => 0 , 'errors' => array (), 'nbperms' => 0 );
2011-09-16 20:25:10 +02:00
$modName = $value ;
$modFile = $modName . " .class.php " ;
2010-11-13 19:57:10 +01:00
2011-12-02 23:23:07 +01:00
// Loop on each directory to fill $modulesdir
2015-10-21 05:06:19 +02:00
$modulesdir = dolGetModulesDirs ();
2010-11-13 19:57:10 +01:00
2015-10-22 13:13:02 +02:00
// Loop on each modulesdir directories
2011-12-02 23:23:07 +01:00
$found = false ;
2011-09-16 20:25:10 +02:00
foreach ( $modulesdir as $dir )
{
2011-09-21 17:53:54 +02:00
if ( file_exists ( $dir . $modFile ))
{
2012-08-23 02:04:35 +02:00
$found =@ include_once $dir . $modFile ;
2011-09-21 17:53:54 +02:00
if ( $found ) break ;
}
2011-09-16 20:25:10 +02:00
}
2010-11-13 19:57:10 +01:00
2011-09-16 20:25:10 +02:00
$objMod = new $modName ( $db );
2010-11-13 19:57:10 +01:00
2011-09-16 20:25:10 +02:00
// Test if PHP version ok
$verphp = versionphparray ();
$vermin = isset ( $objMod -> phpmin ) ? $objMod -> phpmin : 0 ;
2016-10-11 10:24:10 +02:00
if ( is_array ( $vermin ) && versioncompare ( $verphp , $vermin ) < 0 ) {
$ret [ 'errors' ][] = $langs -> trans ( " ErrorModuleRequirePHPVersion " , versiontostring ( $vermin ));
return $ret ;
}
2010-11-13 19:57:10 +01:00
2011-09-16 20:25:10 +02:00
// Test if Dolibarr version ok
$verdol = versiondolibarrarray ();
$vermin = isset ( $objMod -> need_dolibarr_version ) ? $objMod -> need_dolibarr_version : 0 ;
2018-02-26 15:03:09 +01:00
//print 'version: '.versioncompare($verdol,$vermin).' - '.join(',',$verdol).' - '.join(',',$vermin);exit;
2016-10-11 10:24:10 +02:00
if ( is_array ( $vermin ) && versioncompare ( $verdol , $vermin ) < 0 ) {
$ret [ 'errors' ][] = $langs -> trans ( " ErrorModuleRequireDolibarrVersion " , versiontostring ( $vermin ));
return $ret ;
}
// Test if javascript requirement ok
if ( ! empty ( $objMod -> need_javascript_ajax ) && empty ( $conf -> use_javascript_ajax )) {
$ret [ 'errors' ][] = $langs -> trans ( " ErrorModuleRequireJavascript " );
return $ret ;
}
2010-11-13 19:57:10 +01:00
2017-02-16 09:26:18 +01:00
$const_name = $objMod -> const_name ;
if ( ! empty ( $conf -> global -> $const_name )){
return $ret ;
}
2017-05-06 20:43:14 +02:00
$result = $objMod -> init (); // Enable module
2018-03-15 21:48:51 +01:00
2017-06-17 11:43:00 +02:00
if ( $result <= 0 )
2010-11-13 19:57:10 +01:00
{
2016-09-30 18:26:32 +02:00
$ret [ 'errors' ][] = $objMod -> error ;
}
else
{
if ( $withdeps )
2010-11-13 19:57:10 +01:00
{
2016-09-30 18:26:32 +02:00
if ( isset ( $objMod -> depends ) && is_array ( $objMod -> depends ) && ! empty ( $objMod -> depends ))
2010-11-13 19:57:10 +01:00
{
2017-03-09 15:16:16 +01:00
// Activation of modules this module depends on
2018-10-30 13:54:11 +01:00
// this->depends may be array('modModule1', 'mmodModule2') or array('always1'=>"modModule1", 'FR'=>'modModule2')
2017-06-09 16:57:20 +02:00
foreach ( $objMod -> depends as $key => $modulestring )
2016-09-30 18:26:32 +02:00
{
2018-10-30 13:54:11 +01:00
//var_dump((! is_numeric($key)) && ! preg_match('/^always/', $key) && $mysoc->country_code && ! preg_match('/^'.$mysoc->country_code.'/', $key));exit;
if (( ! is_numeric ( $key )) && ! preg_match ( '/^always/' , $key ) && $mysoc -> country_code && ! preg_match ( '/^' . $mysoc -> country_code . '/' , $key ))
2017-03-09 15:16:16 +01:00
{
dol_syslog ( " We are not concerned by dependency with key= " . $key . " because our country is " . $mysoc -> country_code );
continue ;
}
2016-09-30 18:26:32 +02:00
$activate = false ;
foreach ( $modulesdir as $dir )
{
2017-03-09 15:16:16 +01:00
if ( file_exists ( $dir . $modulestring . " .class.php " ))
2016-09-30 18:26:32 +02:00
{
2017-03-09 15:16:16 +01:00
$resarray = activateModule ( $modulestring );
2017-02-16 09:26:18 +01:00
if ( empty ( $resarray [ 'errors' ])){
$activate = true ;
} else {
foreach ( $resarray [ 'errors' ] as $errorMessage ){
dol_syslog ( $errorMessage , LOG_ERR );
}
}
2016-09-30 18:26:32 +02:00
break ;
}
}
2017-06-17 11:43:00 +02:00
2016-09-30 18:26:32 +02:00
if ( $activate )
{
$ret [ 'nbmodules' ] += $resarray [ 'nbmodules' ];
$ret [ 'nbperms' ] += $resarray [ 'nbperms' ];
}
2017-06-17 11:43:00 +02:00
else
2016-09-30 18:26:32 +02:00
{
2017-03-09 15:16:16 +01:00
$ret [ 'errors' ][] = $langs -> trans ( 'activateModuleDependNotSatisfied' , $objMod -> name , $modulestring );
2016-09-30 18:26:32 +02:00
}
}
2010-11-13 19:57:10 +01:00
}
2017-06-17 11:43:00 +02:00
2016-09-30 18:26:32 +02:00
if ( isset ( $objMod -> conflictwith ) && is_array ( $objMod -> conflictwith ) && ! empty ( $objMod -> conflictwith ))
2010-11-13 19:57:10 +01:00
{
2016-09-30 18:26:32 +02:00
// Desactivation des modules qui entrent en conflit
$num = count ( $objMod -> conflictwith );
for ( $i = 0 ; $i < $num ; $i ++ )
{
foreach ( $modulesdir as $dir )
{
if ( file_exists ( $dir . $objMod -> conflictwith [ $i ] . " .class.php " ))
{
2019-01-27 11:55:16 +01:00
unActivateModule ( $objMod -> conflictwith [ $i ], 0 );
2016-09-30 18:26:32 +02:00
}
}
}
2010-11-13 19:57:10 +01:00
}
}
}
2017-06-17 11:43:00 +02:00
if ( ! count ( $ret [ 'errors' ]))
2016-09-30 18:26:32 +02:00
{
$ret [ 'nbmodules' ] ++ ;
$ret [ 'nbperms' ] += count ( $objMod -> rights );
}
2017-06-17 11:43:00 +02:00
2010-11-13 19:57:10 +01:00
return $ret ;
}
/**
* Disable a module
2011-09-16 20:25:10 +02:00
*
* @ param string $value Nom du module a desactiver
* @ param int $requiredby 1 = Desactive aussi modules dependants
* @ return string Error message or '' ;
2010-11-13 19:57:10 +01:00
*/
2019-01-27 15:20:16 +01:00
function unActivateModule ( $value , $requiredby = 1 )
2010-11-13 19:57:10 +01:00
{
global $db , $modules , $conf ;
2011-09-16 20:25:10 +02:00
// Check parameters
if ( empty ( $value )) return 'ErrorBadParameter' ;
2010-11-13 19:57:10 +01:00
$ret = '' ;
2011-09-16 20:25:10 +02:00
$modName = $value ;
$modFile = $modName . " .class.php " ;
2011-01-16 02:14:48 +01:00
2011-12-02 23:23:07 +01:00
// Loop on each directory to fill $modulesdir
2015-10-21 05:06:19 +02:00
$modulesdir = dolGetModulesDirs ();
2011-01-16 02:14:48 +01:00
2015-10-22 13:13:02 +02:00
// Loop on each modulesdir directories
2011-12-02 23:23:07 +01:00
$found = false ;
2011-09-16 20:25:10 +02:00
foreach ( $modulesdir as $dir )
{
2011-09-21 17:53:54 +02:00
if ( file_exists ( $dir . $modFile ))
{
2012-08-23 02:04:35 +02:00
$found =@ include_once $dir . $modFile ;
2011-09-21 17:53:54 +02:00
if ( $found ) break ;
}
2011-09-16 20:25:10 +02:00
}
2010-11-13 19:57:10 +01:00
2011-09-16 20:25:10 +02:00
if ( $found )
{
$objMod = new $modName ( $db );
$result = $objMod -> remove ();
2015-06-05 03:32:09 +02:00
if ( $result <= 0 ) $ret = $objMod -> error ;
2011-09-16 20:25:10 +02:00
}
2019-05-18 19:22:17 +02:00
else // We come here when we try to unactivate a module when module does not exists anymore in sources
2011-09-16 20:25:10 +02:00
{
2019-05-18 19:22:17 +02:00
//print $dir.$modFile;exit;
2015-11-04 16:43:24 +01:00
// TODO Replace this after DolibarrModules is moved as abstract class with a try catch to show module we try to disable has not been found or could not be loaded
2017-07-16 14:57:30 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/DolibarrModules.class.php' ;
$genericMod = new DolibarrModules ( $db );
2019-01-27 11:55:16 +01:00
$genericMod -> name = preg_replace ( '/^mod/i' , '' , $modName );
$genericMod -> rights_class = strtolower ( preg_replace ( '/^mod/i' , '' , $modName ));
$genericMod -> const_name = 'MAIN_MODULE_' . strtoupper ( preg_replace ( '/^mod/i' , '' , $modName ));
2012-02-15 13:55:00 +01:00
dol_syslog ( " modules::unActivateModule Failed to find module file, we use generic function with name " . $modName );
2019-05-18 19:22:17 +02:00
$genericMod -> remove ( '' );
2010-11-13 19:57:10 +01:00
}
2019-05-18 19:28:14 +02:00
// Disable modules that depends on module we disable
if ( ! $ret && $requiredby && is_object ( $objMod ) && is_array ( $objMod -> requiredby ))
2010-11-13 19:57:10 +01:00
{
2011-09-16 20:25:10 +02:00
$countrb = count ( $objMod -> requiredby );
for ( $i = 0 ; $i < $countrb ; $i ++ )
2010-11-13 19:57:10 +01:00
{
2015-09-07 17:15:41 +02:00
//var_dump($objMod->requiredby[$i]);
2012-02-15 13:55:00 +01:00
unActivateModule ( $objMod -> requiredby [ $i ]);
2010-11-13 19:57:10 +01:00
}
}
return $ret ;
}
2011-01-23 20:51:29 +01:00
/**
2018-03-13 12:13:47 +01:00
* Add external modules to list of dictionaries .
* Addition is done into var $taborder , $tabname , etc ... that are passed with pointers .
2011-09-16 20:25:10 +02:00
*
2014-09-27 16:00:11 +02:00
* @ param array $taborder Taborder
* @ param array $tabname Tabname
2014-09-28 02:46:20 +02:00
* @ param array $tablib Tablib
* @ param array $tabsql Tabsql
* @ param array $tabsqlsort Tabsqlsort
2014-09-27 16:00:11 +02:00
* @ param array $tabfield Tabfield
* @ param array $tabfieldvalue Tabfieldvalue
2014-09-28 02:46:20 +02:00
* @ param array $tabfieldinsert Tabfieldinsert
2014-09-27 16:00:11 +02:00
* @ param array $tabrowid Tabrowid
* @ param array $tabcond Tabcond
* @ param array $tabhelp Tabhelp
2014-09-28 02:46:20 +02:00
* @ param array $tabfieldcheck Tabfieldcheck
2011-09-16 20:25:10 +02:00
* @ return int 1
2011-01-23 20:51:29 +01:00
*/
2019-01-27 15:20:16 +01:00
function complete_dictionary_with_modules ( & $taborder , & $tabname , & $tablib , & $tabsql , & $tabsqlsort , & $tabfield , & $tabfieldvalue , & $tabfieldinsert , & $tabrowid , & $tabcond , & $tabhelp , & $tabfieldcheck )
2011-01-23 20:51:29 +01:00
{
global $db , $modules , $conf , $langs ;
2019-09-05 20:06:09 +02:00
dol_syslog ( " complete_dictionary_with_modules Search external modules to complete the list of dictionnary tables " , LOG_DEBUG , 1 );
2011-01-23 20:51:29 +01:00
// Search modules
2015-08-31 17:42:08 +02:00
$modulesdir = dolGetModulesDirs ();
2011-01-23 20:51:29 +01:00
$i = 0 ; // is a sequencer of modules found
$j = 0 ; // j is module number. Automatically affected if module number not defined.
2011-12-13 00:30:54 +01:00
foreach ( $modulesdir as $dir )
{
// Load modules attributes in arrays (name, numero, orders) from dir directory
//print $dir."\n<br>";
dol_syslog ( " Scan directory " . $dir . " for modules " );
$handle =@ opendir ( dol_osencode ( $dir ));
if ( is_resource ( $handle ))
{
2011-01-23 20:51:29 +01:00
while (( $file = readdir ( $handle )) !== false )
{
//print "$i ".$file."\n<br>";
if ( is_readable ( $dir . $file ) && substr ( $file , 0 , 3 ) == 'mod' && substr ( $file , dol_strlen ( $file ) - 10 ) == '.class.php' )
{
$modName = substr ( $file , 0 , dol_strlen ( $file ) - 10 );
if ( $modName )
{
2012-08-23 02:04:35 +02:00
include_once $dir . $file ;
2011-01-23 20:51:29 +01:00
$objMod = new $modName ( $db );
if ( $objMod -> numero > 0 )
{
$j = $objMod -> numero ;
}
else
{
$j = 1000 + $i ;
}
$modulequalified = 1 ;
// We discard modules according to features level (PS: if module is activated we always show it)
2019-01-27 11:55:16 +01:00
$const_name = 'MAIN_MODULE_' . strtoupper ( preg_replace ( '/^mod/i' , '' , get_class ( $objMod )));
2011-01-23 20:51:29 +01:00
if ( $objMod -> version == 'development' && $conf -> global -> MAIN_FEATURES_LEVEL < 2 && ! $conf -> global -> $const_name ) $modulequalified = 0 ;
if ( $objMod -> version == 'experimental' && $conf -> global -> MAIN_FEATURES_LEVEL < 1 && ! $conf -> global -> $const_name ) $modulequalified = 0 ;
2014-06-12 15:28:11 +02:00
//If module is not activated disqualified
if ( empty ( $conf -> global -> $const_name )) $modulequalified = 0 ;
2011-01-23 20:51:29 +01:00
if ( $modulequalified )
{
2011-10-19 01:51:40 +02:00
// Load languages files of module
2018-03-13 12:13:47 +01:00
if ( isset ( $objMod -> langfiles ) && is_array ( $objMod -> langfiles )) {
foreach ( $objMod -> langfiles as $langfile ) {
$langs -> load ( $langfile );
}
}
// Complete the arrays &$tabname,&$tablib,&$tabsql,&$tabsqlsort,&$tabfield,&$tabfieldvalue,&$tabfieldinsert,&$tabrowid,&$tabcond
2014-07-27 23:51:58 +02:00
if ( empty ( $objMod -> dictionaries ) && ! empty ( $objMod -> dictionnaries )) $objMod -> dictionaries = $objMod -> dictionnaries ; // For backward compatibility
2014-02-10 01:30:48 +01:00
if ( ! empty ( $objMod -> dictionaries ))
2011-01-23 20:51:29 +01:00
{
2016-11-30 17:46:53 +01:00
//var_dump($objMod->dictionaries['tabname']);
2016-03-02 23:07:42 +01:00
$nbtabname = $nbtablib = $nbtabsql = $nbtabsqlsort = $nbtabfield = $nbtabfieldvalue = $nbtabfieldinsert = $nbtabrowid = $nbtabcond = $nbtabfieldcheck = $nbtabhelp = 0 ;
2018-03-13 12:13:47 +01:00
foreach ( $objMod -> dictionaries [ 'tabname' ] as $val ) { $nbtabname ++ ; $taborder [] = max ( $taborder ) + 1 ; $tabname [] = $val ; } // Position
2016-03-02 23:07:42 +01:00
foreach ( $objMod -> dictionaries [ 'tablib' ] as $val ) { $nbtablib ++ ; $tablib [] = $val ; }
foreach ( $objMod -> dictionaries [ 'tabsql' ] as $val ) { $nbtabsql ++ ; $tabsql [] = $val ; }
foreach ( $objMod -> dictionaries [ 'tabsqlsort' ] as $val ) { $nbtabsqlsort ++ ; $tabsqlsort [] = $val ; }
foreach ( $objMod -> dictionaries [ 'tabfield' ] as $val ) { $nbtabfield ++ ; $tabfield [] = $val ; }
foreach ( $objMod -> dictionaries [ 'tabfieldvalue' ] as $val ) { $nbtabfieldvalue ++ ; $tabfieldvalue [] = $val ; }
foreach ( $objMod -> dictionaries [ 'tabfieldinsert' ] as $val ) { $nbtabfieldinsert ++ ; $tabfieldinsert [] = $val ; }
foreach ( $objMod -> dictionaries [ 'tabrowid' ] as $val ) { $nbtabrowid ++ ; $tabrowid [] = $val ; }
foreach ( $objMod -> dictionaries [ 'tabcond' ] as $val ) { $nbtabcond ++ ; $tabcond [] = $val ; }
if ( ! empty ( $objMod -> dictionaries [ 'tabhelp' ])) foreach ( $objMod -> dictionaries [ 'tabhelp' ] as $val ) { $nbtabhelp ++ ; $tabhelp [] = $val ; }
if ( ! empty ( $objMod -> dictionaries [ 'tabfieldcheck' ])) foreach ( $objMod -> dictionaries [ 'tabfieldcheck' ] as $val ) { $nbtabfieldcheck ++ ; $tabfieldcheck [] = $val ; }
2016-04-28 13:56:17 +02:00
2016-03-02 23:07:42 +01:00
if ( $nbtabname != $nbtablib || $nbtablib != $nbtabsql || $nbtabsql != $nbtabsqlsort )
2011-01-23 22:24:47 +01:00
{
2016-03-02 23:07:42 +01:00
print 'Error in descriptor of module ' . $const_name . '. Array ->dictionaries has not same number of record for key "tabname", "tablib", "tabsql" and "tabsqlsort"' ;
//print "$const_name: $nbtabname=$nbtablib=$nbtabsql=$nbtabsqlsort=$nbtabfield=$nbtabfieldvalue=$nbtabfieldinsert=$nbtabrowid=$nbtabcond=$nbtabfieldcheck=$nbtabhelp\n";
2011-01-23 22:24:47 +01:00
}
2018-03-13 12:13:47 +01:00
else
{
$taborder [] = 0 ; // Add an empty line
}
2011-01-23 20:51:29 +01:00
}
$j ++ ;
$i ++ ;
}
else dol_syslog ( " Module " . get_class ( $objMod ) . " not qualified " );
}
}
}
closedir ( $handle );
}
else
{
dol_syslog ( " htdocs/admin/modules.php: Failed to open directory " . $dir . " . See permission and open_basedir option. " , LOG_WARNING );
}
}
2019-09-05 20:06:09 +02:00
dol_syslog ( " " , LOG_DEBUG , - 1 );
2011-09-16 20:25:10 +02:00
return 1 ;
2011-01-23 20:51:29 +01:00
}
2017-12-08 10:13:03 +01:00
/**
2018-03-19 12:52:09 +01:00
* Activate external modules mandatory when country is country_code
2017-12-08 10:13:03 +01:00
*
* @ param string $country_code CountryCode
* @ return int 1
*/
2017-12-08 16:15:41 +01:00
function activateModulesRequiredByCountry ( $country_code )
2017-12-08 10:13:03 +01:00
{
global $db , $conf , $langs ;
$modulesdir = dolGetModulesDirs ();
2017-12-08 16:15:41 +01:00
2017-12-08 10:13:03 +01:00
foreach ( $modulesdir as $dir )
{
// Load modules attributes in arrays (name, numero, orders) from dir directory
dol_syslog ( " Scan directory " . $dir . " for modules " );
$handle =@ opendir ( dol_osencode ( $dir ));
if ( is_resource ( $handle ))
{
while (( $file = readdir ( $handle )) !== false )
{
if ( is_readable ( $dir . $file ) && substr ( $file , 0 , 3 ) == 'mod' && substr ( $file , dol_strlen ( $file ) - 10 ) == '.class.php' )
{
$modName = substr ( $file , 0 , dol_strlen ( $file ) - 10 );
2017-12-08 16:15:41 +01:00
2017-12-08 10:13:03 +01:00
if ( $modName )
{
include_once $dir . $file ;
$objMod = new $modName ( $db );
2017-12-08 16:15:41 +01:00
2017-12-08 10:13:03 +01:00
$modulequalified = 1 ;
2017-12-08 16:15:41 +01:00
2017-12-08 10:13:03 +01:00
// We discard modules according to features level (PS: if module is activated we always show it)
2019-01-27 11:55:16 +01:00
$const_name = 'MAIN_MODULE_' . strtoupper ( preg_replace ( '/^mod/i' , '' , get_class ( $objMod )));
2017-12-08 16:15:41 +01:00
2017-12-08 10:13:03 +01:00
if ( $objMod -> version == 'development' && $conf -> global -> MAIN_FEATURES_LEVEL < 2 ) $modulequalified = 0 ;
if ( $objMod -> version == 'experimental' && $conf -> global -> MAIN_FEATURES_LEVEL < 1 ) $modulequalified = 0 ;
if ( ! empty ( $conf -> global -> $const_name )) $modulequalified = 0 ; // already activated
2017-12-08 16:15:41 +01:00
2017-12-08 10:13:03 +01:00
if ( $modulequalified )
{
// Load languages files of module
if ( isset ( $objMod -> automatic_activation ) && is_array ( $objMod -> automatic_activation ) && isset ( $objMod -> automatic_activation [ $country_code ]))
{
activateModule ( $modName );
2017-12-08 16:15:41 +01:00
2018-07-25 15:25:23 +02:00
setEventMessages ( $objMod -> automatic_activation [ $country_code ], null , 'warnings' );
2017-12-08 10:13:03 +01:00
}
}
else dol_syslog ( " Module " . get_class ( $objMod ) . " not qualified " );
}
}
}
closedir ( $handle );
}
else
{
dol_syslog ( " htdocs/admin/modules.php: Failed to open directory " . $dir . " . See permission and open_basedir option. " , LOG_WARNING );
}
}
2017-12-08 16:15:41 +01:00
2017-12-08 10:13:03 +01:00
return 1 ;
}
2015-09-08 13:11:26 +02:00
/**
2019-09-05 20:06:09 +02:00
* Search external modules to complete the list of contact element
2015-09-08 13:11:26 +02:00
*
* @ param array $elementList elementList
* @ return int 1
*/
function complete_elementList_with_modules ( & $elementList )
{
global $db , $modules , $conf , $langs ;
// Search modules
$filename = array ();
$modules = array ();
$orders = array ();
$categ = array ();
$dirmod = array ();
2015-10-21 05:06:19 +02:00
2015-09-08 13:11:26 +02:00
$i = 0 ; // is a sequencer of modules found
$j = 0 ; // j is module number. Automatically affected if module number not defined.
2019-09-05 20:06:09 +02:00
dol_syslog ( " complete_elementList_with_modules Search external modules to complete the list of contact element " , LOG_DEBUG , 1 );
2015-10-21 05:06:19 +02:00
$modulesdir = dolGetModulesDirs ();
2015-09-08 13:11:26 +02:00
foreach ( $modulesdir as $dir )
{
// Load modules attributes in arrays (name, numero, orders) from dir directory
//print $dir."\n<br>";
dol_syslog ( " Scan directory " . $dir . " for modules " );
$handle =@ opendir ( dol_osencode ( $dir ));
if ( is_resource ( $handle ))
{
while (( $file = readdir ( $handle )) !== false )
{
//print "$i ".$file."\n<br>";
if ( is_readable ( $dir . $file ) && substr ( $file , 0 , 3 ) == 'mod' && substr ( $file , dol_strlen ( $file ) - 10 ) == '.class.php' )
{
$modName = substr ( $file , 0 , dol_strlen ( $file ) - 10 );
if ( $modName )
{
include_once $dir . $file ;
$objMod = new $modName ( $db );
if ( $objMod -> numero > 0 )
{
$j = $objMod -> numero ;
}
else
{
$j = 1000 + $i ;
}
$modulequalified = 1 ;
// We discard modules according to features level (PS: if module is activated we always show it)
2019-01-27 11:55:16 +01:00
$const_name = 'MAIN_MODULE_' . strtoupper ( preg_replace ( '/^mod/i' , '' , get_class ( $objMod )));
2015-09-08 13:11:26 +02:00
if ( $objMod -> version == 'development' && $conf -> global -> MAIN_FEATURES_LEVEL < 2 && ! $conf -> global -> $const_name ) $modulequalified = 0 ;
if ( $objMod -> version == 'experimental' && $conf -> global -> MAIN_FEATURES_LEVEL < 1 && ! $conf -> global -> $const_name ) $modulequalified = 0 ;
//If module is not activated disqualified
if ( empty ( $conf -> global -> $const_name )) $modulequalified = 0 ;
if ( $modulequalified )
{
// Load languages files of module
if ( isset ( $objMod -> langfiles ) && is_array ( $objMod -> langfiles ))
{
foreach ( $objMod -> langfiles as $langfile )
{
$langs -> load ( $langfile );
}
}
$modules [ $i ] = $objMod ;
$filename [ $i ] = $modName ;
2018-03-04 11:09:53 +01:00
$orders [ $i ] = $objMod -> family . " _ " . $j ; // Sort on family then module number
$dirmod [ $i ] = $dir ;
2015-09-08 13:11:26 +02:00
//print "x".$modName." ".$orders[$i]."\n<br>";
2018-03-04 11:09:53 +01:00
2015-10-21 05:06:19 +02:00
if ( ! empty ( $objMod -> module_parts [ 'contactelement' ]))
2015-09-08 13:11:26 +02:00
{
$elementList [ $objMod -> name ] = $langs -> trans ( $objMod -> name );
}
$j ++ ;
$i ++ ;
}
else dol_syslog ( " Module " . get_class ( $objMod ) . " not qualified " );
}
}
}
closedir ( $handle );
}
else
{
dol_syslog ( " htdocs/admin/modules.php: Failed to open directory " . $dir . " . See permission and open_basedir option. " , LOG_WARNING );
}
}
2019-09-05 20:06:09 +02:00
dol_syslog ( " " , LOG_DEBUG , - 1 );
2015-09-08 13:11:26 +02:00
return 1 ;
}
2012-01-11 18:43:38 +01:00
/**
* Show array with constants to edit
*
2018-11-03 12:37:52 +01:00
* @ param array $tableau Array of constants array ( 'key' => array ( 'type' => type , 'label' => label )
* where type can be 'string' , 'text' , 'textarea' , 'html' , 'yesno' , 'emailtemplate:xxx' , ...
2019-01-31 20:53:59 +01:00
* @ param int $strictw3c 0 = Include form into table ( deprecated ), 1 = Form is outside table to respect W3C ( no form into table ), 2 = No form nor button at all ( form is output by caller , recommanded )
2017-05-13 13:02:55 +02:00
* @ param string $helptext Help
2012-01-11 18:43:38 +01:00
* @ return void
*/
2019-01-27 15:20:16 +01:00
function form_constantes ( $tableau , $strictw3c = 0 , $helptext = '' )
2012-01-11 18:43:38 +01:00
{
2019-01-31 20:53:59 +01:00
global $db , $langs , $conf , $user ;
2018-03-23 16:09:46 +01:00
global $_Avery_Labels ;
2012-01-11 18:43:38 +01:00
$form = new Form ( $db );
2019-01-31 20:53:59 +01:00
if ( ! empty ( $strictw3c ) && $strictw3c == 1 )
{
print " \n " . '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="POST">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="updateall">' ;
}
2013-06-05 15:44:42 +02:00
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2012-01-11 18:43:38 +01:00
print '<tr class="liste_titre">' ;
2017-09-12 11:17:23 +02:00
print '<td class="titlefield">' . $langs -> trans ( " Description " ) . '</td>' ;
2017-05-13 13:02:55 +02:00
print '<td>' ;
$text = $langs -> trans ( " Value " );
print $form -> textwithpicto ( $text , $helptext , 1 , 'help' , '' , 0 , 2 , 'idhelptext' );
print '</td>' ;
2013-05-09 22:39:31 +02:00
if ( empty ( $strictw3c )) print '<td align="center" width="80">' . $langs -> trans ( " Action " ) . '</td>' ;
2012-01-11 18:43:38 +01:00
print " </tr> \n " ;
2018-11-03 12:37:52 +01:00
$label = '' ;
2018-03-23 16:09:46 +01:00
foreach ( $tableau as $key => $const ) // Loop on each param
2012-01-11 18:43:38 +01:00
{
2018-11-03 12:37:52 +01:00
$label = '' ;
2018-03-23 16:09:46 +01:00
// $const is a const key like 'MYMODULE_ABC'
2018-11-03 12:37:52 +01:00
if ( is_numeric ( $key )) { // Very old behaviour
2018-03-23 16:09:46 +01:00
$type = 'string' ;
}
else
{
2018-11-03 12:37:52 +01:00
if ( is_array ( $const ))
{
$type = $const [ 'type' ];
$label = $const [ 'label' ];
$const = $key ;
}
else
{
$type = $const ;
$const = $key ;
}
2018-03-23 16:09:46 +01:00
}
2012-01-11 18:43:38 +01:00
$sql = " SELECT " ;
$sql .= " rowid " ;
$sql .= " , " . $db -> decrypt ( 'name' ) . " as name " ;
$sql .= " , " . $db -> decrypt ( 'value' ) . " as value " ;
$sql .= " , type " ;
$sql .= " , note " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " const " ;
2018-03-23 16:09:46 +01:00
$sql .= " WHERE " . $db -> decrypt ( 'name' ) . " = ' " . $db -> escape ( $const ) . " ' " ;
2012-09-13 11:52:50 +02:00
$sql .= " AND entity IN (0, " . $conf -> entity . " ) " ;
2012-01-11 18:43:38 +01:00
$sql .= " ORDER BY name ASC, entity DESC " ;
$result = $db -> query ( $sql );
2014-06-12 11:31:53 +02:00
dol_syslog ( " List params " , LOG_DEBUG );
2012-01-11 18:43:38 +01:00
if ( $result )
{
$obj = $db -> fetch_object ( $result ); // Take first result of select
2017-06-17 11:43:00 +02:00
2018-03-23 16:09:46 +01:00
if ( empty ( $obj )) // If not yet into table
{
$obj = ( object ) array ( 'rowid' => '' , 'name' => $const , 'value' => '' , 'type' => $type , 'note' => '' );
2012-09-13 11:52:50 +02:00
}
2018-03-23 16:09:46 +01:00
if ( empty ( $strictw3c ))
{
print " \n " . '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="POST">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
}
2012-01-11 18:43:38 +01:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2012-01-11 18:43:38 +01:00
2013-05-09 22:39:31 +02:00
// Show constant
2012-01-11 18:43:38 +01:00
print '<td>' ;
2018-03-23 16:09:46 +01:00
if ( empty ( $strictw3c )) print '<input type="hidden" name="action" value="update">' ;
2013-05-09 22:39:31 +02:00
print '<input type="hidden" name="rowid' . ( empty ( $strictw3c ) ? '' : '[]' ) . '" value="' . $obj -> rowid . '">' ;
print '<input type="hidden" name="constname' . ( empty ( $strictw3c ) ? '' : '[]' ) . '" value="' . $const . '">' ;
2018-03-23 16:09:46 +01:00
print '<input type="hidden" name="constnote_' . $obj -> name . '" value="' . nl2br ( dol_escape_htmltag ( $obj -> note )) . '">' ;
print '<input type="hidden" name="consttype_' . $obj -> name . '" value="' . ( $obj -> type ? $obj -> type : 'string' ) . '">' ;
2012-01-11 18:43:38 +01:00
2018-11-03 12:37:52 +01:00
print ( $label ? $label : $langs -> trans ( 'Desc' . $const ));
2012-01-11 18:43:38 +01:00
2012-07-30 08:21:05 +02:00
if ( $const == 'ADHERENT_MAILMAN_URL' )
2012-01-11 18:43:38 +01:00
{
print '. ' . $langs -> trans ( " Example " ) . ': <a href="#" id="exampleclick1">' . img_down () . '</a><br>' ;
2015-06-08 17:13:23 +02:00
//print 'http://lists.exampe.com/cgi-bin/mailman/admin/%LISTE%/members?adminpw=%MAILMAN_ADMINPW%&subscribees=%EMAIL%&send_welcome_msg_to_this_batch=1';
2012-01-11 18:43:38 +01:00
print '<div id="example1" class="hidden">' ;
2015-06-08 17:13:23 +02:00
print 'http://lists.example.com/cgi-bin/mailman/admin/%LISTE%/members/add?subscribees_upload=%EMAIL%&adminpw=%MAILMAN_ADMINPW%&subscribe_or_invite=0&send_welcome_msg_to_this_batch=0&notification_to_list_owner=0' ;
2012-01-11 18:43:38 +01:00
print '</div>' ;
}
2012-07-30 08:21:05 +02:00
if ( $const == 'ADHERENT_MAILMAN_UNSUB_URL' )
2012-01-11 18:43:38 +01:00
{
print '. ' . $langs -> trans ( " Example " ) . ': <a href="#" id="exampleclick2">' . img_down () . '</a><br>' ;
print '<div id="example2" class="hidden">' ;
2015-06-08 17:13:23 +02:00
print 'http://lists.example.com/cgi-bin/mailman/admin/%LISTE%/members/remove?unsubscribees_upload=%EMAIL%&adminpw=%MAILMAN_ADMINPW%&send_unsub_ack_to_this_batch=0&send_unsub_notifications_to_list_owner=0' ;
2012-01-11 18:43:38 +01:00
print '</div>' ;
2015-06-08 17:13:23 +02:00
//print 'http://lists.example.com/cgi-bin/mailman/admin/%LISTE%/members/remove?adminpw=%MAILMAN_ADMINPW%&unsubscribees=%EMAIL%';
2012-01-11 18:43:38 +01:00
}
2013-06-05 15:44:42 +02:00
if ( $const == 'ADHERENT_MAILMAN_LISTS' )
{
2013-06-05 16:24:32 +02:00
print '. ' . $langs -> trans ( " Example " ) . ': <a href="#" id="exampleclick3">' . img_down () . '</a><br>' ;
2013-06-05 15:44:42 +02:00
print '<div id="example3" class="hidden">' ;
2013-06-05 16:24:32 +02:00
print 'mymailmanlist<br>' ;
2013-06-05 15:44:42 +02:00
print 'mymailmanlist1,mymailmanlist2<br>' ;
2013-06-05 15:53:27 +02:00
print 'TYPE:Type1:mymailmanlist1,TYPE:Type2:mymailmanlist2<br>' ;
2013-06-06 18:31:33 +02:00
if ( $conf -> categorie -> enabled ) print 'CATEG:Categ1:mymailmanlist1,CATEG:Categ2:mymailmanlist2<br>' ;
print '</div>' ;
2015-06-08 17:13:23 +02:00
//print 'http://lists.example.com/cgi-bin/mailman/admin/%LISTE%/members/remove?adminpw=%MAILMAN_ADMINPW%&unsubscribees=%EMAIL%';
2013-06-05 15:44:42 +02:00
}
2012-01-11 18:43:38 +01:00
print " </td> \n " ;
2013-05-09 22:39:31 +02:00
// Value
2012-01-11 18:43:38 +01:00
if ( $const == 'ADHERENT_CARD_TYPE' || $const == 'ADHERENT_ETIQUETTE_TYPE' )
{
print '<td>' ;
// List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/format_cards.lib.php' ;
2012-01-11 18:43:38 +01:00
$arrayoflabels = array ();
foreach ( array_keys ( $_Avery_Labels ) as $codecards )
{
$arrayoflabels [ $codecards ] = $_Avery_Labels [ $codecards ][ 'name' ];
}
2019-01-27 11:55:16 +01:00
print $form -> selectarray ( 'constvalue' . ( empty ( $strictw3c ) ? '' : '[]' ), $arrayoflabels , ( $obj -> value ? $obj -> value : 'CARD' ), 1 , 0 , 0 );
2012-01-11 18:43:38 +01:00
print '<input type="hidden" name="consttype" value="yesno">' ;
2018-03-23 16:09:46 +01:00
print '<input type="hidden" name="constnote' . ( empty ( $strictw3c ) ? '' : '[]' ) . '" value="' . nl2br ( dol_escape_htmltag ( $obj -> note )) . '">' ;
2012-01-11 18:43:38 +01:00
print '</td>' ;
}
else
{
print '<td>' ;
2018-03-23 16:09:46 +01:00
print '<input type="hidden" name="consttype' . ( empty ( $strictw3c ) ? '' : '[]' ) . '" value="' . ( $obj -> type ? $obj -> type : 'string' ) . '">' ;
print '<input type="hidden" name="constnote' . ( empty ( $strictw3c ) ? '' : '[]' ) . '" value="' . nl2br ( dol_escape_htmltag ( $obj -> note )) . '">' ;
2019-01-27 11:55:16 +01:00
if ( $obj -> type == 'textarea' || in_array ( $const , array ( 'ADHERENT_CARD_TEXT' , 'ADHERENT_CARD_TEXT_RIGHT' , 'ADHERENT_ETIQUETTE_TEXT' )))
2012-01-11 18:43:38 +01:00
{
2013-05-09 22:39:31 +02:00
print '<textarea class="flat" name="constvalue' . ( empty ( $strictw3c ) ? '' : '[]' ) . '" cols="50" rows="5" wrap="soft">' . " \n " ;
2012-01-11 18:43:38 +01:00
print $obj -> value ;
print " </textarea> \n " ;
}
2018-03-23 16:09:46 +01:00
elseif ( $obj -> type == 'html' )
2012-01-11 18:43:38 +01:00
{
2018-03-23 16:09:46 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2019-01-27 11:55:16 +01:00
$doleditor = new DolEditor ( 'constvalue_' . $const . ( empty ( $strictw3c ) ? '' : '[]' ), $obj -> value , '' , 160 , 'dolibarr_notes' , '' , false , false , $conf -> fckeditor -> enabled , ROWS_5 , '90%' );
2018-03-23 16:09:46 +01:00
$doleditor -> Create ();
2012-01-11 18:43:38 +01:00
}
2018-03-23 16:09:46 +01:00
elseif ( $obj -> type == 'yesno' )
2012-01-11 18:43:38 +01:00
{
2019-01-27 11:55:16 +01:00
print $form -> selectyesno ( 'constvalue' . ( empty ( $strictw3c ) ? '' : '[]' ), $obj -> value , 1 );
2012-01-11 18:43:38 +01:00
}
2018-03-23 16:09:46 +01:00
elseif ( preg_match ( '/emailtemplate/' , $obj -> type ))
{
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' ;
$formmail = new FormMail ( $db );
$tmp = explode ( ':' , $obj -> type );
$nboftemplates = $formmail -> fetchAllEMailTemplate ( $tmp [ 1 ], $user , null , - 1 ); // We set lang=null to get in priority record with no lang
//$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, '');
$arrayofmessagename = array ();
if ( is_array ( $formmail -> lines_model ))
{
foreach ( $formmail -> lines_model as $modelmail )
{
//var_dump($modelmail);
$moreonlabel = '' ;
if ( ! empty ( $arrayofmessagename [ $modelmail -> label ])) $moreonlabel = ' <span class="opacitymedium">(' . $langs -> trans ( " SeveralLangugeVariatFound " ) . ')</span>' ;
2019-01-27 11:55:16 +01:00
$arrayofmessagename [ $modelmail -> label ] = $langs -> trans ( preg_replace ( '/\(|\)/' , '' , $modelmail -> label )) . $moreonlabel ;
2018-03-23 16:09:46 +01:00
}
}
//var_dump($arraydefaultmessage);
//var_dump($arrayofmessagename);
print $form -> selectarray ( 'constvalue_' . $obj -> name , $arrayofmessagename , $obj -> value , 'None' , 1 , 0 , '' , 0 , 0 , 0 , '' , '' , 1 );
}
else // type = 'string' ou 'chaine'
2012-01-11 18:43:38 +01:00
{
2013-05-09 22:39:31 +02:00
print '<input type="text" class="flat" size="48" name="constvalue' . ( empty ( $strictw3c ) ? '' : '[]' ) . '" value="' . dol_escape_htmltag ( $obj -> value ) . '">' ;
2012-01-11 18:43:38 +01:00
}
print '</td>' ;
}
2013-05-09 22:39:31 +02:00
// Submit
if ( empty ( $strictw3c ))
{
print '<td align="center">' ;
print '<input type="submit" class="button" value="' . $langs -> trans ( " Update " ) . '" name="Button">' ;
print " </td> " ;
2013-06-05 15:44:42 +02:00
}
2013-05-09 22:39:31 +02:00
print " </tr> \n " ;
2019-01-31 20:53:59 +01:00
2013-05-09 22:39:31 +02:00
if ( empty ( $strictw3c )) print " </form> \n " ;
2012-01-11 18:43:38 +01:00
}
}
print '</table>' ;
2013-05-09 22:39:31 +02:00
2015-10-23 14:40:45 +02:00
if ( ! empty ( $strictw3c ) && $strictw3c == 1 )
2013-05-09 22:39:31 +02:00
{
print '<div align="center"><input type="submit" class="button" value="' . $langs -> trans ( " Update " ) . '" name="update"></div>' ;
print " </form> \n " ;
}
2012-01-11 18:43:38 +01:00
}
2013-01-02 18:43:59 +01:00
2013-01-05 19:23:16 +01:00
/**
* Show array with constants to edit
*
* @ param array $modules Array of all modules
* @ return string HTML string with warning
*/
function showModulesExludedForExternal ( $modules )
{
2013-01-02 18:43:59 +01:00
global $conf , $langs ;
2013-01-05 19:23:16 +01:00
$text = $langs -> trans ( " OnlyFollowingModulesAreOpenedToExternalUsers " );
2019-01-27 11:55:16 +01:00
$listofmodules = explode ( ',' , $conf -> global -> MAIN_MODULES_FOR_EXTERNAL );
2013-01-05 19:23:16 +01:00
$i = 0 ;
2013-03-05 19:05:12 +01:00
if ( ! empty ( $modules )) {
foreach ( $modules as $module )
{
$moduleconst = $module -> const_name ;
$modulename = strtolower ( $module -> name );
//print 'modulename='.$modulename;
2013-03-13 11:06:28 +01:00
2013-03-05 19:05:12 +01:00
//if (empty($conf->global->$moduleconst)) continue;
2019-01-27 11:55:16 +01:00
if ( ! in_array ( $modulename , $listofmodules )) continue ;
2018-02-26 15:03:09 +01:00
//var_dump($modulename.' - '.$langs->trans('Module'.$module->numero.'Name'));
2017-06-17 11:43:00 +02:00
2013-03-05 19:05:12 +01:00
if ( $i > 0 ) $text .= ', ' ;
else $text .= ' ' ;
$i ++ ;
$text .= $langs -> trans ( 'Module' . $module -> numero . 'Name' );
}
2013-01-05 19:23:16 +01:00
}
2014-11-28 19:49:42 +01:00
return $text ;
2013-01-02 18:43:59 +01:00
}
2012-07-02 19:30:37 +02:00
/**
* Add document model used by doc generator
*
2012-04-03 11:01:07 +02:00
* @ param string $name Model name
2012-07-02 19:30:37 +02:00
* @ param string $type Model type
* @ param string $label Model label
* @ param string $description Model description
* @ return int < 0 if KO , > 0 if OK
*/
2019-01-27 15:20:16 +01:00
function addDocumentModel ( $name , $type , $label = '' , $description = '' )
2012-04-03 11:01:07 +02:00
{
global $db , $conf ;
2012-04-28 14:52:53 +02:00
2012-04-03 11:01:07 +02:00
$db -> begin ();
2012-04-28 14:52:53 +02:00
2012-04-03 11:01:07 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " document_model (nom, type, entity, libelle, description) " ;
$sql .= " VALUES (' " . $db -> escape ( $name ) . " ',' " . $type . " ', " . $conf -> entity . " , " ;
$sql .= ( $label ? " ' " . $db -> escape ( $label ) . " ' " : 'null' ) . " , " ;
$sql .= ( ! empty ( $description ) ? " ' " . $db -> escape ( $description ) . " ' " : " null " );
$sql .= " ) " ;
2017-06-17 11:43:00 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( " admin.lib::addDocumentModel " , LOG_DEBUG );
2012-07-02 19:30:37 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
2012-04-03 11:01:07 +02:00
$db -> commit ();
2012-07-02 19:30:37 +02:00
return 1 ;
}
else
{
2012-04-03 11:01:07 +02:00
dol_print_error ( $db );
2012-07-02 19:30:37 +02:00
$db -> rollback ();
return - 1 ;
}
2012-04-03 11:01:07 +02:00
}
2012-07-02 19:30:37 +02:00
/**
* Delete document model used by doc generator
*
* @ param string $name Model name
* @ param string $type Model type
* @ return int < 0 if KO , > 0 if OK
*/
function delDocumentModel ( $name , $type )
{
2012-04-03 11:01:07 +02:00
global $db , $conf ;
2012-04-28 14:52:53 +02:00
2012-04-03 11:01:07 +02:00
$db -> begin ();
2012-07-02 19:30:37 +02:00
2012-04-03 11:01:07 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " document_model " ;
$sql .= " WHERE nom = ' " . $db -> escape ( $name ) . " ' " ;
$sql .= " AND type = ' " . $type . " ' " ;
2012-07-02 19:30:37 +02:00
$sql .= " AND entity = " . $conf -> entity ;
2014-06-12 11:31:53 +02:00
dol_syslog ( " admin.lib::delDocumentModel " , LOG_DEBUG );
2012-07-02 19:30:37 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
2012-04-03 11:01:07 +02:00
$db -> commit ();
2012-07-02 19:30:37 +02:00
return 1 ;
}
else
{
2012-04-03 11:01:07 +02:00
dol_print_error ( $db );
2012-07-02 19:30:37 +02:00
$db -> rollback ();
return - 1 ;
}
2012-04-03 11:01:07 +02:00
}
2012-09-21 00:13:20 +02:00
2012-09-22 09:18:36 +02:00
/**
* Return the php_info into an array
*
* @ return array Array with PHP infos
*/
function phpinfo_array ()
{
ob_start ();
phpinfo ();
$info_arr = array ();
$info_lines = explode ( " \n " , strip_tags ( ob_get_clean (), " <tr><td><h2> " )); // end of ob_start()
$cat = " General " ;
foreach ( $info_lines as $line )
{
// new cat?
2019-04-23 10:24:16 +02:00
$title = array ();
2012-09-22 09:18:36 +02:00
preg_match ( " ~<h2>(.*)</h2>~ " , $line , $title ) ? $cat = $title [ 1 ] : null ;
2019-04-23 10:24:16 +02:00
$val = array ();
if ( preg_match ( " ~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~ " , $line , $val ))
2012-09-22 09:18:36 +02:00
{
$info_arr [ trim ( $cat )][ trim ( $val [ 1 ])] = $val [ 2 ];
}
elseif ( preg_match ( " ~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~ " , $line , $val ))
{
$info_arr [ trim ( $cat )][ trim ( $val [ 1 ])] = array ( " local " => $val [ 2 ], " master " => $val [ 3 ]);
}
2012-09-21 00:13:20 +02:00
}
2012-09-22 09:18:36 +02:00
return $info_arr ;
2012-09-21 00:13:20 +02:00
}
2018-03-18 06:09:50 +01:00
/**
* Return array head with list of tabs to view object informations .
*
* @ return array head array with tabs
*/
function company_admin_prepare_head ()
{
2019-04-23 10:24:16 +02:00
global $langs , $conf ;
2018-03-18 06:09:50 +01:00
$h = 0 ;
$head = array ();
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/company.php " ;
$head [ $h ][ 1 ] = $langs -> trans ( " Company " );
$head [ $h ][ 2 ] = 'company' ;
$h ++ ;
2019-10-24 21:29:07 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/openinghours.php " ;
$head [ $h ][ 1 ] = $langs -> trans ( " OpeningHours " );
$head [ $h ][ 2 ] = 'openinghours' ;
$h ++ ;
2019-01-16 12:42:54 +01:00
2018-03-18 06:09:50 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/accountant.php " ;
$head [ $h ][ 1 ] = $langs -> trans ( " Accountant " );
$head [ $h ][ 2 ] = 'accountant' ;
$h ++ ;
2019-01-27 11:55:16 +01:00
complete_head_from_modules ( $conf , $langs , null , $head , $h , 'company_admin' , 'remove' );
2018-03-18 06:09:50 +01:00
return $head ;
}
2017-10-13 12:02:26 +02:00
/**
* Return array head with list of tabs to view object informations .
*
* @ return array head array with tabs
*/
function email_admin_prepare_head ()
{
global $langs , $conf , $user ;
$h = 0 ;
$head = array ();
2018-11-14 13:55:10 +01:00
if ( ! empty ( $user -> admin ) && ( empty ( $_SESSION [ 'leftmenu' ]) || $_SESSION [ 'leftmenu' ] != 'email_templates' ))
2017-10-13 12:02:26 +02:00
{
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/mails.php " ;
$head [ $h ][ 1 ] = $langs -> trans ( " OutGoingEmailSetup " );
$head [ $h ][ 2 ] = 'common' ;
$h ++ ;
if ( $conf -> mailing -> enabled )
{
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/mails_emailing.php " ;
$head [ $h ][ 1 ] = $langs -> trans ( " OutGoingEmailSetupForEmailing " );
$head [ $h ][ 2 ] = 'common_emailing' ;
$h ++ ;
}
}
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/mails_templates.php " ;
2018-09-12 21:25:14 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( " EMailTemplates " );
2017-10-13 12:02:26 +02:00
$head [ $h ][ 2 ] = 'templates' ;
$h ++ ;
2019-11-14 11:53:28 +01:00
if ( $conf -> global -> MAIN_FEATURES_LEVEL >= 1 && ! empty ( $user -> admin ) && ( empty ( $_SESSION [ 'leftmenu' ]) || $_SESSION [ 'leftmenu' ] != 'email_templates' ))
2017-10-13 12:02:26 +02:00
{
$head [ $h ][ 0 ] = DOL_URL_ROOT . " /admin/mails_senderprofile_list.php " ;
$head [ $h ][ 1 ] = $langs -> trans ( " EmailSenderProfiles " );
$head [ $h ][ 2 ] = 'senderprofiles' ;
$h ++ ;
}
2019-01-27 11:55:16 +01:00
complete_head_from_modules ( $conf , $langs , null , $head , $h , 'email_admin' , 'remove' );
2017-10-13 12:02:26 +02:00
return $head ;
}