menus.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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','aZ09');
  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. setEventMessages($langs->trans("FailedToInitializeMenu").' '.$key, null, 'errors');
  89. $db->rollback();
  90. }
  91. }
  92. }
  93. }
  94. if (! $error)
  95. {
  96. $db->close();
  97. // We make a header redirect because we need to change menu NOW.
  98. header("Location: ".$_SERVER["PHP_SELF"]);
  99. exit;
  100. }
  101. }
  102. /*
  103. * View
  104. */
  105. $form=new Form($db);
  106. $formadmin=new FormAdmin($db);
  107. $wikihelp='EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
  108. llxHeader('',$langs->trans("Setup"),$wikihelp);
  109. print load_fiche_titre($langs->trans("Menus"),'','title_setup');
  110. $h = 0;
  111. $head[$h][0] = DOL_URL_ROOT."/admin/menus.php";
  112. $head[$h][1] = $langs->trans("MenuHandlers");
  113. $head[$h][2] = 'handler';
  114. $h++;
  115. $head[$h][0] = DOL_URL_ROOT."/admin/menus/index.php";
  116. $head[$h][1] = $langs->trans("MenuAdmin");
  117. $head[$h][2] = 'editor';
  118. $h++;
  119. $head[$h][0] = DOL_URL_ROOT."/admin/menus/other.php";
  120. $head[$h][1] = $langs->trans("Miscellaneous");
  121. $head[$h][2] = 'misc';
  122. $h++;
  123. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  124. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  125. print '<input type="hidden" name="action" value="update">';
  126. dol_fiche_head($head, 'handler', $langs->trans("Menus"), -1);
  127. print $langs->trans("MenusDesc")."<br>\n";
  128. print "<br>\n";
  129. if ($action == 'edit')
  130. {
  131. clearstatcache();
  132. // Gestionnaires de menu
  133. $var=true;
  134. print '<table class="noborder" width="100%">';
  135. print '<tr class="liste_titre"><td width="35%">'.$langs->trans("Menu").'</td>';
  136. print '<td>';
  137. print $form->textwithpicto($langs->trans("InternalUsers"),$langs->trans("InternalExternalDesc"));
  138. print '</td>';
  139. print '<td>';
  140. print $form->textwithpicto($langs->trans("ExternalUsers"),$langs->trans("InternalExternalDesc"));
  141. print '</td>';
  142. print '</tr>';
  143. // Menu top
  144. print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuManager").'</td>';
  145. print '<td>';
  146. $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');
  147. print '</td>';
  148. print '<td>';
  149. $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');
  150. print '</td>';
  151. print '</tr>';
  152. // Menu smartphone
  153. print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuSmartphoneManager").'</td>';
  154. print '<td>';
  155. $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');
  156. print '</td>';
  157. print '<td>';
  158. $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');
  159. print '</td>';
  160. print '</tr>';
  161. print '</table>';
  162. }
  163. else
  164. {
  165. // Gestionnaires de menu
  166. $var=true;
  167. print '<table class="noborder" width="100%">';
  168. print '<tr class="liste_titre"><td width="35%">'.$langs->trans("Menu").'</td>';
  169. print '<td>';
  170. print $form->textwithpicto($langs->trans("InternalUsers"),$langs->trans("InternalExternalDesc"));
  171. print '</td>';
  172. print '<td>';
  173. print $form->textwithpicto($langs->trans("ExternalUsers"),$langs->trans("InternalExternalDesc"));
  174. print '</td>';
  175. print '</tr>';
  176. print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuManager").'</td>';
  177. print '<td>';
  178. $filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENU_STANDARD_FORCED)?$conf->global->MAIN_MENU_STANDARD:$conf->global->MAIN_MENU_STANDARD_FORCED));
  179. print $filelib;
  180. print '</td>';
  181. print '<td>';
  182. $filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENUFRONT_STANDARD_FORCED)?$conf->global->MAIN_MENUFRONT_STANDARD:$conf->global->MAIN_MENUFRONT_STANDARD_FORCED));
  183. print $filelib;
  184. print '</td>';
  185. print '</tr>';
  186. print '<tr class="oddeven">';
  187. print '<td>'.$langs->trans("DefaultMenuSmartphoneManager").'</td>';
  188. print '<td>';
  189. $filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED)?$conf->global->MAIN_MENU_SMARTPHONE:$conf->global->MAIN_MENU_SMARTPHONE_FORCED));
  190. print $filelib;
  191. if (! empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && preg_match('/smartphone/', $conf->global->MAIN_MENU_SMARTPHONE_FORCED)
  192. || (empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && ! empty($conf->global->MAIN_MENU_SMARTPHONE) && preg_match('/smartphone/',$conf->global->MAIN_MENU_SMARTPHONE)))
  193. {
  194. print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
  195. }
  196. print '</td>';
  197. print '<td>';
  198. $filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)?$conf->global->MAIN_MENUFRONT_SMARTPHONE:$conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED));
  199. print $filelib;
  200. if (! empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && preg_match('/smartphone/',$conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)
  201. || (empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED) && ! empty($conf->global->MAIN_MENU_SMARTPHONE) && preg_match('/smartphone/',$conf->global->MAIN_MENUFRONT_SMARTPHONE)))
  202. {
  203. print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
  204. }
  205. print '</td>';
  206. print '</tr>';
  207. print '</table>';
  208. }
  209. dol_fiche_end();
  210. if ($action == 'edit')
  211. {
  212. print '<div class="center">';
  213. print '<input class="button" type="submit" name="save" value="'.$langs->trans("Save").'">';
  214. print ' &nbsp; &nbsp; &nbsp; ';
  215. print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  216. print '</div>';
  217. }
  218. print '</form>';
  219. if ($action != 'edit')
  220. {
  221. print '<div class="tabsAction">';
  222. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
  223. print '</div>';
  224. }
  225. llxFooter();
  226. $db->close();