PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/admin/modules.php

https://github.com/asterix14/dolibarr
PHP | 479 lines | 336 code | 74 blank | 69 comment | 84 complexity | b124ea3fd368ec768bd9a568b28f66db MD5 | raw file
Possible License(s): LGPL-2.0
  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."/core/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 . "/core/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 . '/core/modules/'))
  82. {
  83. $modulesdir[] = $dirroot . '/' . $file . '/core/modules/';
  84. }
  85. }
  86. }
  87. closedir($handle);
  88. }
  89. }
  90. }
  91. //var_dump($modulesdir);
  92. foreach ($modulesdir as $dir)
  93. {
  94. // Load modules attributes in arrays (name, numero, orders) from dir directory
  95. //print $dir."\n<br>";
  96. dol_syslog("Scan directory ".$dir." for modules");
  97. $handle=@opendir($dir);
  98. if (is_resource($handle))
  99. {
  100. while (($file = readdir($handle))!==false)
  101. {
  102. //print "$i ".$file."\n<br>";
  103. if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php')
  104. {
  105. $modName = substr($file, 0, dol_strlen($file) - 10);
  106. if ($modName)
  107. {
  108. try
  109. {
  110. $res=include_once($dir.$file);
  111. $objMod = new $modName($db);
  112. if ($objMod->numero > 0)
  113. {
  114. $j = $objMod->numero;
  115. }
  116. else
  117. {
  118. $j = 1000 + $i;
  119. }
  120. $modulequalified=1;
  121. // We discard modules according to features level (PS: if module is activated we always show it)
  122. $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i','',get_class($objMod)));
  123. if ($objMod->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2 && ! $conf->global->$const_name) $modulequalified=0;
  124. if ($objMod->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1 && ! $conf->global->$const_name) $modulequalified=0;
  125. if ($modulequalified)
  126. {
  127. $modules[$i] = $objMod;
  128. $filename[$i]= $modName;
  129. $orders[$i] = $objMod->family."_".$j; // Tri par famille puis numero module
  130. //print "x".$modName." ".$orders[$i]."\n<br>";
  131. if (isset($categ[$objMod->special])) $categ[$objMod->special]++; // Array of all different modules categories
  132. else $categ[$objMod->special]=1;
  133. $dirmod[$i] = $dirroot;
  134. $j++;
  135. $i++;
  136. }
  137. else dol_syslog("Module ".get_class($objMod)." not qualified");
  138. }
  139. catch(Exception $e)
  140. {
  141. dol_syslog("Failed to load ".$dir.$file." ".$e->getMessage(), LOG_ERR);
  142. }
  143. }
  144. }
  145. }
  146. closedir($handle);
  147. }
  148. else
  149. {
  150. dol_syslog("htdocs/admin/modules.php: Failed to open directory ".$dir.". See permission and open_basedir option.", LOG_WARNING);
  151. }
  152. }
  153. asort($orders);
  154. //var_dump($orders);
  155. //var_dump($categ);
  156. //var_dump($modules);
  157. // Affichage debut page
  158. if ($mode==0) { $tagmode = 'common'; print $langs->trans("ModulesDesc")."<br>\n"; }
  159. if ($mode==2) { $tagmode = 'other'; print $langs->trans("ModulesSpecialDesc")."<br>\n"; }
  160. if ($mode==1) { $tagmode = 'interfaces'; print $langs->trans("ModulesInterfaceDesc")."<br>\n"; }
  161. if ($mode==3) { $tagmode = 'functional'; print $langs->trans("ModulesJobDesc")."<br>\n"; }
  162. if ($mode==4) { $tagmode = 'marketplace'; print $langs->trans("ModulesMarketPlaceDesc")."<br>\n"; }
  163. print "<br>\n";
  164. $h = 0;
  165. $categidx=0; // Main
  166. if (! empty($categ[$categidx]))
  167. {
  168. $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=".$categidx;
  169. $head[$h][1] = $langs->trans("ModulesCommon");
  170. $head[$h][2] = 'common';
  171. $h++;
  172. }
  173. $categidx=2; // Other
  174. if (! empty($categ[$categidx]))
  175. {
  176. $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=".$categidx;
  177. $head[$h][1] = $langs->trans("ModulesOther");
  178. $head[$h][2] = 'other';
  179. $h++;
  180. }
  181. $categidx=1; // Interfaces
  182. if (! empty($categ[$categidx]))
  183. {
  184. $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=".$categidx;
  185. $head[$h][1] = $langs->trans("ModulesInterfaces");
  186. $head[$h][2] = 'interfaces';
  187. $h++;
  188. }
  189. $categidx=3; // Not used
  190. if (! empty($categ[$categidx]))
  191. {
  192. $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=".$categidx;
  193. $head[$h][1] = $langs->trans("ModulesSpecial");
  194. $head[$h][2] = 'functional';
  195. $h++;
  196. }
  197. $categidx=4;
  198. //if (! empty($categ[$categidx]))
  199. //{
  200. $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=".$categidx;
  201. $head[$h][1] = $langs->trans("ModulesMarketPlaces");
  202. $head[$h][2] = 'marketplace';
  203. $h++;
  204. //}
  205. dol_fiche_head($head, $tagmode, $langs->trans("Modules"));
  206. if ($mesg) print '<div class="error">'.$mesg.'</div>';
  207. if ($mode != 4)
  208. {
  209. print "<table summary=\"list_of_modules\" class=\"noborder\" width=\"100%\">\n";
  210. //print "<tr class=\"liste_titre\">\n";
  211. print '<tr class="liste_total">'."\n";
  212. //print " <td>".$langs->trans("Family")."</td>\n";
  213. print " <td colspan=\"2\">".$langs->trans("Module")."</td>\n";
  214. print " <td>".$langs->trans("Description")."</td>\n";
  215. print " <td align=\"center\">".$langs->trans("Version")."</td>\n";
  216. //print " <td align=\"center\">".$langs->trans("DbVersion")."</td>\n";
  217. print " <td align=\"center\">".$langs->trans("Status")."</td>\n";
  218. print " <td align=\"right\">".$langs->trans("SetupShort")."</td>\n";
  219. print "</tr>\n";
  220. // Affichage liste modules
  221. $var=true;
  222. $oldfamily='';
  223. $familylib=array(
  224. 'base'=>$langs->trans("ModuleFamilyBase"),
  225. 'crm'=>$langs->trans("ModuleFamilyCrm"),
  226. 'products'=>$langs->trans("ModuleFamilyProducts"),
  227. 'hr'=>$langs->trans("ModuleFamilyHr"),
  228. 'projects'=>$langs->trans("ModuleFamilyProjects"),
  229. 'financial'=>$langs->trans("ModuleFamilyFinancial"),
  230. 'ecm'=>$langs->trans("ModuleFamilyECM"),
  231. 'technic'=>$langs->trans("ModuleFamilyTechnic"),
  232. 'other'=>$langs->trans("ModuleFamilyOther")
  233. );
  234. foreach ($orders as $key => $value)
  235. {
  236. $tab=explode('_',$value);
  237. $family=$tab[0]; $numero=$tab[1];
  238. $modName = $filename[$key];
  239. $objMod = $modules[$key];
  240. //var_dump($objMod);
  241. if ($objMod->special != $mode) continue; // Discard if not for tab
  242. if (! $objMod->getName())
  243. {
  244. dol_syslog("Error for module ".$key." - Property name of module looks empty", LOG_WARNING);
  245. continue;
  246. }
  247. $const_name = 'MAIN_MODULE_'.strtoupper(preg_replace('/^mod/i','',get_class($objMod)));
  248. // Load all lang files of module
  249. if (isset($objMod->langfiles) && is_array($objMod->langfiles))
  250. {
  251. foreach($objMod->langfiles as $domain)
  252. {
  253. $langs->load($domain);
  254. }
  255. }
  256. // Print a separator if we change family
  257. //print "<tr><td>xx".$oldfamily."-".$family."-".$atleastoneforfamily."<br></td><tr>";
  258. //if ($oldfamily && $family!=$oldfamily && $atleastoneforfamily) {
  259. if ($family!=$oldfamily) {
  260. print '<tr class="liste_titre">'."\n <td colspan=\"6\">";
  261. $familytext=empty($familylib[$family])?$family:$familylib[$family];
  262. print $familytext;
  263. print "</td>\n</tr>\n";
  264. $atleastoneforfamily=0;
  265. //print "<tr><td>yy".$oldfamily."-".$family."-".$atleastoneforfamily."<br></td><tr>";
  266. }
  267. if ($objMod->special == $mode)
  268. {
  269. $atleastoneforfamily++;
  270. if ($family!=$oldfamily)
  271. {
  272. $familytext=empty($familylib[$family])?$family:$familylib[$family];
  273. //print $familytext;
  274. $oldfamily=$family;
  275. }
  276. $var=!$var;
  277. print '<tr height="18" '.$bc[$var].">\n";
  278. // Picto
  279. print ' <td valign="top" width="14" align="center">';
  280. $alttext='';
  281. //if (is_array($objMod->need_dolibarr_version)) $alttext.=($alttext?' - ':'').'Dolibarr >= '.join('.',$objMod->need_dolibarr_version);
  282. //if (is_array($objMod->phpmin)) $alttext.=($alttext?' - ':'').'PHP >= '.join('.',$objMod->phpmin);
  283. if (! empty($objMod->picto))
  284. {
  285. if (preg_match('/^\//i',$objMod->picto)) print img_picto($alttext,$objMod->picto,' width="14px"',1);
  286. else print img_object($alttext,$objMod->picto,' width="14px"');
  287. }
  288. else
  289. {
  290. print img_object($alttext,'generic');
  291. }
  292. print '</td>';
  293. // Name
  294. print '<td valign="top">'.$objMod->getName();
  295. print "</td>\n";
  296. // Desc
  297. print "<td valign=\"top\">";
  298. print nl2br($objMod->getDesc());
  299. print "</td>\n";
  300. // Version
  301. print "<td align=\"center\" valign=\"top\" nowrap=\"nowrap\">";
  302. print $objMod->getVersion();
  303. print "</td>\n";
  304. // Activate/Disable and Setup (2 columns)
  305. if (! empty($conf->global->$const_name))
  306. {
  307. $disableSetup = 0;
  308. print "<td align=\"center\" valign=\"top\">";
  309. // Module actif
  310. if (! empty($objMod->always_enabled) || (($conf->global->MAIN_MODULE_MULTICOMPANY && $objMod->core_enabled) && ($user->entity || $conf->entity!=1)))
  311. {
  312. print $langs->trans("Required");
  313. if ($conf->global->MAIN_MODULE_MULTICOMPANY && $user->entity) $disableSetup++;
  314. print '</td>'."\n";
  315. }
  316. else
  317. {
  318. print '<a href="modules.php?id='.$objMod->numero.'&amp;action=reset&amp;value=' . $modName . '&amp;mode=' . $mode . '">';
  319. print img_picto($langs->trans("Activated"),'switch_on');
  320. print '</a></td>'."\n";
  321. }
  322. if (! empty($objMod->config_page_url) && !$disableSetup)
  323. {
  324. if (is_array($objMod->config_page_url))
  325. {
  326. print ' <td align="right" valign="top">';
  327. $i=0;
  328. foreach ($objMod->config_page_url as $page)
  329. {
  330. $urlpage=$page;
  331. if ($i++)
  332. {
  333. print '<a href="'.$urlpage.'" title="'.$langs->trans($page).'">'.img_picto(ucfirst($page),"setup").'</a>&nbsp;';
  334. // print '<a href="'.$page.'">'.ucfirst($page).'</a>&nbsp;';
  335. }
  336. else
  337. {
  338. if (preg_match('/^([^@]+)@([^@]+)$/i',$urlpage,$regs))
  339. {
  340. print '<a href="'.dol_buildpath('/'.$regs[2].'/admin/'.$regs[1],1).'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"),"setup").'</a>&nbsp;';
  341. }
  342. else
  343. {
  344. print '<a href="'.$urlpage.'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"),"setup").'</a>&nbsp;';
  345. }
  346. }
  347. }
  348. print "</td>\n";
  349. }
  350. else if (preg_match('/^([^@]+)@([^@]+)$/i',$objMod->config_page_url,$regs))
  351. {
  352. 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>';
  353. }
  354. else
  355. {
  356. print '<td align="right" valign="top"><a href="'.$objMod->config_page_url.'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"),"setup").'</a></td>';
  357. }
  358. }
  359. else
  360. {
  361. print "<td>&nbsp;</td>";
  362. }
  363. }
  364. else
  365. {
  366. print "<td align=\"center\" valign=\"top\">";
  367. if (! empty($objMod->always_enabled))
  368. {
  369. // Ne devrait pas arriver.
  370. }
  371. // Module non actif
  372. print '<a href="modules.php?id='.$objMod->numero.'&amp;action=set&amp;value=' . $modName . '&amp;mode=' . $mode . '">';
  373. print img_picto($langs->trans("Disabled"),'switch_off');
  374. print "</a></td>\n <td>&nbsp;</td>\n";
  375. }
  376. print "</tr>\n";
  377. }
  378. }
  379. print "</table>\n";
  380. }
  381. else
  382. {
  383. // Marketplace
  384. print "<table summary=\"list_of_modules\" class=\"noborder\" width=\"100%\">\n";
  385. print "<tr class=\"liste_titre\">\n";
  386. //print '<td>'.$langs->trans("Logo").'</td>';
  387. print '<td colspan="2">'.$langs->trans("WebSiteDesc").'</td>';
  388. print '<td>'.$langs->trans("URL").'</td>';
  389. print '</tr>';
  390. $var=!$var;
  391. print "<tr ".$bc[$var].">\n";
  392. $url='http://www.dolistore.com';
  393. print '<td align="left"><a href="'.$url.'" target="_blank"><img border="0" src="'.DOL_URL_ROOT.'/theme/common/dolistore.jpg"></a></td>';
  394. print '<td>'.$langs->trans("DoliStoreDesc").'</td>';
  395. print '<td><a href="'.$url.'" target="_blank">'.$url.'</a></td>';
  396. print '</tr>';
  397. print "</table>\n";
  398. }
  399. dol_fiche_end();
  400. // Pour eviter bug mise en page IE
  401. print '<div class="tabsAction">';
  402. print '</div>';
  403. $db->close();
  404. llxFooter();
  405. ?>