Several minor rewrites, getter GET_JACKPOT_POINTS() added
[mailer.git] / inc / mysql-manager.php
index 23f4621a6df002b9b2f957d673a0403d093596d6..102a3de242ca0f87ac1ffe51ce5cd1d5a58922cf 100644 (file)
@@ -117,10 +117,10 @@ function checkModulePermissions ($mod) {
        // Check for prefix is a extension...
        $modSplit = explode("_", $mod);
        $extension = ''; $mod_chk = $mod;
-       //* DEBUG: */ echo __LINE__."*".count($modSplit)."*/".$mod."*<br />";
+       //* DEBUG: */ OUTPUT_HTML(__LINE__."*".count($modSplit)."*/".$mod."*<br />");
        if (count($modSplit) == 2) {
                // Okay, there is a seperator (_) in the name so is the first part a module?
-               //* DEBUG: */ echo __LINE__."*".$modSplit[0]."*<br />";
+               //* DEBUG: */ OUTPUT_HTML(__LINE__."*".$modSplit[0]."*<br />");
                if (EXT_IS_ACTIVE($modSplit[0])) {
                        // The prefix is an extension's name, so let's set it
                        $extension = $modSplit[0]; $mod = $modSplit[1];
@@ -370,9 +370,9 @@ function ADD_DESCR ($accessLevel, $FQFN, $return = false, $output = true) {
                        $OUT = $prefix . "<strong><a class=\"you_are_here\" href=\"{!URL!}/modules.php?module=" . $modCheck . '&amp;' . $type . '=' . $search.$LINK_ADD . "\">" . $ret . "</a></strong>\n";
 
                        // Can we close the you-are-here navigation?
-                       //* DEBUG: */ echo __LINE__."*".$type.'/'.getWhat()."*<br />\n";
+                       //* DEBUG: */ OUTPUT_HTML(__LINE__."*".$type.'/'.getWhat()."*<br />");
                        if (($type == 'what') || (($type == 'action') && ((!isWhatSet()) || (getWhat() == 'overview')))) {
-                               //* DEBUG: */ echo __LINE__.'+'.$type."+<br />\n";
+                               //* DEBUG: */ OUTPUT_HTML(__LINE__.'+'.$type."+<br />");
                                // Add closing div and br-tag
                                $OUT .= "</div><br />\n";
                                $GLOBALS['nav_depth'] = '0';
@@ -418,12 +418,12 @@ function ADD_MENU ($mode, $act, $wht) {
        // 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)".$AND." ORDER BY `sort` ASC",
                array($mode), __FUNCTION__, __LINE__);
-       //* DEBUG: */ echo __LINE__.'/'.$main_cnt.'/'.$main_action.'/'.$sub_what.':'.getWhat()."*<br />\n";
+       //* DEBUG: */ OUTPUT_HTML(__LINE__.'/'.$main_cnt.'/'.$main_action.'/'.$sub_what.':'.getWhat()."*<br />");
        if (SQL_NUMROWS($result_main) > 0) {
                OUTPUT_HTML("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"".$mode."_menu\">");
                // There are menus available, so we simply display them... :)
                while ($content = SQL_FETCHARRAY($result_main)) {
-                       //* DEBUG: */ echo __LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.$sub_what.':'.getWhat()."*<br />\n";
+                       //* DEBUG: */ OUTPUT_HTML(__LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.$sub_what.':'.getWhat()."*<br />");
                        // Init variables
                        enableBlockMode(false);
                        $act = $content['action'];
@@ -452,7 +452,7 @@ function ADD_MENU ($mode, $act, $wht) {
                                        $OUT = '';
 
                                        // Full file name for checking menu
-                                       //* DEBUG: */ echo __LINE__.":!!!!".$content['sub_what']."!!!<br />\n";
+                                       //* DEBUG: */ OUTPUT_HTML(__LINE__.":!!!!".$content['sub_what']."!!!<br />");
                                        $INC = sprintf("inc/modules/%s/what-%s.php", $mode, $content['sub_what']);
                                        if (isIncludeReadable($INC)) {
                                                if ((!empty($wht)) && (($wht == $content['sub_what']))) {
@@ -505,16 +505,16 @@ function ADD_MENU ($mode, $act, $wht) {
                                        if ((!EXT_IS_ACTIVE($content['action'])) || ($content['action'] == 'online')) OUTPUT_HTML("<tr>
 
   <td class=\"".$mode."_menu_whats\">");
-                                       //* DEBUG: */ echo __LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.$content['sub_what'].':'.getWhat()."*<br />\n";
+                                       //* DEBUG: */ OUTPUT_HTML(__LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.$content['sub_what'].':'.getWhat()."*<br />");
                                        loadInclude($INC_BLOCK);
-                                       //* DEBUG: */ echo __LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.$content['sub_what'].':'.getWhat()."*<br />\n";
+                                       //* DEBUG: */ OUTPUT_HTML(__LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.$content['sub_what'].':'.getWhat()."*<br />");
                                        if ((!EXT_IS_ACTIVE($content['action'])) || ($content['action'] == 'online')) OUTPUT_HTML("  </td>
 </tr>");
                                }
-                               //* DEBUG: */ echo __LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.$content['sub_what'].':'.getWhat()."*<br />\n";
+                               //* DEBUG: */ OUTPUT_HTML(__LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.$content['sub_what'].':'.getWhat()."*<br />");
                        }
                        $main_cnt++;
-                       //* DEBUG: */ echo __LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.$content['sub_what'].':'.getWhat()."*<br />\n";
+                       //* DEBUG: */ OUTPUT_HTML(__LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.$content['sub_what'].':'.getWhat()."*<br />");
                        if (SQL_NUMROWS($result_main) > $main_cnt) {
                                OUTPUT_HTML("<tr><td class=\"".$mode."_menu_seperator\"></td></tr>");
                        } // END - if
@@ -524,7 +524,7 @@ function ADD_MENU ($mode, $act, $wht) {
                SQL_FREERESULT($result_main);
 
                // Close table
-               //* DEBUG: */ echo __LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.$content['sub_what'].':'.getWhat()."*<br />\n";
+               //* DEBUG: */ OUTPUT_HTML(__LINE__.'/'.$main_cnt.'/'.$content['action'].'/'.$content['sub_what'].':'.getWhat()."*<br />");
                OUTPUT_HTML("</table>");
        } // END - if
 }
@@ -575,12 +575,12 @@ function IS_MEMBER () {
                                $ret = true;
                        } else {
                                // Maybe got locked etc.
-                               //* DEBUG: */ echo __LINE__."!!!<br />";
+                               //* DEBUG: */ OUTPUT_HTML(__LINE__."!!!<br />");
                                destroyUserSession();
                        }
                } else {
                        // Cookie data is invalid!
-                       //* DEBUG: */ echo __LINE__."***<br />";
+                       //* DEBUG: */ OUTPUT_HTML(__LINE__."***<br />");
                        destroyUserSession();
                }
 
@@ -588,7 +588,7 @@ function IS_MEMBER () {
                SQL_FREERESULT($result);
        } else {
                // Cookie data is invalid!
-               //* DEBUG: */ echo __LINE__."///<br />";
+               //* DEBUG: */ OUTPUT_HTML(__LINE__."///<br />");
                destroyUserSession();
        }
 
@@ -603,7 +603,7 @@ function IS_MEMBER () {
 function IS_ADMIN ($admin = '') {
        // Init variables
        $ret = false; $passCookie = ''; $valPass = '';
-       //* DEBUG: */ echo __LINE__."ADMIN:".$admin."<br />";
+       //* DEBUG: */ OUTPUT_HTML(__LINE__."ADMIN:".$admin."<br />");
 
        // If admin login is not given take current from cookies...
        if ((empty($admin)) && (isSessionVariableSet('admin_login')) && (isSessionVariableSet('admin_md5'))) {
@@ -611,7 +611,7 @@ function IS_ADMIN ($admin = '') {
                $admin = getSession('admin_login');
                $passCookie = getSession('admin_md5');
        }
-       //* DEBUG: */ echo __LINE__."ADMIN:".$admin.'/'.$passCookie."<br />";
+       //* DEBUG: */ OUTPUT_HTML(__LINE__."ADMIN:".$admin.'/'.$passCookie."<br />");
 
        // Search in array for entry
        if (isset($GLOBALS['cache_array']['admin_hash'])) {
@@ -650,12 +650,12 @@ function IS_ADMIN ($admin = '') {
 
        if (!empty($valPass)) {
                // Check if password is valid
-               //* DEBUG: */ print __FUNCTION__."*".$valPass.'/'.$passCookie."*<br />\n";
+               //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."*".$valPass.'/'.$passCookie."*<br />");
                $ret = (($valPass == $passCookie) || ((strlen($valPass) == 32) && ($valPass == md5($passCookie))) || (($valPass == "*FAILED*") && (!EXT_IS_ACTIVE('cache'))));
        } // END - if
 
        // Return result of comparision
-       //* DEBUG: */ if (!$ret) echo __LINE__."OK!<br />";
+       //* DEBUG: */ if (!$ret) OUTPUT_HTML(__LINE__."OK!<br />");
        return $ret;
 }
 
@@ -747,7 +747,7 @@ function isMenuActionValid ($mode, $act, $wht, $UPDATE=false) {
        $add = '';
        if ((!IS_ADMIN()) && ($mode != 'admin')) $add = " AND `locked`='N'";
 
-       //* DEBUG: */ echo __LINE__.':'.$mode.'/'.$act.'/'.$wht."*<br />\n";
+       //* DEBUG: */ OUTPUT_HTML(__LINE__.':'.$mode.'/'.$act.'/'.$wht."*<br />");
        if (($mode != 'admin') && ($UPDATE === 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",
@@ -921,7 +921,7 @@ function getModeAction ($mode, $wht) {
        // Init status
        $ret = '';
 
-       //* DEBUG: */ echo __LINE__.'='.$mode.'/'.$wht.'/'.getAction()."=<br />";
+       //* DEBUG: */ OUTPUT_HTML(__LINE__.'='.$mode.'/'.$wht.'/'.getAction()."=<br />");
        if ((empty($wht)) && ($mode != 'admin')) {
                $wht = 'welcome';
                if (getConfig('index_home') != '') $wht = getConfig('index_home');
@@ -943,7 +943,7 @@ function getModeAction ($mode, $wht) {
                // Get it directly from URL
                return getAction();
        }
-       //* DEBUG: */ echo __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): ret=".$ret."<br />\n";
+       //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): ret=".$ret."<br />");
 
        // Does the module have a menu?
        if (MODULE_HAS_MENU($mode)) {
@@ -1097,7 +1097,7 @@ function removeReceiver (&$receivers, $key, $uid, $pool_id, $stats_id = '', $bon
 // Calculate sum (default) or count records of given criteria
 function GET_TOTAL_DATA ($search, $tableName, $lookFor = 'id', $whereStatement = 'userid', $countRows = false, $add = '') {
        $ret = 0;
-       //* DEBUG: */ echo $search.'/'.$tableName.'/'.$lookFor.'/'.$whereStatement.'/'.$add.'<br />\n';
+       //* DEBUG: */ OUTPUT_HTML($search.'/'.$tableName.'/'.$lookFor.'/'.$whereStatement.'/'.$add.'<br />');
        if ((empty($search)) && ($search != '0')) {
                // Count or sum whole table?
                if ($countRows === true) {
@@ -1111,12 +1111,12 @@ function GET_TOTAL_DATA ($search, $tableName, $lookFor = 'id', $whereStatement =
                }
        } elseif (($countRows === true) || ($lookFor == 'userid')) {
                // Count rows
-               //* DEBUG: */ echo "COUNT!<br />\n";
+               //* DEBUG: */ OUTPUT_HTML("COUNT!<br />");
                $result = SQL_QUERY_ESC("SELECT COUNT(`%s`) FROM `{!_MYSQL_PREFIX!}_%s` WHERE `%s`='%s'".$add,
                        array($lookFor, $tableName, $whereStatement, $search), __FUNCTION__, __LINE__);
        } else {
                // Add all rows
-               //* DEBUG: */ echo "SUM!<br />\n";
+               //* DEBUG: */ OUTPUT_HTML("SUM!<br />");
                $result = SQL_QUERY_ESC("SELECT SUM(`%s`) FROM `{!_MYSQL_PREFIX!}_%s` WHERE `%s`='%s'".$add,
                        array($lookFor, $tableName, $whereStatement, $search), __FUNCTION__, __LINE__);
        }
@@ -1188,7 +1188,7 @@ function getReferalLevelPercents ($level) {
  *               for default value will cause no referal will get points ever!!!)
  */
 function ADD_POINTS_REFSYSTEM ($subject, $uid, $points, $send_notify = false, $rid = '0', $locked = false, $add_mode = 'ref') {
-       //* DEBUG: */ print "----------------------- <font color=\"#00aa00\">".__FUNCTION__." - ENTRY</font> ------------------------<ul><li>\n";
+       //* DEBUG: */ OUTPUT_HTML("----------------------- <font color=\"#00aa00\">".__FUNCTION__." - ENTRY</font> ------------------------<ul><li>\n");
        global $DATA;
 
        // Convert mode to lower-case
@@ -1210,12 +1210,12 @@ function ADD_POINTS_REFSYSTEM ($subject, $uid, $points, $send_notify = false, $r
        // Count up referal depth
        if (!isset($GLOBALS['ref_level'])) {
                // Initialialize referal system
-               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): Referal system initialized!<br />\n";
+               //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): Referal system initialized!<br />");
                $GLOBALS['ref_level'] = 0;
        } else {
                // Increase referal level
                $GLOBALS['ref_level']++;
-               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): Referal level increased. DEPTH={$GLOBALS['ref_level']}<br />\n";
+               //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): Referal level increased. DEPTH={$GLOBALS['ref_level']}<br />");
        }
 
        // Default is 'normal' points
@@ -1226,9 +1226,9 @@ function ADD_POINTS_REFSYSTEM ($subject, $uid, $points, $send_notify = false, $r
 
        // Check user account
        $result_user = SQL_QUERY_ESC("SELECT refid, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s AND `status`='CONFIRMED' LIMIT 1",
-       array(bigintval($uid)), __FUNCTION__, __LINE__);
+               array(bigintval($uid)), __FUNCTION__, __LINE__);
 
-       //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},numRows=".SQL_NUMROWS($result_user).",points={$points}<br />\n";
+       //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},numRows=".SQL_NUMROWS($result_user).",points={$points}<br />");
        if (SQL_NUMROWS($result_user) == 1) {
                // This is the user and his ref
                list($ref, $email) = SQL_FETCHROW($result_user);
@@ -1236,32 +1236,32 @@ function ADD_POINTS_REFSYSTEM ($subject, $uid, $points, $send_notify = false, $r
 
                // Get percents
                $per = getReferalLevelPercents($GLOBALS['ref_level']);
-               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},points={$points},depth={$GLOBALS['ref_level']},per={$per},mode={$add_mode}<br />\n";
+               //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},points={$points},depth={$GLOBALS['ref_level']},per={$per},mode={$add_mode}<br />");
 
                // Some percents found?
                if ($per > 0) {
                        // Calculate new points
-                       //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},points={$points},per={$per},depth={$GLOBALS['ref_level']}<br />\n";
+                       //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},points={$points},per={$per},depth={$GLOBALS['ref_level']}<br />");
                        $ref_points = $points * $per / 100;
 
                        // Pay refback here if level > 0 and in ref-mode
                        if ((EXT_IS_ACTIVE('refback')) && ($GLOBALS['ref_level'] > 0) && ($per < 100) && ($add_mode == "ref") && (isset($GLOBALS['cache_array']['add_uid'][$uid]))) {
-                               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},data={$GLOBALS['cache_array']['add_uid'][$uid]},ref_points={$ref_points},depth={$GLOBALS['ref_level']} - BEFORE!<br />\n";
+                               //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},data={$GLOBALS['cache_array']['add_uid'][$uid]},ref_points={$ref_points},depth={$GLOBALS['ref_level']} - BEFORE!<br />");
                                $ref_points = ADD_REFBACK_POINTS($GLOBALS['cache_array']['add_uid'][$uid], $uid, $points, $ref_points);
-                               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},data={$GLOBALS['cache_array']['add_uid'][$uid]},ref_points={$ref_points},depth={$GLOBALS['ref_level']} - AFTER!<br />\n";
+                               //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},data={$GLOBALS['cache_array']['add_uid'][$uid]},ref_points={$ref_points},depth={$GLOBALS['ref_level']} - AFTER!<br />");
                        } // 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",
                        array($data, $data, $ref_points, bigintval($uid), bigintval($GLOBALS['ref_level'])), __FUNCTION__, __LINE__);
-                       //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):data={$data},ref_points={$ref_points},uid={$uid},depth={$GLOBALS['ref_level']},mode={$add_mode} - UPDATE! (".SQL_AFFECTEDROWS().")<br />\n";
+                       //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):data={$data},ref_points={$ref_points},uid={$uid},depth={$GLOBALS['ref_level']},mode={$add_mode} - UPDATE! (".SQL_AFFECTEDROWS().")<br />");
 
                        // 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)",
                                array($data, bigintval($uid), bigintval($GLOBALS['ref_level']), $ref_points), __FUNCTION__, __LINE__);
-                               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):data={$data},ref_points={$ref_points},uid={$uid},depth={$GLOBALS['ref_level']},mode={$add_mode} - INSERTED! (".SQL_AFFECTEDROWS().")<br />\n";
+                               //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):data={$data},ref_points={$ref_points},uid={$uid},depth={$GLOBALS['ref_level']},mode={$add_mode} - INSERTED! (".SQL_AFFECTEDROWS().")<br />");
                        } // END - if
 
                        // Update mediadata as well
@@ -1305,7 +1305,7 @@ function ADD_POINTS_REFSYSTEM ($subject, $uid, $points, $send_notify = false, $r
                        // Maybe there's another ref?
                        if (($ref > 0) && ($points > 0) && ($ref != $uid) && ($add_mode == 'ref')) {
                                // Then let's credit him here...
-                               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},ref={$ref},points={$points} - ADVANCE!<br />\n";
+                               //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},ref={$ref},points={$points} - ADVANCE!<br />");
                                ADD_POINTS_REFSYSTEM(sprintf("%s_ref:%s", $subject, $GLOBALS['ref_level']), $ref, $points, $send_notify, $ref, $locked);
                        } // END - if
                } // END - if
@@ -1313,7 +1313,7 @@ function ADD_POINTS_REFSYSTEM ($subject, $uid, $points, $send_notify = false, $r
 
        // Free result
        SQL_FREERESULT($result_user);
-       //* DEBUG: */ print "</li></ul>----------------------- <font color=\"#aa0000\">".__FUNCTION__." - EXIT</font> ------------------------<br />\n";
+       //* DEBUG: */ OUTPUT_HTML("</li></ul>----------------------- <font color=\"#aa0000\">".__FUNCTION__." - EXIT</font> ------------------------<br />");
 }
 
 // Wrapper function for ADD_POINTS_REFSYSTEM()
@@ -1325,19 +1325,19 @@ function ADD_POINTS_REFSYSTEM_DIRECT ($subject, $uid, $points) {
 function updateReferalCounter ($uid) {
        // Make it sure referal level zero (member him-/herself) is at least selected
        if (empty($GLOBALS['cache_array']['ref_level'][$uid])) $GLOBALS['cache_array']['ref_level'][$uid] = 1;
-       //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},level={$GLOBALS['cache_array']['ref_level'][$uid]}<br />\n";
+       //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},level={$GLOBALS['cache_array']['ref_level'][$uid]}<br />");
 
        // Update counter
        SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_refsystem` SET `counter`=`counter`+1 WHERE `userid`=%s AND `level`='%s' LIMIT 1",
                array(bigintval($uid), $GLOBALS['cache_array']['ref_level'][$uid]), __FUNCTION__, __LINE__);
 
        // When no entry was updated then we have to create it here
-       //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):updated=".SQL_AFFECTEDROWS()."<br />\n";
+       //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):updated=".SQL_AFFECTEDROWS()."<br />");
        if (SQL_AFFECTEDROWS() < 1) {
                // First count!
                SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_refsystem` (`userid`, `level`, `counter`) VALUES (%s,%s,1)",
                        array(bigintval($uid), $GLOBALS['cache_array']['ref_level'][$uid]), __FUNCTION__, __LINE__);
-               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid}<br />\n";
+               //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid}<br />");
        } // END - if
 
        // Check for his referal
@@ -1349,16 +1349,16 @@ function updateReferalCounter ($uid) {
 
        // Free memory
        SQL_FREERESULT($result);
-       //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},ref={$ref}<br />\n";
+       //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},ref={$ref}<br />");
 
        // When he has a referal...
        if (($ref > 0) && ($ref != $uid)) {
                // Move to next referal level and count his counter one up!
-               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):ref={$ref} - ADVANCE!<br />\n";
+               //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):ref={$ref} - ADVANCE!<br />");
                $GLOBALS['cache_array']['ref_level'][$uid]++; updateReferalCounter($ref);
        } elseif ((($ref == $uid) || ($ref == 0)) && (GET_EXT_VERSION('cache') >= '0.1.2')) {
                // Remove cache here
-               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):ref={$ref} - CACHE!<br />\n";
+               //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):ref={$ref} - CACHE!<br />");
                rebuildCacheFiles('refsystem', 'refsystem');
        }
 
@@ -1682,20 +1682,37 @@ function generateMetaDescriptionCode ($mod, $wht) {
        unset($GLOBALS['ref_level']);
 }
 
-// Adds points to the jackpot
-function ADD_JACKPOT ($points) {
-       $result = SQL_QUERY("SELECT points FROM `{!_MYSQL_PREFIX!}_jackpot` WHERE ok='ok' LIMIT 1", __FUNCTION__, __LINE__);
+function GET_JACKPOT_POINTS () {
+       // Default is zero
+       $jackpot = '0.00000';
+
+       // Read them
+       $result = SQL_QUERY("SELECT `points` FROM `{!_MYSQL_PREFIX!}_jackpot` WHERE `ok`='ok' LIMIT 1", __FUNCTION__, __LINE__);
+
+       // Do we have an entry?
        if (SQL_NUMROWS($result) == 0) {
-               // Create line
-               SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_jackpot` (ok, points) VALUES ('ok','%s')", array($points), __FUNCTION__, __LINE__);
+               // No, so create line
+               SQL_QUERY("INSERT INTO `{!_MYSQL_PREFIX!}_jackpot` (`ok`, `points`) VALUES ('ok','0.00000')", __FUNCTION__, __LINE__);
        } else {
-               // Free memory
-               SQL_FREERESULT($result);
+               // Read the line
+               list($jackpot) = SQL_FETCHROW($result);
+       }
+
+       // Free result
+       SQL_FREERESULT($result);
+
+       // Return them
+       return $jackpot;
+}
 
-               // Update points
-               SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_jackpot` SET points=points+%s WHERE ok='ok' LIMIT 1",
+// Adds points to the jackpot
+function ADD_JACKPOT ($points) {
+       // Get jackpot points for dummy
+       $jackpot = GET_JACKPOT_POINTS();
+
+       // Update points
+       SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_jackpot` SET `points`=`points`+%s WHERE `ok`='ok' LIMIT 1",
                array($points), __FUNCTION__, __LINE__);
-       }
 }
 
 // Subtracts points from the jackpot
@@ -1703,24 +1720,22 @@ function SUB_JACKPOT ($points) {
        // First failed
        $ret = '-1';
 
-       // Get current points
-       $result = SQL_QUERY("SELECT points FROM `{!_MYSQL_PREFIX!}_jackpot` WHERE ok='ok' LIMIT 1", __FUNCTION__, __LINE__);
-       if (SQL_NUMROWS($result) == 0) {
-               // Create line
-               SQL_QUERY("INSERT INTO `{!_MYSQL_PREFIX!}_jackpot` (ok, points) VALUES ('ok', 0.00000)", __FUNCTION__, __LINE__);
-       } else {
-               // Read points
-               list($jackpot) = SQL_FETCHROW($result);
-               if ($jackpot >= $points) {
-                       // Update points when there are enougth points in jackpot
-                       SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_jackpot` SET points=points-%s WHERE ok='ok' LIMIT 1",
+       // Get jackpot points for dummy
+       $jackpot = GET_JACKPOT_POINTS();
+
+       // Enougth points i jackpot?
+       if ($jackpot >= $points) {
+               // Update points when there are enougth points in jackpot
+               SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_jackpot` SET `points`=`points`-%s WHERE `ok`='ok' LIMIT 1",
                        array($points), __FUNCTION__, __LINE__);
-                       $ret = $jackpot - $points;
-               } // END - if
-       }
+               $ret = $jackpot - $points;
+       } // END - if
 
        // Free memory
        SQL_FREERESULT($result);
+
+       // Return the result
+       return $ret;
 }
 
 // Checks wether the extension demo is actuve and the admin login is demo (password needs to be demo, too!)
@@ -1739,7 +1754,7 @@ function getWhatFromModule ($modCheck) {
        // Default is empty
        $wht = '';
 
-       //* DEBUG: */ echo __LINE__.'!'.$modCheck."!<br />\n";
+       //* DEBUG: */ OUTPUT_HTML(__LINE__.'!'.$modCheck."!<br />");
        switch ($modCheck) {
                case 'admin':
                        $wht = 'overview';
@@ -1831,11 +1846,11 @@ function updateConfiguration ($entries, $values, $updateMode='') {
 
        // Run database update
        //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "entries={$entries}");
-       SQL_QUERY("UPDATE `{!_MYSQL_PREFIX!}_config` SET ".$entries." WHERE config=0 LIMIT 1", __FUNCTION__, __LINE__);
+       SQL_QUERY("UPDATE `{!_MYSQL_PREFIX!}_config` SET ".$entries." WHERE `config`=0 LIMIT 1", __FUNCTION__, __LINE__);
 
        // Get affected rows
        $affectedRows = SQL_AFFECTEDROWS();
-       //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):entries={$entries},affectedRows={$affectedRows}<br />\n";
+       //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):entries={$entries},affectedRows={$affectedRows}<br />");
 
        // Rebuild cache
        rebuildCacheFiles('config', 'config');
@@ -1861,9 +1876,12 @@ function PREPARE_SQL_HTML_HOLIDAY ($mode) {
 // "Getter" for total available receivers
 function getTotalReceivers ($mode='normal') {
        // Query database
-       $result_all = SQL_QUERY("SELECT userid
-FROM `{!_MYSQL_PREFIX!}_user_data`
-WHERE `status`='CONFIRMED' AND receive_mails > 0 ".PREPARE_SQL_HTML_HOLIDAY($mode),
+       $result_all = SQL_QUERY("SELECT
+       `userid`
+FROM
+       `{!_MYSQL_PREFIX!}_user_data`
+WHERE
+       `status`='CONFIRMED' AND `receive_mails` > 0 ".PREPARE_SQL_HTML_HOLIDAY($mode),
        __FUNCTION__, __LINE__);
 
        // Get num rows
@@ -1899,8 +1917,8 @@ function generateCategoryOptionsList ($mode) {
                        $CATS['name'][] = $content['cat'];
 
                        // Check which users are in this category
-                       $result_uids = SQL_QUERY_ESC("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_cats` WHERE cat_id=%s",
-                       array(bigintval($content['id'])), __FUNCTION__, __LINE__);
+                       $result_uids = SQL_QUERY_ESC("SELECT `userid` FROM `{!_MYSQL_PREFIX!}_user_cats` WHERE `cat_id`=%s",
+                               array(bigintval($content['id'])), __FUNCTION__, __LINE__);
 
                        // Start adding all
                        $uid_cnt = 0;
@@ -1911,7 +1929,7 @@ function generateCategoryOptionsList ($mode) {
 FROM
        `{!_MYSQL_PREFIX!}_user_data`
 WHERE
-       `userid`=%s AND `status`='CONFIRMED' AND receive_mails > 0".PREPARE_SQL_HTML_HOLIDAY($mode)."
+       `userid`=%s AND `status`='CONFIRMED' AND `receive_mails` > 0".PREPARE_SQL_HTML_HOLIDAY($mode)."
 LIMIT 1",
                                        array(bigintval($ucat)), __FUNCTION__, __LINE__);
 
@@ -1977,35 +1995,35 @@ function addBonusMailToQueue ($subject, $text, $receiverList, $points, $seconds,
 
                // Add HTML mail
                SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_bonus`
-(subject, text, receivers, points, time, data_type, timestamp, url, cat_id, target_send, mails_sent, html_msg)
+(`subject`, `text`, `receivers`, `points`, `time`, `data_type`, `timestamp`, `url`, `cat_id`, `target_send`, `mails_sent`, `html_msg`)
 VALUES ('%s','%s','%s','%s','%s','NEW', UNIX_TIMESTAMP(),'%s','%s','%s','%s','%s')",
                array(
-               $subject,
-               $text,
-               $receiverList,
-               $points,
-               $seconds,
-               $url,
-               $cat,
-               $target,
-               bigintval($receiver),
-               $HTML
+                       $subject,
+                       $text,
+                       $receiverList,
+                       $points,
+                       $seconds,
+                       $url,
+                       $cat,
+                       $target,
+                       bigintval($receiver),
+                       $HTML
                ), __FUNCTION__, __LINE__);
        } else {
                // Add regular mail
                SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_bonus`
-(subject, text, receivers, points, time, data_type, timestamp, url, cat_id, target_send, mails_sent)
+(`subject`, `text`, `receivers`, `points`, `time`, `data_type`, `timestamp`, `url`, `cat_id`, `target_send`, `mails_sent`)
 VALUES ('%s','%s','%s','%s','%s','NEW', UNIX_TIMESTAMP(),'%s','%s','%s','%s')",
                array(
-               $subject,
-               $text,
-               $receiverList,
-               $points,
-               $seconds,
-               $url,
-               $cat,
-               $target,
-               bigintval($receiver),
+                       $subject,
+                       $text,
+                       $receiverList,
+                       $points,
+                       $seconds,
+                       $url,
+                       $cat,
+                       $target,
+                       bigintval($receiver),
                ), __FUNCTION__, __LINE__);
        }
 }
@@ -2087,9 +2105,12 @@ function getTimestampFromUserStats ($type, $data, $uid = 0) {
        } // 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'
+       $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),
@@ -2122,7 +2143,7 @@ function insertUserStatsRecord ($uid, $type, $data) {
        if ((!getTimestampFromUserStats($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), __FUNCTION__, __LINE__);
+                       array(bigintval($uid), $type, $data), __FUNCTION__, __LINE__);
        } elseif (is_array($data)) {
                // Invalid data!
                DEBUG_LOG(__FUNCTION__, __LINE__, "uid={$uid},type={$type},data={".gettype($data).": Invalid statistics data type!");
@@ -2131,7 +2152,7 @@ function insertUserStatsRecord ($uid, $type, $data) {
 
 // "Getter" for array for user refs and points in given level
 function getUserReferalPoints ($uid, $level) {
-       //* DEBUG: */ print "----------------------- <font color=\"#00aa00\">".__FUNCTION__." - ENTRY</font> ------------------------<ul><li>\n";
+       //* DEBUG: */ OUTPUT_HTML("----------------------- <font color=\"#00aa00\">".__FUNCTION__." - ENTRY</font> ------------------------<ul><li>\n");
        // Default is no refs and no nickname
        $add = '';
        $refs = array();
@@ -2142,15 +2163,25 @@ function getUserReferalPoints ($uid, $level) {
        } // 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
+       $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)), __FUNCTION__, __LINE__);
+               array(
+                       bigintval($uid),
+                       bigintval($level)
+               ), __FUNCTION__, __LINE__);
 
        // Are there some entries?
        if (SQL_NUMROWS($result) > 0) {
@@ -2194,7 +2225,7 @@ ORDER BY ur.refid ASC",
        SQL_FREERESULT($result);
 
        // Return result
-       //* DEBUG: */ print "</li></ul>----------------------- <font color=\"#aa0000\">".__FUNCTION__." - EXIT</font> ------------------------<br />\n";
+       //* DEBUG: */ OUTPUT_HTML("</li></ul>----------------------- <font color=\"#aa0000\">".__FUNCTION__." - EXIT</font> ------------------------<br />");
        return $refs;
 }
 
@@ -2202,7 +2233,7 @@ ORDER BY ur.refid ASC",
 function reduceRecipientReceivedMails ($column, $id, $count) {
        // Search for mail in database
        $result = SQL_QUERY_ESC("SELECT `userid` FROM `{!_MYSQL_PREFIX!}_user_links` WHERE `%s`=%s ORDER BY `userid` ASC LIMIT %s",
-       array($column, bigintval($id), $count), __FUNCTION__, __LINE__);
+               array($column, bigintval($id), $count), __FUNCTION__, __LINE__);
 
        // Are there entries?
        if (SQL_NUMROWS($result) > 0) {