]> git.mxchange.org Git - mailer.git/blobdiff - inc/mysql-manager.php
More fixes, missing js.php added
[mailer.git] / inc / mysql-manager.php
index be834e68f24b556582d5ffb35979fa11e559cfd4..b47722f6d9c735cc4c978dc6a3ab34744c7d953b 100644 (file)
@@ -1074,16 +1074,17 @@ function REMOVE_RECEIVER(&$ARRAY, $key, $uid, $pool_id, $stats_id="", $bonus=fal
        // Return status for sending routine
        return $ret;
 }
-//
+
+// Calculate sum (default) or count records of given criteria
 function GET_TOTAL_DATA($search, $tableName, $lookFor, $whereStatement="userid", $onlyRows=false, $add="") {
        $ret = 0;
        if ($onlyRows) {
                // Count rows
-               $result = SQL_QUERY_ESC("SELECT COUNT(%s) FROM "._MYSQL_PREFIX."_%s WHERE %s='%s'%s",
+               $result = SQL_QUERY_ESC("SELECT COUNT(`%s`) FROM `"._MYSQL_PREFIX."_%s` WHERE `%s`='%s'%s",
                 array($lookFor, $tableName, $whereStatement, $search, $add), __FILE__, __LINE__);
        } else {
                // Add all rows
-               $result = SQL_QUERY_ESC("SELECT SUM(%s) FROM "._MYSQL_PREFIX."_%s WHERE %s='%s'%s",
+               $result = SQL_QUERY_ESC("SELECT SUM(`%s`) FROM `"._MYSQL_PREFIX."_%s` WHERE `%s`='%s'%s",
                 array($lookFor, $tableName, $whereStatement, $search, $add), __FILE__, __LINE__);
        }
 
@@ -1525,7 +1526,7 @@ function GET_ADMIN_DEFAULT_ACL ($aid) {
        } elseif (!EXT_IS_ACTIVE("cache")) {
                // Load from database
                $result_aid = SQL_QUERY_ESC("SELECT default_acl FROM "._MYSQL_PREFIX."_admins WHERE id=%s LIMIT 1",
-                       array(bigintval($ret)), __FILE__, __LINE__);
+                       array(bigintval($aid)), __FILE__, __LINE__);
                if (SQL_NUMROWS($result_aid) == 1) {
                        // Fetch data
                        list($ret) = SQL_FETCHROW($result_aid);
@@ -2267,5 +2268,28 @@ ORDER BY ur.refid ASC",
        return $refs;
 }
 
-//
+// Recuced the amount of received emails for the receipients for given email
+function REDUCT_RECIPIENT_RECEIVED_MAILS ($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), __FILE__, __LINE__);
+
+       // Are there entries?
+       if (SQL_NUMROWS($result) > 0) {
+               // Now load all userids for one big query!
+               $UIDs = array();
+               while (list($uid) = SQL_FETCHROW($result)) {
+                       $UIDs[$uid] = $uid;
+               } // END - while
+
+               // Now update all user accounts
+               SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_user_data` SET `emails_received`=`emails_received`-1 WHERE `userid` IN (%s) LIMIT %s",
+                       array(implode(",", $UIDs), count($UIDs)), __FILE__, __LINE__);
+       } // END - if
+
+       // Free result
+       SQL_FREERESULT($result);
+}
+
+// [EOF]
 ?>