Complete rewrite of and , wrapper functions added, see bug #101
[mailer.git] / inc / modules / admin / what-config_points.php
index 524ec68c71c51a9ea69c0f74a9866ddcb81f83f0..085393a3d5150737e4e3b28916cbf5d97eccfe0b 100644 (file)
@@ -44,61 +44,61 @@ ADD_DESCR("admin", __FILE__);
 $message = "";
 
 // Is the 'sub' parameter set?
-if (!empty($_GET['sub'])) {
+if (REQUEST_ISSET_GET(('sub'))) {
        // Yes, then do some sanity-checks
-       switch ($_GET['sub'])
+       switch (REQUEST_GET('sub'))
        {
        case "points":
-               if ((empty($_POST['points_register'])) || (empty($_POST['points_ref']))) {
-                       unset($_POST['ok']);
+               if ((!REQUEST_ISSET_POST(('points_register'))) || (!REQUEST_ISSET_POST(('points_ref')))) {
+                       REQUEST_UNSET_POST('ok');
                }
                break;
 
        case "ref":
-               if (isset($_GET['do'])) {
-                       if (((empty($_POST['lvl'])) || (empty($_POST['perc']))) && ($_GET['do'] == "add")) {
-                               unset($_POST['ok']);
+               if (REQUEST_ISSET_GET(('do'))) {
+                       if (((!REQUEST_ISSET_POST(('lvl'))) || (!REQUEST_ISSET_POST(('perc')))) && (REQUEST_GET('do') == "add")) {
+                               REQUEST_UNSET_POST('ok');
                        }
                }
                break;
        }
 } else {
        // Display overview
-       $_GET['sub'] = "overview";
+       REQUEST_SET_GET('sub', "overview");
 }
 
-if (isset($_POST['ok'])) {
+if (IS_FORM_SENT()) {
        $SQLs = array();
-       switch ($_GET['sub'])
+       switch (REQUEST_GET('sub'))
        {
        case "points":
-               $SQLs[] = "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='".REQUEST_POST('points_register')."', points_ref='".REQUEST_POST('points_ref')."' WHERE config=0 LIMIT 1";
                break;
 
        case "ref":
-               switch ($_GET['do'])
+               switch (REQUEST_GET('do'))
                {
                case "add":
-                       $SQLs[] = "INSERT INTO `{!_MYSQL_PREFIX!}_refdepths` (level, percents) VALUES ('".$_POST['lvl']."','".$_POST['perc']."')";
+                       $SQLs[] = "INSERT INTO `{!_MYSQL_PREFIX!}_refdepths` (level, percents) VALUES ('".REQUEST_POST('lvl')."','".REQUEST_POST('perc')."')";
                        break;
 
                case "edit": // Change entries
-                       foreach ($_POST['lvl'] as $id => $value) {
+                       foreach (REQUEST_POST('lvl') as $id => $value) {
                                // Secure ID
                                $id = bigintval($id);
 
                                // Revert german commata
-                               $_POST['perc'][$id] = REVERT_COMMA($_POST['perc'][$id]);
+                               REQUEST_POST('perc', $id) = REVERT_COMMA(REQUEST_POST('perc', $id));
 
                                // Update entry
                                SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_refdepths` SET level='%s', percents='%s' WHERE id=%s LIMIT 1",
-                                       array(bigintval($value), $_POST['perc'][$id], $id), __FILE__, __LINE__);
+                                       array(bigintval($value), REQUEST_POST('perc', $id), $id), __FILE__, __LINE__);
                        }
                        $message = REF_DEPTHS_SAVED;
                        break;
 
                case "del":
-                       foreach ($_POST['id'] as $id => $value) {
+                       foreach (REQUEST_POST('id') as $id => $value) {
                                SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_refdepths` WHERE id=%s LIMIT 1",
                                        array(bigintval($id)), __FILE__, __LINE__);
                        }
@@ -113,21 +113,21 @@ if (isset($_POST['ok'])) {
                break;
 
        case "settings":
-               $REF = bigintval($_POST['ref_payout']);
+               $REF = bigintval(REQUEST_POST('ref_payout'));
                $SQLs[] = sprintf("UPDATE `{!_MYSQL_PREFIX!}_config` SET
 allow_direct_pay='%s',
 reg_points_mode='%s',
 ref_payout='%s'
 WHERE config=0 LIMIT 1",
-                       $_POST['allow_direct_pay'],
-                       $_POST['reg_points_mode'],
+                       REQUEST_POST('allow_direct_pay'),
+                       REQUEST_POST('reg_points_mode'),
                        $REF
                );
-               if ((getConfig('ref_payout') == 0) && ($_POST['ref_payout'] > 0)) {
+               if ((getConfig('ref_payout') == 0) && (REQUEST_POST('ref_payout') > 0)) {
                        // Update account's ref_payout for "must-confirm"
                        $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)) {
+               } elseif ((getConfig('ref_payout') > 0) && (REQUEST_POST('ref_payout') == 0)) {
                        // Update account's ref_payout for "not-must-confirm"
                        $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";
@@ -139,7 +139,7 @@ WHERE mails_confirmed < %s", $REF, $REF);
        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(REQUEST_POST('lvl'))), __FILE__, __LINE__);
                        SQL_FREERESULT($result);
                } // END - if
 
@@ -166,7 +166,7 @@ WHERE mails_confirmed < %s", $REF, $REF);
                // When do so...
                LOAD_TEMPLATE("admin_settings_saved", false, $message);
        }
-} elseif ($_GET['sub'] == "settings") {
+} elseif (REQUEST_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')) {
@@ -192,11 +192,11 @@ WHERE mails_confirmed < %s", $REF, $REF);
 
        // Load template
        LOAD_TEMPLATE("admin_config_point_settings");
-} elseif ($_GET['sub'] == "ref") {
-       if ((isset($_POST['del'])) && (isset($_POST['sel'])) && ((SELECTION_COUNT($_POST['sel']) > 0) || (isset($_POST['sel'][0])))) {
+} elseif (REQUEST_GET('sub') == "ref") {
+       if ((REQUEST_ISSET_POST(('del'))) && (REQUEST_ISSET_POST(('sel'))) && ((SELECTION_COUNT(REQUEST_POST('sel')) > 0) || (REQUEST_ISSET_POST(('sel', 0))))) {
                // Delete entries
                $SW = 2; $OUT = "";
-               foreach ($_POST['sel'] as $id => $value) {
+               foreach (REQUEST_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);
@@ -218,10 +218,10 @@ WHERE mails_confirmed < %s", $REF, $REF);
 
                // Load main template
                LOAD_TEMPLATE("admin_points_del");
-       } elseif ((isset($_POST['edit'])) && (isset($_POST['sel'])) && ((SELECTION_COUNT($_POST['sel']) > 0) || (isset($_POST['sel'][0])))) {
+       } elseif ((REQUEST_ISSET_POST(('edit'))) && (REQUEST_ISSET_POST(('sel'))) && ((SELECTION_COUNT(REQUEST_POST('sel')) > 0) || (REQUEST_ISSET_POST(('sel', 0))))) {
                // Edit entries
                $SW = 2; $OUT = "";
-               foreach ($_POST['sel'] as $id => $value) {
+               foreach (REQUEST_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);
@@ -276,7 +276,7 @@ WHERE mails_confirmed < %s", $REF, $REF);
                // Form for adding new referal levels
                LOAD_TEMPLATE("admin_add_reflvl");
        }
-} elseif ($_GET['sub'] == "points") {
+} elseif (REQUEST_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'));