menus.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 <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. $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) accessforbidden();
  33. $dirstandard = array();
  34. $dirsmartphone = array();
  35. $dirmenus=array_merge(array("/core/menus/"),(array) $conf->modules_parts['menus']);
  36. foreach($dirmenus as $dirmenu)
  37. {
  38. $dirstandard[]=$dirmenu.'standard';
  39. $dirsmartphone[]=$dirmenu.'smartphone';
  40. }
  41. $error=0;
  42. // Cette page peut etre longue. On augmente le delai autorise.
  43. // Ne fonctionne que si on est pas en safe_mode.
  44. $err=error_reporting();
  45. error_reporting(0); // Disable all errors
  46. //error_reporting(E_ALL);
  47. @set_time_limit(300); // Need more than 240 on Windows 7/64
  48. error_reporting($err);
  49. /*
  50. * Actions
  51. */
  52. if ($action == 'update' && ! $cancel)
  53. {
  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')) $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i','',GETPOST('MAIN_MENU_SMARTPHONE','alpha'))]=1;
  64. if (GETPOST('MAIN_MENUFRONT_SMARTPHONE','alpha')) $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i','',GETPOST('MAIN_MENUFRONT_SMARTPHONE','alpha'))]=1;
  65. // Initialize menu handlers
  66. foreach ($listofmenuhandler as $key => $val)
  67. {
  68. // Load sql init_menu_handler.sql file
  69. $dirmenus=array_merge(array("/core/menus/"),(array) $conf->modules_parts['menus']);
  70. foreach($dirmenus as $dirmenu)
  71. {
  72. $file='init_menu_'.$key.'.sql';
  73. $fullpath=dol_buildpath($dirmenu.$file);
  74. //print 'action='.$action.' Search menu into fullpath='.$fullpath.'<br>';exit;
  75. if (file_exists($fullpath))
  76. {
  77. $db->begin();
  78. $result=run_sql($fullpath,1,'',1,$key,'none');
  79. if ($result > 0)
  80. {
  81. $db->commit();
  82. }
  83. else
  84. {
  85. $error++;
  86. setEventMessages($langs->trans("FailedToInitializeMenu").' '.$key, null, 'errors');
  87. $db->rollback();
  88. }
  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 load_fiche_titre($langs->trans("Menus"),'','title_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("Miscellaneous");
  119. $head[$h][2] = 'misc';
  120. $h++;
  121. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  122. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  123. print '<input type="hidden" name="action" value="update">';
  124. dol_fiche_head($head, 'handler', $langs->trans("Menus"), -1);
  125. print $langs->trans("MenusDesc")."<br>\n";
  126. print "<br>\n";
  127. if ($action == 'edit')
  128. {
  129. clearstatcache();
  130. // Gestionnaires de menu
  131. print '<table class="noborder" width="100%">';
  132. print '<tr class="liste_titre"><td width="35%">'.$langs->trans("Menu").'</td>';
  133. print '<td>';
  134. print $form->textwithpicto($langs->trans("InternalUsers"),$langs->trans("InternalExternalDesc"));
  135. print '</td>';
  136. print '<td>';
  137. print $form->textwithpicto($langs->trans("ExternalUsers"),$langs->trans("InternalExternalDesc"));
  138. print '</td>';
  139. print '</tr>';
  140. // Menu top
  141. print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuManager").'</td>';
  142. print '<td>';
  143. $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');
  144. print '</td>';
  145. print '<td>';
  146. $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');
  147. print '</td>';
  148. print '</tr>';
  149. // Menu smartphone
  150. print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuSmartphoneManager").'</td>';
  151. print '<td>';
  152. $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');
  153. print '</td>';
  154. print '<td>';
  155. $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');
  156. print '</td>';
  157. print '</tr>';
  158. print '</table>';
  159. }
  160. else
  161. {
  162. // Gestionnaires de menu
  163. print '<table class="noborder" width="100%">';
  164. print '<tr class="liste_titre"><td width="35%">'.$langs->trans("Menu").'</td>';
  165. print '<td>';
  166. print $form->textwithpicto($langs->trans("InternalUsers"),$langs->trans("InternalExternalDesc"));
  167. print '</td>';
  168. print '<td>';
  169. print $form->textwithpicto($langs->trans("ExternalUsers"),$langs->trans("InternalExternalDesc"));
  170. print '</td>';
  171. print '</tr>';
  172. print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuManager").'</td>';
  173. print '<td>';
  174. $filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENU_STANDARD_FORCED)?$conf->global->MAIN_MENU_STANDARD:$conf->global->MAIN_MENU_STANDARD_FORCED));
  175. print $filelib;
  176. print '</td>';
  177. print '<td>';
  178. $filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENUFRONT_STANDARD_FORCED)?$conf->global->MAIN_MENUFRONT_STANDARD:$conf->global->MAIN_MENUFRONT_STANDARD_FORCED));
  179. print $filelib;
  180. print '</td>';
  181. print '</tr>';
  182. print '<tr class="oddeven">';
  183. print '<td>'.$langs->trans("DefaultMenuSmartphoneManager").'</td>';
  184. print '<td>';
  185. $filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED)?$conf->global->MAIN_MENU_SMARTPHONE:$conf->global->MAIN_MENU_SMARTPHONE_FORCED));
  186. print $filelib;
  187. if (! empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && preg_match('/smartphone/', $conf->global->MAIN_MENU_SMARTPHONE_FORCED)
  188. || (empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && ! empty($conf->global->MAIN_MENU_SMARTPHONE) && preg_match('/smartphone/',$conf->global->MAIN_MENU_SMARTPHONE)))
  189. {
  190. print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
  191. }
  192. print '</td>';
  193. print '<td>';
  194. $filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)?$conf->global->MAIN_MENUFRONT_SMARTPHONE:$conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED));
  195. print $filelib;
  196. if (! empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && preg_match('/smartphone/',$conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)
  197. || (empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED) && ! empty($conf->global->MAIN_MENU_SMARTPHONE) && preg_match('/smartphone/',$conf->global->MAIN_MENUFRONT_SMARTPHONE)))
  198. {
  199. print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
  200. }
  201. print '</td>';
  202. print '</tr>';
  203. print '</table>';
  204. }
  205. dol_fiche_end();
  206. if ($action == 'edit')
  207. {
  208. print '<div class="center">';
  209. print '<input class="button" type="submit" name="save" value="'.$langs->trans("Save").'">';
  210. print ' &nbsp; &nbsp; &nbsp; ';
  211. print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
  212. print '</div>';
  213. }
  214. print '</form>';
  215. if ($action != 'edit')
  216. {
  217. print '<div class="tabsAction">';
  218. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
  219. print '</div>';
  220. }
  221. // End of page
  222. llxFooter();
  223. $db->close();