]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-memedit.php
e8e635dbbf15f091d4553240b3b96cdc79a30be9
[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 ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN()))
36 {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
39 }
40 // Add description as navigation point
41 ADD_DESCR("admin", basename(__FILE__));
42
43 // Do we edit/delete/change main menus or sub menus?
44 $AND = "what = ''"; $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 OPEN_TABLE("100%", "admin_content admin_content_align", "");
57 // List all menu points and make them editable
58 OUTPUT_HTML("<br /><br /></FONT>
59 <DIV align=\"center\">");
60 if ((isset($_POST['edit'])) && ($chk > 0) && (!IS_DEMO()))
61 {
62         // Edit menu entries
63         define('__SUB_VALUE', $SUB);
64         define('__CHK_VALUE', $chk);
65         $SW = 2; $cnt = 0; $OUT = "";
66         foreach ($_POST['sel'] as $sel=>$confirm)
67         {
68                 if ($confirm == 1)
69                 {
70                         $cnt++;
71                         $result = SQL_QUERY_ESC("SELECT title, action, what, descr FROM "._MYSQL_PREFIX."_member_menu WHERE ".$AND." AND id=%d LIMIT 1",
72                          array(bigintval($sel)), __FILE__, __LINE__);
73                         if (SQL_NUMROWS($result) == 1)
74                         {
75                                 // Entry found so we load the stuff...
76                                 list($menu, $act, $wht, $descr) = SQL_FETCHROW($result);
77                                 SQL_FREERESULT($result);
78                                 $content = array(
79                                         'cnt'    => $cnt,
80                                         'sel'    => $sel,
81                                         'menu'   => $menu,
82                                         'sw'     => $SW,
83                                         'act' => ADMIN_MAKE_MENU_SELECTION("member", "act", "sel_act[".$sel."]", $act),
84                                         'what'   => ADMIN_MAKE_MENU_SELECTION("member", "what", "sel_what[".$sel."]", $wht),
85                                 );
86                                 // Load template
87                                 $OUT .= LOAD_TEMPLATE("admin_mmenu_edit_row", true, $content);
88                         }
89                          else
90                         {
91                                 // Entry not found?
92                                 $content = array(
93                                         'sw'  => $SW,
94                                         'sel' => $sel
95                                 );
96                                 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
97                         }
98                         $SW = 3 - $SW;
99                 }
100         }
101         define('__MENU_ROWS', $OUT);
102         define('__CNT_VALUE', $cnt);
103
104         // Load template
105         LOAD_TEMPLATE("admin_mmenu_edit");
106 }
107  elseif ((isset($_POST['del'])) && ($chk > 0) && (!IS_DEMO()))
108 {
109         // Del menu entries with or without confirmation
110         define('__SUB_VALUE', $SUB);
111         define('__CHK_VALUE', $chk);
112         $SW = 2; $cnt = 0; $OUT = "";
113         foreach ($_POST['sel'] as $sel=>$confirm)
114         {
115                 if ($confirm == 1)
116                 {
117                         $cnt++;
118                         $result = SQL_QUERY_ESC("SELECT title FROM "._MYSQL_PREFIX."_member_menu WHERE ".$AND." AND id=%d LIMIT 1",
119                          array(bigintval($sel)), __FILE__, __LINE__);
120                         if (SQL_NUMROWS($result) == 1)
121                         {
122                                 // Entry found so we load the stuff...
123                                 list($title) = SQL_FETCHROW($result);
124                                 SQL_FREERESULT($result);
125                                 $content = array(
126                                         'cnt'   => $cnt,
127                                         'sel'   => $sel,
128                                         'title' => $title
129                                 );
130                                 $OUT .= LOAD_TEMPLATE("admin_mmenu_delete_row", true, $content);
131                         }
132                          else
133                         {
134                                 // Entry not found?
135                                 $content = array(
136                                         'sw'  => $SW,
137                                         'sel' => $sel
138                                 );
139                                 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
140                         }
141                 }
142         }
143         define('__MENU_ROWS', $OUT);
144         define('__CNT_VALUE', $cnt);
145
146         // Load template
147         LOAD_TEMPLATE("admin_mmenu_delete");
148 }
149  elseif ((isset($_POST['status'])) && ($chk > 0) && (!IS_DEMO()))
150 {
151         // Change status (visible / locked)
152         define('__SUB_VALUE', $SUB);
153         define('__CHK_VALUE', $chk);
154         $SW = 2; $cnt = 0; $OUT = "";
155         foreach ($_POST['sel'] as $sel=>$confirm)
156         {
157                 if ($confirm == 1)
158                 {
159                         $cnt++;
160                         $result = SQL_QUERY_ESC("SELECT title, visible, locked FROM "._MYSQL_PREFIX."_member_menu WHERE ".$AND." AND id=%d LIMIT 1",
161                          array(bigintval($sel)), __FILE__, __LINE__);
162                         if (SQL_NUMROWS($result) == 1)
163                         {
164                                 // Entry found so we load the stuff...
165                                 list($menu, $vis, $locked) = SQL_FETCHROW($result);
166                                 SQL_FREERESULT($result);
167                                 $content = array(
168                                         'cnt'     => $cnt,
169                                         'menu'    => $menu,
170                                         'sel'     => $sel,
171                                         'sw'      => $SW,
172                                         'visible' => ADD_SELECTION("yn", $vis   , "visible", $sel),
173                                         'locked'  => ADD_SELECTION("yn", $locked, "locked" , $sel),
174                                 );
175
176                                 // Load template
177                                 $OUT .= LOAD_TEMPLATE("admin_menu_status_row", true, $content);
178                         }
179                          else
180                         {
181                                 // Entry not found?
182                                 $content = array(
183                                         'sw'  => $SW,
184                                         'sel' => $sel
185                                 );
186                                 $OUT .= LOAD_TEMPLATE("admin_menu_404_row", true, $content);
187                         }
188                         $SW = 3 - $SW;
189                 }
190         }
191         define('__MENU_ROWS', $OUT);
192         define('__CNT_VALUE', $cnt);
193         //
194         LOAD_TEMPLATE("admin_mmenu_status");
195 }
196  elseif ((isset($_POST['ok'])) && (!IS_DEMO()))
197 {
198         // An act is done...
199         foreach ($_POST['sel'] as $sel=>$menu)
200         {
201                 $AND = "what = ''";
202                 $sel = bigintval($sel);
203                 if (!empty($SUB)) $AND = "action='".$SUB."'";
204                 switch ($_POST['ok'])
205                 {
206                 case "edit": // Edit menu
207                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_member_menu SET title='%s', action='%s', what='%s', descr='%s' WHERE ".$AND." AND id=%d LIMIT 1",
208                          array($menu, $_POST['sel_act'][$sel], $_POST['sel_what'][$sel], $_POST['sel_descr'][$sel], $sel), __FILE__, __LINE__);
209                         break;
210
211                 case "del": // Delete menu
212                         $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_member_menu WHERE ".$AND." AND id=%d LIMIT 1",
213                          array($sel), __FILE__, __LINE__);
214                         break;
215
216                 case "status": // Change status of menus
217                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_member_menu SET visible='%s', locked='%s' WHERE ".$AND." AND id=%d LIMIT 1",
218                          array($_POST['visible'][$sel], $_POST['locked'][$sel], $sel), __FILE__, __LINE__);
219                         break;
220                 }
221                 break;
222         }
223
224         // Load template
225         LOAD_TEMPLATE("admin_data_saved");
226 }
227  else
228 {
229         if ((!empty($_GET['act'])) && (!empty($_GET['tid'])) && (!empty($_GET['fid'])))
230         {
231                 // Get IDs
232                 if (!empty($_GET['w']))
233                 {
234                         // Sub menus selected
235                         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_member_menu WHERE action='%s' AND sort='%s' LIMIT 1",
236                          array(bigintval($_GET['act']), bigintval($_GET['tid'])), __FILE__, __LINE__);
237                         list($tid) = SQL_FETCHROW($result);
238                         SQL_FREERESULT($result);
239                         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_member_menu WHERE action='%s' AND sort='%s' LIMIT 1",
240                          array(bigintval($_GET['act']), bigintval($_GET['fid'])), __FILE__, __LINE__);
241                         list($fid) = SQL_FETCHROW($result);
242                         SQL_FREERESULT($result);
243                 }
244                  else
245                 {
246                         // Main menu selected
247                         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_member_menu WHERE what='' AND sort='%s' LIMIT 1",
248                          array(bigintval($_GET['tid'])), __FILE__, __LINE__);
249                         list($tid) = SQL_FETCHROW($result);
250                         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_member_menu WHERE what='' AND sort='%s' LIMIT 1",
251                          array(bigintval($_GET['fid'])), __FILE__, __LINE__);
252                         list($fid) = SQL_FETCHROW($result);
253                 }
254
255                 if ((!empty($tid)) && (!empty($fid)))
256                 {
257                         // Sort menu
258                         $result_sort = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_member_menu SET sort='%s' WHERE ".$AND." AND id=%d LIMIT 1",
259                          array(bigintval($_GET['tid']), bigintval($fid)), __FILE__, __LINE__);
260                         $result_sort = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_member_menu SET sort='%s' WHERE ".$AND." AND id=%d LIMIT 1",
261                          array(bigintval($_GET['fid']), bigintval($tid)), __FILE__, __LINE__);
262                 }
263         }
264
265         if (!empty($SUB))
266         {
267                 // Edit sub menus
268                 $result = SQL_QUERY("SELECT id, action, what, title, sort FROM "._MYSQL_PREFIX."_member_menu WHERE ".$AND." AND what != '' ORDER BY sort ASC", __FILE__, __LINE__);
269         }
270          else
271         {
272                 // Edit main menus
273                 $result = SQL_QUERY("SELECT id, action, what, title, sort FROM "._MYSQL_PREFIX."_member_menu WHERE what='' ORDER BY sort ASC", __FILE__, __LINE__);
274         }
275         $max = SQL_NUMROWS($result);
276         if ($max > 0)
277         {
278                 $SUB = "";
279                 if (!empty($SUB)) $SUB = $SUB;
280                 define('__SUB_VALUE', $SUB);
281
282                 $SW = 2; $cnt = 0; $OUT = "";
283                 while (list($id, $act, $wht, $title, $sort) = SQL_FETCHROW($result))
284                 {
285                         $cnt++;
286                         if (($sort == 0) || (($sort == 1) && (!empty($SUB))))
287                         {
288                                 // Is highest position
289                                 $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>";
290                         }
291                          elseif ($cnt == $max)
292                         {
293                                 // Is lowest position
294                                 $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>";
295                         }
296                          elseif ($sort > 0)
297                         {
298                                 // Anything else between highest and lowest
299                                 $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>";
300                         }
301                         if (empty($act))   $act   = "&nbsp;";
302                         if (empty($wht))   $wht   = "&nbsp;";
303                         if (empty($title)) $title = "&nbsp;";
304                         $content = array(
305                                 'sw'     => $SW,
306                                 'id'     => $id,
307                                 'action' => $act,
308                                 'what'   => $wht,
309                                 'title'  => $title,
310                                 'navi'   => $NAVI,
311                                 'mode'   => "mem",
312                         );
313                         $OUT .= LOAD_TEMPLATE("admin_menu_overview_row", true, $content);
314                         $SW = 3 - $SW;
315                 }
316
317                 // Free memory
318                 SQL_FREERESULT($result);
319                 define('__MENU_ROWS', $OUT);
320                 LOAD_TEMPLATE("admin_mmenu_overview");
321         }
322          else
323         {
324                 // Menu entries are missing... (???)
325                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NO_MENUS_FOUND);
326         }
327 }
328 OUTPUT_HTML("</DIV>");
329 CLOSE_TABLE();
330 //
331 ?>