modulehelp.php 18 KB

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