29if (!$res && !empty($_SERVER[
"CONTEXT_DOCUMENT_ROOT"])) {
30 $res = @include $_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->fieldAttr[
'placeholder'] = (empty($_SERVER[
'HTTPS']) ?
'http://' :
'https://') . $_SERVER[
'HTTP_HOST'];
116$item->cssClass =
'minwidth500';
119$item = $formSetup->newItem(
'MYMODULE_MYPARAM2');
120$item->defaultFieldValue =
'default value';
121$item->fieldAttr[
'placeholder'] =
'A placeholder here';
124$item = $formSetup->newItem(
'MYMODULE_MYPARAM3');
125$item->nameText = $item->getNameText().
' more html text ';
128$item = $formSetup->newItem(
'MYMODULE_MYPARAM4');
129$item->setAsThirdpartyType();
132$formSetup->newItem(
'MYMODULE_MYPARAM5')->setAsYesNo();
135$formSetup->newItem(
'MYMODULE_MYPARAM6')->setAsEmailTemplate(
'thirdparty');
141$formSetup->newItem(
'MYMODULE_MYPARAM8')->setAsProduct();
144$formSetup->newItem(
'NewSection')->setAsTitle();
147 'test01' => $langs->trans(
'test01'),
148 'test02' => $langs->trans(
'test02'),
149 'test03' => $langs->trans(
'test03'),
150 'test04' => $langs->trans(
'test04'),
151 'test05' => $langs->trans(
'test05'),
152 'test06' => $langs->trans(
'test06'),
156$formSetup->newItem(
'MYMODULE_MYPARAM9')->setAsSelect($TField);
159$item = $formSetup->newItem(
'MYMODULE_MYPARAM10');
160$item->setAsMultiSelect($TField);
161$item->helpText = $langs->transnoentities(
'MYMODULE_MYPARAM10');
164$formSetup->newItem(
'MYMODULE_CATEGORY_ID_XXX')->setAsCategory(
'product');
167$item = $formSetup->newItem(
'MYMODULE_MYPARAM10');
169$item->defaultFieldValue =
'#FF0000';
176$item = $formSetup->newItem(
'MYMODULE_MYPARAM11')->setAsHtml();
177$item->nameText = $item->getNameText().
' more html text ';
178$item->fieldInputOverride =
'';
179$item->helpText = $langs->transnoentities(
'HelpMessage');
180$item->cssClass =
'minwidth500';
182$item = $formSetup->newItem(
'MYMODULE_MYPARAM12');
183$item->fieldOverride =
"Value forced, can't be modified";
184$item->cssClass =
'minwidth500';
191$setupnotempty += count($formSetup->items);
194$dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
196$moduledir =
'mymodule';
197$myTmpObjects = array();
199$myTmpObjects[
'myobject'] = array(
'label' =>
'MyObject',
'includerefgeneration' => 0,
'includedocgeneration' => 0,
'class' =>
'MyObject');
201$tmpobjectkey =
GETPOST(
'object',
'aZ09');
202if ($tmpobjectkey && !array_key_exists($tmpobjectkey, $myTmpObjects)) {
212if (
versioncompare(explode(
'.', DOL_VERSION), array(15)) < 0 && $action ==
'update' && !empty($user->admin)) {
213 $formSetup->saveConfFromPost();
216include DOL_DOCUMENT_ROOT.
'/core/actions_setmoduleoptions.inc.php';
218if ($action ==
'updateMask') {
219 $maskconst =
GETPOST(
'maskconst',
'aZ09');
220 $maskvalue =
GETPOST(
'maskvalue',
'alpha');
222 if ($maskconst && preg_match(
'/_MASK$/', $maskconst)) {
234} elseif ($action ==
'specimen' && $tmpobjectkey) {
235 $modele =
GETPOST(
'module',
'alpha');
237 $className = $myTmpObjects[$tmpobjectkey][
'class'];
238 $tmpobject =
new $className($db);
239 '@phan-var-force MyObject $tmpobject';
240 $tmpobject->initAsSpecimen();
245 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
246 foreach ($dirmodels as $reldir) {
247 $file =
dol_buildpath($reldir.
"core/modules/mymodule/doc/pdf_".$modele.
"_".strtolower($tmpobjectkey).
".modules.php", 0);
248 if (file_exists($file)) {
249 $className =
"pdf_".$modele.
"_".strtolower($tmpobjectkey);
254 if ($className !==
'') {
257 $module =
new $className($db);
258 '@phan-var-force ModelePDFMyObject $module';
260 '@phan-var-force ModelePDFMyObject $module';
262 if ($module->write_file($tmpobject, $langs) > 0) {
263 header(
"Location: ".DOL_URL_ROOT.
"/document.php?modulepart=mymodule-".strtolower($tmpobjectkey).
"&file=SPECIMEN.pdf");
271 dol_syslog($langs->trans(
"ErrorModuleNotFound"), LOG_ERR);
273} elseif ($action ==
'setmod') {
275 if (!empty($tmpobjectkey)) {
276 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
"_ADDON";
279} elseif ($action ==
'set') {
282} elseif ($action ==
'del') {
285 if (!empty($tmpobjectkey)) {
286 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
292} elseif ($action ==
'setdoc') {
294 if (!empty($tmpobjectkey)) {
295 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
299 $conf->global->{$constforval} = $value;
308} elseif ($action ==
'unsetdoc') {
309 if (!empty($tmpobjectkey)) {
310 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
322$form =
new Form($db);
325$title =
"MyModuleSetup";
327llxHeader(
'', $langs->trans($title), $help_url,
'', 0, 0,
'',
'',
'',
'mod-mymodule page-admin');
330$linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1').
'">'.$langs->trans(
"BackToModuleList").
'</a>';
336print
dol_get_fiche_head($head,
'settings', $langs->trans($title), -1,
"mymodule@mymodule");
339echo
'<span class="opacitymedium">'.$langs->trans(
"MyModuleSetupPage").
'</span><br><br>';
352if (!empty($formSetup->items)) {
353 print $formSetup->generateOutput(
true);
356 print
'<br>'.$langs->trans(
"NothingToSetup");
360foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
361 if (!empty($myTmpObjectArray[
'includerefgeneration'])) {
367 print
load_fiche_titre($langs->trans(
"NumberingModules", $myTmpObjectArray[
'label']),
'',
'');
369 print
'<table class="noborder centpercent">';
370 print
'<tr class="liste_titre">';
371 print
'<td>'.$langs->trans(
"Name").
'</td>';
372 print
'<td>'.$langs->trans(
"Description").
'</td>';
373 print
'<td class="nowrap">'.$langs->trans(
"Example").
'</td>';
374 print
'<td class="center" width="60">'.$langs->trans(
"Status").
'</td>';
375 print
'<td class="center" width="16">'.$langs->trans(
"ShortInfo").
'</td>';
380 foreach ($dirmodels as $reldir) {
384 $handle = opendir($dir);
385 if (is_resource($handle)) {
386 while (($file = readdir($handle)) !==
false) {
387 if (strpos($file,
'mod_'.strtolower($myTmpObjectKey).
'_') === 0 && substr($file,
dol_strlen($file) - 3, 3) ==
'php') {
388 $file = substr($file, 0,
dol_strlen($file) - 4);
390 require_once $dir.
'/'.$file.
'.php';
392 $module =
new $file($db);
393 '@phan-var-force ModeleNumRefMyObject $module';
396 if ($module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
399 if ($module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
403 if ($module->isEnabled()) {
404 dol_include_once(
'/'.$moduledir.
'/class/'.strtolower($myTmpObjectKey).
'.class.php');
406 print
'<tr class="oddeven"><td>'.$module->getName($langs).
"</td><td>\n";
407 print $module->info($langs);
411 print
'<td class="nowrap">';
412 $tmp = $module->getExample();
413 if (preg_match(
'/^Error/', $tmp)) {
414 $langs->load(
"errors");
415 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
416 } elseif ($tmp ==
'NotConfigured') {
417 print $langs->trans($tmp);
423 print
'<td class="center">';
424 $constforvar =
'MYMODULE_'.strtoupper($myTmpObjectKey).
'_ADDON';
426 print
img_picto($langs->trans(
"Activated"),
'switch_on');
428 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=setmod&token='.
newToken().
'&object='.strtolower($myTmpObjectKey).
'&value='.urlencode($file).
'">';
429 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
434 $className = $myTmpObjectArray[
'class'];
435 $mytmpinstance =
new $className($db);
436 '@phan-var-force MyObject $mytmpinstance';
437 $mytmpinstance->initAsSpecimen();
441 $htmltooltip .=
''.$langs->trans(
"Version").
': <b>'.$module->getVersion().
'</b><br>';
443 $nextval = $module->getNextValue($mytmpinstance);
444 if (
"$nextval" != $langs->trans(
"NotAvailable")) {
445 $htmltooltip .=
''.$langs->trans(
"NextValue").
': ';
447 if (preg_match(
'/^Error/', $nextval) || $nextval ==
'NotConfigured') {
448 $nextval = $langs->trans($nextval);
450 $htmltooltip .= $nextval.
'<br>';
452 $htmltooltip .= $langs->trans($module->error).
'<br>';
456 print
'<td class="center">';
457 print $form->textwithpicto(
'', $htmltooltip, 1, 0);
468 print
"</table><br>\n";
471 if (!empty($myTmpObjectArray[
'includedocgeneration'])) {
476 $type = strtolower($myTmpObjectKey);
478 print
load_fiche_titre($langs->trans(
"DocumentModules", $myTmpObjectKey),
'',
'');
483 $sql .=
" FROM ".MAIN_DB_PREFIX.
"document_model";
484 $sql .=
" WHERE type = '".$db->escape($type).
"'";
485 $sql .=
" AND entity = ".$conf->entity;
486 $resql = $db->query($sql);
489 $num_rows = $db->num_rows($resql);
490 while ($i < $num_rows) {
491 $array = $db->fetch_array($resql);
492 array_push($def, $array[0]);
499 print
'<table class="noborder centpercent">'.
"\n";
500 print
'<tr class="liste_titre">'.
"\n";
501 print
'<td>'.$langs->trans(
"Name").
'</td>';
502 print
'<td>'.$langs->trans(
"Description").
'</td>';
503 print
'<td class="center" width="60">'.$langs->trans(
"Status").
"</td>\n";
504 print
'<td class="center" width="60">'.$langs->trans(
"Default").
"</td>\n";
505 print
'<td class="center" width="38">'.$langs->trans(
"ShortInfo").
'</td>';
506 print
'<td class="center" width="38">'.$langs->trans(
"Preview").
'</td>';
511 foreach ($dirmodels as $reldir) {
512 foreach (array(
'',
'/doc') as $valdir) {
513 $realpath = $reldir.
"core/modules/".$moduledir.$valdir;
517 $handle = opendir($dir);
518 if (is_resource($handle)) {
520 while (($file = readdir($handle)) !==
false) {
526 foreach ($filelist as $file) {
527 if (preg_match(
'/\.modules\.php$/i', $file) && preg_match(
'/^(pdf_|doc_)/', $file)) {
528 if (file_exists($dir.
'/'.$file)) {
529 $name = substr($file, 4,
dol_strlen($file) - 16);
530 $className = substr($file, 0,
dol_strlen($file) - 12);
532 require_once $dir.
'/'.$file;
533 $module =
new $className($db);
534 '@phan-var-force ModelePDFMyObject $module';
536 $modulequalified = 1;
537 if ($module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
538 $modulequalified = 0;
540 if ($module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
541 $modulequalified = 0;
544 if ($modulequalified) {
545 print
'<tr class="oddeven"><td width="100">';
546 print(empty($module->name) ? $name : $module->
name);
548 if (method_exists($module,
'info')) {
549 print $module->info($langs);
551 print $module->description;
556 if (in_array($name, $def)) {
557 print
'<td class="center">'.
"\n";
558 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=del&token='.
newToken().
'&value='.urlencode($name).
'">';
559 print
img_picto($langs->trans(
"Enabled"),
'switch_on');
563 print
'<td class="center">'.
"\n";
564 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>';
569 print
'<td class="center">';
570 $constforvar =
'MYMODULE_'.strtoupper($myTmpObjectKey).
'_ADDON_PDF';
574 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>';
576 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>';
581 $htmltooltip =
''.$langs->trans(
"Name").
': '.$module->name;
582 $htmltooltip .=
'<br>'.$langs->trans(
"Type").
': '.($module->type ? $module->type : $langs->trans(
"Unknown"));
583 if ($module->type ==
'pdf') {
584 $htmltooltip .=
'<br>'.$langs->trans(
"Width").
'/'.$langs->trans(
"Height").
': '.$module->page_largeur.
'/'.$module->page_hauteur;
586 $htmltooltip .=
'<br>'.$langs->trans(
"Path").
': '.preg_replace(
'/^\//',
'', $realpath).
'/'.$file;
588 $htmltooltip .=
'<br><br><u>'.$langs->trans(
"FeaturesSupported").
':</u>';
589 $htmltooltip .=
'<br>'.$langs->trans(
"Logo").
': '.
yn($module->option_logo, 1, 1);
590 $htmltooltip .=
'<br>'.$langs->trans(
"MultiLanguage").
': '.
yn($module->option_multilang, 1, 1);
592 print
'<td class="center">';
593 print $form->textwithpicto(
'', $htmltooltip, 1, 0);
597 print
'<td class="center">';
598 if ($module->type ==
'pdf') {
599 $newname = preg_replace(
'/_'.preg_quote(strtolower($myTmpObjectKey),
'/').
'/',
'', $name);
600 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=specimen&module='.urlencode($newname).
'&object='.urlencode($myTmpObjectKey).
'">'.
img_object($langs->trans(
"Preview"),
'pdf').
'</a>';
602 print
img_object($langs->trans(
"PreviewNotAvailable"),
'generic');
620if (empty($setupnotempty)) {
621 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.