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 * -------------------------------------------------------------------- *
19 * Copyright (c) 2003 - 2009 by Roland Haeder *
20 * Copyright (c) 2009, 2010 by Mailer Developer Team *
21 * For more information visit: http://www.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 addMenuDescription('admin', __FILE__);
47 // Init variable to avoid a notice
50 if (isFormSent('add')) {
52 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `cat`='%s' LIMIT 1",
53 array(postRequestParameter('catname')), __FILE__, __LINE__);
54 if (SQL_HASZERONUMS($result)) {
55 // Category does not exists, we simply add it...
56 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_cats` (`cat`, `visible`, `sort`) VALUES ('%s','%s','%s')",
58 postRequestParameter('catname'),
59 postRequestParameter('visible'),
60 bigintval(postRequestParameter('parent') + 1)
61 ), __FILE__, __LINE__);
62 $content = '{--CATEGORY_ADDED--}';
64 // Category does already exists
65 $content = '<span class="notice">{--CATEGORY_ALREADY_EXISTS--}</span>';
69 SQL_FREERESULT($result);
72 loadTemplate('admin_settings_saved', false, $content);
73 } elseif ((isFormSent()) && (isPostRequestParameterSet('id')) && (is_array(postRequestParameter('id')))) {
74 // Change or delete categories...
76 foreach (postRequestParameter('id') as $id => $cat) {
82 switch (getRequestParameter('do')) {
83 case 'edit': // Change categories
84 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_cats` SET `cat`='%s', `visible`='%s', `sort`=%s WHERE `id`=%s LIMIT 1",
87 postRequestParameter('visible', $id),
88 postRequestParameter('sort', $id),
90 ), __FILE__, __LINE__);
91 $TEXT = '{--ADMIN_CATEGORIES_SAVED--}';
94 case 'delete': // Delete categories
95 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
96 array($id), __FILE__, __LINE__);
97 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `cat_id`=%s",
98 array($id), __FILE__, __LINE__);
99 $TEXT = '{--ADMIN_CATEGORIES_DELETED--}';
104 $TEXT .= getMaskedMessage('ADMIN_CATEGORY_NOT_SAVED', $id);
110 loadTemplate('admin_settings_saved', false, $TEXT);
112 } elseif ((isFormSent('delete')) && (ifPostContainsSelections())) {
115 foreach (postRequestParameter('sel') as $id => $value) {
116 // Load row template and switch colors
117 $OUT .= loadTemplate('admin_delete_cats_row', true, $id);
120 // Load main template
121 loadTemplate('admin_delete_cats', false, $OUT);
122 } elseif ((isFormSent('edit')) && (ifPostContainsSelections())) {
125 foreach (postRequestParameter('sel') as $id => $value) {
126 // Load data from the category
127 $result = SQL_QUERY_ESC("SELECT `id`, `visible`, `sort` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
128 array(bigintval($id)), __FILE__, __LINE__);
129 $content = SQL_FETCHARRAY($result);
132 SQL_FREERESULT($result);
134 // Prepare data for the row template
135 $content['visible_selection'] = addSelectionBox('yn', $content['visible'], 'visible', $content['id']);
137 // Load row template and switch colors
138 $OUT .= loadTemplate('admin_edit_cats_row', true, $content);
141 // Load main template
142 loadTemplate('admin_edit_cats', false, $OUT);
144 // Init variable here
147 // Load all categories
148 $result = SQL_QUERY("SELECT `id`, `cat`, `visible`, `sort` FROM `{?_MYSQL_PREFIX?}_cats` ORDER BY `sort` ASC", __FILE__, __LINE__);
149 if (!SQL_HASZERONUMS($result)) {
153 // List already existing categories for editing
154 while ($content = SQL_FETCHARRAY($result)) {
155 // Put cat descriptions into variable for the selection box
156 $cat = $content['cat'];
157 if (strlen($cat) > 40) $cat = substr($cat, 0, 37) . '...';
158 $CATS .= '<option value="' . $content['sort'] . '">' . $cat . '</option>';
160 // Load row template and switch color
161 $OUT .= loadTemplate('admin_config_cats_row', true, $content);
165 SQL_FREERESULT($result);
167 // Load main template
168 loadTemplate('admin_config_cats', false, $OUT);
172 $content['cats'] = $CATS;
174 // Form to add a new category
175 loadTemplate('admin_add_cat', false, $content);