menus.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. // Load Dolibarr environment
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  28. $action = GETPOST('action', 'aZ09');
  29. $cancel = GETPOST('cancel', 'alpha');
  30. // Load translation files required by the page
  31. $langs->loadLangs(array("companies", "products", "admin", "users", "other"));
  32. // Security check
  33. if (!$user->admin) {
  34. accessforbidden();
  35. }
  36. $dirstandard = array();
  37. $dirsmartphone = array();
  38. $dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
  39. foreach ($dirmenus as $dirmenu) {
  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' && !$cancel) {
  55. $_SESSION["mainmenu"] = "home"; // Le gestionnaire de menu a pu changer
  56. dolibarr_set_const($db, "MAIN_MENU_STANDARD", GETPOST('MAIN_MENU_STANDARD', 'alpha'), 'chaine', 0, '', $conf->entity);
  57. dolibarr_set_const($db, "MAIN_MENU_SMARTPHONE", GETPOST('MAIN_MENU_SMARTPHONE', 'alpha'), 'chaine', 0, '', $conf->entity);
  58. dolibarr_set_const($db, "MAIN_MENUFRONT_STANDARD", GETPOST('MAIN_MENUFRONT_STANDARD', 'alpha'), 'chaine', 0, '', $conf->entity);
  59. dolibarr_set_const($db, "MAIN_MENUFRONT_SMARTPHONE", GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha'), 'chaine', 0, '', $conf->entity);
  60. // Define list of menu handlers to initialize
  61. $listofmenuhandler = array();
  62. $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENU_STANDARD', 'alpha'))] = 1;
  63. $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENUFRONT_STANDARD', 'alpha'))] = 1;
  64. if (GETPOST('MAIN_MENU_SMARTPHONE', 'alpha')) {
  65. $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENU_SMARTPHONE', 'alpha'))] = 1;
  66. }
  67. if (GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha')) {
  68. $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha'))] = 1;
  69. }
  70. // Initialize menu handlers
  71. foreach ($listofmenuhandler as $key => $val) {
  72. // Load sql init_menu_handler.sql file
  73. $dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
  74. foreach ($dirmenus as $dirmenu) {
  75. $file = 'init_menu_'.$key.'.sql';
  76. $fullpath = dol_buildpath($dirmenu.$file);
  77. //print 'action='.$action.' Search menu into fullpath='.$fullpath.'<br>';exit;
  78. if (file_exists($fullpath)) {
  79. $db->begin();
  80. $result = run_sql($fullpath, 1, '', 1, $key, 'none');
  81. if ($result > 0) {
  82. $db->commit();
  83. } else {
  84. $error++;
  85. setEventMessages($langs->trans("FailedToInitializeMenu").' '.$key, null, 'errors');
  86. $db->rollback();
  87. }
  88. }
  89. }
  90. }
  91. if (!$error) {
  92. $db->close();
  93. // We make a header redirect because we need to change menu NOW.
  94. header("Location: ".$_SERVER["PHP_SELF"]);
  95. exit;
  96. }
  97. }
  98. /*
  99. * View
  100. */
  101. $form = new Form($db);
  102. $formadmin = new FormAdmin($db);
  103. $wikihelp = 'EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
  104. llxHeader('', $langs->trans("Setup"), $wikihelp);
  105. print load_fiche_titre($langs->trans("Menus"), '', 'title_setup');
  106. $h = 0;
  107. $head[$h][0] = DOL_URL_ROOT."/admin/menus.php";
  108. $head[$h][1] = $langs->trans("MenuHandlers");
  109. $head[$h][2] = 'handler';
  110. $h++;
  111. $head[$h][0] = DOL_URL_ROOT."/admin/menus/index.php";
  112. $head[$h][1] = $langs->trans("MenuAdmin");
  113. $head[$h][2] = 'editor';
  114. $h++;
  115. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  116. print '<input type="hidden" name="token" value="'.newToken().'">';
  117. print '<input type="hidden" name="action" value="update">';
  118. print dol_get_fiche_head($head, 'handler', '', -1);
  119. print '<span class="opacitymedium">'.$langs->trans("MenusDesc")."</span><br>\n";
  120. print "<br>\n";
  121. clearstatcache();
  122. // Gestionnaires de menu
  123. print '<table class="noborder centpercent">';
  124. print '<tr class="liste_titre"><td width="35%">'.$langs->trans("Menu").'</td>';
  125. print '<td>';
  126. print $form->textwithpicto($langs->trans("InternalUsers"), $langs->trans("InternalExternalDesc"));
  127. print '</td>';
  128. print '<td>';
  129. print $form->textwithpicto($langs->trans("ExternalUsers"), $langs->trans("InternalExternalDesc"));
  130. print '</td>';
  131. print '</tr>';
  132. // Menu top
  133. print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuManager").'</td>';
  134. print '<td>';
  135. $formadmin->select_menu(!getDolGlobalString('MAIN_MENU_STANDARD_FORCED') ? $conf->global->MAIN_MENU_STANDARD : $conf->global->MAIN_MENU_STANDARD_FORCED, 'MAIN_MENU_STANDARD', $dirstandard, !getDolGlobalString('MAIN_MENU_STANDARD_FORCED') ? '' : ' disabled');
  136. print '</td>';
  137. print '<td>';
  138. $formadmin->select_menu(!getDolGlobalString('MAIN_MENUFRONT_STANDARD_FORCED') ? $conf->global->MAIN_MENUFRONT_STANDARD : $conf->global->MAIN_MENUFRONT_STANDARD_FORCED, 'MAIN_MENUFRONT_STANDARD', $dirstandard, !getDolGlobalString('MAIN_MENUFRONT_STANDARD_FORCED') ? '' : ' disabled');
  139. print '</td>';
  140. print '</tr>';
  141. // Menu smartphone
  142. print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuSmartphoneManager").'</td>';
  143. print '<td>';
  144. $formadmin->select_menu(!getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') ? $conf->global->MAIN_MENU_SMARTPHONE : $conf->global->MAIN_MENU_SMARTPHONE_FORCED, 'MAIN_MENU_SMARTPHONE', array_merge($dirstandard, $dirsmartphone), !getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') ? '' : ' disabled');
  145. if (getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') && preg_match('/smartphone/', $conf->global->MAIN_MENU_SMARTPHONE_FORCED)
  146. || (!getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') && getDolGlobalString('MAIN_MENU_SMARTPHONE') && preg_match('/smartphone/', $conf->global->MAIN_MENU_SMARTPHONE))) {
  147. print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
  148. }
  149. print '</td>';
  150. print '<td>';
  151. $formadmin->select_menu(!getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE_FORCED') ? $conf->global->MAIN_MENUFRONT_SMARTPHONE : $conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED, 'MAIN_MENUFRONT_SMARTPHONE', array_merge($dirstandard, $dirsmartphone), !getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE_FORCED') ? '' : ' disabled');
  152. if (getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') && preg_match('/smartphone/', $conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)
  153. || (!getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE_FORCED') && getDolGlobalString('MAIN_MENU_SMARTPHONE') && preg_match('/smartphone/', $conf->global->MAIN_MENUFRONT_SMARTPHONE))) {
  154. print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
  155. }
  156. print '</td>';
  157. print '</tr>';
  158. print '</table>';
  159. print dol_get_fiche_end();
  160. print '<div class="center">';
  161. print '<input class="button button-save" type="submit" name="save" value="'.$langs->trans("Save").'">';
  162. print '</div>';
  163. print '</form>';
  164. // End of page
  165. llxFooter();
  166. $db->close();