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->fieldAttr[
'placeholder'] = (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';
168$item = $formSetup->newItem(
'MYMODULE_MYPARAM11')->setAsHtml();
169$item->nameText = $item->getNameText().
' more html text ';
170$item->fieldInputOverride =
'';
171$item->helpText = $langs->transnoentities(
'HelpMessage');
172$item->cssClass =
'minwidth500';
174$item = $formSetup->newItem(
'MYMODULE_MYPARAM12');
175$item->fieldOverride =
"Value forced, can't be modified";
176$item->cssClass =
'minwidth500';
183$setupnotempty += count($formSetup->items);
186$dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
188$moduledir =
'mymodule';
189$myTmpObjects = array();
191$myTmpObjects[
'myobject'] = array(
'label' =>
'MyObject',
'includerefgeneration' => 0,
'includedocgeneration' => 0,
'class' =>
'MyObject');
193$tmpobjectkey =
GETPOST(
'object',
'aZ09');
194if ($tmpobjectkey && !array_key_exists($tmpobjectkey, $myTmpObjects)) {
204if (
versioncompare(explode(
'.', DOL_VERSION), array(15)) < 0 && $action ==
'update' && !empty($user->admin)) {
205 $formSetup->saveConfFromPost();
208include DOL_DOCUMENT_ROOT.
'/core/actions_setmoduleoptions.inc.php';
210if ($action ==
'updateMask') {
211 $maskconst =
GETPOST(
'maskconst',
'aZ09');
212 $maskvalue =
GETPOST(
'maskvalue',
'alpha');
214 if ($maskconst && preg_match(
'/_MASK$/', $maskconst)) {
215 $res =
dolibarr_set_const($db, $maskconst, $maskvalue,
'chaine', 0,
'', $conf->entity);
226} elseif ($action ==
'specimen' && $tmpobjectkey) {
227 $modele =
GETPOST(
'module',
'alpha');
229 $className = $myTmpObjects[$tmpobjectkey][
'class'];
230 $tmpobject =
new $className($db);
231 '@phan-var-force MyObject $tmpobject';
232 $tmpobject->initAsSpecimen();
237 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
238 foreach ($dirmodels as $reldir) {
239 $file =
dol_buildpath($reldir.
"core/modules/mymodule/doc/pdf_".$modele.
"_".strtolower($tmpobjectkey).
".modules.php", 0);
240 if (file_exists($file)) {
241 $className =
"pdf_".$modele.
"_".strtolower($tmpobjectkey);
246 if ($className !==
'') {
249 $module =
new $className($db);
250 '@phan-var-force ModelePDFMyObject $module';
252 '@phan-var-force ModelePDFMyObject $module';
254 if ($module->write_file($tmpobject, $langs) > 0) {
255 header(
"Location: ".DOL_URL_ROOT.
"/document.php?modulepart=mymodule-".strtolower($tmpobjectkey).
"&file=SPECIMEN.pdf");
263 dol_syslog($langs->trans(
"ErrorModuleNotFound"), LOG_ERR);
265} elseif ($action ==
'setmod') {
267 if (!empty($tmpobjectkey)) {
268 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
"_ADDON";
271} elseif ($action ==
'set') {
274} elseif ($action ==
'del') {
277 if (!empty($tmpobjectkey)) {
278 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
284} elseif ($action ==
'setdoc') {
286 if (!empty($tmpobjectkey)) {
287 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
291 $conf->global->{$constforval} = $value;
300} elseif ($action ==
'unsetdoc') {
301 if (!empty($tmpobjectkey)) {
302 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
314$form =
new Form($db);
317$title =
"MyModuleSetup";
319llxHeader(
'', $langs->trans($title), $help_url,
'', 0, 0,
'',
'',
'',
'mod-mymodule page-admin');
322$linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1').
'">'.$langs->trans(
"BackToModuleList").
'</a>';
328print
dol_get_fiche_head($head,
'settings', $langs->trans($title), -1,
"mymodule@mymodule");
331echo
'<span class="opacitymedium">'.$langs->trans(
"MyModuleSetupPage").
'</span><br><br>';
344if (!empty($formSetup->items)) {
345 print $formSetup->generateOutput(
true);
348 print
'<br>'.$langs->trans(
"NothingToSetup");
352foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
353 if (!empty($myTmpObjectArray[
'includerefgeneration'])) {
359 print
load_fiche_titre($langs->trans(
"NumberingModules", $myTmpObjectArray[
'label']),
'',
'');
361 print
'<table class="noborder centpercent">';
362 print
'<tr class="liste_titre">';
363 print
'<td>'.$langs->trans(
"Name").
'</td>';
364 print
'<td>'.$langs->trans(
"Description").
'</td>';
365 print
'<td class="nowrap">'.$langs->trans(
"Example").
'</td>';
366 print
'<td class="center" width="60">'.$langs->trans(
"Status").
'</td>';
367 print
'<td class="center" width="16">'.$langs->trans(
"ShortInfo").
'</td>';
372 foreach ($dirmodels as $reldir) {
376 $handle = opendir($dir);
377 if (is_resource($handle)) {
378 while (($file = readdir($handle)) !==
false) {
379 if (strpos($file,
'mod_'.strtolower($myTmpObjectKey).
'_') === 0 && substr($file,
dol_strlen($file) - 3, 3) ==
'php') {
380 $file = substr($file, 0,
dol_strlen($file) - 4);
382 require_once $dir.
'/'.$file.
'.php';
384 $module =
new $file($db);
385 '@phan-var-force ModeleNumRefMyObject $module';
388 if ($module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
391 if ($module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
395 if ($module->isEnabled()) {
396 dol_include_once(
'/'.$moduledir.
'/class/'.strtolower($myTmpObjectKey).
'.class.php');
398 print
'<tr class="oddeven"><td>'.$module->getName($langs).
"</td><td>\n";
399 print $module->info($langs);
403 print
'<td class="nowrap">';
404 $tmp = $module->getExample();
405 if (preg_match(
'/^Error/', $tmp)) {
406 $langs->load(
"errors");
407 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
408 } elseif ($tmp ==
'NotConfigured') {
409 print $langs->trans($tmp);
415 print
'<td class="center">';
416 $constforvar =
'MYMODULE_'.strtoupper($myTmpObjectKey).
'_ADDON';
418 print
img_picto($langs->trans(
"Activated"),
'switch_on');
420 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=setmod&token='.
newToken().
'&object='.strtolower($myTmpObjectKey).
'&value='.urlencode($file).
'">';
421 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
426 $className = $myTmpObjectArray[
'class'];
427 $mytmpinstance =
new $className($db);
428 '@phan-var-force MyObject $mytmpinstance';
429 $mytmpinstance->initAsSpecimen();
433 $htmltooltip .=
''.$langs->trans(
"Version").
': <b>'.$module->getVersion().
'</b><br>';
435 $nextval = $module->getNextValue($mytmpinstance);
436 if (
"$nextval" != $langs->trans(
"NotAvailable")) {
437 $htmltooltip .=
''.$langs->trans(
"NextValue").
': ';
439 if (preg_match(
'/^Error/', $nextval) || $nextval ==
'NotConfigured') {
440 $nextval = $langs->trans($nextval);
442 $htmltooltip .= $nextval.
'<br>';
444 $htmltooltip .= $langs->trans($module->error).
'<br>';
448 print
'<td class="center">';
449 print $form->textwithpicto(
'', $htmltooltip, 1, 0);
460 print
"</table><br>\n";
463 if (!empty($myTmpObjectArray[
'includedocgeneration'])) {
468 $type = strtolower($myTmpObjectKey);
470 print
load_fiche_titre($langs->trans(
"DocumentModules", $myTmpObjectKey),
'',
'');
475 $sql .=
" FROM ".MAIN_DB_PREFIX.
"document_model";
476 $sql .=
" WHERE type = '".$db->escape($type).
"'";
477 $sql .=
" AND entity = ".$conf->entity;
478 $resql = $db->query($sql);
481 $num_rows = $db->num_rows($resql);
482 while ($i < $num_rows) {
483 $array = $db->fetch_array($resql);
484 array_push($def, $array[0]);
491 print
'<table class="noborder centpercent">'.
"\n";
492 print
'<tr class="liste_titre">'.
"\n";
493 print
'<td>'.$langs->trans(
"Name").
'</td>';
494 print
'<td>'.$langs->trans(
"Description").
'</td>';
495 print
'<td class="center" width="60">'.$langs->trans(
"Status").
"</td>\n";
496 print
'<td class="center" width="60">'.$langs->trans(
"Default").
"</td>\n";
497 print
'<td class="center" width="38">'.$langs->trans(
"ShortInfo").
'</td>';
498 print
'<td class="center" width="38">'.$langs->trans(
"Preview").
'</td>';
503 foreach ($dirmodels as $reldir) {
504 foreach (array(
'',
'/doc') as $valdir) {
505 $realpath = $reldir.
"core/modules/".$moduledir.$valdir;
509 $handle = opendir($dir);
510 if (is_resource($handle)) {
512 while (($file = readdir($handle)) !==
false) {
518 foreach ($filelist as $file) {
519 if (preg_match(
'/\.modules\.php$/i', $file) && preg_match(
'/^(pdf_|doc_)/', $file)) {
520 if (file_exists($dir.
'/'.$file)) {
521 $name = substr($file, 4,
dol_strlen($file) - 16);
522 $className = substr($file, 0,
dol_strlen($file) - 12);
524 require_once $dir.
'/'.$file;
525 $module =
new $className($db);
526 '@phan-var-force ModelePDFMyObject $module';
528 $modulequalified = 1;
529 if ($module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
530 $modulequalified = 0;
532 if ($module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
533 $modulequalified = 0;
536 if ($modulequalified) {
537 print
'<tr class="oddeven"><td width="100">';
538 print(empty($module->name) ? $name : $module->
name);
540 if (method_exists($module,
'info')) {
541 print $module->info($langs);
543 print $module->description;
548 if (in_array($name, $def)) {
549 print
'<td class="center">'.
"\n";
550 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=del&token='.
newToken().
'&value='.urlencode($name).
'">';
551 print
img_picto($langs->trans(
"Enabled"),
'switch_on');
555 print
'<td class="center">'.
"\n";
556 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>';
561 print
'<td class="center">';
562 $constforvar =
'MYMODULE_'.strtoupper($myTmpObjectKey).
'_ADDON_PDF';
566 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>';
568 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>';
573 $htmltooltip =
''.$langs->trans(
"Name").
': '.$module->name;
574 $htmltooltip .=
'<br>'.$langs->trans(
"Type").
': '.($module->type ? $module->type : $langs->trans(
"Unknown"));
575 if ($module->type ==
'pdf') {
576 $htmltooltip .=
'<br>'.$langs->trans(
"Width").
'/'.$langs->trans(
"Height").
': '.$module->page_largeur.
'/'.$module->page_hauteur;
578 $htmltooltip .=
'<br>'.$langs->trans(
"Path").
': '.preg_replace(
'/^\//',
'', $realpath).
'/'.$file;
580 $htmltooltip .=
'<br><br><u>'.$langs->trans(
"FeaturesSupported").
':</u>';
581 $htmltooltip .=
'<br>'.$langs->trans(
"Logo").
': '.
yn($module->option_logo, 1, 1);
582 $htmltooltip .=
'<br>'.$langs->trans(
"MultiLanguage").
': '.
yn($module->option_multilang, 1, 1);
584 print
'<td class="center">';
585 print $form->textwithpicto(
'', $htmltooltip, 1, 0);
589 print
'<td class="center">';
590 if ($module->type ==
'pdf') {
591 $newname = preg_replace(
'/_'.preg_quote(strtolower($myTmpObjectKey),
'/').
'/',
'', $name);
592 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=specimen&module='.urlencode($newname).
'&object='.urlencode($myTmpObjectKey).
'">'.
img_object($langs->trans(
"Preview"),
'pdf').
'</a>';
594 print
img_object($langs->trans(
"PreviewNotAvailable"),
'generic');
612if (empty($setupnotempty)) {
613 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)
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'.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
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.