More XHTML-fied and extended header added to templates
[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:: 856                                                    $ *
15  * $Date:: 2009-03-06 20:24:32 +0100 (Fr, 06. March 2009)             $ *
16  * $Tag:: 0.2.1-FINAL                                                 $ *
17  * $Author:: stelzi                                                   $ *
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 - 2008 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')) || (!IS_ADMIN())) {
42         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
43         require($INC);
44 }
45
46 // Add description as navigation point
47 ADD_DESCR("admin", __FILE__);
48
49 // Init variable to avoid a notice
50 $CATS = "";
51
52 if (REQUEST_ISSET_POST(('add'))) {
53         // Add a new category
54         $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_cats` WHERE cat='%s' LIMIT 1",
55                 array(REQUEST_POST('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(REQUEST_POST('catname'), REQUEST_POST('visible'), bigintval(REQUEST_POST('parent') + 1)), __FILE__, __LINE__);
60                 $content = CATEGORY_ADDED;
61         } else {
62                 // Category does already exists
63                 $content = "<span class=\"admin_failed\">".CATEGORY_ALREADY_EXISTS."</span>";
64         }
65
66         // Free memory
67         SQL_FREERESULT($result);
68
69         // Display message
70         LOAD_TEMPLATE("admin_settings_saved", false, $content);
71 } elseif ((IS_FORM_SENT()) && (REQUEST_ISSET_POST(('id'))) && (is_array(REQUEST_POST('id')))) {
72         // Change or delete categories...
73         $TEXT = "";
74         foreach (REQUEST_POST('id') as $id => $cat) {
75                 // Secure ID
76                 $id = bigintval($id);
77
78                 // Is the entry set?
79                 if (!empty($cat)) {
80                         switch (REQUEST_GET('do'))
81                         {
82                         case "edit": // Change categories
83                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_cats` SET cat='%s', `visible`='%s', sort=%s WHERE id=%s LIMIT 1",
84                                         array(
85                                                 $cat,
86                                                 REQUEST_POST('vis', $id),
87                                                 REQUEST_POST('sort', $id),
88                                                 $id
89                                         ), __FILE__, __LINE__);
90                                 $TEXT = CATEGORIES_SAVED;
91                                 break;
92
93                         case "del": // Delete categories
94                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_cats` WHERE id=%s LIMIT 1",
95                                         array($id), __FILE__, __LINE__);
96                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_cats` WHERE cat_id=%s",
97                                         array($id), __FILE__, __LINE__);
98                                 $TEXT = CATEGORIES_DELETED;
99                                 break;
100                         }
101                 } else {
102                         // Entry not saved
103                         $TEXT .= sprintf(CATEGORY_NOT_SAVED, $id);
104                 }
105         }
106
107         if (isset($TEXT)) {
108                 // Display message
109                 LOAD_TEMPLATE("admin_settings_saved", false, $TEXT);
110         }
111 } elseif ((REQUEST_ISSET_POST('del')) && (SELECTION_COUNT(REQUEST_POST('sel')) > 0)) {
112         // Delete categories
113         $OUT = ""; $SW = 2;
114         foreach (REQUEST_POST('sel') as $id => $value) {
115                 // Load data of category
116                 $result = SQL_QUERY_ESC("SELECT cat FROM `{!_MYSQL_PREFIX!}_cats` WHERE id=%s LIMIT 1",
117                         array(bigintval($id)), __FILE__, __LINE__);
118                 list($cat) = SQL_FETCHROW($result);
119                 SQL_FREERESULT($result);
120
121                 // Prepare data for the row template
122                 $content = array(
123                         'sw'  => $SW,
124                         'id'  => $id,
125                         'cat' => $cat,
126                 );
127
128                 // Load row template and switch colors
129                 $OUT .= LOAD_TEMPLATE("admin_del_cats_row", true, $content);
130                 $SW = 3 - $SW;
131         }
132         define('__CAT_ROWS', $OUT);
133
134         // Load main template
135         LOAD_TEMPLATE("admin_del_cats");
136 } elseif ((REQUEST_ISSET_POST('edit')) && (SELECTION_COUNT(REQUEST_POST('sel')) > 0)) {
137         // Edit categories
138         $OUT = ""; $SW = 2;
139         foreach (REQUEST_POST('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'  => ADD_SELECTION("yn", $vis, "vis", $id),
153                         'sort' => $sort,
154                 );
155
156                 // Load row template and switch colors
157                 $OUT .= LOAD_TEMPLATE("admin_edit_cats_row", true, $content);
158                 $SW = 3 - $SW;
159         }
160         define('__CAT_ROWS', $OUT);
161
162         // Load main template
163         LOAD_TEMPLATE("admin_edit_cats");
164 } else {
165         // Init variable here
166         $CATS = "";
167
168         // Load all categories
169         $result = SQL_QUERY("SELECT id, cat, visible, sort FROM `{!_MYSQL_PREFIX!}_cats` ORDER BY `sort`", __FILE__, __LINE__);
170         if (SQL_NUMROWS($result) > 0) {
171                 // Init variables
172                 $OUT = ""; $SW = 2;
173
174                 // List already existing categories for editing
175                 while ($content = SQL_FETCHARRAY($result)) {
176                         // Prepare data for the row template
177                         $content['sw']  = $SW;
178                         $content['vis'] = TRANSLATE_YESNO($content['visible']);
179
180                         // Put cat descriptions into variable for the selection box
181                         if (strlen($content['cat']) > 20) $content['cat'] = substr($content['cat'], 0, 17)."...";
182                         $CATS .= "      <option value=\"".$content['sort']."\">".$content['cat']."</option>\n";
183
184                         // Load row template and switch color
185                         $OUT .= LOAD_TEMPLATE("admin_config_cats_row", true, $content);
186                         $SW = 3 - $SW;
187                 }
188
189                 // Free memory
190                 SQL_FREERESULT($result);
191
192                 // @TODO Rewrite this constant
193                 define('__CAT_ROWS', $OUT);
194
195                 // Load main template
196                 LOAD_TEMPLATE("admin_config_cats");
197         }
198
199         // @TODO Rewrite this constant
200         define('CATS', $CATS);
201
202         // Form to add a new category
203         LOAD_TEMPLATE("admin_add_cat");
204 }
205
206 //
207 ?>