A lot double-quotes rewritten to single-quotes, some redirect URLs fixed
[mailer.git] / inc / modules / admin / what-config_points.php
index f3ae527583d29818a6a15834425892e53e6af6e1..a13f1cdd2036cf63b9cfeb4922ce462657830152 100644 (file)
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Einstellen der Willkommensgutschrift usw.        *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
+ * Needs to be in all Files and every File needs "svn propset           *
+ * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
  * For more information visit: http://www.mxchange.org                  *
  ************************************************************************/
 
 // Some security stuff...
-if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN())) {
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
+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", basename(__FILE__));
+ADD_DESCR('admin', __FILE__);
+
+// Init variables
+$message = '';
 
-if (!empty($_GET['sub']))
-{
-       switch ($_GET['sub'])
+// Is the 'sub' parameter set?
+if (REQUEST_ISSET_GET('sub')) {
+       // Yes, then do some sanity-checks
+       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
-{
+} else {
        // Display overview
-       $_GET['sub'] = "overview";
+       REQUEST_SET_GET('sub', "overview");
 }
 
-if (isset($_POST['ok']))
-{
-       $SQL = array();
-       switch ($_GET['sub'])
+if (IS_FORM_SENT()) {
+       INIT_SQLS();
+       switch (REQUEST_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";
+               ADD_SQL("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":
-                       $SQL[] = "INSERT INTO "._MYSQL_PREFIX."_refdepths (level, percents) VALUES ('".$_POST['lvl']."', '".$_POST['perc']."')";
+               case 'add':
+                       ADD_SQL("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
+                               REQUEST_SET_POST(array('perc', $id), REVERT_COMMA(REQUEST_POST('perc', $id)));
+
                                // Update entry
-                               $result = 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__);
+                               SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_refdepths` SET level='%s', percents='%s' WHERE id=%s LIMIT 1",
+                                       array(bigintval($value), REQUEST_POST('perc', $id), $id), __FILE__, __LINE__);
                        }
-                       $TEXT = REF_DEPTHS_SAVED;
+                       $message = getMessage('REF_DEPTHS_SAVED');
                        break;
 
                case "del":
-                       foreach ($_POST['id'] as $id=>$value)
-                       {
-                               $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_refdepths WHERE id=%s LIMIT 1",
-                                array(bigintval($id)), __FILE__, __LINE__);
+                       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__);
                        }
-                       $TEXT = REF_DEPTHS_DELETED;
+                       $message = getMessage('REF_DEPTHS_DELETED');
                        break;
                }
 
                // Update cache file
-               if (GET_EXT_VERSION("cache") >= "0.1.2")
-               {
-                       if ($cacheInstance->cache_file("refdepths", true)) $cacheInstance->cache_destroy();
+               if (GET_EXT_VERSION('cache') >= '0.1.2') {
+                       if ($GLOBALS['cache_instance']->loadCacheFile("refdepths")) $GLOBALS['cache_instance']->destroyCacheFile();
                }
                break;
 
        case "settings":
-               $REF = bigintval($_POST['ref_payout']);
-               $SQL[] = sprintf("UPDATE "._MYSQL_PREFIX."_config SET
+               $REF = bigintval(REQUEST_POST('ref_payout'));
+               ADD_SQL(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'],
- $REF
-               );
-               if (($_CONFIG['ref_payout'] == 0) && ($_POST['ref_payout'] > 0))
-               {
+                       REQUEST_POST('allow_direct_pay'),
+                       REQUEST_POST('reg_points_mode'),
+                       $REF
+               ));
+               if ((getConfig('ref_payout') == 0) && (REQUEST_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)
-WHERE mails_confirmed < %s", $REF, $REF);
-               }
-                elseif (($_CONFIG['ref_payout'] > 0) && ($_POST['ref_payout'] == 0))
-               {
+                       ADD_SQL(sprintf("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET ref_payout=(%s - mails_confirmed)
+WHERE mails_confirmed < %s", $REF, $REF));
+               } elseif ((getConfig('ref_payout') > 0) && (REQUEST_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";
+                       ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET ref_payout=0 WHERE ref_payout > 0");
+                       ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_user_points` SET points=points+locked_points WHERE locked_points>0");
+                       ADD_SQL("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)
-               {
-                       $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_refdepths WHERE level='%s' LIMIT 1",
-                        array(bigintval($_POST['lvl'])), __FILE__, __LINE__);
+
+       if ((IS_SQLS_VALID()) && (IS_SQLS_VALID())) {
+               if (strpos($GLOBALS['sqls'][0], "INSERT") > -1) {
+                       $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_refdepths` WHERE level='%s' LIMIT 1",
+                               array(bigintval(REQUEST_POST('lvl'))), __FILE__, __LINE__);
                        SQL_FREERESULT($result);
-               }
-               if (count($SQL) > 0)
-               {
+               } // END - if
+
+               if (COUNT_SQLS() > 0) {
                        // Run all SQL commands
-                       foreach ($SQL as $s)
-                       {
-                               $result = SQL_QUERY($s, __FILE__, __LINE__);
-                       }
+                       runFilterChain('run_sqls');
 
-                       $content = "<SPAN class=\"admin_done\">".SETTINGS_SAVED."</SPAN>";
+                       // Entry saved...
+                       $message = getMessage('SETTINGS_SAVED');
 
                        // Destroy config cache file here...
-                       if (GET_EXT_VERSION("cache") >= "0.1.2")
-                       {
-                               if ($cacheInstance->cache_file("config", true)) $cacheInstance->cache_destroy();
-                               unset($cacheArray);
-                       }
-               }
-                else
-               {
-                       $content = "<SPAN class=\"admin_failed\">".SETTINGS_NOT_SAVED."</SPAN>";
+                       rebuildCacheFiles("config", "config");
+               } else {
+                       // Prepare failed-message
+                       $message = "<span class=\"admin_failed\">{--SETTINGS_NOT_SAVED--}</span>";
                }
-               unset($SQL);
-               LOAD_TEMPLATE("admin_settings_saved", false, $content);
+
+               // Remove SQL queries
+               UNSET_SQLS();
        }
-        elseif (isset($TEXT))
-       {
-               LOAD_TEMPLATE("admin_settings_saved", false, $TEXT);
+
+       // Shall we display a message?
+       if (!empty($message)) {
+               // 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 referral bonus
-       switch ($_CONFIG['allow_direct_pay'])
-       {
+       // Including new add-mode for one-time referal bonus
+       switch (getConfig('allow_direct_pay')) {
        case 'Y':
-               define('__DIRECT_Y', ' checked');
-               define('__DIRECT_N', "");
+               define('__DIRECT_Y', ' chkecked="checked"');
+               define('__DIRECT_N', '');
                break;
 
        case 'N':
-               define('__DIRECT_Y', "");
-               define('__DIRECT_N', ' checked');
+               define('__DIRECT_Y', '');
+               define('__DIRECT_N', ' chkecked="checked"');
                break;
        }
 
-       // One-time referral bonus add-mode
-       switch ($_CONFIG['reg_points_mode'])
-       {
-               case "ref"   : define('__MODE_REF', ' checked'); define('__MODE_DIRECT', "");         break;
-               case "direct": define('__MODE_REF', "");         define('__MODE_DIRECT', ' checked'); break;
+       // One-time referal bonus add-mode
+       switch (getConfig('reg_points_mode')) {
+               case "ref"   : define('__MODE_REF', ' chkecked="checked"'); define('__MODE_DIRECT', '');         break;
+               case "direct": define('__MODE_REF', '');         define('__MODE_DIRECT', ' chkecked="checked"'); break;
        }
 
-       // Referral payout value
-       define('__REF_PAYOUT', round($_CONFIG['ref_payout']));
+       // Referal payout value
+       define('__REF_PAYOUT', round(getConfig('ref_payout')));
 
        // 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 (REQUEST_GET('sub') == "ref") {
+       // 12                  3     32    2                  3     32    2               3            4     43    21
+       if ((REQUEST_ISSET_POST('del')) && (REQUEST_ISSET_POST('sel')) && (SELECTION_COUNT(REQUEST_POST('sel')) > 0)) {
                // Delete entries
-               $SW = 2; $OUT = "";
-               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__);
+               $OUT = ''; $SW = 2;
+               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);
                        SQL_FREERESULT($result);
 
@@ -225,7 +213,7 @@ WHERE mails_confirmed < %s", $REF, $REF);
                                'sw'  => $SW,
                                'id'  => $id,
                                'lvl' => $lvl,
-                               'per' => $perc,
+                               'per' => TRANSLATE_COMMA($perc),
                        );
 
                        // Load row template and switch color
@@ -236,14 +224,11 @@ 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 ((REQUEST_ISSET_POST('edit')) && (REQUEST_ISSET_POST('sel')) && (SELECTION_COUNT(REQUEST_POST('sel')) > 0)) {
                // Edit entries
-               $SW = 2; $OUT = "";
-               foreach ($_POST['sel'] as $id=>$value)
-               {
-                       $result = SQL_QUERY_ESC("SELECT level, percents FROM "._MYSQL_PREFIX."_refdepths WHERE id=%s LIMIT 1",
+               $OUT = ''; $SW = 2;
+               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);
                        SQL_FREERESULT($result);
@@ -253,7 +238,7 @@ WHERE mails_confirmed < %s", $REF, $REF);
                                'sw'  => $SW,
                                'id'  => $id,
                                'lvl' => $lvl,
-                               'per' => $perc,
+                               'per' => TRANSLATE_COMMA($perc),
                        );
 
                        // Load row template and switch color
@@ -264,25 +249,22 @@ WHERE mails_confirmed < %s", $REF, $REF);
 
                // Load main template
                LOAD_TEMPLATE("admin_points_edit");
-       }
-        else
-       {
-               // Referral levels
-               $result = SQL_QUERY("SELECT id, level, percents FROM "._MYSQL_PREFIX."_refdepths ORDER BY level", __FILE__, __LINE__);
-               if (SQL_NUMROWS($result) > 0)
-               {
-                       // Make referral levels editable and deletable
-                       $SW = 2; $OUT = "";
+       } else {
+               // Referal levels
+               $result = SQL_QUERY("SELECT id, level, percents FROM `{!_MYSQL_PREFIX!}_refdepths` ORDER BY level", __FILE__, __LINE__);
+               if (SQL_NUMROWS($result) > 0) {
+                       // Make referal levels editable and deletable
+                       $OUT = ''; $SW = 2;
 
                        // List already existing categories for editing
-                       while (list($id, $lvl, $perc) = SQL_FETCHROW($result))
-                       {
+                       while ($content = SQL_FETCHARRAY($result)) {
                                // Prepare data for the row template
+                               // @TODO Rewritings: lvl->level, per->percents in template
                                $content = array(
                                        'sw'  => $SW,
-                                       'id'  => $id,
-                                       'lvl' => $lvl,
-                                       'per' => $perc,
+                                       'id'  => $content['id'],
+                                       'lvl' => $content['level'],
+                                       'per' => TRANSLATE_COMMA($content['percents']),
                                );
 
                                // Load row template and switch color
@@ -298,21 +280,17 @@ WHERE mails_confirmed < %s", $REF, $REF);
                        LOAD_TEMPLATE("admin_points");
                }
 
-               // Form for adding new referral levels
+               // Form for adding new referal levels
                LOAD_TEMPLATE("admin_add_reflvl");
        }
-}
- elseif ($_GET['sub'] == "points")
-{
-       // First points for registration and other fixed points including new add-mode for one-time referral bonus...
-       define('P_REG_VALUE', $_CONFIG['points_register']);
-       define('P_REF_VALUE', $_CONFIG['points_ref']);
+} 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'));
 
        // Load templates
        LOAD_TEMPLATE("admin_config_sub_points");
-}
- else
-{
+} else {
        // Display selection box
        LOAD_TEMPLATE("admin_config_points");
 }