dolibarr  16.0.5
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', 'alpha');
154  $maskvalue = GETPOST('maskvalue', 'alpha');
155 
156  if ($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 $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';
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  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\',
347  generic: true
348  },
349  function(token) {
350  $("#'.$constname.'").val(token);
351  });
352  });
353  });';
354  print '</script>';
355  }
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);
360  }
361  } else {
362  print '<input name="'.$constname.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.$conf->global->{$constname}.'">';
363  }
364  print '</td></tr>';
365  }
366  }
367  print '</table>';
368 
369  print '<br><div class="center">';
370  print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
371  print '</div>';
372 
373  print '</form>';
374  }
375 
376  print '<br>';
377 } else {
378  if ($useFormSetup && (float) DOL_VERSION >= 15) {
379  if (!empty($formSetup->items)) {
380  print $formSetup->generateOutput();
381  }
382  } else {
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>';
386 
387  foreach ($arrayofparameters as $constname => $val) {
388  if ($val['enabled']==1) {
389  $setupnotempty++;
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);
393  print '</td><td>';
394 
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') {
400  print ajax_constantonoff($constname);
401  } elseif (preg_match('/emailtemplate:/', $val['type'])) {
402  include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
403  $formmail = new FormMail($db);
404 
405  $tmp = explode(':', $val['type']);
406 
407  $template = $formmail->getEMailTemplate($db, $tmp[1], $user, $langs, $conf->global->{$constname});
408  if ($template<0) {
409  setEventMessages(null, $formmail->errors, 'errors');
410  }
411  print $langs->trans($template->label);
412  } elseif (preg_match('/category:/', $val['type'])) {
413  $c = new Categorie($db);
414  $result = $c->fetch($conf->global->{$constname});
415  if ($result < 0) {
416  setEventMessages(null, $c->errors, 'errors');
417  } elseif ($result > 0 ) {
418  $ways = $c->print_all_ways(' &gt;&gt; ', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formated text
419  $toprint = array();
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>';
422  }
423  print '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
424  }
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");
434  }
435  } elseif ($val['type'] == 'product') {
436  $product = new Product($db);
437  $resprod = $product->fetch($conf->global->{$constname});
438  if ($resprod > 0) {
439  print $product->ref;
440  } elseif ($resprod < 0) {
441  setEventMessages(null, $object->errors, "errors");
442  }
443  } else {
444  print $conf->global->{$constname};
445  }
446  print '</td></tr>';
447  }
448  }
449 
450  print '</table>';
451  }
452  }
453 
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>';
457  print '</div>';
458  } else {
459  //print '<br>'.$langs->trans("NothingToSetup");
460  }
461 }
462 
463 
464 $moduledir = 'webhook';
465 $myTmpObjects['MyObject'] = array('includerefgeneration'=>0, 'includedocgeneration'=>0);
466 
467 
468 foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
469  if ($myTmpObjectKey == 'MyObject') {
470  continue;
471  }
472  if ($myTmpObjectArray['includerefgeneration']) {
473  /*
474  * Orders Numbering model
475  */
476  $setupnotempty++;
477 
478  print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
479 
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>';
487  print '</tr>'."\n";
488 
489  clearstatcache();
490 
491  foreach ($dirmodels as $reldir) {
492  $dir = dol_buildpath($reldir."core/modules/".$moduledir);
493 
494  if (is_dir($dir)) {
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);
500 
501  require_once $dir.'/'.$file.'.php';
502 
503  $module = new $file($db);
504 
505  // Show modules according to features level
506  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
507  continue;
508  }
509  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
510  continue;
511  }
512 
513  if ($module->isEnabled()) {
514  dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
515 
516  print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
517  print $module->info();
518  print '</td>';
519 
520  // Show example of numbering model
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);
528  } else {
529  print $tmp;
530  }
531  print '</td>'."\n";
532 
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');
537  } else {
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');
540  print '</a>';
541  }
542  print '</td>';
543 
544  $mytmpinstance = new $myTmpObjectKey($db);
545  $mytmpinstance->initAsSpecimen();
546 
547  // Info
548  $htmltooltip = '';
549  $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
550 
551  $nextval = $module->getNextValue($mytmpinstance);
552  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
553  $htmltooltip .= ''.$langs->trans("NextValue").': ';
554  if ($nextval) {
555  if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
556  $nextval = $langs->trans($nextval);
557  }
558  $htmltooltip .= $nextval.'<br>';
559  } else {
560  $htmltooltip .= $langs->trans($module->error).'<br>';
561  }
562  }
563 
564  print '<td class="center">';
565  print $form->textwithpicto('', $htmltooltip, 1, 0);
566  print '</td>';
567 
568  print "</tr>\n";
569  }
570  }
571  }
572  closedir($handle);
573  }
574  }
575  }
576  print "</table><br>\n";
577  }
578 
579  if ($myTmpObjectArray['includedocgeneration']) {
580  /*
581  * Document templates generators
582  */
583  $setupnotempty++;
584  $type = strtolower($myTmpObjectKey);
585 
586  print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
587 
588  // Load array def with activated templates
589  $def = array();
590  $sql = "SELECT nom";
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);
595  if ($resql) {
596  $i = 0;
597  $num_rows = $db->num_rows($resql);
598  while ($i < $num_rows) {
599  $array = $db->fetch_array($resql);
600  array_push($def, $array[0]);
601  $i++;
602  }
603  } else {
604  dol_print_error($db);
605  }
606 
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>';
615  print "</tr>\n";
616 
617  clearstatcache();
618 
619  foreach ($dirmodels as $reldir) {
620  foreach (array('', '/doc') as $valdir) {
621  $realpath = $reldir."core/modules/".$moduledir.$valdir;
622  $dir = dol_buildpath($realpath);
623 
624  if (is_dir($dir)) {
625  $handle = opendir($dir);
626  if (is_resource($handle)) {
627  while (($file = readdir($handle)) !== false) {
628  $filelist[] = $file;
629  }
630  closedir($handle);
631  arsort($filelist);
632 
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);
638 
639  require_once $dir.'/'.$file;
640  $module = new $classname($db);
641 
642  $modulequalified = 1;
643  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
644  $modulequalified = 0;
645  }
646  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
647  $modulequalified = 0;
648  }
649 
650  if ($modulequalified) {
651  print '<tr class="oddeven"><td width="100">';
652  print (empty($module->name) ? $name : $module->name);
653  print "</td><td>\n";
654  if (method_exists($module, 'info')) {
655  print $module->info($langs);
656  } else {
657  print $module->description;
658  }
659  print '</td>';
660 
661  // Active
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');
666  print '</a>';
667  print '</td>';
668  } else {
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>';
671  print "</td>";
672  }
673 
674  // Default
675  print '<td class="center">';
676  $constforvar = 'WEBHOOK_'.strtoupper($myTmpObjectKey).'_ADDON';
677  if ($conf->global->$constforvar == $name) {
678  //print img_picto($langs->trans("Default"), 'on');
679  // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
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).'&amp;type='.urlencode($type).'" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
681  } else {
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>';
683  }
684  print '</td>';
685 
686  // Info
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;
691  }
692  $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
693 
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);
697 
698  print '<td class="center">';
699  print $form->textwithpicto('', $htmltooltip, 1, 0);
700  print '</td>';
701 
702  // Preview
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>';
706  } else {
707  print img_object($langs->trans("PreviewNotAvailable"), 'generic');
708  }
709  print '</td>';
710 
711  print "</tr>\n";
712  }
713  }
714  }
715  }
716  }
717  }
718  }
719  }
720 
721  print '</table>';
722  }
723 }
724 
725 if (empty($setupnotempty)) {
726  print '<br>'.$langs->trans("NothingToSetup");
727 }
728 
729 // Page end
730 print dol_get_fiche_end();
731 
732 llxFooter();
733 $db->close();
yn
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Definition: functions.lib.php:6491
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
dolibarr_del_const
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:552
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_nl2br
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
Definition: functions.lib.php:6963
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_include_once
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
Definition: functions.lib.php:1033
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
FormOther
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formother.class.php:39
Categorie
Class to manage categories.
Definition: categorie.class.php:47
$help_url
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:116
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
delDocumentModel
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1894
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
FormSetup
This class help you create setup render.
Definition: html.formsetup.class.php:22
ajax_constantonoff
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0, $setzeroinsteadofdel=0, $suffix='', $mode='')
On/off button for constant.
Definition: ajax.lib.php:573
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
webhookAdminPrepareHead
webhookAdminPrepareHead()
Prepare admin pages header.
Definition: webhook.lib.php:29
dolibarr_set_const
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:627
addDocumentModel
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
Definition: admin.lib.php:1863
Product
Class to manage products or services.
Definition: product.class.php:46
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
FormMail
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
Definition: html.formmail.class.php:38
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
DolEditor
Class to manage a WYSIWYG editor.
Definition: doleditor.class.php:30