2 /************************************************************************
3 * MXChange v0.2.1 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 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
44 if ((isset($_POST['add'])) && (!empty($_POST['code'])) && (!empty($_POST['descr']))) {
45 // Check if country code does already exist
46 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_countries` WHERE code='%s' LIMIT 1",
47 array(strtoupper($_POST['code'])), __FILE__, __LINE__);
48 if (SQL_NUMROWS($result) == 0) {
50 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_countries` (code, descr, is_active) VALUES ('%s','%s','%s')",
52 strtoupper(substr($_POST['code'], 0, 2)),
55 ), __FILE__, __LINE__);
58 $MSG = ADMIN_COUNTRY_ADDED_1.strtoupper($_POST['descr']).ADMIN_COUNTRY_ADDED_2;
61 SQL_FREERESULT($result);
64 $MSG = ADMIN_COUNTRY_ALREADY_1.strtoupper($_POST['code']).ADMIN_COUNTRY_ALREADY_2;
68 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
69 } elseif ((isset($_POST['change'])) && (!empty($_POST['id']))) {
71 ADMIN_CHANGE_ACTIVATION_STATUS($_POST['id'], "countries", "is_active");
74 LOAD_TEMPLATE("admin_next_link", false, array(
75 'url' => "modules.php?module=admin&what=list_country",
76 'title' => getMessage('ADMIN_COUNTRY_ACTIVATION_NEXT_LINK')
78 } elseif (((isset($_POST['edit'])) || (isset($_POST['delete']))) && (!empty($_POST['id']))) {
79 if (count($_POST['id']) > 0) {
80 if (isset($_POST['edit'])) {
82 $row = "admin_list_country_edit_row";
84 $class = "admin_submit";
85 $submit = ADMIN_COUNTRY_EDIT_NOW;
86 $title = ADMIN_COUNTRY_EDIT_TITLE;
87 $reset = "<input type=\"reset\" class=\"admin_reset\" value=\"{!UNDO_SELECTIONS!}\" /> *\n";
90 $row = "admin_list_country_del_row";
92 $class = "admin_delete";
93 $submit = ADMIN_COUNTRY_DELETE_NOW;
94 $title = ADMIN_COUNTRY_DELETE_TITLE;
98 // Edit all selected country codes
100 foreach ($_POST['id'] as $id => $status) {
102 $result = SQL_QUERY_ESC("SELECT code, descr FROM `{!_MYSQL_PREFIX!}_countries` WHERE id=%s LIMIT 1",
103 array(bigintval($id)), __FILE__, __LINE__);
104 if (SQL_NUMROWS($result) == 1) {
106 list($code, $descr) = SQL_FETCHROW($result);
107 SQL_FREERESULT($result);
109 // Prepare data, load row template and switch colors
117 if ($post == "modify") {
118 // Generate default selection in edit-mode
119 $content['status'] = ADD_OPTION_LINES("/ARRAY/", array("Y","N"), array(YES, NO ), $status);
121 // Only display status when in delete-mode
122 $content['status'] = TRANSLATE_YESNO($status);
125 // Insert row template and switch color
126 $OUT .= LOAD_TEMPLATE($row, true, $content);
130 define('__COUNTRY_ROWS' , $OUT);
131 define('__COUNTRY_MODE' , $post);
132 define('__COUNTRY_CLASS' , $class);
133 define('__COUNTRY_SUBMIT', $submit);
134 define('__COUNTRY_TITLE' , $title);
135 define('__COUNTRY_RESET' , $reset);
137 // Load main template
138 LOAD_TEMPLATE("admin_list_country_form");
141 // Shall we modify / remove entries now?
142 $MSG = ""; $SQLs = array();
143 if ((isset($_POST['modify'])) && (!empty($_POST['id']))) {
145 foreach ($_POST['id'] as $id => $sel) {
146 $SQLs[] = "UPDATE `{!_MYSQL_PREFIX!}_countries` SET code='".$_POST['code'][$id]."', descr='".$_POST['descr'][$id]."', is_active='".$_POST['is_active'][$id]."' WHERE id='".$id."' LIMIT 1";
150 $MSG = ADMIN_COUNTRIES_MODIFIED;
151 } elseif ((isset($_POST['remove'])) && (!empty($_POST['id']))) {
153 $IDs = implode(",", array_keys($_POST['id']));
154 $SQLs[] = "DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_countries` WHERE id IN (".$IDs.") LIMIT ".count($_POST['id'])."";
157 $MSG = ADMIN_COUNTRIES_REMOVED;
160 if ((!empty($MSG)) && (count($SQLs) > 0)) {
162 foreach ($SQLs as $sql) {
163 $result = SQL_QUERY($sql, __FILE__, __LINE__);
167 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
170 // Load currenty setup country codes to list
171 $result = SQL_QUERY("SELECT id, code, descr, is_active FROM `{!_MYSQL_PREFIX!}_countries` ORDER BY code", __FILE__, __LINE__);
172 if (SQL_NUMROWS($result) > 0) {
173 // List all countries
175 while (list($id, $code, $descr, $active) = SQL_FETCHROW($result)) {
176 // Prepare array for the template
181 'active' => TRANSLATE_YESNO($active),
186 // Load row template and switch colors
187 $OUT .= LOAD_TEMPLATE("admin_list_country_row", true, $content);
192 SQL_FREERESULT($result);
194 // No code setup so far (not possible by this software! 'DE' for 'Deutschland' is default
195 $OUT = LOAD_TEMPLATE("admin_list_country_no_row", true);
198 // Add list to constant for the template
199 define('__COUNTRY_ROWS', $OUT);
201 // Include add template
202 define('__ADD_COUNTRY_FORM', LOAD_TEMPLATE("admin_add_country", true));
204 // Load main template
205 LOAD_TEMPLATE("admin_list_country");