Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / admin / what-config_payouts.php
index 2f9885d10abd8f500762e189749b9e2bd40c4122..6517b412102c1f01ee689c42eb3e3f643b53b541 100644 (file)
@@ -16,8 +16,8 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
- * For more information visit: http://www.mxchange.org                  *
+ * 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 *
  * it under the terms of the GNU General Public License as published by *
@@ -43,183 +43,188 @@ if ((!defined('__SECURITY')) || (!isAdmin())) {
 // Add description as navigation point
 addYouAreHereLink('admin', __FILE__);
 
-if (isPostRequestParameterSet('rate')) setPostRequestParameter('rate', convertCommaToDot(postRequestParameter('rate')));
-
-if ((isFormSent('add')) && (isPostRequestParameterSet('title')) && (postRequestParameter('rate') > 0)) {
+// Do we add an entry?
+if ((isFormSent('add')) && (isPostRequestElementSet('title')) && (postRequestElement('rate') > 0)) {
        // Add new payout type
-       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE type='%s' LIMIT 1",
-       array(postRequestParameter('title')), __FILE__, __LINE__);
-       if (SQL_HASZERONUMS($result)) {
+       $result = sqlQueryEscaped("SELECT `id` FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE type='%s' LIMIT 1",
+               array(postRequestElement('title')), __FILE__, __LINE__);
+       if (ifSqlHasZeroNumRows($result)) {
                // Add now
-               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_payout_types`
-(`type`, `rate`, `min_points`, `from_account`, `from_pass`, `engine_url`, `engine_ret_ok`, `engine_ret_failed`, `pass_enc`, `allow_url`)
-VALUES ('%s', %s, %s,'%s','%s','%s','%s','%s','%s','%s')",
+               sqlQueryEscaped("INSERT INTO
+       `{?_MYSQL_PREFIX?}_payout_types`
+(
+       `type`, `rate`, `min_points`, `from_account`, `from_pass`, `engine_url`, `engine_ret_ok`, `engine_ret_failed`, `pass_enc`, `allow_url`
+) VALUES (
+       '%s', %s, %s,'%s','%s','%s','%s','%s','%s','%s'
+)",
                array(
-                       postRequestParameter('title'),
-                       bigintval(postRequestParameter('rate')),
-                       bigintval(postRequestParameter('min_points')),
-                       postRequestParameter('yacc'),
-                       postRequestParameter('ypass'),
-                       postRequestParameter('yurl'),
-                       postRequestParameter('yrdone'),
-                       postRequestParameter('yrfailed'),
-                       postRequestParameter('ytrans'),
-                       postRequestParameter('allow_url'),
+                       postRequestElement('title'),
+                       bigintval(postRequestElement('rate')),
+                       bigintval(postRequestElement('min_points')),
+                       postRequestElement('yacc'),
+                       postRequestElement('ypass'),
+                       postRequestElement('yurl'),
+                       postRequestElement('yrdone'),
+                       postRequestElement('yrfailed'),
+                       postRequestElement('ytrans'),
+                       postRequestElement('allow_url'),
                ), __FILE__, __LINE__);
 
                // Get message
                $message = '{--ADMIN_PAYOUT_TYPE_ADDED--}';
        } else {
                // Free memory
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
 
                // Does already exist
-               $message = '<div class="notice">{--ADMIN_PAYOUT_TYPE_ALREADY--}</div>';
+               $message = '<div class="bad">{--ADMIN_PAYOUT_TYPE_ALREADY--}</div>';
        }
 }
 
 // Payout requests by your members
-$result_mem = SQL_QUERY("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_payouts` WHERE `status`='NEW' ORDER BY payout_timestamp DESC", __FILE__, __LINE__);
+$result_mem = sqlQuery("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_payouts` WHERE `status`='NEW' ORDER BY payout_timestamp DESC", __FILE__, __LINE__);
 
-$display = true;
+$display = TRUE;
 if ((isFormSent('edit')) && (ifPostContainsSelections())) {
-       // Edit payout types
-       if ((isGetRequestParameterSet('ok')) && (getRequestParameter('ok') == 'ok')) {
-               // Init SQLs
-               initSqls();
-
-               // Edit entries
-               foreach (postRequestParameter('sel') as $id => $sel) {
-                       // Secure id
-                       $id = bigintval($id);
-
-                       // Edit only if something is entered
-                       if ((isPostRequestParameterSet('title', $id)) && (postRequestParameter('rate', $id) > 0)) {
-                               // Update entry
-                               addSql(SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_payout_types` SET
-       type='%s',
-       rate=%s,
-       min_points=%s,
-       allow_url='%s'
+       // Make payouts configurable
+       $display = FALSE; //Suppress any other outputs
+       $OUT = '';
+       foreach (postRequestElement('sel') as $id => $sel) {
+               // Load data
+               $result = sqlQueryEscaped("SELECT `id`, `type`, `rate`, `min_points`, `allow_url` FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE `id`=%s LIMIT 1",
+                       array(bigintval($id)), __FILE__, __LINE__);
+               $content = sqlFetchArray($result);
+               sqlFreeResult($result);
+
+               // Prepare data for the row template
+               $content['allow_url'] = addSelectionBox('yn', $content['allow_url'], 'allow_url[' . $content['id'] . ']');
+
+               // Load row template and switch color
+               $OUT .= loadTemplate('admin_edit_payouts_row', TRUE, $content);
+       } // END - foreach
+
+       // Load main template
+       loadTemplate('admin_edit_payouts', FALSE, $OUT);
+} elseif ((isFormSent('do_edit')) && (ifPostContainsSelections())) {
+       // Change them now
+       // Init SQLs
+       initSqls();
+
+       // Edit entries
+       foreach (postRequestElement('sel') as $id => $sel) {
+               // Secure id
+               $id = bigintval($id);
+
+               // Edit only if something is entered
+               if ((isPostRequestElementSet('type', $id)) && (postRequestElement('rate', $id) > 0)) {
+                       // Update entry
+                       addSql(sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_payout_types` SET
+       `type`='%s',
+       `rate`=%s,
+       `min_points`=%s,
+       `allow_url`='%s'
 WHERE
        `id`=%s
 LIMIT 1",
-                               array(
-                                       postRequestParameter('type', $id),
-                                       convertCommaToDot(postRequestParameter('rate', $id)),
-                                       convertCommaToDot(postRequestParameter('min_points' , $id)),
-                                       postRequestParameter('allow_url', $id),
-                                       bigintval($id)
-                               ),__FILE__, __LINE__, false));
-                       }
+                       array(
+                               postRequestElement('type', $id),
+                               convertCommaToDot(postRequestElement('rate', $id)),
+                               convertCommaToDot(postRequestElement('min_points' , $id)),
+                               postRequestElement('allow_url', $id),
+                               $id
+                       ),__FILE__, __LINE__, FALSE));
                }
+       }
 
-               // Run all SQLs
-               runFilterChain('run_sqls');
+       // Run all SQLs
+       runFilterChain('run_sqls');
 
-               // Get message
-               $message = '{--ADMIN_PAYOUT_ENTRIES_CHANGED--}';
-       } else {
-               $display = false; //Suppress any other outputs
-               $OUT = '';
-               foreach (postRequestParameter('sel') as $id => $sel) {
-                       // Load data
-                       $result = SQL_QUERY_ESC("SELECT `id`, `type`, `rate`, `min_points`, `allow_url` FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE `id`=%s LIMIT 1",
-                               array(bigintval($id)), __FILE__, __LINE__);
-                       $content = SQL_FETCHARRAY($result);
-                       SQL_FREERESULT($result);
-
-                       // Prepare data for the row template
-                       $content['allow_url'] = addSelectionBox('yn', $content['allow_url'], 'allow_url[' . $content['id'] . ']');
-
-                       // Load row template and switch color
-                       $OUT .= loadTemplate('admin_config_payouts_edit_row', true, $content);
-               } // END - foreach
-
-               // Load main template
-               loadTemplate('admin_config_payouts_edit', false, $OUT);
-       }
+       // Get message
+       $message = '{--ADMIN_PAYOUT_ENTRIES_CHANGED--}';
 } elseif ((isFormSent('delete')) && (ifPostContainsSelections())) {
-       // Delete payout types
-       if ((isGetRequestParameterSet('ok')) && (getRequestParameter('ok') == 'ok')) {
-               // Init SQLs
-               initSqls();
+       $display = FALSE; //Suppress any other outputs
+       $OUT = '';
+       foreach (postRequestElement('sel') as $id => $sel) {
+               // Secure id number
+               $id = bigintval($id);
 
-               // Delete entries
-               foreach (postRequestParameter('sel') as $id => $sel) {
-                       addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE `id`=%s LIMIT 1",
-                               array(bigintval($id)), __FILE__, __LINE__, false));
-               } // END - foreach
+               // Load data
+               $result = sqlQueryEscaped("SELECT `id`, `type`, `rate`, `min_points` FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE `id`=%s LIMIT 1",
+                       array($id), __FILE__, __LINE__);
+               $content = sqlFetchArray($result);
+               sqlFreeResult($result);
 
-               // Run all SQLs
-               runFilterChain('run_sqls');
+               // Load row template and switch color
+               $OUT .= loadTemplate('admin_delete_payouts_row', TRUE, $content);
+       } // END - foreach
 
