Huge rewrite of default parameters, ext-network continued:
[mailer.git] / inc / modules / admin / what-config_cats.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/10/2003 *
4  * ===============                              Last change: 07/04/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-config_cats.php                             *
8  * -------------------------------------------------------------------- *
9  * Short description : Add new categories and edit / delete existing    *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Neue Kategorien hinzufuegen und bestehende       *
12  *                     editieren / loeschen                             *
13  * -------------------------------------------------------------------- *
14  * $Revision::                                                        $ *
15  * $Date::                                                            $ *
16  * $Tag:: 0.2.1-FINAL                                                 $ *
17  * $Author::                                                          $ *
18  * Needs to be in all Files and every File needs "svn propset           *
19  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
20  * -------------------------------------------------------------------- *
21  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 }
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
48 // Init variable to avoid a notice
49 $CATS = '';
50
51 if (isPostRequestElementSet('add')) {
52         // Add a new category
53         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_cats` WHERE cat='%s' LIMIT 1",
54         array(postRequestElement('catname')), __FILE__, __LINE__);
55         if (SQL_NUMROWS($result) == '0') {
56                 // Category does not exists, we simply add it...
57                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_cats` (cat, visible, sort) VALUES ('%s','%s','%s')",
58                 array(postRequestElement('catname'), postRequestElement('visible'), bigintval(postRequestElement('parent') + 1)), __FILE__, __LINE__);
59                 $content = getMessage('CATEGORY_ADDED');
60         } else {
61                 // Category does already exists
62                 $content = "<span class=\"admin_failed\">{--CATEGORY_ALREADY_EXISTS--}</span>";
63         }
64
65         // Free memory
66         SQL_FREERESULT($result);
67
68         // Display message
69         loadTemplate('admin_settings_saved', false, $content);
70 } elseif ((isFormSent()) && (isPostRequestElementSet('id')) && (is_array(postRequestElement('id')))) {
71         // Change or delete categories...
72         $TEXT = '';
73         foreach (postRequestElement('id') as $id => $cat) {
74                 // Secure id
75                 $id = bigintval($id);
76
77                 // Is the entry set?
78                 if (!empty($cat)) {
79                         switch (getRequestElement('do'))
80                         {
81                                 case 'edit': // Change categories
82                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_cats` SET cat='%s', `visible`='%s', sort=%s WHERE `id`=%s LIMIT 1",
83                                         array(
84                                         $cat,
85                                         postRequestElement('vis', $id),
86                                         postRequestElement('sort', $id),
87                                         $id
88                                         ), __FILE__, __LINE__);
89                                         $TEXT = getMessage('CATEGORIES_SAVED');
90                                         break;
91
92                                 case 'del': // Delete categories
93                                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
94                                                 array($id), __FILE__, __LINE__);
95                                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE cat_id=%s",
96                                                 array($id), __FILE__, __LINE__);
97                                         $TEXT = getMessage('CATEGORIES_DELETED');
98                                         break;
99                         }
100                 } else {
101                         // Entry not saved
102                         $TEXT .= sprintf(getMessage('CATEGORY_NOT_SAVED'), $id);
103                 }
104         }
105
106         if (isset($TEXT)) {
107                 // Display message
108                 loadTemplate('admin_settings_saved', false, $TEXT);
109         }
110 } elseif ((isPostRequestElementSet('del')) && (countPostSelection() > 0)) {
111         // Delete categories
112         $OUT = ''; $SW = 2;
113         foreach (postRequestElement('sel') as $id => $value) {
114                 // Load data of category
115                 $result = SQL_QUERY_ESC("SELECT `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
116                         array(bigintval($id)), __FILE__, __LINE__);
117                 list($cat) = SQL_FETCHROW($result);
118
119                 // Free result
120                 SQL_FREERESULT($result);
121
122                 // Prepare data for the row template
123                 $content = array(
124                         'sw'  => $SW,
125                         'id'  => $id,
126                         'cat' => $cat,
127                 );
128
129                 // Load row template and switch colors
130                 $OUT .= loadTemplate('admin_del_cats_row', true, $content);
131                 $SW = 3 - $SW;
132         }
133
134         // Load main template
135         loadTemplate('admin_del_cats', false, $OUT);
136 } elseif ((isPostRequestElementSet('edit')) && (countPostSelection() > 0)) {
137         // Edit categories
138         $OUT = ''; $SW = 2;
139         foreach (postRequestElement('sel') as $id => $value)
140         {
141                 // Load data from the category
142                 $result = SQL_QUERY_ESC("SELECT cat, visible, sort FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
143                 array(bigintval($id)), __FILE__, __LINE__);
144                 list($cat, $vis, $sort) = SQL_FETCHROW($result);
145                 SQL_FREERESULT($result);
146
147                 // Prepare data for the row template
148                 $content = array(
149                         'sw'   => $SW,
150                         'id'   => $id,
151                         'cat'  => $cat,
152                         'vis'  => addSelectionBox('yn', $vis, 'vis', $id),
153                         'sort' => $sort,
154                 );
155
156                 // Load row template and switch colors
157                 $OUT .= loadTemplate('admin_edit_cats_row', true, $content);
158                 $SW = 3 - $SW;
159         }
160
161         // Load main template
162         loadTemplate('admin_edit_cats', false, $OUT);
163 } else {
164         // Init variable here
165         $CATS = '';
166
167         // Load all categories
168         $result = SQL_QUERY("SELECT `id`, `cat`, `visible`, `sort` FROM `{?_MYSQL_PREFIX?}_cats` ORDER BY `sort` ASC", __FILE__, __LINE__);
169         if (SQL_NUMROWS($result) > 0) {
170                 // Init variables
171                 $OUT = ''; $SW = 2;
172
173                 // List already existing categories for editing
174                 while ($content = SQL_FETCHARRAY($result)) {
175                         // Prepare data for the row template
176                         $content['sw']  = $SW;
177                         $content['vis'] = translateYesNo($content['visible']);
178
179                         // Put cat descriptions into variable for the selection box
180                         if (strlen($content['cat']) > 20) $content['cat'] = substr($content['cat'], 0, 17)."...";
181                         $CATS .= "      <option value=\"".$content['sort']."\">".$content['cat']."</option>\n";
182
183                         // Load row template and switch color
184                         $OUT .= loadTemplate('admin_config_cats_row', true, $content);
185                         $SW = 3 - $SW;
186                 } // END - while
187
188                 // Free memory
189                 SQL_FREERESULT($result);
190
191                 // Load main template
192                 loadTemplate('admin_config_cats', false, $OUT);
193         } // END - if
194
195         // Remember in array
196         $content['cats'] = $CATS;
197
198         // Form to add a new category
199         loadTemplate('admin_add_cat', false, $content);
200 }
201
202 // [EOF]
203 ?>