cc60003eaa6127f3bd418f9e83213e2ad82ac528
[mailer.git] / inc / modules / admin / what-list_country.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 04/30/2005 *
4  * ===================                          Last change: 04/30/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-list_country.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : Manage country codes                             *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Country codes verwalten                          *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
41         die();
42 }
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
47 // Add new code?
48 if ((isPostRequestElementSet('add')) && (isPostRequestElementSet(('code'))) && (isPostRequestElementSet(('descr')))) {
49         // Check if country code does already exist
50         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_countries` WHERE code='%s' LIMIT 1",
51         array(strtoupper(postRequestElement('code'))), __FILE__, __LINE__);
52         if (SQL_NUMROWS($result) == '0') {
53                 // Save entry
54                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_countries` (code, descr, is_active) VALUES ('%s','%s','%s')",
55                 array(
56                 strtoupper(substr(postRequestElement('code'), 0, 2)),
57                 postRequestElement('descr'),
58                 postRequestElement('is_active')
59                 ), __FILE__, __LINE__);
60
61                 // Country added
62                 $message = sprintf(getMessage('ADMIN_COUNTRY_ADDED'), strtoupper(postRequestElement('descr')));
63         } else {
64                 // Free memory
65                 SQL_FREERESULT($result);
66
67                 // Does already exist
68                 $message = sprintf(getMessage('ADMIN_COUNTRY_ALREADY'), strtoupper(postRequestElement('code')));
69         }
70
71         // Display message
72         loadTemplate('admin_settings_saved', false, $message);
73 } elseif ((isPostRequestElementSet('change')) && (isPostRequestElementSet('id'))) {
74         // Change all status
75         adminChangeActivationStatus(postRequestElement('id'), 'countries', 'is_active');
76
77         // Show next link
78         loadTemplate('admin_next_link', false, array(
79                 'url'   => 'modules.php?module=admin&amp;what=list_country',
80                 'title' => getMessage('ADMIN_COUNTRY_ACTIVATION_NEXT_LINK')
81         ));
82 } elseif (((isPostRequestElementSet('edit')) || (isPostRequestElementSet('delete'))) && (isPostRequestElementSet('id'))) {
83         if (count(postRequestElement('id')) > 0) {
84                 if (isPostRequestElementSet('edit')) {
85                         // Edit template
86                         $row    = 'admin_list_country_edit_row';
87                         $post   = 'modify';
88                         $class  = 'admin_submit';
89                         $submit = getMessage('ADMIN_COUNTRY_EDIT_NOW');
90                         $title  = getMessage('ADMIN_COUNTRY_EDIT_TITLE');
91                         $reset  = '<input type="reset" class="admin_reset" value="{--UNDO_SELECTIONS--}" />&nbsp;*';
92                 } else {
93                         // Delete template
94                         $row    = 'admin_list_country_del_row';
95                         $post   = 'remove';
96                         $class  = 'admin_delete';
97                         $submit = getMessage('ADMIN_COUNTRY_DELETE_NOW');
98                         $title  = getMessage('ADMIN_COUNTRY_DELETE_TITLE');
99                         $reset  = '';
100                 }
101
102                 // Edit all selected country codes
103                 $OUT = ''; $SW = 2;
104                 foreach (postRequestElement('id') as $id => $status) {
105                         // Load data from DB
106                         $result = SQL_QUERY_ESC("SELECT code, descr FROM `{?_MYSQL_PREFIX?}_countries` WHERE `id`=%s LIMIT 1",
107                         array(bigintval($id)), __FILE__, __LINE__);
108                         if (SQL_NUMROWS($result) == 1) {
109                                 // Load data
110                                 list($code, $descr) = SQL_FETCHROW($result);
111                                 SQL_FREERESULT($result);
112
113                                 // Prepare data, load row template and switch colors
114                                 $content = array(
115                                         'id'    => $id,
116                                         'code'  => $code,
117                                         'descr' => $descr,
118                                         'sw'    => $SW,
119                                 );
120
121                                 if ($post == 'modify') {
122                                         // Generate default selection in edit-mode
123                                         $content['status'] = generateOptionList('/ARRAY/', array('Y', 'N'), array(getMessage('YES'), getMessage('NO')), $status);
124                                 } else {
125                                         // Only display status when in delete-mode
126                                         $content['status'] = translateYesNo($status);
127                                 }
128
129                                 // Insert row template and switch color
130                                 $OUT .= loadTemplate($row, true, $content);
131                                 $SW = 3 - $SW;
132                         }
133                 }
134
135                 // Prepare content for template
136                 $content = array(
137                         'rows'   => $OUT,
138                         'mode'   => $post,
139                         'class'  => $class,
140                         'title'  => $title,
141                         'submit' => $submit,
142                         'reset'  => $reset,
143                 );
144
145                 // Load main template
146                 loadTemplate('admin_list_country_form', false, $content);
147         }
148 } else {
149         // Shall we modify / remove entries now?
150         $message = ''; initSqls();
151         if ((isPostRequestElementSet(('modify'))) && (isPostRequestElementSet('id'))) {
152                 // Modify
153                 foreach (postRequestElement('id') as $id => $sel) {
154                         addSql("UPDATE `{?_MYSQL_PREFIX?}_countries` SET `code`='".postRequestElement('code', $id)."', `descr`='".postRequestElement('descr', $id)."', `is_active`='".postRequestElement('is_active', $id)."' WHERE `id`='".$id."' LIMIT 1");
155                 }
156
157                 // Create message
158                 $message = getMessage('ADMIN_COUNTRIES_MODIFIED');
159         } elseif ((isPostRequestElementSet('remove')) && (isPostRequestElementSet('id'))) {
160                 // Remove
161                 $IDs = implode(',', array_keys(postRequestElement('id')));
162                 addSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_countries` WHERE `id` IN (".$IDs.") LIMIT ".count(postRequestElement('id'))."");
163
164                 // Create message
165                 $message = getMessage('ADMIN_COUNTRIES_REMOVED');
166         }
167
168         if ((!empty($message)) && (countSqls() > 0)) {
169                 // Run SQL commands
170                 runFilterChain('run_sqls');
171
172                 // Display message
173                 loadTemplate('admin_settings_saved', false, $message);
174         }
175
176         // Load currenty setup country codes to list
177         $result = SQL_QUERY('SELECT id, code, descr, is_active FROM `{?_MYSQL_PREFIX?}_countries` ORDER BY code',
178         __FILE__, __LINE__);
179         if (SQL_NUMROWS($result) > 0) {
180                 // List all countries
181                 $OUT = ''; $SW = 2;
182                 while ($content = SQL_FETCHARRAY($result)) {
183                         // Prepare array for the template
184                         $content['active'] = translateYesNo($content['is_active']);
185                         $content['sw']     = $SW;
186
187                         // Load row template and switch colors
188                         $OUT .= loadTemplate('admin_list_country_row', true, $content);
189                         $SW = 3 - $SW;
190                 }
191
192                 // Free memory
193                 SQL_FREERESULT($result);
194         } else {
195                 // No code setup so far (not possible by this software! 'DE' for 'Deutschland' is default
196                 $OUT = loadTemplate('admin_list_country_no_row', true);
197         }
198
199         // Add list to constant for the template
200         $content['rows'] = $OUT;
201
202         // Include add template
203         $content['add_form'] = loadTemplate('admin_add_country', true);
204
205         // Load main template
206         loadTemplate('admin_list_country', false, $content);
207 }
208
209 // [EOF]
210 ?>