X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=inc%2Fmysql-manager.php;h=322626c01f6f50e53158e9b7cbc0c1659acbff7e;hb=5dc48c7ca2416a0893a34a2e049827a4b4ce68b9;hp=5c996cea14c0f6c20ee8cb74c222ae101d37505c;hpb=11cb7c74eace090fb8e1de4176e96e92b4cc6541;p=mailer.git diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 5c996cea14..322626c01f 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -42,54 +42,6 @@ if (!defined('__SECURITY')) { die(); } // END - if -// "Getter" for module title -function getModuleTitle ($module) { - // Init variables - $data['title'] = ''; - $result = false; - - // Is the script installed? - if (isInstalled()) { - // Check if cache is valid - if ((isExtensionInstalledAndNewer('cache', '0.1.2')) && (isset($GLOBALS['cache_array']['modules']['module'])) && (in_array($module, $GLOBALS['cache_array']['modules']['module']))) { - // Load from cache - $data['title'] = $GLOBALS['cache_array']['modules']['title'][$module]; - - // Update cache hits - incrementStatsEntry('cache_hits'); - } elseif (!isExtensionActive('cache')) { - // Load from database - $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1", - array($module), __FUNCTION__, __LINE__); - - // Is the entry there? - if (SQL_NUMROWS($result)) { - // Get the title from database - $data = SQL_FETCHARRAY($result); - } // END - if - - // Free the result - SQL_FREERESULT($result); - } - } // END - if - - // Trim name - $data['title'] = trim($data['title']); - - // Still no luck or empty title? - if (empty($data['title'])) { - // No name found - $data['title'] = getMaskedMessage('UNKNOWN_MODULE_DETECTED', $module); - if ((is_resource($result)) && (SQL_HASZERONUMS($result))) { - // Add module to database - $dummy = checkModulePermissions($module); - } // END - if - } // END - if - - // Return name - return $data['title']; -} - // "Getter" for module description // @TODO Can we cache this? function getTitleFromMenu ($mode, $what, $column = 'what', $ADD='') { @@ -122,177 +74,6 @@ function getTitleFromMenu ($mode, $what, $column = 'what', $ADD='') { return $data['title']; } -// Check validity of a given module name (no file extension) -function checkModulePermissions ($module = '') { - // Is it empty (default), then take the current one - if (empty($module)) $module = getModule(); - - // Do we have cache? - if (isset($GLOBALS['module_status'][$module])) { - // Then use it - return $GLOBALS['module_status'][$module]; - } // END - if - - // Filter module name (names with low chars and underlines are fine!) - $module = preg_replace('/[^a-z_]/', '', $module); - - // Check for prefix is a extension... - $modSplit = explode('_', $module); - $extension = ''; $module_chk = $module; - //* DEBUG: */ print(__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]."*
"); - if (isExtensionActive($modSplit[0])) { - // The prefix is an extension's name, so let's set it - $extension = $modSplit[0]; $module = $modSplit[1]; - } // END - if - } // END - if - - // Major error in module registry is the default - $ret = 'major'; - - // Check if script is installed if not return a 'done' to prevent some errors - if ((isInstallationPhase()) || (!isAdminRegistered())) { - // Not installed or no admin registered or in installation phase - return 'done'; - } // END - if - - // Init data array - $data = array( - 'locked' => 'Y', - 'hidden' => 'N', - 'admin_only' => 'N', - 'mem_only' => 'N' - ); - - // By default nothing is found - $found = false; - - // Check if cache is latest version - if (isExtensionInstalledAndNewer('cache', '0.1.2')) { - // Is the cache there? - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Using cache.'); - if (isset($GLOBALS['cache_array']['modules']['locked'][$module_chk])) { - // Check cache - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cache found.'); - $data['locked'] = $GLOBALS['cache_array']['modules']['locked'][$module_chk]; - $data['hidden'] = $GLOBALS['cache_array']['modules']['hidden'][$module_chk]; - $data['admin_only'] = $GLOBALS['cache_array']['modules']['admin_only'][$module_chk]; - $data['mem_only'] = $GLOBALS['cache_array']['modules']['mem_only'][$module_chk]; - - // Update cache hits - incrementStatsEntry('cache_hits'); - $found = true; - } else { - // No, then we have to update it! - $ret = 'cache_miss'; - } - } elseif (!isExtensionActive('cache')) { - // Check for module in database - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Using database.'); - $result = SQL_QUERY_ESC("SELECT `locked`, `hidden`, `admin_only`, `mem_only` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1", - array($module_chk), __FUNCTION__, __LINE__); - if (SQL_NUMROWS($result) == 1) { - // Read data - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Entry found.'); - $data = SQL_FETCHARRAY($result); - $found = true; - } elseif (isDebugModeEnabled()) { - // Debug message only in debug-mode... - logDebugMessage(__FUNCTION__, __LINE__, 'Module ' . $module_chk . ' not found!'); - } - - // Free result - SQL_FREERESULT($result); - } - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . $ret); - - // Is the module found? - if ($found === true) { - // Check returned values against current access permissions - // - // Admin access ----- Guest access ----- --- Guest or member? --- - if ((isAdmin()) || (($data['locked'] != 'Y') && ($data['admin_only'] != 'Y') && (($data['mem_only'] != 'Y') || (isMember())))) { - // If you are admin you are welcome for everything! - $ret = 'done'; - } elseif ($data['locked'] == 'Y') { - // Module is locked - $ret = 'locked'; - } elseif (($data['mem_only'] == 'Y') && (!isMember())) { - // You have to login first! - $ret = 'mem_only'; - } elseif (($data['admin_only'] == 'Y') && (!isAdmin())) { - // Only the Admin is allowed to enter this module! - $ret = 'admin_only'; - } else { - // @TODO Nothing helped??? - logDebugMessage(__FUNCTION__, __LINE__, sprintf("ret=%s,locked=%s,admin=%s,mem=%s", - $ret, - $data['locked'], - $data['admin_only'], - $data['mem_only'] - )); - } - } // END - if - - // Still no luck or not found? - if (($found === false) && (!isExtensionActive('cache')) && ($ret != 'done')) { - // ----- Legacy module ----- ---- Module in base folder ---- --- Module with extension's name --- - if ((isIncludeReadable(sprintf("inc/modules/%s.php", $module))) || (isIncludeReadable(sprintf("%s.php", $module))) || (isIncludeReadable(sprintf("%s/%s.php", $extension, $module)))) { - // Data is missing so we add it - if (isExtensionInstalledAndNewer('sql_patches', '0.3.6')) { - // Since 0.3.6 we have a has_menu column, this took me a half hour - // to find a loop here... *sigh* - SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_mod_reg` -(`module`, `locked`, `hidden`, `mem_only`, `admin_only`, `has_menu`) VALUES -('%s','Y','N','N','N','N')", array($module_chk), __FUNCTION__, __LINE__); - } else { - // Wrong/missing sql_patches! - SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_mod_reg` -(`module`, `locked`, `hidden`, `mem_only`, `admin_only`) VALUES -('%s','Y','N','N','N')", array($module_chk), __FUNCTION__, __LINE__); - } - - // Everthing is fine? - if (SQL_AFFECTEDROWS() < 1) { - // Something bad happend! - return 'major'; - } // END - if - - // Destroy cache here - // @TODO Rewrite this to a filter - if ((getOutputMode() == '0') || (getOutputMode() == -1)) rebuildCache('modules', 'modules'); - - // And reload data - unset($GLOBALS['module_status'][$module]); - $ret = checkModulePermissions($module_chk); - } else { - // Module not found we don't add it to the database - $ret = '404'; - } - } elseif (($ret == 'cache_miss') && (getOutputMode() == '0')) { - // Rebuild the cache files - 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", - $module, - $ret, - $data['locked'], - $data['hidden'], - $data['mem_only'], - $data['admin_only'], - getOutputMode() - )); - } - - // Return the value - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . $ret); - $GLOBALS['module_status'][$module] = $ret; - return $ret; -} - // Add menu description pending on given file name (without path!) function addMenuDescription ($accessLevel, $FQFN, $return = false) { // Use only filename of the FQFN... @@ -373,9 +154,9 @@ 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 .= ''; $GLOBALS['nav_depth'] = '0'; @@ -426,13 +207,13 @@ 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/"translate" variables + //* DEBUG: */ debugOutput(__LINE__ . '/' . $main_cnt . '/' . $content['action'] . ':' . getWhat() . '*'); + // Disable the block-mode enableBlockMode(false); // Load menu header template @@ -469,7 +250,7 @@ ORDER BY $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 @@ -481,7 +262,7 @@ ORDER BY $OUT .= ''; } else { // Not found! - open - $OUT .= ''; + $OUT .= ''; } // Menu title @@ -526,12 +307,12 @@ ORDER BY 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 @@ -540,7 +321,7 @@ ORDER BY // 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); @@ -575,7 +356,7 @@ ORDER BY ); // 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 } @@ -733,7 +514,7 @@ function fetchUserData ($userid, $column = 'userid') { } // This patched function will reduce many SELECT queries for the specified or current admin login -function isAdmin ($adminLogin = '') { +function isAdmin () { // No admin in installation phase! if ((isInstallationPhase()) || (!isAdminRegistered())) { return false; @@ -741,39 +522,45 @@ function isAdmin ($adminLogin = '') { // Init variables $ret = false; + $adminId = '0'; $passCookie = ''; $valPass = ''; - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminLogin.'
'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminId); // If admin login is not given take current from cookies... - if ((empty($adminLogin)) && (isSessionVariableSet('admin_login')) && (isSessionVariableSet('admin_md5'))) { + if ((isSessionVariableSet('admin_id')) && (isSessionVariableSet('admin_md5'))) { // Get admin login and password from session/cookies - $adminLogin = getSession('admin_login'); + $adminId = getSession('admin_id'); $passCookie = getSession('admin_md5'); } // END - if - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminLogin.'/'.$passCookie.'
'); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminId.'/'.$passCookie); + + // Abort if admin id is zero + if ($adminId == '0') { + return false; + } // END - if // Do we have cache? - if (!isset($GLOBALS['is_admin'][$adminLogin])) { + if (!isset($GLOBALS['is_admin'][$adminId])) { // Init it with failed - $GLOBALS['is_admin'][$adminLogin] = false; + $GLOBALS['is_admin'][$adminId] = false; // Search in array for entry if (isset($GLOBALS['admin_hash'])) { // Use cached string $valPass = $GLOBALS['admin_hash']; - } elseif ((!empty($passCookie)) && (isAdminHashSet($adminLogin) === true) && (!empty($adminLogin))) { + } elseif ((!empty($passCookie)) && (isAdminHashSet($adminId) === true) && (!empty($adminId))) { // Login data is valid or not? - $valPass = encodeHashForCookie(getAdminHash($adminLogin)); + $valPass = encodeHashForCookie(getAdminHash($adminId)); // Cache it away $GLOBALS['admin_hash'] = $valPass; // Count cache hits incrementStatsEntry('cache_hits'); - } elseif ((!empty($adminLogin)) && ((!isExtensionActive('cache')) || (isAdminHashSet($adminLogin) === false))) { + } elseif ((!empty($adminId)) && ((!isExtensionActive('cache')) || (isAdminHashSet($adminId) === false))) { // Get admin hash and hash it - $valPass = encodeHashForCookie(getAdminHash($adminLogin)); + $valPass = encodeHashForCookie(getAdminHash($adminId)); // Cache it away $GLOBALS['admin_hash'] = $valPass; @@ -782,12 +569,12 @@ function isAdmin ($adminLogin = '') { if (!empty($valPass)) { // Check if password is valid //* 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')))); + $GLOBALS['is_admin'][$adminId] = (($GLOBALS['admin_hash'] == $passCookie) || ((strlen($GLOBALS['admin_hash']) == 32) && ($GLOBALS['admin_hash'] == md5($passCookie))) || (($GLOBALS['admin_hash'] == '*FAILED*') && (!isExtensionActive('cache')))); } // END - if } // END - if // Return result of comparision - return $GLOBALS['is_admin'][$adminLogin]; + return $GLOBALS['is_admin'][$adminId]; } // Generates a list of "max receiveable emails per day" @@ -877,19 +664,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 @@ -919,7 +717,7 @@ function getActionFromModuleWhat ($module, $what) { // Init status $data['action'] = ''; - //* DEBUG: */ print(__LINE__.'='.$module.'/'.$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()) { @@ -953,7 +751,7 @@ function getActionFromModuleWhat ($module, $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($module)) { @@ -988,12 +786,12 @@ function getActionFromModuleWhat ($module, $what) { // Get category name back function getCategory ($cid) { // Default is not found - $data['cat'] = getMessage('_CATEGORY_404'); + $data['cat'] = '{--_CATEGORY_404--}'; // Is the category id set? if ($cid == '0') { // No category - $data['cat'] = getMessage('_CATEGORY_NONE'); + $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", @@ -1014,7 +812,7 @@ function getCategory ($cid) { // Get a string of "mail title" and price back function getPaymentTitlePrice ($pid, $full=false) { // Default is not found - $ret = getMessage('_PAYMENT_404'); + $ret = '{--_PAYMENT_404--}'; // Load payment data $result = SQL_QUERY_ESC("SELECT `mail_title`, `price` FROM `{?_MYSQL_PREFIX?}_payments` WHERE `id`=%s LIMIT 1", @@ -1105,7 +903,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) { @@ -1119,12 +917,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__); } @@ -1145,7 +943,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 @@ -1197,7 +995,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 ------------------------
  • \n"); + //* DEBUG: */ debugOutput('----------------------- ' . __FUNCTION__ . ' - ENTRY ------------------------
    • '); // Convert mode to lower-case $add_mode = strtolower($add_mode); @@ -1226,12 +1024,12 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify // Count up referal depth if (!isset($GLOBALS['ref_level'])) { // Initialialize referal system - //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."): Referal system initialized!
      "); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '): Referal system initialized!'); $GLOBALS['ref_level'] = '0'; } else { // Increase referal level $GLOBALS['ref_level']++; - //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."): Referal level increased. DEPTH={$GLOBALS['ref_level']}
      "); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '): Referal level increased. DEPTH='.$GLOBALS['ref_level']); } // Default is 'normal' points @@ -1241,39 +1039,39 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify if ($locked === true) $data = 'locked_points'; // Check user account - //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},points={$points}
      "); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):userid='.$userid.',points='.$points); if (fetchUserData($userid)) { // This is the user and his ref $GLOBALS['cache_array']['add_userid'][getUserData('refid')] = $userid; // Get percents $per = getReferalLevelPercents($GLOBALS['ref_level']); - //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},points={$points},depth={$GLOBALS['ref_level']},per={$per},mode={$add_mode}
      "); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):userid='.$userid.',points='.$points.',depth='.$GLOBALS['ref_level'].',per='.$per.',mode='.$add_mode); // Some percents found? if ($per > 0) { // Calculate new points - //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},points={$points},per={$per},depth={$GLOBALS['ref_level']}
      "); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):userid='.$userid.',points='.$points.',per='.$per.',depth='.$GLOBALS['ref_level']); $ref_points = $points * $per / 100; // Pay refback here if level > 0 and in ref-mode - if ((isExtensionActive('refback')) && ($GLOBALS['ref_level'] > 0) && ($per < 100) && ($add_mode == "ref") && (isset($GLOBALS['cache_array']['add_userid'][$userid]))) { - //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},data={$GLOBALS['cache_array']['add_userid'][$userid]},ref_points={$ref_points},depth={$GLOBALS['ref_level']} - BEFORE!
      "); + if ((isExtensionActive('refback')) && ($GLOBALS['ref_level'] > 0) && ($per < 100) && ($add_mode == 'ref') && (isset($GLOBALS['cache_array']['add_userid'][$userid]))) { + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):userid='.$userid.',data='.$GLOBALS['cache_array']['add_userid'][$userid].',ref_points='.$ref_points.',depth='.$GLOBALS['ref_level'].' - BEFORE!'); $ref_points = addRefbackPoints($GLOBALS['cache_array']['add_userid'][$userid], $userid, $points, $ref_points); - //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},data={$GLOBALS['cache_array']['add_userid'][$userid]},ref_points={$ref_points},depth={$GLOBALS['ref_level']} - AFTER!
      "); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):userid='.$userid.',data='.$GLOBALS['cache_array']['add_userid'][$userid].',ref_points='.$ref_points.',depth='.$GLOBALS['ref_level'].' - AFTER!'); } // END - if // Update points... - SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `%s`=`%s`+%s WHERE `userid`=%s AND `ref_depth`='%s' LIMIT 1", + SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_points` SET `%s`=`%s`+%s WHERE `userid`=%s AND `ref_depth`=%s LIMIT 1", array($data, $data, $ref_points, bigintval($userid), bigintval($GLOBALS['ref_level'])), __FUNCTION__, __LINE__); - //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):data={$data},ref_points={$ref_points},userid={$userid},depth={$GLOBALS['ref_level']},mode={$add_mode} - UPDATE! (".SQL_AFFECTEDROWS().")
      "); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):data='.$data.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$add_mode.' - UPDATE! ('.SQL_AFFECTEDROWS().')'); // No entry updated? if (SQL_AFFECTEDROWS() < 1) { // First ref in this level! :-) - SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_points` (`userid`,`ref_depth`,`%s`) VALUES (%s,'%s',%s)", + SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_points` (`userid`,`ref_depth`,`%s`) VALUES (%s,%s,%s)", array($data, bigintval($userid), bigintval($GLOBALS['ref_level']), $ref_points), __FUNCTION__, __LINE__); - //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):data={$data},ref_points={$ref_points},userid={$userid},depth={$GLOBALS['ref_level']},mode={$add_mode} - INSERTED! (".SQL_AFFECTEDROWS().")
      "); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):data='.$data.',ref_points='.$ref_points.',userid='.$userid.',depth='.$GLOBALS['ref_level'].',mode='.$add_mode.' - INSERTED! ('.SQL_AFFECTEDROWS().')'); } // END - if // Points updated, maybe I shall send him an email? @@ -1283,18 +1081,17 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify 'percents' => $per, 'level' => bigintval($GLOBALS['ref_level']), 'points' => $ref_points, - 'refid' => getUserData('refid') ); // Load email template $message = loadEmailTemplate('confirm-referal', $content, bigintval($userid)); // Send email - sendEmail($userid, getMessage('THANX_REFERAL_ONE_SUBJECT'), $message); + sendEmail($userid, '{--THANX_REFERAL_ONE_SUBJECT--}', $message); } elseif (($sendNotify === true) && (getUserData('refid') == '0') && ($locked === false) && ($add_mode == 'direct')) { // Prepare content $content = array( - 'text' => getMessage('REASON_DIRECT_PAYMENT'), + 'text' => '{--REASON_DIRECT_PAYMENT--}', 'points' => $ref_points ); @@ -1302,39 +1099,39 @@ function addPointsThroughReferalSystem ($subject, $userid, $points, $sendNotify $message = loadEmailTemplate('add-points', $content, $userid); // And sent it away - sendEmail($userid, getMessage('SUBJECT_DIRECT_PAYMENT'), $message); - if (!isGetRequestParameterSet('mid')) loadTemplate('admin_settings_saved', false, getMessage('ADMIN_POINTS_ADDED')); + sendEmail($userid, '{--DIRECT_PAYMENT_SUBJECT--}', $message); + if (!isGetRequestParameterSet('mid')) loadTemplate('admin_settings_saved', false, '{--ADMIN_POINTS_ADDED--}'); } // Maybe there's another ref? if ((getUserData('refid') > 0) && ($points > 0) && (getUserData('refid') != $userid) && ($add_mode == 'ref')) { // Then let's credit him here... - //* DEBUG: */ print(__FUNCTION__ . '(' . __LINE__."):userid={$userid},ref=".getUserData('refid').",points={$points} - ADVANCE!
      "); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):userid='.$userid.',ref='.getUserData('refid').',points='.$points.' - ADVANCE!'); addPointsThroughReferalSystem(sprintf("%s_ref:%s", $subject, $GLOBALS['ref_level']), getUserData('refid'), $points, $sendNotify, getUserData('refid'), $locked); } // END - if } // END - if } // END - if - //* DEBUG: */ print("
    ----------------------- ".__FUNCTION__." - EXIT ------------------------
    "); + //* DEBUG: */ debugOutput('
