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";
49 if (!$res && file_exists(
"../../../main.inc.php")) {
50 $res = @include
"../../../main.inc.php";
53 die(
"Include of main fails");
59 require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
60 require_once DOL_DOCUMENT_ROOT.
'/webhook/lib/webhook.lib.php';
63 $langs->loadLangs(array(
"admin",
"webhook"));
66 $hookmanager->initHooks(array(
'webhooksetup',
'globalsetup'));
74 $action =
GETPOST(
'action',
'aZ09');
75 $backtopage =
GETPOST(
'backtopage',
'alpha');
76 $modulepart =
GETPOST(
'modulepart',
'aZ09');
78 $value =
GETPOST(
'value',
'alpha');
79 $label =
GETPOST(
'label',
'alpha');
80 $scandir =
GETPOST(
'scan_dir',
'alpha');
83 $arrayofparameters = array(
84 'WEBHOOK_MYPARAM1'=>array(
'type'=>
'string',
'css'=>
'minwidth500' ,
'enabled'=>0),
100 if ($useFormSetup && (
float) DOL_VERSION >= 15) {
101 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formsetup.class.php';
105 $formSetup->addItemsFromParamsArray($arrayofparameters);
139 $setupnotempty = count($formSetup->items);
143 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
150 include DOL_DOCUMENT_ROOT.
'/core/actions_setmoduleoptions.inc.php';
152 if ($action ==
'updateMask') {
153 $maskconst =
GETPOST(
'maskconst',
'alpha');
154 $maskvalue =
GETPOST(
'maskvalue',
'alpha');
157 $res =
dolibarr_set_const($db, $maskconst, $maskvalue,
'chaine', 0,
'', $conf->entity);
168 } elseif ($action ==
'specimen') {
169 $modele =
GETPOST(
'module',
'alpha');
170 $tmpobjectkey =
GETPOST(
'object');
172 $tmpobject =
new $tmpobjectkey($db);
173 $tmpobject->initAsSpecimen();
176 $file =
''; $classname =
''; $filefound = 0;
177 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
178 foreach ($dirmodels as $reldir) {
179 $file =
dol_buildpath($reldir.
"core/modules/webhook/doc/pdf_".$modele.
"_".strtolower($tmpobjectkey).
".modules.php", 0);
180 if (file_exists($file)) {
182 $classname =
"pdf_".$modele;
190 $module =
new $classname($db);
192 if ($module->write_file($tmpobject, $langs) > 0) {
193 header(
"Location: ".DOL_URL_ROOT.
"/document.php?modulepart=".strtolower($tmpobjectkey).
"&file=SPECIMEN.pdf");
201 dol_syslog($langs->trans(
"ErrorModuleNotFound"), LOG_ERR);
203 } elseif ($action ==
'setmod') {
205 $tmpobjectkey =
GETPOST(
'object');
206 if (!empty($tmpobjectkey)) {
207 $constforval =
'WEBHOOK_'.strtoupper($tmpobjectkey).
"_ADDON";
210 } elseif ($action ==
'set') {
213 } elseif ($action ==
'del') {
216 $tmpobjectkey =
GETPOST(
'object');
217 if (!empty($tmpobjectkey)) {
218 $constforval =
'WEBHOOK_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
219 if ($conf->global->$constforval ==
"$value") {
224 } elseif ($action ==
'setdoc') {
226 $tmpobjectkey =
GETPOST(
'object');
227 if (!empty($tmpobjectkey)) {
228 $constforval =
'WEBHOOK_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
232 $conf->global->$constforval = $value;
241 } elseif ($action ==
'unsetdoc') {
242 $tmpobjectkey =
GETPOST(
'object');
243 if (!empty($tmpobjectkey)) {
244 $constforval =
'WEBHOOK_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
258 $page_name =
"WebhookSetup";
263 $linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1').
'">'.$langs->trans(
"BackToModuleList").
'</a>';
265 print
load_fiche_titre($langs->trans($page_name), $linkback,
'title_setup');
269 print
dol_get_fiche_head($head,
'settings', $langs->trans($page_name), -1,
"webhook@webhook");
272 echo
'<span class="opacitymedium">'.$langs->trans(
"WebhookSetupPage").
'</span><br><br>';
275 if ($action ==
'edit') {
276 if ($useFormSetup && (
float) DOL_VERSION >= 15) {
277 print $formSetup->generateOutput(
true);
279 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
280 print
'<input type="hidden" name="token" value="'.newToken().
'">';
281 print
'<input type="hidden" name="action" value="update">';
283 print
'<table class="noborder centpercent">';
284 print
'<tr class="liste_titre"><td class="titlefield">'.$langs->trans(
"Parameter").
'</td><td>'.$langs->trans(
"Value").
'</td></tr>';
286 foreach ($arrayofparameters as $constname => $val) {
287 if ($val[
'enabled']==1) {
289 print
'<tr class="oddeven"><td>';
290 $tooltiphelp = (($langs->trans($constname .
'Tooltip') != $constname .
'Tooltip') ? $langs->trans($constname .
'Tooltip') :
'');
291 print
'<span id="helplink'.$constname.
'" class="spanforparamtooltip">'.
$form->textwithpicto($langs->trans($constname), $tooltiphelp, 1,
'info',
'', 0, 3,
'tootips'.$constname).
'</span>';
294 if ($val[
'type'] ==
'textarea') {
295 print
'<textarea class="flat" name="'.$constname.
'" id="'.$constname.
'" cols="50" rows="5" wrap="soft">' .
"\n";
296 print $conf->global->{$constname};
297 print
"</textarea>\n";
298 } elseif ($val[
'type']==
'html') {
299 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
300 $doleditor =
new DolEditor($constname, $conf->global->{$constname},
'', 160,
'dolibarr_notes',
'',
false,
false, $conf->fckeditor->enabled, ROWS_5,
'90%');
301 $doleditor->Create();
302 } elseif ($val[
'type'] ==
'yesno') {
303 print
$form->selectyesno($constname, $conf->global->{$constname}, 1);
304 } elseif (preg_match(
'/emailtemplate:/', $val[
'type'])) {
305 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
308 $tmp = explode(
':', $val[
'type']);
309 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user,
null, 1);
311 $arrayofmessagename = array();
312 if (is_array($formmail->lines_model)) {
313 foreach ($formmail->lines_model as $modelmail) {
316 if (!empty($arrayofmessagename[$modelmail->label])) {
317 $moreonlabel =
' <span class="opacitymedium">(' . $langs->trans(
"SeveralLangugeVariatFound") .
')</span>';
320 $arrayofmessagename[$modelmail->id] = $langs->trans(preg_replace(
'/\(|\)/',
'', $modelmail->label)) . $moreonlabel;
323 print
$form->selectarray($constname, $arrayofmessagename, $conf->global->{$constname},
'None', 0, 0,
'', 0, 0, 0,
'',
'', 1);
324 } elseif (preg_match(
'/category:/', $val[
'type'])) {
325 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
326 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
329 $tmp = explode(
':', $val[
'type']);
330 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
331 print $formother->select_categories($tmp[1], $conf->global->{$constname}, $constname, 0, $langs->trans(
'CustomersProspectsCategoriesShort'));
332 } elseif (preg_match(
'/thirdparty_type/', $val[
'type'])) {
333 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
335 print $formcompany->selectProspectCustomerType($conf->global->{$constname}, $constname);
336 } elseif ($val[
'type'] ==
'securekey') {
337 print
'<input required="required" type="text" class="flat" id="'.$constname.
'" name="'.$constname.
'" value="'.(
GETPOST($constname,
'alpha') ?
GETPOST($constname,
'alpha') : $conf->global->{$constname}).
'" size="40">';
338 if (!empty($conf->use_javascript_ajax)) {
339 print
' '.img_picto($langs->trans(
'Generate'),
'refresh',
'id="generate_token'.$constname.
'" class="linkobject"');
341 if (!empty($conf->use_javascript_ajax)) {
342 print
"\n".
'<script type="text/javascript">';
343 print
'$(document).ready(function () {
344 $("#generate_token'.$constname.
'").click(function() {
345 $.get( "'.DOL_URL_ROOT.
'/core/ajax/security.php", {
346 action: \'getrandompassword\',
350 $("#'.$constname.
'").val(token);
356 } elseif ($val[
'type'] ==
'product') {
357 if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) {
358 $selected = (empty($conf->global->$constname) ?
'' : $conf->global->$constname);
359 $form->select_produits($selected, $constname,
'', 0);
362 print
'<input name="'.$constname.
'" class="flat '.(empty($val[
'css']) ?
'minwidth200' : $val[
'css']).
'" value="'.$conf->global->{$constname}.
'">';
369 print
'<br><div class="center">';
370 print
'<input class="button button-save" type="submit" value="'.$langs->trans(
"Save").
'">';
378 if ($useFormSetup && (
float) DOL_VERSION >= 15) {
379 if (!empty($formSetup->items)) {
380 print $formSetup->generateOutput();
383 if (!empty($arrayofparameters)) {
384 print
'<table class="noborder centpercent">';
385 print
'<tr class="liste_titre"><td class="titlefield">'.$langs->trans(
"Parameter").
'</td><td>'.$langs->trans(
"Value").
'</td></tr>';
387 foreach ($arrayofparameters as $constname => $val) {
388 if ($val[
'enabled']==1) {
390 print
'<tr class="oddeven"><td>';
391 $tooltiphelp = (($langs->trans($constname .
'Tooltip') != $constname .
'Tooltip') ? $langs->trans($constname .
'Tooltip') :
'');
392 print
$form->textwithpicto($langs->trans($constname), $tooltiphelp);
395 if ($val[
'type'] ==
'textarea') {
396 print
dol_nl2br($conf->global->{$constname});
397 } elseif ($val[
'type']==
'html') {
398 print $conf->global->{$constname};
399 } elseif ($val[
'type'] ==
'yesno') {
401 } elseif (preg_match(
'/emailtemplate:/', $val[
'type'])) {
402 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
405 $tmp = explode(
':', $val[
'type']);
407 $template = $formmail->getEMailTemplate($db, $tmp[1], $user, $langs, $conf->global->{$constname});
411 print $langs->trans($template->label);
412 } elseif (preg_match(
'/category:/', $val[
'type'])) {
414 $result = $c->fetch($conf->global->{$constname});
417 } elseif ($result > 0 ) {
418 $ways = $c->print_all_ways(
' >> ',
'none', 0, 1);
420 foreach ($ways as $way) {
421 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #bbb"') .
'>' . $way .
'</li>';
423 print
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
425 } elseif (preg_match(
'/thirdparty_type/', $val[
'type'])) {
426 if ($conf->global->{$constname}==2) {
427 print $langs->trans(
"Prospect");
428 } elseif ($conf->global->{$constname}==3) {
429 print $langs->trans(
"ProspectCustomer");
430 } elseif ($conf->global->{$constname}==1) {
431 print $langs->trans(
"Customer");
432 } elseif ($conf->global->{$constname}==0) {
433 print $langs->trans(
"NorProspectNorCustomer");
435 } elseif ($val[
'type'] ==
'product') {
437 $resprod = $product->fetch($conf->global->{$constname});
440 } elseif ($resprod < 0) {
444 print $conf->global->{$constname};
454 if ($setupnotempty) {
455 print
'<div class="tabsAction">';
456 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit&token='.
newToken().
'">'.$langs->trans(
"Modify").
'</a>';
464 $moduledir =
'webhook';
465 $myTmpObjects[
'MyObject'] = array(
'includerefgeneration'=>0,
'includedocgeneration'=>0);
468 foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
469 if ($myTmpObjectKey ==
'MyObject') {
472 if ($myTmpObjectArray[
'includerefgeneration']) {
478 print
load_fiche_titre($langs->trans(
"NumberingModules", $myTmpObjectKey),
'',
'');
480 print
'<table class="noborder centpercent">';
481 print
'<tr class="liste_titre">';
482 print
'<td>'.$langs->trans(
"Name").
'</td>';
483 print
'<td>'.$langs->trans(
"Description").
'</td>';
484 print
'<td class="nowrap">'.$langs->trans(
"Example").
'</td>';
485 print
'<td class="center" width="60">'.$langs->trans(
"Status").
'</td>';
486 print
'<td class="center" width="16">'.$langs->trans(
"ShortInfo").
'</td>';
491 foreach ($dirmodels as $reldir) {
495 $handle = opendir($dir);
496 if (is_resource($handle)) {
497 while (($file = readdir($handle)) !==
false) {
498 if (strpos($file,
'mod_'.strtolower($myTmpObjectKey).
'_') === 0 && substr($file,
dol_strlen($file) - 3, 3) ==
'php') {
499 $file = substr($file, 0,
dol_strlen($file) - 4);
501 require_once $dir.
'/'.$file.
'.php';
503 $module =
new $file($db);
506 if ($module->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
509 if ($module->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
513 if ($module->isEnabled()) {
514 dol_include_once(
'/'.$moduledir.
'/class/'.strtolower($myTmpObjectKey).
'.class.php');
516 print
'<tr class="oddeven"><td>'.$module->name.
"</td><td>\n";
517 print $module->info();
521 print
'<td class="nowrap">';
522 $tmp = $module->getExample();
523 if (preg_match(
'/^Error/', $tmp)) {
524 $langs->load(
"errors");
525 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
526 } elseif ($tmp ==
'NotConfigured') {
527 print $langs->trans($tmp);
533 print
'<td class="center">';
534 $constforvar =
'WEBHOOK_'.strtoupper($myTmpObjectKey).
'_ADDON';
535 if ($conf->global->$constforvar == $file) {
536 print
img_picto($langs->trans(
"Activated"),
'switch_on');
538 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=setmod&token='.
newToken().
'&object='.strtolower($myTmpObjectKey).
'&value='.urlencode($file).
'">';
539 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
544 $mytmpinstance =
new $myTmpObjectKey($db);
545 $mytmpinstance->initAsSpecimen();
549 $htmltooltip .=
''.$langs->trans(
"Version").
': <b>'.$module->getVersion().
'</b><br>';
551 $nextval = $module->getNextValue($mytmpinstance);
552 if (
"$nextval" != $langs->trans(
"NotAvailable")) {
553 $htmltooltip .=
''.$langs->trans(
"NextValue").
': ';
555 if (preg_match(
'/^Error/', $nextval) || $nextval ==
'NotConfigured') {
556 $nextval = $langs->trans($nextval);
558 $htmltooltip .= $nextval.
'<br>';
560 $htmltooltip .= $langs->trans($module->error).
'<br>';
564 print
'<td class="center">';
565 print
$form->textwithpicto(
'', $htmltooltip, 1, 0);
576 print
"</table><br>\n";
579 if ($myTmpObjectArray[
'includedocgeneration']) {
584 $type = strtolower($myTmpObjectKey);
586 print
load_fiche_titre($langs->trans(
"DocumentModules", $myTmpObjectKey),
'',
'');
591 $sql .=
" FROM ".MAIN_DB_PREFIX.
"document_model";
592 $sql .=
" WHERE type = '".$db->escape($type).
"'";
593 $sql .=
" AND entity = ".$conf->entity;
594 $resql = $db->query($sql);
597 $num_rows = $db->num_rows(
$resql);
598 while ($i < $num_rows) {
599 $array = $db->fetch_array(
$resql);
600 array_push($def, $array[0]);
607 print
"<table class=\"noborder\" width=\"100%\">\n";
608 print
"<tr class=\"liste_titre\">\n";
609 print
'<td>'.$langs->trans(
"Name").
'</td>';
610 print
'<td>'.$langs->trans(
"Description").
'</td>';
611 print
'<td class="center" width="60">'.$langs->trans(
"Status").
"</td>\n";
612 print
'<td class="center" width="60">'.$langs->trans(
"Default").
"</td>\n";
613 print
'<td class="center" width="38">'.$langs->trans(
"ShortInfo").
'</td>';
614 print
'<td class="center" width="38">'.$langs->trans(
"Preview").
'</td>';
619 foreach ($dirmodels as $reldir) {
620 foreach (array(
'',
'/doc') as $valdir) {
621 $realpath = $reldir.
"core/modules/".$moduledir.$valdir;
625 $handle = opendir($dir);
626 if (is_resource($handle)) {
627 while (($file = readdir($handle)) !==
false) {
633 foreach ($filelist as $file) {
634 if (preg_match(
'/\.modules\.php$/i', $file) && preg_match(
'/^(pdf_|doc_)/', $file)) {
635 if (file_exists($dir.
'/'.$file)) {
636 $name = substr($file, 4,
dol_strlen($file) - 16);
637 $classname = substr($file, 0,
dol_strlen($file) - 12);
639 require_once $dir.
'/'.$file;
640 $module =
new $classname($db);
642 $modulequalified = 1;
643 if ($module->version ==
'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
644 $modulequalified = 0;
646 if ($module->version ==
'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
647 $modulequalified = 0;
650 if ($modulequalified) {
651 print
'<tr class="oddeven"><td width="100">';
652 print (empty($module->name) ? $name : $module->name);
654 if (method_exists($module,
'info')) {
655 print $module->info($langs);
657 print $module->description;
662 if (in_array($name, $def)) {
663 print
'<td class="center">'.
"\n";
664 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=del&token='.
newToken().
'&value='.urlencode($name).
'">';
665 print
img_picto($langs->trans(
"Enabled"),
'switch_on');
669 print
'<td class="center">'.
"\n";
670 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>';
675 print
'<td class="center">';
676 $constforvar =
'WEBHOOK_'.strtoupper($myTmpObjectKey).
'_ADDON';
677 if ($conf->global->$constforvar == $name) {
680 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>';
682 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>';
687 $htmltooltip =
''.$langs->trans(
"Name").
': '.$module->name;
688 $htmltooltip .=
'<br>'.$langs->trans(
"Type").
': '.($module->type ? $module->type : $langs->trans(
"Unknown"));
689 if ($module->type ==
'pdf') {
690 $htmltooltip .=
'<br>'.$langs->trans(
"Width").
'/'.$langs->trans(
"Height").
': '.$module->page_largeur.
'/'.$module->page_hauteur;
692 $htmltooltip .=
'<br>'.$langs->trans(
"Path").
': '.preg_replace(
'/^\//',
'', $realpath).
'/'.$file;
694 $htmltooltip .=
'<br><br><u>'.$langs->trans(
"FeaturesSupported").
':</u>';
695 $htmltooltip .=
'<br>'.$langs->trans(
"Logo").
': '.
yn($module->option_logo, 1, 1);
696 $htmltooltip .=
'<br>'.$langs->trans(
"MultiLanguage").
': '.
yn($module->option_multilang, 1, 1);
698 print
'<td class="center">';
699 print
$form->textwithpicto(
'', $htmltooltip, 1, 0);
703 print
'<td class="center">';
704 if ($module->type ==
'pdf') {
705 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=specimen&module='.$name.
'&object='.$myTmpObjectKey.
'">'.
img_object($langs->trans(
"Preview"),
'pdf').
'</a>';
707 print
img_object($langs->trans(
"PreviewNotAvailable"),
'generic');
725 if (empty($setupnotempty)) {
726 print
'<br>'.$langs->trans(
"NothingToSetup");