-               // Get message
-               $message = '{--ADMIN_PAYOUT_ENTRIES_DELETED--}';
-       } else {
-               $display = false; //Suppress any other outputs
-               $OUT = '';
-               foreach (postRequestParameter('sel') as $id => $sel) {
-                       // Secure id number
-                       $id = bigintval($id);
-
-                       // Load data
-                       $result = SQL_QUERY_ESC("SELECT `id`, `type`, `rate`, `min_points` FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE `id`=%s LIMIT 1",
-                               array($id), __FILE__, __LINE__);
-                       $content = SQL_FETCHARRAY($result);
-                       SQL_FREERESULT($result);
-
-                       // Load row template and switch color
-                       $OUT .= loadTemplate('admin_config_payouts_del_row', true, $content);
-               } // END - foreach
-
-               // Load main template
-               loadTemplate('admin_config_payouts_del', false, $OUT);
-       }
+       // Load main template
+       loadTemplate('admin_delete_payouts', FALSE, $OUT);
+} elseif ((isFormSent('do_delete')) && (ifPostContainsSelections())) {
+       // Init SQLs
+       initSqls();
+
+       // Delete entries
+       foreach (postRequestElement('sel') as $id => $sel) {
+               addSql(sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE `id`=%s LIMIT 1",
+                       array(bigintval($id)), __FILE__, __LINE__, FALSE));
+       } // END - foreach
+
+       // Run all SQLs
+       runFilterChain('run_sqls');
+
+       // Get message
+       $message = '{--ADMIN_PAYOUT_ENTRIES_DELETED--}';
 }
 
 if (!empty($message)) {
        // Output message
-       loadTemplate('admin_settings_saved', false, $message);
+       displayMessage($message);
 } // END - if
 
 // Payout types
