]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-memedit.php
8e9fb5466c1e703973efde30988520823beaac84
[mailer.git] / inc / modules / admin / what-memedit.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 09/28/2003 *
4  * ===============                              Last change: 05/13/2004 *
5  *                                                                      *
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  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
42
43 // Do we edit/delete/change main menus or sub menus?
44 $AND = "(what = '' OR what IS NULL)"; $SUB = "";
45
46 if (!empty($_GET['sub']))
47 {
48         $AND = sprintf("action='%s'", SQL_ESCAPE($_GET['sub']));
49         $SUB = SQL_ESCAPE($_GET['sub']);
50 }
51
52 // Get count of (maybe) selected menu points
53 $chk = 0;
54 if (!empty($_POST['sel'])) $chk = SELECTION_COUNT($_POST['sel']);
55
56 // List all menu points and make them editable
57 if ((isset($_POST['edit'])) && ($chk > 0) && (!IS_DEMO()))
58 {
59         // Edit menu entries
60         define('__SUB_VALUE', $SUB);
61         define('__CHK_VALUE', $chk);
62         $SW = 2; $cnt = 0; $OUT = "";
63         foreach ($_POST['sel'] as $sel => $confirm)
64         {
65                 if ($confirm == 1)
66                 {
67                         $cnt++;
68                         $result = SQL_QUERY_ESC("SELECT title, action, what FROM "._MYSQL_PREFIX."_member_menu WHERE ".$AND." AND id=%s LIMIT 1",
69                          array(bigintval($sel)), __FILE__, __LINE__);
70                         if (SQL_NUMROWS($result) == 1)
71                         {
72                                 // Entry found so we load the stuff...
73                                 list($menu, $act, $wht, $descr) = SQL_FETCHROW($result);
74                                 SQL_FREERESULT($result);
75                                 $content = array(
76                                         'cnt'    => $cnt,
77                                         'sel'    => $sel,
78                                         'menu'   => $menu,
79                                         'sw'     => $SW,
80                                         'act' => ADMIN_MAKE_MENU_SELECTION("member", "act", "sel_act[".$sel."]", $act),
81                                         'what'   => ADMIN_MAKE_MENU_SELECTION("member", "what", "sel_what[".$sel."]", $wht),
82                                 );
83                                 // Load template
84                                 $OUT .= LOAD_TEMPLATE("admin_mmenu_edit_row", true, $content);
85                         }
86                          else
87                         {
88                                 // Entry not found?
89                                 $content = array(
90                                         'sw'  => $SW,
91                                         'sel' => $sel
92                                 );
93                                 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
94                         }
95                         $SW = 3 - $SW;
96                 }
97         }
98         define('__MENU_ROWS', $OUT);
99         define('__CNT_VALUE', $cnt);
100
101         // Load template
102         LOAD_TEMPLATE("admin_mmenu_edit");
103 }
104  elseif ((isset($_POST['del'])) && ($chk > 0) && (!IS_DEMO()))
105 {
106         // Del menu entries with or without confirmation
107         define('__SUB_VALUE', $SUB);
108         define('__CHK_VALUE', $chk);
109         $SW = 2; $cnt = 0; $OUT = "";
110         foreach ($_POST['sel'] as $sel => $confirm)
111         {
112                 if ($confirm == 1)
113                 {
114                         $cnt++;
115                         $result = SQL_QUERY_ESC("SELECT title FROM "._MYSQL_PREFIX."_member_menu WHERE ".$AND." AND id=%s LIMIT 1",
116                          array(bigintval($sel)), __FILE__, __LINE__);
117                         if (SQL_NUMROWS($result) == 1)
118                         {
119                                 // Entry found so we load the stuff...
120                                 list($title) = SQL_FETCHROW($result);
121                                 SQL_FREERESULT($result);
122                                 $content = array(
123                                         'cnt'   => $cnt,
124                                         'sel'   => $sel,
125                                         'title' => $title
126                                 );
127                                 $OUT .= LOAD_TEMPLATE("admin_mmenu_delete_row", true, $content);
128                         }
129                          else
130                         {
131                                 // Entry not found?
132                                 $content = array(
133                                         'sw'  => $SW,
134                                         'sel' => $sel
135                                 );
136                                 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
137                         }
138                 }
139         }
140         define('__MENU_ROWS', $OUT);
141         define('__CNT_VALUE', $cnt);
142
143         // Load template
144         LOAD_TEMPLATE("admin_mmenu_delete");
145 }
146  elseif ((isset($_POST['status'])) && ($chk > 0) && (!IS_DEMO()))
147 {
148         // Change status (visible / locked)
149         define('__SUB_VALUE', $SUB);
150         define('__CHK_VALUE', $chk);
151         $SW = 2; $cnt = 0; $OUT = "";
152         foreach ($_POST['sel'] as $sel => $confirm)
153         {
154                 if ($confirm == 1)
155                 {
156                         $cnt++;
157                         $result = SQL_QUERY_ESC("SELECT title, visible, locked FROM "._MYSQL_PREFIX."_member_menu WHERE ".$AND." AND id=%s LIMIT 1",
158                          array(bigintval($sel)), __FILE__, __LINE__);
159                         if (SQL_NUMROWS($result) == 1)
160                         {
161                                 // Entry found so we load the stuff...
162                                 list($menu, $vis, $locked) = SQL_FETCHROW($result);
163                                 SQL_FREERESULT($result);
164                                 $content = array(
165                                         'cnt'     => $cnt,
166                                         'menu'    => $menu,
167                                         'sel'     => $sel,
168                                         'sw'      => $SW,
169                                         'visible' => ADD_SELECTION("yn", $vis   , "visible", $sel),
170                                         'locked'  => ADD_SELECTION("yn", $locked, "locked" , $sel),
171                                 );
172
173                                 // Load template
174                                 $OUT .= LOAD_TEMPLATE("admin_menu_status_row", true, $content);
175                         }
176                          else
177                         {
178                                 // Entry not found?
179                                 $content = array(
180                                         'sw'  => $SW,
181                                         'sel' => $sel
182                                 );
183                                 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
184                         }
185                         $SW = 3 - $SW;
186                 }
187         }
188         define('__MENU_ROWS', $OUT);
189         define('__CNT_VALUE', $cnt);
190         //
191         LOAD_TEMPLATE("admin_mmenu_status");
192 }
193  elseif ((isset($_POST['ok'])) && (!IS_DEMO()))
194 {
195         // An act is done...
196         foreach ($_POST['sel'] as $sel => $menu)
197         {
198                 $AND = "(what = '' OR what IS NULL)";
199                 $sel = bigintval($sel);
200                 if (!empty($SUB)) $AND = "action='".$SUB."'";
201                 switch ($_POST['ok'])
202                 {
203                 case "edit": // Edit menu
204                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_member_menu SET title='%s', action='%s', what='%s' WHERE ".$AND." AND id=%s LIMIT 1",
205                          array($menu, $_POST['sel_act'][$sel], $_POST['sel_what'][$sel], $sel), __FILE__, __LINE__);
206                         break;
207
208                 case "del": // Delete menu
209                         $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_member_menu WHERE ".$AND." AND id=%s LIMIT 1",
210                          array($sel), __FILE__, __LINE__);
211                         break;
212
213                 case "status": // Change status of menus
214                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_member_menu SET visible='%s', locked='%s' WHERE ".$AND." AND id=%s LIMIT 1",
215                          array($_POST['visible'][$sel], $_POST['locked'][$sel], $sel), __FILE__, __LINE__);
216                         break;
217                 }
218                 break;
219         }
220
221         // Load template
222         LOAD_TEMPLATE("admin_data_saved");
223 }
224  else
225 {
226         if ((!empty($_GET['act'])) && (!empty($_GET['tid'])) && (!empty($_GET['fid'])))
227         {
228                 // Get IDs
229                 if (!empty($_GET['w']))
230                 {
231                         // Sub menus selected
232                         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_member_menu WHERE action='%s' AND sort='%s' LIMIT 1",
233                          array(bigintval($_GET['act']), bigintval($_GET['tid'])), __FILE__, __LINE__);
234                         list($tid) = SQL_FETCHROW($result);
235                         SQL_FREERESULT($result);
236                         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_member_menu WHERE action='%s' AND sort='%s' LIMIT 1",
237                          array(bigintval($_GET['act']), bigintval($_GET['fid'])), __FILE__, __LINE__);
238                         list($fid) = SQL_FETCHROW($result);
239                         SQL_FREERESULT($result);
240                 }
241                  else
242                 {
243                         // Main menu selected
244                         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_member_menu WHERE (what='' OR what IS NULL) AND sort='%s' LIMIT 1",
245                          array(bigintval($_GET['tid'])), __FILE__, __LINE__);
246                         list($tid) = SQL_FETCHROW($result);
247                         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_member_menu WHERE (what='' OR what IS NULL) AND sort='%s' LIMIT 1",
248                          array(bigintval($_GET['fid'])), __FILE__, __LINE__);
249                         list($fid) = SQL_FETCHROW($result);
250                 }
251
252                 if ((!empty($tid)) && (!empty($fid)))
253                 {
254                         // Sort menu
255                         $result_sort = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_member_menu SET sort='%s' WHERE ".$AND." AND id=%s LIMIT 1",
256                          array(bigintval($_GET['tid']), bigintval($fid)), __FILE__, __LINE__);
257                         $result_sort = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_member_menu SET sort='%s' WHERE ".$AND." AND id=%s LIMIT 1",
258                          array(bigintval($_GET['fid']), bigintval($tid)), __FILE__, __LINE__);
259                 }
260         }
261
262         if (!empty($SUB))
263         {
264                 // Edit sub menus
265                 $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__);
266         }
267          else
268         {
269                 // Edit main menus
270                 $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__);
271         }
272         $max = SQL_NUMROWS($result);
273         if ($max > 0)
274         {
275                 $SUB = "";
276                 if (!empty($SUB)) $SUB = $SUB;
277                 define('__SUB_VALUE', $SUB);
278
279                 $SW = 2; $cnt = 0; $OUT = "";
280                 while (list($id, $act, $wht, $title, $sort) = SQL_FETCHROW($result))
281                 {
282                         $cnt++;
283                         if (($sort == 0) || (($sort == 1) && (!empty($SUB))))
284                         {
285                                 // Is highest position
286                                 $NAVI = "<A href=\"".URL."/modules.php?module=admin&amp;what=memedit&amp;sub=".$SUB."&amp;act=".$act."&amp;w=".$wht."&amp;tid=".($sort+1)."&amp;fid=".$sort."\">".LOWER."</A>";
287                         }
288                          elseif ($cnt == $max)
289                         {
290                                 // Is lowest position
291                                 $NAVI = "<A href=\"".URL."/modules.php?module=admin&amp;what=memedit&amp;sub=".$SUB."&amp;act=".$act."&amp;w=".$wht."&amp;tid=".($sort-1)."&amp;fid=".$sort."\">".HIGHER."</A>";
292                         }
293                          elseif ($sort > 0)
294                         {
295                                 // Anything else between highest and lowest
296                                 $NAVI = "<A href=\"".URL."/modules.php?module=admin&amp;what=memedit&amp;sub=".$SUB."&amp;act=".$act."&amp;w=".$wht."&amp;tid=".($sort-1)."&amp;fid=".$sort."\">".HIGHER."</A>/<A href=\"".URL."/modules.php?module=admin&amp;what=memedit&amp;sub=".$SUB."&amp;act=".$act."&amp;w=".$wht."&amp;tid=".($sort+1)."&amp;fid=".$sort."\">".LOWER."</A>";
297                         }
298                         if (empty($act))   $act   = "&nbsp;";
299                         if (empty($wht))   $wht   = "&nbsp;";
300                         if (empty($title)) $title = "&nbsp;";
301                         $content = array(
302                                 'sw'     => $SW,
303                                 'id'     => $id,
304                                 'action' => $act,
305                                 'what'   => $wht,
306                                 'title'  => $title,
307                                 'navi'   => $NAVI,
308                                 'mode'   => "mem",
309                         );
310                         $OUT .= LOAD_TEMPLATE("admin_menu_overview_row", true, $content);
311                         $SW = 3 - $SW;
312                 }
313
314                 // Free memory
315                 SQL_FREERESULT($result);
316                 define('__MENU_ROWS', $OUT);
317                 LOAD_TEMPLATE("admin_mmenu_overview");
318         }
319          else
320         {
321                 // Menu entries are missing... (???)
322                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NO_MENUS_FOUND);
323         }
324 }
325
326 //
327 ?>