2 /************************************************************************
\r
3 * MXChange v0.2.1 Start: 04/30/2005 *
\r
4 * ================ Last change: 04/30/2005 *
\r
6 * -------------------------------------------------------------------- *
\r
7 * File : what-list_country.php *
\r
8 * -------------------------------------------------------------------- *
\r
9 * Short description : Manage country codes *
\r
10 * -------------------------------------------------------------------- *
\r
11 * Kurzbeschreibung : Country codes verwalten *
\r
12 * -------------------------------------------------------------------- *
\r
14 * -------------------------------------------------------------------- *
\r
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
\r
16 * For more information visit: http://www.mxchange.org *
\r
18 * This program is free software; you can redistribute it and/or modify *
\r
19 * it under the terms of the GNU General Public License as published by *
\r
20 * the Free Software Foundation; either version 2 of the License, or *
\r
21 * (at your option) any later version. *
\r
23 * This program is distributed in the hope that it will be useful, *
\r
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
\r
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
\r
26 * GNU General Public License for more details. *
\r
28 * You should have received a copy of the GNU General Public License *
\r
29 * along with this program; if not, write to the Free Software *
\r
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
\r
31 * MA 02110-1301 USA *
\r
32 ************************************************************************/
\r
34 // Some security stuff...
\r
35 if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!is_admin()))
\r
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
\r
41 // Add description as navigation point
\r
42 ADD_DESCR("admin", basename(__FILE__));
\r
45 if ((isset($_POST['add'])) && (!empty($_POST['code'])) && (!empty($_POST['descr'])))
\r
47 // Check if country code does already exist
\r
48 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_countries WHERE code='%s' LIMIT 1",
\r
49 array(strtoupper($_POST['code'])), __FILE__, __LINE__);
\r
50 if (SQL_NUMROWS($result) == 0)
\r
53 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_countries (code, descr, is_active)
\r
54 VALUES('%s', '%s', '%s')",
\r
55 array(strtoupper(substr($_POST['code'], 0, 2)), $_POST['descr'], $_POST['is_active']), __FILE__, __LINE__);
\r
58 $MSG = ADMIN_COUNTRY_ADDED_1.strtoupper($_POST['descr']).ADMIN_COUNTRY_ADDED_2;
\r
63 SQL_FREERESULT($result);
\r
65 // Does already exist
\r
66 $MSG = ADMIN_COUNTRY_ALREADY_1.strtoupper($_POST['code']).ADMIN_COUNTRY_ALREADY_2;
\r
70 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
\r
71 OUTPUT_HTML("<BR>");
\r
74 elseif ((isset($_POST['change'])) && (!empty($_POST['id'])))
\r
76 // Change all status
\r
77 ADMIN_CHANGE_ACTIVATION_STATUS($_POST['id'], "countries", "is_active");
\r
79 // Edit / delete entries?
\r
80 elseif (((isset($_POST['edit'])) || (isset($_POST['delete']))) && (!empty($_POST['id'])))
\r
82 if (count($_POST['id']) > 0)
\r
84 if (isset($_POST['edit']))
\r
87 $row = "admin_list_country_edit_row";
\r
89 $class = "admin_submit";
\r
90 $submit = ADMIN_COUNTRY_EDIT_NOW;
\r
91 $title = ADMIN_COUNTRY_EDIT_TITLE;
\r
92 $reset = "<INPUT type=\"reset\" class=\"admin_reset\" value=\"".UNDO_SELECTIONS."\"> *\n";
\r
97 $row = "admin_list_country_del_row";
\r
99 $class = "admin_delete";
\r
100 $submit = ADMIN_COUNTRY_DELETE_NOW;
\r
101 $title = ADMIN_COUNTRY_DELETE_TITLE;
\r
105 // Edit all selected country codes
\r
106 $OUT = ""; $SW = 2;
\r
107 foreach ($_POST['id'] as $id=>$status)
\r
109 // Load data from DB
\r
110 $result = SQL_QUERY_ESC("SELECT code, descr FROM "._MYSQL_PREFIX."_countries WHERE id=%d LIMIT 1",
\r
111 array(bigintval($id)), __FILE__, __LINE__);
\r
112 if (SQL_NUMROWS($result) == 1)
\r
115 list($code, $descr) = SQL_FETCHROW($result);
\r
116 SQL_FREERESULT($result);
\r
118 // Prepare data, load row template and switch colors
\r
125 if ($post == "modify")
\r
127 // Generate default selection in edit-mode
\r
128 $content['status'] = ADD_OPTION_LINES("/ARRAY/", array('Y', 'N'), array(YES, NO ), $status);
\r
132 // Only display status when in delete-mode
\r
133 $content['status'] = TRANSLATE_YESNO($status);
\r
135 $OUT .= LOAD_TEMPLATE($row, true, $content);
\r
139 define('__COUNTRY_ROWS' , $OUT);
\r
140 define('__COUNTRY_MODE' , $post);
\r
141 define('__COUNTRY_CLASS' , $class);
\r
142 define('__COUNTRY_SUBMIT', $submit);
\r
143 define('__COUNTRY_TITLE' , $title);
\r
144 define('__COUNTRY_RESET' , $reset);
\r
146 // Load main template
\r
147 LOAD_TEMPLATE("admin_list_country_form");
\r
152 // Shall we modify / remove entries now?
\r
153 $MSG = ""; $SQLs = array();
\r
154 if ((isset($_POST['modify'])) && (!empty($_POST['id'])))
\r
157 foreach ($_POST['id'] as $id=>$sel)
\r
159 $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";
\r
163 $MSG = ADMIN_COUNTRIES_MODIFIED;
\r
165 elseif ((isset($_POST['remove'])) && (!empty($_POST['id'])))
\r
168 $IDs = implode(", ", bigintval($_POST['id']));
\r
169 $SQLs[] = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_countries WHERE id IN (".$IDs.") LIMIT ".count($_POST['id'])."";
\r
172 $MSG = ADMIN_COUNTRIES_REMOVED;
\r
175 if ((!empty($MSG)) && (count($SQLs) > 0))
\r
177 // Run SQL commands
\r
178 foreach ($SQLs as $sql)
\r
180 $result = SQL_QUERY($sql, __FILE__, __LINE__);
\r
184 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
\r
185 OUTPUT_HTML("<BR>");
\r
188 // Load currenty setup country codes to list
\r
189 $result = SQL_QUERY("SELECT id, code, descr, is_active FROM "._MYSQL_PREFIX."_countries ORDER BY code", __FILE__, __LINE__);
\r
190 if (SQL_NUMROWS($result) > 0)
\r
192 // List all countries
\r
193 $OUT = ""; $SW = 2;
\r
194 while(list($id, $code, $descr, $active) = SQL_FETCHROW($result))
\r
196 // Prepare array for the template
\r
201 'active' => TRANSLATE_YESNO($active),
\r
203 'status' => $active,
\r
206 // Load row template and switch colors
\r
207 $OUT .= LOAD_TEMPLATE("admin_list_country_row", true, $content);
\r
212 SQL_FREERESULT($result);
\r
216 // No code setup so far (not possible by this software! 'DE' for 'Deutschland' is default
\r
217 $OUT = LOAD_TEMPLATE("admin_list_country_no_row", true);
\r
220 // Add list to constant for the template
\r
221 define('__COUNTRY_ROWS', $OUT);
\r
223 // Include add template
\r
224 define('__ADD_COUNTRY_FORM', LOAD_TEMPLATE("admin_add_country", true));
\r
226 // Load main template
\r
227 LOAD_TEMPLATE("admin_list_country");
\r