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