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