----------------------- '.__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 @@ -1346,17 +1143,17 @@ 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!
"); + //* DEBUG: */ debugOutput(__FUNCTION__ . '(' . __LINE__ . '):ref='.$ref.' - CACHE!'); rebuildCache('refsystem', 'refsystem'); } @@ -1421,10 +1218,7 @@ function getCurrentAdminId () { // Do we have cache? if (!isset($GLOBALS['current_admin_id'])) { // Get the admin login from session - $adminLogin = getSession('admin_login'); - - // "Solve" it into an id - $adminId = getAdminId($adminLogin); + $adminId = getSession('admin_id'); // Remember in cache securely setCurrentAdminId(bigintval($adminId)); @@ -1441,20 +1235,20 @@ function setCurrentAdminId ($currentAdminId) { } // Get password hash from administrator's login name -function getAdminHash ($adminLogin) { +function getAdminHash ($adminId) { // By default an invalid hash is returned $data['password'] = '-1'; - if (isAdminHashSet($adminLogin)) { + if (isAdminHashSet($adminId)) { // Check cache - $data['password'] = $GLOBALS['cache_array']['admin']['password'][$adminLogin]; + $data['password'] = $GLOBALS['cache_array']['admin']['password'][$adminId]; // 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($adminLogin), __FUNCTION__, __LINE__); + $result = SQL_QUERY_ESC("SELECT `password` FROM `{?_MYSQL_PREFIX?}_admins` WHERE `id`=%s LIMIT 1", + array(bigintval($adminId)), __FUNCTION__, __LINE__); // Do we have an entry? if (SQL_NUMROWS($result) == 1) { @@ -1462,7 +1256,7 @@ function getAdminHash ($adminLogin) { $data = SQL_FETCHARRAY($result); // Set cache - setAdminHash($adminLogin, $data['password']); + setAdminHash($adminId, $data['password']); } // END - if // Free result @@ -1725,7 +1519,7 @@ LIMIT 1", // Now a mail to the user and that's all... $message = loadEmailTemplate('del-user', $data, $userid); - sendEmail($userid, getMessage('ADMIN_DEL_ACCOUNT'), $message); + sendEmail($userid, '{--ADMIN_DEL_ACCOUNT--}', $message); // Ok, delete the account! SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1", array(bigintval($userid)), __FUNCTION__, __LINE__); @@ -1742,7 +1536,7 @@ function getWhatFromModule ($modCheck) { // Default is empty $what = ''; - //* DEBUG: */ print(__LINE__.'!'.$modCheck."!
"); + //* DEBUG: */ debugOutput(__LINE__.'!'.$modCheck.'!'); switch ($modCheck) { case 'admin': $what = 'overview'; @@ -1864,7 +1658,7 @@ function generateCategoryOptionsList ($mode) { } // END - foreach } else { // No cateogries are defined yet - $OUT = ''; + $OUT = ''; } // Return HTML code @@ -2000,7 +1794,7 @@ function generateReceiverList ($cat, $receiver, $mode = '') { // "Getter" for array for user refs and points in given level function getUserReferalPoints ($userid, $level) { - //* DEBUG: */ print("----------------------- ".__FUNCTION__." - ENTRY ------------------------
  • \n"); + //* DEBUG: */ debugOutput('----------------------- '.__FUNCTION__.' - ENTRY ------------------------
    • '); // Default is no refs and no nickname $add = ''; $refs = array(); @@ -2052,12 +1846,12 @@ ORDER BY } // END - if // Activity is 'active' by default because if autopurge is not installed - $row['activity'] = getMessage('MEMBER_ACTIVITY_ACTIVE'); + $row['activity'] = '{--MEMBER_ACTIVITY_ACTIVE--}'; // Is autopurge installed and the user inactive? - if ((isExtensionActive('autopurge')) && ((time() - getConfig('ap_inactive_since')) >= $row['last_online'])) { + if ((isExtensionActive('autopurge')) && ((time() - getApInactiveSince()) >= $row['last_online'])) { // Inactive user! - $row['activity'] = getMessage('MEMBER_ACTIVITY_INACTIVE'); + $row['activity'] = '{--MEMBER_ACTIVITY_INACTIVE--}'; } // END - if // Remove some entries @@ -2074,7 +1868,7 @@ ORDER BY SQL_FREERESULT($result); // Return result - //* DEBUG: */ print("
    ----------------------- ".__FUNCTION__." - EXIT ------------------------
    "); + //* DEBUG: */ debugOutput('
----------------------- '.__FUNCTION__.' - EXIT ------------------------
'); return $refs; } @@ -2131,6 +1925,9 @@ function createNewTask ($subject, $notes, $taskType, $userid = '0', $adminId = ' $subject, $notes ), __FUNCTION__, __LINE__, true, $strip); + + // Return insert id which is the task id + return SQL_INSERTID(); } // Updates last module / online time