1<?php
2/* Copyright (C) 2005-2015 Laurent Destailleur  <eldy@users.sourceforge.net>
3 *
4 * This file is a modified version of datepicker.php from phpBSM to fix some
5 * bugs, to add new features and to dramatically increase speed.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21/**
22 *       \file       htdocs/core/get_menudiv.php
23 *       \brief      File to return menu into a div tree, to be used by other frontend
24 */
25
26//if (! defined('NOREQUIREUSER'))   define('NOREQUIREUSER','1');	// Not disabled cause need to load personalized language
27//if (! defined('NOREQUIREDB'))   define('NOREQUIREDB','1');		// Not disabled cause need to load personalized language
28//if (! defined('NOREQUIRESOC'))    define('NOREQUIRESOC','1');
29//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');		// Not disabled cause need to do translations
30if (!defined('NOCSRFCHECK')) {
31	define('NOCSRFCHECK', 1);
32}
33if (!defined('NOTOKENRENEWAL')) {
34	define('NOTOKENRENEWAL', 1);
35}
36//if (! defined('NOLOGIN')) define('NOLOGIN',1);					// Not disabled cause need to load personalized language
37if (!defined('NOREQUIREMENU')) {
38	define('NOREQUIREMENU', 1);
39}
40if (!defined('NOREQUIREHTML')) {
41	define('NOREQUIREHTML', 1);
42}
43if (!defined('NOBROWSERNOTIF')) {
44	define('NOBROWSERNOTIF', 1);
45}
46
47if (!defined('DISABLE_JQUERY_TABLEDND')) {
48	define('DISABLE_JQUERY_TABLEDND', 1);
49}
50if (!defined('DISABLE_JQUERY_JNOTIFY')) {
51	define('DISABLE_JQUERY_JNOTIFY', 1);
52}
53if (!defined('DISABLE_JQUERY_FLOT')) {
54	define('DISABLE_JQUERY_FLOT', 1);
55}
56if (!defined('DISABLE_JQUERY_JEDITABLE')) {
57	define('DISABLE_JQUERY_JEDITABLE', 1);
58}
59if (!defined('DISABLE_CKEDITOR')) {
60	define('DISABLE_CKEDITOR', 1);
61}
62if (!defined('DISABLE_DATE_PICKER')) {
63	define('DISABLE_DATE_PICKER', 1);
64}
65if (!defined('DISABLE_SELECT2')) {
66	define('DISABLE_SELECT2', 1);
67}
68
69require_once '../main.inc.php';
70
71if (GETPOST('lang', 'aZ09')) {
72	$langs->setDefaultLang(GETPOST('lang', 'aZ09')); // If language was forced on URL by the main.inc.php
73}
74
75$langs->load("main");
76$right = ($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right');
77$left = ($langs->trans("DIRECTION") == 'rtl' ? 'right' : 'left');
78
79
80/*
81 * View
82 */
83
84$title = $langs->trans("Menu");
85
86// URL http://mydolibarr/core/get_menudiv.php?dol_use_jmobile=1 can be used for tests
87$head = '<!-- Menu -->'."\n";
88$arrayofjs = array();
89$arrayofcss = array();
90top_htmlhead($head, $title, 0, 0, $arrayofjs, $arrayofcss);
91
92print '<body>'."\n";
93
94// Javascript to make menu active like Jmobile did.
95print '
96<style>
97    /*Lets hide the non active LIs by default*/
98    body {
99        font-size: 16px;
100    }
101    body ul {
102        margin: 0;
103        padding-left: 0;
104    }
105    body ul li {
106        list-style: none;
107    }
108    body ul ul {
109        display: none;
110    }
111
112    a.alilevel0 {
113        background-image: url(\''.DOL_URL_ROOT.'/theme/'.urlencode($conf->theme).'/img/next.png\') !important;
114        background-repeat: no-repeat !important;
115        background-position-x: 10px;
116        background-position-y: 16px;
117        padding: 1em 15px 1em 40px;
118    }
119    li.lilevel0 font.vsmenudisabled {
120        background-repeat: no-repeat !important;
121        background-position-x: 10px;
122        background-position-y: 16px;
123        padding: 1em 15px 1em 40px;
124        background: #f8f8f8;
125        display: block;
126        font-size: 16px !important;
127    }
128    li.lilevel1 {
129        padding: 1em 15px 0.5em 40px;
130        border-top: 1px solid #aaa;
131        margin-right: 0px;
132    	margin-left: 0px;
133        border-right: 0px ! important;
134    }
135    li.lilevel1:first-child {
136        margin-right: 0px;
137        margin-left: 0px;
138    }
139    li.lilevel1 a {
140        padding-bottom: 5px;
141    }
142    li.lilevel1 a, li.lilevel1 {
143        color: #000;
144        cursor: pointer;
145        display: block;
146    }
147    li.lilevel2 a {
148        padding: 0.7em 15px 0.7em 40px;
149        color: #000;
150        cursor: pointer;
151        display: block;
152    }
153    li.lilevel3 a {
154        padding: 0.6em 15px 0.6em 60px;
155        color: #000;
156        cursor: pointer;
157        display: block;
158    }
159    li.lilevel4 a {
160        padding: 0.2em 15px 8px 60px;
161        color: #000;
162        cursor: pointer;
163        display: block;
164    }
165    li.lilevel5 a {
166        padding: 0.2em 15px 0.2em 60px;
167        color: #000;
168        cursor: pointer;
169        display: block;
170    }
171    li.lilevel3:last-child {
172        padding-bottom: 10px;
173    }
174    a.alilevel0, li.lilevel1 a {
175        text-overflow: ellipsis;
176        overflow: hidden;
177        white-space: nowrap;
178        display: block;
179    }
180	.vsmenudisabled .fa, .vsmenudisabled .fas, .vsmenudisabled .far {
181	    color: #aaa !important;
182	}
183</style>
184
185<script type="text/javascript">
186$(document).ready(function(){
187    $("body ul").click(function(){
188        console.log("We click on body ul");
189
190        $(this).siblings().find("li ul").slideUp(0);
191
192        $(this).find("li ul").slideToggle(200);
193
194        target = $(this);
195        $(\'html, body\').animate({
196          scrollTop: target.offset().top
197        }, 300);
198
199    })
200});
201</script>
202';
203
204
205if (empty($user->socid)) {	// If internal user or not defined
206	$conf->standard_menu = (empty($conf->global->MAIN_MENU_STANDARD_FORCED) ? (empty($conf->global->MAIN_MENU_STANDARD) ? 'eldy_menu.php' : $conf->global->MAIN_MENU_STANDARD) : $conf->global->MAIN_MENU_STANDARD_FORCED);
207} else // If external user
208{
209	$conf->standard_menu = (empty($conf->global->MAIN_MENUFRONT_STANDARD_FORCED) ? (empty($conf->global->MAIN_MENUFRONT_STANDARD) ? 'eldy_menu.php' : $conf->global->MAIN_MENUFRONT_STANDARD) : $conf->global->MAIN_MENUFRONT_STANDARD_FORCED);
210}
211
212// Load the menu manager (only if not already done)
213$file_menu = $conf->standard_menu;
214if (GETPOST('menu', 'aZ09')) {
215	$file_menu = GETPOST('menu', 'aZ09'); // example: menu=eldy_menu.php
216}
217if (!class_exists('MenuManager')) {
218	$menufound = 0;
219	$dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
220	foreach ($dirmenus as $dirmenu) {
221		$menufound = dol_include_once($dirmenu."standard/".$file_menu);
222		if ($menufound) {
223			break;
224		}
225	}
226	if (!$menufound) {	// If failed to include, we try with standard
227		dol_syslog("You define a menu manager '".$file_menu."' that can not be loaded.", LOG_WARNING);
228		$file_menu = 'eldy_menu.php';
229		include_once DOL_DOCUMENT_ROOT."/core/menus/standard/".$file_menu;
230	}
231}
232$menumanager = new MenuManager($db, empty($user->socid) ? 0 : 1);
233$menumanager->loadMenu('all', 'all'); // Load this->tabMenu with sql menu entries
234//var_dump($menumanager);exit;
235$menumanager->showmenu('jmobile');
236
237print '</body>';
238
239print '</html>'."\n";
240
241$db->close();
242