2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 10/10/2003 *
4 * =================== Last change: 07/04/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-list_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 * -------------------------------------------------------------------- *
19 * Copyright (c) 2003 - 2009 by Roland Haeder *
20 * Copyright (c) 2009 - 2015 by Mailer Developer Team *
21 * For more information visit: http://mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
44 // Add description as navigation point
45 addYouAreHereLink('admin', __FILE__);
47 // Init variable to avoid a notice
50 if (isFormSent('add')) {
52 $content = '<span class="bad">{--CATEGORY_ALREADY_EXISTS--}</span>';
55 $result = sqlQueryEscaped("SELECT `id` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `cat`='%s' LIMIT 1",
56 array(postRequestElement('catname')), __FILE__, __LINE__);
58 if (ifSqlHasZeroNumRows($result)) {
59 // Category does not exists, we simply add it...
60 sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_cats` (`cat`, `visible`, `sort`) VALUES ('%s','%s','%s')",
62 postRequestElement('catname'),
63 postRequestElement('visible'),
64 bigintval(postRequestElement('parent') + 1)
65 ), __FILE__, __LINE__);
67 // Category has been added
68 $content = '{--CATEGORY_ADDED--}';
72 sqlFreeResult($result);
75 displayMessage($content);
76 } elseif ((isFormSent()) && (ifPostContainsSelections('id'))) {
77 // Change or delete categories...
79 foreach (postRequestElement('id') as $id => $cat) {
85 switch (getRequestElement('do')) {
86 case 'edit': // Change categories
87 sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_cats` SET `cat`='%s',`visible`='%s',`sort`=%s WHERE `id`=%s LIMIT 1",
90 postRequestElement('visible', $id),
91 postRequestElement('sort', $id),
93 ), __FILE__, __LINE__);
94 $TEXT = '{--ADMIN_CATEGORIES_SAVED--}';
97 case 'delete': // Delete categories
98 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
99 array($id), __FILE__, __LINE__);
100 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `cat_id`=%s",
101 array($id), __FILE__, __LINE__);
102 $TEXT = '{--ADMIN_CATEGORIES_DELETED--}';
107 $TEXT .= '{%message,ADMIN_CATEGORY_NOT_SAVED=' . $id . '%}';
113 displayMessage($TEXT);
115 } elseif ((isFormSent('delete')) && (ifPostContainsSelections())) {
118 foreach (postRequestElement('sel') as $id => $value) {
119 // Load row template and switch colors
120 $OUT .= loadTemplate('admin_delete_cats_row', TRUE, $id);
123 // Load main template
124 loadTemplate('admin_delete_cats', FALSE, $OUT);
125 } elseif ((isFormSent('edit')) && (ifPostContainsSelections())) {
128 foreach (postRequestElement('sel') as $id => $value) {
129 // Load data from the category
130 $result = sqlQueryEscaped("SELECT `id`, `visible`, `sort` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
131 array(bigintval($id)), __FILE__, __LINE__);
132 $content = sqlFetchArray($result);
135 sqlFreeResult($result);
137 // Prepare data for the row template
138 $content['visible_selection'] = addSelectionBox('yn', $content['visible'], 'visible', $content['id']);
140 // Load row template and switch colors
141 $OUT .= loadTemplate('admin_edit_cats_row', TRUE, $content);
144 // Load main template
145 loadTemplate('admin_edit_cats', FALSE, $OUT);
147 // Init variable here
150 // Load all categories
151 $result = sqlQuery("SELECT
157 `{?_MYSQL_PREFIX?}_cats`
159 `sort` ASC", __FILE__, __LINE__);
161 if (!ifSqlHasZeroNumRows($result)) {
165 // List already existing categories for editing
166 while ($content = sqlFetchArray($result)) {
167 // Put cat descriptions into variable for the selection box
168 if (strlen($content['cat']) > 40) $content['cat'] = substr($content['cat'], 0, 37) . '...';
169 $CATS .= '<option value="' . $content['sort'] . '">' . $content['cat'] . '</option>';
171 // Load row template and switch color
172 $OUT .= loadTemplate('admin_list_cats_row', TRUE, $content);
176 sqlFreeResult($result);
178 // Load main template
179 loadTemplate('admin_list_cats', FALSE, $OUT);
183 $content['cats'] = $CATS;
185 // Form to add a new category
186 loadTemplate('admin_add_cat', FALSE, $content);