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'));
73$action =
GETPOST(
'action',
'aZ09');
74$backtopage =
GETPOST(
'backtopage',
'alpha');
75$modulepart =
GETPOST(
'modulepart',
'aZ09');
77$value =
GETPOST(
'value',
'alpha');
78$label =
GETPOST(
'label',
'alpha');
79$scandir =
GETPOST(
'scan_dir',
'alpha');
89if (!class_exists(
'FormSetup')) {
90 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formsetup.class.php';
98$item = $formSetup->newItem(
'MYMODULE_MYPARAM1');
99$item->fieldOverride = (empty($_SERVER[
'HTTPS']) ?
'http://' :
'https://') . $_SERVER[
'HTTP_HOST'];
100$item->cssClass =
'minwidth500';
103$item = $formSetup->newItem(
'MYMODULE_MYPARAM2');
104$item->defaultFieldValue =
'default value';
107$item = $formSetup->newItem(
'MYMODULE_MYPARAM3');
108$item->nameText = $item->getNameText().
' more html text ';
111$item = $formSetup->newItem(
'MYMODULE_MYPARAM4');
112$item->setAsThirdpartyType();
115$formSetup->newItem(
'MYMODULE_MYPARAM5')->setAsYesNo();
118$formSetup->newItem(
'MYMODULE_MYPARAM6')->setAsEmailTemplate(
'thirdparty');
124$formSetup->newItem(
'MYMODULE_MYPARAM8')->setAsProduct();
127$formSetup->newItem(
'NewSection')->setAsTitle();
130 'test01' => $langs->trans(
'test01'),
131 'test02' => $langs->trans(
'test02'),
132 'test03' => $langs->trans(
'test03'),
133 'test04' => $langs->trans(
'test04'),
134 'test05' => $langs->trans(
'test05'),
135 'test06' => $langs->trans(
'test06'),
139$formSetup->newItem(
'MYMODULE_MYPARAM9')->setAsSelect($TField);
142$item = $formSetup->newItem(
'MYMODULE_MYPARAM10');
143$item->setAsMultiSelect($TField);
144$item->helpText = $langs->transnoentities(
'MYMODULE_MYPARAM10');
149$item = $formSetup->newItem(
'MYMODULE_MYPARAM10');
151$item->defaultFieldValue =
'#FF0000';
152$item->nameText = $item->getNameText().
' more html text ';
153$item->fieldInputOverride =
'';
154$item->helpText = $langs->transnoentities(
'AnHelpMessage');
162$setupnotempty += count($formSetup->items);
165$dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
173if (
versioncompare(explode(
'.', DOL_VERSION), array(15)) < 0 && $action ==
'update' && !empty($user->admin)) {
174 $formSetup->saveConfFromPost();
177include DOL_DOCUMENT_ROOT.
'/core/actions_setmoduleoptions.inc.php';
179if ($action ==
'updateMask') {
180 $maskconst =
GETPOST(
'maskconst',
'aZ09');
181 $maskvalue =
GETPOST(
'maskvalue',
'alpha');
183 if ($maskconst && preg_match(
'/_MASK$/', $maskconst)) {
184 $res =
dolibarr_set_const($db, $maskconst, $maskvalue,
'chaine', 0,
'', $conf->entity);
195} elseif ($action ==
'specimen') {
196 $modele =
GETPOST(
'module',
'alpha');
197 $tmpobjectkey =
GETPOST(
'object');
199 $tmpobject =
new $tmpobjectkey($db);
200 $tmpobject->initAsSpecimen();
206 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
207 foreach ($dirmodels as $reldir) {
208 $file =
dol_buildpath($reldir.
"core/modules/mymodule/doc/pdf_".$modele.
"_".strtolower($tmpobjectkey).
".modules.php", 0);
209 if (file_exists($file)) {
211 $classname =
"pdf_".$modele.
"_".strtolower($tmpobjectkey);
219 $module =
new $classname($db);
221 if ($module->write_file($tmpobject, $langs) > 0) {
222 header(
"Location: ".DOL_URL_ROOT.
"/document.php?modulepart=mymodule-".strtolower($tmpobjectkey).
"&file=SPECIMEN.pdf");
230 dol_syslog($langs->trans(
"ErrorModuleNotFound"), LOG_ERR);
232} elseif ($action ==
'setmod') {
234 $tmpobjectkey =
GETPOST(
'object');
235 if (!empty($tmpobjectkey)) {
236 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
"_ADDON";
239} elseif ($action ==
'set') {
242} elseif ($action ==
'del') {
245 $tmpobjectkey =
GETPOST(
'object');
246 if (!empty($tmpobjectkey)) {
247 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
253} elseif ($action ==
'setdoc') {
255 $tmpobjectkey =
GETPOST(
'object');
256 if (!empty($tmpobjectkey)) {
257 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
261 $conf->global->{$constforval} = $value;
270} elseif ($action ==
'unsetdoc') {
271 $tmpobjectkey =
GETPOST(
'object');
272 if (!empty($tmpobjectkey)) {
273 $constforval =
'MYMODULE_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
284$form =
new Form($db);
287$page_name =
"MyModuleSetup";
289llxHeader(
'', $langs->trans($page_name), $help_url,
'', 0, 0,
'',
'',
'',
'mod-mymodule page-admin');
292$linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1').
'">'.$langs->trans(
"BackToModuleList").
'</a>';
298print
dol_get_fiche_head($head,
'settings', $langs->trans($page_name), -1,
"mymodule@mymodule");
301echo
'<span class="opacitymedium">'.$langs->trans(
"MyModuleSetupPage").
'</span><br><br>';
304if ($action ==
'edit') {
305 print $formSetup->generateOutput(
true);
307} elseif (!empty($formSetup->items)) {
308 print $formSetup->generateOutput();
309 print
'<div class="tabsAction">';
310 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit&token='.newToken().
'">'.$langs->trans(
"Modify").
'</a>';
313 print
'<br>'.$langs->trans(
"NothingToSetup");
317$moduledir =
'mymodule';
318$myTmpObjects = array();
320$myTmpObjects[
'myobject'] = array(
'label'=>
'MyObject',
'includerefgeneration'=>0,
'includedocgeneration'=>0,
'class'=>
'MyObject');
323foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
324 if ($myTmpObjectArray[
'includerefgeneration']) {
330 print
load_fiche_titre($langs->trans(
"NumberingModules", $myTmpObjectArray[
'label']),
'',
'');
332 print
'<table class="noborder centpercent">';
333 print
'<tr class="liste_titre">';
334 print
'<td>'.$langs->trans(
"Name").
'</td>';
335 print
'<td>'.$langs->trans(
"Description").
'</td>';
336 print
'<td class="nowrap">'.$langs->trans(
"Example").
'</td>';
337 print
'<td class="center" width="60">'.$langs->trans(
"Status").
'</td>';
338 print
'<td class="center" width="16">'.$langs->trans(
"ShortInfo").
'</td>';
343 foreach ($dirmodels as $reldir) {
347 $handle = opendir($dir);
348 if (is_resource($handle)) {
349 while (($file = readdir($handle)) !==
false) {
350 if (strpos($file,
'mod_'.strtolower($myTmpObjectKey).
'_') === 0 && substr($file,
dol_strlen($file) - 3, 3) ==
'php') {
351 $file = substr($file, 0,
dol_strlen($file) - 4);
353 require_once $dir.
'/'.$file.
'.php';
355 $module =
new $file($db);
358 if ($module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
361 if ($module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
365 if ($module->isEnabled()) {
366 dol_include_once(
'/'.$moduledir.
'/class/'.strtolower($myTmpObjectKey).
'.class.php');
368 print
'<tr class="oddeven"><td>'.$module->name.
"</td><td>\n";
369 print $module->info($langs);
373 print
'<td class="nowrap">';
374 $tmp = $module->getExample();
375 if (preg_match(
'/^Error/', $tmp)) {
376 $langs->load(
"errors");
377 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
378 } elseif ($tmp ==
'NotConfigured') {
379 print $langs->trans($tmp);
385 print
'<td class="center">';
386 $constforvar =
'MYMODULE_'.strtoupper($myTmpObjectKey).
'_ADDON';
388 print
img_picto($langs->trans(
"Activated"),
'switch_on');
390 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=setmod&token='.newToken().
'&object='.strtolower($myTmpObjectKey).
'&value='.urlencode($file).
'">';
391 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
396 $nameofclass = $myTmpObjectArray[
'class'];
397 $mytmpinstance =
new $nameofclass($db);
398 $mytmpinstance->initAsSpecimen();
402 $htmltooltip .=
''.$langs->trans(
"Version").
': <b>'.$module->getVersion().
'</b><br>';
404 $nextval = $module->getNextValue($mytmpinstance);
405 if (
"$nextval" != $langs->trans(
"NotAvailable")) {
406 $htmltooltip .=
''.$langs->trans(
"NextValue").
': ';
408 if (preg_match(
'/^Error/', $nextval) || $nextval ==
'NotConfigured') {
409 $nextval = $langs->trans($nextval);
411 $htmltooltip .= $nextval.
'<br>';
413 $htmltooltip .= $langs->trans($module->error).
'<br>';
417 print
'<td class="center">';
418 print $form->textwithpicto(
'', $htmltooltip, 1, 0);
429 print
"</table><br>\n";
432 if ($myTmpObjectArray[
'includedocgeneration']) {
437 $type = strtolower($myTmpObjectKey);
439 print
load_fiche_titre($langs->trans(
"DocumentModules", $myTmpObjectKey),
'',
'');
444 $sql .=
" FROM ".MAIN_DB_PREFIX.
"document_model";
445 $sql .=
" WHERE type = '".$db->escape($type).
"'";
446 $sql .=
" AND entity = ".$conf->entity;
447 $resql = $db->query($sql);
450 $num_rows = $db->num_rows($resql);
451 while ($i < $num_rows) {
452 $array = $db->fetch_array($resql);
453 array_push($def, $array[0]);
460 print
'<table class="noborder centpercent">'.
"\n";
461 print
'<tr class="liste_titre">'.
"\n";
462 print
'<td>'.$langs->trans(
"Name").
'</td>';
463 print
'<td>'.$langs->trans(
"Description").
'</td>';
464 print
'<td class="center" width="60">'.$langs->trans(
"Status").
"</td>\n";
465 print
'<td class="center" width="60">'.$langs->trans(
"Default").
"</td>\n";
466 print
'<td class="center" width="38">'.$langs->trans(
"ShortInfo").
'</td>';
467 print
'<td class="center" width="38">'.$langs->trans(
"Preview").
'</td>';
472 foreach ($dirmodels as $reldir) {
473 foreach (array(
'',
'/doc') as $valdir) {
474 $realpath = $reldir.
"core/modules/".$moduledir.$valdir;
478 $handle = opendir($dir);
479 if (is_resource($handle)) {
480 while (($file = readdir($handle)) !==
false) {
486 foreach ($filelist as $file) {
487 if (preg_match(
'/\.modules\.php$/i', $file) && preg_match(
'/^(pdf_|doc_)/', $file)) {
488 if (file_exists($dir.
'/'.$file)) {
489 $name = substr($file, 4,
dol_strlen($file) - 16);
490 $classname = substr($file, 0,
dol_strlen($file) - 12);
492 require_once $dir.
'/'.$file;
493 $module =
new $classname($db);
495 $modulequalified = 1;
496 if ($module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
497 $modulequalified = 0;
499 if ($module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
500 $modulequalified = 0;
503 if ($modulequalified) {
504 print
'<tr class="oddeven"><td width="100">';
505 print(empty($module->name) ? $name : $module->
name);
507 if (method_exists($module,
'info')) {
508 print $module->info($langs);
510 print $module->description;
515 if (in_array($name, $def)) {
516 print
'<td class="center">'.
"\n";
517 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=del&token='.newToken().
'&value='.urlencode($name).
'">';
518 print
img_picto($langs->trans(
"Enabled"),
'switch_on');
522 print
'<td class="center">'.
"\n";
523 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>';
528 print
'<td class="center">';
529 $constforvar =
'MYMODULE_'.strtoupper($myTmpObjectKey).
'_ADDON_PDF';
533 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>';
535 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>';
540 $htmltooltip =
''.$langs->trans(
"Name").
': '.$module->name;
541 $htmltooltip .=
'<br>'.$langs->trans(
"Type").
': '.($module->type ? $module->type : $langs->trans(
"Unknown"));
542 if ($module->type ==
'pdf') {
543 $htmltooltip .=
'<br>'.$langs->trans(
"Width").
'/'.$langs->trans(
"Height").
': '.$module->page_largeur.
'/'.$module->page_hauteur;
545 $htmltooltip .=
'<br>'.$langs->trans(
"Path").
': '.preg_replace(
'/^\//',
'', $realpath).
'/'.$file;
547 $htmltooltip .=
'<br><br><u>'.$langs->trans(
"FeaturesSupported").
':</u>';
548 $htmltooltip .=
'<br>'.$langs->trans(
"Logo").
': '.
yn($module->option_logo, 1, 1);
549 $htmltooltip .=
'<br>'.$langs->trans(
"MultiLanguage").
': '.
yn($module->option_multilang, 1, 1);
551 print
'<td class="center">';
552 print $form->textwithpicto(
'', $htmltooltip, 1, 0);
556 print
'<td class="center">';
557 if ($module->type ==
'pdf') {
558 $newname = preg_replace(
'/_'.preg_quote(strtolower($myTmpObjectKey),
'/').
'/',
'', $name);
559 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=specimen&module='.urlencode($newname).
'&object='.urlencode($myTmpObjectKey).
'">'.
img_object($langs->trans(
"Preview"),
'pdf').
'</a>';
561 print
img_object($langs->trans(
"PreviewNotAvailable"),
'generic');
579if (empty($setupnotempty)) {
580 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($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
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.
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.