PageRenderTime 192ms CodeModel.GetById 22ms RepoModel.GetById 2ms app.codeStats 0ms

/htdocs/admin/menus.php

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