tiki-admin_menu_options.php 5.98 KB
Newer Older
lrargerich's avatar
lrargerich committed
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project
6
// 
7 8
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
9
// $Id$
changi67's avatar
changi67 committed
10

11
require_once ('tiki-setup.php');
12
$menulib = TikiLib::lib('menu');
13
$access->check_permission(array('tiki_p_edit_menu_option'));
14
if (!isset($_REQUEST["menuId"])) {
15 16 17
	$smarty->assign('msg', tra("No menu indicated"));
	$smarty->display("error.tpl");
	die;
lrargerich's avatar
lrargerich committed
18
}
changi67's avatar
changi67 committed
19
$auto_query_args = array(
20 21 22 23
	'offset',
	'find',
	'sort_mode',
	'menuId',
24 25 26
	'maxRecords',
	'preview_css',
	'preview_type',
changi67's avatar
changi67 committed
27
);
28

29
$maxPos = $menulib->get_max_option($_REQUEST["menuId"]);
30
$smarty->assign('menuId', $_REQUEST["menuId"]);
31
$editable_menu_info = $menulib->get_menu($_REQUEST["menuId"]);
32
$smarty->assign('editable_menu_info', $editable_menu_info);
33
if (!isset($_REQUEST["optionId"])) {
34
	$_REQUEST["optionId"] = 0;
lrargerich's avatar
lrargerich committed
35
}
36 37
$smarty->assign('optionId', $_REQUEST["optionId"]);
if ($_REQUEST["optionId"]) {
38
	$info = $menulib->get_menu_option($_REQUEST["optionId"]);
39
	$cookietab = 2;
lrargerich's avatar
lrargerich committed
40
} else {
41 42 43 44 45 46 47 48 49
	$info = array();
	$info["name"] = '';
	$info["url"] = '';
	$info["section"] = '';
	$info["perm"] = '';
	$info["groupname"] = '';
	$info["userlevel"] = '';
	$info["type"] = 'o';
	$info["icon"] = '';
50
	$info["class"] = '';
51
	$info["position"] = $maxPos + 10;
lrargerich's avatar
lrargerich committed
52
}
53 54
$smarty->assign('name', $info["name"]);
$smarty->assign('url', $info["url"]);
55 56
$smarty->assign('section', $info["section"]);
$smarty->assign('perm', $info["perm"]);
57
$smarty->assign('type', $info["type"]);
58
$smarty->assign('icon', $info["icon"]);
59
$smarty->assign('position', $info["position"]);
60 61
$smarty->assign('groupname', $info["groupname"]);
$smarty->assign('userlevel', $info["userlevel"]);
62 63
$smarty->assign('class', $info["class"]);

