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 * -------------------------------------------------------------------- *
15 * -------------------------------------------------------------------- *
16 * Copyright (c) 2003 - 2008 by Roland Haeder *
17 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
33 ************************************************************************/
35 // Some security stuff...
36 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
41 // Add description as navigation point
42 ADD_DESCR("admin", __FILE__);
44 // Init variable to avoid a notice
47 if (isset($_POST['add'])) {
49 $result = SQL_QUERY_ESC("SELECT id FROM `{!MYSQL_PREFIX!}_cats` WHERE cat='%s' LIMIT 1",
50 array($_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($_POST['catname'], $_POST['visible'], bigintval($_POST['parent'] + 1)), __FILE__, __LINE__);
55 $content = CATEGORY_ADDED;
57 // Category does already exists
58 $content = "<span class=\"admin_failed\">".CATEGORY_ALREADY_EXISTS."</span>";
62 SQL_FREERESULT($result);
65 LOAD_TEMPLATE("admin_settings_saved", false, $content);
66 } elseif ((isset($_POST['ok'])) && (isset($_POST['id'])) && (is_array($_POST['id']))) {
67 // Change or delete categories...
69 foreach ($_POST['id'] as $id => $cat) {
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($cat, $_POST['vis'][$id], $_POST['sort'][$id], $id), __FILE__, __LINE__);
80 $TEXT = CATEGORIES_SAVED;
83 case "del": // Delete categories
84 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!MYSQL_PREFIX!}_cats` WHERE id=%s LIMIT 1",
85 array($id), __FILE__, __LINE__);
86 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!MYSQL_PREFIX!}_user_cats` WHERE cat_id=%s",
87 array($id), __FILE__, __LINE__);
88 $TEXT = CATEGORIES_DELETED;
93 $TEXT .= sprintf(CATEGORY_NOT_SAVED, $id);
99 LOAD_TEMPLATE("admin_settings_saved", false, $TEXT);
101 } elseif ((isset($_POST['del'])) && ((SELECTION_COUNT($_POST['sel']) > 0) || (isset($_POST['sel'][0])))) {
104 foreach ($_POST['sel'] as $id => $value) {
105 // Load data of category
106 $result = SQL_QUERY_ESC("SELECT cat FROM `{!MYSQL_PREFIX!}_cats` WHERE id=%s LIMIT 1",
107 array(bigintval($id)), __FILE__, __LINE__);
108 list($cat) = SQL_FETCHROW($result);
109 SQL_FREERESULT($result);
111 // Prepare data for the row template
118 // Load row template and switch colors
119 $OUT .= LOAD_TEMPLATE("admin_del_cats_row", true, $content);
122 define('__CAT_ROWS', $OUT);
124 // Load main template
125 LOAD_TEMPLATE("admin_del_cats");
126 } elseif ((isset($_POST['edit'])) && ((SELECTION_COUNT($_POST['sel']) > 0) || (isset($_POST['sel'][0])))) {
129 foreach ($_POST['sel'] as $id => $value)
131 // Load data from the category
132 $result = SQL_QUERY_ESC("SELECT cat, visible, sort FROM `{!MYSQL_PREFIX!}_cats` WHERE id=%s LIMIT 1",
133 array(bigintval($id)), __FILE__, __LINE__);
134 list($cat, $vis, $sort) = SQL_FETCHROW($result);
135 SQL_FREERESULT($result);
137 // Prepare data for the row template
142 'vis' => ADD_SELECTION("yn", $vis, "vis", $id),
146 // Load row template and switch colors
147 $OUT .= LOAD_TEMPLATE("admin_edit_cats_row", true, $content);
150 define('__CAT_ROWS', $OUT);
152 // Load main template
153 LOAD_TEMPLATE("admin_edit_cats");
157 // Load all categories
158 $result = SQL_QUERY("SELECT id, cat, visible, sort FROM `{!MYSQL_PREFIX!}_cats` ORDER BY sort", __FILE__, __LINE__);
159 if (SQL_NUMROWS($result) > 0)
161 // List already existing categories for editing
162 $SW = 2; $OUT = ""; $CATS = "";
163 while (list($id, $cat, $visible, $sort) = SQL_FETCHROW($result))
165 // Prepare data for the row template
170 'vis' => TRANSLATE_YESNO($visible),
174 // Put cat descriptions into variable for the selection box
175 if (strlen($cat) > 20) $cat = substr($cat, 0, 17)."...";
176 $CATS .= " <option value=\"".$sort."\">".$cat."</option>\n";
178 // Load row template and switch color
179 $OUT .= LOAD_TEMPLATE("admin_config_cats_row", true, $content);
184 SQL_FREERESULT($result);
185 define('__CAT_ROWS', $OUT);
187 // Load main template
188 LOAD_TEMPLATE("admin_config_cats");
191 define('CATS', $CATS);
193 // Form to add a new category
194 LOAD_TEMPLATE("admin_add_cat");