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 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009, 2010 by Mailer Developer Team *
20 * For more information visit: http://www.mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
47 if ((isFormSent('add')) && (isPostRequestParameterSet('code')) && (isPostRequestParameterSet('descr'))) {
48 // Check if country code does already exist
49 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_countries` WHERE code='%s' LIMIT 1",
50 array(strtoupper(postRequestParameter('code'))), __FILE__, __LINE__);
51 if (SQL_HASZERONUMS($result)) {
53 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_countries` (code, descr, is_active) VALUES ('%s','%s','%s')",
55 strtoupper(substr(postRequestParameter('code'), 0, 2)),
56 postRequestParameter('descr'),
57 postRequestParameter('is_active')
58 ), __FILE__, __LINE__);
61 $message = getMaskedMessage('ADMIN_COUNTRY_ADDED', strtoupper(postRequestParameter('descr')));
64 SQL_FREERESULT($result);
67 $message = getMaskedMessage('ADMIN_COUNTRY_ALREADY', strtoupper(postRequestParameter('code')));
71 loadTemplate('admin_settings_saved', false, $message);
72 } elseif ((isFormSent('change')) && (isPostRequestParameterSet('id'))) {
74 adminChangeActivationStatus(postRequestParameter('id'), 'countries', 'is_active');
77 loadTemplate('admin_next_link', false, array(
78 'url' => 'modules.php?module=admin&what=list_country',
79 'title' => '{--ADMIN_COUNTRY_ACTIVATION_NEXT_LINK--}'
81 } elseif (((isFormSent('edit')) || (isPostRequestParameterSet('delete'))) && (isPostRequestParameterSet('id'))) {
82 if (count(postRequestParameter('id')) > 0) {
83 if (isFormSent('edit')) {
85 $row = 'admin_list_country_edit_row';
87 $class = 'form_submit';
88 $submit = '{--ADMIN_COUNTRY_EDIT_NOW--}';
89 $title = '{--ADMIN_COUNTRY_EDIT_TITLE--}';
90 $reset = '<input type="reset" class="form_reset" value="{--UNDO_SELECTIONS--}" /> ';
93 $row = 'admin_list_country_del_row';
95 $class = 'form_delete';
96 $submit = '{--ADMIN_COUNTRY_DELETE_NOW--}';
97 $title = '{--ADMIN_COUNTRY_DELETE_TITLE--}';
101 // Edit all selected country codes
103 foreach (postRequestParameter('id') as $id => $isActive) {
105 $result = SQL_QUERY_ESC("SELECT `id`, `code`, `descr` FROM `{?_MYSQL_PREFIX?}_countries` WHERE `id`=%s LIMIT 1",
106 array(bigintval($id)), __FILE__, __LINE__);
107 if (SQL_NUMROWS($result) == 1) {
109 $content = SQL_FETCHARRAY($result);
111 if ($post == 'modify') {
112 // Generate default selection in edit-mode
113 $content['is_active'] = generateOptionList('/ARRAY/', array('Y', 'N'), array('{--YES--}', '{--NO--}'), $isActive);
115 // Only display status when in delete-mode
116 $content['is_active'] = translateYesNo($isActive);
119 // Insert row template and switch color
120 $OUT .= loadTemplate($row, true, $content);
124 SQL_FREERESULT($result);
127 // Prepare content for template
137 // Load main template
138 loadTemplate('admin_list_country_form', false, $content);
141 // Shall we modify / remove entries now?
142 $message = ''; initSqls();
143 if ((isPostRequestParameterSet('modify')) && (isPostRequestParameterSet('id'))) {
145 foreach (postRequestParameter('id') as $id => $sel) {
146 addSql("UPDATE `{?_MYSQL_PREFIX?}_countries` SET `code`='" . postRequestParameter('code', $id) . "', `descr`='" . postRequestParameter('descr', $id) . "', `is_active`='" . postRequestParameter('is_active', $id) . "' WHERE `id`=" . bigintval($id) . " LIMIT 1");
150 $message = '{--ADMIN_COUNTRIES_MODIFIED--}';
151 } elseif ((isFormSent('remove')) && (isPostRequestParameterSet('id'))) {
153 $IDs = implode(',', array_keys(postRequestParameter('id')));
154 addSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_countries` WHERE `id` IN (".$IDs.") LIMIT ".count(postRequestParameter('id'))."");
157 $message = '{--ADMIN_COUNTRIES_REMOVED--}';
160 if ((!empty($message)) && (countSqls() > 0)) {
162 runFilterChain('run_sqls');
165 loadTemplate('admin_settings_saved', false, $message);
168 // Load currenty setup country codes to list
169 $result = SQL_QUERY('SELECT `id`, `code`, `descr`, `is_active` FROM `{?_MYSQL_PREFIX?}_countries` ORDER BY `code` ASC',
172 // Do we have entries?
173 if (!SQL_HASZERONUMS($result)) {
174 // List all countries
176 while ($content = SQL_FETCHARRAY($result)) {
177 // Load row template and switch colors
178 $OUT .= loadTemplate('admin_list_country_row', true, $content);
182 SQL_FREERESULT($result);
184 // No code setup so far (not possible by this software! 'DE' for 'Deutschland' is default
185 $OUT = loadTemplate('admin_list_country_no_row', true);
188 // Add list to constant for the template
189 $content['rows'] = $OUT;
191 // Include add template
192 $content['add_form'] = loadTemplate('admin_add_country', true);
194 // Load main template
195 loadTemplate('admin_list_country', false, $content);