webhook.php 24 KB

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