webhook.php 24 KB

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