29if (!$res && !empty($_SERVER[
"CONTEXT_DOCUMENT_ROOT"])) {
30 $res = @include str_replace(
"..",
"", $_SERVER[
"CONTEXT_DOCUMENT_ROOT"]).
"/main.inc.php";
33$tmp = empty($_SERVER[
'SCRIPT_FILENAME']) ?
'' : $_SERVER[
'SCRIPT_FILENAME'];
34$tmp2 = realpath(__FILE__);
36$j = strlen($tmp2) - 1;
37while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
41if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)).
"/main.inc.php")) {
42 $res = @include substr($tmp, 0, ($i + 1)).
"/main.inc.php";
44if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))).
"/main.inc.php")) {
45 $res = @include dirname(substr($tmp, 0, ($i + 1))).
"/main.inc.php";
48if (!$res && file_exists(
"../../main.inc.php")) {
49 $res = @include
"../../main.inc.php";
51if (!$res && file_exists(
"../../../main.inc.php")) {
52 $res = @include
"../../../main.inc.php";
55 die(
"Include of main fails");
59require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
60require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions.lib.php';
61require_once
'../lib/mymodule.lib.php';
73$langs->loadLangs(array(
"admin",
"mymodule@mymodule"));
77$hookmanager->initHooks(array(
'mymodulesetup',
'globalsetup'));
80$action =
GETPOST(
'action',
'aZ09');
81$backtopage =
GETPOST(
'backtopage',
'alpha');
82$modulepart =
GETPOST(
'modulepart',
'aZ09');
84$value =
GETPOST(
'value',
'alpha');
85$label =
GETPOST(
'label',
'alpha');
86$scandir =
GETPOST(
'scan_dir',
'alpha');
101if (!class_exists(
'FormSetup')) {
102 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formsetup.class.php';
109$item = $formSetup->newItem(
'MYMODULE_MYPARAM1');
110$item->fieldParams[
'isMandatory'] = 1;
111$item->fieldAttr[
'placeholder'] = (empty($_SERVER[
'HTTPS']) ?
'http://' :
'https://') . $_SERVER[
'HTTP_HOST'];
112$item->cssClass =
'minwidth500';
115$item = $formSetup->newItem(
'MYMODULE_MYPARAM2');
116$item->defaultFieldValue =
'default value';
117$item->fieldAttr[
'placeholder'] =
'A placeholder here';
118$item->helpText =
'Tooltip text';
121$item = $formSetup->newItem(
'MYMODULE_MYPARAM3');
122$item->nameText = $item->getNameText().
' more html text ';
125$item = $formSetup->newItem(
'MYMODULE_MYPARAM4');
126$item->setAsThirdpartyType();
129$formSetup->newItem(
'MYMODULE_MYPARAM5')->setAsYesNo();
132$formSetup->newItem(
'MYMODULE_MYPARAM6')->setAsEmailTemplate(
'thirdparty');
138$formSetup->newItem(
'MYMODULE_MYPARAM8')->setAsProduct();
141$formSetup->newItem(
'NewSection')->setAsTitle();
144 'test01' => $langs->trans(
'test01'),
145 'test02' => $langs->trans(
'test02'),
146 'test03' => $langs->trans(
'test03'),
147 'test04' => $langs->trans(
'test04'),
148 'test05' => $langs->trans(
'test05'),
149 'test06' => $langs->trans(
'test06'),
153$formSetup->newItem(
'MYMODULE_MYPARAM9')->setAsSelect($TField);
156$item = $formSetup->newItem(
'MYMODULE_MYPARAM10');
157$item->setAsMultiSelect($TField);
158$item->helpText = $langs->transnoentities(
'MYMODULE_MYPARAM10');
161$formSetup->newItem(
'MYMODULE_CATEGORY_ID_XXX')->setAsCategory(
'product');
164$item = $formSetup->newItem(
'MYMODULE_MYPARAM10');
166$item->defaultFieldValue =
'#FF0000';
173$item = $formSetup->newItem(
'MYMODULE_MYPARAM11')->setAsHtml();
174$item->nameText = $item->getNameText().
' more html text ';
175$item->fieldInputOverride =
'';
176$item->helpText = $langs->transnoentities(
'HelpMessage');
177$item->cssClass =
'minwidth500';
179$item = $formSetup->newItem(
'MYMODULE_MYPARAM12');
180$item->fieldOverride =
"Value forced, can't be modified";
181$item->cssClass =
'minwidth500';
188$setupnotempty += count($formSetup->items);
191$dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
193$moduledir =
'mymodule';
194$myTmpObjects = array();
196$myTmpObjects[
'myobject'] = array(
'label' =>
'MyObject',
'includerefgeneration' => 0,
'includedocgeneration' => 0,
'class' =>
'MyObject');
198$tmpobjectkey =
GETPOST(
'object',
'aZ09');
199if ($tmpobjectkey && !array_key_exists($tmpobjectkey, $myTmpObjects)) {
209if (
versioncompare(explode(
'.', DOL_VERSION), array(15)) < 0 && $action ==
'update' && !empty($user->admin)) {
210 $formSetup->saveConfFromPost();
213include DOL_DOCUMENT_ROOT.
'/core/actions_setmoduleoptions.inc.php';
215if ($action ==
'updateMask') {
216 $maskconst =
GETPOST(
'maskconst',
'aZ09');
217 $maskvalue =
GETPOST(
'maskvalue',
'alpha');
219 if ($maskconst && preg_match(
'/_MASK$/', $maskconst)) {
227 setEventMessages($langs->trans(
"SetupSaved"),
null,
'mesgs');
229 setEventMessages($langs->trans(
"Error"),
null,
'errors');
231} elseif ($action ==
'specimen' && $tmpobjectkey) {
232 $modele =
GETPOST(
'module',
'alpha');
234 $className = $myTmpObjects[$tmpobjectkey][
'class'];
235 $tmpobject =
new $className($db);
236 '@phan-var-force MyObject $tmpobject';
237 $tmpobject->initAsSpecimen();
242 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
243 foreach ($dirmodels as $reldir) {
245 if (file_exists($file)) {
251 if ($className !==
'') {
255 '@phan-var-force ModelePDFMyObject $module';
257 '@phan-var-force ModelePDFMyObject $module';
259 if (
$module->write_file($tmpobject, $langs) > 0) {
260 header(
"Location: ".DOL_URL_ROOT.
"/document.php?modulepart=mymodule-".
dol_strtolower($tmpobjectkey).
"&file=SPECIMEN.pdf");
263 setEventMessages(
$module->error,
null,
'errors');
267 setEventMessages($langs->trans(
"ErrorModuleNotFound"),
null,
'errors');
268 dol_syslog($langs->trans(
"ErrorModuleNotFound"), LOG_ERR);
270} elseif ($action ==
'setmod') {
272 if (!empty($tmpobjectkey)) {
273 $constforval =
'MYMODULE_'.dol_strtoupper($tmpobjectkey).
"_ADDON";
276} elseif ($action ==
'set') {
279} elseif ($action ==
'del') {
282 if (!empty($tmpobjectkey)) {
283 $constforval =
'MYMODULE_'.dol_strtoupper($tmpobjectkey).
'_ADDON_PDF';
289} elseif ($action ==
'setdoc') {
291 if (!empty($tmpobjectkey)) {
292 $constforval =
'MYMODULE_'.dol_strtoupper($tmpobjectkey).
'_ADDON_PDF';
296 $conf->global->{$constforval} = $value;
305} elseif ($action ==
'unsetdoc') {
306 if (!empty($tmpobjectkey)) {
307 $constforval =
'MYMODULE_'.dol_strtoupper($tmpobjectkey).
'_ADDON_PDF';
319$form =
new Form($db);
322$title =
"MyModuleSetup";
324llxHeader(
'', $langs->trans($title), $help_url,
'', 0, 0,
'',
'',
'',
'mod-mymodule page-admin');
327$linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1').
'">'.img_picto($langs->trans(
"BackToModuleList"),
'back',
'class="pictofixedwidth"').
'<span class="hideonsmartphone">'.$langs->trans(
"BackToModuleList").
'</span></a>';
333print
dol_get_fiche_head($head,
'settings', $langs->trans($title), -1,
"mymodule@mymodule");
336echo
'<span class="opacitymedium">'.$langs->trans(
"MyModuleSetupPage").
'</span><br><br>';
349if (!empty($formSetup->items)) {
350 print $formSetup->generateOutput(
true);
355$refGenerationObjects = array();
356$docGenerationObjects = array();
358foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
359 if (!empty($myTmpObjectArray[
'includerefgeneration'])) {
360 $refGenerationObjects[$myTmpObjectKey] = $myTmpObjectArray;
363 if (!empty($myTmpObjectArray[
'includedocgeneration'])) {
364 $docGenerationObjects[$myTmpObjectKey] = $myTmpObjectArray;
369if (!empty($refGenerationObjects)) {
374 print
'<table class="noborder centpercent">';
375 print
'<tr class="liste_titre">';
376 print
'<td>'.$langs->trans(
"Name").
'</td>';
377 print
'<td>'.$langs->trans(
"Description").
'</td>';
378 print
'<td class="nowrap">'.$langs->trans(
"Example").
'</td>';
379 print
'<td class="center" width="60">'.$langs->trans(
"Status").
'</td>';
380 print
'<td class="center" width="16">'.$langs->trans(
"ShortInfo").
'</td>';
385 foreach ($refGenerationObjects as $myTmpObjectKey => $myTmpObjectArray) {
386 if (empty($myTmpObjectArray[
'includerefgeneration'])) {
390 print
'<tr class="liste_titre">';
391 print
'<td colspan="5"><strong>'.$langs->trans($myTmpObjectArray[
'label']).
'</strong></td>';
394 foreach ($dirmodels as $reldir) {
401 $handle = opendir($dir);
402 if (!is_resource($handle)) {
406 while (($file = readdir($handle)) !==
false) {
413 require_once $dir.
'/'.$file.
'.php';
416 '@phan-var-force ModeleNumRefMyObject $module';
430 print
'<tr class="oddeven"><td>'.$module->getName($langs).
"</td><td>\n";
434 print
'<td class="nowrap">';
436 if (preg_match(
'/^Error/', $tmp)) {
437 $langs->load(
"errors");
438 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
439 } elseif ($tmp ==
'NotConfigured') {
440 print $langs->trans($tmp);
446 print
'<td class="center">';
447 $constforvar =
'MYMODULE_'.dol_strtoupper($myTmpObjectKey).
'_ADDON';
448 $defaultifnotset =
'thevaluetousebydefault';
451 if ($activenumberingmodel == $file) {
452 print img_picto($langs->trans(
"Activated"),
'switch_on');
454 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=setmod&token='.
newToken().
'&object='.urlencode(
dol_strtolower($myTmpObjectKey)).
'&value='.urlencode($file).
'">';
455 print img_picto($langs->trans(
"Disabled"),
'switch_off');
460 $className = $myTmpObjectArray[
'class'];
461 $mytmpinstance =
new $className($db);
462 '@phan-var-force MyObject $mytmpinstance';
463 $mytmpinstance->initAsSpecimen();
466 $htmltooltip .=
''.$langs->trans(
"Version").
': <b>'.
$module->getVersion().
'</b><br>';
468 $nextval =
$module->getNextValue($mytmpinstance);
469 if (
"$nextval" != $langs->trans(
"NotAvailable")) {
470 $htmltooltip .=
''.$langs->trans(
"NextValue").
': ';
472 if (preg_match(
'/^Error/', $nextval) || $nextval ==
'NotConfigured') {
473 $nextval = $langs->trans($nextval);
475 $htmltooltip .= $nextval.
'<br>';
477 $htmltooltip .= $langs->trans(
$module->error).
'<br>';
481 print
'<td class="center">';
482 print $form->textwithpicto(
'', $htmltooltip, 1,
'info');
491 print
'<tr><td colspan="5"><br></td></tr>'.
"\n";
494 print
"</table><br>\n";
498if (!empty($docGenerationObjects)) {
503 print
'<table class="noborder centpercent">'.
"\n";
504 print
'<tr class="liste_titre">'.
"\n";
505 print
'<td>'.$langs->trans(
"Name").
'</td>';
506 print
'<td>'.$langs->trans(
"Description").
'</td>';
507 print
'<td class="center" width="60">'.$langs->trans(
"Status").
"</td>\n";
508 print
'<td class="center" width="60">'.$langs->trans(
"Default").
"</td>\n";
509 print
'<td class="center" width="38">'.$langs->trans(
"ShortInfo").
'</td>';
510 print
'<td class="center" width="38">'.$langs->trans(
"Preview").
'</td>';
515 foreach ($docGenerationObjects as $myTmpObjectKey => $myTmpObjectArray) {
516 if (empty($myTmpObjectArray[
'includedocgeneration'])) {
522 print
'<tr class="liste_titre">';
523 print
'<td colspan="6"><strong>'.$langs->trans($myTmpObjectArray[
'label']).
'</strong></td>';
529 $sql .=
" FROM ".$db->prefix().
"document_model";
530 $sql .=
" WHERE type = '".$db->escape($type).
"'";
531 $sql .=
" AND entity = ".((int)
$conf->entity);
533 $resql = $db->query($sql);
536 $num_rows = $db->num_rows($resql);
537 while ($i < $num_rows) {
538 $array = $db->fetch_array($resql);
539 array_push($def, $array[0]);
543 dol_print_error($db);
546 foreach ($dirmodels as $reldir) {
547 foreach (array(
'',
'/doc') as $valdir) {
548 $realpath = $reldir.
"core/modules/".$moduledir.$valdir;
555 $handle = opendir($dir);
556 if (!is_resource($handle)) {
562 while (($file = readdir($handle)) !==
false) {
569 foreach ($filelist as $file) {
570 if (!preg_match(
'/\.modules\.php$/i', $file) || !preg_match(
'/^(pdf_|doc_)/', $file)) {
574 if (!preg_match(
'/_'.preg_quote($type,
'/').
'(_odt)?\.modules\.php$/i', $file)) {
578 if (!file_exists($dir.
'/'.$file)) {
585 require_once $dir.
'/'.$file;
588 '@phan-var-force ModelePDFMyObject $module';
590 $modulequalified = 1;
592 $modulequalified = 0;
595 $modulequalified = 0;
598 if (!$modulequalified) {
602 print
'<tr class="oddeven"><td width="100">';
606 if (method_exists(
$module,
'info')) {
614 if (in_array($name, $def)) {
615 print
'<td class="center">'.
"\n";
616 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=del&token='.
newToken().
'&object='.urlencode($type).
'&value='.urlencode($name).
'&type='.urlencode($type).
'">';
617 print img_picto($langs->trans(
"Enabled"),
'switch_on');
621 print
'<td class="center">'.
"\n";
622 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=set&token='.
newToken().
'&object='.urlencode($type).
'&value='.urlencode($name).
'&scan_dir='.urlencode(
$module->scandir).
'&label='.urlencode(
$module->name).
'&type='.urlencode($type).
'">';
623 print img_picto($langs->trans(
"Disabled"),
'switch_off');
628 print
'<td class="center">';
629 $constforvar =
'MYMODULE_'.dol_strtoupper($myTmpObjectKey).
'_ADDON_PDF';
632 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=unsetdoc&token='.
newToken().
'&object='.urlencode($type).
'&value='.urlencode($name).
'&scan_dir='.urlencode(
$module->scandir).
'&label='.urlencode(
$module->name).
'&type='.urlencode($type).
'" alt="'.$langs->trans(
"Disable").
'">';
633 print img_picto($langs->trans(
"Enabled"),
'on');
636 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=setdoc&token='.
newToken().
'&object='.urlencode($type).
'&value='.urlencode($name).
'&scan_dir='.urlencode(
$module->scandir).
'&label='.urlencode(
$module->name).
'&type='.urlencode($type).
'" alt="'.$langs->trans(
"Default").
'">';
637 print img_picto($langs->trans(
"Disabled"),
'off');
643 $htmltooltip =
''.$langs->trans(
"Name").
': '.
$module->name;
644 $htmltooltip .=
'<br>'.$langs->trans(
"Type").
': '.(
$module->type ?
$module->type : $langs->trans(
"Unknown"));
647 $htmltooltip .=
'<br>'.$langs->trans(
"Width").
'/'.$langs->trans(
"Height").
': '.
$module->page_largeur.
'/'.
$module->page_hauteur;
650 $htmltooltip .=
'<br>'.$langs->trans(
"Path").
': '.preg_replace(
'/^\//',
'', $realpath).
'/'.$file;
651 $htmltooltip .=
'<br><br><u>'.$langs->trans(
"FeaturesSupported").
':</u>';
652 $htmltooltip .=
'<br>'.$langs->trans(
"Logo").
': '.yn(
$module->option_logo, 1, 1);
653 $htmltooltip .=
'<br>'.$langs->trans(
"MultiLanguage").
': '.yn(
$module->option_multilang, 1, 1);
655 print
'<td class="center">';
656 print $form->textwithpicto(
'', $htmltooltip, 1,
'info');
659 print
'<td class="center">';
661 $newname = preg_replace(
'/_'.preg_quote($type,
'/').
'/',
'', $name);
662 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=specimen&module='.urlencode($newname).
'&object='.urlencode($type).
'">';
663 print img_object($langs->trans(
"Preview"),
'pdf');
666 print img_object($langs->transnoentitiesnoconv(
"PreviewNotAvailable"),
'generic');
675 print
'<tr><td colspan="6"><br></td></tr>'.
"\n";
681if (empty($setupnotempty)) {
682 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), to know if a version (a,b,c) is lower than (x,...
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
if(! $sortfield) if(! $sortorder) $module
dol_is_dir($folder)
Test if filename is a directory.
dol_strtolower($string, $encoding="UTF-8")
Convert a string to lower.
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.