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
'../lib/mymodule.lib.php';
72$langs->loadLangs(array(
"admin",
"mymodule@mymodule"));
76$hookmanager->initHooks(array(
'mymodulesetup',
'globalsetup'));
79$action =
GETPOST(
'action',
'aZ09');
80$backtopage =
GETPOST(
'backtopage',
'alpha');
81$modulepart =
GETPOST(
'modulepart',
'aZ09');
83$value =
GETPOST(
'value',
'alpha');
84$label =
GETPOST(
'label',
'alpha');
85$scandir =
GETPOST(
'scan_dir',
'alpha');
100if (!class_exists(
'FormSetup')) {
101 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formsetup.class.php';
114$item = $formSetup->newItem(
'MYMODULE_MYPARAM1');
115$item->fieldParams[
'isMandatory'] = 1;
116$item->fieldAttr[
'placeholder'] = (empty($_SERVER[
'HTTPS']) ?
'http://' :
'https://') . $_SERVER[
'HTTP_HOST'];
117$item->cssClass =
'minwidth500';
120$item = $formSetup->newItem(
'MYMODULE_MYPARAM2');
121$item->defaultFieldValue =
'default value';
122$item->fieldAttr[
'placeholder'] =
'A placeholder here';
123$item->helpText =
'Tooltip text';
126$item = $formSetup->newItem(
'MYMODULE_MYPARAM3');
127$item->nameText = $item->getNameText().
' more html text ';
130$item = $formSetup->newItem(
'MYMODULE_MYPARAM4');
131$item->setAsThirdpartyType();
134$formSetup->newItem(
'MYMODULE_MYPARAM5')->setAsYesNo();
137$formSetup->newItem(
'MYMODULE_MYPARAM6')->setAsEmailTemplate(
'thirdparty');
143$formSetup->newItem(
'MYMODULE_MYPARAM8')->setAsProduct();
146$formSetup->newItem(
'NewSection')->setAsTitle();
149 'test01' => $langs->trans(
'test01'),
150 'test02' => $langs->trans(
'test02'),
151 'test03' => $langs->trans(
'test03'),
152 'test04' => $langs->trans(
'test04'),
153 'test05' => $langs->trans(
'test05'),
154 'test06' => $langs->trans(
'test06'),
158$formSetup->newItem(
'MYMODULE_MYPARAM9')->setAsSelect($TField);
161$item = $formSetup->newItem(
'MYMODULE_MYPARAM10');
162$item->setAsMultiSelect($TField);
163$item->helpText = $langs->transnoentities(
'MYMODULE_MYPARAM10');
166$formSetup->newItem(
'MYMODULE_CATEGORY_ID_XXX')->setAsCategory(
'product');
169$item = $formSetup->newItem(
'MYMODULE_MYPARAM10');
171$item->defaultFieldValue =
'#FF0000';
178$item = $formSetup->newItem(
'MYMODULE_MYPARAM11')->setAsHtml();
179$item->nameText = $item->getNameText().
' more html text ';
180$item->fieldInputOverride =
'';
181$item->helpText = $langs->transnoentities(
'HelpMessage');
182$item->cssClass =
'minwidth500';
184$item = $formSetup->newItem(
'MYMODULE_MYPARAM12');
185$item->fieldOverride =
"Value forced, can't be modified";
186$item->cssClass =
'minwidth500';
193$setupnotempty += count($formSetup->items);
196$dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
198$moduledir =
'mymodule';
199$myTmpObjects = array();
201$myTmpObjects[
'myobject'] = array(
'label' =>
'MyObject',
'includerefgeneration' => 0,
'includedocgeneration' => 0,
'class' =>
'MyObject');
203$tmpobjectkey =
GETPOST(
'object',
'aZ09');
204if ($tmpobjectkey && !array_key_exists($tmpobjectkey, $myTmpObjects)) {
214if (
versioncompare(explode(
'.', DOL_VERSION), array(15)) < 0 && $action ==
'update' && !empty($user->admin)) {
215 $formSetup->saveConfFromPost();
218include DOL_DOCUMENT_ROOT.
'/core/actions_setmoduleoptions.inc.php';
220if ($action ==
'updateMask') {
221 $maskconst =
GETPOST(
'maskconst',
'aZ09');
222 $maskvalue =
GETPOST(
'maskvalue',
'alpha');
224 if ($maskconst && preg_match(
'/_MASK$/', $maskconst)) {
225 $res =
dolibarr_set_const($db, $maskconst, $maskvalue,
'chaine', 0,
'', $conf->entity);
236} elseif ($action ==
'specimen' && $tmpobjectkey) {
237 $modele =
GETPOST(
'module',
'alpha');
239 $className = $myTmpObjects[$tmpobjectkey][
'class'];
240 $tmpobject =
new $className($db);
241 '@phan-var-force MyObject $tmpobject';
242 $tmpobject->initAsSpecimen();
247 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
248 foreach ($dirmodels as $reldir) {
249 $file =
dol_buildpath($reldir.
"core/modules/mymodule/doc/pdf_".$modele.
"_".strtolower($tmpobjectkey).
".modules.php", 0);
250 if (file_exists($file)) {
251 $className =
"pdf_".$modele.
"_".strtolower($tmpobjectkey);
256 if ($className !==
'') {
259 $module =
new $className($db);
260 '@phan-var-force ModelePDFMyObject $module';
262 '@phan-var-force ModelePDFMyObject $module';
264 if ($module->write_file($tmpobject, $langs) > 0) {
265 header(
"Location: ".DOL_URL_ROOT.
"/document.php?modulepart=mymodule-".strtolower($tmpobjectkey).
"&file=SPECIMEN.pdf");
273 dol_syslog($langs->trans(
"ErrorModuleNotFound"), LOG_ERR);
275} elseif ($action ==
'setmod') {
277 if (!empty($tmpobjectkey)) {
278 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
"_ADDON";
281} elseif ($action ==
'set') {
284} elseif ($action ==
'del') {
287 if (!empty($tmpobjectkey)) {
288 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
294} elseif ($action ==
'setdoc') {
296 if (!empty($tmpobjectkey)) {
297 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
301 $conf->global->{$constforval} = $value;
310} elseif ($action ==
'unsetdoc') {
311 if (!empty($tmpobjectkey)) {
312 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
324$form =
new Form($db);
327$title =
"MyModuleSetup";
329llxHeader(
'', $langs->trans($title), $help_url,
'', 0, 0,
'',
'',
'',
'mod-mymodule page-admin');
332$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>';
338print
dol_get_fiche_head($head,
'settings', $langs->trans($title), -1,
"mymodule@mymodule");
341echo
'<span class="opacitymedium">'.$langs->trans(
"MyModuleSetupPage").
'</span><br><br>';
354if (!empty($formSetup->items)) {
355 print $formSetup->generateOutput(
true);
360foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
361 if (!empty($myTmpObjectArray[
'includerefgeneration'])) {
366 print
load_fiche_titre($langs->trans(
"NumberingModules", $myTmpObjectArray[
'label']),
'',
'');
368 print
'<table class="noborder centpercent">';
369 print
'<tr class="liste_titre">';
370 print
'<td>'.$langs->trans(
"Name").
'</td>';
371 print
'<td>'.$langs->trans(
"Description").
'</td>';
372 print
'<td class="nowrap">'.$langs->trans(
"Example").
'</td>';
373 print
'<td class="center" width="60">'.$langs->trans(
"Status").
'</td>';
374 print
'<td class="center" width="16">'.$langs->trans(
"ShortInfo").
'</td>';
379 foreach ($dirmodels as $reldir) {
383 $handle = opendir($dir);
384 if (is_resource($handle)) {
385 while (($file = readdir($handle)) !==
false) {
386 if (strpos($file,
'mod_'.strtolower($myTmpObjectKey).
'_') === 0 && substr($file,
dol_strlen($file) - 3, 3) ==
'php') {
387 $file = substr($file, 0,
dol_strlen($file) - 4);
389 require_once $dir.
'/'.$file.
'.php';
391 $module =
new $file($db);
392 '@phan-var-force ModeleNumRefMyObject $module';
395 if ($module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
398 if ($module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
402 if ($module->isEnabled()) {
403 dol_include_once(
'/'.$moduledir.
'/class/'.strtolower($myTmpObjectKey).
'.class.php');
405 print
'<tr class="oddeven"><td>'.$module->getName($langs).
"</td><td>\n";
406 print $module->info($langs);
410 print
'<td class="nowrap">';
411 $tmp = $module->getExample();
412 if (preg_match(
'/^Error/', $tmp)) {
413 $langs->load(
"errors");
414 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
415 } elseif ($tmp ==
'NotConfigured') {
416 print $langs->trans($tmp);
422 print
'<td class="center">';
423 $constforvar =
'MYMODULE_'.strtoupper($myTmpObjectKey).
'_ADDON';
424 $defaultifnotset =
'thevaluetousebydefault';
426 if ($activenumberingmodel == $file) {
427 print
img_picto($langs->trans(
"Activated"),
'switch_on');
429 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=setmod&token='.
newToken().
'&object='.strtolower($myTmpObjectKey).
'&value='.urlencode($file).
'">';
430 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
435 $className = $myTmpObjectArray[
'class'];
436 $mytmpinstance =
new $className($db);
437 '@phan-var-force MyObject $mytmpinstance';
438 $mytmpinstance->initAsSpecimen();
442 $htmltooltip .=
''.$langs->trans(
"Version").
': <b>'.$module->getVersion().
'</b><br>';
444 $nextval = $module->getNextValue($mytmpinstance);
445 if (
"$nextval" != $langs->trans(
"NotAvailable")) {
446 $htmltooltip .=
''.$langs->trans(
"NextValue").
': ';
448 if (preg_match(
'/^Error/', $nextval) || $nextval ==
'NotConfigured') {
449 $nextval = $langs->trans($nextval);
451 $htmltooltip .= $nextval.
'<br>';
453 $htmltooltip .= $langs->trans($module->error).
'<br>';
457 print
'<td class="center">';
458 print $form->textwithpicto(
'', $htmltooltip, 1,
'info');
469 print
"</table><br>\n";
472 if (!empty($myTmpObjectArray[
'includedocgeneration'])) {
477 $type = strtolower($myTmpObjectKey);
479 print
load_fiche_titre($langs->trans(
"DocumentModules", $myTmpObjectKey),
'',
'');
485 $sql .=
" FROM ".$db->prefix().
"document_model";
486 $sql .=
" WHERE type = '".$db->escape($type).
"'";
487 $sql .=
" AND entity = ".$conf->entity;
488 $resql = $db->query($sql);
491 $num_rows = $db->num_rows($resql);
492 while ($i < $num_rows) {
493 $array = $db->fetch_array($resql);
494 array_push($def, $array[0]);
501 print
'<table class="noborder centpercent">'.
"\n";
502 print
'<tr class="liste_titre">'.
"\n";
503 print
'<td>'.$langs->trans(
"Name").
'</td>';
504 print
'<td>'.$langs->trans(
"Description").
'</td>';
505 print
'<td class="center" width="60">'.$langs->trans(
"Status").
"</td>\n";
506 print
'<td class="center" width="60">'.$langs->trans(
"Default").
"</td>\n";
507 print
'<td class="center" width="38">'.$langs->trans(
"ShortInfo").
'</td>';
508 print
'<td class="center" width="38">'.$langs->trans(
"Preview").
'</td>';
513 foreach ($dirmodels as $reldir) {
514 foreach (array(
'',
'/doc') as $valdir) {
515 $realpath = $reldir.
"core/modules/".$moduledir.$valdir;
519 $handle = opendir($dir);
520 if (is_resource($handle)) {
522 while (($file = readdir($handle)) !==
false) {
528 foreach ($filelist as $file) {
529 if (preg_match(
'/\.modules\.php$/i', $file) && preg_match(
'/^(pdf_|doc_)/', $file)) {
530 if (file_exists($dir.
'/'.$file)) {
531 $name = substr($file, 4,
dol_strlen($file) - 16);
532 $className = substr($file, 0,
dol_strlen($file) - 12);
534 require_once $dir.
'/'.$file;
535 $module =
new $className($db);
536 '@phan-var-force ModelePDFMyObject $module';
538 $modulequalified = 1;
539 if ($module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
540 $modulequalified = 0;
542 if ($module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
543 $modulequalified = 0;
546 if ($modulequalified) {
547 print
'<tr class="oddeven"><td width="100">';
548 print(empty($module->name) ? $name : $module->
name);
550 if (method_exists($module,
'info')) {
551 print $module->info($langs);
553 print $module->description;
558 if (in_array($name, $def)) {
559 print
'<td class="center">'.
"\n";
560 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=del&token='.
newToken().
'&value='.urlencode($name).
'">';
561 print
img_picto($langs->trans(
"Enabled"),
'switch_on');
565 print
'<td class="center">'.
"\n";
566 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>';
571 print
'<td class="center">';
572 $constforvar =
'MYMODULE_'.strtoupper($myTmpObjectKey).
'_ADDON_PDF';
576 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>';
578 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>';
583 $htmltooltip =
''.$langs->trans(
"Name").
': '.$module->name;
584 $htmltooltip .=
'<br>'.$langs->trans(
"Type").
': '.($module->type ? $module->type : $langs->trans(
"Unknown"));
585 if ($module->type ==
'pdf') {
586 $htmltooltip .=
'<br>'.$langs->trans(
"Width").
'/'.$langs->trans(
"Height").
': '.$module->page_largeur.
'/'.$module->page_hauteur;
588 $htmltooltip .=
'<br>'.$langs->trans(
"Path").
': '.preg_replace(
'/^\//',
'', $realpath).
'/'.$file;
590 $htmltooltip .=
'<br><br><u>'.$langs->trans(
"FeaturesSupported").
':</u>';
591 $htmltooltip .=
'<br>'.$langs->trans(
"Logo").
': '.
yn($module->option_logo, 1, 1);
592 $htmltooltip .=
'<br>'.$langs->trans(
"MultiLanguage").
': '.
yn($module->option_multilang, 1, 1);
594 print
'<td class="center">';
595 print $form->textwithpicto(
'', $htmltooltip, 1,
'info');
599 print
'<td class="center">';
600 if ($module->type ==
'pdf') {
601 $newname = preg_replace(
'/_'.preg_quote(strtolower($myTmpObjectKey),
'/').
'/',
'', $name);
602 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=specimen&module='.urlencode($newname).
'&object='.urlencode($myTmpObjectKey).
'">'.
img_object($langs->trans(
"Preview"),
'pdf').
'</a>';
604 print
img_object($langs->transnoentitiesnoconv(
"PreviewNotAvailable"),
'generic');
622if (empty($setupnotempty)) {
623 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.
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, $allowothertags=array())
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, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.