<?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 *
* -------------------------------------------------------------------- *
* Kurzbeschreibung : Einstellen der Willkommensgutschrift usw. *
* -------------------------------------------------------------------- *
- * *
+ * $Revision:: $ *
+ * $Date:: $ *
+ * $Tag:: 0.2.1-FINAL $ *
+ * $Author:: $ *
* -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder *
- * For more information visit: http://www.mxchange.org *
+ * Copyright (c) 2003 - 2009 by Roland Haeder *
+ * Copyright (c) 2009 - 2012 by Mailer Developer Team *
+ * For more information visit: http://mxchange.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
************************************************************************/
// 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", basename(__FILE__));
-
-if (!empty($_GET['sub'])) {
- switch ($_GET['sub'])
- {
- case "points":
- if ((empty($_POST['points_register'])) || (empty($_POST['points_ref']))) {
- unset($_POST['ok']);
- }
- break;
+addYouAreHereLink('admin', __FILE__);
+
+// Init variables
+$message = '';
+
+// Is the 'sub' parameter set?
+if (isGetRequestElementSet('sub')) {
+ // Yes, then do some sanity-checks
+ switch (getRequestElement('sub')) {
+ case 'points':
+ if ((!isPostRequestElementSet('points_register')) || (!isPostRequestElementSet('points_ref'))) {
+ unsetPostRequestElement('ok');
+ } // END - if
+ break;
- case "ref":
- if (isset($_GET['do'])) {
- if (((empty($_POST['lvl'])) || (empty($_POST['perc']))) && ($_GET['do'] == "add")) {
- unset($_POST['ok']);
+ case 'ref':
+ if (isGetRequestElementSet('do')) {
+ if (((!isPostRequestElementSet('level')) || (!isPostRequestElementSet('percents'))) && (getRequestElement('do') == 'add')) {
+ unsetPostRequestElement('ok');
+ }
}
- }
- break;
- }
+ break;
+ } // END - switch
} else {
// Display overview
- $_GET['sub'] = "overview";
+ setGetRequestElement('sub', 'overview');
}
-if (isset($_POST['ok'])) {
- $SQL = 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";
- break;
-
- case "ref":
- switch ($_GET['do'])
- {
- case "add":
- $SQL[] = "INSERT INTO "._MYSQL_PREFIX."_refdepths (level, percents) VALUES ('".$_POST['lvl']."','".$_POST['perc']."')";
+if (isFormSent()) {
+ initSqls();
+ switch (getRequestElement('sub')) {
+ case 'points':
+ adminSaveSettingsFromPostData();
break;
- case "edit": // Change entries
- foreach ($_POST['lvl'] as $id => $value) {
- // Secure ID
- $id = bigintval($id);
-
- // Revert german commata
- $_POST['perc'][$id] = REVERT_COMMA($_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__);
- }
- $TEXT = REF_DEPTHS_SAVED;
+ case 'ref':
+ switch (getRequestElement('do')) {
+ case 'add':
+ addSql("INSERT INTO `{?_MYSQL_PREFIX?}_refdepths` (`level`,`percents`) VALUES ('".bigintval(postRequestElement('level'))."','".bigintval(postRequestElement('percents'))."')");
+ break;
+
+ case 'edit': // Change entries
+ foreach (postRequestElement('level') as $id => $value) {
+ // Secure id
+ $id = bigintval($id);
+
+ // Revert german commata
+ setPostRequestElement('percents', array($id => convertCommaToDot(postRequestElement('percents', $id))));
+
+ // Update entry
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refdepths` SET `level`=%s,`percents`=%s WHERE `id`=%s LIMIT 1",
+ array(bigintval($value), convertCommaToDot(postRequestElement('percents', $id)), $id), __FILE__, __LINE__);
+ } // END - foreach
+ $message = '{--ADMIN_REFERRAL_DEPTHS_SAVED--}';
+ break;
+
+ case 'delete':
+ foreach (postRequestElement('id') as $id => $value) {
+ SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_refdepths` WHERE `id`=%s LIMIT 1",
+ array(bigintval($id)), __FILE__, __LINE__);
+ } // END - foreach
+ $message = '{--ADMIN_REFERRAL_DEPTHS_DELETED--}';
+ break;
+ } // END - switch
+
+ // Update cache file
+ // @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 "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__);
+ case 'settings':
+ $REF = bigintval(postRequestElement('ref_payout'));
+ updateConfiguration(
+ array('allow_direct_pay', 'ref_payout'),
+ array(postRequestElement('allow_direct_pay'), $REF)
+ );
+ if ((getRefPayout() == '0') && (postRequestElement('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 ((getRefPayout() > 0) && (postRequestElement('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");
+ // @TODO Rewrite these two lines for new user_points columns (e.g. locked_order_points) with a filter
+ 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");
}
- $TEXT = REF_DEPTHS_DELETED;
break;
- }
+ } // END - switch
- // Update cache file
- if (GET_EXT_VERSION("cache") >= "0.1.2") {
- if ($cacheInstance->cache_file("refdepths", true)) $cacheInstance->cache_destroy();
- }
- break;
+ // Is there an array?
+ if ((getRequestElement('sub') != 'points') && (isSqlsValid())) {
+ // Default is failed-message
+ $message = '<span class="bad">{--SETTINGS_NOT_SAVED--}</span>';
- case "settings":
- $REF = bigintval($_POST['ref_payout']);
- $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))
- {
- // 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))
- {
- // 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";
- }
- 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__);
- SQL_FREERESULT($result);
- }
- if (count($SQL) > 0)
- {
+ if (countSqls() > 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 = '{--SETTINGS_SAVED--}';
// Destroy config cache file here...
- REBUILD_CACHE("config", "config");
- }
- else
- {
- $content = "<SPAN class=\"admin_failed\">".SETTINGS_NOT_SAVED."</SPAN>";
- }
- unset($SQL);
- LOAD_TEMPLATE("admin_settings_saved", false, $content);
- }
- elseif (isset($TEXT))
- {
- LOAD_TEMPLATE("admin_settings_saved", false, $TEXT);
- }
-}
- elseif ($_GET['sub'] == "settings")
-{
+ rebuildCache('config', 'config');
+ } // END - if
+
+ // Remove SQL queries
+ unsetSqls();
+ } // END - if
+
+ // Shall we display a message?
+ if (!empty($message)) {
+ // When do so...
+ displayMessage($message);
+ } // END - if
+} elseif (getRequestElement('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'])
- {
- case 'Y':
- define('__DIRECT_Y', " checked=\"checked\"");
- define('__DIRECT_N', "");
- break;
-
- case 'N':
- define('__DIRECT_Y', "");
- define('__DIRECT_N', " checked=\"checked\"");
- break;
- }
-
- // One-time referral bonus add-mode
- switch ($_CONFIG['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;
- }
-
- // Referral payout value
- define('__REF_PAYOUT', round($_CONFIG['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 ($_GET['sub'] == "ref")
-{
- if ((isset($_POST['del'])) && ((SELECTION_COUNT($_POST['sel']) > 0) || (isset($_POST['sel'][0]))))
- {
+ loadTemplate('admin_config_point_settings', false, $content);
+} elseif (getRequestElement('sub') == 'ref') {
+ // 12 3 32 2 3321
+ if ((isFormSent('delete')) && (ifPostContainsSelections())) {
// 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__);
- list($lvl, $perc) = SQL_FETCHROW($result);
+ $OUT = '';
+ foreach (postRequestElement('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' => TRANSLATE_COMMA($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 ((isset($_POST['edit'])) && ((SELECTION_COUNT($_POST['sel']) > 0) || (isset($_POST['sel'][0]))))
- {
+ loadTemplate('admin_delete_reflevel', false, $OUT);
+ } elseif ((isFormSent('edit')) && (ifPostContainsSelections())) {
// 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",
- array(bigintval($id)), __FILE__, __LINE__);
- list($lvl, $perc) = SQL_FETCHROW($result);
+ $OUT = '';
+ foreach (postRequestElement('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' => TRANSLATE_COMMA($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");
- }
- else
- {
+ loadTemplate('admin_edit_reflevel', false, $OUT);
+ } else {
// Referral levels
- $result = SQL_QUERY("SELECT id, level, percents FROM "._MYSQL_PREFIX."_refdepths ORDER BY level", __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 referral levels editable and deletable
- $SW = 2; $OUT = "";
+ $OUT = '';
// List already existing categories for editing
- while (list($id, $lvl, $perc) = SQL_FETCHROW($result))
- {
- // Prepare data for the row template
- $content = array(
- 'sw' => $SW,
- 'id' => $id,
- 'lvl' => $lvl,
- 'per' => TRANSLATE_COMMA($perc),
- );
-
+ while ($content = SQL_FETCHARRAY($result)) {
// 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 referral levels
- LOAD_TEMPLATE("admin_add_reflvl");
+ loadTemplate('admin_add_reflevel');
}
-}
- 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']);
-
- // Load templates
- LOAD_TEMPLATE("admin_config_sub_points");
-}
- else
-{
+} elseif (getRequestElement('sub') == 'points') {
+ // Load template
+ loadTemplate('admin_config_sub_points');
+} else {
// Display selection box
- LOAD_TEMPLATE("admin_config_points");
+ loadTemplate('admin_config_points');
}
-//
+// [EOF]
?>