25require
'../main.inc.php';
26require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
27require_once DOL_DOCUMENT_ROOT.
'/webhook/lib/webhook.lib.php';
30$langs->loadLangs(array(
"admin",
"webhook"));
33$hookmanager->initHooks(array(
'webhooksetup',
'globalsetup'));
41$action =
GETPOST(
'action',
'aZ09');
42$backtopage =
GETPOST(
'backtopage',
'alpha');
43$modulepart =
GETPOST(
'modulepart',
'aZ09');
45$value =
GETPOST(
'value',
'alpha');
46$label =
GETPOST(
'label',
'alpha');
47$scandir =
GETPOST(
'scan_dir',
'alpha');
57if (!class_exists(
'FormSetup')) {
58 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formsetup.class.php';
64$setupnotempty = count($formSetup->items);
67$dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
74include DOL_DOCUMENT_ROOT.
'/core/actions_setmoduleoptions.inc.php';
76if ($action ==
'updateMask') {
77 $maskconst =
GETPOST(
'maskconst',
'aZ09');
78 $maskvalue =
GETPOST(
'maskvalue',
'alpha');
80 if ($maskconst && preg_match(
'/_MASK$/', $maskconst)) {
81 $res =
dolibarr_set_const($db, $maskconst, $maskvalue,
'chaine', 0,
'', $conf->entity);
92} elseif ($action ==
'specimen') {
93 $modele =
GETPOST(
'module',
'alpha');
94 $tmpobjectkey =
GETPOST(
'object');
96 $tmpobject =
new $tmpobjectkey($db);
97 $tmpobject->initAsSpecimen();
103 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
104 foreach ($dirmodels as $reldir) {
105 $file =
dol_buildpath($reldir.
"core/modules/webhook/doc/pdf_".$modele.
"_".strtolower($tmpobjectkey).
".modules.php", 0);
106 if (file_exists($file)) {
108 $classname =
"pdf_".$modele.
"_".strtolower($tmpobjectkey);
116 $module =
new $classname($db);
118 if ($module->write_file($tmpobject, $langs) > 0) {
119 header(
"Location: ".DOL_URL_ROOT.
"/document.php?modulepart=webhook-".strtolower($tmpobjectkey).
"&file=SPECIMEN.pdf");
127 dol_syslog($langs->trans(
"ErrorModuleNotFound"), LOG_ERR);
129} elseif ($action ==
'setmod') {
131 $tmpobjectkey =
GETPOST(
'object');
132 if (!empty($tmpobjectkey)) {
133 $constforval =
'WEBHOOK_'.strtoupper($tmpobjectkey).
"_ADDON";
136} elseif ($action ==
'set') {
139} elseif ($action ==
'del') {
142 $tmpobjectkey =
GETPOST(
'object');
143 if (!empty($tmpobjectkey)) {
144 $constforval =
'WEBHOOK_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
150} elseif ($action ==
'setdoc') {
152 $tmpobjectkey =
GETPOST(
'object');
153 if (!empty($tmpobjectkey)) {
154 $constforval =
'WEBHOOK_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
158 $conf->global->$constforval = $value;
167} elseif ($action ==
'unsetdoc') {
168 $tmpobjectkey =
GETPOST(
'object');
169 if (!empty($tmpobjectkey)) {
170 $constforval =
'WEBHOOK_'.strtoupper($tmpobjectkey).
'_ADDON_PDF';
181$form =
new Form($db);
184$page_name =
"WebhookSetup";
186llxHeader(
'', $langs->trans($page_name), $help_url);
189$linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1').
'">'.$langs->trans(
"BackToModuleList").
'</a>';
198echo
'<span class="opacitymedium">'.$langs->trans(
"WebhookSetupPage").
'</span><br><br>';
201if ($action ==
'edit') {
202 if ($useFormSetup && (
float) DOL_VERSION >= 15) {
203 print $formSetup->generateOutput(
true);
205 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
206 print
'<input type="hidden" name="token" value="'.newToken().
'">';
207 print
'<input type="hidden" name="action" value="update">';
209 print
'<table class="noborder centpercent">';
210 print
'<tr class="liste_titre"><td class="titlefield">'.$langs->trans(
"Parameter").
'</td><td>'.$langs->trans(
"Value").
'</td></tr>';
212 foreach ($arrayofparameters as $constname => $val) {
213 if ($val[
'enabled']==1) {
215 print
'<tr class="oddeven"><td>';
216 $tooltiphelp = (($langs->trans($constname .
'Tooltip') != $constname .
'Tooltip') ? $langs->trans($constname .
'Tooltip') :
'');
217 print
'<span id="helplink'.$constname.
'" class="spanforparamtooltip">'.$form->textwithpicto($langs->trans($constname), $tooltiphelp, 1,
'info',
'', 0, 3,
'tootips'.$constname).
'</span>';
220 if ($val[
'type'] ==
'textarea') {
221 print
'<textarea class="flat" name="'.$constname.
'" id="'.$constname.
'" cols="50" rows="5" wrap="soft">' .
"\n";
223 print
"</textarea>\n";
224 } elseif ($val[
'type']==
'html') {
225 require_once DOL_DOCUMENT_ROOT .
'/core/class/doleditor.class.php';
226 $doleditor =
new DolEditor($constname,
getDolGlobalString($constname),
'', 160,
'dolibarr_notes',
'',
false,
false, isModEnabled(
'fckeditor'), ROWS_5,
'90%');
227 $doleditor->Create();
228 } elseif ($val[
'type'] ==
'yesno') {
230 } elseif (preg_match(
'/emailtemplate:/', $val[
'type'])) {
231 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
234 $tmp = explode(
':', $val[
'type']);
235 $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user,
null, 1);
237 $arrayofmessagename = array();
238 if (is_array($formmail->lines_model)) {
239 foreach ($formmail->lines_model as $modelmail) {
242 if (!empty($arrayofmessagename[$modelmail->label])) {
243 $moreonlabel =
' <span class="opacitymedium">(' . $langs->trans(
"SeveralLangugeVariatFound") .
')</span>';
246 $arrayofmessagename[$modelmail->id] = $langs->trans(preg_replace(
'/\(|\)/',
'', $modelmail->label)) . $moreonlabel;
249 print $form->selectarray($constname, $arrayofmessagename,
getDolGlobalString($constname),
'None', 0, 0,
'', 0, 0, 0,
'',
'', 1);
250 } elseif (preg_match(
'/category:/', $val[
'type'])) {
251 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
252 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
255 $tmp = explode(
':', $val[
'type']);
256 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
257 print $formother->select_categories($tmp[1],
getDolGlobalString($constname), $constname, 0, $langs->trans(
'CustomersProspectsCategoriesShort'));
258 } elseif (preg_match(
'/thirdparty_type/', $val[
'type'])) {
259 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
261 print $formcompany->selectProspectCustomerType(
getDolGlobalString($constname), $constname);
262 } elseif ($val[
'type'] ==
'securekey') {
263 print
'<input required="required" type="text" class="flat" id="'.$constname.
'" name="'.$constname.
'" value="'.(
GETPOST($constname,
'alpha') ?
GETPOST($constname,
'alpha') :
getDolGlobalString($constname)).
'" size="40">';
264 if (!empty($conf->use_javascript_ajax)) {
265 print
' '.img_picto($langs->trans(
'Generate'),
'refresh',
'id="generate_token'.$constname.
'" class="linkobject"');
269 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
271 } elseif ($val[
'type'] ==
'product') {
272 if (isModEnabled(
"product") || isModEnabled(
"service")) {
274 $form->select_produits($selected, $constname,
'', 0);
277 print
'<input name="'.$constname.
'" class="flat '.(empty($val[
'css']) ?
'minwidth200' : $val[
'css']).
'" value="'.
getDolGlobalString($constname).
'">';
284 print
'<br><div class="center">';
285 print
'<input class="button button-save" type="submit" value="'.$langs->trans(
"Save").
'">';
293 if ($useFormSetup && (
float) DOL_VERSION >= 15) {
294 if (!empty($formSetup->items)) {
295 print $formSetup->generateOutput();
298 if (!empty($arrayofparameters)) {
299 print
'<table class="noborder centpercent">';
300 print
'<tr class="liste_titre"><td class="titlefield">'.$langs->trans(
"Parameter").
'</td><td>'.$langs->trans(
"Value").
'</td></tr>';
302 foreach ($arrayofparameters as $constname => $val) {
303 if ($val[
'enabled']==1) {
305 print
'<tr class="oddeven"><td>';
306 $tooltiphelp = (($langs->trans($constname .
'Tooltip') != $constname .
'Tooltip') ? $langs->trans($constname .
'Tooltip') :
'');
307 print $form->textwithpicto($langs->trans($constname), $tooltiphelp);
310 if ($val[
'type'] ==
'textarea') {
312 } elseif ($val[
'type']==
'html') {
314 } elseif ($val[
'type'] ==
'yesno') {
315 print ajax_constantonoff($constname);
316 } elseif (preg_match(
'/emailtemplate:/', $val[
'type'])) {
317 include_once DOL_DOCUMENT_ROOT .
'/core/class/html.formmail.class.php';
320 $tmp = explode(
':', $val[
'type']);
322 $template = $formmail->getEMailTemplate($db, $tmp[1], $user, $langs,
getDolGlobalString($constname));
326 print $langs->trans($template->label);
327 } elseif (preg_match(
'/category:/', $val[
'type'])) {
332 } elseif ($result > 0) {
333 $ways = $c->print_all_ways(
' >> ',
'none', 0, 1);
335 foreach ($ways as $way) {
336 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #bbb"') .
'>' . $way .
'</li>';
338 print
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
340 } elseif (preg_match(
'/thirdparty_type/', $val[
'type'])) {
342 print $langs->trans(
"Prospect");
344 print $langs->trans(
"ProspectCustomer");
346 print $langs->trans(
"Customer");
348 print $langs->trans(
"NorProspectNorCustomer");
350 } elseif ($val[
'type'] ==
'product') {
355 } elseif ($resprod < 0) {
369 if ($setupnotempty) {
370 print
'<div class="tabsAction">';
371 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit&token='.newToken().
'">'.$langs->trans(
"Modify").
'</a>';
379$moduledir =
'webhook';
380$myTmpObjects[
'MyObject'] = array(
'includerefgeneration'=>0,
'includedocgeneration'=>0);
383foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
384 if ($myTmpObjectKey ==
'MyObject') {
387 if ($myTmpObjectArray[
'includerefgeneration']) {
393 print
load_fiche_titre($langs->trans(
"NumberingModules", $myTmpObjectKey),
'',
'');
395 print
'<table class="noborder centpercent">';
396 print
'<tr class="liste_titre">';
397 print
'<td>'.$langs->trans(
"Name").
'</td>';
398 print
'<td>'.$langs->trans(
"Description").
'</td>';
399 print
'<td class="nowrap">'.$langs->trans(
"Example").
'</td>';
400 print
'<td class="center" width="60">'.$langs->trans(
"Status").
'</td>';
401 print
'<td class="center" width="16">'.$langs->trans(
"ShortInfo").
'</td>';
406 foreach ($dirmodels as $reldir) {
410 $handle = opendir($dir);
411 if (is_resource($handle)) {
412 while (($file = readdir($handle)) !==
false) {
413 if (strpos($file,
'mod_'.strtolower($myTmpObjectKey).
'_') === 0 && substr($file,
dol_strlen($file) - 3, 3) ==
'php') {
414 $file = substr($file, 0,
dol_strlen($file) - 4);
416 require_once $dir.
'/'.$file.
'.php';
418 $module =
new $file($db);
421 if ($module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
424 if ($module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
428 if ($module->isEnabled()) {
429 dol_include_once(
'/'.$moduledir.
'/class/'.strtolower($myTmpObjectKey).
'.class.php');
431 print
'<tr class="oddeven"><td>'.$module->name.
"</td><td>\n";
432 print $module->info($langs);
436 print
'<td class="nowrap">';
437 $tmp = $module->getExample();
438 if (preg_match(
'/^Error/', $tmp)) {
439 $langs->load(
"errors");
440 print
'<div class="error">'.$langs->trans($tmp).
'</div>';
441 } elseif ($tmp ==
'NotConfigured') {
442 print $langs->trans($tmp);
448 print
'<td class="center">';
449 $constforvar =
'WEBHOOK_'.strtoupper($myTmpObjectKey).
'_ADDON';
451 print
img_picto($langs->trans(
"Activated"),
'switch_on');
453 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=setmod&token='.newToken().
'&object='.strtolower($myTmpObjectKey).
'&value='.urlencode($file).
'">';
454 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
459 $mytmpinstance =
new $myTmpObjectKey($db);
460 $mytmpinstance->initAsSpecimen();
464 $htmltooltip .=
''.$langs->trans(
"Version").
': <b>'.$module->getVersion().
'</b><br>';
466 $nextval = $module->getNextValue($mytmpinstance);
467 if (
"$nextval" != $langs->trans(
"NotAvailable")) {
468 $htmltooltip .=
''.$langs->trans(
"NextValue").
': ';
470 if (preg_match(
'/^Error/', $nextval) || $nextval ==
'NotConfigured') {
471 $nextval = $langs->trans($nextval);
473 $htmltooltip .= $nextval.
'<br>';
475 $htmltooltip .= $langs->trans($module->error).
'<br>';
479 print
'<td class="center">';
480 print $form->textwithpicto(
'', $htmltooltip, 1, 0);
491 print
"</table><br>\n";
494 if ($myTmpObjectArray[
'includedocgeneration']) {
499 $type = strtolower($myTmpObjectKey);
501 print
load_fiche_titre($langs->trans(
"DocumentModules", $myTmpObjectKey),
'',
'');
506 $sql .=
" FROM ".MAIN_DB_PREFIX.
"document_model";
507 $sql .=
" WHERE type = '".$db->escape($type).
"'";
508 $sql .=
" AND entity = ".$conf->entity;
509 $resql = $db->query($sql);
512 $num_rows = $db->num_rows($resql);
513 while ($i < $num_rows) {
514 $array = $db->fetch_array($resql);
515 array_push($def, $array[0]);
522 print
"<table class=\"noborder\" width=\"100%\">\n";
523 print
"<tr class=\"liste_titre\">\n";
524 print
'<td>'.$langs->trans(
"Name").
'</td>';
525 print
'<td>'.$langs->trans(
"Description").
'</td>';
526 print
'<td class="center" width="60">'.$langs->trans(
"Status").
"</td>\n";
527 print
'<td class="center" width="60">'.$langs->trans(
"Default").
"</td>\n";
528 print
'<td class="center" width="38">'.$langs->trans(
"ShortInfo").
'</td>';
529 print
'<td class="center" width="38">'.$langs->trans(
"Preview").
'</td>';
534 foreach ($dirmodels as $reldir) {
535 foreach (array(
'',
'/doc') as $valdir) {
536 $realpath = $reldir.
"core/modules/".$moduledir.$valdir;
540 $handle = opendir($dir);
541 if (is_resource($handle)) {
542 while (($file = readdir($handle)) !==
false) {
548 foreach ($filelist as $file) {
549 if (preg_match(
'/\.modules\.php$/i', $file) && preg_match(
'/^(pdf_|doc_)/', $file)) {
550 if (file_exists($dir.
'/'.$file)) {
551 $name = substr($file, 4,
dol_strlen($file) - 16);
552 $classname = substr($file, 0,
dol_strlen($file) - 12);
554 require_once $dir.
'/'.$file;
555 $module =
new $classname($db);
557 $modulequalified = 1;
558 if ($module->version ==
'development' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 2) {
559 $modulequalified = 0;
561 if ($module->version ==
'experimental' &&
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') < 1) {
562 $modulequalified = 0;
565 if ($modulequalified) {
566 print
'<tr class="oddeven"><td width="100">';
567 print(empty($module->name) ? $name : $module->
name);
569 if (method_exists($module,
'info')) {
570 print $module->info($langs);
572 print $module->description;
577 if (in_array($name, $def)) {
578 print
'<td class="center">'.
"\n";
579 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=del&token='.newToken().
'&value='.urlencode($name).
'">';
580 print
img_picto($langs->trans(
"Enabled"),
'switch_on');
584 print
'<td class="center">'.
"\n";
585 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>';
590 print
'<td class="center">';
591 $constforvar =
'WEBHOOK_'.strtoupper($myTmpObjectKey).
'_ADDON';
595 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>';
597 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>';
602 $htmltooltip =
''.$langs->trans(
"Name").
': '.$module->name;
603 $htmltooltip .=
'<br>'.$langs->trans(
"Type").
': '.($module->type ? $module->type : $langs->trans(
"Unknown"));
604 if ($module->type ==
'pdf') {
605 $htmltooltip .=
'<br>'.$langs->trans(
"Width").
'/'.$langs->trans(
"Height").
': '.$module->page_largeur.
'/'.$module->page_hauteur;
607 $htmltooltip .=
'<br>'.$langs->trans(
"Path").
': '.preg_replace(
'/^\//',
'', $realpath).
'/'.$file;
609 $htmltooltip .=
'<br><br><u>'.$langs->trans(
"FeaturesSupported").
':</u>';
610 $htmltooltip .=
'<br>'.$langs->trans(
"Logo").
': '.
yn($module->option_logo, 1, 1);
611 $htmltooltip .=
'<br>'.$langs->trans(
"MultiLanguage").
': '.
yn($module->option_multilang, 1, 1);
613 print
'<td class="center">';
614 print $form->textwithpicto(
'', $htmltooltip, 1, 0);
618 print
'<td class="center">';
619 if ($module->type ==
'pdf') {
620 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=specimen&module='.$name.
'&object='.$myTmpObjectKey.
'">'.
img_object($langs->trans(
"Preview"),
'pdf').
'</a>';
622 print
img_object($langs->trans(
"PreviewNotAvailable"),
'generic');
640if (empty($setupnotempty)) {
641 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.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage categories.
Class to manage a WYSIWYG editor.
Class to manage products or services.
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_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
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.
$conf db name
Only used if Module[ID]Name translation string is not found.
dolJSToSetRandomPassword($htmlname, $htmlnameofbutton='generate_token', $generic=1)
Ouput javacript to autoset a generated password using default module into a HTML element.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
webhookAdminPrepareHead()
Prepare admin pages header.