// Init user data array
initUserData();
- // Fix "deleted" cookies first
+ // Fix "deleted" cookies
fixDeletedCookies(array('userid', 'u_hash'));
// Are cookies set and can the member data be loaded?
}
// Generates an option list from various parameters
-function generateOptions ($table, $id, $name, $default = '', $special = '', $whereStatement = '', $disabled = array(), $callback = '') {
+function generateOptions ($table, $key, $value, $default = '', $extra = '', $whereStatement = '', $disabled = array(), $callback = '') {
$ret = '';
if ($table == '/ARRAY/') {
// Selection from array
- if ((is_array($id)) && (is_array($name)) && ((count($id)) == (count($name)) || (!empty($callback)))) {
+ if ((is_array($key)) && (is_array($value)) && ((count($key)) == (count($value)) || (!empty($callback)))) {
// Both are arrays
- foreach ($id as $idx => $value) {
- $ret .= '<option value="' . $value . '"';
- if ($default == $value) {
+ foreach ($key as $idx => $optionValue) {
+ $ret .= '<option value="' . $optionValue . '"';
+ if ($default == $optionValue) {
// Selected by default
$ret .= ' selected="selected"';
- } elseif (isset($disabled[$value])) {
+ } elseif (isset($disabled[$optionValue])) {
// Disabled!
$ret .= ' disabled="disabled"';
}
// Is the call-back function set?
if (!empty($callback)) {
// Call it
- $name[$idx] = call_user_func_array($callback, array($id[$idx]));
+ $value[$idx] = call_user_func_array($callback, array($key[$idx]));
} // END - if
// Finish option tag
- $ret .= '>' . $name[$idx] . '</option>';
+ $ret .= '>' . $value[$idx] . '</option>';
} // END - foreach
} else {
// Problem in request
- reportBug(__FUNCTION__, __LINE__, 'Not all are arrays: id[' . count($id) . ']=' . gettype($id) . ',name[' . count($name) . ']=' . gettype($name) . ',callback=' . $callback);
+ reportBug(__FUNCTION__, __LINE__, 'Not all are arrays: key[' . count($key) . ']=' . gettype($key) . ',value[' . count($value) . ']=' . gettype($value) . ',callback=' . $callback);
}
} else {
- // Data from database
- $SPEC = ',`' . $id . '`';
- if (!empty($special)) {
- $SPEC = ',`' . $special . '` AS `special`';
+ ///////////////////////
+ // Data from database /
+ ///////////////////////
+
+ // Init extra column (if requested)
+ $extraColumn = '';
+ if (!empty($extra)) {
+ $extraColumn = ',`' . $extra . '` AS `extra`';
} // END - if
- // Query the database
- $result = SQL_QUERY_ESC("SELECT `%s` AS `id`,`%s` AS `name`".$SPEC." FROM `{?_MYSQL_PREFIX?}_%s` ".$whereStatement." ORDER BY `%s` ASC",
+ // Run SQL query
+ $result = SQL_QUERY_ESC("SELECT `%s` AS `key`,`%s` AS `value`" . $extraColumn . " FROM `{?_MYSQL_PREFIX?}_%s` " . $whereStatement . " ORDER BY `%s` ASC",
array(
- $id,
- $name,
+ $key,
+ $value,
$table,
- $name
+ $value
), __FUNCTION__, __LINE__);
// Do we have rows?
if (!SQL_HASZERONUMS($result)) {
// Found data so add them as OPTION lines
while ($content = SQL_FETCHARRAY($result)) {
- // Is special set?
- if (!isset($content['special'])) {
+ // Is extra set?
+ if (!isset($content['extra'])) {
// Set it to empty
- $content['special'] = '';
+ $content['extra'] = '';
} // END - if
- $ret .= '<option value="' . $content['id'] . '"';
+ $ret .= '<option value="' . $content['key'] . '"';
- if ($default == $content['id']) {
+ if ($default == $content['key']) {
// Selected by default
$ret .= ' selected="selected"';
- } elseif (isset($disabled[$content['id']])) {
+ } elseif (isset($disabled[$content['key']])) {
// Disabled!
$ret .= ' disabled="disabled"';
}
// Add it, if set
- if (!empty($content['special'])) {
- $content['special'] = ' (' . $content['special'] . ')';
+ if (!empty($content['extra'])) {
+ $content['extra'] = ' (' . $content['extra'] . ')';
} // END - if
// Is the call-back function set?
if (!empty($callback)) {
// Call it
- $content['name'] = call_user_func_array($callback, array($content['name']));
+ $content['value'] = call_user_func_array($callback, array($content['value']));
} // END - if
// Finish option list
- $ret .= '>' . $content['name'] . $content['special'] . '</option>';
+ $ret .= '>' . $content['value'] . $content['extra'] . '</option>';
} // END - while
} else {
// No data found
// Maybe he wants to confirm an email?
if ($mailId > 0) {
- $result_main = SQL_QUERY_ESC("SELECT `id`,`link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s AND `userid`=%s LIMIT 1",
+ $result_main = SQL_QUERY_ESC("SELECT `id` AS `link_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s AND `userid`=%s LIMIT 1",
array($mailId, $userId), __FILE__, __LINE__);
$type = 'mailid';
$urlId = $mailId;
} elseif ($bonusId > 0) {
- $result_main = SQL_QUERY_ESC("SELECT `id`,`link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s AND `userid`=%s LIMIT 1",
+ $result_main = SQL_QUERY_ESC("SELECT `id` AS `link_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s AND `userid`=%s LIMIT 1",
array($bonusId, $userId), __FILE__, __LINE__);
$type = 'bonusid';
$urlId = $bonusId;
+ } else {
+ // Not detected
+ reportBug(__FILE__, __LINE__, 'Whether bonusid or mailid was set. This is a strange bug.');
}
+ // Is an entry found?
if (SQL_NUMROWS($result_main) == 1) {
// Is the stats id valid?
- list($lid, $ltype) = SQL_FETCHROW($result_main);
+ $data = SQL_FETCHARRAY($result_main);
// Init result here with invalid to avoid possible missing variable
$result_mailid = false;
- // @TODO Rewrite this to a filter
- switch ($ltype) {
+ // @TODO Rewrite this to a filter/function
+ switch ($data['link_type']) {
case 'NORMAL':
- $result_mailid = SQL_QUERY_ESC("SELECT `pool_id`,`userid`,`id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
- array($mailId), __FILE__, __LINE__);
+ $result_mailid = SQL_QUERY_ESC("SELECT `pool_id`, `userid` AS `sender` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
+ array($urlId), __FILE__, __LINE__);
break;
case 'BONUS':
- $result_mailid = SQL_QUERY_ESC("SELECT `id`,`id`,`is_notify` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
- array($bonusId), __FILE__, __LINE__);
+ $result_mailid = SQL_QUERY_ESC("SELECT `is_notify` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
+ array($urlId), __FILE__, __LINE__);
break;
default: // Unknown type
- reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
+ reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $data['link_type'] . ' detected.');
break;
- }
+ } // END - switch
// Entry found?
if (SQL_NUMROWS($result_mailid) == 1) {
// Load data
- list($pool, $sender, $notify) = SQL_FETCHROW($result_mailid);
+ $data = merge_array($data, SQL_FETCHARRAY($result_mailid));
// Correct notification switch in non-bonus mails
- if (!in_array($notify, array('Y', 'N'))) {
- $notify = 'N';
+ if ((!isset($data['is_notify'])) || (!in_array($data['is_notify'], array('Y', 'N')))) {
+ $data['is_notify'] = 'N';
} // END - if
// Set sender to 0 when we have a bonus mail
- if ($ltype == 'BONUS') {
- $sender = '0';
+ if ($data['link_type'] == 'BONUS') {
+ $data['sender'] = '0';
} // END - if
// Is the user id valid?
if (getUserData('status') == 'CONFIRMED') {
// User has confirmed his account so we can procede...
// @TODO Rewrite this to a filter
- switch ($ltype) {
+ switch ($data['link_type']) {
case 'NORMAL':
$result = SQL_QUERY_ESC("SELECT `payment_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
- array(bigintval($pool)), __FILE__, __LINE__);
+ array(bigintval($data['pool_id'])), __FILE__, __LINE__);
// Entry found?
if (SQL_NUMROWS($result) == 1) {
case 'BONUS':
$result = SQL_QUERY_ESC("SELECT `time`,`points` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
- array(bigintval($pool)), __FILE__, __LINE__);
+ array(bigintval($data['pool_id'])), __FILE__, __LINE__);
// Entry found?
if (SQL_NUMROWS($result) == 1) {
break;
default: // Unknown type
- reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
+ reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $data['link_type'] . ' detected.');
break;
} // END - switch
// Count clicks
// @TODO Rewrite this to a filter
- switch ($ltype) {
+ switch ($data['link_type']) {
case 'NORMAL':
SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_stats` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1",
array($mailId), __FILE__, __LINE__);
break;
default: // Unknown type
- reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $ltype . ' detected.');
+ reportBug(__FILE__, __LINE__, 'Unknown mail type ' . $data['link_type'] . ' detected.');
break;
} // END - switch
// Shall I add bonus points for "turbo clickers" ?
if (isExtensionInstalledAndNewer('bonus', '0.2.2')) {
// Is an active-rallye running and this is not a notification mail?
- if ((isBonusRallyeActive()) && ($notify != 'Y')) {
+ if ((isBonusRallyeActive()) && ($data['is_notify'] != 'Y')) {
// Shall I exclude the webmaster's own userid from the active-rallye?
if ((((getBonusUserid() == $userId) && (getConfig('bonus_include_own') == 'Y')) || (getBonusUserid() != $userId)) && (getDefRefid() != $userId)) {
// Add points and remember ranking are done in this function....
// Load template
loadTemplate($template, false, $content);
- } elseif (isValidUserId($sender)) {
+ } elseif (isValidUserId($data['sender'])) {
// Wrong image code! So add points to sender's account
initReferralSystem();
- addPointsThroughReferralSystem('mailid_payback', $sender, $payment);
+ addPointsThroughReferralSystem('mailid_payback', $data['sender'], $payment);
// Add payment points
$content['points'] = $payment;
// Remove link from table
SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `id`=%s LIMIT 1",
- array(bigintval($lid)), __FILE__, __LINE__);
+ array(bigintval($data['link_id'])), __FILE__, __LINE__);
break;
case 'img':