27 require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
38 if (isset($versionarray[0])) $string=$versionarray[0];
39 if (isset($versionarray[1])) $string.=
'.'.$versionarray[1];
40 if (isset($versionarray[2])) $string.=
'.'.$versionarray[2];
62 $count1=count($versionarray1);
63 $count2=count($versionarray2);
64 $maxcount=max($count1,$count2);
65 while ($level < $maxcount)
67 $operande1=isset($versionarray1[$level])?$versionarray1[$level]:0;
68 $operande2=isset($versionarray2[$level])?$versionarray2[$level]:0;
69 if (preg_match(
'/alpha|dev/i',$operande1)) $operande1=-5;
70 if (preg_match(
'/alpha|dev/i',$operande2)) $operande2=-5;
71 if (preg_match(
'/beta$/i',$operande1)) $operande1=-4;
72 if (preg_match(
'/beta$/i',$operande2)) $operande2=-4;
73 if (preg_match(
'/beta([0-9])+/i',$operande1)) $operande1=-3;
74 if (preg_match(
'/beta([0-9])+/i',$operande2)) $operande2=-3;
75 if (preg_match(
'/rc$/i',$operande1)) $operande1=-2;
76 if (preg_match(
'/rc$/i',$operande2)) $operande2=-2;
77 if (preg_match(
'/rc([0-9])+/i',$operande1)) $operande1=-1;
78 if (preg_match(
'/rc([0-9])+/i',$operande2)) $operande2=-1;
81 if ($operande1 < $operande2) { $ret = -$level;
break; }
82 if ($operande1 > $operande2) { $ret = $level;
break; }
96 return explode(
'.',PHP_VERSION);
106 return explode(
'.',DOL_VERSION);
130 function run_sql($sqlfile, $silent=1, $entity=
'', $usesavepoint=1, $handler=
'', $okerror=
'default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0)
132 global $db, $conf, $langs, $user;
134 dol_syslog(
"Admin.lib::run_sql run sql file ".$sqlfile.
" silent=".$silent.
" entity=".$entity.
" usesavepoint=".$usesavepoint.
" handler=".$handler.
" okerror=".$okerror, LOG_DEBUG);
136 if (! is_numeric($linelengthlimit))
138 dol_syslog(
"Admin.lib::run_sql param linelengthlimit is not a numeric", LOG_ERR);
149 $versionarray=$db->getVersionArray();
151 $fp = fopen($sqlfile,
"r");
157 if ($linelengthlimit > 0) $buf = fgets($fp, $linelengthlimit);
158 else $buf = fgets($fp);
161 if (preg_match(
'/^--\sV(MYSQL|PGSQL)([^\s]*)/i',$buf,$reg))
166 if (! empty($reg[1]))
168 if (! preg_match(
'/'.preg_quote($reg[1]).
'/i',$db->type)) $qualified=0;
174 if (! empty($reg[2]))
176 if (is_numeric($reg[2]))
178 $versionrequest=explode(
'.',$reg[2]);
181 if (! count($versionrequest) || ! count($versionarray) ||
versioncompare($versionrequest,$versionarray) > 0)
188 $dbcollation = strtoupper(preg_replace(
'/_/',
'', $conf->db->dolibarr_main_db_collation));
191 if (empty($conf->db->dolibarr_main_db_collation) || ($reg[2] != $dbcollation)) $qualified=0;
200 $buf=preg_replace(
'/^--\sV(MYSQL|PGSQL)([^\s]*)/i',
'',$buf);
206 if ($nocommentremoval || ! preg_match(
'/^\s*--/',$buf))
208 if (empty($nocommentremoval)) $buf=preg_replace(
'/([,;ERLT\)])\s*--.*$/i',
'\1',$buf);
209 $buffer .= trim($buf);
214 if (preg_match(
'/;/',$buffer))
217 if ($buffer) $arraysql[$i]=$buffer;
223 if ($buffer) $arraysql[$i]=$buffer;
228 dol_syslog(
"Admin.lib::run_sql failed to open file ".$sqlfile, LOG_ERR);
232 $listofmaxrowid=array();
233 foreach($arraysql as $i => $sql)
238 while (preg_match(
'/__\+MAX_([A-Za-z_]+)__/i',$newsql,$reg))
241 if (! isset($listofmaxrowid[$table]))
244 $sqlgetrowid=
'SELECT MAX(rowid) as max from '.preg_replace(
'/^llx_/', MAIN_DB_PREFIX, $table);
245 $resql=$db->query($sqlgetrowid);
248 $obj=$db->fetch_object(
$resql);
249 $listofmaxrowid[$table]=$obj->max;
250 if (empty($listofmaxrowid[$table])) $listofmaxrowid[$table]=0;
254 if (! $silent)
print '<tr><td valign="top" colspan="2">';
255 if (! $silent)
print '<div class="error">'.$langs->trans(
"Failed to get max rowid for ".$table).
"</div></td>";
256 if (! $silent)
print '</tr>';
262 $from=
'__+MAX_'.$table.
'__';
263 $to=
'+'.$listofmaxrowid[$table];
264 $newsql=str_replace($from, $to, $newsql);
265 dol_syslog(
'Admin.lib::run_sql New Request '.($i+1).
' (replacing '.$from.
' to '.$to.
')', LOG_DEBUG);
267 $arraysql[$i]=$newsql;
270 if ($offsetforchartofaccount > 0)
276 $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);
277 $newsql = preg_replace(
'/([,\s])0 \+ '.$offsetforchartofaccount.
'/ims',
'\1 0', $newsql);
279 $arraysql[$i] = $newsql;
285 $listofinsertedrowid=array();
286 foreach($arraysql as $i => $sql)
291 if (MAIN_DB_PREFIX !=
'llx_')
293 $sql=preg_replace(
'/llx_/i',MAIN_DB_PREFIX,$sql);
296 if (!empty($handler)) $sql=preg_replace(
'/__HANDLER__/i',
"'".$handler.
"'",$sql);
298 $newsql=preg_replace(
'/__ENTITY__/i',(!empty($entity)?$entity:$conf->entity),$sql);
301 if (! $silent)
print '<tr><td class="tdtop">'.$langs->trans(
"Request").
' '.($i+1).
" sql='".
dol_htmlentities($newsql,ENT_NOQUOTES).
"'</td></tr>\n";
302 dol_syslog(
'Admin.lib::run_sql Request '.($i+1), LOG_DEBUG);
306 if (preg_match_all(
'/__ENCRYPT\(\'([^\']+)\'\)__/i',$newsql,$reg))
310 for($j=0;$j<$num;$j++)
313 $to = $db->encrypt($reg[1][$j],1);
314 $newsql = str_replace($from,$to,$newsql);
320 if (preg_match_all(
'/__DECRYPT\(\'([A-Za-z0-9_]+)\'\)__/i',$newsql,$reg))
324 for($j=0;$j<$num;$j++)
327 $to = $db->decrypt($reg[1][$j]);
328 $newsql = str_replace($from,$to,$newsql);
334 while (preg_match(
'/__([0-9]+)__/',$newsql,$reg))
337 if (empty($listofinsertedrowid[$cursor]))
339 if (! $silent)
print '<tr><td valign="top" colspan="2">';
340 if (! $silent)
print '<div class="error">'.$langs->trans(
"FileIsNotCorrect").
"</div></td>";
341 if (! $silent)
print '</tr>';
345 $from=
'__'.$cursor.
'__';
346 $to=$listofinsertedrowid[$cursor];
347 $newsql=str_replace($from,$to,$newsql);
351 if ($sqlmodified)
dol_syslog(
'Admin.lib::run_sql New Request '.($i+1), LOG_DEBUG);
353 $result=$db->query($newsql,$usesavepoint);
356 if (! $silent)
print '<!-- Result = OK -->'.
"\n";
358 if (preg_replace(
'/insert into ([^\s]+)/i',$newsql,$reg))
363 $table=preg_replace(
'/([^a-zA-Z_]+)/i',
'',$reg[1]);
364 $insertedrowid=$db->last_insert_id($table);
365 $listofinsertedrowid[$cursorinsert]=$insertedrowid;
366 dol_syslog(
'Admin.lib::run_sql Insert nb '.$cursorinsert.
', done in table '.$table.
', rowid is '.$listofinsertedrowid[$cursorinsert], LOG_DEBUG);
373 if (! $silent)
print '<!-- Result = '.$errno.
' -->'.
"\n";
377 'DB_ERROR_TABLE_ALREADY_EXISTS',
378 'DB_ERROR_COLUMN_ALREADY_EXISTS',
379 'DB_ERROR_KEY_NAME_ALREADY_EXISTS',
380 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS',
381 'DB_ERROR_RECORD_ALREADY_EXISTS',
382 'DB_ERROR_NOSUCHTABLE',
383 'DB_ERROR_NOSUCHFIELD',
384 'DB_ERROR_NO_FOREIGN_KEY_TO_DROP',
385 'DB_ERROR_NO_INDEX_TO_DROP',
386 'DB_ERROR_CANNOT_CREATE',
387 'DB_ERROR_CANT_DROP_PRIMARY_KEY',
388 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS',
391 if ($okerror ==
'none') $okerrors=array();
394 if (! in_array($errno,$okerrors))
396 if (! $silent)
print '<tr><td valign="top" colspan="2">';
397 if (! $silent)
print '<div class="error">'.$langs->trans(
"Error").
" ".$db->errno().
": ".$newsql.
"<br>".$db->error().
"</div></td>";
398 if (! $silent)
print '</tr>'.
"\n";
399 dol_syslog(
'Admin.lib::run_sql Request '.($i+1).
" Error ".$db->errno().
" ".$newsql.
"<br>".$db->error(), LOG_ERR);
404 if (! $silent)
print '</tr>'.
"\n";
410 if (! $silent)
print '<tr><td>'.$langs->trans(
"ProcessMigrateScript").
'</td>';
411 if (! $silent)
print '<td align="right">'.$langs->trans(
"OK").
'</td></tr>'.
"\n";
416 if (! $silent)
print '<tr><td>'.$langs->trans(
"ProcessMigrateScript").
'</td>';
417 if (! $silent)
print '<td align="right"><font class="error">'.$langs->trans(
"KO").
'</font></td></tr>'.
"\n";
441 dol_print_error(
'',
'Error call dolibar_del_const with parameter name empty');
445 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
446 $sql.=
" WHERE (".$db->decrypt(
'name').
" = '".$db->escape($name).
"'";
447 if (is_numeric($name)) $sql.=
" OR rowid = '".$db->escape($name).
"'";
449 if ($entity >= 0) $sql.=
" AND entity = ".$entity;
451 dol_syslog(
"admin.lib::dolibarr_del_const", LOG_DEBUG);
455 $conf->global->$name=
'';
480 $sql =
"SELECT ".$db->decrypt(
'value').
" as value";
481 $sql.=
" FROM ".MAIN_DB_PREFIX.
"const";
482 $sql.=
" WHERE name = ".$db->encrypt($name,1);
483 $sql.=
" AND entity = ".$entity;
485 dol_syslog(
"admin.lib::dolibarr_get_const", LOG_DEBUG);
489 $obj=$db->fetch_object(
$resql);
490 if ($obj) $value=$obj->value;
520 dol_print_error($db,
"Error: Call to function dolibarr_set_const with wrong parameters", LOG_ERR);
528 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
529 $sql.=
" WHERE name = ".$db->encrypt($name,1);
530 if ($entity >= 0) $sql.=
" AND entity = ".$entity;
532 dol_syslog(
"admin.lib::dolibarr_set_const", LOG_DEBUG);
535 if (strcmp($value,
''))
537 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const(name,value,type,visible,note,entity)";
539 $sql.= $db->encrypt($name,1);
540 $sql.=
", ".$db->encrypt($value,1);
541 $sql.=
",'".$db->escape($type).
"',".$visible.
",'".$db->escape($note).
"',".$entity.
")";
545 dol_syslog(
"admin.lib::dolibarr_set_const", LOG_DEBUG);
552 $conf->global->$name=$value;
557 $error=$db->lasterror();
573 global $langs, $conf, $user;
577 $head[$h][0] = DOL_URL_ROOT.
"/admin/modules.php?mode=common";
578 $head[$h][1] = $langs->trans(
"AvailableModules");
579 $head[$h][2] =
'common';
582 $head[$h][0] = DOL_URL_ROOT.
"/admin/modules.php?mode=marketplace";
583 $head[$h][1] = $langs->trans(
"ModulesMarketPlaces");
584 $head[$h][2] =
'marketplace';
587 $head[$h][0] = DOL_URL_ROOT.
"/admin/modules.php?mode=deploy";
588 $head[$h][1] = $langs->trans(
"AddExtensionThemeModuleOrOther");
589 $head[$h][2] =
'deploy';
592 $head[$h][0] = DOL_URL_ROOT.
"/admin/modules.php?mode=develop";
593 $head[$h][1] = $langs->trans(
"ModulesDevelopYourModule");
594 $head[$h][2] =
'develop';
608 global $db, $langs, $conf, $user;
612 $head[$h][0] = DOL_URL_ROOT.
"/admin/security_other.php";
613 $head[$h][1] = $langs->trans(
"Miscellaneous");
614 $head[$h][2] =
'misc';
617 $head[$h][0] = DOL_URL_ROOT.
"/admin/security.php";
618 $head[$h][1] = $langs->trans(
"Passwords");
619 $head[$h][2] =
'passwords';
622 $head[$h][0] = DOL_URL_ROOT.
"/admin/security_file.php";
623 $head[$h][1] = $langs->trans(
"Files").
' ('.$langs->trans(
"Upload").
')';
624 $head[$h][2] =
'file';
634 $head[$h][0] = DOL_URL_ROOT.
"/admin/proxy.php";
635 $head[$h][1] = $langs->trans(
"ExternalAccess");
636 $head[$h][2] =
'proxy';
639 $head[$h][0] = DOL_URL_ROOT.
"/admin/events.php";
640 $head[$h][1] = $langs->trans(
"Audit");
641 $head[$h][2] =
'audit';
647 $sql =
"SELECT COUNT(r.id) as nb";
648 $sql.=
" FROM ".MAIN_DB_PREFIX.
"rights_def as r";
649 $sql.=
" WHERE r.libelle NOT LIKE 'tou%'";
650 $sql.=
" AND entity = ".$conf->entity;
651 $sql.=
" AND bydefault = 1";
652 if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) $sql.=
" AND r.perms NOT LIKE '%_advance'";
653 $resql = $db->query($sql);
656 $obj = $db->fetch_object(
$resql);
657 if ($obj) $nbPerms = $obj->nb;
661 $head[$h][0] = DOL_URL_ROOT.
"/admin/perms.php";
662 $head[$h][1] = $langs->trans(
"DefaultRights");
663 if ($nbPerms > 0) $head[$h][1].=
' <span class="badge">'.$nbPerms.
'</span>';
664 $head[$h][2] =
'default';
678 global $langs, $conf, $user;
682 $head[$h][0] = DOL_URL_ROOT.
"/admin/translation.php?mode=overwrite";
683 $head[$h][1] = $langs->trans(
"TranslationOverwriteKey");
684 $head[$h][2] =
'overwrite';
687 $head[$h][0] = DOL_URL_ROOT.
"/admin/translation.php?mode=searchkey";
688 $head[$h][1] = $langs->trans(
"TranslationKeySearch");
689 $head[$h][2] =
'searchkey';
708 global $langs, $conf, $user;
712 $head[$h][0] = DOL_URL_ROOT.
"/admin/defaultvalues.php?mode=createform";
713 $head[$h][1] = $langs->trans(
"DefaultCreateForm");
714 $head[$h][2] =
'createform';
717 $head[$h][0] = DOL_URL_ROOT.
"/admin/defaultvalues.php?mode=filters";
718 $head[$h][1] = $langs->trans(
"DefaultSearchFilters");
719 $head[$h][2] =
'filters';
722 $head[$h][0] = DOL_URL_ROOT.
"/admin/defaultvalues.php?mode=sortorder";
723 $head[$h][1] = $langs->trans(
"DefaultSortOrder");
724 $head[$h][2] =
'sortorder';
727 if (! empty($conf->use_javascript_ajax))
729 $head[$h][0] = DOL_URL_ROOT.
"/admin/defaultvalues.php?mode=focus";
730 $head[$h][1] = $langs->trans(
"DefaultFocus");
731 $head[$h][2] =
'focus';
734 $head[$h][0] = DOL_URL_ROOT.
"/admin/defaultvalues.php?mode=mandatory";
735 $head[$h][1] = $langs->trans(
"DefaultMandatory");
736 $head[$h][2] =
'mandatory';
763 $arrayofSessions = array();
766 $iniPath = ini_get(
"session.save_path");
768 $sessPath = $iniPath;
771 dol_syslog(
'admin.lib:listOfSessions sessPath='.$sessPath);
776 while(($file = @readdir($dh)) !==
false)
778 if (preg_match(
'/^sess_/i',$file) && $file !=
"." && $file !=
"..")
780 $fullpath = $sessPath.$file;
781 if(! @is_dir($fullpath) && is_readable($fullpath))
783 $sessValues = file_get_contents($fullpath);
789 if (preg_match(
'/dol_login/i',$sessValues) &&
790 (preg_match(
'/dol_entity\|i:'.$conf->entity.
';/i',$sessValues) || preg_match(
'/dol_entity\|s:([0-9]+):"'.$conf->entity.
'"/i',$sessValues)) &&
791 preg_match(
'/dol_company\|s:([0-9]+):"('.$conf->global->MAIN_INFO_SOCIETE_NOM.
')"/i',$sessValues))
793 $tmp=explode(
'_', $file);
795 $login = preg_match(
'/dol_login\|s:[0-9]+:"([A-Za-z0-9]+)"/i',$sessValues,$regs);
796 $arrayofSessions[$idsess][
"login"] = $regs[1];
797 $arrayofSessions[$idsess][
"age"] = time()-filectime($fullpath);
798 $arrayofSessions[$idsess][
"creation"] = filectime($fullpath);
799 $arrayofSessions[$idsess][
"modification"] = filemtime($fullpath);
800 $arrayofSessions[$idsess][
"raw"] = $sessValues;
808 return $arrayofSessions;
821 $arrayofSessions = array();
822 $sessPath = ini_get(
"session.save_path").
"/";
823 dol_syslog(
'admin.lib:purgeSessions mysessionid='.$mysessionid.
' sessPath='.$sessPath);
827 while(($file = @readdir($dh)) !==
false)
829 if ($file !=
"." && $file !=
"..")
831 $fullpath = $sessPath.$file;
832 if(! @is_dir($fullpath))
834 $sessValues = file_get_contents($fullpath);
836 if (preg_match(
'/dol_login/i',$sessValues) &&
837 preg_match(
'/dol_entity\|s:([0-9]+):"('.$conf->entity.
')"/i',$sessValues) &&
838 preg_match(
'/dol_company\|s:([0-9]+):"('.$conf->global->MAIN_INFO_SOCIETE_NOM.
')"/i',$sessValues))
840 $tmp=explode(
'_', $file);
843 if ($idsess != $mysessionid)
845 $res=@unlink($fullpath);
846 if (! $res) $error++;
854 if (! $error)
return 1;
869 global $db, $modules, $langs, $conf, $mysoc;
873 $ret[
'errors'][] =
'ErrorBadParameter';
877 $ret=array(
'nbmodules'=>0,
'errors'=>array(),
'nbperms'=>0);
879 $modFile = $modName .
".class.php";
886 foreach ($modulesdir as $dir)
888 if (file_exists($dir.$modFile))
890 $found=@include_once $dir.$modFile;
895 $objMod =
new $modName($db);
899 $vermin=isset($objMod->phpmin)?$objMod->phpmin:0;
901 $ret[
'errors'][] = $langs->trans(
"ErrorModuleRequirePHPVersion",
versiontostring($vermin));
907 $vermin=isset($objMod->need_dolibarr_version)?$objMod->need_dolibarr_version:0;
910 $ret[
'errors'][] = $langs->trans(
"ErrorModuleRequireDolibarrVersion",
versiontostring($vermin));
915 if (!empty($objMod->need_javascript_ajax) && empty($conf->use_javascript_ajax)) {
916 $ret[
'errors'][] = $langs->trans(
"ErrorModuleRequireJavascript");
920 $const_name = $objMod->const_name;
921 if(!empty($conf->global->$const_name)){
925 $result=$objMod->init();
929 $ret[
'errors'][]=$objMod->error;
935 if (isset($objMod->depends) && is_array($objMod->depends) && ! empty($objMod->depends))
939 foreach ($objMod->depends as $key => $modulestring)
942 if ((! is_numeric($key)) && ! preg_match(
'/^always/', $key) && $mysoc->country_code && ! preg_match(
'/^'.$mysoc->country_code.
'/', $key))
944 dol_syslog(
"We are not concerned by dependency with key=".$key.
" because our country is ".$mysoc->country_code);
948 foreach ($modulesdir as $dir)
950 if (file_exists($dir.$modulestring.
".class.php"))
953 if (empty($resarray[
'errors'])){
956 foreach ($resarray[
'errors'] as $errorMessage){
966 $ret[
'nbmodules']+=$resarray[
'nbmodules'];
967 $ret[
'nbperms']+=$resarray[
'nbperms'];
971 $ret[
'errors'][] = $langs->trans(
'activateModuleDependNotSatisfied', $objMod->name, $modulestring);
976 if (isset($objMod->conflictwith) && is_array($objMod->conflictwith) && ! empty($objMod->conflictwith))
979 $num = count($objMod->conflictwith);
980 for ($i = 0; $i < $num; $i++)
982 foreach ($modulesdir as $dir)
984 if (file_exists($dir.$objMod->conflictwith[$i].
".class.php"))
994 if (! count($ret[
'errors']))
997 $ret[
'nbperms']+=count($objMod->rights);
1013 global $db, $modules, $conf;
1016 if (empty($value))
return 'ErrorBadParameter';
1020 $modFile = $modName .
".class.php";
1027 foreach ($modulesdir as $dir)
1029 if (file_exists($dir.$modFile))
1031 $found=@include_once $dir.$modFile;
1038 $objMod =
new $modName($db);
1039 $result=$objMod->remove();
1040 if ($result <= 0) $ret=$objMod->error;
1046 include_once DOL_DOCUMENT_ROOT.
'/core/modules/DolibarrModules.class.php';
1048 $genericMod->name=preg_replace(
'/^mod/i',
'',$modName);
1049 $genericMod->rights_class=strtolower(preg_replace(
'/^mod/i',
'',$modName));
1050 $genericMod->const_name=
'MAIN_MODULE_'.strtoupper(preg_replace(
'/^mod/i',
'',$modName));
1051 dol_syslog(
"modules::unActivateModule Failed to find module file, we use generic function with name " . $modName);
1052 $genericMod->_remove(array());
1056 if (! $ret && $requiredby)
1058 $countrb=count($objMod->requiredby);
1059 for ($i = 0; $i < $countrb; $i++)
1088 function complete_dictionary_with_modules(&$taborder,&$tabname,&$tablib,&$tabsql,&$tabsqlsort,&$tabfield,&$tabfieldvalue,&$tabfieldinsert,&$tabrowid,&$tabcond,&$tabhelp,&$tabfieldcheck)
1090 global $db, $modules, $conf, $langs;
1097 foreach ($modulesdir as $dir)
1101 dol_syslog(
"Scan directory ".$dir.
" for modules");
1103 if (is_resource($handle))
1105 while (($file = readdir($handle))!==
false)
1108 if (is_readable($dir.$file) && substr($file, 0, 3) ==
'mod' && substr($file,
dol_strlen($file) - 10) ==
'.class.php')
1110 $modName = substr($file, 0,
dol_strlen($file) - 10);
1114 include_once $dir.$file;
1115 $objMod =
new $modName($db);
1117 if ($objMod->numero > 0)
1119 $j = $objMod->numero;
1129 $const_name =
'MAIN_MODULE_'.strtoupper(preg_replace(
'/^mod/i',
'',get_class($objMod)));
1130 if ($objMod->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2 && ! $conf->global->$const_name) $modulequalified=0;
1131 if ($objMod->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1 && ! $conf->global->$const_name) $modulequalified=0;
1133 if (empty($conf->global->$const_name)) $modulequalified=0;
1135 if ($modulequalified)
1138 if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
1139 foreach ($objMod->langfiles as $langfile) {
1140 $langs->load($langfile);
1145 if (empty($objMod->dictionaries) && ! empty($objMod->dictionnaries)) $objMod->dictionaries=$objMod->dictionnaries;
1147 if (! empty($objMod->dictionaries))
1150 $nbtabname=$nbtablib=$nbtabsql=$nbtabsqlsort=$nbtabfield=$nbtabfieldvalue=$nbtabfieldinsert=$nbtabrowid=$nbtabcond=$nbtabfieldcheck=$nbtabhelp=0;
1151 foreach($objMod->dictionaries[
'tabname'] as $val) { $nbtabname++; $taborder[] = max($taborder)+1; $tabname[] = $val; }
1152 foreach($objMod->dictionaries[
'tablib'] as $val) { $nbtablib++; $tablib[] = $val; }
1153 foreach($objMod->dictionaries[
'tabsql'] as $val) { $nbtabsql++; $tabsql[] = $val; }
1154 foreach($objMod->dictionaries[
'tabsqlsort'] as $val) { $nbtabsqlsort++; $tabsqlsort[] = $val; }
1155 foreach($objMod->dictionaries[
'tabfield'] as $val) { $nbtabfield++; $tabfield[] = $val; }
1156 foreach($objMod->dictionaries[
'tabfieldvalue'] as $val) { $nbtabfieldvalue++; $tabfieldvalue[] = $val; }
1157 foreach($objMod->dictionaries[
'tabfieldinsert'] as $val) { $nbtabfieldinsert++; $tabfieldinsert[] = $val; }
1158 foreach($objMod->dictionaries[
'tabrowid'] as $val) { $nbtabrowid++; $tabrowid[] = $val; }
1159 foreach($objMod->dictionaries[
'tabcond'] as $val) { $nbtabcond++; $tabcond[] = $val; }
1160 if (! empty($objMod->dictionaries[
'tabhelp']))
foreach($objMod->dictionaries[
'tabhelp'] as $val) { $nbtabhelp++; $tabhelp[] = $val; }
1161 if (! empty($objMod->dictionaries[
'tabfieldcheck']))
foreach($objMod->dictionaries[
'tabfieldcheck'] as $val) { $nbtabfieldcheck++; $tabfieldcheck[] = $val; }
1163 if ($nbtabname != $nbtablib || $nbtablib != $nbtabsql || $nbtabsql != $nbtabsqlsort)
1165 print 'Error in descriptor of module '.$const_name.
'. Array ->dictionaries has not same number of record for key "tabname", "tablib", "tabsql" and "tabsqlsort"';
1177 else dol_syslog(
"Module ".get_class($objMod).
" not qualified");
1185 dol_syslog(
"htdocs/admin/modules.php: Failed to open directory ".$dir.
". See permission and open_basedir option.", LOG_WARNING);
1200 global $db, $conf, $langs;
1204 foreach ($modulesdir as $dir)
1207 dol_syslog(
"Scan directory ".$dir.
" for modules");
1209 if (is_resource($handle))
1211 while (($file = readdir($handle))!==
false)
1213 if (is_readable($dir.$file) && substr($file, 0, 3) ==
'mod' && substr($file,
dol_strlen($file) - 10) ==
'.class.php')
1215 $modName = substr($file, 0,
dol_strlen($file) - 10);
1219 include_once $dir.$file;
1220 $objMod =
new $modName($db);
1225 $const_name =
'MAIN_MODULE_'.strtoupper(preg_replace(
'/^mod/i',
'',get_class($objMod)));
1227 if ($objMod->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0;
1228 if ($objMod->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0;
1229 if(!empty($conf->global->$const_name)) $modulequalified=0;
1231 if ($modulequalified)
1234 if (isset($objMod->automatic_activation) && is_array($objMod->automatic_activation) && isset($objMod->automatic_activation[$country_code]))
1238 setEventMessages($objMod->automatic_activation[$country_code], null,
'warnings');
1241 else dol_syslog(
"Module ".get_class($objMod).
" not qualified");
1249 dol_syslog(
"htdocs/admin/modules.php: Failed to open directory ".$dir.
". See permission and open_basedir option.", LOG_WARNING);
1264 global $db, $modules, $conf, $langs;
1267 $filename = array();
1278 foreach ($modulesdir as $dir)
1282 dol_syslog(
"Scan directory ".$dir.
" for modules");
1284 if (is_resource($handle))
1286 while (($file = readdir($handle))!==
false)
1289 if (is_readable($dir.$file) && substr($file, 0, 3) ==
'mod' && substr($file,
dol_strlen($file) - 10) ==
'.class.php')
1291 $modName = substr($file, 0,
dol_strlen($file) - 10);
1295 include_once $dir.$file;
1296 $objMod =
new $modName($db);
1298 if ($objMod->numero > 0)
1300 $j = $objMod->numero;
1310 $const_name =
'MAIN_MODULE_'.strtoupper(preg_replace(
'/^mod/i',
'',get_class($objMod)));
1311 if ($objMod->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2 && ! $conf->global->$const_name) $modulequalified=0;
1312 if ($objMod->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1 && ! $conf->global->$const_name) $modulequalified=0;
1314 if (empty($conf->global->$const_name)) $modulequalified=0;
1316 if ($modulequalified)
1319 if (isset($objMod->langfiles) && is_array($objMod->langfiles))
1321 foreach($objMod->langfiles as $langfile)
1323 $langs->load($langfile);
1327 $modules[$i] = $objMod;
1328 $filename[$i]= $modName;
1329 $orders[$i] = $objMod->family.
"_".$j;
1333 if (! empty($objMod->module_parts[
'contactelement']))
1335 $elementList[$objMod->name] = $langs->trans($objMod->name);
1341 else dol_syslog(
"Module ".get_class($objMod).
" not qualified");
1349 dol_syslog(
"htdocs/admin/modules.php: Failed to open directory ".$dir.
". See permission and open_basedir option.", LOG_WARNING);
1367 global $db,$bc,$langs,$conf,$user;
1368 global $_Avery_Labels;
1370 $form =
new Form($db);
1372 if (! empty($strictw3c) && $strictw3c == 1)
print "\n".
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1374 print '<table class="noborder" width="100%">';
1375 print '<tr class="liste_titre">';
1376 print '<td class="titlefield">'.$langs->trans(
"Description").
'</td>';
1378 $text = $langs->trans(
"Value");
1379 print $form->textwithpicto($text, $helptext, 1,
'help',
'', 0, 2,
'idhelptext');
1381 if (empty($strictw3c))
print '<td align="center" width="80">'.$langs->trans(
"Action").
'</td>';
1385 $listofparam=array();
1386 foreach($tableau as $key => $const)
1390 if (is_numeric($key)) {
1395 if (is_array($const))
1397 $type = $const[
'type'];
1398 $label = $const[
'label'];
1410 $sql.=
", ".$db->decrypt(
'name').
" as name";
1411 $sql.=
", ".$db->decrypt(
'value').
" as value";
1414 $sql.=
" FROM ".MAIN_DB_PREFIX.
"const";
1415 $sql.=
" WHERE ".$db->decrypt(
'name').
" = '".$db->escape($const).
"'";
1416 $sql.=
" AND entity IN (0, ".$conf->entity.
")";
1417 $sql.=
" ORDER BY name ASC, entity DESC";
1418 $result = $db->query($sql);
1423 $obj = $db->fetch_object($result);
1427 $obj = (object) array(
'rowid'=>
'',
'name'=>$const,
'value'=>
'',
'type'=>$type,
'note'=>
'');
1430 if (empty($strictw3c))
1432 print "\n".
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1433 print '<input type="hidden" name="token" value="'.$_SESSION[
'newtoken'].
'">';
1436 print '<tr class="oddeven">';
1440 if (empty($strictw3c))
print '<input type="hidden" name="action" value="update">';
1441 print '<input type="hidden" name="rowid'.(empty($strictw3c)?
'':
'[]').
'" value="'.$obj->rowid.
'">';
1442 print '<input type="hidden" name="constname'.(empty($strictw3c)?
'':
'[]').
'" value="'.$const.
'">';
1443 print '<input type="hidden" name="constnote_'.$obj->name.
'" value="'.nl2br(
dol_escape_htmltag($obj->note)).
'">';
1444 print '<input type="hidden" name="consttype_'.$obj->name.
'" value="'.($obj->type?$obj->type:
'string').
'">';
1446 print ($label ? $label : $langs->trans(
'Desc'.$const));
1448 if ($const ==
'ADHERENT_MAILMAN_URL')
1450 print '. '.$langs->trans(
"Example").
': <a href="#" id="exampleclick1">'.
img_down().
'</a><br>';
1452 print '<div id="example1" class="hidden">';
1453 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';
1456 if ($const ==
'ADHERENT_MAILMAN_UNSUB_URL')
1458 print '. '.$langs->trans(
"Example").
': <a href="#" id="exampleclick2">'.
img_down().
'</a><br>';
1459 print '<div id="example2" class="hidden">';
1460 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';
1464 if ($const ==
'ADHERENT_MAILMAN_LISTS')
1466 print '. '.$langs->trans(
"Example").
': <a href="#" id="exampleclick3">'.
img_down().
'</a><br>';
1467 print '<div id="example3" class="hidden">';
1468 print 'mymailmanlist<br>';
1469 print 'mymailmanlist1,mymailmanlist2<br>';
1470 print 'TYPE:Type1:mymailmanlist1,TYPE:Type2:mymailmanlist2<br>';
1471 if ($conf->categorie->enabled)
print 'CATEG:Categ1:mymailmanlist1,CATEG:Categ2:mymailmanlist2<br>';
1479 if ($const ==
'ADHERENT_CARD_TYPE' || $const ==
'ADHERENT_ETIQUETTE_TYPE')
1483 require_once DOL_DOCUMENT_ROOT.
'/core/lib/format_cards.lib.php';
1484 $arrayoflabels=array();
1485 foreach(array_keys($_Avery_Labels) as $codecards)
1487 $arrayoflabels[$codecards]=$_Avery_Labels[$codecards][
'name'];
1489 print $form->selectarray(
'constvalue'.(empty($strictw3c)?
'':
'[]'),$arrayoflabels,($obj->value?$obj->value:
'CARD'),1,0,0);
1490 print '<input type="hidden" name="consttype" value="yesno">';
1491 print '<input type="hidden" name="constnote'.(empty($strictw3c)?
'':
'[]').
'" value="'.nl2br(
dol_escape_htmltag($obj->note)).
'">';
1497 print '<input type="hidden" name="consttype'.(empty($strictw3c)?
'':
'[]').
'" value="'.($obj->type?$obj->type:
'string').
'">';
1498 print '<input type="hidden" name="constnote'.(empty($strictw3c)?
'':
'[]').
'" value="'.nl2br(
dol_escape_htmltag($obj->note)).
'">';
1499 if ($obj->type ==
'textarea' || in_array($const,array(
'ADHERENT_CARD_TEXT',
'ADHERENT_CARD_TEXT_RIGHT',
'ADHERENT_ETIQUETTE_TEXT')))
1501 print '<textarea class="flat" name="constvalue'.(empty($strictw3c)?
'':
'[]').
'" cols="50" rows="5" wrap="soft">'.
"\n";
1503 print "</textarea>\n";
1505 elseif ($obj->type ==
'html')
1507 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1508 $doleditor=
new DolEditor(
'constvalue_'.$const.(empty($strictw3c)?
'':
'[]'),$obj->value,
'',160,
'dolibarr_notes',
'',
false,
false,$conf->fckeditor->enabled,ROWS_5,
'90%');
1509 $doleditor->Create();
1511 elseif ($obj->type ==
'yesno')
1513 print $form->selectyesno(
'constvalue'.(empty($strictw3c)?
'':
'[]'),$obj->value,1);
1515 elseif (preg_match(
'/emailtemplate/', $obj->type))
1517 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1520 $tmp=explode(
':', $obj->type);
1522 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, -1);
1524 $arrayofmessagename=array();
1525 if (is_array($formmail->lines_model))
1527 foreach($formmail->lines_model as $modelmail)
1531 if (! empty($arrayofmessagename[$modelmail->label])) $moreonlabel=
' <span class="opacitymedium">('.$langs->trans(
"SeveralLangugeVariatFound").
')</span>';
1532 $arrayofmessagename[$modelmail->label]=$langs->trans(preg_replace(
'/\(|\)/',
'',$modelmail->label)).$moreonlabel;
1537 print $form->selectarray(
'constvalue_'.$obj->name, $arrayofmessagename, $obj->value,
'None', 1, 0,
'', 0, 0, 0,
'',
'', 1);
1541 print '<input type="text" class="flat" size="48" name="constvalue'.(empty($strictw3c)?
'':
'[]').
'" value="'.
dol_escape_htmltag($obj->value).
'">';
1546 if (empty($strictw3c))
1548 print '<td align="center">';
1549 print '<input type="submit" class="button" value="'.$langs->trans(
"Update").
'" name="Button">';
1553 if (empty($strictw3c))
print "</form>\n";
1558 if (! empty($strictw3c) && $strictw3c == 1)
1560 print '<div align="center"><input type="submit" class="button" value="'.$langs->trans(
"Update").
'" name="update"></div>';
1574 global $conf,$langs;
1576 $text=$langs->trans(
"OnlyFollowingModulesAreOpenedToExternalUsers");
1577 $listofmodules=explode(
',',$conf->global->MAIN_MODULES_FOR_EXTERNAL);
1579 if (!empty($modules)) {
1580 foreach($modules as $module)
1582 $moduleconst=$module->const_name;
1583 $modulename=strtolower($module->name);
1587 if (! in_array($modulename,$listofmodules))
continue;
1590 if ($i > 0) $text.=
', ';
1593 $text .= $langs->trans(
'Module'.$module->numero.
'Name');
1615 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"document_model (nom, type, entity, libelle, description)";
1616 $sql.=
" VALUES ('".$db->escape($name).
"','".$type.
"',".$conf->entity.
", ";
1617 $sql.= ($label?
"'".$db->escape($label).
"'":
'null').
", ";
1618 $sql.= (! empty($description)?
"'".$db->escape($description).
"'":
"null");
1621 dol_syslog(
"admin.lib::addDocumentModel", LOG_DEBUG);
1649 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"document_model";
1650 $sql.=
" WHERE nom = '".$db->escape($name).
"'";
1651 $sql.=
" AND type = '".$type.
"'";
1652 $sql.=
" AND entity = ".$conf->entity;
1654 dol_syslog(
"admin.lib::delDocumentModel", LOG_DEBUG);
1679 $info_arr = array();
1680 $info_lines = explode(
"\n", strip_tags(ob_get_clean(),
"<tr><td><h2>"));
1682 foreach($info_lines as $line)
1685 preg_match(
"~<h2>(.*)</h2>~", $line, $title) ? $cat = $title[1] : null;
1686 if(preg_match(
"~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~", $line, $val))
1688 $info_arr[trim($cat)][trim($val[1])] = $val[2];
1690 elseif(preg_match(
"~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~", $line, $val))
1692 $info_arr[trim($cat)][trim($val[1])] = array(
"local" => $val[2],
"master" => $val[3]);
1705 global $langs, $conf, $user;
1710 $head[$h][0] = DOL_URL_ROOT.
"/admin/company.php";
1711 $head[$h][1] = $langs->trans(
"Company");
1712 $head[$h][2] =
'company';
1715 $head[$h][0] = DOL_URL_ROOT.
"/admin/accountant.php";
1716 $head[$h][1] = $langs->trans(
"Accountant");
1717 $head[$h][2] =
'accountant';
1732 global $langs, $conf, $user;
1737 if (! empty($user->admin) && (empty($_SESSION[
'leftmenu']) || $_SESSION[
'leftmenu'] !=
'email_templates'))
1739 $head[$h][0] = DOL_URL_ROOT.
"/admin/mails.php";
1740 $head[$h][1] = $langs->trans(
"OutGoingEmailSetup");
1741 $head[$h][2] =
'common';
1744 if ($conf->mailing->enabled)
1746 $head[$h][0] = DOL_URL_ROOT.
"/admin/mails_emailing.php";
1747 $head[$h][1] = $langs->trans(
"OutGoingEmailSetupForEmailing");
1748 $head[$h][2] =
'common_emailing';
1753 $head[$h][0] = DOL_URL_ROOT.
"/admin/mails_templates.php";
1754 $head[$h][1] = $langs->trans(
"EMailTemplates");
1755 $head[$h][2] =
'templates';
1758 if ($conf->global->MAIN_FEATURES_LEVEL >= 1 && ! empty($user->admin) && (empty($_SESSION[
'leftmenu']) || $_SESSION[
'leftmenu'] !=
'email_templates'))
1760 $head[$h][0] = DOL_URL_ROOT.
"/admin/mails_senderprofile_list.php";
1761 $head[$h][1] = $langs->trans(
"EmailSenderProfiles");
1762 $head[$h][2] =
'senderprofiles';
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
delDocumentModel($name, $type)
Delete document model used by doc generator.
print
Draft customers invoices.
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dolibarr_get_const($db, $name, $entity=1)
Recupere une constante depuis la base de donnees.
unActivateModule($value, $requiredby=1)
Disable a module.
complete_elementList_with_modules(&$elementList)
Add external modules to list of contact element.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
listOfSessions()
Return list of session.
purgeSessions($mysessionid)
Purge existing sessions.
email_admin_prepare_head()
Return array head with list of tabs to view object informations.
dolGetModulesDirs($subdir='')
Return list of modules directories.
versiondolibarrarray()
Return version Dolibarr.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
showModulesExludedForExternal($modules)
Show array with constants to edit.
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
form_constantes($tableau, $strictw3c=0, $helptext='')
Show array with constants to edit.
versiontostring($versionarray)
Renvoi une version en chaine depuis une version en tableau.
translation_prepare_head()
Prepare array with list of tabs.
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
company_admin_prepare_head()
Return array head with list of tabs to view object informations.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
complete_dictionary_with_modules(&$taborder, &$tabname, &$tablib, &$tabsql, &$tabsqlsort, &$tabfield, &$tabfieldvalue, &$tabfieldinsert, &$tabrowid, &$tabcond, &$tabhelp, &$tabfieldcheck)
Add external modules to list of dictionaries.
dolibarr_del_const($db, $name, $entity=1)
Effacement d'une constante dans la base de donnees.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays).
run_sql($sqlfile, $silent=1, $entity='', $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0)
Launch a sql file.
security_prepare_head()
Prepare array with list of tabs.
phpinfo_array()
Return the php_info into an array.
activateModulesRequiredByCountry($country_code)
Activate external modules mandatory when country is country_code.
defaultvalues_prepare_head()
Prepare array with list of tabs.
activateModule($value, $withdeps=1)
Enable a module.
Class to manage a WYSIWYG editor.
modules_prepare_head()
Prepare array with list of tabs.
dol_htmlentities($string, $flags=null, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
versionphparray()
Return version PHP.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.