modulehelp.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2017 Regis Houssin <regis.houssin@inodbox.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 htdocs/admin/modulehelp.php
  20. * \brief Page to activate/disable all modules
  21. */
  22. if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
  23. if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Disabled because this page is into a popup on module search page and we want to avoid to have an Anti CSRF token error (done if MAIN_SECURITY_CSRF_WITH_TOKEN is on) when we make a second search after closing popup.
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  28. // Load translation files required by the page
  29. $langs->loadLangs(array('errors', 'admin'));
  30. $mode = GETPOST('mode', 'alpha');
  31. $action = GETPOST('action', 'alpha');
  32. $id = GETPOST('id', 'int');
  33. if (empty($mode)) $mode = 'desc';
  34. if (!$user->admin)
  35. accessforbidden();
  36. /*
  37. * Actions
  38. */
  39. // Nothing
  40. /*
  41. * View
  42. */
  43. $form = new Form($db);
  44. $help_url = 'EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
  45. llxHeader('', $langs->trans("Setup"), $help_url);
  46. print '<!-- Force style container -->'."\n".'<style>
  47. .id-container {
  48. width: 100%;
  49. }
  50. </style>';
  51. $arrayofnatures = array('core'=>$langs->transnoentitiesnoconv("Core"), 'external'=>$langs->transnoentitiesnoconv("External").' - '.$langs->trans("AllPublishers"));
  52. // Search modules dirs
  53. $modulesdir = dolGetModulesDirs();
  54. $filename = array();
  55. $modules = array();
  56. $orders = array();
  57. $categ = array();
  58. $dirmod = array();
  59. $i = 0; // is a sequencer of modules found
  60. $j = 0; // j is module number. Automatically affected if module number not defined.
  61. $modNameLoaded = array();
  62. foreach ($modulesdir as $dir)
  63. {
  64. // Load modules attributes in arrays (name, numero, orders) from dir directory
  65. //print $dir."\n<br>";
  66. dol_syslog("Scan directory ".$dir." for module descriptor files (modXXX.class.php)");
  67. $handle = @opendir($dir);
  68. if (is_resource($handle))
  69. {
  70. while (($file = readdir($handle)) !== false)
  71. {
  72. //print "$i ".$file."\n<br>";
  73. if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php')
  74. {
  75. $modName = substr($file, 0, dol_strlen($file) - 10);
  76. if ($modName)
  77. {
  78. if (!empty($modNameLoaded[$modName]))
  79. {
  80. $mesg = "Error: Module ".$modName." was found twice: Into ".$modNameLoaded[$modName]." and ".$dir.". You probably have an old file on your disk.<br>";
  81. setEventMessages($mesg, null, 'warnings');
  82. dol_syslog($mesg, LOG_ERR);
  83. continue;
  84. }
  85. try
  86. {
  87. $res = include_once $dir.$file;
  88. if (class_exists($modName))
  89. {
  90. try {
  91. $objMod = new $modName($db);
  92. $modNameLoaded[$modName] = $dir;
  93. if (!$objMod->numero > 0 && $modName != 'modUser')
  94. {
  95. dol_syslog('The module descriptor '.$modName.' must have a numero property', LOG_ERR);
  96. }
  97. $j = $objMod->numero;
  98. $modulequalified = 1;
  99. // We discard modules according to features level (PS: if module is activated we always show it)
  100. $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($objMod)));
  101. if ($objMod->version == 'development' && (empty($conf->global->$const_name) && ($conf->global->MAIN_FEATURES_LEVEL < 2))) $modulequalified = 0;
  102. if ($objMod->version == 'experimental' && (empty($conf->global->$const_name) && ($conf->global->MAIN_FEATURES_LEVEL < 1))) $modulequalified = 0;
  103. if (preg_match('/deprecated/', $objMod->version) && (empty($conf->global->$const_name) && ($conf->global->MAIN_FEATURES_LEVEL >= 0))) $modulequalified = 0;
  104. // We discard modules according to property disabled
  105. //if (! empty($objMod->hidden)) $modulequalified=0;
  106. if ($modulequalified > 0)
  107. {
  108. $publisher = dol_escape_htmltag($objMod->getPublisher());
  109. $external = ($objMod->isCoreOrExternalModule() == 'external');
  110. if ($external)
  111. {
  112. if ($publisher)
  113. {
  114. $arrayofnatures['external_'.$publisher] = $langs->trans("External").' - '.$publisher;
  115. }
  116. else
  117. {
  118. $arrayofnatures['external_'] = $langs->trans("External").' - '.$langs->trans("UnknownPublishers");
  119. }
  120. }
  121. ksort($arrayofnatures);
  122. }
  123. // Define array $categ with categ with at least one qualified module
  124. if ($modulequalified > 0)
  125. {
  126. $modules[$i] = $objMod;
  127. $filename[$i] = $modName;
  128. // Gives the possibility to the module, to provide his own family info and position of this family
  129. if (is_array($objMod->familyinfo) && !empty($objMod->familyinfo)) {
  130. if (!is_array($familyinfo)) $familyinfo = array();
  131. $familyinfo = array_merge($familyinfo, $objMod->familyinfo);
  132. $familykey = key($objMod->familyinfo);
  133. } else {
  134. $familykey = $objMod->family;
  135. }
  136. $moduleposition = ($objMod->module_position ? $objMod->module_position : '50');
  137. if ($moduleposition == '50' && ($objMod->isCoreOrExternalModule() == 'external'))
  138. {
  139. $moduleposition = '80'; // External modules at end by default
  140. }
  141. $orders[$i] = $familyinfo[$familykey]['position']."_".$familykey."_".$moduleposition."_".$j; // Sort by family, then by module position then number
  142. $dirmod[$i] = $dir;
  143. //print $i.'-'.$dirmod[$i].'<br>';
  144. // Set categ[$i]
  145. $specialstring = 'unknown';
  146. if ($objMod->version == 'development' || $objMod->version == 'experimental') $specialstring = 'expdev';
  147. if (isset($categ[$specialstring])) $categ[$specialstring]++; // Array of all different modules categories
  148. else $categ[$specialstring] = 1;
  149. $j++;
  150. $i++;
  151. }
  152. else dol_syslog("Module ".get_class($objMod)." not qualified");
  153. }
  154. catch (Exception $e)
  155. {
  156. dol_syslog("Failed to load ".$dir.$file." ".$e->getMessage(), LOG_ERR);
  157. }
  158. }
  159. else
  160. {
  161. print "Warning bad descriptor file : ".$dir.$file." (Class ".$modName." not found into file)<br>";
  162. }
  163. }
  164. catch (Exception $e)
  165. {
  166. dol_syslog("Failed to load ".$dir.$file." ".$e->getMessage(), LOG_ERR);
  167. }
  168. }
  169. }
  170. }
  171. closedir($handle);
  172. }
  173. else
  174. {
  175. dol_syslog("htdocs/admin/modulehelp.php: Failed to open directory ".$dir.". See permission and open_basedir option.", LOG_WARNING);
  176. }
  177. }
  178. asort($orders);
  179. //var_dump($orders);
  180. //var_dump($categ);
  181. //var_dump($modules);
  182. unset($objMod);
  183. $i = 0;
  184. foreach ($orders as $tmpkey => $tmpvalue)
  185. {
  186. $tmpMod = $modules[$tmpkey];
  187. if ($tmpMod->numero == $id)
  188. {
  189. $key = $i;
  190. $modName = $filename[$tmpkey];
  191. $dirofmodule = $dirmod[$tmpkey];
  192. $objMod = $tmpMod;
  193. break;
  194. }
  195. $i++;
  196. }
  197. $value = $orders[$key];
  198. $tab = explode('_', $value);
  199. $familyposition = $tab[0]; $familykey = $tab[1]; $module_position = $tab[2]; $numero = $tab[3];
  200. $head = modulehelp_prepare_head($objMod);
  201. // Check filters
  202. $modulename = $objMod->getName();
  203. $moduledesc = $objMod->getDesc();
  204. $moduleauthor = $objMod->getPublisher();
  205. $moduledir = strtolower(preg_replace('/^mod/i', '', get_class($objMod)));
  206. $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i', '', get_class($objMod)));
  207. $text = '<span class="opacitymedium">'.$langs->trans("LastActivationDate").':</span> ';
  208. if (!empty($conf->global->$const_name)) $text .= dol_print_date($objMod->getLastActivationDate(), 'dayhour');
  209. else $text .= $langs->trans("Disabled");
  210. $tmp = $objMod->getLastActivationInfo();
  211. $authorid = $tmp['authorid'];
  212. if ($authorid > 0)
  213. {
  214. $tmpuser = new User($db);
  215. $tmpuser->fetch($authorid);
  216. $text .= '<br><span class="opacitymedium">'.$langs->trans("LastActivationAuthor").':</span> ';
  217. $text .= $tmpuser->getNomUrl(1);
  218. }
  219. $ip = $tmp['ip'];
  220. if ($ip)
  221. {
  222. $text .= '<br><span class="opacitymedium">'.$langs->trans("LastActivationIP").':</span> ';
  223. $text .= $ip;
  224. }
  225. $moreinfo = $text;
  226. $title = ($modulename ? $modulename : $moduledesc);
  227. print '<div class="centpercent">';
  228. $picto = 'object_'.$objMod->picto;
  229. print load_fiche_titre(($modulename ? $modulename : $moduledesc), $moreinfo, $picto);
  230. print '<br>';
  231. dol_fiche_head($head, $mode, '', -1);
  232. if (!$modulename)
  233. {
  234. dol_syslog("Error for module ".$key." - Property name of module looks empty", LOG_WARNING);
  235. }
  236. // Load all lang files of module
  237. if (isset($objMod->langfiles) && is_array($objMod->langfiles))
  238. {
  239. foreach ($objMod->langfiles as $domain)
  240. {
  241. $langs->load($domain);
  242. }
  243. }
  244. // Version (with picto warning or not)
  245. $version = $objMod->getVersion(0);
  246. $versiontrans = '';
  247. if (preg_match('/development/i', $version)) $versiontrans .= img_warning($langs->trans("Development"), 'style="float: left"');
  248. if (preg_match('/experimental/i', $version)) $versiontrans .= img_warning($langs->trans("Experimental"), 'style="float: left"');
  249. if (preg_match('/deprecated/i', $version)) $versiontrans .= img_warning($langs->trans("Deprecated"), 'style="float: left"');
  250. $versiontrans .= $objMod->getVersion(1);
  251. // Define imginfo
  252. $imginfo = "info";
  253. if ($objMod->isCoreOrExternalModule() == 'external')
  254. {
  255. $imginfo = "info_black";
  256. }
  257. // Define text of description of module
  258. $text = '';
  259. if ($mode == 'desc')
  260. {
  261. if ($moduledesc) $text .= '<br>'.$moduledesc.'<br><br><br>';
  262. $text .= '<span class="opacitymedium">'.$langs->trans("Version").':</span> '.$version;
  263. $textexternal = '';
  264. if ($objMod->isCoreOrExternalModule() == 'external')
  265. {
  266. $textexternal .= '<br><span class="opacitymedium">'.$langs->trans("Origin").':</span> '.$langs->trans("ExternalModule", $dirofmodule);
  267. if ($objMod->editor_name != 'dolibarr') $textexternal .= '<br><span class="opacitymedium">'.$langs->trans("Publisher").':</span> '.(empty($objMod->editor_name) ? $langs->trans("Unknown") : $objMod->editor_name);
  268. $editor_url = $objMod->editor_url;
  269. if (!preg_match('/^http/', $editor_url)) $editor_url = 'http://'.$editor_url;
  270. if (!empty($objMod->editor_url) && !preg_match('/dolibarr\.org/i', $objMod->editor_url)) $textexternal .= ($objMod->editor_name != 'dolibarr' ? ' - ' : '').img_picto('', 'globe').' <a href="'.$editor_url.'" target="_blank">'.$objMod->editor_url.'</a>';
  271. $text .= $textexternal;
  272. $text .= '<br>';
  273. }
  274. else
  275. {
  276. $text .= '<br><span class="opacitymedium">'.$langs->trans("Origin").':</span> '.$langs->trans("Core").'<br>';
  277. }
  278. $moduledesclong = $objMod->getDescLong();
  279. if ($moduledesclong) $text .= '<br><hr><div class="moduledesclong">'.$moduledesclong.'<div>';
  280. }
  281. if ($mode == 'feature')
  282. {
  283. $text .= '<br><strong>'.$langs->trans("DependsOn").':</strong> ';
  284. if (count($objMod->depends)) $text .= join(',', $objMod->depends);
  285. else $text .= $langs->trans("None");
  286. $text .= '<br><strong>'.$langs->trans("RequiredBy").':</strong> ';
  287. if (count($objMod->requiredby)) $text .= join(',', $objMod->requiredby);
  288. else $text .= $langs->trans("None");
  289. $text .= '<br><br>';
  290. $text .= '<br><strong>'.$langs->trans("AddDataTables").':</strong> ';
  291. $sqlfiles = dol_dir_list(dol_buildpath($moduledir.'/sql/'), 'files', 0, 'llx.*\.sql', array('\.key\.sql'));
  292. if (count($sqlfiles) > 0)
  293. {
  294. $text .= $langs->trans("Yes").' (';
  295. $i = 0;
  296. foreach ($sqlfiles as $val)
  297. {
  298. $text .= ($i ? ', ' : '').preg_replace('/\.sql$/', '', preg_replace('/llx_/', '', $val['name']));
  299. $i++;
  300. }
  301. $text .= ')';
  302. }
  303. else $text .= $langs->trans("No");
  304. $text .= '<br>';
  305. $text .= '<br><strong>'.$langs->trans("AddDictionaries").':</strong> ';
  306. if (isset($objMod->dictionaries) && isset($objMod->dictionaries['tablib']) && is_array($objMod->dictionaries['tablib']) && count($objMod->dictionaries['tablib']))
  307. {
  308. $i = 0;
  309. foreach ($objMod->dictionaries['tablib'] as $val)
  310. {
  311. $text .= ($i ? ', ' : '').$val;
  312. $i++;
  313. }
  314. }
  315. else $text .= $langs->trans("No");
  316. $text .= '<br>';
  317. $text .= '<br><strong>'.$langs->trans("AddData").':</strong> ';
  318. $filedata = dol_buildpath($moduledir.'/sql/data.sql');
  319. if (dol_is_file($filedata))
  320. {
  321. $text .= $langs->trans("Yes").' ('.$moduledir.'/sql/data.sql'.')';
  322. }
  323. else $text .= $langs->trans("No");
  324. $text .= '<br>';
  325. $text .= '<br><strong>'.$langs->trans("AddRemoveTabs").':</strong> ';
  326. if (isset($objMod->tabs) && is_array($objMod->tabs) && count($objMod->tabs))
  327. {
  328. $i = 0;
  329. foreach ($objMod->tabs as $val)
  330. {
  331. if (is_array($val)) $val = $val['data'];
  332. if (is_string($val))
  333. {
  334. $tmp = explode(':', $val, 3);
  335. $text .= ($i ? ', ' : '').$tmp[0].':'.$tmp[1];
  336. $i++;
  337. }
  338. }
  339. }
  340. else $text .= $langs->trans("No");
  341. $text .= '<br>';
  342. $text .= '<br><strong>'.$langs->trans("AddModels").':</strong> ';
  343. if (isset($objMod->module_parts) && isset($objMod->module_parts['models']) && $objMod->module_parts['models'])
  344. {
  345. $text .= $langs->trans("Yes");
  346. }
  347. else $text .= $langs->trans("No");
  348. $text .= '<br>';
  349. $text .= '<br><strong>'.$langs->trans("AddSubstitutions").':</strong> ';
  350. if (isset($objMod->module_parts) && isset($objMod->module_parts['substitutions']) && $objMod->module_parts['substitutions'])
  351. {
  352. $text .= $langs->trans("Yes");
  353. }
  354. else $text .= $langs->trans("No");
  355. $text .= '<br>';
  356. $text .= '<br><strong>'.$langs->trans("AddSheduledJobs").':</strong> ';
  357. if (isset($objMod->cronjobs) && is_array($objMod->cronjobs) && count($objMod->cronjobs))
  358. {
  359. $i = 0;
  360. foreach ($objMod->cronjobs as $val)
  361. {
  362. $text .= ($i ? ', ' : '').($val['label']);
  363. $i++;
  364. }
  365. }
  366. else $text .= $langs->trans("No");
  367. $text .= '<br>';
  368. $text .= '<br><strong>'.$langs->trans("AddTriggers").':</strong> ';
  369. $moreinfoontriggerfile = '';
  370. if (isset($objMod->module_parts) && isset($objMod->module_parts['triggers']) && $objMod->module_parts['triggers'])
  371. {
  372. $yesno = 'Yes';
  373. }
  374. else
  375. {
  376. $yesno = 'No';
  377. }
  378. require_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php';
  379. $interfaces = new Interfaces($db);
  380. $triggers = $interfaces->getTriggersList(array((($objMod->isCoreOrExternalModule() == 'external') ? '/'.$moduledir : '').'/core/triggers'));
  381. foreach ($triggers as $triggercursor)
  382. {
  383. if ($triggercursor['module'] == $moduledir)
  384. {
  385. $yesno = 'Yes';
  386. $moreinfoontriggerfile = ' ('.$triggercursor['relpath'].')';
  387. }
  388. }
  389. $text .= $langs->trans($yesno).$moreinfoontriggerfile;
  390. $text .= '<br>';
  391. $text .= '<br><strong>'.$langs->trans("AddBoxes").':</strong> ';
  392. if (isset($objMod->boxes) && is_array($objMod->boxes) && count($objMod->boxes))
  393. {
  394. $i = 0;
  395. foreach ($objMod->boxes as $val)
  396. {
  397. $text .= ($i ? ', ' : '').($val['file'] ? $val['file'] : $val[0]);
  398. $i++;
  399. }
  400. }
  401. else $text .= $langs->trans("No");
  402. $text .= '<br>';
  403. $text .= '<br><strong>'.$langs->trans("AddHooks").':</strong> ';
  404. if (isset($objMod->module_parts) && is_array($objMod->module_parts['hooks']) && count($objMod->module_parts['hooks']))
  405. {
  406. $i = 0;
  407. foreach ($objMod->module_parts['hooks'] as $key => $val)
  408. {
  409. if ($key === 'entity') continue;
  410. // For special values
  411. if ($key === 'data')
  412. {
  413. if (is_array($val))
  414. {
  415. foreach ($val as $value)
  416. {
  417. $text .= ($i ? ', ' : '').($value);
  418. $i++;
  419. }
  420. continue;
  421. }
  422. }
  423. $text .= ($i ? ', ' : '').($val);
  424. $i++;
  425. }
  426. }
  427. else $text .= $langs->trans("No");
  428. $text .= '<br>';
  429. $text .= '<br><strong>'.$langs->trans("AddPermissions").':</strong> ';
  430. if (isset($objMod->rights) && is_array($objMod->rights) && count($objMod->rights))
  431. {
  432. $i = 0;
  433. foreach ($objMod->rights as $val)
  434. {
  435. $text .= ($i ? ', ' : '').($val[1]);
  436. $i++;
  437. }
  438. }
  439. else $text .= $langs->trans("No");
  440. $text .= '<br>';
  441. $text .= '<br><strong>'.$langs->trans("AddMenus").':</strong> ';
  442. if (isset($objMod->menu) && !empty($objMod->menu)) // objMod can be an array or just an int 1
  443. {
  444. $text .= $langs->trans("Yes");
  445. }
  446. else $text .= $langs->trans("No");
  447. $text .= '<br>';
  448. $text .= '<br><strong>'.$langs->trans("AddExportProfiles").':</strong> ';
  449. if (isset($objMod->export_label) && is_array($objMod->export_label) && count($objMod->export_label))
  450. {
  451. $i = 0;
  452. foreach ($objMod->export_label as $val)
  453. {
  454. $text .= ($i ? ', ' : '').($val);
  455. $i++;
  456. }
  457. }
  458. else $text .= $langs->trans("No");
  459. $text .= '<br>';
  460. $text .= '<br><strong>'.$langs->trans("AddImportProfiles").':</strong> ';
  461. if (isset($objMod->import_label) && is_array($objMod->import_label) && count($objMod->import_label))
  462. {
  463. $i = 0;
  464. foreach ($objMod->import_label as $val)
  465. {
  466. $text .= ($i ? ', ' : '').($val);
  467. $i++;
  468. }
  469. }
  470. else $text .= $langs->trans("No");
  471. $text .= '<br>';
  472. $text .= '<br><strong>'.$langs->trans("AddOtherPagesOrServices").':</strong> ';
  473. $text .= $langs->trans("DetectionNotPossible");
  474. }
  475. if ($mode == 'changelog')
  476. {
  477. $changelog = $objMod->getChangeLog();
  478. if ($changelog) $text .= '<div class="moduledesclong">'.$changelog.'<div>';
  479. else $text .= '<div class="moduledesclong">'.$langs->trans("NotAvailable").'</div>';
  480. }
  481. print $text;
  482. dol_fiche_end();
  483. print '</div>';
  484. // End of page
  485. llxFooter();
  486. $db->close();