28 if (!$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;
33 while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
36 if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)).
"/main.inc.php")) {
37 $res = @include substr($tmp, 0, ($i + 1)).
"/main.inc.php";
39 if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))).
"/main.inc.php")) {
40 $res = @include dirname(substr($tmp, 0, ($i + 1))).
"/main.inc.php";
43 if (!$res && file_exists(
"../../main.inc.php")) {
44 $res = @include
"../../main.inc.php";
46 if (!$res && file_exists(
"../../../main.inc.php")) {
47 $res = @include
"../../../main.inc.php";
50 die(
"Include of main fails");
56 require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
57 require_once
'../lib/bookcal.lib.php';
61 $langs->loadLangs(array(
"admin",
"bookcal@bookcal"));
64 $hookmanager->initHooks(array(
'bookcalsetup',
'globalsetup'));
72 $action =
GETPOST(
'action',
'aZ09');
73 $backtopage =
GETPOST(
'backtopage',
'alpha');
74 $modulepart =
GETPOST(
'modulepart',
'aZ09');
76 $value =
GETPOST(
'value',
'alpha');
77 $label =
GETPOST(
'label',
'alpha');
78 $scandir =
GETPOST(
'scan_dir',
'alpha');
88 if (!class_exists(
'FormSetup')) {
90 if (floatval(DOL_VERSION) < 16.0 && !class_exists(
'FormSetup')) {
91 require_once __DIR__.
'/../backport/v16/core/class/html.formsetup.class.php';
93 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formsetup.class.php';
101 $item = $formSetup->newItem(
'NO_PARAM_JUST_TEXT');
102 $item->fieldOverride = (empty($_SERVER[
'HTTPS']) ?
'http://' :
'https://') . $_SERVER[
'HTTP_HOST'];
103 $item->cssClass =
'minwidth500';
106 $item = $formSetup->newItem(
'BOOKCAL_MYPARAM1');
107 $item->defaultFieldValue =
'default value';
110 $item = $formSetup->newItem(
'BOOKCAL_MYPARAM2');
111 $item->nameText = $item->getNameText().
' more html text ';
114 $item = $formSetup->newItem(
'BOOKCAL_MYPARAM3');
115 $item->setAsThirdpartyType();
118 $formSetup->newItem(
'BOOKCAL_MYPARAM4')->setAsYesNo();
121 $formSetup->newItem(
'BOOKCAL_MYPARAM5')->setAsEmailTemplate(
'thirdparty');
124 $formSetup->newItem(
'BOOKCAL_MYPARAM6')->setAsSecureKey()->enabled = 0;
127 $formSetup->newItem(
'BOOKCAL_MYPARAM7')->setAsProduct();
129 $formSetup->newItem(
'Title')->setAsTitle();
132 $item = $formSetup->newItem(
'BOOKCAL_MYPARAM8');
134 'test01' => $langs->trans(
'test01'),
135 'test02' => $langs->trans(
'test02'),
136 'test03' => $langs->trans(
'test03'),
137 'test04' => $langs->trans(
'test04'),
138 'test05' => $langs->trans(
'test05'),
139 'test06' => $langs->trans(
'test06'),
141 $item->setAsMultiSelect($TField);
142 $item->helpText = $langs->transnoentities(
'BOOKCAL_MYPARAM8');
146 $formSetup->newItem(
'BOOKCAL_MYPARAM9')->setAsSelect($TField);
150 $item = $formSetup->newItem(
'BOOKCAL_MYPARAM10');
152 $item->defaultFieldValue =
'#FF0000';
153 $item->nameText = $item->getNameText().
' more html text ';
154 $item->fieldInputOverride =
'';
155 $item->helpText = $langs->transnoentities(
'AnHelpMessage');
163 $setupnotempty =+ count($formSetup->items);
166 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
174 if (
versioncompare(explode(
'.', DOL_VERSION), array(15)) < 0 && $action ==
'update' && !empty($user->admin)) {
175 $formSetup->saveConfFromPost();
178 include DOL_DOCUMENT_ROOT.
'/core/actions_setmoduleoptions.inc.php';
180 if ($action ==
'updateMask') {
181 $maskconst =
GETPOST(
'maskconst',
'aZ09');
182 $maskvalue =
GETPOST(
'maskvalue',
'alpha');
184 if ($maskconst && preg_match(
'/_MASK$/', $maskconst)) {
185 $res =
dolibarr_set_const($db, $maskconst, $maskvalue,
'chaine', 0,
'', $conf->entity);
196 } elseif ($action ==
'specimen') {
197 $modele =
GETPOST(
'module',
'alpha');
198 $tmpobjectkey =
GETPOST(
'object');
200 $tmpobject =
new $tmpobjectkey($db);
201 $tmpobject->initAsSpecimen();
204 $file =
''; $classname =
''; $filefound = 0;
205 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
206 foreach ($dirmodels as $reldir) {
207 $file =
dol_buildpath($reldir.
"core/modules/bookcal/doc/pdf_".$modele.
"_".strtolower($tmpobjectkey).
".modules.php", 0);
208 if (file_exists($file)) {
210 $classname =
"pdf_".$modele.
"_".strtolower($tmpobjectkey);
218 $module =
new $classname($db);
220 if ($module->write_file($tmpobject, $langs) > 0) {
221 header(
"Location: ".DOL_URL_ROOT.
"/document.php?modulepart=bookcal-".strtolower($tmpobjectkey).
"&file=SPECIMEN.pdf");
229 dol_syslog($langs->trans(
"ErrorModuleNotFound"), LOG_ERR);
231 } elseif ($action ==
'setmod') {
233 $tmpobjectkey =
GETPOST(
'object');
234 if (!empty($tmpobjectkey)) {
235 $constforval =
'BOOKCAL_'.strtoupper($tmpobjectkey).
"_ADDON";
238 } elseif ($action ==
'set') {
241 } elseif ($action ==
'del') {
244 $tmpobjectkey =
GETPOST(
'object');
245 if (!empty($tmpobjectkey)) {
246 $constforval =
'BOOKCAL_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
247 if ($conf->global->$constforval ==
"$value") {
252 } elseif ($action ==
'setdoc') {
254 $tmpobjectkey =
GETPOST(
'object');
255 if (!empty($tmpobjectkey)) {
256 $constforval =
'BOOKCAL_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
260 $conf->global->$constforval = $value;
269 } elseif ($action ==
'unsetdoc') {
270 $tmpobjectkey =
GETPOST(
'object');
271 if (!empty($tmpobjectkey)) {
272 $constforval =
'BOOKCAL_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
286 $page_name =
"BookCalSetup";
291 $linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1').
'">'.$langs->trans(
"BackToModuleList").
'</a>';
293 print
load_fiche_titre($langs->trans($page_name), $linkback,
'title_setup');
297 print
dol_get_fiche_head($head,
'settings', $langs->trans($page_name), -1,
"bookcal@bookcal");
300 echo
'<span class="opacitymedium">'.$langs->trans(
"BookCalSetupPage").
'</span><br><br>';
303 if ($action ==
'edit') {
304 print $formSetup->generateOutput(
true);
306 } elseif (!empty($formSetup->items)) {
307 print $formSetup->generateOutput();
308 print
'<div class="tabsAction">';
309 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit&token='.
newToken().
'">'.$langs->trans(
"Modify").
'</a>';
312 print
'<br>'.$langs->trans(
"NothingToSetup");
316 $moduledir =
'bookcal';
317 $myTmpObjects = array();
318 $myTmpObjects[
'MyObject'] = array(
'includerefgeneration'=>0,
'includedocgeneration'=>0);
321 foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
322 if ($myTmpObjectKey ==
'MyObject') {
325 if ($myTmpObjectArray[
'includerefgeneration']) {
331 print
load_fiche_titre($langs->trans(
"NumberingModules", $myTmpObjectKey),
'',
'');
333 print
'<table class="noborder centpercent">';
334 print
'<tr class="liste_titre">';
335 print
'<td>'.$langs->trans(
"Name").
'</td>';
336 print
'<td>'.$langs->trans(
"Description").
'</td>';
337 print
'<td class="nowrap">'.$langs->trans(
"Example").
'</td>';
338 print
'<td class="center" width="60">'.$langs->trans(
"Status").
'</td>';
339 print
'<td class="center" width="16">'.$langs->trans(
"ShortInfo").
'</td>';
344 foreach ($dirmodels as $reldir) {
348 $handle = opendir($dir);
349 if (is_resource($handle)) {
350 while (($file = readdir($handle)) !==
false) {
351 if (strpos($file,
'mod_'.strtolower($myTmpObjectKey).
'_') === 0 && substr($file,
dol_strlen($file) - 3, 3) ==
'php') {
352 $file = substr($file, 0,
dol_strlen($file) - 4);
354 require_once $dir.
'/'.$file.
'.php';
356 $module =
new $file($db);
359 if ($module->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
362 if ($module->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
366 if ($module->isEnabled()) {
367 dol_include_once(
'/'.$moduledir.
'/class/'.strtolower($myTmpObjectKey).
'.class.php');
369 print
'<tr class="oddeven"><td>'.$module->name.
"</td><td>\n";
370 print $module->info();
374 print
'<td class="nowrap">';
375 $tmp = $module->getExample();
376 if (preg_match(
'/^Error/', $tmp)) {
377 $langs->load(
"errors");
378 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
379 } elseif ($tmp ==
'NotConfigured') {
380 print $langs->trans($tmp);
386 print
'<td class="center">';
387 $constforvar =
'BOOKCAL_'.strtoupper($myTmpObjectKey).
'_ADDON';
389 print
img_picto($langs->trans(
"Activated"),
'switch_on');
391 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=setmod&token='.
newToken().
'&object='.strtolower($myTmpObjectKey).
'&value='.urlencode($file).
'">';
392 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
397 $mytmpinstance =
new $myTmpObjectKey($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\" width=\"100%\">\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' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
497 $modulequalified = 0;
499 if ($module->version ==
'experimental' && $conf->global->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 =
'BOOKCAL_'.strtoupper($myTmpObjectKey).
'_ADDON';
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');
579 if (empty($setupnotempty)) {
580 print
'<br>'.$langs->trans(
"NothingToSetup");