28if (!$res && !empty($_SERVER[
"CONTEXT_DOCUMENT_ROOT"])) {
29 $res = @include $_SERVER[
"CONTEXT_DOCUMENT_ROOT"].
"/main.inc.php";
32$tmp = empty($_SERVER[
'SCRIPT_FILENAME']) ?
'' : $_SERVER[
'SCRIPT_FILENAME'];
33$tmp2 = realpath(__FILE__);
35$j = strlen($tmp2) - 1;
36while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
40if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)).
"/main.inc.php")) {
41 $res = @include substr($tmp, 0, ($i + 1)).
"/main.inc.php";
43if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))).
"/main.inc.php")) {
44 $res = @include dirname(substr($tmp, 0, ($i + 1))).
"/main.inc.php";
47if (!$res && file_exists(
"../../main.inc.php")) {
48 $res = @include
"../../main.inc.php";
50if (!$res && file_exists(
"../../../main.inc.php")) {
51 $res = @include
"../../../main.inc.php";
54 die(
"Include of main fails");
60require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
61require_once
'../lib/mymodule.lib.php';
65$langs->loadLangs(array(
"admin",
"mymodule@mymodule"));
68$hookmanager->initHooks(array(
'mymodulesetup',
'globalsetup'));
71$action =
GETPOST(
'action',
'aZ09');
72$backtopage =
GETPOST(
'backtopage',
'alpha');
73$modulepart =
GETPOST(
'modulepart',
'aZ09');
75$value =
GETPOST(
'value',
'alpha');
76$label =
GETPOST(
'label',
'alpha');
77$scandir =
GETPOST(
'scan_dir',
'alpha');
92if (!class_exists(
'FormSetup')) {
93 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formsetup.class.php';
106$item = $formSetup->newItem(
'MYMODULE_MYPARAM1');
107$item->fieldOverride = (empty($_SERVER[
'HTTPS']) ?
'http://' :
'https://') . $_SERVER[
'HTTP_HOST'];
108$item->cssClass =
'minwidth500';
111$item = $formSetup->newItem(
'MYMODULE_MYPARAM2');
112$item->defaultFieldValue =
'default value';
113$item->fieldAttr[
'placeholder'] =
'A placeholder here';
116$item = $formSetup->newItem(
'MYMODULE_MYPARAM3');
117$item->nameText = $item->getNameText().
' more html text ';
120$item = $formSetup->newItem(
'MYMODULE_MYPARAM4');
121$item->setAsThirdpartyType();
124$formSetup->newItem(
'MYMODULE_MYPARAM5')->setAsYesNo();
127$formSetup->newItem(
'MYMODULE_MYPARAM6')->setAsEmailTemplate(
'thirdparty');
133$formSetup->newItem(
'MYMODULE_MYPARAM8')->setAsProduct();
136$formSetup->newItem(
'NewSection')->setAsTitle();
139 'test01' => $langs->trans(
'test01'),
140 'test02' => $langs->trans(
'test02'),
141 'test03' => $langs->trans(
'test03'),
142 'test04' => $langs->trans(
'test04'),
143 'test05' => $langs->trans(
'test05'),
144 'test06' => $langs->trans(
'test06'),
148$formSetup->newItem(
'MYMODULE_MYPARAM9')->setAsSelect($TField);
151$item = $formSetup->newItem(
'MYMODULE_MYPARAM10');
152$item->setAsMultiSelect($TField);
153$item->helpText = $langs->transnoentities(
'MYMODULE_MYPARAM10');
156$formSetup->newItem(
'MYMODULE_CATEGORY_ID_XXX')->setAsCategory(
'product');
159$item = $formSetup->newItem(
'MYMODULE_MYPARAM10');
161$item->defaultFieldValue =
'#FF0000';
162$item->nameText = $item->getNameText().
' more html text ';
163$item->fieldInputOverride =
'';
164$item->helpText = $langs->transnoentities(
'AnHelpMessage');
172$setupnotempty += count($formSetup->items);
175$dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
177$moduledir =
'mymodule';
178$myTmpObjects = array();
180$myTmpObjects[
'myobject'] = array(
'label' =>
'MyObject',
'includerefgeneration' => 0,
'includedocgeneration' => 0,
'class' =>
'MyObject');
182$tmpobjectkey =
GETPOST(
'object',
'aZ09');
183if ($tmpobjectkey && !array_key_exists($tmpobjectkey, $myTmpObjects)) {
193if (
versioncompare(explode(
'.', DOL_VERSION), array(15)) < 0 && $action ==
'update' && !empty($user->admin)) {
194 $formSetup->saveConfFromPost();
197include DOL_DOCUMENT_ROOT.
'/core/actions_setmoduleoptions.inc.php';
199if ($action ==
'updateMask') {
200 $maskconst =
GETPOST(
'maskconst',
'aZ09');
201 $maskvalue =
GETPOST(
'maskvalue',
'alpha');
203 if ($maskconst && preg_match(
'/_MASK$/', $maskconst)) {
204 $res =
dolibarr_set_const($db, $maskconst, $maskvalue,
'chaine', 0,
'', $conf->entity);
215} elseif ($action ==
'specimen' && $tmpobjectkey) {
216 $modele =
GETPOST(
'module',
'alpha');
218 $className = $myTmpObjects[$tmpobjectkey][
'class'];
219 $tmpobject =
new $className($db);
220 '@phan-var-force MyObject $tmpobject';
221 $tmpobject->initAsSpecimen();
226 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
227 foreach ($dirmodels as $reldir) {
228 $file =
dol_buildpath($reldir.
"core/modules/mymodule/doc/pdf_".$modele.
"_".strtolower($tmpobjectkey).
".modules.php", 0);
229 if (file_exists($file)) {
230 $className =
"pdf_".$modele.
"_".strtolower($tmpobjectkey);
235 if ($className !==
'') {
238 $module =
new $className($db);
239 '@phan-var-force ModelePDFMyObject $module';
241 '@phan-var-force ModelePDFMyObject $module';
243 if ($module->write_file($tmpobject, $langs) > 0) {
244 header(
"Location: ".DOL_URL_ROOT.
"/document.php?modulepart=mymodule-".strtolower($tmpobjectkey).
"&file=SPECIMEN.pdf");
252 dol_syslog($langs->trans(
"ErrorModuleNotFound"), LOG_ERR);
254} elseif ($action ==
'setmod') {
256 if (!empty($tmpobjectkey)) {
257 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
"_ADDON";
260} elseif ($action ==
'set') {
263} elseif ($action ==
'del') {
266 if (!empty($tmpobjectkey)) {
267 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
273} elseif ($action ==
'setdoc') {
275 if (!empty($tmpobjectkey)) {
276 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
280 $conf->global->{$constforval} = $value;
289} elseif ($action ==
'unsetdoc') {
290 if (!empty($tmpobjectkey)) {
291 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
303$form =
new Form($db);
306$title =
"MyModuleSetup";
308llxHeader(
'', $langs->trans($title), $help_url,
'', 0, 0,
'',
'',
'',
'mod-mymodule page-admin');
311$linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1').
'">'.$langs->trans(
"BackToModuleList").
'</a>';
317print
dol_get_fiche_head($head,
'settings', $langs->trans($title), -1,
"mymodule@mymodule");
320echo
'<span class="opacitymedium">'.$langs->trans(
"MyModuleSetupPage").
'</span><br><br>';
333if (!empty($formSetup->items)) {
334 print $formSetup->generateOutput(
true);
337 print
'<br>'.$langs->trans(
"NothingToSetup");
341foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
342 if (!empty($myTmpObjectArray[
'includerefgeneration'])) {
348 print
load_fiche_titre($langs->trans(
"NumberingModules", $myTmpObjectArray[
'label']),
'',
'');
350 print
'<table class="noborder centpercent">';
351 print
'<tr class="liste_titre">';
352 print
'<td>'.$langs->trans(
"Name").
'</td>';
353 print
'<td>'.$langs->trans(
"Description").
'</td>';
354 print
'<td class="nowrap">'.$langs->trans(
"Example").
'</td>';
355 print
'<td class="center" width="60">'.$langs->trans(
"Status").
'</td>';
356 print
'<td class="center" width="16">'.$langs->trans(
"ShortInfo").
'</td>';
361 foreach ($dirmodels as $reldir) {
365 $handle = opendir($dir);
366 if (is_resource($handle)) {
367 while (($file = readdir($handle)) !==
false) {
368 if (strpos($file,
'mod_'.strtolower($myTmpObjectKey).
'_') === 0 && substr($file,
dol_strlen($file) - 3, 3) ==
'php') {
369 $file = substr($file, 0,
dol_strlen($file) - 4);
371 require_once $dir.
'/'.$file.
'.php';
373 $module =
new $file($db);
374 '@phan-var-force ModeleNumRefMyObject $module';
377 if ($module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
380 if ($module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
384 if ($module->isEnabled()) {
385 dol_include_once(
'/'.$moduledir.
'/class/'.strtolower($myTmpObjectKey).
'.class.php');
387 print
'<tr class="oddeven"><td>'.$module->getName($langs).
"</td><td>\n";
388 print $module->info($langs);
392 print
'<td class="nowrap">';
393 $tmp = $module->getExample();
394 if (preg_match(
'/^Error/', $tmp)) {
395 $langs->load(
"errors");
396 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
397 } elseif ($tmp ==
'NotConfigured') {
398 print $langs->trans($tmp);
404 print
'<td class="center">';
405 $constforvar =
'MYMODULE_'.strtoupper($myTmpObjectKey).
'_ADDON';
407 print
img_picto($langs->trans(
"Activated"),
'switch_on');
409 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=setmod&token='.
newToken().
'&object='.strtolower($myTmpObjectKey).
'&value='.urlencode($file).
'">';
410 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
415 $className = $myTmpObjectArray[
'class'];
416 $mytmpinstance =
new $className($db);
417 '@phan-var-force MyObject $mytmpinstance';
418 $mytmpinstance->initAsSpecimen();
422 $htmltooltip .=
''.$langs->trans(
"Version").
': <b>'.$module->getVersion().
'</b><br>';
424 $nextval = $module->getNextValue($mytmpinstance);
425 if (
"$nextval" != $langs->trans(
"NotAvailable")) {
426 $htmltooltip .=
''.$langs->trans(
"NextValue").
': ';
428 if (preg_match(
'/^Error/', $nextval) || $nextval ==
'NotConfigured') {
429 $nextval = $langs->trans($nextval);
431 $htmltooltip .= $nextval.
'<br>';
433 $htmltooltip .= $langs->trans($module->error).
'<br>';
437 print
'<td class="center">';
438 print $form->textwithpicto(
'', $htmltooltip, 1, 0);
449 print
"</table><br>\n";
452 if (!empty($myTmpObjectArray[
'includedocgeneration'])) {
457 $type = strtolower($myTmpObjectKey);
459 print
load_fiche_titre($langs->trans(
"DocumentModules", $myTmpObjectKey),
'',
'');
464 $sql .=
" FROM ".MAIN_DB_PREFIX.
"document_model";
465 $sql .=
" WHERE type = '".$db->escape($type).
"'";
466 $sql .=
" AND entity = ".$conf->entity;
467 $resql = $db->query($sql);
470 $num_rows = $db->num_rows($resql);
471 while ($i < $num_rows) {
472 $array = $db->fetch_array($resql);
473 array_push($def, $array[0]);
480 print
'<table class="noborder centpercent">'.
"\n";
481 print
'<tr class="liste_titre">'.
"\n";
482 print
'<td>'.$langs->trans(
"Name").
'</td>';
483 print
'<td>'.$langs->trans(
"Description").
'</td>';
484 print
'<td class="center" width="60">'.$langs->trans(
"Status").
"</td>\n";
485 print
'<td class="center" width="60">'.$langs->trans(
"Default").
"</td>\n";
486 print
'<td class="center" width="38">'.$langs->trans(
"ShortInfo").
'</td>';
487 print
'<td class="center" width="38">'.$langs->trans(
"Preview").
'</td>';
492 foreach ($dirmodels as $reldir) {
493 foreach (array(
'',
'/doc') as $valdir) {
494 $realpath = $reldir.
"core/modules/".$moduledir.$valdir;
498 $handle = opendir($dir);
499 if (is_resource($handle)) {
501 while (($file = readdir($handle)) !==
false) {
507 foreach ($filelist as $file) {
508 if (preg_match(
'/\.modules\.php$/i', $file) && preg_match(
'/^(pdf_|doc_)/', $file)) {
509 if (file_exists($dir.
'/'.$file)) {
510 $name = substr($file, 4,
dol_strlen($file) - 16);
511 $className = substr($file, 0,
dol_strlen($file) - 12);
513 require_once $dir.
'/'.$file;
514 $module =
new $className($db);
515 '@phan-var-force ModelePDFMyObject $module';
517 $modulequalified = 1;
518 if ($module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
519 $modulequalified = 0;
521 if ($module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
522 $modulequalified = 0;
525 if ($modulequalified) {
526 print
'<tr class="oddeven"><td width="100">';
527 print(empty($module->name) ? $name : $module->
name);
529 if (method_exists($module,
'info')) {
530 print $module->info($langs);
532 print $module->description;
537 if (in_array($name, $def)) {
538 print
'<td class="center">'.
"\n";
539 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=del&token='.
newToken().
'&value='.urlencode($name).
'">';
540 print
img_picto($langs->trans(
"Enabled"),
'switch_on');
544 print
'<td class="center">'.
"\n";
545 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=set&token='.
newToken().
'&value='.urlencode($name).
'&scan_dir='.urlencode($module->scandir).
'&label='.urlencode($module->name).
'">'.
img_picto($langs->trans(
"Disabled"),
'switch_off').
'</a>';
550 print
'<td class="center">';
551 $constforvar =
'MYMODULE_'.strtoupper($myTmpObjectKey).
'_ADDON_PDF';
555 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=unsetdoc&token='.
newToken().
'&object='.urlencode(strtolower($myTmpObjectKey)).
'&value='.urlencode($name).
'&scan_dir='.urlencode($module->scandir).
'&label='.urlencode($module->name).
'&type='.urlencode($type).
'" alt="'.$langs->trans(
"Disable").
'">'.
img_picto($langs->trans(
"Enabled"),
'on').
'</a>';
557 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=setdoc&token='.
newToken().
'&object='.urlencode(strtolower($myTmpObjectKey)).
'&value='.urlencode($name).
'&scan_dir='.urlencode($module->scandir).
'&label='.urlencode($module->name).
'" alt="'.$langs->trans(
"Default").
'">'.
img_picto($langs->trans(
"Disabled"),
'off').
'</a>';
562 $htmltooltip =
''.$langs->trans(
"Name").
': '.$module->name;
563 $htmltooltip .=
'<br>'.$langs->trans(
"Type").
': '.($module->type ? $module->type : $langs->trans(
"Unknown"));
564 if ($module->type ==
'pdf') {
565 $htmltooltip .=
'<br>'.$langs->trans(
"Width").
'/'.$langs->trans(
"Height").
': '.$module->page_largeur.
'/'.$module->page_hauteur;
567 $htmltooltip .=
'<br>'.$langs->trans(
"Path").
': '.preg_replace(
'/^\//',
'', $realpath).
'/'.$file;
569 $htmltooltip .=
'<br><br><u>'.$langs->trans(
"FeaturesSupported").
':</u>';
570 $htmltooltip .=
'<br>'.$langs->trans(
"Logo").
': '.
yn($module->option_logo, 1, 1);
571 $htmltooltip .=
'<br>'.$langs->trans(
"MultiLanguage").
': '.
yn($module->option_multilang, 1, 1);
573 print
'<td class="center">';
574 print $form->textwithpicto(
'', $htmltooltip, 1, 0);
578 print
'<td class="center">';
579 if ($module->type ==
'pdf') {
580 $newname = preg_replace(
'/_'.preg_quote(strtolower($myTmpObjectKey),
'/').
'/',
'', $name);
581 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=specimen&module='.urlencode($newname).
'&object='.urlencode($myTmpObjectKey).
'">'.
img_object($langs->trans(
"Preview"),
'pdf').
'</a>';
583 print
img_object($langs->trans(
"PreviewNotAvailable"),
'generic');
601if (empty($setupnotempty)) {
602 print
'<br>'.$langs->trans(
"NothingToSetup");
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
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).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
delDocumentModel($name, $type)
Delete document model used by doc generator.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays).
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
mymoduleAdminPrepareHead()
Prepare admin pages header.
$conf db name
Only used if Module[ID]Name translation string is not found.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.