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';
108$item = $formSetup->newItem(
'MYMODULE_MYPARAM1');
109$item->fieldParams[
'isMandatory'] = 1;
110$item->fieldAttr[
'placeholder'] = (empty($_SERVER[
'HTTPS']) ?
'http://' :
'https://') . $_SERVER[
'HTTP_HOST'];
111$item->cssClass =
'minwidth500';
114$item = $formSetup->newItem(
'MYMODULE_MYPARAM2');
115$item->defaultFieldValue =
'default value';
116$item->fieldAttr[
'placeholder'] =
'A placeholder here';
117$item->helpText =
'Tooltip text';
120$item = $formSetup->newItem(
'MYMODULE_MYPARAM3');
121$item->nameText = $item->getNameText().
' more html text ';
124$item = $formSetup->newItem(
'MYMODULE_MYPARAM4');
125$item->setAsThirdpartyType();
128$formSetup->newItem(
'MYMODULE_MYPARAM5')->setAsYesNo();
131$formSetup->newItem(
'MYMODULE_MYPARAM6')->setAsEmailTemplate(
'thirdparty');
137$formSetup->newItem(
'MYMODULE_MYPARAM8')->setAsProduct();
140$formSetup->newItem(
'NewSection')->setAsTitle();
143 'test01' => $langs->trans(
'test01'),
144 'test02' => $langs->trans(
'test02'),
145 'test03' => $langs->trans(
'test03'),
146 'test04' => $langs->trans(
'test04'),
147 'test05' => $langs->trans(
'test05'),
148 'test06' => $langs->trans(
'test06'),
152$formSetup->newItem(
'MYMODULE_MYPARAM9')->setAsSelect($TField);
155$item = $formSetup->newItem(
'MYMODULE_MYPARAM10');
156$item->setAsMultiSelect($TField);
157$item->helpText = $langs->transnoentities(
'MYMODULE_MYPARAM10');
160$formSetup->newItem(
'MYMODULE_CATEGORY_ID_XXX')->setAsCategory(
'product');
163$item = $formSetup->newItem(
'MYMODULE_MYPARAM10');
165$item->defaultFieldValue =
'#FF0000';
172$item = $formSetup->newItem(
'MYMODULE_MYPARAM11')->setAsHtml();
173$item->nameText = $item->getNameText().
' more html text ';
174$item->fieldInputOverride =
'';
175$item->helpText = $langs->transnoentities(
'HelpMessage');
176$item->cssClass =
'minwidth500';
178$item = $formSetup->newItem(
'MYMODULE_MYPARAM12');
179$item->fieldOverride =
"Value forced, can't be modified";
180$item->cssClass =
'minwidth500';
187$setupnotempty += count($formSetup->items);
190$dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
192$moduledir =
'mymodule';
193$myTmpObjects = array();
195$myTmpObjects[
'myobject'] = array(
'label' =>
'MyObject',
'includerefgeneration' => 0,
'includedocgeneration' => 0,
'class' =>
'MyObject');
197$tmpobjectkey =
GETPOST(
'object',
'aZ09');
198if ($tmpobjectkey && !array_key_exists($tmpobjectkey, $myTmpObjects)) {
208if (
versioncompare(explode(
'.', DOL_VERSION), array(15)) < 0 && $action ==
'update' && !empty($user->admin)) {
209 $formSetup->saveConfFromPost();
212include DOL_DOCUMENT_ROOT.
'/core/actions_setmoduleoptions.inc.php';
214if ($action ==
'updateMask') {
215 $maskconst =
GETPOST(
'maskconst',
'aZ09');
216 $maskvalue =
GETPOST(
'maskvalue',
'alpha');
218 if ($maskconst && preg_match(
'/_MASK$/', $maskconst)) {
230} elseif ($action ==
'specimen' && $tmpobjectkey) {
231 $modele =
GETPOST(
'module',
'alpha');
233 $className = $myTmpObjects[$tmpobjectkey][
'class'];
234 $tmpobject =
new $className(
$db);
235 '@phan-var-force MyObject $tmpobject';
236 $tmpobject->initAsSpecimen();
241 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
242 foreach ($dirmodels as $reldir) {
243 $file =
dol_buildpath($reldir.
"core/modules/mymodule/doc/pdf_".$modele.
"_".strtolower($tmpobjectkey).
".modules.php", 0);
244 if (file_exists($file)) {
245 $className =
"pdf_".$modele.
"_".strtolower($tmpobjectkey);
250 if ($className !==
'') {
253 $module =
new $className(
$db);
254 '@phan-var-force ModelePDFMyObject $module';
256 '@phan-var-force ModelePDFMyObject $module';
258 if ($module->write_file($tmpobject, $langs) > 0) {
259 header(
"Location: ".DOL_URL_ROOT.
"/document.php?modulepart=mymodule-".strtolower($tmpobjectkey).
"&file=SPECIMEN.pdf");
267 dol_syslog($langs->trans(
"ErrorModuleNotFound"), LOG_ERR);
269} elseif ($action ==
'setmod') {
271 if (!empty($tmpobjectkey)) {
272 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
"_ADDON";
275} elseif ($action ==
'set') {
278} elseif ($action ==
'del') {
281 if (!empty($tmpobjectkey)) {
282 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
288} elseif ($action ==
'setdoc') {
290 if (!empty($tmpobjectkey)) {
291 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
295 $conf->global->{$constforval} = $value;
304} elseif ($action ==
'unsetdoc') {
305 if (!empty($tmpobjectkey)) {
306 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
321$title =
"MyModuleSetup";
323llxHeader(
'', $langs->trans($title), $help_url,
'', 0, 0,
'',
'',
'',
'mod-mymodule page-admin');
326$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>';
332print
dol_get_fiche_head($head,
'settings', $langs->trans($title), -1,
"mymodule@mymodule");
335echo
'<span class="opacitymedium">'.$langs->trans(
"MyModuleSetupPage").
'</span><br><br>';
348if (!empty($formSetup->items)) {
349 print $formSetup->generateOutput(
true);
354$refGenerationObjects = array();
355$docGenerationObjects = array();
357foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
358 if (!empty($myTmpObjectArray[
'includerefgeneration'])) {
359 $refGenerationObjects[$myTmpObjectKey] = $myTmpObjectArray;
362 if (!empty($myTmpObjectArray[
'includedocgeneration'])) {
363 $docGenerationObjects[$myTmpObjectKey] = $myTmpObjectArray;
368if (!empty($refGenerationObjects)) {
373 print
'<table class="noborder centpercent">';
374 print
'<tr class="liste_titre">';
375 print
'<td>'.$langs->trans(
"Name").
'</td>';
376 print
'<td>'.$langs->trans(
"Description").
'</td>';
377 print
'<td class="nowrap">'.$langs->trans(
"Example").
'</td>';
378 print
'<td class="center" width="60">'.$langs->trans(
"Status").
'</td>';
379 print
'<td class="center" width="16">'.$langs->trans(
"ShortInfo").
'</td>';
384 foreach ($refGenerationObjects as $myTmpObjectKey => $myTmpObjectArray) {
385 if (empty($myTmpObjectArray[
'includerefgeneration'])) {
389 print
'<tr class="liste_titre">';
390 print
'<td colspan="5"><strong>'.$langs->trans($myTmpObjectArray[
'label']).
'</strong></td>';
393 foreach ($dirmodels as $reldir) {
400 $handle = opendir($dir);
401 if (!is_resource($handle)) {
405 while (($file = readdir($handle)) !==
false) {
406 if (strpos($file,
'mod_'.strtolower($myTmpObjectKey).
'_') !== 0 || substr($file,
dol_strlen($file) - 3, 3) !=
'php') {
410 $file = substr($file, 0,
dol_strlen($file) - 4);
412 require_once $dir.
'/'.$file.
'.php';
414 $module =
new $file(
$db);
415 '@phan-var-force ModeleNumRefMyObject $module';
417 if ($module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
420 if ($module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
423 if (!$module->isEnabled()) {
427 dol_include_once(
'/'.$moduledir.
'/class/'.strtolower($myTmpObjectKey).
'.class.php');
429 print
'<tr class="oddeven"><td>'.$module->getName($langs).
"</td><td>\n";
430 print $module->info($langs);
433 print
'<td class="nowrap">';
434 $tmp = $module->getExample();
435 if (preg_match(
'/^Error/', $tmp)) {
436 $langs->load(
"errors");
437 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
438 } elseif ($tmp ==
'NotConfigured') {
439 print $langs->trans($tmp);
445 print
'<td class="center">';
446 $constforvar =
'MYMODULE_'.strtoupper($myTmpObjectKey).
'_ADDON';
447 $defaultifnotset =
'thevaluetousebydefault';
450 if ($activenumberingmodel == $file) {
451 print
img_picto($langs->trans(
"Activated"),
'switch_on');
453 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=setmod&token='.newToken().
'&object='.urlencode(strtolower($myTmpObjectKey)).
'&value='.urlencode($file).
'">';
454 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
459 $className = $myTmpObjectArray[
'class'];
460 $mytmpinstance =
new $className(
$db);
461 '@phan-var-force MyObject $mytmpinstance';
462 $mytmpinstance->initAsSpecimen();
465 $htmltooltip .=
''.$langs->trans(
"Version").
': <b>'.$module->getVersion().
'</b><br>';
467 $nextval = $module->getNextValue($mytmpinstance);
468 if (
"$nextval" != $langs->trans(
"NotAvailable")) {
469 $htmltooltip .=
''.$langs->trans(
"NextValue").
': ';
471 if (preg_match(
'/^Error/', $nextval) || $nextval ==
'NotConfigured') {
472 $nextval = $langs->trans($nextval);
474 $htmltooltip .= $nextval.
'<br>';
476 $htmltooltip .= $langs->trans($module->error).
'<br>';
480 print
'<td class="center">';
481 print $form->textwithpicto(
'', $htmltooltip, 1,
'info');
490 print
'<tr><td colspan="5"><br></td></tr>'.
"\n";
493 print
"</table><br>\n";
497if (!empty($docGenerationObjects)) {
502 print
'<table class="noborder centpercent">'.
"\n";
503 print
'<tr class="liste_titre">'.
"\n";
504 print
'<td>'.$langs->trans(
"Name").
'</td>';
505 print
'<td>'.$langs->trans(
"Description").
'</td>';
506 print
'<td class="center" width="60">'.$langs->trans(
"Status").
"</td>\n";
507 print
'<td class="center" width="60">'.$langs->trans(
"Default").
"</td>\n";
508 print
'<td class="center" width="38">'.$langs->trans(
"ShortInfo").
'</td>';
509 print
'<td class="center" width="38">'.$langs->trans(
"Preview").
'</td>';
514 foreach ($docGenerationObjects as $myTmpObjectKey => $myTmpObjectArray) {
515 if (empty($myTmpObjectArray[
'includedocgeneration'])) {
519 $type = strtolower($myTmpObjectKey);
521 print
'<tr class="liste_titre">';
522 print
'<td colspan="6"><strong>'.$langs->trans($myTmpObjectArray[
'label']).
'</strong></td>';
528 $sql .=
" FROM ".$db->prefix().
"document_model";
529 $sql .=
" WHERE type = '".$db->escape($type).
"'";
530 $sql .=
" AND entity = ".$conf->entity;
532 $resql =
$db->query($sql);
535 $num_rows =
$db->num_rows($resql);
536 while ($i < $num_rows) {
537 $array =
$db->fetch_array($resql);
538 array_push($def, $array[0]);
545 foreach ($dirmodels as $reldir) {
546 foreach (array(
'',
'/doc') as $valdir) {
547 $realpath = $reldir.
"core/modules/".$moduledir.$valdir;
554 $handle = opendir($dir);
555 if (!is_resource($handle)) {
561 while (($file = readdir($handle)) !==
false) {
568 foreach ($filelist as $file) {
569 if (!preg_match(
'/\.modules\.php$/i', $file) || !preg_match(
'/^(pdf_|doc_)/', $file)) {
573 if (!preg_match(
'/_'.preg_quote($type,
'/').
'(_odt)?\.modules\.php$/i', $file)) {
577 if (!file_exists($dir.
'/'.$file)) {
581 $name = substr($file, 4,
dol_strlen($file) - 16);
582 $className = substr($file, 0,
dol_strlen($file) - 12);
584 require_once $dir.
'/'.$file;
586 $module =
new $className(
$db);
587 '@phan-var-force ModelePDFMyObject $module';
589 $modulequalified = 1;
590 if ($module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
591 $modulequalified = 0;
593 if ($module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
594 $modulequalified = 0;
597 if (!$modulequalified) {
601 print
'<tr class="oddeven"><td width="100">';
602 print(empty($module->name) ? $name : $module->
name);
605 if (method_exists($module,
'info')) {
606 print $module->info($langs);
608 print $module->description;
613 if (in_array($name, $def)) {
614 print
'<td class="center">'.
"\n";
615 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=del&token='.newToken().
'&object='.urlencode($type).
'&value='.urlencode($name).
'&type='.urlencode($type).
'">';
616 print
img_picto($langs->trans(
"Enabled"),
'switch_on');
620 print
'<td class="center">'.
"\n";
621 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).
'">';
622 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
627 print
'<td class="center">';
628 $constforvar =
'MYMODULE_'.strtoupper($myTmpObjectKey).
'_ADDON_PDF';
631 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").
'">';
632 print
img_picto($langs->trans(
"Enabled"),
'on');
635 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").
'">';
636 print
img_picto($langs->trans(
"Disabled"),
'off');
642 $htmltooltip =
''.$langs->trans(
"Name").
': '.$module->name;
643 $htmltooltip .=
'<br>'.$langs->trans(
"Type").
': '.($module->type ? $module->type : $langs->trans(
"Unknown"));
645 if ($module->type ==
'pdf') {
646 $htmltooltip .=
'<br>'.$langs->trans(
"Width").
'/'.$langs->trans(
"Height").
': '.$module->page_largeur.
'/'.$module->page_hauteur;
649 $htmltooltip .=
'<br>'.$langs->trans(
"Path").
': '.preg_replace(
'/^\//',
'', $realpath).
'/'.$file;
650 $htmltooltip .=
'<br><br><u>'.$langs->trans(
"FeaturesSupported").
':</u>';
651 $htmltooltip .=
'<br>'.$langs->trans(
"Logo").
': '.
yn($module->option_logo, 1, 1);
652 $htmltooltip .=
'<br>'.$langs->trans(
"MultiLanguage").
': '.
yn($module->option_multilang, 1, 1);
654 print
'<td class="center">';
655 print $form->textwithpicto(
'', $htmltooltip, 1,
'info');
658 print
'<td class="center">';
659 if ($module->type ==
'pdf') {
660 $newname = preg_replace(
'/_'.preg_quote($type,
'/').
'/',
'', $name);
661 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=specimen&module='.urlencode($newname).
'&object='.urlencode($type).
'">';
662 print
img_object($langs->trans(
"Preview"),
'pdf');
665 print
img_object($langs->transnoentitiesnoconv(
"PreviewNotAvailable"),
'generic');
674 print
'<tr><td colspan="6"><br></td></tr>'.
"\n";
680if (empty($setupnotempty)) {
681 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.
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.