menus.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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@inodbox.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 <https://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. $cancel = GETPOST('cancel', 'alpha');
  29. // Load translation files required by the page
  30. $langs->loadLangs(array("companies", "products", "admin", "users", "other"));
  31. // Security check
  32. if (!$user->admin) {
  33. accessforbidden();
  34. }
  35. $dirstandard = array();
  36. $dirsmartphone = array();
  37. $dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
  38. foreach ($dirmenus as $dirmenu) {
  39. $dirstandard[] = $dirmenu.'standard';
  40. $dirsmartphone[] = $dirmenu.'smartphone';
  41. }
  42. $error = 0;
  43. // Cette page peut etre longue. On augmente le delai autorise.
  44. // Ne fonctionne que si on est pas en safe_mode.
  45. $err = error_reporting();
  46. error_reporting(0); // Disable all errors
  47. //error_reporting(E_ALL);
  48. @set_time_limit(300); // Need more than 240 on Windows 7/64
  49. error_reporting($err);
  50. /*
  51. * Actions
  52. */
  53. if ($action == 'update' && !$cancel) {
  54. $_SESSION["mainmenu"] = "home"; // Le gestionnaire de menu a pu changer
  55. dolibarr_set_const($db, "MAIN_MENU_STANDARD", GETPOST('MAIN_MENU_STANDARD', 'alpha'), 'chaine', 0, '', $conf->entity);
  56. dolibarr_set_const($db, "MAIN_MENU_SMARTPHONE", GETPOST('MAIN_MENU_SMARTPHONE', 'alpha'), 'chaine', 0, '', $conf->entity);
  57. dolibarr_set_const($db, "MAIN_MENUFRONT_STANDARD", GETPOST('MAIN_MENUFRONT_STANDARD', 'alpha'), 'chaine', 0, '', $conf->entity);
  58. dolibarr_set_const($db, "MAIN_MENUFRONT_SMARTPHONE", GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha'), 'chaine', 0, '', $conf->entity);
  59. // Define list of menu handlers to initialize
  60. $listofmenuhandler = array();
  61. $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENU_STANDARD', 'alpha'))] = 1;
  62. $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENUFRONT_STANDARD', 'alpha'))] = 1;
  63. if (GETPOST('MAIN_MENU_SMARTPHONE', 'alpha')) {
  64. $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENU_SMARTPHONE', 'alpha'))] = 1;
  65. }
  66. if (GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha')) {
  67. $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha'))] = 1;
  68. }
  69. // Initialize menu handlers
  70. foreach ($listofmenuhandler as $key => $val) {
  71. // Load sql init_menu_handler.sql file
  72. $dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
  73. foreach ($dirmenus as $dirmenu) {
  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. $db->begin();
  79. $result = run_sql($fullpath, 1, '', 1, $key, 'none');
  80. if ($result > 0) {
  81. $db->commit();
  82. } else {
  83. $error++;
  84. setEventMessages($langs->trans("FailedToInitializeMenu").' '.$key, null, 'errors');
  85. $db->rollback();
  86. }
  87. }
  88. }
  89. }
  90. if (!$error) {
  91. $db->close();
  92. // We make a header redirect because we need to change menu NOW.
  93. header("Location: ".$_SERVER["PHP_SELF"]);
  94. exit;
  95. }
  96. }
  97. /*
  98. * View
  99. */
  100. $form = new Form($db);
  101. $formadmin = new FormAdmin($db);
  102. $wikihelp = 'EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
  103. llxHeader('', $langs->trans("Setup"), $wikihelp);
  104. print load_fiche_titre($langs->trans("Menus"), '', 'title_setup');
  105. $h = 0;
  106. $head[$h][0] = DOL_URL_ROOT."/admin/menus.php";
  107. $head[$h][1] = $langs->trans("MenuHandlers");
  108. $head[$h][2] = 'handler';
  109. $h++;
  110. $head[$h][0] = DOL_URL_ROOT."/admin/menus/index.php";
  111. $head[$h][1] = $langs->trans("MenuAdmin");
  112. $head[$h][2] = 'editor';
  113. $h++;
  114. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  115. print '<input type="hidden" name="token" value="'.newToken().'">';
  116. print '<input type="hidden" name="action" value="update">';
  117. print dol_get_fiche_head($head, 'handler', '', -1);
  118. print '<span class="opacitymedium">'.$langs->trans("MenusDesc")."</span><br>\n";
  119. print "<br>\n";
  120. clearstatcache();
  121. // Gestionnaires de menu
  122. print '<table class="noborder centpercent">';
  123. print '<tr class="liste_titre"><td width="35%">'.$langs->trans("Menu").'</td>';
  124. print '<td>';
  125. print $form->textwithpicto($langs->trans("InternalUsers"), $langs->trans("InternalExternalDesc"));
  126. print '</td>';
  127. print '<td>';
  128. print $form->textwithpicto($langs->trans("ExternalUsers"), $langs->trans("InternalExternalDesc"));
  129. print '</td>';
  130. print '</tr>';
  131. // Menu top
  132. print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuManager").'</td>';
  133. print '<td>';
  134. $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');
  135. print '</td>';
  136. print '<td>';
  137. $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');
  138. print '</td>';
  139. print '</tr>';
  140. // Menu smartphone
  141. print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuSmartphoneManager").'</td>';
  142. print '<td>';
  143. $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');
  144. if (!empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && preg_match('/smartphone/', $conf->global->MAIN_MENU_SMARTPHONE_FORCED)
  145. || (empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && !empty($conf->global->MAIN_MENU_SMARTPHONE) && preg_match('/smartphone/', $conf->global->MAIN_MENU_SMARTPHONE))) {
  146. print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
  147. }
  148. print '</td>';
  149. print '<td>';
  150. $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');
  151. if (!empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && preg_match('/smartphone/', $conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)
  152. || (empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED) && !empty($conf->global->MAIN_MENU_SMARTPHONE) && preg_match('/smartphone/', $conf->global->MAIN_MENUFRONT_SMARTPHONE))) {
  153. print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
  154. }
  155. print '</td>';
  156. print '</tr>';
  157. print '</table>';
  158. print dol_get_fiche_end();
  159. print '<div class="center">';
  160. print '<input class="button button-save" type="submit" name="save" value="'.$langs->trans("Save").'">';
  161. print '</div>';
  162. print '</form>';
  163. // End of page
  164. llxFooter();
  165. $db->close();