/
menu_function.php
151 lines (129 loc) · 4.38 KB
/
menu_function.php
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
<?php
/**
***********************************************************************************************
* Various functions for categories
*
* @copyright 2004-2021 The Admidio Team
* @see http://www.admidio.org/
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2.0 only
***********************************************************************************************
*/
/******************************************************************************
* Parameters:
*
* men_id: Id of the menu that should be edited
* mode : 1 - Create or edit menu
* 2 - Delete menu
* 3 - Change sequence for parameter men_id
* sequence: New sequence for the parameter men_id
*
*****************************************************************************/
require_once(__DIR__ . '/../../system/common.php');
// Initialize and check the parameters
$getMenId = admFuncVariableIsValid($_GET, 'men_id', 'int');
$getMode = admFuncVariableIsValid($_GET, 'mode', 'int', array('requireValue' => true));
// check rights
if(!$gCurrentUser->isAdministrator())
{
$gMessage->show($gL10n->get('SYS_NO_RIGHTS'));
}
// create menu object
$menu = new TableMenu($gDb);
if($getMenId > 0)
{
$menu->readDataById($getMenId);
}
// create menu or update it
if($getMode === 1)
{
$_SESSION['menu_request'] = $_POST;
$postIdParent = admFuncVariableIsValid($_POST, 'men_men_id_parent', 'int');
$postComId = admFuncVariableIsValid($_POST, 'men_com_id', 'int');
$postName = admFuncVariableIsValid($_POST, 'men_name', 'string', array('default' => ''));
$postDesc = admFuncVariableIsValid($_POST, 'men_description', 'string', array('default' => ''));
$postUrl = admFuncVariableIsValid($_POST, 'men_url', 'url', array('default' => ''));
$postIcon = admFuncVariableIsValid($_POST, 'men_icon', 'string', array('default' => ''));
// within standard menu items the url should not be changed
if($menu->getValue('men_standard'))
{
$postUrl = $menu->getValue('men_url');
}
// Check if mandatory fields are filled
if($postName === '')
{
$gMessage->show($gL10n->get('SYS_FIELD_EMPTY', array($gL10n->get('SYS_NAME'))));
// => EXIT
}
if($postUrl === '')
{
$gMessage->show($gL10n->get('SYS_FIELD_EMPTY', array($gL10n->get('ORG_URL'))));
// => EXIT
}
// check if font awesome syntax is used or if its a valid filename syntax
if($postIcon !== '' && !preg_match('/fa-[a-zA-z0-9]/', $postIcon))
{
try
{
StringUtils::strIsValidFileName($postIcon, true);
}
catch (AdmException $e)
{
$gMessage->show($gL10n->get('SYS_INVALID_FONT_AWESOME'));
// => EXIT
}
}
$menu->setValue('men_icon', $postIcon);
$menu->setValue('men_men_id_parent', $postIdParent);
$menu->setValue('men_name', $postName);
$menu->setValue('men_description', $postDesc);
if(!$menu->getValue('men_standard'))
{
$menu->setValue('men_url', $postUrl);
$menu->setValue('men_com_id', $postComId);
}
// save Data to Table
$returnCode = $menu->save();
if($returnCode < 0)
{
$gMessage->show($gL10n->get('SYS_NO_RIGHTS'));
}
// Read current roles of the menu
$displayMenu = new RolesRights($gDb, 'menu_view', (int) $menu->getValue('men_id'));
$rolesDisplayRight = $displayMenu->getRolesIds();
if(!isset($_POST['menu_view']) || !is_array($_POST['menu_view']))
{
// remove all entries, so it is allowed without login
$displayMenu->removeRoles($rolesDisplayRight);
}
else
{
// add new or update roles
$displayMenu->addRoles(array_map('intval', $_POST['menu_view']));
}
if($gNavigation->count() > 1)
{
$gNavigation->deleteLastUrl();
}
else
{
$gNavigation->addUrl($gHomepage, 'Home');
}
unset($_SESSION['menu_request']);
header('Location: '. $gNavigation->getUrl());
exit();
}
elseif($getMode === 2)
{
// delete menu
if($menu->delete())
{
echo 'done';
}
}
elseif($getMode === 3)
{
// Kategoriereihenfolge aktualisieren
$getSequence = admFuncVariableIsValid($_GET, 'sequence', 'string', array('validValues' => array(TableMenu::MOVE_UP, TableMenu::MOVE_DOWN)));
$menu->moveSequence($getSequence);
exit();
}