* $Author:: $ *
* -------------------------------------------------------------------- *
* Copyright (c) 2003 - 2009 by Roland Haeder *
- * Copyright (c) 2009 - 2011 by Mailer Developer Team *
+ * 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 *
// "Getter" for module description
// @TODO Can we cache this?
-function getTitleFromMenu ($mode, $what, $column = 'what', $ADD='') {
+function getTitleFromMenu ($mode, $what, $column = 'what', $ADD = '') {
+ // Debug message
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'mode=' . $mode . ',what=' . $what . ',column=' . $column . ',add=' . $ADD);
+
// Fix empty 'what'
if (empty($what)) {
$what = getIndexHome();
} elseif ((isGetRequestElementSet('action')) && ($column == 'what')) {
// Get it from action
return getTitleFromMenu($mode, getAction(), 'action', $ADD);
- } elseif ($what == 'overview') {
+ } elseif ($what == 'welcome') {
// Overview page
- return '{--WHAT_IS_OVERVIEW--}';
+ return '{--WHAT_IS_WELCOME--}';
}
// Default is not found
// Can we close the you-are-here navigation?
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'type=' . $type . 'getWhat()=' . getWhat());
- if (($type == 'what') || (($type == 'action') && ((!isWhatSet()) || (getWhat() == 'overview')))) {
+ if (($type == 'what') || (($type == 'action') && ((!isWhatSet()) || (getWhat() == 'welcome')))) {
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'type=' . $type);
// Add closing div and br-tag
$GLOBALS['nav_depth'] = '0';
} // END - if
// Is ext-sql_patches up-to-date, and display_home_in_index is Y?
- if ((isExtensionInstalledAndNewer('sql_patches', '0.8.3')) && (isDisplayHomeInIndexEnabled()) && ($content['sub_what'] == getIndexHome())) {
+ if ((getModule() == 'index') && (isExtensionInstalledAndNewer('sql_patches', '0.8.3')) && (isDisplayHomeInIndexEnabled()) && ($content['sub_what'] == getIndexHome())) {
// Use index.php as link
$OUT .= '<a name="menu" class="menu_blur" href="{%url=index.php%}" target="_self">';
} else {
}
} else {
// Not found - open
- $OUT .= '<em style="cursor:help" class="notice" title="{%message,ADMIN_MENU_WHAT_404_TITLE=' . $content['sub_what'] . '%}">';
+ $OUT .= '<span class="bad" style="cursor:help" title="{%message,ADMIN_MENU_WHAT_404_TITLE=' . $content['sub_what'] . '%}">';
}
// Menu title
} // END - if
} else {
// Not found - close
- $OUT .= '</em>';
+ $OUT .= '</span>';
}
// Cunt it up
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'main_cnt=' . $main_cnt . ',getWhat()=' . getWhat());
if (SQL_NUMROWS($result_main) > $main_cnt) {
- // Add seperator
- $GLOBALS['rows'] .= loadTemplate('menu_seperator', true, $mode);
+ // Add separator
+ $GLOBALS['rows'] .= loadTemplate('menu_separator', true, $mode);
// Should we display adverts in this menu?
if ((isExtensionInstalledAndNewer('menu', '0.0.1')) && (getConfig($mode . '_menu_advert_enabled') == 'Y') && ($action != 'admin')) {
// Display advert template
$GLOBALS['rows'] .= loadTemplate('menu_' . $mode . '_advert_' . $action, true);
- // Add seperator again
- $GLOBALS['rows'] .= loadTemplate('menu_seperator', true, $mode);
+ // Add separator again
+ $GLOBALS['rows'] .= loadTemplate('menu_separator', true, $mode);
} // END - if
} // END - if
} // END - while
// Should we display adverts in this menu?
if ((isExtensionInstalledAndNewer('menu', '0.0.1')) && (getConfig($mode . '_menu_advert_enabled') == 'Y')) {
- // Add seperator again
- $GLOBALS['rows'] .= loadTemplate('menu_seperator', true, $mode);
+ // Add separator again
+ $GLOBALS['rows'] .= loadTemplate('menu_separator', true, $mode);
// Display advert template
$GLOBALS['rows'] .= loadTemplate('menu_' . $mode . '_advert_end', true);
// Prepare data
$content = array(
- 'rows' => $GLOBALS['rows'],
- 'mode' => $mode
+ 'rows' => $GLOBALS['rows'],
+ 'menu_mode' => $mode
);
// Load main template
} // END - if
}
-// Checks wether the current user is a member
+// Checks whether the current user is a member
function isMember () {
// By default no member
$ret = false;
// So did we now have valid data and an unlocked user?
if ((getUserData('status') == 'CONFIRMED') && ($valPass == getSession('u_hash'))) {
// Transfer last module and online time
- $GLOBALS['last_online']['module'] = getUserData('last_module');
+ $GLOBALS['last_online']['module'] = getUserData(getUserLastWhatName());
$GLOBALS['last_online']['online'] = getUserData('last_online');
// Account is confirmed and all cookie data is valid so he is definely logged in! :-)
return false;
} elseif (is_null($value)) {
// This shall never happen, so please report it
- debug_report_bug(__FUNCTION__, __LINE__, 'value=NULL,column=' . $column . ' - value can never be NULL');
+ reportBug(__FUNCTION__, __LINE__, 'value=NULL,column=' . $column . ' - value can never be NULL');
}
// If we should look for userid secure&set it here
// Don't look for invalid userids...
if (!isValidUserId($value)) {
// Invalid, so abort here
- debug_report_bug(__FUNCTION__, __LINE__, 'User id ' . $value . ' is invalid.');
+ reportBug(__FUNCTION__, __LINE__, 'User id ' . $value . ' is invalid.');
} elseif (isUserDataValid()) {
// Use cache, so it is fine
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' is valid, using cache #1');
// By default none was found
$found = false;
- // Extra statements
- $ADD = '';
- if (isExtensionInstalledAndNewer('user', '0.3.5')) {
- $ADD = ', UNIX_TIMESTAMP(`lock_timestamp`) AS `lock_timestamp`';
- } // END - if
+ // Extra SQL statements
+ $ADD = runFilterChain('convert_user_data_columns', '');
// Query for the user
- $result = SQL_QUERY_ESC("SELECT *".$ADD." FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `%s`='%s' LIMIT 1",
+ $result = SQL_QUERY_ESC("SELECT *" . $ADD . " FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `%s`='%s' LIMIT 1",
array($column, $value), __FUNCTION__, __LINE__);
// Do we have a record?
return $found;
}
-// This patched function will reduce many SELECT queries for the specified or current admin login
+/*
+ * Checks whether the current session bears a valid admin id and password hash.
+ *
+ * This patched function will reduce many SELECT queries for the current admin
+ * login.
+ */
function isAdmin () {
// No admin in installation phase!
if ((isInstallationPhase()) || (!isAdminRegistered())) {
// Init variables
$ret = false;
$adminId = '0';
- $passCookie = '';
+ $passwordFromCookie = '';
$valPass = '';
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminId);
if ((isSessionVariableSet('admin_id')) && (isSessionVariableSet('admin_md5'))) {
// Get admin login and password from session/cookies
$adminId = getCurrentAdminId();
- $passCookie = getAdminMd5();
+ $passwordFromCookie = getAdminMd5();
} // END - if
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'mainId=' . $adminId . 'passCookie=' . $passCookie);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId . 'passwordFromCookie=' . $passwordFromCookie);
// Abort if admin id is zero
if ($adminId == '0') {
+ // A very noisy debug message ...
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Current adminId is zero. isSessionVariableSet(admin_id)=' . intval(isSessionVariableSet('admin_id')) . ',isSessionVariableSet(admin_md5)=' . intval(isSessionVariableSet('admin_md5')));
+
+ // Abort here now
return false;
} // END - if
if (isset($GLOBALS['admin_hash'])) {
// Use cached string
$valPass = $GLOBALS['admin_hash'];
- } elseif ((!empty($passCookie)) && (isAdminHashSet($adminId) === true) && (!empty($adminId))) {
+ } elseif ((!empty($passwordFromCookie)) && (isAdminHashSet($adminId) === true) && (!empty($adminId))) {
// Login data is valid or not?
$valPass = encodeHashForCookie(getAdminHash($adminId));
if (!empty($valPass)) {
// Check if password is valid
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '(' . $valPass . '==' . $passCookie . ')='.intval($valPass == $passCookie));
- $GLOBALS[__FUNCTION__][$adminId] = (($GLOBALS['admin_hash'] == $passCookie) || ((strlen($GLOBALS['admin_hash']) == 32) && ($GLOBALS['admin_hash'] == md5($passCookie))) || (($GLOBALS['admin_hash'] == '*FAILED*') && (!isExtensionActive('cache'))));
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '(' . $valPass . '==' . $passwordFromCookie . ')='.intval($valPass == $passwordFromCookie));
+ $GLOBALS[__FUNCTION__][$adminId] = ($GLOBALS['admin_hash'] == $passwordFromCookie);
} // END - if
} // END - if
__FUNCTION__, __LINE__);
break;
+ case 'admin':
case 'member':
// Members are allowed to set to zero mails per day (we will change this soon!)
$result = SQL_QUERY('SELECT `value`,`comment` FROM `{?_MYSQL_PREFIX?}_max_receive` ORDER BY `value` ASC',
$OUT = '';
while ($content = SQL_FETCHARRAY($result)) {
$OUT .= ' <option value="' . $content['value'] . '"';
- if (postRequestElement('max_mails') == $content['value']) $OUT .= ' selected="selected"';
+
+ if (postRequestElement('max_mails') == $content['value']) {
+ $OUT .= ' selected="selected"';
+ } // END - if
+
$OUT .= '>' . $content['value'] . ' {--PER_DAY--}';
if (!empty($content['comment'])) $OUT .= '(' . $content['comment'] . ')';
$OUT .= '</option>';
$OUT = loadTemplate(($mode . '_receive_table'), true, $OUT);
} else {
// Maybe the admin has to setup some maximum values?
- debug_report_bug(__FUNCTION__, __LINE__, 'Nothing is being done here?');
+ reportBug(__FUNCTION__, __LINE__, 'Nothing is being done here?');
}
// Free result
}
}
-// Checks wether the given email address is used.
+// Checks whether the given email address is used.
function isEmailTaken ($email) {
+ // Default is no userid
+ $useridSql = ' IS NOT NULL';
+
+ // Is a member logged in?
+ if (isMember()) {
+ // Get userid
+ $useridSql = '!= ' . bigintval(getMemberId());
+ } // END - if
+
// Replace dot with {DOT}
$email = str_replace('.', '{DOT}', $email);
// Query the database
- $result = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `email` LIKE '%%%s%%' LIMIT 1",
- array($email), __FUNCTION__, __LINE__);
+ $result = SQL_QUERY_ESC("SELECT
+ COUNT(`userid`) AS `cnt`
+FROM
+ `{?_MYSQL_PREFIX?}_user_data`
+WHERE
+ '%s' REGEXP `email` AND
+ `userid` %s
+LIMIT 1",
+ array(
+ $email,
+ $useridSql
+ ), __FUNCTION__, __LINE__);
// Is the email there?
- $isTaken = (SQL_NUMROWS($result) == 1);
+ list($count) = SQL_FETCHROW($result);
// Free the result
SQL_FREERESULT($result);
// Return result
- return $isTaken;
+ return ($count == 1);
}
// Validate the given menu action
-function isMenuActionValid ($mode, $action, $what, $updateEntry=false) {
+function isMenuActionValid ($mode, $action, $what, $updateEntry = false) {
// Is the cache entry there and we shall not update?
if ((isset($GLOBALS['action_valid'][$mode][$action][$what])) && ($updateEntry === false)) {
// Count cache hit
$action,
$what
), __FUNCTION__, __LINE__, false);
- } elseif (($what != 'overview') && (!empty($what))) {
+ } elseif (($what != 'welcome') && (!empty($what))) {
// Other actions
$sql = SQL_QUERY_ESC("SELECT `id`,`what` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND `what`='%s'".$add." ORDER BY `action` DESC LIMIT 1",
array(
if (!isExtensionInstalledAndNewer('sql_patches', '0.0.5')) {
// sql_patches is missing so choose depending on mode
- if (isWhatSet()) {
- // Use setted what
- $what = getWhat();
- } elseif ($module == 'admin') {
- // Admin area
- $what = 'overview';
- } else {
- // Everywhere else
- $what = 'welcome';
- }
+ $what = determineWhat($module);
} elseif ((empty($what)) && ($module != 'admin')) {
// Use configured 'home'
$what = getIndexHome();
} elseif (isActionSet()) {
// Get it directly from URL
return getAction();
- } elseif (($what == 'overview') || (!isWhatSet())) {
+ } elseif (($what == 'welcome') || (!isWhatSet())) {
// Default value for admin area
$data['action'] = 'login';
}
$data['cat'] = '{--_CATEGORY_NONE--}';
} elseif ($cid > 0) {
// Lookup the category in database
- $result = SQL_QUERY_ESC("SELECT `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1",
+ $result = SQL_QUERY_ESC('SELECT `cat` FROM `{?_MYSQL_PREFIX?}_cats` WHERE `id`=%s LIMIT 1',
array(bigintval($cid)), __FUNCTION__, __LINE__);
if (SQL_NUMROWS($result) == 1) {
// Category found... :-)
}
// Get a string of "mail title" and price back
-function getPaymentTitlePrice ($pid, $full=false) {
- // Default is not found
- $ret = '{--_PAYMENT_404--}';
-
- // Load payment data
- $result = SQL_QUERY_ESC("SELECT `mail_title`,`price` FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1",
- array(bigintval($pid)), __FUNCTION__, __LINE__);
-
- // Do we have an entry?
- if (SQL_NUMROWS($result) == 1) {
- // Payment type found... :-)
- $data = SQL_FETCHARRAY($result);
-
- // Only title or also including price?
- if ($full === false) {
- $ret = $data['mail_title'];
- } else {
- $ret = $data['mail_title'] . ' / {%pipe,translateComma=' . $data['price'] . '%} {?POINTS?}';
- }
- } // END - if
-
- // Free result
- SQL_FREERESULT($result);
+function getPaymentTitlePrice ($paymentsId, $full = false) {
+ // Only title or also including price?
+ if ($full === false) {
+ $ret = getPaymentData($paymentsId, 'main_title');
+ } else {
+ $ret = getPaymentData($paymentsId, 'main_title') . ' / {%pipe,getPaymentData,translateComma=' . $paymentsId . '%} {?POINTS?}';
+ }
// Return result
return $ret;
}
-// Get (basicly) the price of given payment id
-function getPaymentPoints ($pid, $lookFor = 'price') {
+// "Getter" for payment data (cached)
+function getPaymentData ($paymentsId, $lookFor = 'price') {
// Default value...
- $data[$lookFor] = -1;
+ $data[$lookFor] = NULL;
- // Search for it in database
- $result = SQL_QUERY_ESC("SELECT `%s` FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1",
- array($lookFor, $pid), __FUNCTION__, __LINE__);
+ // Do we have cache?
+ if (isset($GLOBALS['cache_array']['payments'][$paymentsId]['id'])) {
+ // Use it if found to save SQL queries
+ $data[$lookFor] = $GLOBALS['cache_array']['payments'][$lookFor][$paymentsId];
- // Is the entry there?
- if (SQL_NUMROWS($result) == 1) {
- // Payment type found... :-)
- $data = SQL_FETCHARRAY($result);
- } // END - if
+ // Update cache hits
+ incrementStatsEntry('cache_hits');
+ } elseif (!isExtensionActive('cache')) {
+ // Search for it in database
+ $result = SQL_QUERY_ESC('SELECT `%s` FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1',
+ array(
+ $lookFor,
+ bigintval($paymentsId)
+ ), __FUNCTION__, __LINE__);
- // Free result
- SQL_FREERESULT($result);
+ // Is the entry there?
+ if (SQL_NUMROWS($result) == 1) {
+ // Payment type found... :-)
+ $data = SQL_FETCHARRAY($result);
+ } // END - if
+
+ // Free result
+ SQL_FREERESULT($result);
+ }
// Return value
return $data[$lookFor];
}
// Remove a receiver's id from $receivers and add a link for him to confirm
-function removeReceiver (&$receivers, $key, $userid, $pool_id, $stats_id = 0, $isBonusMail = false) {
+function removeReceiver (&$receivers, $key, $userid, $poolId, $statsId = 0, $isBonusMail = false) {
// Default is not removed
$ret = 'failed';
unset($receivers[$key]);
// Is there already a line for this user available?
- if ($stats_id > 0) {
+ if ($statsId > 0) {
// Default is 'normal' mail
$type = 'NORMAL';
$rowName = 'stats_id';
} // END - if
// Try to look the entry up
- $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE %s='%s' AND `userid`=%s AND link_type='%s' LIMIT 1",
- array($rowName, $stats_id, bigintval($userid), $type), __FUNCTION__, __LINE__);
+ $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `%s`=%s AND `userid`=%s AND `link_type`='%s' LIMIT 1",
+ array(
+ $rowName,
+ bigintval($statsId),
+ bigintval($userid),
+ $type
+ ), __FUNCTION__, __LINE__);
// Was it *not* found?
if (SQL_HASZERONUMS($result)) {
// 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__);
+ SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_links` (`%s`,`userid`,`link_type`) VALUES (%s,%s,'%s')",
+ array(
+ $rowName,
+ bigintval($statsId),
+ bigintval($userid),
+ $type
+ ), __FUNCTION__, __LINE__);
// Update 'mails_sent' if sql_patches is updated
if (isExtensionInstalledAndNewer('sql_patches', '0.7.4')) {
// Update the pool
- SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `mails_sent`=`mails_sent`+1 WHERE `id`=%s LIMIT 1",
- array(bigintval($pool_id)), __FUNCTION__, __LINE__);
+ SQL_QUERY_ESC('UPDATE `{?_MYSQL_PREFIX?}_pool` SET `mails_sent`=`mails_sent`+1 WHERE `id`=%s LIMIT 1',
+ array(bigintval($poolId)), __FUNCTION__, __LINE__);
} // END - if
$ret = 'done';
} else {
// Count or sum whole table?
if ($countRows === true) {
// Count whole table
- $result = SQL_QUERY_ESC("SELECT COUNT(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`".$add,
+ $result = SQL_QUERY_ESC('SELECT COUNT(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`' . $add . ' LIMIT 1',
array(
$lookFor,
$tableName
), __FUNCTION__, __LINE__);
} else {
// Sum whole table
- $result = SQL_QUERY_ESC("SELECT SUM(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`".$add,
+ $result = SQL_QUERY_ESC('SELECT SUM(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s`' . $add . ' LIMIT 1',
array(
$lookFor,
$tableName
} elseif (($countRows === true) || ($lookFor == 'userid')) {
// Count rows
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'COUNT!');
- $result = SQL_QUERY_ESC("SELECT COUNT(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`%s'%s'".$add,
+ $result = SQL_QUERY_ESC("SELECT COUNT(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`%s'%s'" . $add . ' LIMIT 1',
array(
$lookFor,
$tableName,
} else {
// Add all rows
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SUM!');
- $result = SQL_QUERY_ESC("SELECT SUM(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`%s'%s'".$add,
+ $result = SQL_QUERY_ESC("SELECT SUM(`%s`) AS `res` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`%s'%s'" . $add . ' LIMIT 1',
array(
$lookFor,
$tableName,
SQL_FREERESULT($result);
// Fix empty values
- if ((empty($data['res'])) && ($lookFor != 'counter') && ($lookFor != 'id') && ($lookFor != 'userid')) {
+ if ((empty($data['res'])) && ($lookFor != 'counter') && ($lookFor != 'id') && ($lookFor != 'userid') && ($lookFor != 'rallye_id')) {
// Float number
$data['res'] = '0.00000';
} elseif (''.$data['res'].'' == '') {
return $data['res'];
}
-// Sends out mail to all administrators. This function is no longer obsolete
-// because we need it when there is no ext-admins installed
-function sendAdminEmails ($subj, $message) {
+/**
+ * Sends out mail to all administrators. This function is no longer obsolete
+ * because we need it when there is no ext-admins installed
+ */
+function sendAdminEmails ($subject, $message, $isBugReport = false) {
+ // Default is no special header
+ $mailHeader = '';
+
+ // Is it a bug report?
+ if ($isBugReport === true) {
+ // Then add a reply-to line back to the author (me)
+ $mailHeader = 'Reply-To: webmaster@mxchange.org' . chr(10);
+ } // END - if
+
// Load all admin email addresses
$result = SQL_QUERY('SELECT `email` FROM `{?_MYSQL_PREFIX?}_admins` ORDER BY `id` ASC', __FUNCTION__, __LINE__);
+
+ // And send the notification to all of them
while ($content = SQL_FETCHARRAY($result)) {
// Send the email out
- sendEmail($content['email'], $subj, $message);
+ sendEmail($content['email'], $subject, $message, 'N', $mailHeader);
} // END - if
// Free result
}
// Generates an option list from various parameters
-function generateOptionList ($table, $id, $name, $default = '', $special = '', $whereStatement = '', $disabled = array(), $callback = '') {
+function generateOptions ($table, $id, $name, $default = '', $special = '', $whereStatement = '', $disabled = array(), $callback = '') {
$ret = '';
if ($table == '/ARRAY/') {
// Selection from array
} // END - foreach
} else {
// Problem in request
- debug_report_bug(__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: id[' . count($id) . ']=' . gettype($id) . ',name[' . count($name) . ']=' . gettype($name) . ',callback=' . $callback);
}
} else {
// Data from database
- $SPEC = ', `' . $id . '`';
+ $SPEC = ',`' . $id . '`';
if (!empty($special)) {
- $SPEC = ', `' . $special . '` AS `special`';
+ $SPEC = ',`' . $special . '` AS `special`';
} // END - if
// Query the database
// Default is empty
$what = '';
+ // Check on given module
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'modCheck=' . $modCheck);
switch ($modCheck) {
- case 'admin':
- $what = 'overview';
- break;
-
- case 'login':
- case 'index':
+ case 'index': // Guest area
// Is ext-sql_patches installed and newer than 0.0.5?
if (isExtensionInstalledAndNewer('sql_patches', '0.0.5')) {
// Use it from config
}
break;
- default:
- $what = '';
+ default: // Default for all other menus (getIndexHome() is for index module only)
+ $what = 'welcome';
break;
} // END - switch
}
// Returns HTML code with an option list of all categories
-function generateCategoryOptionsList ($mode) {
+function generateCategoryOptionsList ($mode, $userid = NULL) {
// Prepare WHERE statement
$whereStatement = " WHERE `visible`='Y'";
if (isAdmin()) $whereStatement = '';
// Initialize array...
- $CATS = array(
- 'id' => array(),
- 'name' => array(),
+ $categories = array(
+ 'id' => array(),
+ 'name' => array(),
'userids' => array()
);
// ... and begin loading stuff
while ($content = SQL_FETCHARRAY($result)) {
// Transfer some data
- $CATS['id'][] = $content['id'];
- $CATS['name'][] = $content['cat'];
+ $categories['id'][] = $content['id'];
+ array_push($categories['name'], $content['cat']);
// Check which users are in this category
- $result_userids = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `cat_id`=%s ORDER BY `userid` ASC",
- array(bigintval($content['id'])), __FUNCTION__, __LINE__);
+ $result_userids = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `cat_id`=%s AND `userid` != %s ORDER BY `userid` ASC",
+ array(
+ bigintval($content['id']),
+ convertNullToZero($userid)
+ ), __FUNCTION__, __LINE__);
// Init count
$userid_cnt = '0';
// Start adding all
while ($data = SQL_FETCHARRAY($result_userids)) {
// Add user count
- $userid_cnt += countSumTotalData($data['userid'], 'user_data', 'userid', 'userid', true, " AND `status`='CONFIRMED' AND `receive_mails` > 0");
+ $userid_cnt += countSumTotalData($data['userid'], 'user_data', 'userid', 'userid', true, runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED' AND `receive_mails` > 0"));
} // END - while
// Free memory
SQL_FREERESULT($result_userids);
// Add counter
- $CATS['userids'][] = $userid_cnt;
+ array_push($categories['userids'], $userid_cnt);
} // END - while
// Free memory
// Generate options
$OUT = '';
- foreach ($CATS['id'] as $key => $value) {
- if (strlen($CATS['name'][$key]) > 20) $CATS['name'][$key] = substr($CATS['name'][$key], 0, 17)."...";
- $OUT .= ' <option value="' . $value . '">' . $CATS['name'][$key] . ' (' . $CATS['userids'][$key] . ' {--USER_IN_CAT--})</option>';
+ foreach ($categories['id'] as $key => $value) {
+ $OUT .= ' <option value="' . $value . '">' . $categories['name'][$key] . ' (' . $categories['userids'][$key] . ' {--USERS_IN_CATEGORY--})</option>';
} // END - foreach
} else {
// No cateogries are defined yet
- $OUT = '<option class="notice">{--MEMBER_NO_CATEGORIES--}</option>';
+ $OUT = '<option class="bad">{--MEMBER_NO_CATEGORIES--}</option>';
}
// Return HTML code
// Generate a receiver list for given category and maximum receivers
function generateReceiverList ($categoryId, $receiver, $mode = '') {
// Init variables
- $CAT_TABS = '';
- $CAT_WHERE = '';
+ $extraColumns = '';
$receiverList = '';
$result = false;
$receiver = getTotalReceivers($mode);
} // END - if
+ // Exclude (maybe exclude) testers
+ $addWhere = runFilterChain('user_exclusion_sql', ' ');
+
// Category given?
if ($categoryId > 0) {
// Select category
- $CAT_TABS = "LEFT JOIN `{?_MYSQL_PREFIX?}_user_cats` AS c ON d.`userid`=c.`userid`";
- $CAT_WHERE = sprintf(" AND c.`cat_id`=%s", $categoryId);
+ $extraColumns = "LEFT JOIN `{?_MYSQL_PREFIX?}_user_cats` AS c ON d.`userid`=c.`userid`";
+ $addWhere = sprintf(" AND c.`cat_id`=%s", $categoryId);
} // END - if
// Exclude users in holiday?
if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
// Add something for the holiday extension
- $CAT_WHERE .= " AND d.`holiday_active`='N'";
+ $addWhere .= " AND d.`holiday_active`='N'";
} // END - if
+ // Include only HTML recipients?
if ((isExtensionActive('html_mail')) && ($mode == 'html')) {
- // Only include HTML receivers
- $result = SQL_QUERY_ESC("SELECT d.`userid` FROM `{?_MYSQL_PREFIX?}_user_data` AS d ".$CAT_TABS." WHERE d.`status`='CONFIRMED' AND d.`html`='Y'".$CAT_WHERE." ORDER BY d.`{?order_select?}` {?order_mode?} LIMIT %s",
- array(
- $receiver
- ), __FUNCTION__, __LINE__);
- } else {
- // Include all
- $result = SQL_QUERY_ESC("SELECT d.`userid` FROM `{?_MYSQL_PREFIX?}_user_data` AS d ".$CAT_TABS." WHERE d.`status`='CONFIRMED'".$CAT_WHERE." ORDER BY d.`{?order_select?}` {?order_mode?} LIMIT %s",
- array(
- $receiver
- ), __FUNCTION__, __LINE__);
- }
+ $addWhere .= " AND d.`html`='Y'";
+ } // END - if
+
+ // Run query
+ $result = SQL_QUERY_ESC("SELECT d.`userid` FROM `{?_MYSQL_PREFIX?}_user_data` AS d ".$extraColumns." WHERE d.`status`='CONFIRMED' ".$addWhere." ORDER BY d.`{?order_select?}` {?order_mode?} LIMIT %s",
+ array(
+ $receiver
+ ), __FUNCTION__, __LINE__);
// Entries found?
if ((SQL_NUMROWS($result) >= $receiver) && ($receiver > 0)) {
}
// Creates a new task
-function createNewTask ($subject, $notes, $taskType, $userid = NULL, $adminId = '0', $strip = true) {
+function createNewTask ($subject, $notes, $taskType, $userid = NULL, $adminId = NULL, $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,
+ convertZeroToNull($adminId),
+ convertZeroToNull($userid),
$taskType,
$subject,
$notes
}
// Updates last module / online time
-// @TODO Fix inconsistency between last_module and getWhat()
function updateLastActivity($userid) {
- // Run the update query
- SQL_QUERY_ESC("UPDATE
+ // Is 'what' set?
+ if (isWhatSet()) {
+ // Run the update query
+ SQL_QUERY_ESC("UPDATE
`{?_MYSQL_PREFIX?}_user_data`
SET
- `last_module`='%s',
+ `%s`='%s',
`last_online`=UNIX_TIMESTAMP(),
`REMOTE_ADDR`='%s'
WHERE
`userid`=%s
LIMIT 1",
array(
+ getUserLastWhatName(),
getWhat(),
detectRemoteAddr(),
bigintval($userid)
), __FUNCTION__, __LINE__);
+ } else {
+ // No what set, needs to be ignored (last_module is last_what)
+ SQL_QUERY_ESC("UPDATE
+ `{?_MYSQL_PREFIX?}_user_data`
+SET
+ `%s`=NULL,
+ `last_online`=UNIX_TIMESTAMP(),
+ `REMOTE_ADDR`='%s'
+WHERE
+ `userid`=%s
+LIMIT 1",
+ array(
+ getUserLastWhatName(),
+ detectRemoteAddr(),
+ bigintval($userid)
+ ), __FUNCTION__, __LINE__);
+ }
+}
+
+/**
+ * Checks if given subject is found and if not, adds an SQL query to the
+ * extension registration queue.
+ */
+function registerExtensionPointsData ($subject, $columnName, $lockedMode, $paymentMethod) {
+ // Default is old extension version
+ $add = '';
+
+ // Is the extension equal or newer 0.8.9?
+ if ((getExtensionMode() == 'register') || (getExtensionMode() == 'update') || (isExtensionInstalledAndNewer('sql_patches', '0.8.9'))) {
+ // Then add provider
+ $add = " AND `account_provider`='EXTENSION'";
+ } // END - if
+
+ // Is the 'subject' there?
+ if (((!ifSqlTableExist('points_data')) && ((getExtensionMode() == 'register') || (getExtensionMode() == 'update'))) || (countSumTotalData($subject, 'points_data', 'id', 'subject', true, $add) == 0)) {
+ // Not found so add an SQL query
+ addExtensionSql(sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_points_data` (`subject`,`column_name`,`locked_mode`,`payment_method`) VALUES ('%s','%s','%s','%s')",
+ $subject,
+ $columnName,
+ $lockedMode,
+ $paymentMethod
+ ));
+ } // END - if
+}
+
+/**
+ * Checks if given subject is found and if so, adds an SQL query to the
+ * extension unregistration queue.
+ */
+function unregisterExtensionPointsData ($subject) {
+ // Default is old extension version
+ $add = '';
+
+ // Is the extension equal or newer 0.8.9?
+ if (isExtensionInstalledAndNewer('sql_patches', '0.8.9')) {
+ // Then add provider
+ $add = " AND `account_provider`='EXTENSION'";
+ } // END - if
+
+ // Is the 'subject' there?
+ if (countSumTotalData($subject, 'points_data', 'id', 'subject', true, $add) == 1) {
+ // Found one or more, so add an SQL query
+ addExtensionSql(sprintf("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_points_data` WHERE `subject`='%s'" . $add . " LIMIT 1",
+ $subject
+ ));
+ } // END - if
}
// [EOF]