New functions introduced, several rewrites:
[mailer.git] / inc / modules / admin / what-config_cats.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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 } // END - if
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(
59                                 postRequestElement('catname'),
60                                 postRequestElement('visible'),
61                                 bigintval(postRequestElement('parent') + 1)
62                         ), __FILE__, __LINE__);
63                 $content = getMessage('CATEGORY_ADDED');
64         } else {
65                 // Category does already exists
66                 $content = '<span class="admin_failed">{--CATEGORY_ALREADY_EXISTS--}</span>';
67         }
68
69         // Free memory
70         SQL_FREERESULT($result);
71
72         // Display message
73         loadTemplate('admin_settings_saved', false, $content);
74 } elseif ((isFormSent()) && (isPostRequestElementSet('id')) && (is_array(postRequestElement('id')))) {
75         // Change or delete categories...
76         $TEXT = '';
77         foreach (postRequestElement('id') as $id => $cat) {
78                 // Secure id
79                 $id = bigintval($id);
80
81                 // Is the entry set?
82                 if (!empty($cat)) {
83                         switch (getRequestElement('do')) {
84                                 case 'edit': // Change categories
85                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_cats` SET `cat`='%s', `visible`='%s', `sort`=%s WHERE `id`=%s LIMIT 1",
86                                                 array(
87                                                         $cat,
88                                                         postRequestElement('vis', $id),
89                                                         postRequestElement('sort', $id),
90                                                         $id
91                                                 ), __FILE__, __LINE__);
92                                         $TEXT = getMessage('CATEGORIES_SAVED');
93                                         break;
94
95                                 case 'del': // Delete categories
96                                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
97                                                 array($id), __FILE__, __LINE__);
98                                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `cat_id`=%s",
99                                                 array($id), __FILE__, __LINE__);
100                                         $TEXT = getMessage('CATEGORIES_DELETED');
101                                         break;
102                         } // END - switch
103                 } else {
104                         // Entry not saved
105                         $TEXT .= getMaskedMessage('CATEGORY_NOT_SAVED', $id);
106                 }
107         } // END - foreach
108
109         if (isset($TEXT)) {
110                 // Display message
111                 loadTemplate('admin_settings_saved', false, $TEXT);
112         } // END - if
113 } elseif ((isPostRequestElementSet('del')) && (countPostSelection() > 0)) {
114         // Delete categories
115         $OUT = ''; $SW = 2;
116         foreach (postRequestElement('sel') as $id => $value) {
117                 // Load data of category
118                 $result = SQL_QUERY_ESC("SELECT `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
119                         array(bigintval($id)), __FILE__, __LINE__);
120                 list($cat) = SQL_FETCHROW($result);
121
122                 // Free result
123                 SQL_FREERESULT($result);
124
125                 // Prepare data for the row template
126                 $content = array(
127                         'sw'  => $SW,
128                         'id'  => $id,
129                         'cat' => $cat,
130                 );
131
132                 // Load row template and switch colors
133                 $OUT .= loadTemplate('admin_del_cats_row', true, $content);
134                 $SW = 3 - $SW;
135         } // END - foreach
136
137         // Load main template
138         loadTemplate('admin_del_cats', false, $OUT);
139 } elseif ((isPostRequestElementSet('edit')) && (countPostSelection() > 0)) {
140         // Edit categories
141         $OUT = ''; $SW = 2;
142         foreach (postRequestElement('sel') as $id => $value) {
143                 // Load data from the category
144                 $result = SQL_QUERY_ESC("SELECT cat, visible, sort FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
145                 array(bigintval($id)), __FILE__, __LINE__);
146                 list($cat, $vis, $sort) = SQL_FETCHROW($result);
147                 SQL_FREERESULT($result);
148
149                 // Prepare data for the row template
150                 $content = array(
151                         'sw'   => $SW,
152                         'id'   => $id,
153                         'cat'  => $cat,
154                         'vis'  => addSelectionBox('yn', $vis, 'vis', $id),
155                         'sort' => $sort,
156                 );
157
158                 // Load row template and switch colors
159                 $OUT .= loadTemplate('admin_edit_cats_row', true, $content);
160                 $SW = 3 - $SW;
161         } // END - foreach
162
163         // Load main template
164         loadTemplate('admin_edit_cats', false, $OUT);
165 } else {
166         // Init variable here
167         $CATS = '';
168
169         // Load all categories
170         $result = SQL_QUERY("SELECT `id`, `cat`, `visible`, `sort` FROM `{?_MYSQL_PREFIX?}_cats` ORDER BY `sort` ASC", __FILE__, __LINE__);
171         if (SQL_NUMROWS($result) > 0) {
172                 // Init variables
173                 $OUT = ''; $SW = 2;
174
175                 // List already existing categories for editing
176                 while ($content = SQL_FETCHARRAY($result)) {
177                         // Prepare data for the row template
178                         $content['sw']  = $SW;
179                         $content['vis'] = translateYesNo($content['visible']);
180
181                         // Put cat descriptions into variable for the selection box
182                         $cat = $content['cat'];
183                         if (strlen($cat) > 40) $cat = substr($cat, 0, 37) . '...';
184                         $CATS .= '<option value="' . $content['sort'] . '">' . $cat . '</option>';
185
186                         // Load row template and switch color
187                         $OUT .= loadTemplate('admin_config_cats_row', true, $content);
188                         $SW = 3 - $SW;
189                 } // END - while
190
191                 // Free memory
192                 SQL_FREERESULT($result);
193
194                 // Load main template
195                 loadTemplate('admin_config_cats', false, $OUT);
196         } // END - if
197
198         // Remember in array
199         $content['cats'] = $CATS;
200
201         // Form to add a new category
202         loadTemplate('admin_add_cat', false, $content);
203 }
204
205 // [EOF]
206 ?>