webhook.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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. /**
  19. * \file webhook/admin/webhook.php
  20. * \ingroup webhook
  21. * \brief Webhook setup page.
  22. */
  23. // Load Dolibarr environment
  24. $res = 0;
  25. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  26. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  27. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
  28. }
  29. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  30. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
  31. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  32. $i--; $j--;
  33. }
  34. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
  35. $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
  36. }
  37. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
  38. $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
  39. }
  40. // Try main.inc.php using relative path
  41. if (!$res && file_exists("../main.inc.php")) {
  42. $res = @include "../main.inc.php";
  43. }
  44. if (!$res && file_exists("../../main.inc.php")) {
  45. $res = @include "../../main.inc.php";
  46. }
  47. if (!$res && file_exists("../../../main.inc.php")) {
  48. $res = @include "../../../main.inc.php";
  49. }
  50. if (!$res) {
  51. die("Include of main fails");
  52. }
  53. global $langs, $user;
  54. // Libraries
  55. require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
  56. require_once DOL_DOCUMENT_ROOT.'/webhook/lib/webhook.lib.php';
  57. // Translations
  58. $langs->loadLangs(array("admin", "webhook"));
  59. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  60. $hookmanager->initHooks(array('webhooksetup', 'globalsetup'));
  61. // Access control
  62. if (!$user->admin) {
  63. accessforbidden();
  64. }
  65. // Parameters
  66. $action = GETPOST('action', 'aZ09');
  67. $backtopage = GETPOST('backtopage', 'alpha');
  68. $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
  69. $value = GETPOST('value', 'alpha');
  70. $label = GETPOST('label', 'alpha');
  71. $scandir = GETPOST('scan_dir', 'alpha');
  72. $type = 'myobject';
  73. $arrayofparameters = array(
  74. 'WEBHOOK_MYPARAM1'=>array('type'=>'string', 'css'=>'minwidth500' ,'enabled'=>0),
  75. //'WEBHOOK_MYPARAM2'=>array('type'=>'textarea','enabled'=>1),
  76. //'WEBHOOK_MYPARAM3'=>array('type'=>'category:'.Categorie::TYPE_CUSTOMER, 'enabled'=>1),
  77. //'WEBHOOK_MYPARAM4'=>array('type'=>'emailtemplate:thirdparty', 'enabled'=>1),
  78. //'WEBHOOK_MYPARAM5'=>array('type'=>'yesno', 'enabled'=>1),
  79. //'WEBHOOK_MYPARAM5'=>array('type'=>'thirdparty_type', 'enabled'=>1),
  80. //'WEBHOOK_MYPARAM6'=>array('type'=>'securekey', 'enabled'=>1),
  81. //'WEBHOOK_MYPARAM7'=>array('type'=>'product', 'enabled'=>1),
  82. );
  83. $error = 0;
  84. $setupnotempty = 0;
  85. // Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only
  86. $useFormSetup = 0;
  87. // Convert arrayofparameter into a formSetup object
  88. if ($useFormSetup && (float) DOL_VERSION >= 15) {
  89. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php';
  90. $formSetup = new FormSetup($db);
  91. // you can use the param convertor
  92. $formSetup->addItemsFromParamsArray($arrayofparameters);
  93. // or use the new system see exemple as follow (or use both because you can ;-) )
  94. /*
  95. // Hôte
  96. $item = $formSetup->newItem('NO_PARAM_JUST_TEXT');
  97. $item->fieldOverride = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'];
  98. $item->cssClass = 'minwidth500';
  99. // Setup conf WEBHOOK_MYPARAM1 as a simple string input
  100. $item = $formSetup->newItem('WEBHOOK_MYPARAM1');
  101. // Setup conf WEBHOOK_MYPARAM1 as a simple textarea input but we replace the text of field title
  102. $item = $formSetup->newItem('WEBHOOK_MYPARAM2');
  103. $item->nameText = $item->getNameText().' more html text ';
  104. // Setup conf WEBHOOK_MYPARAM3
  105. $item = $formSetup->newItem('WEBHOOK_MYPARAM3');
  106. $item->setAsThirdpartyType();
  107. // Setup conf WEBHOOK_MYPARAM4 : exemple of quick define write style
  108. $formSetup->newItem('WEBHOOK_MYPARAM4')->setAsYesNo();
  109. // Setup conf WEBHOOK_MYPARAM5
  110. $formSetup->newItem('WEBHOOK_MYPARAM5')->setAsEmailTemplate('thirdparty');
  111. // Setup conf WEBHOOK_MYPARAM6
  112. $formSetup->newItem('WEBHOOK_MYPARAM6')->setAsSecureKey()->enabled = 0; // disabled
  113. // Setup conf WEBHOOK_MYPARAM7
  114. $formSetup->newItem('WEBHOOK_MYPARAM7')->setAsProduct();
  115. */
  116. $setupnotempty = count($formSetup->items);
  117. }
  118. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  119. /*
  120. * Actions
  121. */
  122. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  123. if ($action == 'updateMask') {
  124. $maskconst = GETPOST('maskconst', 'alpha');
  125. $maskvalue = GETPOST('maskvalue', 'alpha');
  126. if ($maskconst) {
  127. $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
  128. if (!($res > 0)) {
  129. $error++;
  130. }
  131. }
  132. if (!$error) {
  133. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  134. } else {
  135. setEventMessages($langs->trans("Error"), null, 'errors');
  136. }
  137. } elseif ($action == 'specimen') {
  138. $modele = GETPOST('module', 'alpha');
  139. $tmpobjectkey = GETPOST('object');
  140. $tmpobject = new $tmpobjectkey($db);
  141. $tmpobject->initAsSpecimen();
  142. // Search template files
  143. $file = ''; $classname = ''; $filefound = 0;
  144. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  145. foreach ($dirmodels as $reldir) {
  146. $file = dol_buildpath($reldir."core/modules/webhook/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
  147. if (file_exists($file)) {
  148. $filefound = 1;
  149. $classname = "pdf_".$modele;
  150. break;
  151. }
  152. }
  153. if ($filefound) {
  154. require_once $file;
  155. $module = new $classname($db);
  156. if ($module->write_file($tmpobject, $langs) > 0) {
  157. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
  158. return;
  159. } else {
  160. setEventMessages($module->error, null, 'errors');
  161. dol_syslog($module->error, LOG_ERR);
  162. }
  163. } else {
  164. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  165. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  166. }
  167. } elseif ($action == 'setmod') {
  168. // TODO Check if numbering module chosen can be activated by calling method canBeActivated
  169. $tmpobjectkey = GETPOST('object');
  170. if (!empty($tmpobjectkey)) {
  171. $constforval = 'WEBHOOK_'.strtoupper($tmpobjectkey)."_ADDON";
  172. dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
  173. }
  174. } elseif ($action == 'set') {
  175. // Activate a model
  176. $ret = addDocumentModel($value, $type, $label, $scandir);
  177. } elseif ($action == 'del') {
  178. $ret = delDocumentModel($value, $type);
  179. if ($ret > 0) {
  180. $tmpobjectkey = GETPOST('object');
  181. if (!empty($tmpobjectkey)) {
  182. $constforval = 'WEBHOOK_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  183. if ($conf->global->$constforval == "$value") {
  184. dolibarr_del_const($db, $constforval, $conf->entity);
  185. }
  186. }
  187. }
  188. } elseif ($action == 'setdoc') {
  189. // Set or unset default model
  190. $tmpobjectkey = GETPOST('object');
  191. if (!empty($tmpobjectkey)) {
  192. $constforval = 'WEBHOOK_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  193. if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
  194. // The constant that was read before the new set
  195. // We therefore requires a variable to have a coherent view
  196. $conf->global->$constforval = $value;
  197. }
  198. // We disable/enable the document template (into llx_document_model table)
  199. $ret = delDocumentModel($value, $type);
  200. if ($ret > 0) {
  201. $ret = addDocumentModel($value, $type, $label, $scandir);
  202. }
  203. }
  204. } elseif ($action == 'unsetdoc') {
  205. $tmpobjectkey = GETPOST('object');
  206. if (!empty($tmpobjectkey)) {
  207. $constforval = 'WEBHOOK_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
  208. dolibarr_del_const($db, $constforval, $conf->entity);
  209. }
  210. }
  211. /*
  212. * View
  213. */
  214. $form = new Form($db);
  215. $help_url = '';
  216. $page_name = "WebhookSetup";
  217. llxHeader('', $langs->trans($page_name), $help_url);
  218. // Subheader
  219. $linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
  220. print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
  221. // Configuration header
  222. $head = webhookAdminPrepareHead();
  223. print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "webhook@webhook");
  224. // Setup page goes here
  225. echo '<span class="opacitymedium">'.$langs->trans("WebhookSetupPage").'</span><br><br>';
  226. if ($action == 'edit') {
  227. if ($useFormSetup && (float) DOL_VERSION >= 15) {
  228. print $formSetup->generateOutput(true);
  229. } else {
  230. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  231. print '<input type="hidden" name="token" value="'.newToken().'">';
  232. print '<input type="hidden" name="action" value="update">';
  233. print '<table class="noborder centpercent">';
  234. print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  235. foreach ($arrayofparameters as $constname => $val) {
  236. if ($val['enabled']==1) {
  237. $setupnotempty++;
  238. print '<tr class="oddeven"><td>';
  239. $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
  240. print '<span id="helplink'.$constname.'" class="spanforparamtooltip">'.$form->textwithpicto($langs->trans($constname), $tooltiphelp, 1, 'info', '', 0, 3, 'tootips'.$constname).'</span>';
  241. print '</td><td>';
  242. if ($val['type'] == 'textarea') {
  243. print '<textarea class="flat" name="'.$constname.'" id="'.$constname.'" cols="50" rows="5" wrap="soft">' . "\n";
  244. print $conf->global->{$constname};
  245. print "</textarea>\n";
  246. } elseif ($val['type']== 'html') {
  247. require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
  248. $doleditor = new DolEditor($constname, $conf->global->{$constname}, '', 160, 'dolibarr_notes', '', false, false, $conf->fckeditor->enabled, ROWS_5, '90%');
  249. $doleditor->Create();
  250. } elseif ($val['type'] == 'yesno') {
  251. print $form->selectyesno($constname, $conf->global->{$constname}, 1);
  252. } elseif (preg_match('/emailtemplate:/', $val['type'])) {
  253. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
  254. $formmail = new FormMail($db);
  255. $tmp = explode(':', $val['type']);
  256. $nboftemplates = $formmail->fetchAllEMailTemplate($tmp[1], $user, null, 1); // We set lang=null to get in priority record with no lang
  257. //$arraydefaultmessage = $formmail->getEMailTemplate($db, $tmp[1], $user, null, 0, 1, '');
  258. $arrayofmessagename = array();
  259. if (is_array($formmail->lines_model)) {
  260. foreach ($formmail->lines_model as $modelmail) {
  261. //var_dump($modelmail);
  262. $moreonlabel = '';
  263. if (!empty($arrayofmessagename[$modelmail->label])) {
  264. $moreonlabel = ' <span class="opacitymedium">(' . $langs->trans("SeveralLangugeVariatFound") . ')</span>';
  265. }
  266. // The 'label' is the key that is unique if we exclude the language
  267. $arrayofmessagename[$modelmail->id] = $langs->trans(preg_replace('/\(|\)/', '', $modelmail->label)) . $moreonlabel;
  268. }
  269. }
  270. print $form->selectarray($constname, $arrayofmessagename, $conf->global->{$constname}, 'None', 0, 0, '', 0, 0, 0, '', '', 1);
  271. } elseif (preg_match('/category:/', $val['type'])) {
  272. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  273. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  274. $formother = new FormOther($db);
  275. $tmp = explode(':', $val['type']);
  276. print img_picto('', 'category', 'class="pictofixedwidth"');
  277. print $formother->select_categories($tmp[1], $conf->global->{$constname}, $constname, 0, $langs->trans('CustomersProspectsCategoriesShort'));
  278. } elseif (preg_match('/thirdparty_type/', $val['type'])) {
  279. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  280. $formcompany = new FormCompany($db);
  281. print $formcompany->selectProspectCustomerType($conf->global->{$constname}, $constname);
  282. } elseif ($val['type'] == 'securekey') {
  283. print '<input required="required" type="text" class="flat" id="'.$constname.'" name="'.$constname.'" value="'.(GETPOST($constname, 'alpha') ?GETPOST($constname, 'alpha') : $conf->global->{$constname}).'" size="40">';
  284. if (!empty($conf->use_javascript_ajax)) {
  285. print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token'.$constname.'" class="linkobject"');
  286. }
  287. if (!empty($conf->use_javascript_ajax)) {
  288. print "\n".'<script type="text/javascript">';
  289. print '$(document).ready(function () {
  290. $("#generate_token'.$constname.'").click(function() {
  291. $.get( "'.DOL_URL_ROOT.'/core/ajax/security.php", {
  292. action: \'getrandompassword\',
  293. generic: true
  294. },
  295. function(token) {
  296. $("#'.$constname.'").val(token);
  297. });
  298. });
  299. });';
  300. print '</script>';
  301. }
  302. } elseif ($val['type'] == 'product') {
  303. if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) {
  304. $selected = (empty($conf->global->$constname) ? '' : $conf->global->$constname);
  305. $form->select_produits($selected, $constname, '', 0);
  306. }
  307. } else {
  308. print '<input name="'.$constname.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.$conf->global->{$constname}.'">';
  309. }
  310. print '</td></tr>';
  311. }
  312. }
  313. print '</table>';
  314. print '<br><div class="center">';
  315. print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
  316. print '</div>';
  317. print '</form>';
  318. }
  319. print '<br>';
  320. } else {
  321. if ($useFormSetup && (float) DOL_VERSION >= 15) {
  322. if (!empty($formSetup->items)) {
  323. print $formSetup->generateOutput();
  324. }
  325. } else {
  326. if (!empty($arrayofparameters)) {
  327. print '<table class="noborder centpercent">';
  328. print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  329. foreach ($arrayofparameters as $constname => $val) {
  330. if ($val['enabled']==1) {
  331. $setupnotempty++;
  332. print '<tr class="oddeven"><td>';
  333. $tooltiphelp = (($langs->trans($constname . 'Tooltip') != $constname . 'Tooltip') ? $langs->trans($constname . 'Tooltip') : '');
  334. print $form->textwithpicto($langs->trans($constname), $tooltiphelp);
  335. print '</td><td>';
  336. if ($val['type'] == 'textarea') {
  337. print dol_nl2br($conf->global->{$constname});
  338. } elseif ($val['type']== 'html') {
  339. print $conf->global->{$constname};
  340. } elseif ($val['type'] == 'yesno') {
  341. print ajax_constantonoff($constname);
  342. } elseif (preg_match('/emailtemplate:/', $val['type'])) {
  343. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
  344. $formmail = new FormMail($db);
  345. $tmp = explode(':', $val['type']);
  346. $template = $formmail->getEMailTemplate($db, $tmp[1], $user, $langs, $conf->global->{$constname});
  347. if ($template<0) {
  348. setEventMessages(null, $formmail->errors, 'errors');
  349. }
  350. print $langs->trans($template->label);
  351. } elseif (preg_match('/category:/', $val['type'])) {
  352. $c = new Categorie($db);
  353. $result = $c->fetch($conf->global->{$constname});
  354. if ($result < 0) {
  355. setEventMessages(null, $c->errors, 'errors');
  356. } elseif ($result > 0 ) {
  357. $ways = $c->print_all_ways(' &gt;&gt; ', 'none', 0, 1); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formated text
  358. $toprint = array();
  359. foreach ($ways as $way) {
  360. $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #bbb"') . '>' . $way . '</li>';
  361. }
  362. print '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
  363. }
  364. } elseif (preg_match('/thirdparty_type/', $val['type'])) {
  365. if ($conf->global->{$constname}==2) {
  366. print $langs->trans("Prospect");
  367. } elseif ($conf->global->{$constname}==3) {
  368. print $langs->trans("ProspectCustomer");
  369. } elseif ($conf->global->{$constname}==1) {
  370. print $langs->trans("Customer");
  371. } elseif ($conf->global->{$constname}==0) {
  372. print $langs->trans("NorProspectNorCustomer");
  373. }
  374. } elseif ($val['type'] == 'product') {
  375. $product = new Product($db);
  376. $resprod = $product->fetch($conf->global->{$constname});
  377. if ($resprod > 0) {
  378. print $product->ref;
  379. } elseif ($resprod < 0) {
  380. setEventMessages(null, $object->errors, "errors");
  381. }
  382. } else {
  383. print $conf->global->{$constname};
  384. }
  385. print '</td></tr>';
  386. }
  387. }
  388. print '</table>';
  389. }
  390. }
  391. if ($setupnotempty) {
  392. print '<div class="tabsAction">';
  393. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
  394. print '</div>';
  395. } else {
  396. //print '<br>'.$langs->trans("NothingToSetup");
  397. }
  398. }
  399. $moduledir = 'webhook';
  400. $myTmpObjects['MyObject'] = array('includerefgeneration'=>0, 'includedocgeneration'=>0);
  401. foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
  402. if ($myTmpObjectKey == 'MyObject') {
  403. continue;
  404. }
  405. if ($myTmpObjectArray['includerefgeneration']) {
  406. /*
  407. * Orders Numbering model
  408. */
  409. $setupnotempty++;
  410. print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
  411. print '<table class="noborder centpercent">';
  412. print '<tr class="liste_titre">';
  413. print '<td>'.$langs->trans("Name").'</td>';
  414. print '<td>'.$langs->trans("Description").'</td>';
  415. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  416. print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
  417. print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  418. print '</tr>'."\n";
  419. clearstatcache();
  420. foreach ($dirmodels as $reldir) {
  421. $dir = dol_buildpath($reldir."core/modules/".$moduledir);
  422. if (is_dir($dir)) {
  423. $handle = opendir($dir);
  424. if (is_resource($handle)) {
  425. while (($file = readdir($handle)) !== false) {
  426. if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
  427. $file = substr($file, 0, dol_strlen($file) - 4);
  428. require_once $dir.'/'.$file.'.php';
  429. $module = new $file($db);
  430. // Show modules according to features level
  431. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  432. continue;
  433. }
  434. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  435. continue;
  436. }
  437. if ($module->isEnabled()) {
  438. dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
  439. print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
  440. print $module->info();
  441. print '</td>';
  442. // Show example of numbering model
  443. print '<td class="nowrap">';
  444. $tmp = $module->getExample();
  445. if (preg_match('/^Error/', $tmp)) {
  446. $langs->load("errors");
  447. print '<div class="error">'.$langs->trans($tmp).'</div>';
  448. } elseif ($tmp == 'NotConfigured') {
  449. print $langs->trans($tmp);
  450. } else {
  451. print $tmp;
  452. }
  453. print '</td>'."\n";
  454. print '<td class="center">';
  455. $constforvar = 'WEBHOOK_'.strtoupper($myTmpObjectKey).'_ADDON';
  456. if ($conf->global->$constforvar == $file) {
  457. print img_picto($langs->trans("Activated"), 'switch_on');
  458. } else {
  459. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&object='.strtolower($myTmpObjectKey).'&value='.urlencode($file).'">';
  460. print img_picto($langs->trans("Disabled"), 'switch_off');
  461. print '</a>';
  462. }
  463. print '</td>';
  464. $mytmpinstance = new $myTmpObjectKey($db);
  465. $mytmpinstance->initAsSpecimen();
  466. // Info
  467. $htmltooltip = '';
  468. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  469. $nextval = $module->getNextValue($mytmpinstance);
  470. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  471. $htmltooltip .= ''.$langs->trans("NextValue").': ';
  472. if ($nextval) {
  473. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
  474. $nextval = $langs->trans($nextval);
  475. }
  476. $htmltooltip .= $nextval.'<br>';
  477. } else {
  478. $htmltooltip .= $langs->trans($module->error).'<br>';
  479. }
  480. }
  481. print '<td class="center">';
  482. print $form->textwithpicto('', $htmltooltip, 1, 0);
  483. print '</td>';
  484. print "</tr>\n";
  485. }
  486. }
  487. }
  488. closedir($handle);
  489. }
  490. }
  491. }
  492. print "</table><br>\n";
  493. }
  494. if ($myTmpObjectArray['includedocgeneration']) {
  495. /*
  496. * Document templates generators
  497. */
  498. $setupnotempty++;
  499. $type = strtolower($myTmpObjectKey);
  500. print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
  501. // Load array def with activated templates
  502. $def = array();
  503. $sql = "SELECT nom";
  504. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  505. $sql .= " WHERE type = '".$db->escape($type)."'";
  506. $sql .= " AND entity = ".$conf->entity;
  507. $resql = $db->query($sql);
  508. if ($resql) {
  509. $i = 0;
  510. $num_rows = $db->num_rows($resql);
  511. while ($i < $num_rows) {
  512. $array = $db->fetch_array($resql);
  513. array_push($def, $array[0]);
  514. $i++;
  515. }
  516. } else {
  517. dol_print_error($db);
  518. }
  519. print "<table class=\"noborder\" width=\"100%\">\n";
  520. print "<tr class=\"liste_titre\">\n";
  521. print '<td>'.$langs->trans("Name").'</td>';
  522. print '<td>'.$langs->trans("Description").'</td>';
  523. print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
  524. print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
  525. print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
  526. print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
  527. print "</tr>\n";
  528. clearstatcache();
  529. foreach ($dirmodels as $reldir) {
  530. foreach (array('', '/doc') as $valdir) {
  531. $realpath = $reldir."core/modules/".$moduledir.$valdir;
  532. $dir = dol_buildpath($realpath);
  533. if (is_dir($dir)) {
  534. $handle = opendir($dir);
  535. if (is_resource($handle)) {
  536. while (($file = readdir($handle)) !== false) {
  537. $filelist[] = $file;
  538. }
  539. closedir($handle);
  540. arsort($filelist);
  541. foreach ($filelist as $file) {
  542. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
  543. if (file_exists($dir.'/'.$file)) {
  544. $name = substr($file, 4, dol_strlen($file) - 16);
  545. $classname = substr($file, 0, dol_strlen($file) - 12);
  546. require_once $dir.'/'.$file;
  547. $module = new $classname($db);
  548. $modulequalified = 1;
  549. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  550. $modulequalified = 0;
  551. }
  552. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  553. $modulequalified = 0;
  554. }
  555. if ($modulequalified) {
  556. print '<tr class="oddeven"><td width="100">';
  557. print (empty($module->name) ? $name : $module->name);
  558. print "</td><td>\n";
  559. if (method_exists($module, 'info')) {
  560. print $module->info($langs);
  561. } else {
  562. print $module->description;
  563. }
  564. print '</td>';
  565. // Active
  566. if (in_array($name, $def)) {
  567. print '<td class="center">'."\n";
  568. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
  569. print img_picto($langs->trans("Enabled"), 'switch_on');
  570. print '</a>';
  571. print '</td>';
  572. } else {
  573. print '<td class="center">'."\n";
  574. 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>';
  575. print "</td>";
  576. }
  577. // Default
  578. print '<td class="center">';
  579. $constforvar = 'WEBHOOK_'.strtoupper($myTmpObjectKey).'_ADDON';
  580. if ($conf->global->$constforvar == $name) {
  581. //print img_picto($langs->trans("Default"), 'on');
  582. // Even if choice is the default value, we allow to disable it. Replace this with previous line if you need to disable unset
  583. 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>';
  584. } else {
  585. 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>';
  586. }
  587. print '</td>';
  588. // Info
  589. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  590. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  591. if ($module->type == 'pdf') {
  592. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  593. }
  594. $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
  595. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  596. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  597. $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
  598. print '<td class="center">';
  599. print $form->textwithpicto('', $htmltooltip, 1, 0);
  600. print '</td>';
  601. // Preview
  602. print '<td class="center">';
  603. if ($module->type == 'pdf') {
  604. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
  605. } else {
  606. print img_object($langs->trans("PreviewNotAvailable"), 'generic');
  607. }
  608. print '</td>';
  609. print "</tr>\n";
  610. }
  611. }
  612. }
  613. }
  614. }
  615. }
  616. }
  617. }
  618. print '</table>';
  619. }
  620. }
  621. if (empty($setupnotempty)) {
  622. print '<br>'.$langs->trans("NothingToSetup");
  623. }
  624. // Page end
  625. print dol_get_fiche_end();
  626. llxFooter();
  627. $db->close();