X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fmysql-manager.php;h=ebb750ba2754d42b4215eed8f8deb146dac08ec0;hp=96785ed9d3b7b746b68c3822398bfd1e27ea0204;hb=04b69ac9f33369cbf654396c4a42cb1fff710ff4;hpb=57227d33e870ec5cd271209c4a978a52b45c2dd6 diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 96785ed9d3..ebb750ba27 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -18,6 +18,7 @@ * svn:keywords Date Revision" (autoprobset!) at least!!!!!! * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * + * Copyright (c) 2009, 2010 by Mailer Developer Team * * For more information visit: http://www.mxchange.org * * * * This program is free software; you can redistribute it and/or modify * @@ -78,8 +79,8 @@ function getModuleTitle ($module) { // Still no luck or empty title? if (empty($data['title'])) { // No name found - $data['title'] = sprintf("%s (%s)", getMessage('LANG_UNKNOWN_MODULE'), $module); - if (SQL_NUMROWS($result) == '0') { + $data['title'] = getMaskedMessage('UNKNOWN_MODULE_DETECTED', $module); + if ((is_resource($result)) && (SQL_HASZERONUMS($result))) { // Add module to database $dummy = checkModulePermissions($module); } // END - if @@ -138,10 +139,10 @@ function checkModulePermissions ($module = '') { // Check for prefix is a extension... $modSplit = explode('_', $module); $extension = ''; $module_chk = $module; - //* DEBUG: */ print(__LINE__."*".count($modSplit)."*/".$module."*
"); + //* DEBUG: */ debugOutput(__LINE__.'*'.count($modSplit).'/'.$module.'*'); if (count($modSplit) == 2) { // Okay, there is a seperator (_) in the name so is the first part a module? - //* DEBUG: */ print(__LINE__."*".$modSplit[0]."*
"); + //* DEBUG: */ debugOutput(__LINE__.'*'.$modSplit[0].'*'); if (isExtensionActive($modSplit[0])) { // The prefix is an extension's name, so let's set it $extension = $modSplit[0]; $module = $modSplit[1]; @@ -261,7 +262,7 @@ function checkModulePermissions ($module = '') { // Destroy cache here // @TODO Rewrite this to a filter - if ((getOutputMode() == '0') || (getOutputMode() == -1)) rebuildCacheFile('modules', 'modules'); + if ((getOutputMode() == '0') || (getOutputMode() == -1)) rebuildCache('modules', 'modules'); // And reload data unset($GLOBALS['module_status'][$module]); @@ -272,7 +273,7 @@ function checkModulePermissions ($module = '') { } } elseif (($ret == 'cache_miss') && (getOutputMode() == '0')) { // Rebuild the cache files - rebuildCacheFile('modules', 'modules'); + rebuildCache('modules', 'modules'); } elseif ($found === false) { // Problem with module detected logDebugMessage(__FUNCTION__, __LINE__, sprintf("Problem in module %s detected. ret=%s, locked=%s, hidden=%s, mem=%s, admin=%s, output_mode=%s", @@ -301,6 +302,7 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false) { $LINK_ADD = ''; $OUT = ''; $ADD = ''; + $prefix = ''; // First we have to do some analysis... if (substr($file, 0, 7) == 'action-') { @@ -326,7 +328,7 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false) { if (isAdmin()) $ADD = ''; $dummy = substr($search, 0, -4); - $ADD .= " AND `action`='".getModeAction($accessLevel, $dummy)."'"; + $ADD .= " AND `action`='".getActionFromModuleWhat($accessLevel, $dummy)."'"; } elseif (($accessLevel == 'sponsor') || ($accessLevel == 'engine')) { // Sponsor / engine menu $type = 'what'; @@ -343,11 +345,19 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false) { // Begin the navigation line if ((!isset($GLOBALS['nav_depth'])) && ($return === false)) { + // Init nav_depth $GLOBALS['nav_depth'] = '0'; - $prefix = '
{--YOU_ARE_HERE--} Home'; - } else { - if ($return === false) $GLOBALS['nav_depth']++; - $prefix = ''; + + // Run the pre-filter chain + $ret = runFilterChain('pre_youhere_line', array('access_level' => $accessLevel, 'type' => $type, 'content' => '')); + + // Add pre-content + $prefix = $ret['content']; + + $prefix .= '
{--YOU_ARE_HERE--} Home'; + } elseif ($return === false) { + // Count depth + $GLOBALS['nav_depth']++; } $prefix .= ' -> '; @@ -363,20 +373,20 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false) { $OUT = $prefix . '' . getTitleFromMenu($accessLevel, $search, $type, $ADD) . ''; // Can we close the you-are-here navigation? - //* DEBUG: */ print(__LINE__."*".$type.'/'.getWhat()."*
"); + //* DEBUG: */ debugOutput(__LINE__.'*'.$type.'/'.getWhat().'*'); if (($type == 'what') || (($type == 'action') && ((!isWhatSet()) || (getWhat() == 'overview')))) { - //* DEBUG: */ print(__LINE__.'+'.$type."+
"); + //* DEBUG: */ debugOutput(__LINE__.'+'.$type.'+'); // Add closing div and br-tag - $OUT .= '