-$result_type = SQL_QUERY("SELECT
-       `id`, `type`, `rate`, `min_points`, `from_account`
+$result_type = sqlQuery('SELECT
+       `id`,
+       `type`,
+       `rate`,
+       `min_points`,
+       `from_account`
 FROM
        `{?_MYSQL_PREFIX?}_payout_types`
 ORDER BY
-       `type` ASC", __FILE__, __LINE__);
+       `type` ASC', __FILE__, __LINE__);
 
-if ((!SQL_HASZERONUMS($result_type)) && ($display)) {
+if ((!ifSqlHasZeroNumRows($result_type)) && ($display)) {
        // List all payout types
        $OUT = '';
-       while ($content = SQL_FETCHARRAY($result_type)) {
+       while ($content = sqlFetchArray($result_type)) {
                // Load row template and switch color
-               $OUT .= loadTemplate('admin_config_payouts_row', true, $content);
+               $OUT .= loadTemplate('admin_config_payouts_row', TRUE, $content);
        } // END - while
 
        // Free memory
-       SQL_FREERESULT($result_type);
+       sqlFreeResult($result_type);
 
        // Load main template
-       loadTemplate('admin_config_payouts', false, $OUT);
+       loadTemplate('admin_config_payouts', FALSE, $OUT);
 } // END - if
 
 // Does your members request payouts?
-if ((!SQL_HASZERONUMS($result_mem)) && ($display)) {
+if ((!ifSqlHasZeroNumRows($result_mem)) && ($display === TRUE)) {
        // Members has requested payouts
-       loadTemplate('admin_settings_saved', false, '<a href="{%url=modules.php?module=admin&amp;what=list_payouts%}">{--ADMIN_PAYOUT_LIST_REQUESTS--}</a>');
-} elseif ($display) {
+       displayMessage('<a href="{%url=modules.php?module=admin&amp;what=list_payouts%}">{--ADMIN_PAYOUT_LIST_REQUESTS--}</a>');
+} elseif ($display === TRUE) {
        // No member requests so far
-       loadTemplate('admin_settings_saved', false, '{--ADMIN_PAYOUT_NO_MEMBER_REQUESTS--}');
+       displayMessage('{--ADMIN_PAYOUT_NO_MEMBER_REQUESTS--}');
 }
 
 // Free result
-SQL_FREERESULT($result_mem);
+sqlFreeResult($result_mem);
 
 // Add new payout type
-if ($display === true) loadTemplate('admin_payout_add_new');
+if ($display === TRUE) {
+       loadTemplate('admin_add_payout');
+} // END - if
 
 // [EOF]
 ?>