]> git.mxchange.org Git - mailer.git/blobdiff - inc/mysql-manager.php
Fixes for running SQL queries
[mailer.git] / inc / mysql-manager.php
index 1f261f4f3b656668aa1804431fe3b54eabfc798b..7a4e9833adb57d38c63fa226e44989630bb21d61 100644 (file)
@@ -105,7 +105,7 @@ function CHECK_MODULE ($mod) {
 
        // Check if cache is latest version
        $locked = "Y"; $hidden = "N"; $admin = "N"; $mem = "N"; $found = false;
-       if ((GET_EXT_VERSION("cache") >= "0.1.2") && (isset($cacheArray['modules']['module'])) && (is_array($cacheArray['modules']['module']))) {
+       if (GET_EXT_VERSION("cache") >= "0.1.2") {
                // Is the module cached?
                if (isset($cacheArray['modules']['locked'][$mod_chk])) {
                        // Check cache
@@ -132,25 +132,28 @@ function CHECK_MODULE ($mod) {
                }
        }
 
-       // Check returned values against current access permissions
-       //
-       //  Admin access            ----- Guest access -----           --- Guest   or   member? ---
-       if ((IS_ADMIN()) || (($locked == "N") && ($admin == "N") && (($mem == "N") || (IS_MEMBER())))) {
-               // If you are admin you are welcome for everything!
-               $ret = "done";
-       } elseif ($locked == "Y") {
-               // Module is locked
-               $ret = "locked";
-       } elseif (($mem == "Y") && (!IS_MEMBER())) {
-               // You have to login first!
-               $ret = "mem_only";
-       } elseif (($admin == "Y") && (!IS_ADMIN())) {
-               // Only the Admin is allowed to enter this module!
-               $ret = "admin_only";
-       }
+       // Is the module found?
+       if ($found) {
+               // Check returned values against current access permissions
+               //
+               //  Admin access            ----- Guest access -----           --- Guest   or   member? ---
+               if ((IS_ADMIN()) || (($locked == "N") && ($admin == "N") && (($mem == "N") || (IS_MEMBER())))) {
+                       // If you are admin you are welcome for everything!
+                       $ret = "done";
+               } elseif ($locked == "Y") {
+                       // Module is locked
+                       $ret = "locked";
+               } elseif (($mem == "Y") && (!IS_MEMBER())) {
+                       // You have to login first!
+                       $ret = "mem_only";
+               } elseif (($admin == "Y") && (!IS_ADMIN())) {
+                       // Only the Admin is allowed to enter this module!
+                       $ret = "admin_only";
+               }
+       } // END - if
 
        // Still no luck or not found?
-       if (($ret == "major") || ($ret == "cache_miss") || (!$found)) {
+       if (($ret == "cache_miss") || (!$found)) {
                //              ----- Legacy module -----                                   ---- Module in base folder  ----                       --- Module with extension's name ---
                if ((FILE_READABLE(sprintf("%sinc/modules/%s.php", PATH, $mod))) || (FILE_READABLE(sprintf("%s%s.php", PATH, $mod))) || (FILE_READABLE(sprintf("%s%s/%s.php", PATH, $extension, $mod)))) {
                        // Data is missing so we add it
@@ -182,7 +185,17 @@ function CHECK_MODULE ($mod) {
                        // Module not found we don't add it to the database
                        $ret = "404";
                }
-       } // END - if
+       } elseif (!$found) {
+               // Problem with module detected
+               DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Problem in module %s detected. ret=%s, locked=%s, hidden=%s, mem=%s, admin=%s",
+                       $mod,
+                       $ret,
+                       $locked,
+                       $hidden,
+                       $mem,
+                       $admin
+               ));
+       }
 
        // Return the value
        return $ret;
@@ -1106,7 +1119,7 @@ function GET_REF_LEVEL_PERCENTS ($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: */ print "----------------------- <font color=\"#00aa00\">".__FUNCTION__." - ENTRY</font> ------------------------<ul><li>\n";
        global $_CONFIG, $DATA, $cacheArray;
 
        // Convert mode to lower-case
@@ -1128,12 +1141,12 @@ function ADD_POINTS_REFSYSTEM ($subject, $uid, $points, $send_notify=false, $rid
        // 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: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): Referal system initialized!<br />\n";
                $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: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): Referal level increased. DEPTH={$GLOBALS['ref_level']}<br />\n";
        }
 
        // Default is "normal" points
@@ -1144,9 +1157,9 @@ function ADD_POINTS_REFSYSTEM ($subject, $uid, $points, $send_notify=false, $rid
 
        // 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)), __FILE__, __LINE__);
+               array(bigintval($uid)), __FILE__, __LINE__);
 
-       /* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},numRows=".SQL_NUMROWS($result_user).",points={$points}<br />\n";
+       //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},numRows=".SQL_NUMROWS($result_user).",points={$points}<br />\n";
        if (SQL_NUMROWS($result_user) == 1) {
                // This is the user and his ref
                list($ref, $email) = SQL_FETCHROW($result_user);
@@ -1154,31 +1167,32 @@ function ADD_POINTS_REFSYSTEM ($subject, $uid, $points, $send_notify=false, $rid
 
                // Get percents
                $per = GET_REF_LEVEL_PERCENTS($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: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},points={$points},depth={$GLOBALS['ref_level']},per={$per},mode={$add_mode}<br />\n";
 
                // 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: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},points={$points},per={$per},depth={$GLOBALS['ref_level']}<br />\n";
                        $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($cacheArray['add_uid'][$uid]))) {
-                               /* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},data={$cacheArray['add_uid'][$uid]},ref_points={$ref_points},depth={$GLOBALS['ref_level']} - BEFORE!<br />\n";
+                               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},data={$cacheArray['add_uid'][$uid]},ref_points={$ref_points},depth={$GLOBALS['ref_level']} - BEFORE!<br />\n";
                                $ref_points = ADD_REFBACK_POINTS($cacheArray['add_uid'][$uid], $uid, $points, $ref_points);
-                               /* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},data={$cacheArray['add_uid'][$uid]},ref_points={$ref_points},depth={$GLOBALS['ref_level']} - AFTER!<br />\n";
+                               //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},data={$cacheArray['add_uid'][$uid]},ref_points={$ref_points},depth={$GLOBALS['ref_level']} - AFTER!<br />\n";
                        } // 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'])), __FILE__, __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";
+                               array($data, $data, $ref_points, bigintval($uid), bigintval($GLOBALS['ref_level'])), __FILE__, __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";
 
                        // No entry updated?
                        if (SQL_AFFECTEDROWS() < 1) {
                                // First ref in this level! :-)
-                               $result = 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), __FILE__, __LINE__);
+                               $result = 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), __FILE__, __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";
                        } // END - if
 
                        // Update mediadata as well
@@ -1222,7 +1236,7 @@ function ADD_POINTS_REFSYSTEM ($subject, $uid, $points, $send_notify=false, $rid
                        // 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: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):uid={$uid},ref={$ref},points={$points} - ADVANCE!<br />\n";
                                ADD_POINTS_REFSYSTEM(sprintf("%s_ref:%s", $subject, $GLOBALS['ref_level']), $ref, $points, $send_notify, $ref, $locked);
                        } // END - if
                } // END - if
@@ -1230,7 +1244,7 @@ function ADD_POINTS_REFSYSTEM ($subject, $uid, $points, $send_notify=false, $rid
 
        // Free result
        SQL_FREERESULT($result_user);
-       /* DEBUG: */ print "</li></ul>----------------------- <font color=\"#aa0000\">".__FUNCTION__." - EXIT</font> ------------------------<br />\n";
+       //* DEBUG: */ print "</li></ul>----------------------- <font color=\"#aa0000\">".__FUNCTION__." - EXIT</font> ------------------------<br />\n";
 }
 //
 function UPDATE_REF_COUNTER ($uid) {