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']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
33while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
37if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)).
"/main.inc.php")) {
38 $res = @include substr($tmp, 0, ($i + 1)).
"/main.inc.php";
40if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))).
"/main.inc.php")) {
41 $res = @include dirname(substr($tmp, 0, ($i + 1))).
"/main.inc.php";
44if (!$res && file_exists(
"../../main.inc.php")) {
45 $res = @include
"../../main.inc.php";
47if (!$res && file_exists(
"../../../main.inc.php")) {
48 $res = @include
"../../../main.inc.php";
51 die(
"Include of main fails");
57require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
58require_once
'../lib/mymodule.lib.php';
62$langs->loadLangs(array(
"admin",
"mymodule@mymodule"));
65$hookmanager->initHooks(array(
'mymodulesetup',
'globalsetup'));
68$action =
GETPOST(
'action',
'aZ09');
69$backtopage =
GETPOST(
'backtopage',
'alpha');
70$modulepart =
GETPOST(
'modulepart',
'aZ09');
72$value =
GETPOST(
'value',
'alpha');
73$label =
GETPOST(
'label',
'alpha');
74$scandir =
GETPOST(
'scan_dir',
'alpha');
89if (!class_exists(
'FormSetup')) {
90 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formsetup.class.php';
103$item = $formSetup->newItem(
'MYMODULE_MYPARAM1');
104$item->fieldOverride = (empty($_SERVER[
'HTTPS']) ?
'http://' :
'https://') . $_SERVER[
'HTTP_HOST'];
105$item->cssClass =
'minwidth500';
108$item = $formSetup->newItem(
'MYMODULE_MYPARAM2');
109$item->defaultFieldValue =
'default value';
110$item->fieldAttr[
'placeholder'] =
'A placeholder here';
113$item = $formSetup->newItem(
'MYMODULE_MYPARAM3');
114$item->nameText = $item->getNameText().
' more html text ';
117$item = $formSetup->newItem(
'MYMODULE_MYPARAM4');
118$item->setAsThirdpartyType();
121$formSetup->newItem(
'MYMODULE_MYPARAM5')->setAsYesNo();
124$formSetup->newItem(
'MYMODULE_MYPARAM6')->setAsEmailTemplate(
'thirdparty');
130$formSetup->newItem(
'MYMODULE_MYPARAM8')->setAsProduct();
133$formSetup->newItem(
'NewSection')->setAsTitle();
136 'test01' => $langs->trans(
'test01'),
137 'test02' => $langs->trans(
'test02'),
138 'test03' => $langs->trans(
'test03'),
139 'test04' => $langs->trans(
'test04'),
140 'test05' => $langs->trans(
'test05'),
141 'test06' => $langs->trans(
'test06'),
145$formSetup->newItem(
'MYMODULE_MYPARAM9')->setAsSelect($TField);
148$item = $formSetup->newItem(
'MYMODULE_MYPARAM10');
149$item->setAsMultiSelect($TField);
150$item->helpText = $langs->transnoentities(
'MYMODULE_MYPARAM10');
153$formSetup->newItem(
'MYMODULE_CATEGORY_ID_XXX')->setAsCategory(
'product');
156$item = $formSetup->newItem(
'MYMODULE_MYPARAM10');
158$item->defaultFieldValue =
'#FF0000';
159$item->nameText = $item->getNameText().
' more html text ';
160$item->fieldInputOverride =
'';
161$item->helpText = $langs->transnoentities(
'AnHelpMessage');
169$setupnotempty += count($formSetup->items);
172$dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
174$moduledir =
'mymodule';
175$myTmpObjects = array();
177$myTmpObjects[
'myobject'] = array(
'label'=>
'MyObject',
'includerefgeneration'=>0,
'includedocgeneration'=>0,
'class'=>
'MyObject');
179$tmpobjectkey =
GETPOST(
'object',
'aZ09');
180if ($tmpobjectkey && !array_key_exists($tmpobjectkey, $myTmpObjects)) {
190if (
versioncompare(explode(
'.', DOL_VERSION), array(15)) < 0 && $action ==
'update' && !empty($user->admin)) {
191 $formSetup->saveConfFromPost();
194include DOL_DOCUMENT_ROOT.
'/core/actions_setmoduleoptions.inc.php';
196if ($action ==
'updateMask') {
197 $maskconst =
GETPOST(
'maskconst',
'aZ09');
198 $maskvalue =
GETPOST(
'maskvalue',
'alpha');
200 if ($maskconst && preg_match(
'/_MASK$/', $maskconst)) {
201 $res =
dolibarr_set_const($db, $maskconst, $maskvalue,
'chaine', 0,
'', $conf->entity);
212} elseif ($action ==
'specimen' && $tmpobjectkey) {
213 $modele =
GETPOST(
'module',
'alpha');
215 $className = $myTmpObjects[$tmpobjectkey][
'class'];
216 $tmpobject =
new $className($db);
217 $tmpobject->initAsSpecimen();
223 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
224 foreach ($dirmodels as $reldir) {
225 $file =
dol_buildpath($reldir.
"core/modules/mymodule/doc/pdf_".$modele.
"_".strtolower($tmpobjectkey).
".modules.php", 0);
226 if (file_exists($file)) {
228 $className =
"pdf_".$modele.
"_".strtolower($tmpobjectkey);
236 $module =
new $className($db);
238 if ($module->write_file($tmpobject, $langs) > 0) {
239 header(
"Location: ".DOL_URL_ROOT.
"/document.php?modulepart=mymodule-".strtolower($tmpobjectkey).
"&file=SPECIMEN.pdf");
247 dol_syslog($langs->trans(
"ErrorModuleNotFound"), LOG_ERR);
249} elseif ($action ==
'setmod') {
251 if (!empty($tmpobjectkey)) {
252 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
"_ADDON";
255} elseif ($action ==
'set') {
258} elseif ($action ==
'del') {
261 if (!empty($tmpobjectkey)) {
262 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
268} elseif ($action ==
'setdoc') {
270 if (!empty($tmpobjectkey)) {
271 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
275 $conf->global->{$constforval} = $value;
284} elseif ($action ==
'unsetdoc') {
285 if (!empty($tmpobjectkey)) {
286 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
298$form =
new Form($db);
301$title =
"MyModuleSetup";
303llxHeader(
'', $langs->trans($title), $help_url,
'', 0, 0,
'',
'',
'',
'mod-mymodule page-admin');
306$linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1').
'">'.$langs->trans(
"BackToModuleList").
'</a>';
312print
dol_get_fiche_head($head,
'settings', $langs->trans($title), -1,
"mymodule@mymodule");
315echo
'<span class="opacitymedium">'.$langs->trans(
"MyModuleSetupPage").
'</span><br><br>';
328if (!empty($formSetup->items)) {
329 print $formSetup->generateOutput(
true);
332 print
'<br>'.$langs->trans(
"NothingToSetup");
336foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
337 if (!empty($myTmpObjectArray[
'includerefgeneration'])) {
343 print
load_fiche_titre($langs->trans(
"NumberingModules", $myTmpObjectArray[
'label']),
'',
'');
345 print
'<table class="noborder centpercent">';
346 print
'<tr class="liste_titre">';
347 print
'<td>'.$langs->trans(
"Name").
'</td>';
348 print
'<td>'.$langs->trans(
"Description").
'</td>';
349 print
'<td class="nowrap">'.$langs->trans(
"Example").
'</td>';
350 print
'<td class="center" width="60">'.$langs->trans(
"Status").
'</td>';
351 print
'<td class="center" width="16">'.$langs->trans(
"ShortInfo").
'</td>';
356 foreach ($dirmodels as $reldir) {
360 $handle = opendir($dir);
361 if (is_resource($handle)) {
362 while (($file = readdir($handle)) !==
false) {
363 if (strpos($file,
'mod_'.strtolower($myTmpObjectKey).
'_') === 0 && substr($file,
dol_strlen($file) - 3, 3) ==
'php') {
364 $file = substr($file, 0,
dol_strlen($file) - 4);
366 require_once $dir.
'/'.$file.
'.php';
368 $module =
new $file($db);
371 if ($module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
374 if ($module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
378 if ($module->isEnabled()) {
379 dol_include_once(
'/'.$moduledir.
'/class/'.strtolower($myTmpObjectKey).
'.class.php');
381 print
'<tr class="oddeven"><td>'.$module->name.
"</td><td>\n";
382 print $module->info($langs);
386 print
'<td class="nowrap">';
387 $tmp = $module->getExample();
388 if (preg_match(
'/^Error/', $tmp)) {
389 $langs->load(
"errors");
390 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
391 } elseif ($tmp ==
'NotConfigured') {
392 print $langs->trans($tmp);
398 print
'<td class="center">';
399 $constforvar =
'MYMODULE_'.strtoupper($myTmpObjectKey).
'_ADDON';
401 print
img_picto($langs->trans(
"Activated"),
'switch_on');
403 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=setmod&token='.
newToken().
'&object='.strtolower($myTmpObjectKey).
'&value='.urlencode($file).
'">';
404 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
409 $className = $myTmpObjectArray[
'class'];
410 $mytmpinstance =
new $className($db);
411 $mytmpinstance->initAsSpecimen();
415 $htmltooltip .=
''.$langs->trans(
"Version").
': <b>'.$module->getVersion().
'</b><br>';
417 $nextval = $module->getNextValue($mytmpinstance);
418 if (
"$nextval" != $langs->trans(
"NotAvailable")) {
419 $htmltooltip .=
''.$langs->trans(
"NextValue").
': ';
421 if (preg_match(
'/^Error/', $nextval) || $nextval ==
'NotConfigured') {
422 $nextval = $langs->trans($nextval);
424 $htmltooltip .= $nextval.
'<br>';
426 $htmltooltip .= $langs->trans($module->error).
'<br>';
430 print
'<td class="center">';
431 print $form->textwithpicto(
'', $htmltooltip, 1, 0);
442 print
"</table><br>\n";
445 if (!empty($myTmpObjectArray[
'includedocgeneration'])) {
450 $type = strtolower($myTmpObjectKey);
452 print
load_fiche_titre($langs->trans(
"DocumentModules", $myTmpObjectKey),
'',
'');
457 $sql .=
" FROM ".MAIN_DB_PREFIX.
"document_model";
458 $sql .=
" WHERE type = '".$db->escape($type).
"'";
459 $sql .=
" AND entity = ".$conf->entity;
460 $resql = $db->query($sql);
463 $num_rows = $db->num_rows($resql);
464 while ($i < $num_rows) {
465 $array = $db->fetch_array($resql);
466 array_push($def, $array[0]);
473 print
'<table class="noborder centpercent">'.
"\n";
474 print
'<tr class="liste_titre">'.
"\n";
475 print
'<td>'.$langs->trans(
"Name").
'</td>';
476 print
'<td>'.$langs->trans(
"Description").
'</td>';
477 print
'<td class="center" width="60">'.$langs->trans(
"Status").
"</td>\n";
478 print
'<td class="center" width="60">'.$langs->trans(
"Default").
"</td>\n";
479 print
'<td class="center" width="38">'.$langs->trans(
"ShortInfo").
'</td>';
480 print
'<td class="center" width="38">'.$langs->trans(
"Preview").
'</td>';
485 foreach ($dirmodels as $reldir) {
486 foreach (array(
'',
'/doc') as $valdir) {
487 $realpath = $reldir.
"core/modules/".$moduledir.$valdir;
491 $handle = opendir($dir);
492 if (is_resource($handle)) {
493 while (($file = readdir($handle)) !==
false) {
499 foreach ($filelist as $file) {
500 if (preg_match(
'/\.modules\.php$/i', $file) && preg_match(
'/^(pdf_|doc_)/', $file)) {
501 if (file_exists($dir.
'/'.$file)) {
502 $name = substr($file, 4,
dol_strlen($file) - 16);
503 $className = substr($file, 0,
dol_strlen($file) - 12);
505 require_once $dir.
'/'.$file;
506 $module =
new $className($db);
508 $modulequalified = 1;
509 if ($module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
510 $modulequalified = 0;
512 if ($module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
513 $modulequalified = 0;
516 if ($modulequalified) {
517 print
'<tr class="oddeven"><td width="100">';
518 print(empty($module->name) ? $name : $module->
name);
520 if (method_exists($module,
'info')) {
521 print $module->info($langs);
523 print $module->description;
528 if (in_array($name, $def)) {
529 print
'<td class="center">'.
"\n";
530 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=del&token='.
newToken().
'&value='.urlencode($name).
'">';
531 print
img_picto($langs->trans(
"Enabled"),
'switch_on');
535 print
'<td class="center">'.
"\n";
536 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>';
541 print
'<td class="center">';
542 $constforvar =
'MYMODULE_'.strtoupper($myTmpObjectKey).
'_ADDON_PDF';
546 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>';
548 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>';
553 $htmltooltip =
''.$langs->trans(
"Name").
': '.$module->name;
554 $htmltooltip .=
'<br>'.$langs->trans(
"Type").
': '.($module->type ? $module->type : $langs->trans(
"Unknown"));
555 if ($module->type ==
'pdf') {
556 $htmltooltip .=
'<br>'.$langs->trans(
"Width").
'/'.$langs->trans(
"Height").
': '.$module->page_largeur.
'/'.$module->page_hauteur;
558 $htmltooltip .=
'<br>'.$langs->trans(
"Path").
': '.preg_replace(
'/^\//',
'', $realpath).
'/'.$file;
560 $htmltooltip .=
'<br><br><u>'.$langs->trans(
"FeaturesSupported").
':</u>';
561 $htmltooltip .=
'<br>'.$langs->trans(
"Logo").
': '.
yn($module->option_logo, 1, 1);
562 $htmltooltip .=
'<br>'.$langs->trans(
"MultiLanguage").
': '.
yn($module->option_multilang, 1, 1);
564 print
'<td class="center">';
565 print $form->textwithpicto(
'', $htmltooltip, 1, 0);
569 print
'<td class="center">';
570 if ($module->type ==
'pdf') {
571 $newname = preg_replace(
'/_'.preg_quote(strtolower($myTmpObjectKey),
'/').
'/',
'', $name);
572 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=specimen&module='.urlencode($newname).
'&object='.urlencode($myTmpObjectKey).
'">'.
img_object($langs->trans(
"Preview"),
'pdf').
'</a>';
574 print
img_object($langs->trans(
"PreviewNotAvailable"),
'generic');
592if (empty($setupnotempty)) {
593 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()
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)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
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'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 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.