64
if (isset($_REQUEST["remove"])) {
65 66 67
	$access->check_authenticity();
	$menulib->remove_menu_option($_REQUEST["remove"]);
	$maxPos = $menulib->get_max_option($_REQUEST["menuId"]);
68
	$smarty->assign('position', $maxPos + 10);
lrargerich's avatar
lrargerich committed
69
}
70
if (isset($_REQUEST["up"])) {
71 72
	check_ticket('admin-menu-options');
	$res = $menulib->prev_pos($_REQUEST["up"]);
73 74
}
if (isset($_REQUEST["down"])) {
75 76 77
	check_ticket('admin-menu-options');
	$area = 'downmenuoption';
	$res = $menulib->next_pos($_REQUEST["down"]);
78
}
79
if (isset($_REQUEST['delsel_x']) && isset($_REQUEST['checked'])) {
80
	check_ticket('admin-menu-options');
81
	foreach ($_REQUEST['checked'] as $id) {
82 83 84
		$menulib->remove_menu_option($id);
	}
	$maxPos = $menulib->get_max_option($_REQUEST['menuId']);
85
	$smarty->assign('position', $maxPos + 10);
86
}
87
if (isset($_REQUEST["save"])) {
88 89 90
	if (!isset($_REQUEST['groupname'])) $_REQUEST['groupname'] = '';
	elseif (is_array($_REQUEST['groupname'])) $_REQUEST['groupname'] = implode(',', $_REQUEST['groupname']);
	if (!isset($_REQUEST['level'])) $_REQUEST['level'] = 0;
91
	$modlib = TikiLib::lib('mod');
92
	check_ticket('admin-menu-options');
93
	$menulib->replace_menu_option($_REQUEST["menuId"], $_REQUEST["optionId"], $_REQUEST["name"], $_REQUEST["url"], $_REQUEST["type"], $_REQUEST["position"], $_REQUEST["section"], $_REQUEST["perm"], $_REQUEST["groupname"], $_REQUEST['level'], $_REQUEST['icon'], $_REQUEST['class']);
94
	$modlib->clear_cache();
95
	$smarty->assign('position', $_REQUEST["position"] + 10);
96 97 98 99 100 101 102 103 104
	$smarty->assign('name', '');
	$smarty->assign('optionId', 0);
	$smarty->assign('url', '');
	$smarty->assign('section', '');
	$smarty->assign('perm', '');
	$smarty->assign('groupname', '');
	$smarty->assign('userlevel', 0);
	$smarty->assign('type', 'o');
	$smarty->assign('icon', '');
105
	$smarty->assign('class', '');
106
	$cookietab = 1;
lrargerich's avatar
lrargerich committed
107
}
108
if (!isset($_REQUEST["sort_mode"])) {
109
	$sort_mode = 'position_asc';
lrargerich's avatar
lrargerich committed
110
} else {
111
	$sort_mode = $_REQUEST["sort_mode"];
112 113
}
if (!isset($_REQUEST["offset"])) {
114
	$offset = 0;
lrargerich's avatar
lrargerich committed
115
} else {
116
	$offset = $_REQUEST["offset"];
lrargerich's avatar
lrargerich committed
117
}
118 119
$smarty->assign_by_ref('offset', $offset);
if (isset($_REQUEST["find"])) {
120
	$find = $_REQUEST["find"];
lrargerich's avatar
lrargerich committed
121
} else {
122
	$find = '';
lrargerich's avatar
lrargerich committed
123
}
124
$smarty->assign('find', $find);
sylvieg's avatar
sylvieg committed
125
if (isset($_REQUEST['maxRecords'])) {
126
	$maxRecords = $_REQUEST['maxRecords'];
127
} else {
128
	$maxRecords = $prefs['maxRecords'];
129
}
130 131

$smarty->assign('preview_type', isset($_REQUEST['preview_type']) && $_REQUEST['preview_type'] === 'horiz' ? 'horiz' : 'vert');
jonnybradley's avatar
jonnybradley committed
132
$smarty->assign('preview_css', isset($_REQUEST['preview_css']) && $_REQUEST['preview_css'] === 'On' ? 'y' : 'n');
133

134
$headerlib->add_js('var permNames = ' . json_encode(TikiLib::lib('user')->get_permission_names_for('all')) . ';');
135 136 137 138 139 140
$feature_prefs = array();
foreach ($prefs as $k => $v) {	// attempt to filter out non-feature prefs (still finds 133!)
	if (strpos($k, 'feature') !== false && preg_match_all('/_/m', $k, $m) === 1) {
		$feature_prefs[] = $k;
	}
}
141
$headerlib->add_js('var prefNames = ' . json_encode($feature_prefs) . ';');
142

143
$smarty->assign_by_ref('maxRecords', $maxRecords);
144
$smarty->assign_by_ref('sort_mode', $sort_mode);
145
$allchannels = $menulib->list_menu_options($_REQUEST["menuId"], 0, -1, $sort_mode, $find);
146
$allchannels = $menulib->sort_menu_options($allchannels);
147
$channels = $menulib->list_menu_options($_REQUEST["menuId"], $offset, $maxRecords, $sort_mode, $find, true, 0, true);
148
$channels = $menulib->describe_menu_types($channels);
149
$smarty->assign_by_ref('cant_pages', $channels["cant"]);
150
$smarty->assign_by_ref('channels', $channels["data"]);
151
$smarty->assign_by_ref('allchannels', $allchannels["data"]);
changi67's avatar
changi67 committed
152
if (isset($info['groupname']) && !is_array($info['groupname'])) $info['groupname'] = explode(',', $info['groupname']);
153
$all_groups = $userlib->list_all_groups();
154
if (is_array($all_groups)) foreach ($all_groups as $g) $option_groups[$g] = (is_array($info['groupname']) && in_array($g, $info['groupname'])) ? 'selected="selected"' : '';
155
$smarty->assign_by_ref('option_groups', $option_groups);
156
$smarty->assign('escape_menu_labels', ($prefs['menus_item_names_raw'] === 'n' && $editable_menu_info['parse'] === 'n'));
157

158
ask_ticket('admin-menu-options');
159 160
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
lrargerich's avatar
lrargerich committed
161
// Display the template
162
$smarty->assign('mid', 'tiki-admin_menu_options.tpl');
163
$smarty->display("tiki.tpl");