Configuration of advertisement networks prepared, CSS cleaned up, HTML rewritten:
[mailer.git] / inc / modules / admin / what-config_cats.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 10/10/2003 *
4  * ===================                          Last change: 07/04/2004 *
5  *                                                                      *
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  * -------------------------------------------------------------------- *
14  * $Revision::                                                        $ *
15  * $Date::                                                            $ *
16  * $Tag:: 0.2.1-FINAL                                                 $ *
17  * $Author::                                                          $ *
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  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
23  * For more information visit: http://www.mxchange.org                  *
24  *                                                                      *
25  * This program is free software; you can redistribute it and/or modify *
26  * it under the terms of the GNU General Public License as published by *
27  * the Free Software Foundation; either version 2 of the License, or    *
28  * (at your option) any later version.                                  *
29  *                                                                      *
30  * This program is distributed in the hope that it will be useful,      *
31  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
33  * GNU General Public License for more details.                         *
34  *                                                                      *
35  * You should have received a copy of the GNU General Public License    *
36  * along with this program; if not, write to the Free Software          *
37  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
38  * MA  02110-1301  USA                                                  *
39  ************************************************************************/
40
41 // Some security stuff...
42 if ((!defined('__SECURITY')) || (!isAdmin())) {
43         die();
44 } // END - if
45
46 // Add description as navigation point
47 addMenuDescription('admin', __FILE__);
48
49 // Init variable to avoid a notice
50 $CATS = '';
51
52 if (isFormSent('add')) {
53         // Add a new category
54         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `cat`='%s' LIMIT 1",
55                 array(postRequestParameter('catname')), __FILE__, __LINE__);
56         if (SQL_HASZERONUMS($result)) {
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(
60                                 postRequestParameter('catname'),
61                                 postRequestParameter('visible'),
62                                 bigintval(postRequestParameter('parent') + 1)
63                         ), __FILE__, __LINE__);
64                 $content = '{--CATEGORY_ADDED--}';
65         } else {
66                 // Category does already exists
67                 $content = '<span class="notice">{--CATEGORY_ALREADY_EXISTS--}</span>';
68         }
69
70         // Free memory
71         SQL_FREERESULT($result);
72
73         // Display message
74         loadTemplate('admin_settings_saved', false, $content);
75 } elseif ((isFormSent()) && (isPostRequestParameterSet('id')) && (is_array(postRequestParameter('id')))) {
76         // Change or delete categories...
77         $TEXT = '';
78         foreach (postRequestParameter('id') as $id => $cat) {
79                 // Secure id
80                 $id = bigintval($id);
81
82                 // Is the entry set?
83                 if (!empty($cat)) {
84                         switch (getRequestParameter('do')) {
85                                 case 'edit': // Change categories
86                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_cats` SET `cat`='%s', `visible`='%s', `sort`=%s WHERE `id`=%s LIMIT 1",
87                                                 array(
88                                                         $cat,
89                                                         postRequestParameter('visible', $id),
90                                                         postRequestParameter('sort', $id),
91                                                         $id
92                                                 ), __FILE__, __LINE__);
93                                         $TEXT = '{--ADMIN_CATEGORIES_SAVED--}';
94                                         break;
95
96                                 case 'delete': // Delete categories
97                                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
98                                                 array($id), __FILE__, __LINE__);
99                                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `cat_id`=%s",
100                                                 array($id), __FILE__, __LINE__);
101                                         $TEXT = '{--ADMIN_CATEGORIES_DELETED--}';
102                                         break;
103                         } // END - switch
104                 } else {
105                         // Entry not saved
106                         $TEXT .= getMaskedMessage('ADMIN_CATEGORY_NOT_SAVED', $id);
107                 }
108         } // END - foreach
109
110         if (isset($TEXT)) {
111                 // Display message
112                 loadTemplate('admin_settings_saved', false, $TEXT);
113         } // END - if
114 } elseif ((isFormSent('delete')) && (ifPostContainsSelections())) {
115         // Delete categories
116         $OUT = '';
117         foreach (postRequestParameter('sel') as $id => $value) {
118                 // Load row template and switch colors
119                 $OUT .= loadTemplate('admin_delete_cats_row', true, $id);
120         } // END - foreach
121
122         // Load main template
123         loadTemplate('admin_delete_cats', false, $OUT);
124 } elseif ((isFormSent('edit')) && (ifPostContainsSelections())) {
125         // Edit categories
126         $OUT = '';
127         foreach (postRequestParameter('sel') as $id => $value) {
128                 // Load data from the category
129                 $result = SQL_QUERY_ESC("SELECT `id`, `visible`, `sort` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
130                         array(bigintval($id)), __FILE__, __LINE__);
131                 $content = SQL_FETCHARRAY($result);
132
133                 // Free result
134                 SQL_FREERESULT($result);
135
136                 // Prepare data for the row template
137                 $content['visible_selection'] = addSelectionBox('yn', $content['visible'], 'visible', $content['id']);
138
139                 // Load row template and switch colors
140                 $OUT .= loadTemplate('admin_edit_cats_row', true, $content);
141         } // END - foreach
142
143         // Load main template
144         loadTemplate('admin_edit_cats', false, $OUT);
145 } else {
146         // Init variable here
147         $CATS = '';
148
149         // Load all categories
150         $result = SQL_QUERY("SELECT `id`, `cat`, `visible`, `sort` FROM `{?_MYSQL_PREFIX?}_cats` ORDER BY `sort` ASC", __FILE__, __LINE__);
151         if (!SQL_HASZERONUMS($result)) {
152                 // Init variables
153                 $OUT = '';
154
155                 // List already existing categories for editing
156                 while ($content = SQL_FETCHARRAY($result)) {
157                         // Put cat descriptions into variable for the selection box
158                         $cat = $content['cat'];
159                         if (strlen($cat) > 40) $cat = substr($cat, 0, 37) . '...';
160                         $CATS .= '<option value="' . $content['sort'] . '">' . $cat . '</option>';
161
162                         // Load row template and switch color
163                         $OUT .= loadTemplate('admin_config_cats_row', true, $content);
164                 } // END - while
165
166                 // Free memory
167                 SQL_FREERESULT($result);
168
169                 // Load main template
170                 loadTemplate('admin_config_cats', false, $OUT);
171         } // END - if
172
173         // Remember in array
174         $content['cats'] = $CATS;
175
176         // Form to add a new category
177         loadTemplate('admin_add_cat', false, $content);
178 }
179
180 // [EOF]
181 ?>