Fixes for a lot bug tickets. (Sorry for lame comment)
[mailer.git] / inc / modules / admin / what-list_country.php
index 70ea85152ecca172d897b47a6783deb8f6c9782f..776b59948df438839d6a06e0080ee8f4ef698c4f 100644 (file)
@@ -41,22 +41,18 @@ if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
 ADD_DESCR("admin", __FILE__);
 
 // Add new code?
-if ((isset($_POST['add'])) && (!empty($_POST['code'])) && (!empty($_POST['descr'])))
-{
+if ((isset($_POST['add'])) && (!empty($_POST['code'])) && (!empty($_POST['descr']))) {
        // Check if country code does already exist
        $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_countries WHERE code='%s' LIMIT 1",
         array(strtoupper($_POST['code'])), __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) == 0)
-       {
+       if (SQL_NUMROWS($result) == 0) {
                // Save entry
                SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_countries (code, descr, is_active) VALUES ('%s','%s','%s')",
  array(strtoupper(substr($_POST['code'], 0, 2)), $_POST['descr'], $_POST['is_active']), __FILE__, __LINE__);
 
                // Country added
                $MSG = ADMIN_COUNTRY_ADDED_1.strtoupper($_POST['descr']).ADMIN_COUNTRY_ADDED_2;
-       }
-        else
-       {
+       } else {
                // Free memory
                SQL_FREERESULT($result);
 
@@ -67,20 +63,12 @@ if ((isset($_POST['add'])) && (!empty($_POST['code'])) && (!empty($_POST['descr'
        // Display message
        LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
        OUTPUT_HTML("<br />");
-}
-// Change status?
- elseif ((isset($_POST['change'])) && (!empty($_POST['id'])))
-{
+} elseif ((isset($_POST['change'])) && (!empty($_POST['id']))) {
        // Change all status
        ADMIN_CHANGE_ACTIVATION_STATUS($_POST['id'], "countries", "is_active");
-}
-// Edit / delete entries?
- elseif (((isset($_POST['edit'])) || (isset($_POST['delete']))) && (!empty($_POST['id'])))
-{
-       if (count($_POST['id']) > 0)
-       {
-               if (isset($_POST['edit']))
-               {
+} elseif (((isset($_POST['edit'])) || (isset($_POST['delete']))) && (!empty($_POST['id']))) {
+       if (count($_POST['id']) > 0) {
+               if (isset($_POST['edit'])) {
                        // Edit template
                        $row    = "admin_list_country_edit_row";
                        $post   = "modify";
@@ -88,9 +76,7 @@ if ((isset($_POST['add'])) && (!empty($_POST['code'])) && (!empty($_POST['descr'
                        $submit = ADMIN_COUNTRY_EDIT_NOW;
                        $title  = ADMIN_COUNTRY_EDIT_TITLE;
                        $reset  = "<INPUT type=\"reset\" class=\"admin_reset\" value=\"".UNDO_SELECTIONS."\">&nbsp;*\n";
-               }
-                else
-               {
+               } else {
                        // Delete template
                        $row    = "admin_list_country_del_row";
                        $post   = "remove";
@@ -102,13 +88,11 @@ if ((isset($_POST['add'])) && (!empty($_POST['code'])) && (!empty($_POST['descr'
 
                // Edit all selected country codes
                $OUT = ""; $SW = 2;
-               foreach ($_POST['id'] as $id => $status)
-               {
+               foreach ($_POST['id'] as $id => $status) {
                        // Load data from DB
                        $result = SQL_QUERY_ESC("SELECT code, descr FROM "._MYSQL_PREFIX."_countries WHERE id=%s LIMIT 1",
-                        array(bigintval($id)), __FILE__, __LINE__);
-                       if (SQL_NUMROWS($result) == 1)
-                       {
+                               array(bigintval($id)), __FILE__, __LINE__);
+                       if (SQL_NUMROWS($result) == 1) {
                                // Load data
                                list($code, $descr) = SQL_FETCHROW($result);
                                SQL_FREERESULT($result);
@@ -120,16 +104,16 @@ if ((isset($_POST['add'])) && (!empty($_POST['code'])) && (!empty($_POST['descr'
                                        'descr' => $descr,
                                        'sw'    => $SW,
                                );
-                               if ($post == "modify")
-                               {
+
+                               if ($post == "modify") {
                                        // Generate default selection in edit-mode
                                        $content['status'] = ADD_OPTION_LINES("/ARRAY/", array("Y","N"), array(YES, NO ), $status);
-                               }
-                                else
-                               {
+                               } else {
                                        // Only display status when in delete-mode
                                        $content['status'] = TRANSLATE_YESNO($status);
                                }
+
+                               // Insert row template and switch color
                                $OUT .= LOAD_TEMPLATE($row, true, $content);
                                $SW = 3 - $SW;
                        }
@@ -144,37 +128,29 @@ if ((isset($_POST['add'])) && (!empty($_POST['code'])) && (!empty($_POST['descr'
                // Load main template
                LOAD_TEMPLATE("admin_list_country_form");
        }
-}
- else
-{
+} else {
        // Shall we modify / remove entries now?
        $MSG = ""; $SQLs = array();
-       if ((isset($_POST['modify'])) && (!empty($_POST['id'])))
-       {
+       if ((isset($_POST['modify'])) && (!empty($_POST['id']))) {
                // Modify
-               foreach ($_POST['id'] as $id => $sel)
-               {
+               foreach ($_POST['id'] as $id => $sel) {
                        $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";
                }
 
                // Create message
                $MSG = ADMIN_COUNTRIES_MODIFIED;
-       }
-        elseif ((isset($_POST['remove'])) && (!empty($_POST['id'])))
-       {
+       } elseif ((isset($_POST['remove'])) && (!empty($_POST['id']))) {
                // Remove
-               $IDs = implode(", ", bigintval($_POST['id']));
+               $IDs = implode(", ", $_POST['id']);
                $SQLs[] = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_countries WHERE id IN (".$IDs.") LIMIT ".count($_POST['id'])."";
 
                // Create message
                $MSG = ADMIN_COUNTRIES_REMOVED;
        }
 
-       if ((!empty($MSG)) && (count($SQLs) > 0))
-       {
+       if ((!empty($MSG)) && (count($SQLs) > 0)) {
                // Run SQL commands
-               foreach ($SQLs as $sql)
-               {
+               foreach ($SQLs as $sql) {
                        $result = SQL_QUERY($sql, __FILE__, __LINE__);
                }
 
@@ -185,12 +161,10 @@ if ((isset($_POST['add'])) && (!empty($_POST['code'])) && (!empty($_POST['descr'
 
        // Load currenty setup country codes to list
        $result = SQL_QUERY("SELECT id, code, descr, is_active FROM "._MYSQL_PREFIX."_countries ORDER BY code", __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) > 0)
-       {
+       if (SQL_NUMROWS($result) > 0) {
                // List all countries
                $OUT = ""; $SW = 2;
-               while(list($id, $code, $descr, $active) = SQL_FETCHROW($result))
-               {
+               while(list($id, $code, $descr, $active) = SQL_FETCHROW($result)) {
                        // Prepare array for the template
                        $content = array(
                                'id'     => $id,
@@ -208,9 +182,7 @@ if ((isset($_POST['add'])) && (!empty($_POST['code'])) && (!empty($_POST['descr'
 
                // Free memory
                SQL_FREERESULT($result);
-       }
-        else
-       {
+       } else {
                // No code setup so far (not possible by this software! 'DE' for 'Deutschland' is default
                $OUT = LOAD_TEMPLATE("admin_list_country_no_row", true);
        }