X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Flibs%2Fsponsor_functions.php;h=e76834d86d5dbcc8d0b2a7571922247e19d5d1cc;hb=e98608bf2a6208376d30996cf9152e1f091ac369;hp=5ef940265a065abbe5fdcd415fe9bf860e9f76f6;hpb=c5e685ff1b1bd296243b9bfcd8921969fa09d53f;p=mailer.git diff --git a/inc/libs/sponsor_functions.php b/inc/libs/sponsor_functions.php index 5ef940265a..e76834d86d 100644 --- a/inc/libs/sponsor_functions.php +++ b/inc/libs/sponsor_functions.php @@ -10,7 +10,12 @@ * -------------------------------------------------------------------- * * Kurzbeschreibung : Funktionen fuer den Sponsorenbereich * * -------------------------------------------------------------------- * - * * + * $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 * @@ -37,7 +42,7 @@ if (!defined('__SECURITY')) { } // -function SPONSOR_HANDLE_SPONSOR (&$POST, $NO_UPDATE=false, $MSGs=array(), $RET_STATUS=false) { +function SPONSOR_HANDLE_SPONSOR (&$POST, $NO_UPDATE=false, $messageArray=array(), $RET_STATUS=false) { // Init a lot variables $SAVE = true; $UPDATE = false; @@ -70,7 +75,7 @@ function SPONSOR_HANDLE_SPONSOR (&$POST, $NO_UPDATE=false, $MSGs=array(), $RET_S } else { // Do we want to add a new sponsor or update his data? $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_sponsor_data` WHERE email='%s' LIMIT 1", - array($POST['email']), __FILE__, __LINE__); + array($POST['email']), __FUNCTION__, __LINE__); // Is a sponsor alread in the db? if (SQL_NUMROWS($result) == 1) { @@ -120,22 +125,22 @@ function SPONSOR_HANDLE_SPONSOR (&$POST, $NO_UPDATE=false, $MSGs=array(), $RET_S if ((empty($POST['force'])) || (!IS_ADMIN())) $POST['force'] = 0; // SQL and message string is empty by default - $SQL = ""; $MSG = ""; + $sql = ""; $message = ""; // Update? if ($UPDATE) { // Update his data - $SQL = "UPDATE `{!_MYSQL_PREFIX!}_sponsor_data` SET "; + $sql = "UPDATE `{!_MYSQL_PREFIX!}_sponsor_data` SET "; foreach ($DATA['keys'] as $k => $v) { - $SQL .= $v."='%s', "; + $sql .= $v."='%s', "; } // Remove last ", " from SQL string - $SQL = substr($SQL, 0, -2)." WHERE id='%s' LIMIT 1"; - $DATA['values'][] = bigintval($_GET['id']); + $sql = substr($sql, 0, -2)." WHERE id='%s' LIMIT 1"; + $DATA['values'][] = bigintval(REQUEST_GET('id')); // Generate message - $MSG = SPONSOR_GET_MESSAGE(ADMIN_SPONSOR_UPDATED, "updated", $MSGs); + $message = SPONSOR_GET_MESSAGE(ADMIN_SPONSOR_UPDATED, "updated", $messageArray); $ret = "updated"; } elseif ((!$ALREADY) || (($POST['force'] == "1") && (IS_ADMIN()))) { // Add new sponsor, first add more data @@ -144,7 +149,7 @@ function SPONSOR_HANDLE_SPONSOR (&$POST, $NO_UPDATE=false, $MSGs=array(), $RET_S if ((!$NO_UPDATE) && (IS_ADMIN()) && ($GLOBALS['what'] == "add_sponsor")) { // Only allowed for admin $DATA['values'][] = "PENDING"; - } elsen{ + } else { // Guest area $DATA['values'][] = "UNCONFIRMED"; @@ -160,10 +165,10 @@ function SPONSOR_HANDLE_SPONSOR (&$POST, $NO_UPDATE=false, $MSGs=array(), $RET_S $VALUES = str_repeat("%s', '", count($DATA['values']) - 1); // Generate string - $SQL = "INSERT INTO `{!_MYSQL_PREFIX!}_sponsor_data` (".$KEYS.") VALUES ('".$VALUES."%s')"; + $sql = "INSERT INTO `{!_MYSQL_PREFIX!}_sponsor_data` (".$KEYS.") VALUES ('".$VALUES."%s')"; // Generate message - $MSG = SPONSOR_GET_MESSAGE(ADMIN_SPONSOR_ADDED, "added", $MSGs); + $message = SPONSOR_GET_MESSAGE(getMessage('ADMIN_SPONSOR_ADDED'), "added", $messageArray); $ret = "added"; } elseif ((!$NO_UPDATE) && (IS_ADMIN())) { // Add all data as hidden data @@ -171,7 +176,7 @@ function SPONSOR_HANDLE_SPONSOR (&$POST, $NO_UPDATE=false, $MSGs=array(), $RET_S foreach ($POST as $k => $v) { // Do not add 'force' ! if ($k != "force") { - $OUT .= "\n"; + $OUT .= "\n"; } } define('__HIDDEN_DATA', $OUT); @@ -182,56 +187,41 @@ function SPONSOR_HANDLE_SPONSOR (&$POST, $NO_UPDATE=false, $MSGs=array(), $RET_S return; } else { // Already added! - $MSG = SPONSOR_ALREADY_FOUND_1.$POST['email'].SPONSOR_ALREADY_FOUND_2; + $message = sprintf(getMessage('SPONSOR_ALREADY_FOUND', $POST['email'])); $ret = "already"; } - if (!empty($SQL)) { + if (!empty($sql)) { // Run SQL command - $result = SQL_QUERY_ESC($SQL, $DATA['values'], __FILE__, __LINE__); + $result = SQL_QUERY_ESC($sql, $DATA['values'], __FUNCTION__, __LINE__); } // Output message if ((!$NO_UPDATE) && (IS_ADMIN())) { - LOAD_TEMPLATE("admin_settings_saved", false, $MSG); + LOAD_TEMPLATE("admin_settings_saved", false, $message); } } else { // Error found! - $MSG = SPONSOR_GET_MESSAGE(SPONSOR_DATA_NOT_SAVED, "failed", $MSGs); - LOAD_TEMPLATE("admin_settings_saved", false, $MSG); + $message = SPONSOR_GET_MESSAGE(getMessage('SPONSOR_DATA_NOT_SAVED'), "failed", $messageArray); + LOAD_TEMPLATE("admin_settings_saved", false, $message); } // Shall we return the status? if ($RET_STATUS) return $ret; } // -function SPONSOR_TRANSLATE_STATUS($status) { - switch ($status) - { - case "UNCONFIRMED": - $ret = ACCOUNT_UNCONFIRMED; - break; - - case "CONFIRMED": - $ret = ACCOUNT_CONFIRMED; - break; - - case "LOCKED": - $ret = ACCOUNT_LOCKED; - break; - - case "PENDING": - $ret = ACCOUNT_PENDING; - break; - - case "EMAIL": - $ret = ACCOUNT_EMAIL; - break; - - default: +function SPONSOR_TRANSLATE_STATUS ($status) { + // Construct constant name + $constantName = sprintf("ACCOUNT_%s", $status); + + // Is the constant there? + if (defined($constantName)) { + // Then use it + $ret = constant($constantName); + } else { + // Not found! DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Unknown status %s detected.", $status)); - $ret = UNKNOWN_STATUS_1.$status.UNKNOWN_STATUS_2; - break; + $ret = sprintf(getMessage('UNKNOWN_STATUS'), $status); } return $ret; } @@ -262,11 +252,11 @@ function SPONSOR_GET_MESSAGE ($msg, $pos, $array) { function IS_SPONSOR () { // Failed... $ret = false; - if ((isSessionVariableSet('sponsorid'))) && (isSessionVariableSet('sponsorpass')))) { + if ((isSessionVariableSet('sponsorid')) && (isSessionVariableSet('sponsorpass'))) { // Check cookies against database records... $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_sponsor_data` WHERE id='%s' AND password='%s' AND `status`='CONFIRMED' LIMIT 1", - array(bigintval(get_session('sponsorid')), get_session('sponsorpass')), __FILE__, __LINE__); + array(bigintval(get_session('sponsorid')), get_session('sponsorpass')), __FUNCTION__, __LINE__); if (SQL_NUMROWS($result) == 1) { // All is fine $ret = true; @@ -287,31 +277,31 @@ function GENERATE_SPONSOR_MENU($current) if (IS_ADMIN()) $WHERE = ""; // Load main menu entries - $result_main = SQL_QUERY("SELECT action, title FROM `{!_MYSQL_PREFIX!}_sponsor_menu` + $result_main = SQL_QUERY("SELECT action AS main_action, title AS main_title FROM `{!_MYSQL_PREFIX!}_sponsor_menu` WHERE (what='' OR `what` IS NULL) ".$WHERE." -ORDER BY `sort`", __FILE__, __LINE__); - if (SQL_NUMROWS($result_main) > 0) - { +ORDER BY `sort`", __FUNCTION__, __LINE__); + if (SQL_NUMROWS($result_main) > 0) { // Load every menu and it's sub menus - while (list($action, $title_main) = SQL_FETCHROW($result_main)) - { + while ($content = SQL_FETCHARRAY($result_main)) { // Load sub menus - $result_sub = SQL_QUERY_ESC("SELECT what, title FROM `{!_MYSQL_PREFIX!}_sponsor_menu` + $result_sub = SQL_QUERY_ESC("SELECT what AS sub_what, title AS sub_title FROM `{!_MYSQL_PREFIX!}_sponsor_menu` WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ".$WHERE." -ORDER BY `sort`", array($action), __FILE__, __LINE__); - if (SQL_NUMROWS($result_sub) > 0) - { +ORDER BY `sort`", + array($content['main_action']), __FUNCTION__, __LINE__); + if (SQL_NUMROWS($result_sub) > 0) { // Load sub menus $SUB = ""; - while (list($what, $title_sub) = SQL_FETCHROW($result_sub)) - { + while ($content2 = SQL_FETCHARRAY($result_sub)) { + // Merge both arrays + $content = merge_array($content, $content2); + // Check if current selected menu is matching the loaded one - if ($current == $what) $title_sub = "".$title_sub.""; + if ($current == $content['sub_what']) $content['sub_title'] = "".$content['sub_title'].""; // Prepare data for the sub template $content = array( - 'what' => $what, - 'title' => $title_sub + 'what' => $content['sub_what'], + 'title' => $content['sub_title'] ); // Load row template @@ -320,27 +310,23 @@ ORDER BY `sort`", array($action), __FILE__, __LINE__); // Prepare data for the main template $content = array( - 'title' => $title_main, + 'title' => $content['main_title'], 'menu' => $SUB ); // Load menu template $OUT .= LOAD_TEMPLATE("sponsor_action", true, $content); - } - else - { + } else { // No sub menus active - $OUT .= LOAD_TEMPLATE("admin_settings_saved", true, SPONSOR_NO_SUB_MENUS_ACTIVE); + $OUT .= LOAD_TEMPLATE("admin_settings_saved", true, getMessage('SPONSOR_NO_SUB_MENUS_ACTIVE')); } // Free memory SQL_FREERESULT($result_sub); } - } - else - { + } else { // No main menus active - $OUT .= LOAD_TEMPLATE("admin_settings_saved", true, SPONSOR_NO_MAIN_MENUS_ACTIVE); + $OUT .= LOAD_TEMPLATE("admin_settings_saved", true, getMessage('SPONSOR_NO_MAIN_MENUS_ACTIVE')); } // Free memory @@ -349,22 +335,23 @@ ORDER BY `sort`", array($action), __FILE__, __LINE__); // Return content return $OUT; } + // -function GENERATE_SPONSOR_CONTENT($what) -{ +function GENERATE_SPONSOR_CONTENT ($what) { $OUT = ""; $INC = sprintf("inc/modules/sponsor/%s.php", $what); - if (FILE_READABLE($INC)) { + if (INCLUDE_READABLE($INC)) { // Every sponsor action will output nothing directly. It will be written into $OUT! LOAD_INC_ONCE($INC); } else { // File not found! - $OUT .= LOAD_TEMPLATE("admin_settings_saved", true, SPONSOR_CONTENT_404_1.$what.SPONSOR_CONTENT_404_2); + $OUT .= LOAD_TEMPLATE("admin_settings_saved", true, sprintf(getMessage('SPONSOR_CONTENT_404'), $what)); } // Return content return $OUT; } + // function UPDATE_SPONSOR_LOGIN () { // Failed by default @@ -376,7 +363,7 @@ function UPDATE_SPONSOR_LOGIN () { SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_sponsor_data` SET last_online=UNIX_TIMESTAMP() WHERE id='%s' AND password='%s' LIMIT 1", - array(bigintval(get_session('sponsorid')), get_session('sponsorpass')), __FILE__, __LINE__); + array(bigintval(get_session('sponsorid')), get_session('sponsorpass')), __FUNCTION__, __LINE__); // This update went fine? $login = (SQL_AFFECTEDROWS() == 1); @@ -395,7 +382,7 @@ function SPONSOR_SAVE_DATA ($POST, $content) { 'ok', 'pass1', 'pass2'); // Set default message ("not saved") - $MSG = SPONSOR_ACCOUNT_DATA_NOT_SAVED; + $message = getMessage('SPONSOR_ACCOUNT_DATA_NOT_SAVED'); // Check for submitted passwords if ((!empty($POST['pass1'])) && (!empty($POST['pass2']))) { @@ -403,30 +390,30 @@ function SPONSOR_SAVE_DATA ($POST, $content) { if ($POST['pass1'] == $POST['pass2']) { // Okay, then set password and remove pass1 and pass2 $POST['password'] = md5($POST['pass1']); - } - } + } // END - if + } // END - if // Remove all (maybe spoofed) unsafe data from array foreach ($UNSAFE as $remove) { unset($POST[$remove]); - } + } // END - foreach // This array is for the submitted data which we will use with the SQL_QUERY_ESC() function to // secure the data $DATA = array(); // Prepare SQL string - $SQL = "UPDATE `{!_MYSQL_PREFIX!}_sponsor_data` SET"; + $sql = "UPDATE `{!_MYSQL_PREFIX!}_sponsor_data` SET"; foreach ($POST as $key => $value) { // Mmmmm, too less security here??? - $SQL .= " ".strip_tags($key)."='%s',"; + $sql .= " ".strip_tags($key)."='%s',"; // We will secure this later inside the SQL_QUERY_ESC() function $DATA[] = strip_tags($value); // Compile {SLASH} and so on for the email templates $POST[$key] = COMPILE_CODE($value); - } + } // END - foreach // Check if email has changed if ((!empty($content['email'])) && (!empty($POST['email']))) { @@ -435,19 +422,19 @@ function SPONSOR_SAVE_DATA ($POST, $content) { $EMAIL = true; // Okay, has changed then add status with UNCONFIRMED and new hash code - $SQL .= " `status`='EMAIL', hash='%s',"; + $sql .= " `status`='EMAIL', hash='%s',"; // Generate hash code $HASH = md5(session_id().":".$POST['email'].":".GET_REMOTE_ADDR().":".GET_USER_AGENT().":".time()); $DATA[] = $HASH; - } - } + } // END - if + } // END - if // Remove last commata - $SQL = substr($SQL, 0, -1); + $sql = substr($sql, 0, -1); // Add SQL tail data - $SQL .= " WHERE id='%s' AND password='%s' LIMIT 1"; + $sql .= " WHERE id='%s' AND password='%s' LIMIT 1"; $DATA[] = bigintval(get_session('sponsorid')); $DATA[] = get_session('sponsorpass'); @@ -456,11 +443,11 @@ function SPONSOR_SAVE_DATA ($POST, $content) { { case "account": // Change account data if ($EMAIL === true) { - $MSG = getMessage('SPONSOR_ACCOUNT_EMAIL_CHANGED'); + $message = getMessage('SPONSOR_ACCOUNT_EMAIL_CHANGED'); $templ = "admin_sponsor_change_email"; $subj = getMessage('ADMIN_SPONSOR_ACC_EMAIL_SUBJ'); } else { - $MSG = getMessage('SPONSOR_ACCOUNT_DATA_SAVED'); + $message = getMessage('SPONSOR_ACCOUNT_DATA_SAVED'); $templ = "admin_sponsor_change_data"; $subj = getMessage('ADMIN_SPONSOR_ACC_DATA_SUBJ'); } @@ -472,14 +459,14 @@ function SPONSOR_SAVE_DATA ($POST, $content) { $content['interval'] = CREATE_FANCY_TIME($content['warning_interval']); // Set message template and subject for admin - $MSG = getMessage('SPONSOR_SETTINGS_SAVED'); + $message = getMessage('SPONSOR_SETTINGS_SAVED'); $templ = "admin_sponsor_settings"; $subj = getMessage('ADMIN_SPONSOR_SETTINGS_SUBJ'); break; default: // Unknown sponsor what value! DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Unknown sponsor module (what) %s detected.", $GLOBALS['what'])); - $MSG = SPONSOR_UNKNOWN_WHAT_1.$GLOBALS['what'].SPONSOR_UNKNOWN_WHAT_2; + $message = sprintf(getMessage('SPONSOR_UNKNOWN_WHAT'), $GLOBALS['what']); $templ = ""; $subj = ""; break; } @@ -487,7 +474,7 @@ function SPONSOR_SAVE_DATA ($POST, $content) { if (SQL_AFFECTEDROWS() == 1) { if (!empty($templ) && !empty($subj)) { // Run SQL command and check for success - $result = SQL_QUERY_ESC($SQL, $DATA, __FILE__, __LINE__); + $result = SQL_QUERY_ESC($sql, $DATA, __FUNCTION__, __LINE__); // Add all data to content global $DATA; @@ -530,12 +517,12 @@ function SPONSOR_SAVE_DATA ($POST, $content) { SEND_EMAIL($content['email'], getMessage('SPONSOR_SETTINGS_SUBJ'), $email_msg); break; } - } - } - } + } // END - if + } // END - if + } // END - if // Return final message - return $MSG; + return $message; } //