A lot has been rewritten, ext-teams added, ext-forced continued:
[mailer.git] / inc / modules / admin / what-config_points.php
index 6be930611ab19b57a16f55b809e5087dfa641672..0c60e88fe5443a62958a637fd90fe6cb2e0c8101 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 10/12/2003 *
- * ===============                              Last change: 12/12/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 10/12/2003 *
+ * ===================                          Last change: 12/12/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : what-config_points.php                           *
  * $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                           *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  ************************************************************************/
 
 // Some security stuff...
-if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
-       require($INC);
-}
+if ((!defined('__SECURITY')) || (!isAdmin())) {
+       die();
+} // END - if
 
 // Add description as navigation point
-ADD_DESCR('admin', __FILE__);
+addYouAreHereLink('admin', __FILE__);
 
 // Init variables
 $message = '';
 
 // Is the 'sub' parameter set?
-if (REQUEST_ISSET_GET('sub')) {
+if (isGetRequestParameterSet('sub')) {
        // Yes, then do some sanity-checks
-       switch (REQUEST_GET('sub')) {
+       switch (getRequestParameter('sub')) {
                case 'points':
-                       if ((!REQUEST_ISSET_POST(('points_register'))) || (!REQUEST_ISSET_POST(('points_ref')))) {
-                               REQUEST_UNSET_POST('ok');
-                       }
+                       if ((!isPostRequestParameterSet('points_register')) || (!isPostRequestParameterSet('points_ref'))) {
+                               unsetPostRequestParameter('ok');
+                       } // END - if
                        break;
 
                case 'ref':
-                       if (REQUEST_ISSET_GET('do')) {
-                               if (((!REQUEST_ISSET_POST(('lvl'))) || (!REQUEST_ISSET_POST(('perc')))) && (REQUEST_GET('do') == 'add')) {
-                                       REQUEST_UNSET_POST('ok');
+                       if (isGetRequestParameterSet('do')) {
+                               if (((!isPostRequestParameterSet('level')) || (!isPostRequestParameterSet('percents'))) && (getRequestParameter('do') == 'add')) {
+                                       unsetPostRequestParameter('ok');
                                }
                        }
                        break;
-       }
+       } // END - switch
 } else {
        // Display overview
-       REQUEST_SET_GET('sub', 'overview');
+       setGetRequestParameter('sub', 'overview');
 }
 
 if (isFormSent()) {
-       INIT_SQLS();
-       switch (REQUEST_GET('sub')) {
+       initSqls();
+       switch (getRequestParameter('sub')) {
                case 'points':
-                       updateConfiguration(array('points_register', 'points_ref'), array(REQUEST_POST('points_register'), REQUEST_POST('points_ref')));
+                       adminSaveSettingsFromPostData();
                        break;
 
                case 'ref':
-                       switch (REQUEST_GET('do'))
-                       {
+                       switch (getRequestParameter('do')) {
                                case 'add':
-                                       ADD_SQL("INSERT INTO `{!_MYSQL_PREFIX!}_refdepths` (level, percents) VALUES ('".REQUEST_POST('lvl')."','".REQUEST_POST('perc')."')");
+                                       addSql("INSERT INTO `{?_MYSQL_PREFIX?}_refdepths` (`level`,`percents`) VALUES ('".bigintval(postRequestParameter('level'))."','".bigintval(postRequestParameter('percents'))."')");
                                        break;
 
                                case 'edit': // Change entries
-                                       foreach (REQUEST_POST('lvl') as $id => $value) {
-                                               // Secure ID
+                                       foreach (postRequestParameter('level') as $id => $value) {
+                                               // Secure id
                                                $id = bigintval($id);
 
                                                // Revert german commata
-                                               REQUEST_SET_POST('perc', array($id => convertCommaToDot(REQUEST_POST('perc', $id))));
+                                               setPostRequestParameter('percents', array($id => convertCommaToDot(postRequestParameter('percents', $id))));
 
                                                // Update entry
-                                               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__);
-                                       }
-                                       $message = getMessage('REF_DEPTHS_SAVED');
+                                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refdepths` SET `level`=%s, `percents`=%s WHERE `id`=%s LIMIT 1",
+                                                       array(bigintval($value), convertCommaToDot(postRequestParameter('percents', $id)), $id), __FILE__, __LINE__);
+                                       } // END - foreach
+                                       $message = '{--ADMIN_REFERAL_DEPTHS_SAVED--}';
                                        break;
 
-                               case 'del':
-                                       foreach (REQUEST_POST('id') as $id => $value) {
-                                               SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_refdepths` WHERE `id`=%s LIMIT 1",
+                               case 'delete':
+                                       foreach (postRequestParameter('id') as $id => $value) {
+                                               SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `id`=%s LIMIT 1",
                                                array(bigintval($id)), __FILE__, __LINE__);
-                                       }
-                                       $message = getMessage('REF_DEPTHS_DELETED');
+                                       } // END - foreach
+                                       $message = '{--ADMIN_REFERAL_DEPTHS_DELETED--}';
                                        break;
-                       }
+                       } // END - switch
 
                        // Update cache file
-                       if (GET_EXT_VERSION('cache') >= '0.1.2') {
-                               if ($GLOBALS['cache_instance']->loadCacheFile("refdepths")) $GLOBALS['cache_instance']->destroyCacheFile();
-                       }
+                       // @TODO Rewrite this to a filter
+                       if (isExtensionInstalledAndNewer('cache', '0.1.2')) {
+                               if ($GLOBALS['cache_instance']->loadCacheFile('refdepths')) $GLOBALS['cache_instance']->removeCacheFile();
+                       } // END - if
                        break;
 
-                               case "settings":
-                                       $REF = bigintval(REQUEST_POST('ref_payout'));
-                                       updateConfiguration(
-                                               array('allow_direct_pay', 'reg_points_mode', 'ref_payout'),
-                                               array(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"
-                                               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"
-                                               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;
-       }
+               case 'settings':
+                       $REF = bigintval(postRequestParameter('ref_payout'));
+                       updateConfiguration(
+                               array('allow_direct_pay', 'ref_payout'),
+                               array(postRequestParameter('allow_direct_pay'), $REF)
+                       );
+                       if ((getConfig('ref_payout') == '0') && (postRequestParameter('ref_payout') > 0)) {
+                               // Update account's ref_payout for "must-confirm"
+                               addSql(sprintf("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=(%s - `mails_confirmed`)
+WHERE
+       `mails_confirmed` < %s", $REF, $REF));
+                       } elseif ((getConfig('ref_payout') > 0) && (postRequestParameter('ref_payout') == '0')) {
+                               // Update account's ref_payout for "not-must-confirm"
+                               addSql("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `ref_payout`=0 WHERE `ref_payout` > 0");
+                               addSql("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `points`=`points`+`locked_points` WHERE `locked_points` > 0");
+                               addSql("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `locked_points`=0 WHERE `locked_points` > 0");
+                       }
+                       break;
+       } // END - switch
 
-       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__);
+       if ((isSqlsValid()) && (isSqlsValid())) {
+               if (strpos($GLOBALS['sqls'][0], 'INSERT') > -1) {
+                       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `level`=%s LIMIT 1",
+                               array(bigintval(postRequestParameter('level'))), __FILE__, __LINE__);
                        SQL_FREERESULT($result);
                } // END - if
 
-               if (COUNT_SQLS() > 0) {
+               if (countSqls() > 0) {
                        // Run all SQL commands
                        runFilterChain('run_sqls');
 
                        // Entry saved...
-                       $message = getMessage('SETTINGS_SAVED');
+                       $message = '{--SETTINGS_SAVED--}';
 
                        // Destroy config cache file here...
-                       rebuildCacheFiles("config", "config");
+                       rebuildCache('config', 'config');
                } else {
                        // Prepare failed-message
-                       $message = "<span class=\"admin_failed\">{--SETTINGS_NOT_SAVED--}</span>";
+                       $message = '<span class="notice">{--SETTINGS_NOT_SAVED--}</span>';
                }
 
                // Remove SQL queries
-               UNSET_SQLS();
+               unsetSqls();
        }
 
        // Shall we display a message?
        if (!empty($message)) {
                // When do so...
-               LOAD_TEMPLATE('admin_settings_saved', false, $message);
-       }
-} elseif (REQUEST_GET('sub') == "settings") {
+               displayMessage($message);
+       } // END - if
+} elseif (getRequestParameter('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')) {
-               case 'Y':
-                       define('__DIRECT_Y', ' checked="checked"');
-                       define('__DIRECT_N', '');
-                       break;
-
-               case 'N':
-                       define('__DIRECT_Y', '');
-                       define('__DIRECT_N', ' checked="checked"');
-                       break;
-       }
-
-       // One-time referal bonus add-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;
-       }
-
-       // Referal payout value
-       define('__REF_PAYOUT', round(getConfig('ref_payout')));
+       foreach (array('allow_direct_pay') as $entry) {
+               $content[$entry . '_y'] = '';
+               $content[$entry . '_n'] = '';
+               $content[$entry . '_' . strtolower(getConfig($entry))] = ' checked="checked"';
+       } // END - foreach
 
        // Load template
-       LOAD_TEMPLATE("admin_config_point_settings");
-} 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')) && (countPostSelection() > 0)) {
+       loadTemplate('admin_config_point_settings', false, $content);
+} elseif (getRequestParameter('sub') == 'ref') {
+       // 12          3     32    2                        3321
+       if ((isFormSent('delete')) && (ifPostContainsSelections())) {
                // Delete entries
-               $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);
+               $OUT = '';
+               foreach (postRequestParameter('sel') as $id => $value) {
+                       $result = SQL_QUERY_ESC("SELECT `id`,`level`,`percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `id`=%s LIMIT 1",
+                               array(bigintval($id)), __FILE__, __LINE__);
+                       $content = SQL_FETCHARRAY($result);
                        SQL_FREERESULT($result);
 
-                       // Prepare data for the row template
-                       $content = array(
-                               'sw'  => $SW,
-                               'id'  => $id,
-                               'lvl' => $lvl,
-                               'per' => translateComma($perc),
-                       );
-
                        // Load row template and switch color
-                       $OUT .= LOAD_TEMPLATE("admin_points_del_row", true, $content);
-                       $SW = 3 - $SW;
-               }
-               define('__LEVEL_ROWS', $OUT);
+                       $OUT .= loadTemplate('admin_delete_reflevel_row', true, $content);
+               } // END - foreach
 
                // Load main template
