2 /************************************************************************
3 * MXChange v0.2.1 Start: 10/10/2003 *
4 * =============== Last change: 07/04/2004 *
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 * -------------------------------------------------------------------- *
16 * $Tag:: 0.2.1-FINAL $ *
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 *
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. *
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. *
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, *
38 ************************************************************************/
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
42 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
46 // Add description as navigation point
47 ADD_DESCR("admin", __FILE__);
49 // Init variable to avoid a notice
52 if (REQUEST_ISSET_POST(('add'))) {
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;
62 // Category does already exists
63 $content = "<span class=\"admin_failed\">".CATEGORY_ALREADY_EXISTS."</span>";
67 SQL_FREERESULT($result);
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...
74 foreach (REQUEST_POST('id') as $id => $cat) {
80 switch (REQUEST_GET('do'))
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",
86 REQUEST_POST('vis', $id),
87 REQUEST_POST('sort', $id),
89 ), __FILE__, __LINE__);
90 $TEXT = CATEGORIES_SAVED;
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;
103 $TEXT .= sprintf(CATEGORY_NOT_SAVED, $id);
109 LOAD_TEMPLATE("admin_settings_saved", false, $TEXT);
111 } elseif ((REQUEST_ISSET_POST('del')) && (SELECTION_COUNT(REQUEST_POST('sel')) > 0)) {
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);
121 // Prepare data for the row template
128 // Load row template and switch colors
129 $OUT .= LOAD_TEMPLATE("admin_del_cats_row", true, $content);
132 define('__CAT_ROWS', $OUT);
134 // Load main template
135 LOAD_TEMPLATE("admin_del_cats");
136 } elseif ((REQUEST_ISSET_POST('edit')) && (SELECTION_COUNT(REQUEST_POST('sel')) > 0)) {
139 foreach (REQUEST_POST('sel') as $id => $value)
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);
147 // Prepare data for the row template
152 'vis' => ADD_SELECTION("yn", $vis, "vis", $id),
156 // Load row template and switch colors
157 $OUT .= LOAD_TEMPLATE("admin_edit_cats_row", true, $content);
160 define('__CAT_ROWS', $OUT);
162 // Load main template
163 LOAD_TEMPLATE("admin_edit_cats");
165 // Init variable here
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) {
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']);
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";
184 // Load row template and switch color
185 $OUT .= LOAD_TEMPLATE("admin_config_cats_row", true, $content);
190 SQL_FREERESULT($result);
192 // @TODO Rewrite this constant
193 define('__CAT_ROWS', $OUT);
195 // Load main template
196 LOAD_TEMPLATE("admin_config_cats");
199 // @TODO Rewrite this constant
200 define('CATS', $CATS);
202 // Form to add a new category
203 LOAD_TEMPLATE("admin_add_cat");