-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathmenu.class.php
More file actions
268 lines (226 loc) · 9.41 KB
/
Copy pathmenu.class.php
File metadata and controls
268 lines (226 loc) · 9.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<?php
/**
* EfrontMenu Class file
*
* @package eFront
* @version 1.0
*/
//This file cannot be called directly, only included.
if (str_replace(DIRECTORY_SEPARATOR, "/", __FILE__) == $_SERVER['SCRIPT_FILENAME']) {
exit;
}
/**
* EfrontMenuException class
*
* This class extends Exception class and is used to issue errors regarding lessons
* @author Nick Baltas <[email protected]>
* @package eFront
* @version 1.0
*/
class EfrontMenuException extends Exception
{
const NO_ERROR = 0;
const MENU_NOT_EXISTS = 201;
const INVALID_ID = 202;
const FATHER_NOT_VALID = 203;
const INVALID_LOGIN = 204;
const DATABASE_ERROR = 205;
const DIR_NOT_EXISTS = 206;
const FILESYSTEM_ERROR = 207;
const DIRECTION_NOT_EXISTS = 208;
const GENERAL_ERROR = 299;
}
/**
* EfrontMenu class
*
* This class represents a menu
* @author Baltas Nick <[email protected]>
* @package eFront
* @version 1.0
*/
class EfrontMenu
{
public $menuCount;
/**
* The menu array. A two dimensional array of menus
*
* @since 3.5.0
* @var array
* @access public
*/
public $menu = array();
/* The array mapping categories to menus*/
private $ctg_to_menu = array();
function __construct() {
$this -> menuCount = 1;
}
/**
* Function that creates a menu with the given attributes
*
* Example:
* <code>
* $menu = new EfrontMenu();
* $newMenuId = $menu -> createMenu( array("title" => _LESSONS, "image" => "user1")); // Create a menu with title Lessons and that image
* $menu -> insertMenuOption (array(...), false, $newMenuId);
* </code>
* @param menuAttributes is an array of fields
* @return the new menu id
* @access public
*/
public function createMenu($menuAttributes) {
// The menu id may be one of the attributes
isset($menuAttributes['id']) ? $id = $menuAttributes['id']: $id = $this -> menuCount++;
foreach ($menuAttributes as $key => $value) {
$this -> menu[$id][$key] = $value;
}
return $id;
}
/**
* Function to add another Option in the menu item
* the $menuOptions is an array with the following fields
* 'id': the id of the menu
* 'image': the image of the menu item without the extension
* 'link': the href of the link pointed to by
* 'title': the title of the link
*
* Example:
* <code>
* $menu = new EfrontMenu();
* $menu -> insertMenuOption( array ("id" => "users_a", "image" => "user1", "link" => "administrator.php?ctg=users", "target" => "mainframe", "title" => _USERS), false, _USERS, "user1");
* $menu -> insertMenuOption( array ("id" => "users_a", "image" => "user1", "link" => "administrator.php?ctg=users", "target" => "mainframe", "title" => _USERS) , 'menu_with_user' );
* $menu -> insertMenuOption( array (array ("id" => "users_a", "image" => "user1", "link" => "administrator.php?ctg=users", "target" => "mainframe", "title" => _USERS), array ("id" => "employees_a", "image" => "user2", "href" => "administrator.php?ctg=employees", "target" => "mainframe", false, _EMPLOYEES));
* </code>
*
* @param $menuOptions the array with all values. May also be an array of arrays
* @param $specific_menuID optional parameter to assign a specific name to the menu
* @return false if the menu had wrong fields otherwise the id of the new menu
* @access public
*/
public function insertMenuOption($menuOptions, $specific_menuID = false, $menuTitle = false, $menuImg = false) {
if (isset($menuOptions['id'])) {
(!$specific_menuID)? $menuId = $this -> menuCount++ : $menuId = $specific_menuID;
if (!isset($menuOptions['target'])) {
$menuOptions['target'] = "mainframe";
}
if (!isset($menuOptions['link'])) {
$menuOptions['link'] = "#";
}
$optionId = $menuOptions['id'];
$this -> menu[$menuId]['options'][$optionId] = $menuOptions;
$this -> ctg_to_menu[substr($optionId, 0, strlen($optionId)-2)] = $menuId;
} else if (is_array(end($menuOptions))) {
(!$specific_menuID)? $menuId = $this -> menuCount++ : $menuId = $specific_menuID;
foreach ($menuOptions as $menuOption) {
if (!isset($menuOption['target'])) {
$menuOption['target'] = "mainframe";
}
if (!isset($menuOption['link'])) {
$menuOption['link'] = "#";
}
$optionId = $menuOption['id'];
$this -> menu[$menuId]['options'][$optionId] = $menuOption;
$this -> ctg_to_menu[substr($optionId, 0, strlen($optionId)-2)] = $menuId;
}
} else {
return false;
}
if ($menuTitle) {
$this -> menu[$menuId]["title"] = $menuTitle;
}
if ($menuImg) {
$this -> menu[$menuId]["image"] = $menuImg;
}
return $menuId -1 ;
}
/**
* Function to insert a row in a specific menu that has a prefined HTML code
*
* Example:
* <code>
* $menu = new EfrontMenu();
* $newMenuId = $menu -> createMenu( array("title" => _LESSONS, "image" => "user1")); // Create a menu with title Lessons and that image
* $newMenu -> insertMenuOptionAsRawHtml("<table height='8px'></table>", $newMenuId); // add this table - blank line
* </code>
* @param $menuId the id of the menu
* @return boolean false if the menu had wrong fields otherwise true
* @access public
*/
public function insertMenuOptionAsRawHtml($htmlCode, $menuId) {
if ($menuId) {
$this -> menu[$menuId]['options'][]['html'] = $htmlCode;
return true;
} else {
return false;
}
}
/**
* Function which adds an image to the header of a menu
* Attention: NOT to the left of a menu option
*
* Example:
* <code>
* $menu = new EfrontMenu();
* $id = $menu -> insertMenuOption( array ("id" => "users_a", "image" => "user1", "link" => "administrator.php?ctg=users", "target" => "mainframe", "title" => _USERS) );
* $menu -> addMenuImage($id, "user1");
* </code>
*
* @param $menuId the ID of the menu to assign the image to
* @param $img the image to be assigned without its extension
* @access public
*/
/*
public function addMenuImage($menuId, $img) {
if ($this -> menu[$menuId]) {
$this -> menu[$menuId]["image"] = $img;
}
}
*/
/**
* Function that creates the system menu
* Only administrators may have system menus
*
* @access public
*/
/*
public function addSystemMenu() {
$systemMenu = array();
$systemMenu[0] = array("id" => "control_panel_a", "image" => "home", "link" => "administrator.php?ctg=control_panel", "title" => _CONTROLCENTER);
$systemMenu[1] = array("id" => "forum_a", "image" => "messages", "link" => basename($_SERVER['PHP_SELF'])."?ctg=forum", "title" => _FORUM);
$systemMenu[2] = array("id" => "cms_a", "image" => "document_text", "link" => "administrator.php?ctg=cms", "title" => _CMS);
if (!$GLOBALS['currentUser'] -> coreAccess['statistics'] || $GLOBALS['currentUser'] -> coreAccess['statistics'] != 'hidden') {
$systemMenu[4] = array("id" => "statistics_system_a", "image" => "chart", "link" => "administrator.php?ctg=statistics&option=system", "title" => _SYSTEMSTATISTICS);
}
$this -> insertMenuOption($systemMenu, false, _SYSTEM);
}
*/
/**
* Function that creates the users menu
* Only administrators may have users menus
*
* @access public
*/
/*
public function addUsersMenu() {
$usersMenu = array();
$usersMenu[0] = array("id" => "users_a", "image" => "user1", "link" => "administrator.php?ctg=users", "title" => _USERS);
//$usersMenu[1] = array("id" => "user_types_a", "image" => "users_family", "link" => "administrator.php?ctg=user_types", "title" => _ROLES);
$usersMenu[2] = array("id" => "user_groups_a", "image" => "users3", "link" => "administrator.php?ctg=user_groups", "title" => _GROUPS);
$usersMenu[3] = array("id" => "statistics_user_a", "image" => "chart", "link" => "administrator.php?ctg=statistics&option=user", "title" => _USERSTATISTICS);
if (G_VERSIONTYPE == 'enterprise') { #cpp#ifdef ENTERPRISE
$usersMenu[4] = array("id" => "search_employee_a", "image" => "book_red", "link" => "administrator.php?ctg=module_hcd&op=reports", "title" => _SEARCHFOREMPLOYEE);
} #cpp#endif
$this -> insertMenuOption($usersMenu, false, _USERS);
}
*/
/*
* Function returning the menu id of the category described by the argument string
*/
public function getCategoryMenu($category) {
//pr($this->ctg_to_menu);
if (isset($this -> ctg_to_menu[$category])) {
return $this -> ctg_to_menu[$category];
} else {
return 1; // default value
}
}
}