2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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 - 2009 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')) || (!isAdmin())) {
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
48 // Init variable to avoid a notice
51 if (isPostRequestElementSet('add')) {
53 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_cats` WHERE cat='%s' LIMIT 1",
54 array(postRequestElement('catname')), __FILE__, __LINE__);
55 if (SQL_NUMROWS($result) == '0') {
56 // Category does not exists, we simply add it...
57 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_cats` (cat, visible, sort) VALUES ('%s','%s','%s')",
58 array(postRequestElement('catname'), postRequestElement('visible'), bigintval(postRequestElement('parent') + 1)), __FILE__, __LINE__);
59 $content = getMessage('CATEGORY_ADDED');
61 // Category does already exists
62 $content = "<span class=\"admin_failed\">{--CATEGORY_ALREADY_EXISTS--}</span>";
66 SQL_FREERESULT($result);
69 loadTemplate('admin_settings_saved', false, $content);
70 } elseif ((isFormSent()) && (isPostRequestElementSet('id')) && (is_array(postRequestElement('id')))) {
71 // Change or delete categories...
73 foreach (postRequestElement('id') as $id => $cat) {
79 switch (getRequestElement('do'))
81 case 'edit': // Change categories
82 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_cats` SET cat='%s', `visible`='%s', sort=%s WHERE `id`=%s LIMIT 1",
85 postRequestElement('vis', $id),
86 postRequestElement('sort', $id),
88 ), __FILE__, __LINE__);
89 $TEXT = getMessage('CATEGORIES_SAVED');
92 case 'del': // Delete categories
93 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
94 array($id), __FILE__, __LINE__);
95 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE cat_id=%s",
96 array($id), __FILE__, __LINE__);
97 $TEXT = getMessage('CATEGORIES_DELETED');
102 $TEXT .= sprintf(getMessage('CATEGORY_NOT_SAVED'), $id);
108 loadTemplate('admin_settings_saved', false, $TEXT);
110 } elseif ((isPostRequestElementSet('del')) && (countPostSelection() > 0)) {
113 foreach (postRequestElement('sel') as $id => $value) {
114 // Load data of category
115 $result = SQL_QUERY_ESC("SELECT `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
116 array(bigintval($id)), __FILE__, __LINE__);
117 list($cat) = SQL_FETCHROW($result);
120 SQL_FREERESULT($result);
122 // Prepare data for the row template
129 // Load row template and switch colors
130 $OUT .= loadTemplate('admin_del_cats_row', true, $content);
134 // Load main template
135 loadTemplate('admin_del_cats', false, $OUT);
136 } elseif ((isPostRequestElementSet('edit')) && (countPostSelection() > 0)) {
139 foreach (postRequestElement('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' => addSelectionBox('yn', $vis, 'vis', $id),
156 // Load row template and switch colors
157 $OUT .= loadTemplate('admin_edit_cats_row', true, $content);
161 // Load main template
162 loadTemplate('admin_edit_cats', false, $OUT);
164 // Init variable here
167 // Load all categories
168 $result = SQL_QUERY("SELECT `id`, `cat`, `visible`, `sort` FROM `{?_MYSQL_PREFIX?}_cats` ORDER BY `sort` ASC", __FILE__, __LINE__);
169 if (SQL_NUMROWS($result) > 0) {
173 // List already existing categories for editing
174 while ($content = SQL_FETCHARRAY($result)) {
175 // Prepare data for the row template
176 $content['sw'] = $SW;
177 $content['vis'] = translateYesNo($content['visible']);
179 // Put cat descriptions into variable for the selection box
180 if (strlen($content['cat']) > 20) $content['cat'] = substr($content['cat'], 0, 17)."...";
181 $CATS .= " <option value=\"".$content['sort']."\">".$content['cat']."</option>\n";
183 // Load row template and switch color
184 $OUT .= loadTemplate('admin_config_cats_row', true, $content);
189 SQL_FREERESULT($result);
191 // Load main template
192 loadTemplate('admin_config_cats', false, $OUT);
196 $content['cats'] = $CATS;
198 // Form to add a new category
199 loadTemplate('admin_add_cat', false, $content);