modules.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
  4. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  6. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  7. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/admin/modules.php
  24. * \brief Page to activate/disable all modules
  25. */
  26. require("../main.inc.php");
  27. require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
  28. $langs->load("errors");
  29. $langs->load("admin");
  30. $mode=isset($_GET["mode"])?GETPOST("mode"):(isset($_SESSION['mode'])?$_SESSION['mode']:0);
  31. $mesg=GETPOST("mesg");
  32. if (!$user->admin)
  33. accessforbidden();
  34. /*
  35. * Actions
  36. */
  37. if (isset($_GET["action"]) && $_GET["action"] == 'set' && $user->admin)
  38. {
  39. $result=Activate($_GET["value"]);
  40. $mesg='';
  41. if ($result) $mesg=$result;
  42. Header("Location: modules.php?mode=".$mode."&mesg=".urlencode($mesg));
  43. exit;
  44. }
  45. if (isset($_GET["action"]) && $_GET["action"] == 'reset' && $user->admin)
  46. {
  47. $result=UnActivate($_GET["value"]);
  48. $mesg='';
  49. if ($result) $mesg=$result;
  50. Header("Location: modules.php?mode=".$mode."&mesg=".urlencode($mesg));
  51. exit;
  52. }
  53. /*
  54. * View
  55. */
  56. $_SESSION["mode"]=$mode;
  57. $help_url='EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
  58. llxHeader('',$langs->trans("Setup"),$help_url);
  59. print_fiche_titre($langs->trans("ModulesSetup"),'','setup');
  60. // Search modules
  61. $filename = array();
  62. $modules = array();
  63. $orders = array();
  64. $categ = array();
  65. $dirmod = array();
  66. $modulesdir = 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. foreach ($conf->file->dol_document_root as $type => $dirroot)
  70. {
  71. $modulesdir[] = $dirroot . "/includes/modules/";
  72. if ($type == 'alt')
  73. {
  74. $handle=@opendir($dirroot);
  75. if (is_resource($handle))
  76. {
  77. while (($file = readdir($handle))!==false)
  78. {
  79. if (is_dir($dirroot.'/'.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && $file != 'includes')
  80. {
  81. if (is_dir($dirroot . '/' . $file . '/includes/modules/'))
  82. {
  83. $modulesdir[] = $dirroot . '/' . $file . '/includes/modules/';
  84. }
  85. }
  86. }
  87. closedir($handle);
  88. }
  89. }
  90. }
  91. foreach ($modulesdir as $dir)
  92. {
  93. // Load modules attributes in arrays (name, numero, orders) from dir directory
  94. //print $dir."\n<br>";
  95. dol_syslog("Scan directory ".$dir." for modules");
  96. $handle=@opendir($dir);
  97. if (is_resource($handle))
  98. {
  99. while (($file = readdir($handle))!==false)
  100. {
  101. //print "$i ".$file."\n<br>";
  102. if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php')
  103. {
  104. $modName = substr($file, 0, dol_strlen($file) - 10);
  105. if ($modName)
  106. {
  107. include_once($dir.$file);
  108. $objMod = new $modName($db);
  109. if ($objMod->numero > 0)
  110. {
  111. $j = $objMod->numero;
  112. }
  113. else
  114. {
  115. $j = 1000 + $i;
  116. }
  117. $modulequalified=1;
  118. // We discard modules according to features level (PS: if module is activated we always show it)
  119. $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i','',get_class($objMod)));
  120. if ($objMod->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2 && ! $conf->global->$const_name) $modulequalified=0;
  121. if ($objMod->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1 && ! $conf->global->$const_name) $modulequalified=0;
  122. if ($modulequalified)
  123. {
  124. $modules[$i] = $objMod;
  125. $filename[$i]= $modName;
  126. $orders[$i] = $objMod->family."_".$j; // Tri par famille puis numero module
  127. //print "x".$modName." ".$orders[$i]."\n<br>";
  128. if (isset($categ[$objMod->special])) $categ[$objMod->special]++; // Array of all different modules categories
  129. else $categ[$objMod->special]=1;
  130. $dirmod[$i] = $dirroot;
  131. $j++;
  132. $i++;
  133. }
  134. else dol_syslog("Module ".get_class($objMod)." not qualified");
  135. }
  136. }
  137. }
  138. closedir($handle);
  139. }
  140. else
  141. {
  142. dol_syslog("htdocs/admin/modules.php: Failed to open directory ".$dir.". See permission and open_basedir option.", LOG_WARNING);
  143. }
  144. }
  145. asort($orders);
  146. //var_dump($orders);
  147. //var_dump($categ);
  148. //var_dump($modules);
  149. // Affichage debut page
  150. if ($mode==0) { $tagmode = 'common'; print $langs->trans("ModulesDesc")."<br>\n"; }
  151. if ($mode==2) { $tagmode = 'other'; print $langs->trans("ModulesSpecialDesc")."<br>\n"; }
  152. if ($mode==1) { $tagmode = 'interfaces'; print $langs->trans("ModulesInterfaceDesc")."<br>\n"; }
  153. if ($mode==3) { $tagmode = 'functional'; print $langs->trans("ModulesJobDesc")."<br>\n"; }
  154. if ($mode==4) { $tagmode = 'marketplace'; print $langs->trans("ModulesMarketPlaceDesc")."<br>\n"; }
  155. print "<br>\n";
  156. $h = 0;
  157. $categidx=0; // Main
  158. if (! empty($categ[$categidx]))
  159. {
  160. $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=".$categidx;
  161. $head[$h][1] = $langs->trans("ModulesCommon");
  162. $head[$h][2] = 'common';
  163. $h++;
  164. }
  165. $categidx=2; // Other
  166. if (! empty($categ[$categidx]))
  167. {
  168. $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=".$categidx;
  169. $head[$h][1] = $langs->trans("ModulesOther");
  170. $head[$h][2] = 'other';
  171. $h++;
  172. }
  173. $categidx=1; // Interfaces
  174. if (! empty($categ[$categidx]))
  175. {
  176. $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=".$categidx;
  177. $head[$h][1] = $langs->trans("ModulesInterfaces");
  178. $head[$h][2] = 'interfaces';
  179. $h++;
  180. }
  181. $categidx=3; // Not used
  182. if (! empty($categ[$categidx]))
  183. {
  184. $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=".$categidx;
  185. $head[$h][1] = $langs->trans("ModulesSpecial");
  186. $head[$h][2] = 'functional';
  187. $h++;
  188. }
  189. $categidx=4;
  190. //if (! empty($categ[$categidx]))
  191. //{
  192. $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=".$categidx;
  193. $head[$h][1] = $langs->trans("ModulesMarketPlaces");
  194. $head[$h][2] = 'marketplace';
  195. $h++;
  196. //}
  197. dol_fiche_head($head, $tagmode, $langs->trans("Modules"));
  198. if ($mesg) print '<div class="error">'.$mesg.'</div>';
  199. if ($mode != 4)
  200. {
  201. print "<table summary=\"list_of_modules\" class=\"noborder\" width=\"100%\">\n";
  202. //print "<tr class=\"liste_titre\">\n";
  203. print '<tr class="liste_total">'."\n";
  204. //print " <td>".$langs->trans("Family")."</td>\n";
  205. print " <td colspan=\"2\">".$langs->trans("Module")."</td>\n";
  206. print " <td>".$langs->trans("Description")."</td>\n";
  207. print " <td align=\"center\">".$langs->trans("Version")."</td>\n";
  208. //print " <td align=\"center\">".$langs->trans("DbVersion")."</td>\n";
  209. print " <td align=\"center\">".$langs->trans("Status")."</td>\n";
  210. print " <td align=\"right\">".$langs->trans("SetupShort")."</td>\n";
  211. print "</tr>\n";
  212. // Affichage liste modules
  213. $var=true;
  214. $oldfamily='';
  215. $familylib=array(
  216. 'base'=>$langs->trans("ModuleFamilyBase"),
  217. 'crm'=>$langs->trans("ModuleFamilyCrm"),
  218. 'products'=>$langs->trans("ModuleFamilyProducts"),
  219. 'hr'=>$langs->trans("ModuleFamilyHr"),
  220. 'projects'=>$langs->trans("ModuleFamilyProjects"),
  221. 'financial'=>$langs->trans("ModuleFamilyFinancial"),
  222. 'ecm'=>$langs->trans("ModuleFamilyECM"),
  223. 'technic'=>$langs->trans("ModuleFamilyTechnic"),
  224. 'other'=>$langs->trans("ModuleFamilyOther")
  225. );
  226. foreach ($orders as $key => $value)
  227. {
  228. $tab=explode('_',$value);
  229. $family=$tab[0]; $numero=$tab[1];
  230. $modName = $filename[$key];
  231. $objMod = $modules[$key];
  232. //var_dump($objMod);
  233. if ($objMod->special != $mode) continue; // Discard if not for tab
  234. if (! $objMod->getName())
  235. {
  236. dol_syslog("Error for module ".$key." - Property name of module looks empty", LOG_WARNING);
  237. continue;
  238. }
  239. $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i','',get_class($objMod)));
  240. // Load all lang files of module
  241. if (isset($objMod->langfiles) && is_array($objMod->langfiles))
  242. {
  243. foreach($objMod->langfiles as $domain)
  244. {
  245. $langs->load($domain);
  246. }
  247. }
  248. // Print a separator if we change family
  249. //print "<tr><td>xx".$oldfamily."-".$family."-".$atleastoneforfamily."<br></td><tr>";
  250. //if ($oldfamily && $family!=$oldfamily && $atleastoneforfamily) {
  251. if ($family!=$oldfamily) {
  252. print '<tr class="liste_titre">'."\n <td colspan=\"6\">";
  253. $familytext=empty($familylib[$family])?$family:$familylib[$family];
  254. print $familytext;
  255. print "</td>\n</tr>\n";
  256. $atleastoneforfamily=0;
  257. //print "<tr><td>yy".$oldfamily."-".$family."-".$atleastoneforfamily."<br></td><tr>";
  258. }
  259. if ($objMod->special == $mode)
  260. {
  261. $atleastoneforfamily++;
  262. $var=!$var;
  263. print '<tr height="18" '.$bc[$var].">\n";
  264. //print ' <td valign="top" nowrap="nowrap">';
  265. if ($family!=$oldfamily)
  266. {
  267. $familytext=empty($familylib[$family])?$family:$familylib[$family];
  268. //print $familytext;
  269. $oldfamily=$family;
  270. }
  271. else
  272. {
  273. //print '&nbsp;';
  274. }
  275. //print "</td>\n";
  276. // Picto
  277. print ' <td valign="top" width="14" align="center">';
  278. $alttext='';
  279. //if (is_array($objMod->need_dolibarr_version)) $alttext.=($alttext?' - ':'').'Dolibarr >= '.join('.',$objMod->need_dolibarr_version);
  280. //if (is_array($objMod->phpmin)) $alttext.=($alttext?' - ':'').'PHP >= '.join('.',$objMod->phpmin);
  281. if (! empty($objMod->picto))
  282. {
  283. if (preg_match('/^\//i',$objMod->picto)) print img_picto($alttext,$objMod->picto,' width="14px"',1);
  284. else print img_object($alttext,$objMod->picto,' width="14px"');
  285. }
  286. else
  287. {
  288. print img_object($alttext,'generic');
  289. }
  290. print '</td>';
  291. // Name
  292. print '<td valign="top">'.$objMod->getName();
  293. print "</td>\n";
  294. // Desc
  295. print "<td valign=\"top\">";
  296. print nl2br($objMod->getDesc());
  297. print "</td>\n";
  298. // Version
  299. print "<td align=\"center\" valign=\"top\" nowrap=\"nowrap\">";
  300. print $objMod->getVersion();
  301. print "</td>\n";
  302. // Activate/Disable and Setup (2 columns)
  303. if (! empty($conf->global->$const_name))
  304. {
  305. $disableSetup = 0;
  306. print "<td align=\"center\" valign=\"top\">";
  307. // Module actif
  308. if (! empty($objMod->always_enabled) || (($conf->global->MAIN_MODULE_MULTICOMPANY && $objMod->core_enabled) && ($user->entity || $conf->entity!=1)))
  309. {
  310. print $langs->trans("Required");
  311. if ($conf->global->MAIN_MODULE_MULTICOMPANY && $user->entity) $disableSetup++;
  312. print '</td>'."\n";
  313. }
  314. else
  315. {
  316. print '<a href="modules.php?id='.$objMod->numero.'&amp;action=reset&amp;value=' . $modName . '&amp;mode=' . $mode . '">';
  317. print img_picto($langs->trans("Activated"),'switch_on');
  318. print '</a></td>'."\n";
  319. }
  320. if (! empty($objMod->config_page_url) && !$disableSetup)
  321. {
  322. if (is_array($objMod->config_page_url))
  323. {
  324. print ' <td align="right" valign="top">';
  325. $i=0;
  326. foreach ($objMod->config_page_url as $page)
  327. {
  328. $urlpage=$page;
  329. if ($i++)
  330. {
  331. print '<a href="'.$urlpage.'" title="'.$langs->trans($page).'">'.img_picto(ucfirst($page),"setup").'</a>&nbsp;';
  332. // print '<a href="'.$page.'">'.ucfirst($page).'</a>&nbsp;';
  333. }
  334. else
  335. {
  336. if (preg_match('/^([^@]+)@([^@]+)$/i',$urlpage,$regs))
  337. {
  338. print '<a href="'.dol_buildpath('/'.$regs[2].'/admin/'.$regs[1],1).'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"),"setup").'</a>&nbsp;';
  339. }
  340. else
  341. {
  342. print '<a href="'.$urlpage.'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"),"setup").'</a>&nbsp;';
  343. }
  344. }
  345. }
  346. print "</td>\n";
  347. }
  348. else if (preg_match('/^([^@]+)@([^@]+)$/i',$objMod->config_page_url,$regs))
  349. {
  350. print '<td align="right" valign="top"><a href="'.dol_buildpath('/'.$regs[2].'/admin/'.$regs[1],1).'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"),"setup").'</a></td>';
  351. }
  352. else
  353. {
  354. print '<td align="right" valign="top"><a href="'.$objMod->config_page_url.'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"),"setup").'</a></td>';
  355. }
  356. }
  357. else
  358. {
  359. print "<td>&nbsp;</td>";
  360. }
  361. }
  362. else
  363. {
  364. print "<td align=\"center\" valign=\"top\">";
  365. if (! empty($objMod->always_enabled))
  366. {
  367. // Ne devrait pas arriver.
  368. }
  369. // Module non actif
  370. print '<a href="modules.php?id='.$objMod->numero.'&amp;action=set&amp;value=' . $modName . '&amp;mode=' . $mode . '">';
  371. print img_picto($langs->trans("Disabled"),'switch_off');
  372. print "</a></td>\n <td>&nbsp;</td>\n";
  373. }
  374. print "</tr>\n";
  375. }
  376. }
  377. print "</table>\n";
  378. }
  379. else
  380. {
  381. // Marketplace
  382. print "<table summary=\"list_of_modules\" class=\"noborder\" width=\"100%\">\n";
  383. print "<tr class=\"liste_titre\">\n";
  384. //print '<td>'.$langs->trans("Logo").'</td>';
  385. print '<td colspan="2">'.$langs->trans("WebSiteDesc").'</td>';
  386. print '<td>'.$langs->trans("URL").'</td>';
  387. print '</tr>';
  388. $var=!$var;
  389. print "<tr ".$bc[$var].">\n";
  390. $url='http://www.dolistore.com';
  391. print '<td align="left"><a href="'.$url.'" target="_blank"><img border="0" src="'.DOL_URL_ROOT.'/theme/common/dolistore.jpg"></a></td>';
  392. print '<td>'.$langs->trans("DoliStoreDesc").'</td>';
  393. print '<td><a href="'.$url.'" target="_blank">'.$url.'</a></td>';
  394. print '</tr>';
  395. print "</table>\n";
  396. }
  397. dol_fiche_end();
  398. // Pour eviter bug mise en page IE
  399. print '<div class="tabsAction">';
  400. print '</div>';
  401. $db->close();
  402. llxFooter();
  403. ?>