2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 04/30/2005 *
4 * ================ Last change: 04/30/2005 *
6 * -------------------------------------------------------------------- *
7 * File : what-list_country.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Manage country codes *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Country codes verwalten *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 *
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__);
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') {
54 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_countries` (code, descr, is_active) VALUES ('%s','%s','%s')",
56 strtoupper(substr(postRequestElement('code'), 0, 2)),
57 postRequestElement('descr'),
58 postRequestElement('is_active')
59 ), __FILE__, __LINE__);
62 $message = sprintf(getMessage('ADMIN_COUNTRY_ADDED'), strtoupper(postRequestElement('descr')));
65 SQL_FREERESULT($result);
68 $message = sprintf(getMessage('ADMIN_COUNTRY_ALREADY'), strtoupper(postRequestElement('code')));
72 loadTemplate('admin_settings_saved', false, $message);
73 } elseif ((isPostRequestElementSet('change')) && (isPostRequestElementSet('id'))) {
75 adminChangeActivationStatus(postRequestElement('id'), 'countries', 'is_active');
78 loadTemplate('admin_next_link', false, array(
79 'url' => 'modules.php?module=admin&what=list_country',
80 'title' => getMessage('ADMIN_COUNTRY_ACTIVATION_NEXT_LINK')
82 } elseif (((isPostRequestElementSet('edit')) || (isPostRequestElementSet('delete'))) && (isPostRequestElementSet('id'))) {
83 if (count(postRequestElement('id')) > 0) {
84 if (isPostRequestElementSet('edit')) {
86 $row = 'admin_list_country_edit_row';
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--}" /> *';
94 $row = 'admin_list_country_del_row';
96 $class = 'admin_delete';
97 $submit = getMessage('ADMIN_COUNTRY_DELETE_NOW');
98 $title = getMessage('ADMIN_COUNTRY_DELETE_TITLE');
102 // Edit all selected country codes
104 foreach (postRequestElement('id') as $id => $status) {
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) {
110 list($code, $descr) = SQL_FETCHROW($result);
111 SQL_FREERESULT($result);
113 // Prepare data, load row template and switch colors
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);
125 // Only display status when in delete-mode
126 $content['status'] = translateYesNo($status);
129 // Insert row template and switch color
130 $OUT .= loadTemplate($row, true, $content);
135 // Prepare content for template
145 // Load main template
146 loadTemplate('admin_list_country_form', false, $content);
149 // Shall we modify / remove entries now?
150 $message = ''; initSqls();
151 if ((isPostRequestElementSet(('modify'))) && (isPostRequestElementSet('id'))) {
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");
158 $message = getMessage('ADMIN_COUNTRIES_MODIFIED');
159 } elseif ((isPostRequestElementSet('remove')) && (isPostRequestElementSet('id'))) {
161 $IDs = implode(',', array_keys(postRequestElement('id')));
162 addSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_countries` WHERE `id` IN (".$IDs.") LIMIT ".count(postRequestElement('id'))."");
165 $message = getMessage('ADMIN_COUNTRIES_REMOVED');
168 if ((!empty($message)) && (countSqls() > 0)) {
170 runFilterChain('run_sqls');
173 loadTemplate('admin_settings_saved', false, $message);
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',
179 if (SQL_NUMROWS($result) > 0) {
180 // List all countries
182 while ($content = SQL_FETCHARRAY($result)) {
183 // Prepare array for the template
184 $content['active'] = translateYesNo($content['is_active']);
185 $content['sw'] = $SW;
187 // Load row template and switch colors
188 $OUT .= loadTemplate('admin_list_country_row', true, $content);
193 SQL_FREERESULT($result);
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);
199 // Add list to constant for the template
200 $content['rows'] = $OUT;
202 // Include add template
203 $content['add_form'] = loadTemplate('admin_add_country', true);
205 // Load main template
206 loadTemplate('admin_list_country', false, $content);