modulehelp.php 19 KB

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