<?php
/************************************************************************
- * MXChange v0.2.1 Start: 08/26/2003 *
- * =============== Last change: 11/29/2004 *
+ * Mailer v0.2.1-FINAL Start: 08/26/2003 *
+ * =================== Last change: 11/29/2004 *
* *
* -------------------------------------------------------------------- *
* File : mysql-manager.php *
if (empty($title)) {
// No name found
$title = sprintf("%s (%s)", getMessage('LANG_UNKNOWN_MODULE'), $mod);
- if (SQL_NUMROWS($result) == 0) {
+ if (SQL_NUMROWS($result) == '0') {
// Add module to database
$dummy = checkModulePermissions($mod);
} // END - if
// "Getter" for module description
// @TODO Can we cache this?
-function getModuleDescription ($mode, $what, $column = 'what') {
+function getTitleFromMenu ($mode, $what, $column = 'what', $ADD='') {
// Fix empty 'what'
if (empty($what)) {
$what = getConfig('index_home');
$ret = '??? (' . $what . ')';
// Look for title
- $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE %s='%s' LIMIT 1",
- array($mode, $column, $what), __FUNCTION__, __LINE__);
+ $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `%s`='%s'" . $ADD . " LIMIT 1",
+ array(
+ $mode,
+ $column,
+ $what
+ ), __FUNCTION__, __LINE__);
// Is there an entry?
if (SQL_NUMROWS($result) == 1) {
// Destroy cache here
// @TODO Rewrite this to a filter
- if ((getOutputMode() == 0) || (getOutputMode() == -1)) rebuildCacheFile('modules', 'modules');
+ if ((getOutputMode() == '0') || (getOutputMode() == -1)) rebuildCacheFile('modules', 'modules');
// And reload data
unset($GLOBALS['module_status'][$mod]);
// Module not found we don't add it to the database
$ret = '404';
}
- } elseif (($ret == 'cache_miss') && (getOutputMode() == 0)) {
+ } elseif (($ret == 'cache_miss') && (getOutputMode() == '0')) {
// Rebuild the cache files
rebuildCacheFile('modules', 'modules');
} elseif ($found === false) {
}
// Add menu description pending on given file name (without path!)
-function addMenuDescription ($accessLevel, $FQFN, $return = false, $output = true) {
+function addMenuDescription ($accessLevel, $FQFN, $return = false) {
// Use only filename of the FQFN...
$file = basename($FQFN);
// Init variables
$LINK_ADD = '';
$OUT = '';
- $AND = '';
+ $ADD = '';
// First we have to do some analysis...
if (substr($file, 0, 7) == 'action-') {
// This is an action file!
$type = 'action';
$search = substr($file, 7);
- switch ($accessLevel) {
- case 'admin':
- $modCheck = 'admin';
- break;
-
- case 'sponsor':
- case 'guest':
- case 'member':
- $modCheck = getModule();
- break;
- }
- $AND = " AND (`what`='' OR `what` IS NULL)";
+
+ // Get access level from it
+ $modCheck = getModuleFromFileName($file, $accessLevel);
+
+ // Add what
+ $ADD = " AND (`what`='' OR `what` IS NULL)";
} elseif (substr($file, 0, 5) == 'what-') {
- // This is an admin what file!
+ // This is a 'what file'!
$type = 'what';
$search = substr($file, 5);
- $AND = '';
- switch ($accessLevel) {
- case 'admin':
- $modCheck = 'admin';
- break;
-
- case 'guest':
- case 'member':
- $modCheck = getModule();
- if (!isAdmin()) {
- $AND = " AND `visible`='Y' AND `locked`='N'";
- }
- break;
- }
+ $ADD = " AND `visible`='Y' AND `locked`='N'";
+
+ // Get access level from it
+ $modCheck = getModuleFromFileName($file, $accessLevel);
+
+ // Do we have admin? Then display all
+ if (isAdmin()) $ADD = '';
$dummy = substr($search, 0, -4);
- $AND .= " AND `action`='".getModeAction($accessLevel, $dummy)."'";
- } elseif (($accessLevel == 'sponsor') || ($accessLevel == "engine")) {
+ $ADD .= " AND `action`='".getModeAction($accessLevel, $dummy)."'";
+ } elseif (($accessLevel == 'sponsor') || ($accessLevel == 'engine')) {
// Sponsor / engine menu
$type = 'what';
$search = $file;
$modCheck = getModule();
- $AND = '';
+ $ADD = '';
} else {
// Other
$type = 'menu';
$search = $file;
$modCheck = getModule();
- $AND = '';
+ $ADD = '';
}
// Begin the navigation line
if ((!isset($GLOBALS['nav_depth'])) && ($return === false)) {
- $GLOBALS['nav_depth'] = 0;
- $prefix = "<div class=\"you_are_here\">{--YOU_ARE_HERE--} <strong><a class=\"you_are_here\" href=\"{?URL?}/modules.php?module=".getModule().$LINK_ADD."\">Home</a></strong>";
+ $GLOBALS['nav_depth'] = '0';
+ $prefix = "<div class=\"you_are_here\">{--YOU_ARE_HERE--} <strong><a class=\"you_are_here\" href=\"{%url=modules.php?module=" . getModule() . $LINK_ADD . "%}\">Home</a></strong>";
} else {
if ($return === false) $GLOBALS['nav_depth']++;
$prefix = '';
$search = substr($search, 0, -4);
} // END - i
- // Get the title from menu
- $result = SQL_QUERY_ESC("SELECT title FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE %s='%s' ".$AND." LIMIT 1",
- array($accessLevel, $type, $search), __FUNCTION__, __LINE__);
+ if (((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (getConfig('youre_here') == 'Y')) || ((isAdmin()) && ($modCheck == 'admin'))) {
+ // Output HTML code
+ $OUT = $prefix . "<strong><a class=\"you_are_here\" href=\"{%url=modules.php?module=" . $modCheck . '&' . $type . '=' . $search . $LINK_ADD . "%}\">" . getTitleFromMenu($accessLevel, $search, $type, $ADD) . "</a></strong>\n";
- // Menu found?
- if (SQL_NUMROWS($result) == 1) {
- // Load title
- list($ret) = SQL_FETCHROW($result);
+ // Can we close the you-are-here navigation?
+ //* DEBUG: */ print(__LINE__."*".$type.'/'.getWhat()."*<br />");
+ if (($type == 'what') || (($type == 'action') && ((!isWhatSet()) || (getWhat() == 'overview')))) {
+ //* DEBUG: */ print(__LINE__.'+'.$type."+<br />");
+ // Add closing div and br-tag
+ $OUT .= "</div><br />\n";
+ $GLOBALS['nav_depth'] = '0';
- // Shall we return it?
- if ($return === true) {
- // Return title
- return $ret;
- } elseif (((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (getConfig('youre_here') == 'Y')) || ((isAdmin()) && ($modCheck == 'admin'))) {
- // Output HTML code
- $OUT = $prefix . "<strong><a class=\"you_are_here\" href=\"{?URL?}/modules.php?module=" . $modCheck . '&' . $type . '=' . $search.$LINK_ADD . "\">" . $ret . "</a></strong>\n";
-
- // Can we close the you-are-here navigation?
- //* DEBUG: */ print(__LINE__."*".$type.'/'.getWhat()."*<br />");
- if (($type == 'what') || (($type == 'action') && ((!isWhatSet()) || (getWhat() == 'overview')))) {
- //* DEBUG: */ print(__LINE__.'+'.$type."+<br />");
- // Add closing div and br-tag
- $OUT .= "</div><br />\n";
- $GLOBALS['nav_depth'] = 0;
-
- // Run the filter chain
- $ret = runFilterChain('post_youhere_line', array('access_level' => $accessLevel, 'type' => $type, 'content' => ""));
- $OUT .= $ret['content'];
- } // END - if
- }
- } // END - if
+ // Run the filter chain
+ $ret = runFilterChain('post_youhere_line', array('access_level' => $accessLevel, 'type' => $type, 'content' => ''));
- // Free result
- SQL_FREERESULT($result);
+ // Add additional content
+ $OUT .= $ret['content'];
+ } // END - if
+ }
// Return or output HTML code?
- if ($output) {
- // Output HTML code here
- outputHtml($OUT);
- } else {
+ if ($return === true) {
// Return HTML code
return $OUT;
+ } else {
+ // Output HTML code here
+ outputHtml($OUT);
}
}
// Adds a menu (mode = guest/member/admin/sponsor) to output
function addMenu ($mode, $action, $what) {
// Init some variables
- $main_cnt = 0;
- $AND = '';
+ $main_cnt = '0';
+ $ADD = '';
// is the menu action valid?
if (!isMenuActionValid($mode, $action, $what, true)) {
// Non-admin shall not see all menus
if (!isAdmin()) {
- $AND = " AND `visible`='Y' AND `locked`='N'";
+ $ADD = " AND `visible`='Y' AND `locked`='N'";
} // END - if
// Load SQL data and add the menu to the output stream...
- $result_main = SQL_QUERY_ESC("SELECT `title`, `action` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE (`what`='' OR `what` IS NULL)".$AND." ORDER BY `sort` ASC",
+ $result_main = SQL_QUERY_ESC("SELECT `title`, `action` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE (`what`='' OR `what` IS NULL)".$ADD." ORDER BY `sort` ASC",
array($mode), __FUNCTION__, __LINE__);
//* DEBUG: */ print(__LINE__.'/'.$main_cnt.':'.getWhat()."*<br />");
$GLOBALS['rows'] .= loadTemplate($mode . '_menu_title', true, $content);
// Sub menu
- $result_sub = SQL_QUERY_ESC("SELECT `title` AS sub_title, `what` AS sub_what FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ".$AND." ORDER BY `sort`",
+ $result_sub = SQL_QUERY_ESC("SELECT `title` AS sub_title, `what` AS sub_what FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ".$ADD." ORDER BY `sort`",
array($mode, $content['action']), __FUNCTION__, __LINE__);
// Get number of rows
// Do we have some entries?
if ($totalWhats > 0) {
// Init counter
- $cnt = 0;
+ $cnt = '0';
// Load all sub menus
while ($content2 = SQL_FETCHARRAY($result_sub)) {
} // END - if
// Navigation link
- $OUT .= "<a name=\"menu\" class=\"menu_blur\" href=\"{?URL?}/modules.php?module=".getModule()."&what=".$content['sub_what']."\" target=\"_self\">";
+ $OUT .= "<a name=\"menu\" class=\"menu_blur\" href=\"{%url=modules.php?module=" . getModule() . '&what=' . $content['sub_what'] . "%}\" target=\"_self\">";
} else {
// Not found! - open
$OUT .= "<em style=\"cursor:help\" class=\"admin_note\" title=\"{--MENU_WHAT_404--}\">";
if (isset($GLOBALS['is_member'])) {
// Then return it
return $GLOBALS['is_member'];
- } // END - if
+ } elseif (getMemberId() == '0') {
+ // No member
+ return false;
+ } else {
+ // Transfer userid=>current
+ setCurrentUserid(getMemberId());
+ }
- // Init global 'status'
- $GLOBALS['status'] = false;
+ // Init global user data array
+ initUserData();
// Fix "deleted" cookies first
fixDeletedCookies(array('userid', 'u_hash'));
// Are cookies set?
- if ((isUserIdSet()) && (isSessionVariableSet('u_hash'))) {
+ if ((isMemberIdSet()) && (isSessionVariableSet('u_hash'))) {
// Cookies are set with values, but are they valid?
- $result = SQL_QUERY_ESC("SELECT `password`, `status`, `last_module`, `last_online` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
- array(getUserId()), __FUNCTION__, __LINE__);
- if (SQL_NUMROWS($result) == 1) {
- // Load data from cookies
- list($password, $GLOBALS['status'], $mod, $onl) = SQL_FETCHROW($result);
-
+ if (fetchUserData(getMemberId()) === true) {
// Validate password by created the difference of it and the secret key
- $valPass = generatePassString($password);
+ $valPass = generatePassString(getUserData('password'));
// Transfer last module and online time
- if ((!empty($mod)) && (empty($GLOBALS['last_online']['module']))) {
- // @TODO Try to rewrite this to one or more functions
- $GLOBALS['last_online']['module'] = $mod;
- $GLOBALS['last_online']['online'] = $onl;
- } // END - if
+ $GLOBALS['last_online']['module'] = getUserData('last_module');
+ $GLOBALS['last_online']['online'] = getUserData('last_online');
// So did we now have valid data and an unlocked user?
- if (($GLOBALS['status'] == 'CONFIRMED') && ($valPass == getSession('u_hash'))) {
+ if ((getUserData('status') == 'CONFIRMED') && ($valPass == getSession('u_hash'))) {
// Account is confirmed and all cookie data is valid so he is definely logged in! :-)
$ret = true;
} else {
// Maybe got locked etc.
- //* DEBUG: */ print(__LINE__."!!!<br />");
- destroyUserSession();
+ logDebugMessage(__FUNCTION__, __LINE__, 'status=' . getUserData('status'));
+ destroyMemberSession();
}
} else {
// Cookie data is invalid!
- //* DEBUG: */ print(__LINE__."***<br />");
- destroyUserSession();
+ destroyMemberSession();
}
-
- // Free memory
- SQL_FREERESULT($result);
} else {
// Cookie data is invalid!
- //* DEBUG: */ print(__LINE__."///<br />");
- destroyUserSession();
+ destroyMemberSession();
}
// Cache status
return $ret;
}
+// Fetch user data for given user id
+function fetchUserData ($userid, $column = 'userid') {
+ // If we should look for userid secure&set it here
+ if (substr($column, -2, 2) == 'id') {
+ // Secure userid
+ $userid = bigintval($userid);
+
+ // Set it here
+ setCurrentUserId($userid);
+
+ // Don't look for invalid userids...
+ if ($userid < 1) {
+ // Invalid, so abort here
+ debug_report_bug('User id ' . $userid . ' is invalid.');
+ } elseif (isUserDataValid()) {
+ // Use cache, so it is fine
+ return true;
+ }
+ } elseif (isUserDataValid()) {
+ // Use cache, so it is fine
+ return true;
+ }
+
+
+ // By default none was found
+ $found = false;
+
+ // Query for the user
+ $result = SQL_QUERY_ESC("SELECT * FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `%s`='%s' LIMIT 1",
+ array($column, $userid), __FUNCTION__, __LINE__);
+
+ // Do we have a record?
+ if (SQL_NUMROWS($result) == 1) {
+ // Load data from cookies
+ $data = SQL_FETCHARRAY($result);
+
+ // Set the userid for later use
+ setCurrentUserId($data['userid']);
+ $GLOBALS['user_data'][getCurrentUserId()] = $data;
+
+ // Rewrite 'last_failure' if found
+ if (isset($GLOBALS['user_data'][getCurrentUserId()]['last_failure'])) {
+ // Backup the raw one and zero it
+ $GLOBALS['user_data'][getCurrentUserId()]['last_failure_raw'] = $GLOBALS['user_data'][getCurrentUserId()]['last_failure'];
+ $GLOBALS['user_data'][getCurrentUserId()]['last_failure'] = '0';
+
+ // Is it not zero?
+ if ($GLOBALS['user_data'][getCurrentUserId()]['last_failure_raw'] != '0000-00-00 00:00:00') {
+ // Seperate data/time
+ $array = explode(' ', $GLOBALS['user_data'][getCurrentUserId()]['last_failure_raw']);
+
+ // Seperate data and time again
+ $array['date'] = explode('-', $array[0]);
+ $array['time'] = explode(':', $array[1]);
+
+ // Now pass it to mktime()
+ $GLOBALS['user_data'][getCurrentUserId()]['last_failure'] = mktime(
+ $array['time'][0],
+ $array['time'][1],
+ $array['time'][2],
+ $array['date'][1],
+ $array['date'][2],
+ $array['date'][0]
+ );
+ } // END - if
+ } // END - if
+
+ // Found, but valid?
+ $found = isUserDataValid();
+ } // END - if
+
+ // Free memory
+ SQL_FREERESULT($result);
+
+ // Return result
+ return $found;
+}
+
// This patched function will reduce many SELECT queries for the specified or current admin login
function isAdmin ($admin = '') {
// Init variables
// Checks wether the given email address is used.
function isEmailTaken ($email) {
// Query the database
- $result = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE email LIKE '{PER}%s{PER}' LIMIT 1",
- array($email), __FUNCTION__, __LINE__);
+ $result = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `email` LIKE '{PER}%s{PER}' OR `email` LIKE '{PER}%s{PER}' LIMIT 1",
+ array($email, str_replace('.', '{DOT}', $email)), __FUNCTION__, __LINE__);
// Is the email there?
$ret = (SQL_NUMROWS($result) == 1);
// Run SQL command
$result = SQL_QUERY($sql, __FUNCTION__, __LINE__);
+
+ // Should we look for affected rows (only update) or found rows?
if ($updateEntry === true) {
// Check updated/affected rows
$ret = (SQL_AFFECTEDROWS() == 1);
return $ret;
}
-//
-function sendModeMails ($mod, $modes) {
- // Load hash
- $result_main = SQL_QUERY_ESC("SELECT `password` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s AND `status`='CONFIRMED' LIMIT 1",
- array(getUserId()), __FUNCTION__, __LINE__);
- if (SQL_NUMROWS($result_main) == 1) {
- // Load hash from database
- list($hashDB) = SQL_FETCHROW($result_main);
-
- // Extract salt from cookie
- $salt = substr(getSession('u_hash'), 0, -40);
-
- // Now let's compare passwords
- $hash = generatePassString($hashDB);
- if (($hash == getSession('u_hash')) || (postRequestElement('pass1') == postRequestElement('pass2'))) {
- // Load user's data 0 1 2 3 4 5 6 7
- $result = SQL_QUERY_ESC("SELECT gender, surname, family, street_nr, country, zip, city, email FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s AND password='%s' LIMIT 1",
- array(getUserId(), $hashDB), __FUNCTION__, __LINE__);
- if (SQL_NUMROWS($result) == 1) {
- // Load the data
- $content = SQL_FETCHARRAY($result, 0, false);
-
- // Free result
- SQL_FREERESULT($result);
-
- // Translate gender
- $content['gender'] = translateGender($content['gender']);
-
- // Clear/init the content variable
- $content['info'] = '';
-
- switch ($mod) {
- case 'mydata':
- foreach ($modes as $mode) {
- switch ($mode) {
- case 'normal': break; // Do not add any special lines
- case 'email': // Email was changed!
- $content['message'] = getMessage('MEMBER_CHANGED_EMAIL').": ".postRequestElement('old_email')."\n";
- break;
-
- case 'pass': // Password was changed
- $content['message'] = getMessage('MEMBER_CHANGED_PASS')."\n";
- break;
-
- default:
- logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown mode %s detected.", $mode));
- $content['message'] = getMessage('MEMBER_UNKNOWN_MODE').": ".$mode."\n\n";
- break;
- } // END - switch
- } // END - if
-
- if (isExtensionActive('country')) {
- // Replace code with description
- $content['country'] = generateCountryInfo(postRequestElement('country_code'));
- } // END - if
-
- // Merge content with data from POST
- $content = merge_array($content, postRequestArray());
-
- // Load template
- $message = loadEmailTemplate('member_mydata_notify', $content, getUserId());
-
- if (getConfig('admin_notify') == 'Y') {
- // The admin needs to be notified about a profile change
- $message_admin = 'admin_mydata_notify';
- $sub_adm = getMessage('ADMIN_CHANGED_DATA');
- } else {
- // No mail to admin
- $message_admin = '';
- $sub_adm = '';
- }
-
- // Set subject lines
- $sub_mem = getMessage('MEMBER_CHANGED_DATA');
-
- // Output success message
- $content = "<span class=\"member_done\">{--MYDATA_MAIL_SENT--}</span>";
- break;
-
- default: // Unsupported module!
- logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unsupported module %s detected.", $mod));
- $content = "<span class=\"member_failed\">{--UNKNOWN_MODULE--}</span>";
- break;
- } // END - switch
- } else {
- // Could not load profile data
- $content = "<span class=\"member_failed\">{--MEMBER_CANNOT_LOAD_PROFILE--}</span>";
- }
- } else {
- // Passwords mismatch
- $content = "<span class=\"member_failed\">{--MEMBER_PASSWORD_ERROR--}</span>";
- }
- } else {
- // Could not load profile
- $content = "<span class=\"member_failed\">{--MEMBER_CANNOT_LOAD_PROFILE--}</span>";
- }
-
- // Send email to user if required
- if ((!empty($sub_mem)) && (!empty($message))) {
- // Send member mail
- sendEmail($content['email'], $sub_mem, $message);
- } // END - if
-
- // Send only if no other error has occured
- if (empty($content)) {
- if ((!empty($sub_adm)) && (!empty($message_admin))) {
- // Send admin mail
- sendAdminNotification($sub_adm, $message_admin, $content, getUserId());
- } elseif (getConfig('admin_notify') == 'Y') {
- // Cannot send mails to admin!
- $content = getMessage('CANNOT_SEND_ADMIN_MAILS');
- } else {
- // No mail to admin
- $content = "<span class=\"member_done\">{--MYDATA_MAIL_SENT--}</span>";
- }
- } // END - if
-
- // Load template
- loadTemplate('admin_settings_saved', false, $content);
-}
-
// Get action value from mode (admin/guest/member) and what-value
function getModeAction ($mode, $what) {
// Init status
$ret = '';
//* DEBUG: */ print(__LINE__.'='.$mode.'/'.$what.'/'.getAction()."=<br />");
- if ((empty($what)) && ($mode != 'admin')) {
+ if (!isExtensionInstalledAndNewer('sql_patches', '0.0.5')) {
+ // sql_patches is missing so choose depending on mode
+ if (isWhatSet()) {
+ // Use setted what
+ $what = getWhat();
+ } elseif ($mode == 'admin') {
+ // Admin area
+ $what = 'overview';
+ } else {
+ // Everywhere else
+ $what = 'welcome';
+ }
+ } elseif ((empty($what)) && ($mode != 'admin')) {
+ // Use configured 'home'
$what = getConfig('index_home');
} // END - if
// Free memory
SQL_FREERESULT($result);
- } elseif ((!isExtensionInstalled('sql_patches')) && ($mode != 'admin')) {
+ } elseif ((!isExtensionInstalled('sql_patches')) && (($mode != 'admin') && ($mode != 'unknown'))) {
// No sql_patches installed, but maybe we need to register an admin?
if (isAdminRegistered()) {
// Redirect to admin area
$ret = getMessage('_CATEGORY_404');
// Is the category id set?
- if ($cid == 0) {
+ if ($cid == '0') {
// No category
$ret = getMessage('_CATEGORY_NONE');
} elseif ($cid > 0) {
return $ret;
}
-// Remove a receiver's ID from $receivers and add a link for him to confirm
+// Remove a receiver's id from $receivers and add a link for him to confirm
function removeReceiver (&$receivers, $key, $userid, $pool_id, $stats_id = '', $bonus = false) {
// Default is not removed
$ret = 'failed';
// Is there already a line for this user available?
if ($stats_id > 0) {
- // Only when we got a real stats ID continue searching for the entry
+ // Only when we got a real stats id continue searching for the entry
$type = 'NORMAL'; $rowName = 'stats_id';
if ($bonus) { $type = 'BONUS'; $rowName = 'bonus_id'; }
array($rowName, $stats_id, bigintval($userid), $type), __FUNCTION__, __LINE__);
// Was it *not* found?
- if (SQL_NUMROWS($result) == 0) {
+ if (SQL_NUMROWS($result) == '0') {
// So we add one!
SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_links` (`%s`, `userid`, `link_type`) VALUES ('%s','%s','%s')",
array($rowName, $stats_id, bigintval($userid), $type), __FUNCTION__, __LINE__);
// Calculate sum (default) or count records of given criteria
function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatement = 'userid', $countRows = false, $add = '') {
- $ret = 0;
+ $ret = '0';
//* DEBUG: */ print($search.'/'.$tableName.'/'.$lookFor.'/'.$whereStatement.'/'.$add.'<br />');
if ((empty($search)) && ($search != '0')) {
// Count or sum whole table?
$ret = '0.00000';
} elseif (''.$ret.'' == '') {
// Fix empty result
- $ret = 0;
+ $ret = '0';
}
// Return value
+ //* DEBUG: */ print 'ret='.$ret.'<br />';
return $ret;
}
// Getter fro ref level percents
function getReferalLevelPercents ($level) {
// Default is zero
- $per = 0;
+ $per = '0';
// Do we have cache?
if ((isset($GLOBALS['cache_array']['refdepths']['level'])) && (isExtensionActive('cache'))) {
* Dynamic referal system, can also send mails!
*
* subject = Subject line, write in lower-case letters and underscore is allowed
- * userid = Referal ID wich should receive...
+ * userid = Referal id wich should receive...
* points = ... xxx points
* sendNotify = shall I send the referal an email or not?
* rid = inc/modules/guest/what-confirm.php need this
* add_mode = Add points only to $userid or also refs? (WARNING! Changing 'ref' to 'direct'
* for default value will cause no referal will get points ever!!!)
*/
-function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify = false, $rid = 0, $locked = false, $add_mode = 'ref') {
+function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify = false, $rid = '0', $locked = false, $add_mode = 'ref') {
//* DEBUG: */ print("----------------------- <font color=\"#00aa00\">".__FUNCTION__." - ENTRY</font> ------------------------<ul><li>\n");
// Convert mode to lower-case
$add_mode = strtolower($add_mode);
- // When $userid = 0 add points to jackpot
- if (($userid == 0) && (isExtensionActive('jackpot'))) {
+ // When $userid = '0' add points to jackpot
+ if (($userid == '0') && (isExtensionActive('jackpot'))) {
// Add points to jackpot
addPointsToJackpot($points);
return;
if (!isset($GLOBALS['ref_level'])) {
// Initialialize referal system
//* DEBUG: */ print(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): Referal system initialized!<br />");
- $GLOBALS['ref_level'] = 0;
+ $GLOBALS['ref_level'] = '0';
} else {
// Increase referal level
$GLOBALS['ref_level']++;
if ($locked === true) $data = 'locked_points';
// Check user account
- $result_user = SQL_QUERY_ESC("SELECT `refid`, `email` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s AND `status`='CONFIRMED' LIMIT 1",
- array(bigintval($userid)), __FUNCTION__, __LINE__);
-
- //* DEBUG: */ print(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):userid={$userid},numRows=".SQL_NUMROWS($result_user).",points={$points}<br />");
- if (SQL_NUMROWS($result_user) == 1) {
+ //* DEBUG: */ print(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):userid={$userid},points={$points}<br />");
+ if (fetchUserData($userid)) {
// This is the user and his ref
- list($ref, $email) = SQL_FETCHROW($result_user);
- $GLOBALS['cache_array']['add_userid'][$ref] = $userid;
+ $GLOBALS['cache_array']['add_userid'][getUserData('refid')] = $userid;
// Get percents
$per = getReferalLevelPercents($GLOBALS['ref_level']);
} // END - if
// Points updated, maybe I shall send him an email?
- if (($sendNotify === true) && ($ref > 0) && ($locked === false)) {
+ if (($sendNotify === true) && (getUserData('refid') > 0) && ($locked === false)) {
// Prepare content
$content = array(
'percents' => $per,
'level' => bigintval($GLOBALS['ref_level']),
'points' => $ref_points,
- 'refid' => bigintval($ref)
+ 'refid' => getUserData('refid')
);
// Load email template
$message = loadEmailTemplate('confirm-referal', $content, bigintval($userid));
- sendEmail($email, THANX_REFERRAL_ONE, $message);
- } elseif (($sendNotify) && ($ref == 0) && ($locked === false) && ($add_mode == 'direct')) {
+ // Send email
+ sendEmail($userid, getMessage('THANX_REFERAL_ONE_SUBJECT'), $message);
+ } elseif (($sendNotify) && (getUserData('refid') == '0') && ($locked === false) && ($add_mode == 'direct')) {
// Prepare content
$content = array(
'text' => getMessage('REASON_DIRECT_PAYMENT'),
$message = loadEmailTemplate('add-points', $content, $userid);
// And sent it away
- sendEmail($email, getMessage('SUBJECT_DIRECT_PAYMENT'), $message);
+ sendEmail($userid, getMessage('SUBJECT_DIRECT_PAYMENT'), $message);
if (!isGetRequestElementSet('mid')) loadTemplate('admin_settings_saved', false, getMessage('ADMIN_POINTS_ADDED'));
}
// Maybe there's another ref?
- if (($ref > 0) && ($points > 0) && ($ref != $userid) && ($add_mode == 'ref')) {
+ if ((getUserData('refid') > 0) && ($points > 0) && (getUserData('refid') != $userid) && ($add_mode == 'ref')) {
// Then let's credit him here...
- //* DEBUG: */ print(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):userid={$userid},ref={$ref},points={$points} - ADVANCE!<br />");
- addPointsThroughReferalSystem(sprintf("%s_ref:%s", $subject, $GLOBALS['ref_level']), $ref, $points, $sendNotify, $ref, $locked);
+ //* DEBUG: */ print(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):userid={$userid},ref=".getUserData('refid').",points={$points} - ADVANCE!<br />");
+ addPointsThroughReferalSystem(sprintf("%s_ref:%s", $subject, $GLOBALS['ref_level']), getUserData('refid'), $points, $sendNotify, getUserData('refid'), $locked);
} // END - if
} // END - if
} // END - if
- // Free result
- SQL_FREERESULT($result_user);
//* DEBUG: */ print("</li></ul>----------------------- <font color=\"#aa0000\">".__FUNCTION__." - EXIT</font> ------------------------<br />");
}
//* DEBUG: */ print(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):userid={$userid}<br />");
} // END - if
- // Check for his referal
- $result = SQL_QUERY_ESC("SELECT `refid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
- array(bigintval($userid)), __FUNCTION__, __LINE__);
+ // Init referal id
+ $ref = '0';
- // Load refid
- list($ref) = SQL_FETCHROW($result);
+ // Check for his referal
+ if (fetchUserData($userid)) {
+ // Get it
+ $ref = getUserData('refid');
+ } // END - if
- // Free memory
- SQL_FREERESULT($result);
//* DEBUG: */ print(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):userid={$userid},ref={$ref}<br />");
// When he has a referal...
if (($ref > 0) && ($ref != $userid)) {
// Move to next referal level and count his counter one up!
//* DEBUG: */ print(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):ref={$ref} - ADVANCE!<br />");
- $GLOBALS['cache_array']['ref_level'][$userid]++; updateReferalCounter($ref);
- } elseif ((($ref == $userid) || ($ref == 0)) && (getExtensionVersion('cache') >= '0.1.2')) {
+ $GLOBALS['cache_array']['ref_level'][$userid]++;
+ updateReferalCounter($ref);
+ } elseif ((($ref == $userid) || ($ref == '0')) && (isExtensionInstalledAndNewer('cache', '0.1.2'))) {
// Remove cache here
//* DEBUG: */ print(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):ref={$ref} - CACHE!<br />");
rebuildCacheFile('refsystem', 'refsystem');
// Really simple... ;-)
}
-// Get ID number from administrator's login name
+// Get id number from administrator's login name
function getAdminId ($login) {
// By default no admin is found
$ret = '-1';
$ret = '';
if ($table == '/ARRAY/') {
// Selection from array
- if (is_array($id) && is_array($name) && count($id) == count($name)) {
+ if ((is_array($id)) && (is_array($name)) && (count($id)) == (count($name))) {
// Both are arrays
foreach ($id as $idx => $value) {
$ret .= '<option value="' . $value . '"';
if ($default == $value) $ret .= ' selected="selected"';
$ret .= '>' . $name[$idx] . '</option>';
} // END - foreach
- } // END - if
+ } else {
+ // Problem in request
+ debug_report_bug('Not all are arrays: id[' . count($id) . ']=' . gettype($id) . ',name[' . count($name) . ']=' . gettype($name));
+ }
} else {
// Data from database
- $SPEC = ', '.$id;
- if (!empty($special)) $SPEC = ', ' . $special;
- $ORDER = $name.$SPEC;
- if ($table == 'country') $ORDER = $special;
- $result = SQL_QUERY_ESC("SELECT %s, %s".$SPEC." FROM `{?_MYSQL_PREFIX?}_%s` ".$where." ORDER BY %s",
- array($id, $ORDER, $table, $name), __FUNCTION__, __LINE__);
+ $SPEC = ', `' . $id . '`';
+ if (!empty($special)) $SPEC = ', `' . $special . '`';
+
+ // Query the database
+ $result = SQL_QUERY_ESC("SELECT `%s`, `%s`".$SPEC." FROM `{?_MYSQL_PREFIX?}_%s` ".$where." ORDER BY `%s` ASC",
+ array(
+ $id,
+ $name,
+ $table,
+ $name
+ ), __FUNCTION__, __LINE__);
+
+ // Do we have rows?
if (SQL_NUMROWS($result) > 0) {
// Found data so add them as OPTION lines: $id is the value and $name is the "name" of the option
// @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
if (!empty($add)) $add = ' ('.$add.')';
$ret .= '>' . $title . $add . '</option>';
} // END - while
-
- // Free memory
- SQL_FREERESULT($result);
} else {
// No data found
$ret = '<option value="x">{--SELECT_NONE--}</option>';
}
+
+ // Free memory
+ SQL_FREERESULT($result);
}
// Return - hopefully - the requested data
// Activate exchange
function FILTER_ACTIVATE_EXCHANGE () {
// Is the extension 'user' there?
- if ((!isExtensionActive('user')) || (getConfig('activate_xchange') == 0)) {
+ if ((!isExtensionActive('user')) || (getConfig('activate_xchange') == '0')) {
// Silently abort here
return false;
} // END - if
// Deletes a user account with given reason
function deleteUserAccount ($userid, $reason) {
- $points = 0;
+ $points = '0';
$result = SQL_QUERY_ESC("SELECT
(SUM(p.points) - d.used_points) AS points
FROM
SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `userid`=%s", array(bigintval($userid)), __FUNCTION__, __LINE__);
// Update mediadata as well
- if (getExtensionVersion('mediadata') >= '0.0.4') {
+ if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
// Update database
updateMediadataEntry(array('total_points'), 'sub', $points);
} // END - if
// Exclude admin and member's area
if (($mod != 'admin') && ($mod != 'login')) {
// Construct dynamic description
- $DESCR = '{?MAIN_TITLE?} '.trim(getConfig('title_middle')) . ' ' . addMenuDescription('guest', 'what-'.$what, true);
+ $DESCR = '{?MAIN_TITLE?} '.trim(getConfig('title_middle')) . ' ' . getTitleFromMenu('guest', $what);
// Output it directly
outputHtml('<meta name="description" content="' . $DESCR . '" />');
);
// Get categories
- $result = SQL_QUERY("SELECT id, cat FROM `{?_MYSQL_PREFIX?}_cats`".$whereStatement." ORDER BY `sort`", __FUNCTION__, __LINE__);
+ $result = SQL_QUERY("SELECT `id`, `cat` FROM `{?_MYSQL_PREFIX?}_cats`".$whereStatement." ORDER BY `sort` ASC",
+ __FUNCTION__, __LINE__);
+
+ // Do we have entries?
if (SQL_NUMROWS($result) > 0) {
// ... and begin loading stuff
while ($content = SQL_FETCHARRAY($result)) {
array(bigintval($content['id'])), __FUNCTION__, __LINE__);
// Start adding all
- $userid_cnt = 0;
+ $userid_cnt = '0';
// @TODO Rewrite this to $content = SQL_FETCHARRAY()
while (list($ucat) = SQL_FETCHROW($result_userids)) {
$result_ver = SQL_QUERY_ESC("SELECT
FROM
`{?_MYSQL_PREFIX?}_user_data`
WHERE
- `userid`=%s AND `status`='CONFIRMED' AND `receive_mails` > 0".runFilterChain('exclude_users', $mode)."
+ `userid`=%s AND
+ `status`='CONFIRMED' AND
+ `receive_mails` > 0".runFilterChain('exclude_users', $mode)."
LIMIT 1",
array(bigintval($ucat)), __FUNCTION__, __LINE__);
$target = countSelection(explode(';', $receiverList));
// Receiver is zero?
- if ($receiver == 0) {
+ if ($receiver == '0') {
// Then auto-fix it
$receiver = $target;
} // END - if
$receiver = bigintval($receiver);
// Is the receiver zero and mode set?
- if (($receiver == 0) && (!empty($mode))) {
+ if (($receiver == '0') && (!empty($mode))) {
// Auto-fix receiver maximum
$receiver = getTotalReceivers($mode);
} // END - if
}
// Get timestamp for given stats type and data
-function getTimestampFromUserStats ($type, $data, $userid = 0) {
+function getTimestampFromUserStats ($type, $data, $userid = '0') {
// Default timestamp is zero
- $stamp = 0;
+ $stamp = '0';
// User id set?
- if ((isUserIdSet()) && ($userid == 0)) {
- $userid = getUserId();
+ if ((isMemberIdSet()) && ($userid == '0')) {
+ $userid = getMemberId();
} // END - if
// Is the extension installed and updated?
$row['unconfirmed'] = countSumTotalData($row['refid'], 'user_links', 'id', 'userid', true);
// Init clickrate with zero
- $row['clickrate'] = 0;
+ $row['clickrate'] = '0';
// Is at least one mail received?
if ($row['emails_received'] > 0) {
// Recuce the amount of received emails for the receipients for given email
function reduceRecipientReceivedMails ($column, $id, $count) {
// Search for mail in database
- $result = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `%s`=%s ORDER BY `userid` ASC LIMIT %s",
+ $result = SQL_QUERY_ESC("SELECT * FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `%s`=%s ORDER BY `userid` ASC LIMIT %s",
array($column, bigintval($id), $count), __FUNCTION__, __LINE__);
// Are there entries?
if (SQL_NUMROWS($result) > 0) {
// Now load all userids for one big query!
- // @TODO This can be somehow rewritten
- $UIDs = array();
- while (list($userid) = SQL_FETCHROW($result)) {
- $UIDs[$userid] = $userid;
+ $userids = array();
+ while ($data = SQL_FETCHARRAY($result)) {
+ // By default we want to reduce and have no mails found
+ $num = 0;
+
+ // We must now look if he has already confirmed this mail, so might sound double, but it may resolve problems
+ // @TODO Rewrite this to a filter
+ if ((isset($data['stats_id'])) && ($data['stats_id'] > 0)) {
+ // User email
+ $num = countSumTotalData($data['userid'], 'user_stats_data', 'id', 'userid', true, sprintf(" AND `stats_type`='mailid' AND `stats_data`=%s", bigintval($data['stats_id'])));
+ } elseif ((isset($data['bonus_id'])) && ($data['bonus_id'] > 0)) {
+ // Bonus mail
+ $num = countSumTotalData($data['userid'], 'user_stats_data', 'id', 'userid', true, sprintf(" AND `stats_type`='bonusid' AND `stats_data`=%s", bigintval($data['bonus_id'])));
+ }
+
+ // Reduce this users total received emails?
+ if ($num === 0) $userids[$data['userid']] = $data['userid'];
} // END - while
// Now update all user accounts
SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `emails_received`=`emails_received`-1 WHERE `userid` IN (%s) LIMIT %s",
- array(implode(',', $UIDs), count($UIDs)), __FUNCTION__, __LINE__);
+ array(implode(',', $userids), count($userids)), __FUNCTION__, __LINE__);
} // END - if
// Free result
}
// Creates a new task
-function createNewTask ($subject, $notes, $taskType, $userid = 0, $adminId = 0, $strip = true) {
+function createNewTask ($subject, $notes, $taskType, $userid = '0', $adminId = '0', $strip = true) {
// Insert the task data into the database
SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_task_system` (`assigned_admin`, `userid`, `status`, `task_type`, `subject`, `text`, `task_created`) VALUES (%s,%s,'NEW','%s','%s','%s', UNIX_TIMESTAMP())",
- array($adminId, $userid, $taskType, $subject, smartAddSlashes($notes)), __FUNCTION__, __LINE__, true, $strip);
+ array($adminId, $userid, $taskType, $subject, escapeQuotes($notes)), __FUNCTION__, __LINE__, true, $strip);
+}
+
+// Updates last module / online time
+// @TODO Fix inconsistency between last_module and getWhat()
+function updateLastActivity($userid) {
+ // Run the update query
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `last_module`='%s', `last_online`=UNIX_TIMESTAMP(), `REMOTE_ADDR`='%s' WHERE `userid`=%s LIMIT 1",
+ array(
+ getWhat(),
+ detectRemoteAddr(),
+ bigintval($userid)
+ ), __FUNCTION__, __LINE__);
}
// [EOF]