More misc fixes and rewrites (sorry, lame description)
[mailer.git] / inc / mysql-manager.php
index 76f6957921e860d40daed4920ea22c33a96a99ea..491bf296ffee12acb3e81cacc81c5a8297464957 100644 (file)
@@ -253,7 +253,7 @@ function checkModulePermissions ($mod) {
                        // Module not found we don't add it to the database
                        $ret = '404';
                }
-       } elseif ($ret == 'cache_miss') {
+       } elseif (($ret == 'cache_miss') && (getOutputMode() > -1)) {
                // Rebuild the cache files
                rebuildCacheFiles('modreg', 'modreg');
        } elseif ($found === false) {
@@ -800,7 +800,7 @@ function sendModeMails ($mod, $modes) {
                $hash = generatePassString($hashDB);
                if (($hash == getSession('u_hash')) || (REQUEST_POST('pass1') == REQUEST_POST('pass2'))) {
                        // Load user's data
-                       $result = SQL_QUERY_ESC("SELECT gender, surname, family, street_nr, country, zip, city, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s AND password='%s' LIMIT 1",
+                       $result = SQL_QUERY_ESC("SELECT gender, surname, family, street_nr, country, zip, city, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s AND password='%s' LIMIT 1",
                        array(getUserId(), $hashDB), __FUNCTION__, __LINE__);
                        if (SQL_NUMROWS($result) == 1) {
                                // Load the data
@@ -1225,7 +1225,7 @@ function ADD_POINTS_REFSYSTEM ($subject, $uid, $points, $send_notify = false, $r
        if ($locked) $data = 'locked_points';
 
        // Check user account
-       $result_user = SQL_QUERY_ESC("SELECT refid, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s AND `status`='CONFIRMED' LIMIT 1",
+       $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__);
 
        //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},numRows=".SQL_NUMROWS($result_user).",points={$points}<br />\n";
@@ -1252,7 +1252,7 @@ function ADD_POINTS_REFSYSTEM ($subject, $uid, $points, $send_notify = false, $r
                        } // 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($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";
 
@@ -1634,7 +1634,7 @@ WHERE p.userid=%s", array(bigintval($uid)), __FUNCTION__, __LINE__);
                list($points) = SQL_FETCHROW($result);
 
                // Delete points entries as well
-               SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_points` WHERE userid=%s", array(bigintval($uid)), __FUNCTION__, __LINE__);
+               SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_points` WHERE `userid`=%s", array(bigintval($uid)), __FUNCTION__, __LINE__);
 
                // Update mediadata as well
                if (GET_EXT_VERSION('mediadata') >= '0.0.4') {
@@ -1650,12 +1650,12 @@ WHERE p.userid=%s", array(bigintval($uid)), __FUNCTION__, __LINE__);
        SQL_FREERESULT($result);
 
        // Delete category selections as well...
-       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_cats` WHERE userid=%s",
+       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_cats` WHERE `userid`=%s",
        array(bigintval($uid)), __FUNCTION__, __LINE__);
 
        // Remove from rallye if found
        if (EXT_IS_ACTIVE('rallye')) {
-               SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_rallye_users` WHERE userid=%s",
+               SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_rallye_users` WHERE `userid`=%s",
                array(bigintval($uid)), __FUNCTION__, __LINE__);
        } // END - if
 
@@ -1664,7 +1664,7 @@ WHERE p.userid=%s", array(bigintval($uid)), __FUNCTION__, __LINE__);
        sendEmail($uid, getMessage('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($uid)), __FUNCTION__, __LINE__);
+       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1", array(bigintval($uid)), __FUNCTION__, __LINE__);
 }
 
 // Generates meta description for given module and 'what' value
@@ -1763,7 +1763,7 @@ function getWhatFromModule ($modCheck) {
 // Subtract points from database and mediadata cache
 function SUB_POINTS ($subject, $uid, $points) {
        // Add points to used points
-       SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET `used_points`=`used_points`+%s WHERE userid=%s LIMIT 1",
+       SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET `used_points`=`used_points`+%s WHERE `userid`=%s LIMIT 1",
                array($points, bigintval($uid)), __FUNCTION__, __LINE__);
 
        // Insert booking record
@@ -1906,9 +1906,14 @@ function generateCategoryOptionsList ($mode) {
                        $uid_cnt = 0;
                        // @TODO Rewrite this to $content = SQL_FETCHARRAY()
                        while (list($ucat) = SQL_FETCHROW($result_uids)) {
-                               $result_ver = SQL_QUERY_ESC("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data`
-WHERE userid=%s AND `status`='CONFIRMED' AND receive_mails > 0".PREPARE_SQL_HTML_HOLIDAY($mode)." LIMIT 1",
-                               array(bigintval($ucat)), __FUNCTION__, __LINE__);
+                               $result_ver = SQL_QUERY_ESC("SELECT
+       `userid`
+FROM
+       `{!_MYSQL_PREFIX!}_user_data`
+WHERE
+       `userid`=%s AND `status`='CONFIRMED' AND receive_mails > 0".PREPARE_SQL_HTML_HOLIDAY($mode)."
+LIMIT 1",
+                                       array(bigintval($ucat)), __FUNCTION__, __LINE__);
 
                                // Add user count
                                $uid_cnt += SQL_NUMROWS($result_ver);