menus.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/admin/menus.php
  21. * \ingroup core
  22. * \brief Page to setup menu manager to use
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  27. $action=GETPOST('action');
  28. $langs->load("companies");
  29. $langs->load("products");
  30. $langs->load("admin");
  31. $langs->load("users");
  32. $langs->load("other");
  33. // Security check
  34. if (! $user->admin) accessforbidden();
  35. $dirstandard = array();
  36. $dirsmartphone = array();
  37. $dirmenus=array_merge(array("/core/menus/"),(array) $conf->modules_parts['menus']);
  38. foreach($dirmenus as $dirmenu)
  39. {
  40. $dirstandard[]=$dirmenu.'standard';
  41. $dirsmartphone[]=$dirmenu.'smartphone';
  42. }
  43. $error=0;
  44. // Cette page peut etre longue. On augmente le delai autorise.
  45. // Ne fonctionne que si on est pas en safe_mode.
  46. $err=error_reporting();
  47. error_reporting(0); // Disable all errors
  48. //error_reporting(E_ALL);
  49. @set_time_limit(300); // Need more than 240 on Windows 7/64
  50. error_reporting($err);
  51. /*
  52. * Actions
  53. */
  54. if ($action == 'update' && empty($_POST["cancel"]))
  55. {
  56. $_SESSION["mainmenu"]="home"; // Le gestionnaire de menu a pu changer
  57. dolibarr_set_const($db, "MAIN_MENU_STANDARD", $_POST["MAIN_MENU_STANDARD"],'chaine',0,'',$conf->entity);
  58. dolibarr_set_const($db, "MAIN_MENU_SMARTPHONE", $_POST["MAIN_MENU_SMARTPHONE"],'chaine',0,'',$conf->entity);
  59. dolibarr_set_const($db, "MAIN_MENUFRONT_STANDARD", $_POST["MAIN_MENUFRONT_STANDARD"],'chaine',0,'',$conf->entity);
  60. dolibarr_set_const($db, "MAIN_MENUFRONT_SMARTPHONE",$_POST["MAIN_MENUFRONT_SMARTPHONE"],'chaine',0,'',$conf->entity);
  61. // Define list of menu handlers to initialize
  62. $listofmenuhandler=array();
  63. $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i','',$_POST["MAIN_MENU_STANDARD"])]=1;
  64. $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i','',$_POST["MAIN_MENUFRONT_STANDARD"])]=1;
  65. if (isset($_POST["MAIN_MENU_SMARTPHONE"])) $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i','',$_POST["MAIN_MENU_SMARTPHONE"])]=1;
  66. if (isset($_POST["MAIN_MENUFRONT_SMARTPHONE"])) $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i','',$_POST["MAIN_MENUFRONT_SMARTPHONE"])]=1;
  67. // Initialize menu handlers
  68. foreach ($listofmenuhandler as $key => $val)
  69. {
  70. // Load sql init_menu_handler.sql file
  71. $dirmenus=array_merge(array("/core/menus/"),(array) $conf->modules_parts['menus']);
  72. foreach($dirmenus as $dirmenu)
  73. {
  74. $file='init_menu_'.$key.'.sql';
  75. $fullpath=dol_buildpath($dirmenu.$file);
  76. //print 'action='.$action.' Search menu into fullpath='.$fullpath.'<br>';exit;
  77. if (file_exists($fullpath))
  78. {
  79. $db->begin();
  80. $result=run_sql($fullpath,1,'',1,$key,'none');
  81. if ($result > 0)
  82. {
  83. $db->commit();
  84. }
  85. else
  86. {
  87. $error++;
  88. //TODO: Translate
  89. setEventMessage('Failed to initialize menu '.$key.'.', 'errors');
  90. $db->rollback();
  91. }
  92. }
  93. }
  94. }
  95. if (! $error)
  96. {
  97. $db->close();
  98. // We make a header redirect because we need to change menu NOW.
  99. header("Location: ".$_SERVER["PHP_SELF"]);
  100. exit;
  101. }
  102. }
  103. /*
  104. * View
  105. */
  106. $form=new Form($db);
  107. $formadmin=new FormAdmin($db);
  108. $wikihelp='EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
  109. llxHeader('',$langs->trans("Setup"),$wikihelp);
  110. print_fiche_titre($langs->trans("Menus"),'','title_setup');
  111. $h = 0;
  112. $head[$h][0] = DOL_URL_ROOT."/admin/menus.php";
  113. $head[$h][1] = $langs->trans("MenuHandlers");
  114. $head[$h][2] = 'handler';
  115. $h++;
  116. $head[$h][0] = DOL_URL_ROOT."/admin/menus/index.php";
  117. $head[$h][1] = $langs->trans("MenuAdmin");
  118. $head[$h][2] = 'editor';
  119. $h++;
  120. $head[$h][0] = DOL_URL_ROOT."/admin/menus/other.php";
  121. $head[$h][1] = $langs->trans("Miscellaneous");
  122. $head[$h][2] = 'misc';
  123. $h++;
  124. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  125. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  126. print '<input type="hidden" name="action" value="update">';
  127. dol_fiche_head($head, 'handler', $langs->trans("Menus"));
  128. print $langs->trans("MenusDesc")."<br>\n";
  129. print "<br>\n";
  130. if ($action == 'edit')
  131. {
  132. clearstatcache();
  133. // Gestionnaires de menu
  134. $var=true;
  135. print '<table class="noborder" width="100%">';
  136. print '<tr class="liste_titre"><td width="35%">'.$langs->trans("Menu").'</td>';
  137. print '<td>';
  138. print $form->textwithpicto($langs->trans("InternalUsers"),$langs->trans("InternalExternalDesc"));
  139. print '</td>';
  140. print '<td>';
  141. print $form->textwithpicto($langs->trans("ExternalUsers"),$langs->trans("InternalExternalDesc"));
  142. print '</td>';
  143. print '</tr>';
  144. // Menu top
  145. $var=!$var;
  146. print '<tr '.$bc[$var].'><td>'.$langs->trans("DefaultMenuManager").'</td>';
  147. print '<td>';
  148. $formadmin->select_menu(empty($conf->global->MAIN_MENU_STANDARD_FORCED)?$conf->global->MAIN_MENU_STANDARD:$conf->global->MAIN_MENU_STANDARD_FORCED, 'MAIN_MENU_STANDARD', $dirstandard, empty($conf->global->MAIN_MENU_STANDARD_FORCED)?'':' disabled="disabled"');
  149. print '</td>';
  150. print '<td>';
  151. $formadmin->select_menu(empty($conf->global->MAIN_MENUFRONT_STANDARD_FORCED)?$conf->global->MAIN_MENUFRONT_STANDARD:$conf->global->MAIN_MENUFRONT_STANDARD_FORCED, 'MAIN_MENUFRONT_STANDARD', $dirstandard, empty($conf->global->MAIN_MENUFRONT_STANDARD_FORCED)?'':' disabled="disabled"');
  152. print '</td>';
  153. print '</tr>';
  154. // Menu smartphone
  155. $var=!$var;
  156. print '<tr '.$bc[$var].'><td>'.$langs->trans("DefaultMenuSmartphoneManager").'</td>';
  157. print '<td>';
  158. $formadmin->select_menu(empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED)?$conf->global->MAIN_MENU_SMARTPHONE:$conf->global->MAIN_MENU_SMARTPHONE_FORCED, 'MAIN_MENU_SMARTPHONE', array_merge($dirstandard,$dirsmartphone), empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED)?'':' disabled="disabled"');
  159. print '</td>';
  160. print '<td>';
  161. $formadmin->select_menu(empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)?$conf->global->MAIN_MENUFRONT_SMARTPHONE:$conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED, 'MAIN_MENUFRONT_SMARTPHONE', array_merge($dirstandard,$dirsmartphone), empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)?'':' disabled="disabled"');
  162. print '</td>';
  163. print '</tr>';
  164. print '</table>';
  165. }
  166. else
  167. {
  168. // Gestionnaires de menu
  169. $var=true;
  170. print '<table class="noborder" width="100%">';
  171. print '<tr class="liste_titre"><td width="35%">'.$langs->trans("Menu").'</td>';
  172. print '<td>';
  173. print $form->textwithpicto($langs->trans("InternalUsers"),$langs->trans("InternalExternalDesc"));
  174. print '</td>';
  175. print '<td>';
  176. print $form->textwithpicto($langs->trans("ExternalUsers"),$langs->trans("InternalExternalDesc"));
  177. print '</td>';
  178. print '</tr>';
  179. $var=!$var;
  180. print '<tr '.$bc[$var].'><td>'.$langs->trans("DefaultMenuManager").'</td>';
  181. print '<td>';
  182. $filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENU_STANDARD_FORCED)?$conf->global->MAIN_MENU_STANDARD:$conf->global->MAIN_MENU_STANDARD_FORCED));
  183. print $filelib;
  184. print '</td>';
  185. print '<td>';
  186. $filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENUFRONT_STANDARD_FORCED)?$conf->global->MAIN_MENUFRONT_STANDARD:$conf->global->MAIN_MENUFRONT_STANDARD_FORCED));
  187. print $filelib;
  188. print '</td>';
  189. print '</tr>';
  190. $var=!$var;
  191. print '<tr '.$bc[$var].'>';
  192. print '<td>'.$langs->trans("DefaultMenuSmartphoneManager").'</td>';
  193. print '<td>';
  194. $filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED)?$conf->global->MAIN_MENU_SMARTPHONE:$conf->global->MAIN_MENU_SMARTPHONE_FORCED));
  195. print $filelib;
  196. if (! empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && preg_match('/smartphone/', $conf->global->MAIN_MENU_SMARTPHONE_FORCED)
  197. || (empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && ! empty($conf->global->MAIN_MENU_SMARTPHONE) && preg_match('/smartphone/',$conf->global->MAIN_MENU_SMARTPHONE)))
  198. {
  199. print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
  200. }
  201. print '</td>';
  202. print '<td>';
  203. $filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)?$conf->global->MAIN_MENUFRONT_SMARTPHONE:$conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED));
  204. print $filelib;
  205. if (! empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && preg_match('/smartphone/',$conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)
  206. || (empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED) && ! empty($conf->global->MAIN_MENU_SMARTPHONE) && preg_match('/smartphone/',$conf->global->MAIN_MENUFRONT_SMARTPHONE)))
  207. {
  208. print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
  209. }
  210. print '</td>';
  211. print '</tr>';
  212. print '</table>';
  213. }
  214. dol_fiche_end();
  215. if ($action == 'edit')
  216. {
  217. print '<div class="center">';
  218. print '<input class="button" type="submit" name="save" value="'.$langs->trans("Save").'">';
  219. print ' &nbsp; &nbsp; &nbsp; ';
  220. print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  221. print '</div>';
  222. }
  223. print '</form>';
  224. if ($action != 'edit')
  225. {
  226. print '<div class="tabsAction">';
  227. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
  228. print '</div>';
  229. }
  230. llxFooter();
  231. $db->close();