-// Get timestamp for given stats type and data
-function USER_STATS_GET_TIMESTAMP ($type, $data, $uid = 0) {
- // Default timestamp is zero
- $stamp = 0;
-
- // User id set?
- if ((isset($GLOBALS['userid'])) && ($uid == 0)) {
- $uid = $GLOBALS['userid'];
- } // END - if
-
- // Is the extension installed and updated?
- if ((!EXT_IS_ACTIVE("sql_patches")) || (EXT_VERSION_IS_OLDER("sql_patches", "0.5.6"))) {
- // Return zero here
- return $stamp;
- } // END - if
-
- // Try to find the entry
- $result = SQL_QUERY_ESC("SELECT UNIX_TIMESTAMP(`inserted`) AS `stamp`
-FROM "._MYSQL_PREFIX."_user_stats_data
-WHERE userid=%s AND stats_type='%s' AND stats_data='%s'
-LIMIT 1",
- array(bigintval($uid), $type, $data), __FILE__, __LINE__);
-
- // Is the entry there?
- if (SQL_NUMROWS($result) == 1) {
- // Get this stamp
- list($stamp) = SQL_FETCHROW($result);
- } // END - if
-
- // Free result
- SQL_FREERESULT($result);
-
- // Return stamp
- return $stamp;
-}
-
-// Inserts user stats
-function USER_STATS_INSERT_RECORD ($uid, $type, $data) {
- // Is the extension installed and updated?
- if ((!EXT_IS_ACTIVE("sql_patches")) || (EXT_VERSION_IS_OLDER("sql_patches", "0.5.6"))) {
- // Return zero here
- return false;
- } // END - if
-
- // Does it exist?
- if ((!USER_STATS_GET_TIMESTAMP($type, $data, $uid)) && (!is_array($data))) {
- // Then insert it!
- SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_stats_data (`userid`,`stats_type`,`stats_data`) VALUES (%s,'%s','%s')",
- array(bigintval($uid), $type, $data), __FILE__, __LINE__);
- } elseif (is_array($data)) {
- // Invalid data!
- DEBUG_LOG(__FUNCTION__, __LINE__, " uid={$uid},type={$type},data={".gettype($data).": Invalid statistics data type!");
- }
-}
-
-// "Getter" for array for user refs and points in given level
-function GET_USER_REF_POINTS ($uid, $level) {
- global $_CONFIG;
-
- //* DEBUG: */ print "----------------------- <font color=\"#00aa00\">".__FUNCTION__." - ENTRY</font> ------------------------<ul><li>\n";
- // Default is no refs and no nickname
- $ADD = "";
- $refs = array();
-
- // Do we have nickname extension installed?
- if (EXT_IS_ACTIVE("nickname")) {
- $ADD = ", ud.nickname";
- } // END - if
-
- // Get refs from database
- $result = SQL_QUERY_ESC("SELECT ur.id, ur.refid, ud.status, ud.last_online, ud.mails_confirmed, ud.emails_received".$ADD."
-FROM "._MYSQL_PREFIX."_user_refs AS ur
-LEFT JOIN "._MYSQL_PREFIX."_user_points AS up
-ON ur.refid=up.userid AND ur.level=0
-LEFT JOIN `"._MYSQL_PREFIX."_user_data` AS ud
-ON ur.refid=ud.userid
-WHERE ur.userid=%s AND ur.level=%s
-ORDER BY ur.refid ASC",
- array(bigintval($uid), bigintval($level)), __FILE__, __LINE__);
-
- // Are there some entries?
- if (SQL_NUMROWS($result) > 0) {
- // Fetch all entries
- while ($row = SQL_FETCHARRAY($result)) {
- // Get total points of this user
- $row['points'] = GET_TOTAL_DATA($row['refid'], "user_points", "points") - GET_TOTAL_DATA($row['refid'], "user_data", "used_points");
-
- // Get unconfirmed mails
- $row['unconfirmed'] = GET_TOTAL_DATA($row['refid'], "user_links", "id", "userid", true);
-
- // Init clickrate with zero
- $row['clickrate'] = 0;
-
- // Is at least one mail received?
- if ($row['emails_received'] > 0) {
- // Calculate clickrate
- $row['clickrate'] = ($row['mails_confirmed'] / $row['emails_received'] * 100);
- } // END - if