2 /************************************************************************
3 * MXChange v0.2.1 Start: 09/28/2003 *
4 * =============== Last change: 05/13/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-memedit.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Edit member's menu *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Editieren Sie das Menue fuer Ihre Mitglieder *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2008 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
48 // Do we edit/delete/change main menus or sub menus?
49 $AND = "(`what` = '' OR `what` IS NULL)"; $SUB = '';
51 if (REQUEST_ISSET_GET('sub')) {
52 $AND = sprintf("`action`='%s' AND `what` IS NOT NULL", REQUEST_GET('sub'));
53 $SUB = REQUEST_GET('sub');
56 // Get count of (maybe) selected menu points
58 if (REQUEST_ISSET_POST('sel')) $chk = countPostSelection();
60 // List all menu points and make them editable
61 if ((REQUEST_ISSET_POST('edit')) && ($chk > 0) && (!IS_DEMO())) {
63 define('__SUB_VALUE', $SUB);
64 define('__CHK_VALUE', $chk);
65 $SW = 2; $cnt = 0; $OUT = '';
66 foreach (REQUEST_POST('sel') as $sel => $confirm) {
69 $result = SQL_QUERY_ESC("SELECT title, action, what FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE ".$AND." AND id=%s LIMIT 1",
70 array(bigintval($sel)), __FILE__, __LINE__);
71 if (SQL_NUMROWS($result) == 1) {
72 // Entry found so we load the stuff...
73 list($menu, $act, $wht, $descr) = SQL_FETCHROW($result);
74 SQL_FREERESULT($result);
80 'act' => ADMIN_MAKE_MENU_SELECTION('member', "act", "sel_act[".$sel."]", $act),
81 'what' => ADMIN_MAKE_MENU_SELECTION('member', "what", "sel_what[".$sel."]", $wht),
84 $OUT .= LOAD_TEMPLATE("admin_mmenu_edit_row", true, $content);
91 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
96 define('__MENU_ROWS', $OUT);
97 define('__CNT_VALUE', $cnt);
100 LOAD_TEMPLATE("admin_mmenu_edit");
101 } elseif ((REQUEST_ISSET_POST('del')) && ($chk > 0) && (!IS_DEMO())) {
102 // Del menu entries with or without confirmation
103 define('__SUB_VALUE', $SUB);
104 define('__CHK_VALUE', $chk);
105 $SW = 2; $cnt = 0; $OUT = '';
106 foreach (REQUEST_POST('sel') as $sel => $confirm) {
109 $result = SQL_QUERY_ESC("SELECT title FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE ".$AND." AND id=%s LIMIT 1",
110 array(bigintval($sel)), __FILE__, __LINE__);
111 if (SQL_NUMROWS($result) == 1) {
112 // Entry found so we load the stuff...
113 list($title) = SQL_FETCHROW($result);
114 SQL_FREERESULT($result);
120 $OUT .= LOAD_TEMPLATE("admin_mmenu_delete_row", true, $content);
127 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
131 define('__MENU_ROWS', $OUT);
132 define('__CNT_VALUE', $cnt);
135 LOAD_TEMPLATE("admin_mmenu_delete");
136 } elseif ((REQUEST_ISSET_POST(('status'))) && ($chk > 0) && (!IS_DEMO())) {
137 // Change status (visible / locked)
138 define('__SUB_VALUE', $SUB);
139 define('__CHK_VALUE', $chk);
140 $SW = 2; $cnt = 0; $OUT = '';
141 foreach (REQUEST_POST('sel') as $sel => $confirm) {
144 $result = SQL_QUERY_ESC("SELECT title, visible, locked FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE ".$AND." AND id=%s LIMIT 1",
145 array(bigintval($sel)), __FILE__, __LINE__);
146 if (SQL_NUMROWS($result) == 1) {
147 // Entry found so we load the stuff...
148 list($menu, $vis, $locked) = SQL_FETCHROW($result);
149 SQL_FREERESULT($result);
155 'visible' => ADD_SELECTION('yn', $vis , "visible", $sel),
156 'locked' => ADD_SELECTION('yn', $locked, "locked" , $sel),
160 $OUT .= LOAD_TEMPLATE("admin_menu_status_row", true, $content);
169 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
174 define('__MENU_ROWS', $OUT);
175 define('__CNT_VALUE', $cnt);
177 LOAD_TEMPLATE("admin_mmenu_status");
178 } elseif ((isFormSent()) && (!IS_DEMO())) {
180 foreach (REQUEST_POST('sel') as $sel => $menu) {
181 $AND = "(`what` = '' OR `what` IS NULL)";
182 $sel = bigintval($sel);
183 if (!empty($SUB)) $AND = "`action`='".$SUB."'";
184 switch (REQUEST_POST('ok'))
186 case 'edit': // Edit menu
187 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_member_menu` SET `title`='%s', `action`='%s', `what`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
188 array($menu, REQUEST_POST('sel_act', $sel), REQUEST_POST('sel_what', $sel), $sel), __FILE__, __LINE__);
191 case 'del': // Delete menu
192 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE ".$AND." AND id=%s LIMIT 1",
193 array($sel), __FILE__, __LINE__);
196 case 'status': // Change status of menus
197 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_member_menu` SET `visible`='%s', `locked`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
198 array(REQUEST_POST('visible', $sel), REQUEST_POST('locked', $sel), $sel), __FILE__, __LINE__);
205 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
207 if ((REQUEST_ISSET_GET(('act'))) && (REQUEST_ISSET_GET(('tid'))) && (REQUEST_ISSET_GET(('fid')))) {
209 $tid = ''; $fid = '';
212 if (REQUEST_ISSET_GET(('w'))) {
213 // Sub menus selected
214 $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
215 array(bigintval(REQUEST_GET('act')), bigintval(REQUEST_GET('tid'))), __FILE__, __LINE__);
216 list($tid) = SQL_FETCHROW($result);
217 SQL_FREERESULT($result);
218 $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE `action`='%s' AND `sort`='%s' LIMIT 1",
219 array(bigintval(REQUEST_GET('act')), bigintval(REQUEST_GET('fid'))), __FILE__, __LINE__);
220 list($fid) = SQL_FETCHROW($result);
221 SQL_FREERESULT($result);
223 // Main menu selected
224 $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
225 array(bigintval(REQUEST_GET('tid'))), __FILE__, __LINE__);
226 list($tid) = SQL_FETCHROW($result);
227 $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE (`what`='' OR `what` IS NULL) AND `sort`='%s' LIMIT 1",
228 array(bigintval(REQUEST_GET('fid'))), __FILE__, __LINE__);
229 list($fid) = SQL_FETCHROW($result);
232 if ((!empty($tid)) && (!empty($fid))) {
234 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_member_menu` SET `sort`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
235 array(bigintval(REQUEST_GET('tid')), bigintval($fid)), __FILE__, __LINE__);
236 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_member_menu` SET `sort`='%s' WHERE ".$AND." AND id=%s LIMIT 1",
237 array(bigintval(REQUEST_GET('fid')), bigintval($tid)), __FILE__, __LINE__);
243 $result = SQL_QUERY("SELECT id, action, what, title, sort FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE ".$AND." AND `what` != '' AND `what` IS NOT NULL ORDER BY `sort` ASC", __FILE__, __LINE__);
246 $result = SQL_QUERY("SELECT id, action, what, title, sort FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE (`what`='' OR `what` IS NULL) ORDER BY `sort` ASC", __FILE__, __LINE__);
249 $max = SQL_NUMROWS($result);
252 // @TODO Rewrite this constant
253 define('__SUB_VALUE', $SUB);
255 $SW = 2; $cnt = 0; $OUT = '';
256 while ($content = SQL_FETCHARRAY($result)) {
258 $content['navi'] = '';
260 if (($content['sort'] == 0) || (($content['sort'] == 1) && (!empty($SUB)))) {
261 // Is highest position
262 $content['navi'] = "<a href=\"{!URL!}/modules.php?module=admin&what=memedit&sub={!__SUB_VALUE!}&act=".$content['action']."&w=".$content['what']."&tid=".($content['sort']+1)."&fid=".$content['sort']."\">{--LOWER--}</a>";
263 } elseif ($cnt == $max) {
264 // Is lowest position
265 $content['navi'] = "<a href=\"{!URL!}/modules.php?module=admin&what=memedit&sub={!__SUB_VALUE!}&act=".$content['action']."&w=".$content['what']."&tid=".($content['sort']-1)."&fid=".$content['sort']."\">{--HIGHER--}</a>";
266 } elseif ($content['sort'] > 0) {
267 // Anything else between highest and lowest
268 $content['navi'] = "<a href=\"{!URL!}/modules.php?module=admin&what=memedit&sub={!__SUB_VALUE!}&act=".$content['action']."&w=".$content['what']."&tid=".($content['sort']-1)."&fid=".$content['sort']."\">{--HIGHER--}</a>/<a href=\"{!URL!}/modules.php?module=admin&what=memedit&sub={!__SUB_VALUE!}&act=".$content['action']."&w=".$content['what']."&tid=".($content['sort']+1)."&fid=".$content['sort']."\">{--LOWER--}</a>";
271 // Fix empty values for Firefox
272 if (empty($content['action'])) $content['action'] = " ";
273 if (empty($content['what'])) $content['what'] = " ";
274 if (empty($content['title'])) $content['title'] = " ";
277 $content['sw'] = $SW;
278 $content['mode'] = "mem";
280 // Load row template and switch color
281 $OUT .= LOAD_TEMPLATE("admin_menu_overview_row", true, $content);
286 SQL_FREERESULT($result);
288 // @TODO Rewrite this constant
289 define('__MENU_ROWS', $OUT);
291 // Load main template
292 LOAD_TEMPLATE("admin_mmenu_overview");
294 // Menu entries are missing... (???)
295 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_NO_MENUS_FOUND'));