'; + $OUT .= '
'; $GLOBALS['nav_depth'] = '0'; - // Run the filter chain + // Run the post-filter chain $ret = runFilterChain('post_youhere_line', array('access_level' => $accessLevel, 'type' => $type, 'content' => '')); // Add additional content $OUT .= $ret['content']; } // END - if - } + } // END - if // Return or output HTML code? if ($return === true) { @@ -405,31 +415,48 @@ function addMenu ($mode, $action, $what) { } // 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)".$ADD." ORDER BY `sort` ASC", + $result_main = SQL_QUERY_ESC("SELECT + `title`, `what`, `action`, `visible`, `locked` +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()."*
"); + //* DEBUG: */ debugOutput(__LINE__.'/'.$main_cnt.':'.getWhat().'*'); if (SQL_NUMROWS($result_main) > 0) { // There are menus available, so we simply display them... :) $GLOBALS['rows'] = ''; while ($content = SQL_FETCHARRAY($result_main)) { - //* DEBUG: */ print(__LINE__.'/'.$main_cnt.'/'.$content['action'].':'.getWhat()."*
"); - // Init variables + //* DEBUG: */ debugOutput(__LINE__ . '/' . $main_cnt . '/' . $content['action'] . ':' . getWhat() . '*'); + // Disable the block-mode enableBlockMode(false); - $action = $content['action']; // Load menu header template $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 ".$ADD." ORDER BY `sort`", + $result_sub = SQL_QUERY_ESC("SELECT + `title` AS `sub_title`, + `what` AS `sub_what`, + `visible` AS `sub_visible`, + `locked` AS `sub_locked` +FROM + `{?_MYSQL_PREFIX?}_%s_menu` +WHERE + `action`='%s' AND + `what` != '' AND + `what` IS NOT NULL + ".$ADD." +ORDER BY + `sort` ASC", array($mode, $content['action']), __FUNCTION__, __LINE__); - // Get number of rows - $totalWhats = SQL_NUMROWS($result_sub); - // Do we have some entries? - if ($totalWhats > 0) { + if (SQL_NUMROWS($result_sub) > 0) { // Init counter $cnt = '0'; @@ -442,7 +469,7 @@ function addMenu ($mode, $action, $what) { $OUT = ''; // Full file name for checking menu - //* DEBUG: */ print(__LINE__.":!!!!".$content['sub_what']."!!!
"); + //* DEBUG: */ debugOutput(__LINE__ . ':!!!!' . $content['sub_what'] . '!!!'); $inc = sprintf("inc/modules/%s/what-%s.php", $mode, $content['sub_what']); if (isIncludeReadable($inc)) { // Mark currently selected menu - open @@ -476,18 +503,20 @@ function addMenu ($mode, $action, $what) { $cnt++; // Rewrite array - $content = array( - 'menu' => $OUT, - 'what' => $content['sub_what'] + $content = array( + 'menu' => $OUT, + 'what' => $content['sub_what'], + 'visible' => $content['sub_visible'], + 'locked' => $content['locked'], ); // Add regular menu row or bottom row? - if ($cnt < $totalWhats) { + if ($cnt < SQL_NUMROWS($result_sub)) { $GLOBALS['rows'] .= loadTemplate($mode . '_menu_row', true, $content); } else { $GLOBALS['rows'] .= loadTemplate($mode . '_menu_bottom', true, $content); } - } + } // END - while } else { // This is a menu block... ;-) enableBlockMode(); @@ -497,17 +526,21 @@ function addMenu ($mode, $action, $what) { if (isFileReadable($INC)) { // Load include file if ((!isExtensionActive($content['action'])) || ($content['action'] == 'online')) $GLOBALS['rows'] .= loadTemplate('menu_what_begin', true, $mode); - //* DEBUG: */ print(__LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.getWhat()."*
"); + //* DEBUG: */ debugOutput(__LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.getWhat().'*'); loadInclude($INC); - //* DEBUG: */ print(__LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.getWhat()."*
"); + //* DEBUG: */ debugOutput(__LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.getWhat().'*'); if ((!isExtensionActive($content['action'])) || ($content['action'] == 'online')) $GLOBALS['rows'] .= loadTemplate('menu_what_end', true, $mode); } - //* DEBUG: */ print(__LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.$content['sub_what'].':'.getWhat()."*
"); + //* DEBUG: */ debugOutput(__LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.$content['sub_what'].':'.getWhat().'*'); } + // Free result + SQL_FREERESULT($result_sub); + + // Count one up $main_cnt++; - //* DEBUG: */ print(__LINE__.'/'.$main_cnt.':'.getWhat()."*
"); + //* DEBUG: */ debugOutput(__LINE__.'/'.$main_cnt.':'.getWhat().'*'); if (SQL_NUMROWS($result_main) > $main_cnt) { // Add seperator $GLOBALS['rows'] .= loadTemplate('menu_seperator', true, $mode); @@ -542,7 +575,7 @@ function addMenu ($mode, $action, $what) { ); // Load main template - //* DEBUG: */ print(__LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.$content['sub_what'].':'.getWhat()."*
"); + //* DEBUG: */ debugOutput(__LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.$content['sub_what'].':'.getWhat().'*'); loadTemplate('menu_table', false, $content); } // END - if } @@ -559,16 +592,20 @@ function isMember () { // is the cache entry there? if (isset($GLOBALS['is_member'])) { // Then return it + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'CACHED! (' . intval($GLOBALS['is_member']) . ')'); return $GLOBALS['is_member']; - } elseif (getMemberId() == '0') { + } elseif ((!isSessionVariableSet('userid')) || (!isSessionVariableSet('u_hash'))) { // No member + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'No member set in cookie/session.'); return false; } else { - // Transfer userid=>current - setCurrentUserid(getMemberId()); + // Get it secured from session + setMemberId(getSession('userid')); + setCurrentUserId(getMemberId()); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . getSession('userid') . ' used from cookie/session.'); } - // Init global user data array + // Init user data array initUserData(); // Fix "deleted" cookies first @@ -579,7 +616,7 @@ function isMember () { // Cookies are set with values, but are they valid? if (fetchUserData(getMemberId()) === true) { // Validate password by created the difference of it and the secret key - $valPass = generatePassString(getUserData('password')); + $valPass = encodeHashForCookie(getUserData('password')); // Transfer last module and online time $GLOBALS['last_online']['module'] = getUserData('last_module'); @@ -591,15 +628,17 @@ function isMember () { $ret = true; } else { // Maybe got locked etc. - logDebugMessage(__FUNCTION__, __LINE__, 'status=' . getUserData('status')); + //* DEBUG */ logDebugMessage(__FUNCTION__, __LINE__, 'status=' . getUserData('status') . ',' . $valPass . '(' . strlen($valPass) . ')/' . getSession('u_hash') . '(' . strlen(getSession('u_hash')) . ')/' . getUserData('password') . '(' . strlen(getUserData('password')) . ')'); destroyMemberSession(); } } else { // Cookie data is invalid! + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cookie data invalid or user not found.'); destroyMemberSession(); } } else { // Cookie data is invalid! + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cookie data not complete.'); destroyMemberSession(); } @@ -607,6 +646,7 @@ function isMember () { $GLOBALS['is_member'] = $ret; // Return status + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . intval($ret)); return $ret; } @@ -623,7 +663,7 @@ function fetchUserData ($userid, $column = 'userid') { // Don't look for invalid userids... if ($userid < 1) { // Invalid, so abort here - debug_report_bug('User id ' . $userid . ' is invalid.'); + debug_report_bug(__FUNCTION__, __LINE__, 'User id ' . $userid . ' is invalid.'); } elseif (isUserDataValid()) { // Use cache, so it is fine return true; @@ -693,51 +733,61 @@ function fetchUserData ($userid, $column = 'userid') { } // This patched function will reduce many SELECT queries for the specified or current admin login -function isAdmin ($admin = '') { +function isAdmin ($adminLogin = '') { + // No admin in installation phase! + if ((isInstallationPhase()) || (!isAdminRegistered())) { + return false; + } // END - if + // Init variables - $ret = false; $passCookie = ''; $valPass = ''; - //* DEBUG: */ print(__FUNCTION__.':'.$admin.'
'); + $ret = false; + $passCookie = ''; + $valPass = ''; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminLogin); // If admin login is not given take current from cookies... - if ((empty($admin)) && (isSessionVariableSet('admin_login')) && (isSessionVariableSet('admin_md5'))) { + if ((empty($adminLogin)) && (isSessionVariableSet('admin_login')) && (isSessionVariableSet('admin_md5'))) { // Get admin login and password from session/cookies - $admin = getSession('admin_login'); + $adminLogin = getSession('admin_login'); $passCookie = getSession('admin_md5'); } // END - if - //* DEBUG: */ print(__FUNCTION__.':'.$admin.'/'.$passCookie.'
'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminLogin.'/'.$passCookie); // Do we have cache? - if (!isset($GLOBALS['is_admin'][$admin])) { + if (!isset($GLOBALS['is_admin'][$adminLogin])) { // Init it with failed - $GLOBALS['is_admin'][$admin] = false; + $GLOBALS['is_admin'][$adminLogin] = false; // Search in array for entry if (isset($GLOBALS['admin_hash'])) { // Use cached string $valPass = $GLOBALS['admin_hash']; - } elseif ((!empty($passCookie)) && (isAdminHashSet($admin) === true) && (!empty($admin))) { + } elseif ((!empty($passCookie)) && (isAdminHashSet($adminLogin) === true) && (!empty($adminLogin))) { // Login data is valid or not? - $valPass = generatePassString(getAdminHash($admin)); + $valPass = encodeHashForCookie(getAdminHash($adminLogin)); // Cache it away $GLOBALS['admin_hash'] = $valPass; // Count cache hits incrementStatsEntry('cache_hits'); - } elseif ((!empty($admin)) && ((!isExtensionActive('cache'))) || (isAdminHashSet($admin) === false)) { + } elseif ((!empty($adminLogin)) && ((!isExtensionActive('cache')) || (isAdminHashSet($adminLogin) === false))) { // Get admin hash and hash it - $valPass = generatePassString(getAdminHash($admin)); + $valPass = encodeHashForCookie(getAdminHash($adminLogin)); + + // Cache it away + $GLOBALS['admin_hash'] = $valPass; } if (!empty($valPass)) { // Check if password is valid - //* DEBUG: */ print(__FUNCTION__ . ':(' . $valPass . '==' . $passCookie . ')='.intval($valPass == $passCookie).'
'); - $GLOBALS['is_admin'][$admin] = (($valPass == $passCookie) || ((strlen($valPass) == 32) && ($valPass == md5($passCookie))) || (($valPass == '*FAILED*') && (!isExtensionActive('cache')))); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '(' . $valPass . '==' . $passCookie . ')='.intval($valPass == $passCookie)); + $GLOBALS['is_admin'][$adminLogin] = (($valPass == $passCookie) || ((strlen($valPass) == 32) && ($valPass == md5($passCookie))) || (($valPass == '*FAILED*') && (!isExtensionActive('cache')))); } // END - if } // END - if // Return result of comparision - return $GLOBALS['is_admin'][$admin]; + return $GLOBALS['is_admin'][$adminLogin]; } // Generates a list of "max receiveable emails per day" @@ -778,7 +828,7 @@ function addMaxReceiveList ($mode, $default = '', $return = false) { $OUT = loadTemplate(($mode . '_receive_table'), true, $OUT); } else { // Maybe the admin has to setup some maximum values? - debug_report_bug('Nothing is being done here?'); + debug_report_bug(__FUNCTION__, __LINE__, 'Nothing is being done here?'); } // Free result @@ -796,7 +846,7 @@ function addMaxReceiveList ($mode, $default = '', $return = false) { // 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}' OR `email` LIKE '{PER}%s{PER}' LIMIT 1", + $result = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `email` LIKE '%%%s%%' OR `email` LIKE '%%%s%%' LIMIT 1", array($email, str_replace('.', '{DOT}', $email)), __FUNCTION__, __LINE__); // Is the email there? @@ -827,19 +877,30 @@ function isMenuActionValid ($mode, $action, $what, $updateEntry=false) { $add = ''; if ((!isAdmin()) && ($mode != 'admin')) $add = " AND `locked`='N'"; - //* DEBUG: */ print(__LINE__.':'.$mode.'/'.$action.'/'.$what."*
"); + //* DEBUG: */ debugOutput(__LINE__.':'.$mode.'/'.$action.'/'.$what.'*'); if (($mode != 'admin') && ($updateEntry === true)) { // Update guest or member menu $sql = SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_%s_menu` SET counter=counter+1 WHERE `action`='%s' AND `what`='%s'".$add." LIMIT 1", - array($mode, $action, $what), __FUNCTION__, __LINE__, false); + array( + $mode, + $action, + $what + ), __FUNCTION__, __LINE__, false); } elseif (($what != 'overview') && (!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($mode, $action, $what), __FUNCTION__, __LINE__, false); + array( + $mode, + $action, + $what + ), __FUNCTION__, __LINE__, false); } else { // Admin login overview $sql = SQL_QUERY_ESC("SELECT `id`, `what` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `action`='%s' AND (`what`='' OR `what` IS NULL)".$add." ORDER BY `action` DESC LIMIT 1", - array($mode, $action), __FUNCTION__, __LINE__, false); + array( + $mode, + $action + ), __FUNCTION__, __LINE__, false); } // Run SQL command @@ -865,29 +926,29 @@ function isMenuActionValid ($mode, $action, $what, $updateEntry=false) { } // Get action value from mode (admin/guest/member) and what-value -function getModeAction ($mode, $what) { +function getActionFromModuleWhat ($module, $what) { // Init status $data['action'] = ''; - //* DEBUG: */ print(__LINE__.'='.$mode.'/'.$what.'/'.getAction()."=
"); + //* DEBUG: */ debugOutput(__LINE__.'='.$module.'/'.$what.'/'.getAction().'='); 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') { + } elseif ($module == 'admin') { // Admin area $what = 'overview'; } else { // Everywhere else $what = 'welcome'; } - } elseif ((empty($what)) && ($mode != 'admin')) { + } elseif ((empty($what)) && ($module != 'admin')) { // Use configured 'home' $what = getConfig('index_home'); } // END - if - if ($mode == 'admin') { + if ($module == 'admin') { // Action value for admin area if (isGetRequestParameterSet('action')) { // Use from request! @@ -903,19 +964,19 @@ function getModeAction ($mode, $what) { // Get it directly from URL return getAction(); } - //* DEBUG: */ print(__FUNCTION__."(".__LINE__."): ret=".$data['action'].'
'); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '): ret=' . $data['action']); // Does the module have a menu? - if (ifModuleHasMenu($mode)) { + if (ifModuleHasMenu($module)) { // Rewriting modules to menu - $mode = mapModuleToTable($mode); + $module = mapModuleToTable($module); // Guest and member menu is 'main' as the default if (empty($data['action'])) $data['action'] = 'main'; // Load from database $result = SQL_QUERY_ESC("SELECT `action` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `what`='%s' LIMIT 1", - array($mode, $what), __FUNCTION__, __LINE__); + array($module, $what), __FUNCTION__, __LINE__); if (SQL_NUMROWS($result) == 1) { // Load action value and pray that this one is the right you want... ;-) $data = SQL_FETCHARRAY($result); @@ -923,7 +984,7 @@ function getModeAction ($mode, $what) { // Free memory SQL_FREERESULT($result); - } elseif ((!isExtensionInstalled('sql_patches')) && (($mode != 'admin') && ($mode != 'unknown'))) { + } elseif ((!isExtensionInstalled('sql_patches')) && ($module != 'admin') && ($module != 'unknown')) { // No sql_patches installed, but maybe we need to register an admin? if (isAdminRegistered()) { // Redirect to admin area @@ -1031,7 +1092,7 @@ function removeReceiver (&$receivers, $key, $userid, $pool_id, $stats_id = '', $ array($rowName, $stats_id, bigintval($userid), $type), __FUNCTION__, __LINE__); // Was it *not* found? - if (SQL_NUMROWS($result) == '0') { + 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__); @@ -1055,7 +1116,7 @@ function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatemen // Init count/sum $data['res'] = '0'; - //* DEBUG: */ print($search.'/'.$tableName.'/'.$lookFor.'/'.$whereStatement.'/'.$add.'
'); + //* DEBUG: */ debugOutput($search.'/'.$tableName.'/'.$lookFor.'/'.$whereStatement.'/'.$add); if ((empty($search)) && ($search != '0')) { // Count or sum whole table? if ($countRows === true) { @@ -1069,12 +1130,12 @@ function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatemen } } elseif (($countRows === true) || ($lookFor == 'userid')) { // Count rows - //* DEBUG: */ print("COUNT!
"); + //* DEBUG: */ debugOutput('COUNT!'); $result = SQL_QUERY_ESC("SELECT COUNT(`%s`) AS res FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`='%s'".$add, array($lookFor, $tableName, $whereStatement, $search), __FUNCTION__, __LINE__); } else { // Add all rows - //* DEBUG: */ print("SUM!
"); + //* DEBUG: */ debugOutput('SUM!'); $result = SQL_QUERY_ESC("SELECT SUM(`%s`) AS res FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`='%s'".$add, array($lookFor, $tableName, $whereStatement, $search), __FUNCTION__, __LINE__); } @@ -1095,7 +1156,7 @@ function countSumTotalData ($search, $tableName, $lookFor = 'id', $whereStatemen } // Return value - //* DEBUG: */ print 'ret=' . $data['res'] . '
'; + //* DEBUG: */ debugOutput('ret=' . $data['res']); return $data['res']; } // Getter fro ref level percents @@ -1147,7 +1208,7 @@ function getReferalLevelPercents ($level) { * 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') { - //* DEBUG: */ print("----------------------- ".__FUNCTION__." - ENTRY ----------------------------------------------- '.__FUNCTION__.' - EXIT ------------------------
'); } // Updates the referal counter function updateReferalCounter ($userid) { // Make it sure referal level zero (member him-/herself) is at least selected if (empty($GLOBALS['cache_array']['ref_level'][$userid])) $GLOBALS['cache_array']['ref_level'][$userid] = 1; - //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):userid={$userid},level={$GLOBALS['cache_array']['ref_level'][$userid]}
"); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):userid='.$userid.',level='.$GLOBALS['cache_array']['ref_level'][$userid]); // Update counter SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refsystem` SET `counter`=`counter`+1 WHERE `userid`=%s AND `level`='%s' LIMIT 1", array(bigintval($userid), $GLOBALS['cache_array']['ref_level'][$userid]), __FUNCTION__, __LINE__); // When no entry was updated then we have to create it here - //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):updated=".SQL_AFFECTEDROWS().'
'); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):updated=' . SQL_AFFECTEDROWS()); if (SQL_AFFECTEDROWS() < 1) { // First count! SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_refsystem` (`userid`, `level`, `counter`) VALUES (%s,%s,1)", array(bigintval($userid), $GLOBALS['cache_array']['ref_level'][$userid]), __FUNCTION__, __LINE__); - //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):userid={$userid}
"); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):userid='.$userid); } // END - if // Init referal id @@ -1296,18 +1357,18 @@ function updateReferalCounter ($userid) { $ref = getUserData('refid'); } // END - if - //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):userid={$userid},ref={$ref}
"); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):userid='.$userid.',ref='.$ref); // When he has a referal... if (($ref > 0) && ($ref != $userid)) { // Move to next referal level and count his counter one up! - //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):ref={$ref} - ADVANCE!
"); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):ref='.$ref.' - ADVANCE!'); $GLOBALS['cache_array']['ref_level'][$userid]++; updateReferalCounter($ref); } elseif ((($ref == $userid) || ($ref == '0')) && (isExtensionInstalledAndNewer('cache', '0.1.2'))) { // Remove cache here - //* DEBUG: */ print(__FUNCTION__."(".__LINE__."):ref={$ref} - CACHE!
"); - rebuildCacheFile('refsystem', 'refsystem'); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):ref='.$ref.' - CACHE!'); + rebuildCache('refsystem', 'refsystem'); } // "Walk" back here @@ -1336,21 +1397,21 @@ function sendAdminEmails ($subj, $message) { } // Get id number from administrator's login name -function getAdminId ($login) { +function getAdminId ($adminLogin) { // By default no admin is found $data['id'] = '-1'; // Check cache - if (isset($GLOBALS['cache_array']['admin']['admin_id'][$login])) { + if (isset($GLOBALS['cache_array']['admin']['admin_id'][$adminLogin])) { // Use it if found to save SQL queries - $data['id'] = $GLOBALS['cache_array']['admin']['admin_id'][$login]; + $data['id'] = $GLOBALS['cache_array']['admin']['admin_id'][$adminLogin]; // Update cache hits incrementStatsEntry('cache_hits'); } elseif (!isExtensionActive('cache')) { // Load from database $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `login`='%s' LIMIT 1", - array($login), __FUNCTION__, __LINE__); + array($adminLogin), __FUNCTION__, __LINE__); // Do we have an entry? if (SQL_NUMROWS($result) == 1) { @@ -1377,28 +1438,34 @@ function getCurrentAdminId () { $adminId = getAdminId($adminLogin); // Remember in cache securely - $GLOBALS['current_admin_id'] = bigintval($adminId); + setCurrentAdminId(bigintval($adminId)); } // END - if // Return it return $GLOBALS['current_admin_id']; } +// Setter for current admin id +function setCurrentAdminId ($currentAdminId) { + // Set it secured + $GLOBALS['current_admin_id'] = bigintval($currentAdminId); +} + // Get password hash from administrator's login name -function getAdminHash ($admin) { +function getAdminHash ($adminLogin) { // By default an invalid hash is returned $data['password'] = '-1'; - if (isAdminHashSet($admin)) { + if (isAdminHashSet($adminLogin)) { // Check cache - $data['password'] = $GLOBALS['cache_array']['admin']['password'][$admin]; + $data['password'] = $GLOBALS['cache_array']['admin']['password'][$adminLogin]; // Update cache hits incrementStatsEntry('cache_hits'); } elseif (!isExtensionActive('cache')) { // Load from database $result = SQL_QUERY_ESC("SELECT `password` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `login`='%s' LIMIT 1", - array($admin), __FUNCTION__, __LINE__); + array($adminLogin), __FUNCTION__, __LINE__); // Do we have an entry? if (SQL_NUMROWS($result) == 1) { @@ -1406,7 +1473,7 @@ function getAdminHash ($admin) { $data = SQL_FETCHARRAY($result); // Set cache - setAdminHash($admin, $data['password']); + setAdminHash($adminLogin, $data['password']); } // END - if // Free result @@ -1538,7 +1605,7 @@ function generateOptionList ($table, $id, $name, $default='', $special='', $wher } // END - foreach } else { // Problem in request - debug_report_bug('Not all are arrays: id[' . count($id) . ']=' . gettype($id) . ',name[' . count($name) . ']=' . gettype($name)); + debug_report_bug(__FUNCTION__, __LINE__, 'Not all are arrays: id[' . count($id) . ']=' . gettype($id) . ',name[' . count($name) . ']=' . gettype($name)); } } else { // Data from database @@ -1608,7 +1675,7 @@ function FILTER_ACTIVATE_EXCHANGE () { updateConfiguration('activate_xchange' ,0); // Rebuild cache - rebuildCacheFile('modules', 'modules'); + rebuildCache('modules', 'modules'); } // END - if } @@ -1626,7 +1693,8 @@ LEFT JOIN ON p.userid=d.userid WHERE - p.userid=%s", + p.userid=%s +LIMIT 1", array(bigintval($userid)), __FUNCTION__, __LINE__); // Do we have an entry? @@ -1635,7 +1703,8 @@ WHERE $data = SQL_FETCHARRAY($result); // Delete points entries as well - SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `userid`=%s", array(bigintval($userid)), __FUNCTION__, __LINE__); + SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `userid`=%s", + array(bigintval($userid)), __FUNCTION__, __LINE__); // Update mediadata as well if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) { @@ -1673,21 +1742,6 @@ WHERE SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1", array(bigintval($userid)), __FUNCTION__, __LINE__); } -// Generates meta description for given module and 'what' value -function generateMetaDescriptionCode ($module, $what) { - // Exclude admin and member's area - if (($module != 'admin') && ($module != 'login')) { - // Construct dynamic description - $DESCR = '{?MAIN_TITLE?} '.trim(getConfig('title_middle')) . ' ' . getTitleFromMenu('guest', $what); - - // Output it directly - outputHtml(''); - } // END - if - - // Remove depth - unset($GLOBALS['ref_level']); -} - // Gets the matching what name from module function getWhatFromModule ($modCheck) { // Is the request element set? @@ -1699,7 +1753,7 @@ function getWhatFromModule ($modCheck) { // Default is empty $what = ''; - //* DEBUG: */ print(__LINE__.'!'.$modCheck."!
"); + //* DEBUG: */ debugOutput(__LINE__.'!'.$modCheck.'!'); switch ($modCheck) { case 'admin': $what = 'overview'; @@ -1917,7 +1971,7 @@ function generateReceiverList ($cat, $receiver, $mode = '') { } // END - if // Exclude users in holiday? - if (getExtensionVersion('holiday') >= '0.1.3') { + if (isExtensionInstalledAndNewer('holiday', '0.1.3')) { // Add something for the holiday extension $CAT_WHERE .= " AND d.`holiday_active`='N'"; } // END - if @@ -1955,73 +2009,9 @@ function generateReceiverList ($cat, $receiver, $mode = '') { return $receiverList; } -// Get timestamp for given stats type and data -function getTimestampFromUserStats ($statsType, $statsData, $userid = '0') { - // Default timestamp is zero - $data['inserted'] = '0'; - - // User id set? - if ((isMemberIdSet()) && ($userid == '0')) { - $userid = getMemberId(); - } // END - if - - // Is the extension installed and updated? - if ((!isExtensionActive('sql_patches')) || (isExtensionOlder('sql_patches', '0.5.6'))) { - // Return zero here - return $data['inserted']; - } // END - if - - // Try to find the entry - $result = SQL_QUERY_ESC("SELECT - UNIX_TIMESTAMP(`inserted`) AS inserted -FROM - `{?_MYSQL_PREFIX?}_user_stats_data` -WHERE - `userid`=%s AND - `stats_type`='%s' AND - `stats_data`='%s' -LIMIT 1", - array( - bigintval($userid), - $statsType, - $statsData - ), __FUNCTION__, __LINE__); - - // Is the entry there? - if (SQL_NUMROWS($result) == 1) { - // Get this stamp - $data = SQL_FETCHARRAY($result); - } // END - if - - // Free result - SQL_FREERESULT($result); - - // Return stamp - return $data['inserted']; -} - -// Inserts user stats -function insertUserStatsRecord ($userid, $statsType, $statsData) { - // Is the extension installed and updated? - if ((!isExtensionActive('sql_patches')) || (isExtensionOlder('sql_patches', '0.5.6'))) { - // Return zero here - return false; - } // END - if - - // Does it exist? - if ((!getTimestampFromUserStats($statsType, $statsData, $userid)) && (!is_array($statsData))) { - // Then insert it! - SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_stats_data` (`userid`,`stats_type`,`stats_data`) VALUES (%s,'%s','%s')", - array(bigintval($userid), $statsType, $statsData), __FUNCTION__, __LINE__); - } elseif (is_array($statsData)) { - // Invalid data! - logDebugMessage(__FUNCTION__, __LINE__, "userid={$userid},type={$statsType},data={".gettype($statsData).": Invalid statistics data type!"); - } -} - // "Getter" for array for user refs and points in given level function getUserReferalPoints ($userid, $level) { - //* DEBUG: */ print("----------------------- ".__FUNCTION__." - ENTRY ----------------------------------------------- '.__FUNCTION__.' - EXIT ------------------------
'); return $refs; }