dolibarr  x.y.z
webhook.php
1 <?php
2 /* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2022 SuperAdmin <test@dolibarr.com>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 // Load Dolibarr environment
26 $res = 0;
27 // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
28 if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
29  $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
30 }
31 // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
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]) {
34  $i--; $j--;
35 }
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";
38 }
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";
41 }
42 // Try main.inc.php using relative path
43 if (!$res && file_exists("../main.inc.php")) {
44  $res = @include "../main.inc.php";
45 }
46 if (!$res && file_exists("../../main.inc.php")) {
47  $res = @include "../../main.inc.php";
48 }
49 if (!$res && file_exists("../../../main.inc.php")) {
50  $res = @include "../../../main.inc.php";
51 }
52 if (!$res) {
53  die("Include of main fails");
54 }
55 
56 global $langs, $user;
57 
58 // Libraries
59 require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
60 require_once DOL_DOCUMENT_ROOT.'/webhook/lib/webhook.lib.php';
61 
62 // Translations
63 $langs->loadLangs(array("admin", "webhook"));
64 
65 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
66 $hookmanager->initHooks(array('webhooksetup', 'globalsetup'));
67 
68 // Access control
69 if (!$user->admin) {
71 }
72 
73 // Parameters
74 $action = GETPOST('action', 'aZ09');
75 $backtopage = GETPOST('backtopage', 'alpha');
76 $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
77 
78 $value = GETPOST('value', 'alpha');
79 $label = GETPOST('label', 'alpha');
80 $scandir = GETPOST('scan_dir', 'alpha');
81 $type = 'myobject';
82 
83 $arrayofparameters = array(
84  'WEBHOOK_MYPARAM1'=>array('type'=>'string', 'css'=>'minwidth500' ,'enabled'=>0),
85  //'WEBHOOK_MYPARAM2'=>array('type'=>'textarea','enabled'=>1),
86  //'WEBHOOK_MYPARAM3'=>array('type'=>'category:'.Categorie::TYPE_CUSTOMER, 'enabled'=>1),
87  //'WEBHOOK_MYPARAM4'=>array('type'=>'emailtemplate:thirdparty', 'enabled'=>1),
88  //'WEBHOOK_MYPARAM5'=>array('type'=>'yesno', 'enabled'=>1),
89  //'WEBHOOK_MYPARAM5'=>array('type'=>'thirdparty_type', 'enabled'=>1),
90  //'WEBHOOK_MYPARAM6'=>array('type'=>'securekey', 'enabled'=>1),
91  //'WEBHOOK_MYPARAM7'=>array('type'=>'product', 'enabled'=>1),
92 );
93 
94 $error = 0;
95 $setupnotempty = 0;
96 
97 // Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only
98 $useFormSetup = 0;
99 // Convert arrayofparameter into a formSetup object
100 if ($useFormSetup && (float) DOL_VERSION >= 15) {
101  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php';
102  $formSetup = new FormSetup($db);
103 
104  // you can use the param convertor
105  $formSetup->addItemsFromParamsArray($arrayofparameters);
106 
107  // or use the new system see exemple as follow (or use both because you can ;-) )
108 
109  /*
110  // Hôte
111  $item = $formSetup->newItem('NO_PARAM_JUST_TEXT');
112  $item->fieldOverride = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'];
113  $item->cssClass = 'minwidth500';
114 
115  // Setup conf WEBHOOK_MYPARAM1 as a simple string input
116  $item = $formSetup->newItem('WEBHOOK_MYPARAM1');
117 
118  // Setup conf WEBHOOK_MYPARAM1 as a simple textarea input but we replace the text of field title
119  $item = $formSetup->newItem('WEBHOOK_MYPARAM2');
120  $item->nameText = $item->getNameText().' more html text ';
121 
122  // Setup conf WEBHOOK_MYPARAM3
123  $item = $formSetup->newItem('WEBHOOK_MYPARAM3');
124  $item->setAsThirdpartyType();
125 
126  // Setup conf WEBHOOK_MYPARAM4 : exemple of quick define write style
127  $formSetup->newItem('WEBHOOK_MYPARAM4')->setAsYesNo();
128 
129  // Setup conf WEBHOOK_MYPARAM5
130  $formSetup->newItem('WEBHOOK_MYPARAM5')->setAsEmailTemplate('thirdparty');
131 
132  // Setup conf WEBHOOK_MYPARAM6
133  $formSetup->newItem('WEBHOOK_MYPARAM6')->setAsSecureKey()->enabled = 0; // disabled
134 
135  // Setup conf WEBHOOK_MYPARAM7
136  $formSetup->newItem('WEBHOOK_MYPARAM7')->setAsProduct();
137  */
138 
139  $setupnotempty = count($formSetup->items);
140 }
141 
142 
143 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
144 
145 
146 /*
147  * Actions
148  */
149 
150 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
151 
152 if ($action == 'updateMask') {
153  $maskconst = GETPOST('maskconst', 'aZ09');
154  $maskvalue = GETPOST('maskvalue', 'alpha');
155 
156  if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
157  $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
158  if (!($res > 0)) {
159  $error++;
160  }
161  }
162 
163  if (!$error) {
164  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
165  } else {
166  setEventMessages($langs->trans("Error"), null, 'errors');
167  }
168 } elseif ($action == 'specimen') {
169  $modele = GETPOST('module', 'alpha');
170  $tmpobjectkey = GETPOST('object');
171 
172  $tmpobject = new $tmpobjectkey($db);
173  $tmpobject->initAsSpecimen();
174 
175  // Search template files
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)) {
181  $filefound = 1;
182  $classname = "pdf_".$modele;
183  break;
184  }
185  }
186 
187  if ($filefound) {
188  require_once $file;
189 
190  $module = new $classname($db);
191 
192  if ($module->write_file($tmpobject, $langs) > 0) {
193  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
194  return;
195  } else {
196  setEventMessages($module->error, null, 'errors');
197  dol_syslog($module->error, LOG_ERR);
198  }
199  } else {
200  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
201  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
202  }
203 } elseif ($action == 'setmod') {
204  // TODO Check if numbering module chosen can be activated by calling method canBeActivated
205  $tmpobjectkey = GETPOST('object');
206  if (!empty($tmpobjectkey)) {
207  $constforval = 'WEBHOOK_'.strtoupper($tmpobjectkey)."_ADDON";
208  dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
209  }
210 } elseif ($action == 'set') {
211  // Activate a model
212  $ret = addDocumentModel($value, $type, $label, $scandir);
213 } elseif ($action == 'del') {
214  $ret = delDocumentModel($value, $type);
215  if ($ret > 0) {
216  $tmpobjectkey = GETPOST('object');
217  if (!empty($tmpobjectkey)) {
218  $constforval = 'WEBHOOK_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
219  if ($conf->global->$constforval == "$value") {
220  dolibarr_del_const($db, $constforval, $conf->entity);
221  }
222  }
223  }
224 } elseif ($action == 'setdoc') {
225  // Set or unset default model
226  $tmpobjectkey = GETPOST('object');
227  if (!empty($tmpobjectkey)) {
228  $constforval = 'WEBHOOK_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
229  if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
230  // The constant that was read before the new set
231  // We therefore requires a variable to have a coherent view
232  $conf->global->$constforval = $value;
233  }
234 
235  // We disable/enable the document template (into llx_document_model table)
236  $ret = delDocumentModel($value, $type);
237  if ($ret > 0) {
238  $ret = addDocumentModel($value, $type, $label, $scandir);
239  }
240  }
241 } elseif ($action == 'unsetdoc') {
242  $tmpobjectkey = GETPOST('object');
243  if (!empty($tmpobjectkey)) {
244  $constforval = 'WEBHOOK_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
245  dolibarr_del_const($db, $constforval, $conf->entity);
246  }
247 }
248 
249 
250 
251 /*
252  * View
253  */
254 
255 $form = new Form($db);
256 
257 $help_url = '';
258 $page_name = "WebhookSetup";
259 
260 llxHeader('', $langs->trans($page_name), $help_url);
261 
262 // Subheader
263 $linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
264 
265 print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
266 
267 // Configuration header
268 $head = webhookAdminPrepareHead();
269 print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "webhook@webhook");
270 
271 // Setup page goes here
272 echo '<span class="opacitymedium">'.$langs->trans("WebhookSetupPage").'</span><br><br>';
273 
274 
275 if ($action == 'edit') {
276  if ($useFormSetup && (float) DOL_VERSION >= 15) {
277  print $formSetup->generateOutput(true);
278  } else {
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">';
282 
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>';
285 
286  foreach ($arrayofparameters as $constname => $val) {
287  if ($val['enabled']==1) {
288  $setupnotempty++;
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>';
292  print '</td><td>';
293 
294  if ($val['type'] == 'textarea') {
295  print '<textarea class="flat" name="'.$constname.'" id="'.$constname.'" cols="50" rows="5" wrap="soft">' . "\n";
296  print getDolGlobalString($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, getDolGlobalString($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, getDolGlobalString($constname), 1);
304  } elseif (preg_match('/emailtemplate:/', $val['type'])) {
305  include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
306  $formmail = new FormMail($db);
307 
308  $tmp = explode(':', $val['type']);
309  $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, 1); // We set lang=null to get in priority record with no lang
310  //$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, '');
311  $arrayofmessagename = array();
312  if (is_array($formmail->lines_model)) {
313  foreach ($formmail->lines_model as $modelmail) {
314  //var_dump($modelmail);
315  $moreonlabel = '';
316  if (!empty($arrayofmessagename[$modelmail->label])) {
317  $moreonlabel = ' <span class="opacitymedium">(' . $langs->trans("SeveralLangugeVariatFound") . ')</span>';
318  }
319  // The 'label' is the key that is unique if we exclude the language
320  $arrayofmessagename[$modelmail->id] = $langs->trans(preg_replace('/\‍(|\‍)/', '', $modelmail->label)) . $moreonlabel;
321  }
322  }
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';
327  $formother = new FormOther($db);
328 
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';
334  $formcompany = new FormCompany($db);
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 '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token'.$constname.'" class="linkobject"');
340  }
341 
342  // Add button to autosuggest a key
343  include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
344  print dolJSToSetRandomPassword($constname, 'generate_token'.$constname);
345  } elseif ($val['type'] == 'product') {
346  if (isModEnabled("product") || isModEnabled("service")) {
347  $selected = (empty($conf->global->$constname) ? '' : $conf->global->$constname);
348  $form->select_produits($selected, $constname, '', 0);
349  }
350  } else {
351  print '<input name="'.$constname.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.$conf->global->{$constname}.'">';
352  }
353  print '</td></tr>';
354  }
355  }
356  print '</table>';
357 
358  print '<br><div class="center">';
359  print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
360  print '</div>';
361 
362  print '</form>';
363  }
364 
365  print '<br>';
366 } else {
367  if ($useFormSetup && (float) DOL_VERSION >= 15) {
368  if (!empty($formSetup->items)) {
369  print $formSetup->generateOutput();
370  }
371  } else {
372  if (!empty($arrayofparameters)) {
373  print '<table class="noborder centpercent">';
374  print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
375 
376  foreach ($arrayofparameters as $constname => $val) {
377  if ($val['enabled']==1) {
378  $setupnotempty++;
379  print '<tr class="oddeven"><td>';
380  $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
381  print $form->textwithpicto($langs->trans($constname), $tooltiphelp);
382  print '</td><td>';
383 
384  if ($val['type'] == 'textarea') {
385  print dol_nl2br(getDolGlobalString($constname));
386  } elseif ($val['type']== 'html') {
387  print getDolGlobalString($constname);
388  } elseif ($val['type'] == 'yesno') {
389  print ajax_constantonoff($constname);
390  } elseif (preg_match('/emailtemplate:/', $val['type'])) {
391  include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
392  $formmail = new FormMail($db);
393 
394  $tmp = explode(':', $val['type']);
395 
396  $template = $formmail->getEMailTemplate($db, $tmp[1], $user, $langs, getDolGlobalString($constname));
397  if ($template<0) {
398  setEventMessages(null, $formmail->errors, 'errors');
399  }
400  print $langs->trans($template->label);
401  } elseif (preg_match('/category:/', $val['type'])) {
402  $c = new Categorie($db);
403  $result = $c->fetch(getDolGlobalString($constname));
404  if ($result < 0) {
405  setEventMessages(null, $c->errors, 'errors');
406  } elseif ($result > 0 ) {
407  $ways = $c->print_all_ways(' &gt;&gt; ', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formated text
408  $toprint = array();
409  foreach ($ways as $way) {
410  $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #bbb"') . '>' . $way . '</li>';
411  }
412  print '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
413  }
414  } elseif (preg_match('/thirdparty_type/', $val['type'])) {
415  if (getDolGlobalInt($constname)==2) {
416  print $langs->trans("Prospect");
417  } elseif (getDolGlobalInt($constname)==3) {
418  print $langs->trans("ProspectCustomer");
419  } elseif (getDolGlobalInt($constname)==1) {
420  print $langs->trans("Customer");
421  } elseif (getDolGlobalInt($constname)==0) {
422  print $langs->trans("NorProspectNorCustomer");
423  }
424  } elseif ($val['type'] == 'product') {
425  $product = new Product($db);
426  $resprod = $product->fetch(getDolGlobalInt($constname));
427  if ($resprod > 0) {
428  print $product->ref;
429  } elseif ($resprod < 0) {
430  setEventMessages(null, $object->errors, "errors");
431  }
432  } else {
433  print getDolGlobalString($constname);
434  }
435  print '</td></tr>';
436  }
437  }
438 
439  print '</table>';
440  }
441  }
442 
443  if ($setupnotempty) {
444  print '<div class="tabsAction">';
445  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
446  print '</div>';
447  } else {
448  //print '<br>'.$langs->trans("NothingToSetup");
449  }
450 }
451 
452 
453 $moduledir = 'webhook';
454 $myTmpObjects['MyObject'] = array('includerefgeneration'=>0, 'includedocgeneration'=>0);
455 
456 
457 foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
458  if ($myTmpObjectKey == 'MyObject') {
459  continue;
460  }
461  if ($myTmpObjectArray['includerefgeneration']) {
462  /*
463  * Orders Numbering model
464  */
465  $setupnotempty++;
466 
467  print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
468 
469  print '<table class="noborder centpercent">';
470  print '<tr class="liste_titre">';
471  print '<td>'.$langs->trans("Name").'</td>';
472  print '<td>'.$langs->trans("Description").'</td>';
473  print '<td class="nowrap">'.$langs->trans("Example").'</td>';
474  print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
475  print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
476  print '</tr>'."\n";
477 
478  clearstatcache();
479 
480  foreach ($dirmodels as $reldir) {
481  $dir = dol_buildpath($reldir."core/modules/".$moduledir);
482 
483  if (is_dir($dir)) {
484  $handle = opendir($dir);
485  if (is_resource($handle)) {
486  while (($file = readdir($handle)) !== false) {
487  if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
488  $file = substr($file, 0, dol_strlen($file) - 4);
489 
490  require_once $dir.'/'.$file.'.php';
491 
492  $module = new $file($db);
493 
494  // Show modules according to features level
495  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
496  continue;
497  }
498  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
499  continue;
500  }
501 
502  if ($module->isEnabled()) {
503  dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
504 
505  print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
506  print $module->info();
507  print '</td>';
508 
509  // Show example of numbering model
510  print '<td class="nowrap">';
511  $tmp = $module->getExample();
512  if (preg_match('/^Error/', $tmp)) {
513  $langs->load("errors");
514  print '<div class="error">'.$langs->trans($tmp).'</div>';
515  } elseif ($tmp == 'NotConfigured') {
516  print $langs->trans($tmp);
517  } else {
518  print $tmp;
519  }
520  print '</td>'."\n";
521 
522  print '<td class="center">';
523  $constforvar = 'WEBHOOK_'.strtoupper($myTmpObjectKey).'_ADDON';
524  if ($conf->global->$constforvar == $file) {
525  print img_picto($langs->trans("Activated"), 'switch_on');
526  } else {
527  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
528  print img_picto($langs->trans("Disabled"), 'switch_off');
529  print '</a>';
530  }
531  print '</td>';
532 
533  $mytmpinstance = new $myTmpObjectKey($db);
534  $mytmpinstance->initAsSpecimen();
535 
536  // Info
537  $htmltooltip = '';
538  $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
539 
540  $nextval = $module->getNextValue($mytmpinstance);
541  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
542  $htmltooltip .= ''.$langs->trans("NextValue").': ';
543  if ($nextval) {
544  if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
545  $nextval = $langs->trans($nextval);
546  }
547  $htmltooltip .= $nextval.'<br>';
548  } else {
549  $htmltooltip .= $langs->trans($module->error).'<br>';
550  }
551  }
552 
553  print '<td class="center">';
554  print $form->textwithpicto('', $htmltooltip, 1, 0);
555  print '</td>';
556 
557  print "</tr>\n";
558  }
559  }
560  }
561  closedir($handle);
562  }
563  }
564  }
565  print "</table><br>\n";
566  }
567 
568  if ($myTmpObjectArray['includedocgeneration']) {
569  /*
570  * Document templates generators
571  */
572  $setupnotempty++;
573  $type = strtolower($myTmpObjectKey);
574 
575  print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
576 
577  // Load array def with activated templates
578  $def = array();
579  $sql = "SELECT nom";
580  $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
581  $sql .= " WHERE type = '".$db->escape($type)."'";
582  $sql .= " AND entity = ".$conf->entity;
583  $resql = $db->query($sql);
584  if ($resql) {
585  $i = 0;
586  $num_rows = $db->num_rows($resql);
587  while ($i < $num_rows) {
588  $array = $db->fetch_array($resql);
589  array_push($def, $array[0]);
590  $i++;
591  }
592  } else {
593  dol_print_error($db);
594  }
595 
596  print "<table class=\"noborder\" width=\"100%\">\n";
597  print "<tr class=\"liste_titre\">\n";
598  print '<td>'.$langs->trans("Name").'</td>';
599  print '<td>'.$langs->trans("Description").'</td>';
600  print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
601  print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
602  print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
603  print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
604  print "</tr>\n";
605 
606  clearstatcache();
607 
608  foreach ($dirmodels as $reldir) {
609  foreach (array('', '/doc') as $valdir) {
610  $realpath = $reldir."core/modules/".$moduledir.$valdir;
611  $dir = dol_buildpath($realpath);
612 
613  if (is_dir($dir)) {
614  $handle = opendir($dir);
615  if (is_resource($handle)) {
616  while (($file = readdir($handle)) !== false) {
617  $filelist[] = $file;
618  }
619  closedir($handle);
620  arsort($filelist);
621 
622  foreach ($filelist as $file) {
623  if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
624  if (file_exists($dir.'/'.$file)) {
625  $name = substr($file, 4, dol_strlen($file) - 16);
626  $classname = substr($file, 0, dol_strlen($file) - 12);
627 
628  require_once $dir.'/'.$file;
629  $module = new $classname($db);
630 
631  $modulequalified = 1;
632  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
633  $modulequalified = 0;
634  }
635  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
636  $modulequalified = 0;
637  }
638 
639  if ($modulequalified) {
640  print '<tr class="oddeven"><td width="100">';
641  print (empty($module->name) ? $name : $module->name);
642  print "</td><td>\n";
643  if (method_exists($module, 'info')) {
644  print $module->info($langs);
645  } else {
646  print $module->description;
647  }
648  print '</td>';
649 
650  // Active
651  if (in_array($name, $def)) {
652  print '<td class="center">'."\n";
653  print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
654  print img_picto($langs->trans("Enabled"), 'switch_on');
655  print '</a>';
656  print '</td>';
657  } else {
658  print '<td class="center">'."\n";
659  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>';
660  print "</td>";
661  }
662 
663  // Default
664  print '<td class="center">';
665  $constforvar = 'WEBHOOK_'.strtoupper($myTmpObjectKey).'_ADDON';
666  if ($conf->global->$constforvar == $name) {
667  //print img_picto($langs->trans("Default"), 'on');
668  // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
669  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).'&amp;type='.urlencode($type).'" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
670  } else {
671  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>';
672  }
673  print '</td>';
674 
675  // Info
676  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
677  $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
678  if ($module->type == 'pdf') {
679  $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
680  }
681  $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
682 
683  $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
684  $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
685  $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
686 
687  print '<td class="center">';
688  print $form->textwithpicto('', $htmltooltip, 1, 0);
689  print '</td>';
690 
691  // Preview
692  print '<td class="center">';
693  if ($module->type == 'pdf') {
694  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
695  } else {
696  print img_object($langs->trans("PreviewNotAvailable"), 'generic');
697  }
698  print '</td>';
699 
700  print "</tr>\n";
701  }
702  }
703  }
704  }
705  }
706  }
707  }
708  }
709 
710  print '</table>';
711  }
712 }
713 
714 if (empty($setupnotempty)) {
715  print '<br>'.$langs->trans("NothingToSetup");
716 }
717 
718 // Page end
719 print dol_get_fiche_end();
720 
721 llxFooter();
722 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
Definition: admin.lib.php:1888
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).
Definition: admin.lib.php:632
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:556
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1919
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0, $setzeroinsteadofdel=0, $suffix='', $mode='', $morecss='')
On/off button for constant.
Definition: ajax.lib.php:601
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage categories.
Class to manage a WYSIWYG editor.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
Classe permettant la generation de composants html autre Only common components are here.
This class help you create setup render.
Class to manage products or services.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
getDolGlobalInt($key, $default=0)
Return 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)
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dolJSToSetRandomPassword($htmlname, $htmlnameofbutton='generate_token')
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.
Definition: webhook.lib.php:29