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