Naming convention applied, rewritten to use filter
[mailer.git] / inc / modules / admin / what-config_points.php
index bbd75cdddd23d4da49a7f806ba136ba78616eb62..9af8f84fb0f098d961f4e996ea61f65bf870f721 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");
 }