-               LOAD_TEMPLATE("admin_points_del");
-       } elseif ((REQUEST_ISSET_POST('edit')) && (REQUEST_ISSET_POST('sel')) && (countPostSelection() > 0)) {
+               loadTemplate('admin_delete_reflevel', false, $OUT);
+       } elseif ((isFormSent('edit')) && (ifPostContainsSelections())) {
                // Edit entries
-               $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);
+               $OUT = '';
+               foreach (postRequestParameter('sel') as $id => $value) {
+                       $result = SQL_QUERY_ESC("SELECT `id`,`level`,`percents` FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `id`=%s LIMIT 1",
+                               array(bigintval($id)), __FILE__, __LINE__);
+                       $content = SQL_FETCHARRAY($result);
                        SQL_FREERESULT($result);
 
-                       // Prepare data for the row template
-                       $content = array(
-                               'sw'  => $SW,
-                               'id'  => $id,
-                               'lvl' => $lvl,
-                               'per' => translateComma($perc),
-                       );
-
                        // Load row template and switch color
-                       $OUT .= LOAD_TEMPLATE("admin_points_edit_row", true, $content);
-                       $SW = 3 - $SW;
-               }
-               define('__LEVEL_ROWS', $OUT);
+                       $OUT .= loadTemplate('admin_edit_reflevel_row', true, $content);
+               } // END - foreach
 
                // Load main template
