Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / admin / what-payments.php
index 66e61a4694183c71eeb47f01b1a899041abb0069..4dc746ee8a953ceaf6ce7d43f8ef7bdf7daece9d 100644 (file)
@@ -16,7 +16,7 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
+ * Copyright (c) 2009 - 2015 by Mailer Developer Team                   *
  * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -47,25 +47,55 @@ if (((!isPostRequestElementSet('t_wait')) || (!isPostRequestElementSet('payment'
        unsetPostRequestElement('ok');
 } // END - if
 
+// Init SQL array
+initSqls();
+
 if (isFormSent()) {
        switch (getRequestElement('do')) {
                case 'add':
-                       addSql("INSERT INTO `{?_MYSQL_PREFIX?}_payments` (`time`,`payment`,`mail_title`,`price`) VALUES ('".postRequestElement('t_wait')."','".postRequestElement('payment')."','".postRequestElement('title')."','".postRequestElement('price')."')");
-                       if (countSumTotalData(postRequestElement('t_wait'), 'payments', 'id', 'time', true) == 1) {
-                               // Re-init the array here
-                               initSqls();
+                       if (countSumTotalData(postRequestElement('t_wait'), 'payments', 'id', 'time', TRUE) == 0) {
+                               addSql("INSERT INTO
+       `{?_MYSQL_PREFIX?}_payments`
+(
+       `time`,
+       `payment`,
+       `mail_title`,
+       `price`
+) VALUES (
+       '" . postRequestElement('t_wait') . "',
+       '" . postRequestElement('payment') . "',
+       '" . postRequestElement('title') . "',
+       '" . postRequestElement('price') . "'
+)");
                        } // END - if
                        break;
 
                case 'edit':
                        foreach (postRequestElement('time') as $id => $value) {
-                               addSql("UPDATE `{?_MYSQL_PREFIX?}_payments` SET `time`='" . $value . "',`payment`='".postRequestElement('payment', $id)."', price='".postRequestElement('price', $id)."', mail_title='".postRequestElement('mail_title', $id)."' WHERE `id`='".$id."' LIMIT 1");
+                               // Secure id
+                               $id = bigintval($id);
+
+                               // Add UPDATE
+                               addSql("UPDATE
+       `{?_MYSQL_PREFIX?}_payments`
+SET
+       `time`='" . $value . "',
+       `payment`='" . postRequestElement('payment', $id) . "',
+       `price`='" . postRequestElement('price', $id) . "',
+       `mail_title`='" . postRequestElement('mail_title', $id) . "'
+WHERE
+       `id`='" . $id . "'
+LIMIT 1");
                        } // END - foreach
                        break;
 
                case 'delete':
                        foreach (postRequestElement('id') as $id => $value) {
-                               addSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=" . bigintval($id) . " LIMIT 1");
+                               // Secure id
+                               $id = bigintval($id);
+
+                               // Add DELETE
+                               addSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=" . $id . " LIMIT 1");
                        } // END - foreach
                        break;
        } // END - switch
@@ -91,54 +121,84 @@ if (isFormSent()) {
        // Delete entries here
        $OUT = '';
        foreach (postRequestElement('sel') as $id => $value) {
-               $result = SQL_QUERY_ESC("SELECT `id`,`time`,`mail_title` FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1",
+               $result = sqlQueryEscaped("SELECT
+       `id`,
+       `time`,
+       `payment`,
+       `mail_title`,
+       `price`
+FROM
+       `{?_MYSQL_PREFIX?}_payments`
+WHERE
+       `id`=%s
+LIMIT 1",
                        array(bigintval($id)), __FILE__, __LINE__);
-               $content = SQL_FETCHARRAY($result);
+               $content = sqlFetchArray($result);
 
                // Free result
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
 
                // Load row template and switch colors
-               $OUT .= loadTemplate('admin_delete_payments_row', true, $content);
+               $OUT .= loadTemplate('admin_delete_payments_row', TRUE, $content);
        } // END - foreach
 
        // Load main template
-       loadTemplate('admin_delete_payments', false, $OUT);
+       loadTemplate('admin_delete_payments', FALSE, $OUT);
 } elseif ((isFormSent('edit')) && (ifPostContainsSelections())) {
        // Edit entries
        $OUT = '';
        foreach (postRequestElement('sel') as $id => $value) {
-               $result = SQL_QUERY_ESC("SELECT `id`,`time`,`payment`,`mail_title`,`price` FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1",
+               $result = sqlQueryEscaped("SELECT
+       `id`,
+       `time`,
+       `payment`,
+       `mail_title`,
+       `price`
+FROM
+       `{?_MYSQL_PREFIX?}_payments`
+WHERE
+       `id`=%s
+LIMIT 1",
                        array(bigintval($id)), __FILE__, __LINE__);
-               $content = SQL_FETCHARRAY($result);
+               $content = sqlFetchArray($result);
 
                // Free result
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
 
                // Load row template and switch colors
-               $OUT .= loadTemplate('admin_edit_payments_row', true, $content);
+               $OUT .= loadTemplate('admin_edit_payments_row', TRUE, $content);
        } // END - foreach
 
        // Load main template
-       loadTemplate('admin_edit_payments', false, $OUT);
+       loadTemplate('admin_edit_payments', FALSE, $OUT);
 } else {
        // Referral levels
-       $result = SQL_QUERY("SELECT `id`,`time`,`payment`,`mail_title`,`price` FROM `{?_MYSQL_PREFIX?}_payments` ORDER BY `time` ASC", __FILE__, __LINE__);
-       if (!SQL_HASZERONUMS($result)) {
+       $result = sqlQuery("SELECT
+       `id`,
+       `time`,
+       `payment`,
+       `mail_title`,
+       `price`
+FROM
+       `{?_MYSQL_PREFIX?}_payments`
+ORDER BY
+       `time` ASC", __FILE__, __LINE__);
+
+       if (!ifSqlHasZeroNumRows($result)) {
                // Make referral levels editable and deletable
                $OUT = '';
 
                // List already existing categories for editing
-               while ($content = SQL_FETCHARRAY($result)) {
+               while ($content = sqlFetchArray($result)) {
                        // Load row template and switch colors
-                       $OUT .= loadTemplate('admin_list_payments_row', true, $content);
+                       $OUT .= loadTemplate('admin_list_payments_row', TRUE, $content);
                } // END - switch
 
                // Free memory
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
 
                // Load main template
-               loadTemplate('admin_list_payments', false, $OUT);
+               loadTemplate('admin_list_payments', FALSE, $OUT);
        } // END - if
 
        // Form for adding new referral levels