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 * $Date:: 2009-03-06 20:24:32 +0100 (Fr, 06. Mär 2009) $ *
15 * $Tag:: 0.2.1-FINAL $ *
16 * $Author:: stelzi $ *
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 - 2008 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')) || (!IS_ADMIN())) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
45 // Add description as navigation point
46 ADD_DESCR("admin", __FILE__);
49 if ((REQUEST_ISSET_POST(('add'))) && (REQUEST_ISSET_POST(('code'))) && (REQUEST_ISSET_POST(('descr')))) {
50 // Check if country code does already exist
51 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_countries` WHERE code='%s' LIMIT 1",
52 array(strtoupper(REQUEST_POST('code'))), __FILE__, __LINE__);
53 if (SQL_NUMROWS($result) == 0) {
55 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_countries` (code, descr, is_active) VALUES ('%s','%s','%s')",
57 strtoupper(substr(REQUEST_POST('code'), 0, 2)),
58 REQUEST_POST('descr'),
59 REQUEST_POST('is_active')
60 ), __FILE__, __LINE__);
63 $MSG = ADMIN_COUNTRY_ADDED_1.strtoupper(REQUEST_POST('descr')).ADMIN_COUNTRY_ADDED_2;
66 SQL_FREERESULT($result);
69 $MSG = ADMIN_COUNTRY_ALREADY_1.strtoupper(REQUEST_POST('code')).ADMIN_COUNTRY_ALREADY_2;
73 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
74 } elseif ((REQUEST_ISSET_POST(('change'))) && (REQUEST_ISSET_POST(('id')))) {
76 ADMIN_CHANGE_ACTIVATION_STATUS(REQUEST_POST('id'), "countries", "is_active");
79 LOAD_TEMPLATE("admin_next_link", false, array(
80 'url' => "modules.php?module=admin&what=list_country",
81 'title' => getMessage('ADMIN_COUNTRY_ACTIVATION_NEXT_LINK')
83 } elseif (((REQUEST_ISSET_POST('edit')) || (REQUEST_ISSET_POST(('delete')))) && (REQUEST_ISSET_POST(('id')))) {
84 if (count(REQUEST_POST('id')) > 0) {
85 if (REQUEST_ISSET_POST('edit')) {
87 $row = "admin_list_country_edit_row";
89 $class = "admin_submit";
90 $submit = ADMIN_COUNTRY_EDIT_NOW;
91 $title = ADMIN_COUNTRY_EDIT_TITLE;
92 $reset = "<input type=\"reset\" class=\"admin_reset\" value=\"{!UNDO_SELECTIONS!}\" /> *\n";
95 $row = "admin_list_country_del_row";
97 $class = "admin_delete";
98 $submit = ADMIN_COUNTRY_DELETE_NOW;
99 $title = ADMIN_COUNTRY_DELETE_TITLE;
103 // Edit all selected country codes
105 foreach (REQUEST_POST('id') as $id => $status) {
107 $result = SQL_QUERY_ESC("SELECT code, descr FROM `{!_MYSQL_PREFIX!}_countries` WHERE id=%s LIMIT 1",
108 array(bigintval($id)), __FILE__, __LINE__);
109 if (SQL_NUMROWS($result) == 1) {
111 list($code, $descr) = SQL_FETCHROW($result);
112 SQL_FREERESULT($result);
114 // Prepare data, load row template and switch colors
122 if ($post == "modify") {
123 // Generate default selection in edit-mode
124 $content['status'] = ADD_OPTION_LINES("/ARRAY/", array("Y","N"), array(YES, NO ), $status);
126 // Only display status when in delete-mode
127 $content['status'] = TRANSLATE_YESNO($status);
130 // Insert row template and switch color
131 $OUT .= LOAD_TEMPLATE($row, true, $content);
135 define('__COUNTRY_ROWS' , $OUT);
136 define('__COUNTRY_MODE' , $post);
137 define('__COUNTRY_CLASS' , $class);
138 define('__COUNTRY_SUBMIT', $submit);
139 define('__COUNTRY_TITLE' , $title);
140 define('__COUNTRY_RESET' , $reset);
142 // Load main template
143 LOAD_TEMPLATE("admin_list_country_form");
146 // Shall we modify / remove entries now?
147 $MSG = ""; INIT_SQLS();
148 if ((REQUEST_ISSET_POST(('modify'))) && (REQUEST_ISSET_POST(('id')))) {
150 foreach (REQUEST_POST('id') as $id => $sel) {
151 ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_countries` SET code='".REQUEST_POST('code', $id)."', descr='".REQUEST_POST('descr', $id)."', is_active='".REQUEST_POST('is_active', $id)."' WHERE id='".$id."' LIMIT 1");
155 $MSG = getMessage('ADMIN_COUNTRIES_MODIFIED');
156 } elseif ((REQUEST_ISSET_POST(('remove'))) && (REQUEST_ISSET_POST(('id')))) {
158 $IDs = implode(",", array_keys(REQUEST_POST('id')));
159 ADD_SQL("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_countries` WHERE id IN (".$IDs.") LIMIT ".count(REQUEST_POST('id'))."");
162 $MSG = getMessage('ADMIN_COUNTRIES_REMOVED');
165 if ((!empty($MSG)) && (COUNT_SQLS() > 0)) {
167 runFilterChain('run_sqls');
170 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
173 // Load currenty setup country codes to list
174 $result = SQL_QUERY("SELECT id, code, descr, is_active FROM `{!_MYSQL_PREFIX!}_countries` ORDER BY code", __FILE__, __LINE__);
175 if (SQL_NUMROWS($result) > 0) {
176 // List all countries
178 while ($content = SQL_FETCHARRAY($result)) {
179 // Prepare array for the template
180 // @TODO Rewritings: name->descr,status->is_active in template
182 'id' => $content['id'],
183 'code' => $content['code'],
184 'name' => $content['descr'],
185 'active' => TRANSLATE_YESNO($content['is_active']),
187 'status' => $content['is_active'],
190 // Load row template and switch colors
191 $OUT .= LOAD_TEMPLATE("admin_list_country_row", true, $content);
196 SQL_FREERESULT($result);
198 // No code setup so far (not possible by this software! 'DE' for 'Deutschland' is default
199 $OUT = LOAD_TEMPLATE("admin_list_country_no_row", true);
202 // Add list to constant for the template
203 define('__COUNTRY_ROWS', $OUT);
205 // Include add template
206 define('__ADD_COUNTRY_FORM', LOAD_TEMPLATE("admin_add_country", true));
208 // Load main template
209 LOAD_TEMPLATE("admin_list_country");