webhook.php 24 KB

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