Naming convention applied, rewritten to use filter
authorRoland Häder <roland@mxchange.org>
Fri, 19 Dec 2008 22:17:21 +0000 (22:17 +0000)
committerRoland Häder <roland@mxchange.org>
Fri, 19 Dec 2008 22:17:21 +0000 (22:17 +0000)
inc/databases.php
inc/modules/admin/what-config_points.php
inc/modules/admin/what-edit_emails.php
inc/modules/admin/what-payments.php

index 77692d4..75bf0cd 100644 (file)
@@ -115,7 +115,7 @@ define('USAGE_BASE', "usage");
 define('SERVER_URL', "http://www.mxchange.org");
 
 // Current SVN revision
-define('CURR_SVN_REVISION', "685");
+define('CURR_SVN_REVISION', "686");
 
 // Take a prime number which is long (if you know a longer one please try it out!)
 define('_PRIME', 591623);
index bbd75cd..9af8f84 100644 (file)
@@ -63,18 +63,18 @@ if (!empty($_GET['sub'])) {
 }
 
 if (isset($_POST['ok'])) {
-       $SQL = array();
+       $SQLs = array();
        switch ($_GET['sub'])
        {
        case "points":
-               $SQL[] = "UPDATE `"._MYSQL_PREFIX."_config` SET points_register='".$_POST['points_register']."', points_ref='".$_POST['points_ref']."' WHERE config=0 LIMIT 1";
+               $SQLs[] = "UPDATE `"._MYSQL_PREFIX."_config` SET points_register='".$_POST['points_register']."', points_ref='".$_POST['points_ref']."' WHERE config=0 LIMIT 1";
                break;
 
        case "ref":
                switch ($_GET['do'])
                {
                case "add":
-                       $SQL[] = "INSERT INTO "._MYSQL_PREFIX."_refdepths (level, percents) VALUES ('".$_POST['lvl']."','".$_POST['perc']."')";
+                       $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_refdepths (level, percents) VALUES ('".$_POST['lvl']."','".$_POST['perc']."')";
                        break;
 
                case "edit": // Change entries
@@ -109,7 +109,7 @@ if (isset($_POST['ok'])) {
 
        case "settings":
                $REF = bigintval($_POST['ref_payout']);
-               $SQL[] = sprintf("UPDATE `"._MYSQL_PREFIX."_config` SET
+               $SQLs[] = sprintf("UPDATE `"._MYSQL_PREFIX."_config` SET
 allow_direct_pay='%s',
 reg_points_mode='%s',
 ref_payout='%s'
@@ -121,57 +121,46 @@ WHERE config=0 LIMIT 1",
                if ((getConfig('ref_payout') == 0) && ($_POST['ref_payout'] > 0))
                {
                        // Update account's ref_payout for "must-confirm"
-                       $SQL[] = sprintf("UPDATE `"._MYSQL_PREFIX."_user_data` SET ref_payout=(%s - mails_confirmed)
+                       $SQLs[] = sprintf("UPDATE `"._MYSQL_PREFIX."_user_data` SET ref_payout=(%s - mails_confirmed)
 WHERE mails_confirmed < %s", $REF, $REF);
                }
                 elseif ((getConfig('ref_payout') > 0) && ($_POST['ref_payout'] == 0))
                {
                        // Update account's ref_payout for "not-must-confirm"
-                       $SQL[] = "UPDATE `"._MYSQL_PREFIX."_user_data` SET ref_payout=0 WHERE ref_payout > 0";
-                       $SQL[] = "UPDATE "._MYSQL_PREFIX."_user_points SET points=points+locked_points WHERE locked_points>0";
-                       $SQL[] = "UPDATE "._MYSQL_PREFIX."_user_points SET locked_points=0 WHERE locked_points>0";
+                       $SQLs[] = "UPDATE `"._MYSQL_PREFIX."_user_data` SET ref_payout=0 WHERE ref_payout > 0";
+                       $SQLs[] = "UPDATE "._MYSQL_PREFIX."_user_points SET points=points+locked_points WHERE locked_points>0";
+                       $SQLs[] = "UPDATE "._MYSQL_PREFIX."_user_points SET locked_points=0 WHERE locked_points>0";
                }
                break;
        }
-       if ((isset($SQL)) && (is_array($SQL)) && (!empty($SQL[0])))
-       {
-               if (strpos($SQL[0], "INSERT") > -1)
+
+       if ((isset($SQLs)) && (is_array($SQLs)) && (!empty($SQLs[0]))) {
+               if (strpos($SQLs[0], "INSERT") > -1)
                {
                        $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_refdepths WHERE level='%s' LIMIT 1",
-                        array(bigintval($_POST['lvl'])), __FILE__, __LINE__);
+                               array(bigintval($_POST['lvl'])), __FILE__, __LINE__);
                        SQL_FREERESULT($result);
                }
-               if (count($SQL) > 0)
-               {
+               if (count($SQLs) > 0) {
                        // Run all SQL commands
-                       foreach ($SQL as $s)
-                       {
-                               $result = SQL_QUERY($s, __FILE__, __LINE__);
-                       }
+                       RUN_FILTER('run_sqls', array('dry_run' => false, 'sqls' => $SQLs));
 
                        $content = "<SPAN class=\"admin_done\">".SETTINGS_SAVED."</SPAN>";
 
                        // Destroy config cache file here...
                        REBUILD_CACHE("config", "config");
-               }
-                else
-               {
+               } else {
                        $content = "<SPAN class=\"admin_failed\">".SETTINGS_NOT_SAVED."</SPAN>";
                }
-               unset($SQL);
+               unset($SQLs);
                LOAD_TEMPLATE("admin_settings_saved", false, $content);
-       }
-        elseif (isset($TEXT))
-       {
+       } elseif (isset($TEXT)) {
                LOAD_TEMPLATE("admin_settings_saved", false, $TEXT);
        }
-}
- elseif ($_GET['sub'] == "settings")
-{
+} elseif ($_GET['sub'] == "settings") {
        // Setup some settings like direct pay and so on
        // Including new add-mode for one-time referal bonus
-       switch (getConfig('allow_direct_pay'))
-       {
+       switch (getConfig('allow_direct_pay')) {
        case "Y":
                define('__DIRECT_Y', " checked=\"checked\"");
                define('__DIRECT_N', "");
@@ -184,8 +173,7 @@ WHERE mails_confirmed < %s", $REF, $REF);
        }
 
        // One-time referal bonus add-mode
-       switch (getConfig('reg_points_mode'))
-       {
+       switch (getConfig('reg_points_mode')) {
                case "ref"   : define('__MODE_REF', " checked=\"checked\""); define('__MODE_DIRECT', "");         break;
                case "direct": define('__MODE_REF', "");         define('__MODE_DIRECT', " checked=\"checked\""); break;
        }
@@ -195,17 +183,13 @@ WHERE mails_confirmed < %s", $REF, $REF);
 
        // Load template
        LOAD_TEMPLATE("admin_config_point_settings");
-}
- elseif ($_GET['sub'] == "ref")
-{
-        if ((isset($_POST['del'])) && ((SELECTION_COUNT($_POST['sel']) > 0) || (isset($_POST['sel'][0]))))
-       {
+} elseif ($_GET['sub'] == "ref") {
+       if ((isset($_POST['del'])) && ((SELECTION_COUNT($_POST['sel']) > 0) || (isset($_POST['sel'][0])))) {
                // Delete entries
                $SW = 2; $OUT = "";
-               foreach ($_POST['sel'] as $id => $value)
-               {
+               foreach ($_POST['sel'] as $id => $value) {
                        $result = SQL_QUERY_ESC("SELECT level, percents FROM "._MYSQL_PREFIX."_refdepths WHERE id=%s LIMIT 1",
-                        array(bigintval($id)), __FILE__, __LINE__);
+                               array(bigintval($id)), __FILE__, __LINE__);
                        list($lvl, $perc) = SQL_FETCHROW($result);
                        SQL_FREERESULT($result);
 
@@ -225,13 +209,10 @@ WHERE mails_confirmed < %s", $REF, $REF);
 
                // Load main template
                LOAD_TEMPLATE("admin_points_del");
-       }
-        elseif ((isset($_POST['edit'])) && ((SELECTION_COUNT($_POST['sel']) > 0) || (isset($_POST['sel'][0]))))
-       {
+       } elseif ((isset($_POST['edit'])) && ((SELECTION_COUNT($_POST['sel']) > 0) || (isset($_POST['sel'][0])))) {
                // Edit entries
                $SW = 2; $OUT = "";
-               foreach ($_POST['sel'] as $id => $value)
-               {
+               foreach ($_POST['sel'] as $id => $value) {
                        $result = SQL_QUERY_ESC("SELECT level, percents FROM "._MYSQL_PREFIX."_refdepths WHERE id=%s LIMIT 1",
                         array(bigintval($id)), __FILE__, __LINE__);
                        list($lvl, $perc) = SQL_FETCHROW($result);
@@ -253,19 +234,15 @@ WHERE mails_confirmed < %s", $REF, $REF);
 
                // Load main template
                LOAD_TEMPLATE("admin_points_edit");
-       }
-        else
-       {
+       } else {
                // Referal levels
                $result = SQL_QUERY("SELECT id, level, percents FROM "._MYSQL_PREFIX."_refdepths ORDER BY level", __FILE__, __LINE__);
-               if (SQL_NUMROWS($result) > 0)
-               {
+               if (SQL_NUMROWS($result) > 0) {
                        // Make referal levels editable and deletable
                        $SW = 2; $OUT = "";
 
                        // List already existing categories for editing
-                       while (list($id, $lvl, $perc) = SQL_FETCHROW($result))
-                       {
+                       while (list($id, $lvl, $perc) = SQL_FETCHROW($result)) {
                                // Prepare data for the row template
                                $content = array(
                                        'sw'  => $SW,
@@ -290,18 +267,14 @@ WHERE mails_confirmed < %s", $REF, $REF);
                // Form for adding new referal levels
                LOAD_TEMPLATE("admin_add_reflvl");
        }
-}
- elseif ($_GET['sub'] == "points")
-{
+} elseif ($_GET['sub'] == "points") {
        // First points for registration and other fixed points including new add-mode for one-time referal bonus...
        define('P_REG_VALUE', getConfig('points_register'));
        define('P_REF_VALUE', getConfig('points_ref'));
 
        // Load templates
        LOAD_TEMPLATE("admin_config_sub_points");
-}
- else
-{
+} else {
        // Display selection box
        LOAD_TEMPLATE("admin_config_points");
 }
index 5505cda..9c8359b 100644 (file)
@@ -45,10 +45,8 @@ if ((isset($_POST['ok'])) && (empty($_POST['id']))) {
 }
 
 $result = SQL_QUERY("SELECT id, sender, subject, payment_id, cat_id FROM "._MYSQL_PREFIX."_pool ORDER BY timestamp", __FILE__, __LINE__);
-if (SQL_NUMROWS($result) > 0)
-{
-       if (isset($_POST['ok']))
-       {
+if (SQL_NUMROWS($result) > 0) {
+       if (isset($_POST['ok'])) {
                // Make mail editable...
                $result = SQL_QUERY_ESC("SELECT subject, text, url FROM "._MYSQL_PREFIX."_pool WHERE id=%s LIMIT 1",
                 array(bigintval($_POST['id'])), __FILE__, __LINE__);
@@ -61,13 +59,9 @@ if (SQL_NUMROWS($result) > 0)
 
                // Load template
                LOAD_TEMPLATE("admin_edit_email");
-       }
-        elseif (!empty($_POST['save']))
-       {
+       } elseif (!empty($_POST['save'])) {
                // Save changes
-               if (!empty($SQL))
-               {
-                       SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET
+               SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET
 subject='%s',
 text='%s',
 url='%s'
@@ -78,29 +72,19 @@ WHERE id=%s LIMIT 1",
        $_POST['url'],
        bigintval($_POST['id']),
 ), __FILE__, __LINE__);
-                       if (SQL_AFFECTEDROWS() == 1)
-                       {
+
+               if (SQL_AFFECTEDROWS() == 1) {
                                $content = "<SPAN class=\"admin_done\">".SETTINGS_SAVED."</SPAN>";
-                       }
-                        else
-                       {
-                               $content = "<SPAN class=\"admin_failed\">".SETTINGS_NOT_SAVED."</SPAN>";
-                       }
-               }
-                else
-               {
+               } else {
                        $content = "<SPAN class=\"admin_failed\">".SETTINGS_NOT_SAVED."</SPAN>";
                }
 
                // Display message
                LOAD_TEMPLATE("admin_settings_saved", false, $content);
-       }
-        else
-       {
+       } else {
                // There are mail orders available
                $SW = 2; $OUT = "";
-               while (list($id, $sender, $subj, $pay, $cat) = SQL_FETCHROW($result))
-               {
+               while (list($id, $sender, $subj, $pay, $cat) = SQL_FETCHROW($result)) {
                        // Prepare data for the row template
                        $content = array(
                                'sw'   => $SW,
index b78d8b9..d6b4f9d 100644 (file)
@@ -36,83 +36,61 @@ if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
        require($INC);
 }
+
 // Add description as navigation point
 ADD_DESCR("admin", __FILE__);
 
 if (empty($_GET['do'])) unset($_GET['do']);
-if (((empty($_POST['t_wait'])) || (empty($_POST['payment']))) && (!empty($_GET['do'])) && ($_GET['do'] == "add"))
-{
+
+if (((empty($_POST['t_wait'])) || (empty($_POST['payment']))) && (!empty($_GET['do'])) && ($_GET['do'] == "add")) {
        unset($_POST['ok']);
 }
 
-if (isset($_POST['ok']))
-{
+if (isset($_POST['ok'])) {
        $SQL = array();
-       switch ($_GET['do'])
-       {
+       switch ($_GET['do']) {
        case "add":
-               $SQL[] = "INSERT INTO "._MYSQL_PREFIX."_payments (time, payment, mail_title, price) VALUES ('".$_POST['t_wait']."','".$_POST['payment']."','".$_POST['title']."','".$_POST['price']."')";
+               $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_payments (time, payment, mail_title, price) VALUES ('".$_POST['t_wait']."','".$_POST['payment']."','".$_POST['title']."','".$_POST['price']."')";
                $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_payments WHERE time='%s' LIMIT 1",
                 array($_POST['t_wait']), __FILE__, __LINE__);
-               if (SQL_NUMROWS($result) == 1)
-               {
+               if (SQL_NUMROWS($result) == 1) {
                        // Free memory
-                       $SQL[0] = "";
+                       $SQLs[0] = "";
                        SQL_FREERESULT($result);
                }
                break;
 
        case "edit":
-               foreach ($_POST['time'] as $id => $value)
-               {
-                       $SQL[] = "UPDATE "._MYSQL_PREFIX."_payments SET time='".$value."', payment='".$_POST['pay'][$id]."', price='".$_POST['price'][$id]."', mail_title='".$_POST['title'][$id]."' WHERE id='".$id."' LIMIT 1";
+               foreach ($_POST['time'] as $id => $value) {
+                       $SQLs[] = "UPDATE "._MYSQL_PREFIX."_payments SET time='".$value."', payment='".$_POST['pay'][$id]."', price='".$_POST['price'][$id]."', mail_title='".$_POST['title'][$id]."' WHERE id='".$id."' LIMIT 1";
                }
                break;
 
        case "del":
-               foreach ($_POST['id'] as $id => $value)
-               {
-                       $SQL[] = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_payments WHERE id='".$id."' LIMIT 1";
+               foreach ($_POST['id'] as $id => $value) {
+                       $SQLs[] = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_payments WHERE id='".$id."' LIMIT 1";
                }
                break;
        }
-       // Daten abspeichern
-       if ((count($SQL) > 0) || (!empty($SQL[0])))
-       {
-               foreach ($SQL as $s)
-               {
-                       if (!empty($s))
-                       {
-                               // Only run non-empty strings
-                               $result = SQL_QUERY(trim($s), __FILE__, __LINE__);
-                               if (empty($content))
-                               {
-                                       if (SQL_AFFECTEDROWS() == 1)
-                                       {
-                                               $content = "<SPAN class=\"admin_done\">".SETTINGS_SAVED."</SPAN>";
-                                       }
-                                        else
-                                       {
-                                               $content = "<SPAN class=\"admin_failed\">".SETTINGS_NOT_SAVED."</SPAN>";
-                                       }
-                               }
-                       }
-               }
-       }
-        else
-       {
+
+       // Save settings
+       if (count($SQLs) > 0) {
+               // Run all queries
+               RUN_FILTER('run_sqls', array('dry_run' => false, 'sqls' => $SQLs));
+               $content = "<SPAN class=\"admin_failed\">".SETTINGS_SAVED."</SPAN>";
+       } else {
+               // Nothing has changed!
                $content = "<SPAN class=\"admin_failed\">".SETTINGS_NOT_SAVED."</SPAN>";
        }
+
+       // Output template
        LOAD_TEMPLATE("admin_settings_saved", false, $content);
-}
- elseif ((isset($_POST['del'])) && (SELECTION_COUNT($_POST['sel']) > 0))
-{
+} elseif ((isset($_POST['del'])) && (SELECTION_COUNT($_POST['sel']) > 0)) {
        // Delete entries here
        $SW = 2; $OUT = "";
-       foreach ($_POST['sel'] as $id => $value)
-       {
+       foreach ($_POST['sel'] as $id => $value) {
                $result = SQL_QUERY_ESC("SELECT time, mail_title FROM "._MYSQL_PREFIX."_payments WHERE id=%s LIMIT 1",
-                array(bigintval($id)), __FILE__, __LINE__);
+                       array(bigintval($id)), __FILE__, __LINE__);
                list($time, $title) = SQL_FETCHROW($result);
                SQL_FREERESULT($result);
 
@@ -132,13 +110,10 @@ if (isset($_POST['ok']))
 
        // Load main template
        LOAD_TEMPLATE("admin_del_payments");
-}
- elseif ((isset($_POST['edit'])) && (SELECTION_COUNT($_POST['sel']) > 0))
-{
+} elseif ((isset($_POST['edit'])) && (SELECTION_COUNT($_POST['sel']) > 0)) {
        // Edit entries
        $SW = 2; $OUT = "";
-       foreach ($_POST['sel'] as $id => $value)
-       {
+       foreach ($_POST['sel'] as $id => $value) {
                $result = SQL_QUERY_ESC("SELECT time, payment, mail_title, price FROM "._MYSQL_PREFIX."_payments WHERE id=%s LIMIT 1",
                 array(bigintval($id)), __FILE__, __LINE__);
                list($time, $pay, $title, $price) = SQL_FETCHROW($result);
@@ -162,19 +137,15 @@ if (isset($_POST['ok']))
 
        // Load main template
        LOAD_TEMPLATE("admin_edit_payments");
-}
- else
-{
+} else {
        // Referal levels
        $result = SQL_QUERY("SELECT id, time, payment, mail_title, price FROM "._MYSQL_PREFIX."_payments ORDER BY time", __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) > 0)
-       {
+       if (SQL_NUMROWS($result) > 0) {
                // Make referal levels editable and deletable
                $SW = 2; $OUT = "";
 
                // List already existing categories for editing
-               while (list($id, $time, $pay, $title, $price) = SQL_FETCHROW($result))
-               {
+               while (list($id, $time, $pay, $title, $price) = SQL_FETCHROW($result)) {
                        $pay   = TRANSLATE_COMMA($pay);
                        $price = TRANSLATE_COMMA($price);