-               LOAD_TEMPLATE("admin_points_edit");
+               loadTemplate('admin_edit_reflevel', false, $OUT);
        } else {
                // Referal levels
-               $result = SQL_QUERY("SELECT `id`, `level`, `percents` FROM `{!_MYSQL_PREFIX!}_refdepths` ORDER BY `level` ASC", __FILE__, __LINE__);
-               if (SQL_NUMROWS($result) > 0) {
+               $result = SQL_QUERY("SELECT `id`,`level`,`percents` FROM `{?_MYSQL_PREFIX?}_refdepths` ORDER BY `level` ASC", __FILE__, __LINE__);
+               if (!SQL_HASZERONUMS($result)) {
                        // Make referal levels editable and deletable
-                       $OUT = ''; $SW = 2;
+                       $OUT = '';
 
                        // List already existing categories for editing
                        while ($content = SQL_FETCHARRAY($result)) {
-                               // Prepare data for the row template
-                               // @TODO Rewritings: lvl->level, per->percents in template
-                               $content = array(
-                                       'sw'  => $SW,
-                                       'id'  => $content['id'],
-                                       'lvl' => $content['level'],
-                                       'per' => translateComma($content['percents']),
-                               );
-
                                // Load row template and switch color
-                               $OUT .= LOAD_TEMPLATE('admin_points_row', true, $content);
-                               $SW = 3 - $SW;
-                       }
+                               $OUT .= loadTemplate('admin_list_reflevel_row', true, $content);
+                       } // END - while
 
                        // Free memory
                        SQL_FREERESULT($result);
-                       define('__LEVEL_ROWS', $OUT);
 
                        // Load main template
-                       LOAD_TEMPLATE('admin_points');
+                       loadTemplate('admin_list_reflevel', false, $OUT);
                }
 
                // Form for adding new referal levels
-               LOAD_TEMPLATE('admin_add_reflvl');
+               loadTemplate('admin_add_reflevel');
        }
-} 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');
+} elseif (getRequestParameter('sub') == 'points') {
+       // Load template
+       loadTemplate('admin_config_sub_points');
 } else {
        // Display selection box
-       LOAD_TEMPLATE('admin_config_points');
+       loadTemplate('admin_config_points');
 }
 
-//
+// [EOF]
 ?>