Fix for deleting email
authorRoland Häder <roland@mxchange.org>
Tue, 15 Apr 2008 12:54:30 +0000 (12:54 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 15 Apr 2008 12:54:30 +0000 (12:54 +0000)
inc/functions.php
inc/language/de.php
inc/modules/admin/admin-inc.php
inc/modules/admin/what-del_email.php
inc/mysql-manager.php

index 3cdabf7..005fea7 100644 (file)
@@ -786,7 +786,11 @@ function LOAD_EMAIL_TEMPLATE($template, $content="", $UID="0") {
                break;
 
        case "add-points":
-               $points         = bigintval($_POST['points']);
+               if (isset($_POST['points'])) {
+                       $points         = bigintval($_POST['points']);
+               } else {
+                       $points = __POINTS_VALUE;
+               }
                break;
 
        case "guest_request_confirm":
index fc034ce..ff35894 100644 (file)
@@ -1102,6 +1102,8 @@ define('ADMIN_OPTION_SHOW_TIMINGS', "Skript-Statistiken im Seitenfuss einblenden
 define('ADMIN_OPTION_MAILID_REDIRECT', "Soll bei fehlerhafter/gel&ouml;schter Mailbuchung beim Best&auml;tigen die Mail auf die Hauptseite oder Ablehnungsseite weitergleitet werden?");
 define('ADMIN_CONFIG_MAILID_REDIRECT_INDEX', "Auf Hauptseite weiterleiten.");
 define('ADMIN_CONFIG_MAILID_REDIRECT_REJECT', "Auf Ablehnungsseite umleiten.");
+define('REASON_DIRECT_PAYMENT', "Direkte Gutschrift (siehe evtl. vorangegangene Mail)");
+define('SUBJECT_DIRECT_PAYMENT', "Direkte {!POINTS!}-Gutschrift durch das System");
 
 //
 ?>
index 6aba44b..f9f775a 100644 (file)
@@ -221,7 +221,7 @@ function admin_WriteData ($file, $comment, $prefix, $suffix, $DATA, $seek=0)
 //
 function ADMIN_DO_ACTION($wht)
 {
-       global $menuDesription, $menuTitle, $_CONFIG, $cacheArray, $link, $DATA;
+       global $menuDesription, $menuTitle, $_CONFIG, $cacheArray, $link, $DATA, $DEPTH;
        //* DEBUG: */ echo __LINE__."*".$wht."/".$GLOBALS['module']."/".$GLOBALS['action']."/".$GLOBALS['what']."*<br />\n";
        if (EXT_IS_ACTIVE("cache"))
        {
index 751ad74..3401751 100644 (file)
@@ -45,13 +45,18 @@ ADD_DESCR("admin", basename(__FILE__));
 
 if (!empty($_GET['mid'])) {
        // Load email data
-       $result = SQL_QUERY_ESC("SELECT id, sender, subject, url, timestamp FROM "._MYSQL_PREFIX."_pool WHERE id=%d LIMIT 1",
+       $result = SQL_QUERY_ESC("SELECT id, sender, subject, url, timestamp, payment_id FROM "._MYSQL_PREFIX."_pool WHERE id=%d LIMIT 1",
         array(bigintval($_GET['mid'])), __FILE__, __LINE__);
-       list ($id, $sender, $subject, $url, $timestamp,) = SQL_FETCHROW($result);
-       SQL_FREERESULT($result);
 
        // Delete mail only once
-       if ($sender > 0) {
+       if (SQL_NUMROWS($result) == 1) {
+               // Load data
+               list ($id, $sender, $subject, $url, $timestamp, $payId) = SQL_FETCHROW($result);
+               SQL_FREERESULT($result);
+
+               // Get points we shall pay back per mail
+               $price = GET_PAY_POINTS($payId, "price");
+
                // Prepare data for the template
                define('__ID'     , $id);
                define('__SENDER' , ADMIN_USER_PROFILE_LINK($sender));
@@ -70,25 +75,45 @@ if (!empty($_GET['mid'])) {
                SEND_EMAIL($sender, MEMBER_ORDER_DELETED, $msg_user);
 
                // Delete mail from queue
-               $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_pool WHERE id=%d LIMIT 1",
-                array(bigintval($_GET['mid'])), __FILE__, __LINE__);
+               //$result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_pool WHERE id=%d LIMIT 1",
+               // array(bigintval($_GET['mid'])), __FILE__, __LINE__);
 
                // Fetch right stats_id from pool
                $result = SQL_QUERY_ESC("SELECT s.id FROM "._MYSQL_PREFIX."_user_stats AS s
 LEFT JOIN "._MYSQL_PREFIX."_pool AS p
-ON s.pool_id=%d LIMIT 1",
+ON s.pool_id=p.id
+WHERE s.pool_id=%d LIMIT 1",
  array(bigintval($_GET['mid'])), __FILE__, __LINE__);
                if (SQL_NUMROWS($result) == 1) {
                        // Fetch stats id
                        list($stats_id) = SQL_FETCHROW($result);
                        SQL_FREERESULT($result);
 
+                       // Get all user links
+                       $result = SQL_QUERY_ESC("SELECT COUNT(id) AS 'cnt' FROM "._MYSQL_PREFIX."_user_links WHERE stats_id=%d",
+                               array(bigintval($stats_id)), __FILE__, __LINE__);
+
+                       // Get unconfirmed links for calculation of total points
+                       list($links) = SQL_FETCHROW($result);
+
+                       // Free result
+                       SQL_FREERESULT($result);
+
+                       // Calc total points and pay them back
+                       $totalPoints = $links * $price;
+                       //* DEBUG: */ echo $stats_id.":".$totalPoints."/".$links."/".$price."<br />\n";
+                       if ($totalPoints > 0) {
+                               // Pay back points
+                               //* DEBUG: */ echo "PAYBACK:".$sender."<br />\n";
+                               ADD_POINTS_REFSYSTEM($sender, $totalPoints, true, "0", false,"direct");
+                       }
+
                        // Remove links from DB
-                       $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE stats_id=%d",
-                        array(bigintval($stats_id)), __FILE__, __LINE__);
+                       //$result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE stats_id=%d",
+                       // array(bigintval($stats_id)), __FILE__, __LINE__);
 
                        // Output link for manually removing stats entry
-                       LOAD_TEMPLATE("admin_settings_saved", false, "<A href=\"".URL."/modules.php?module=admin&amp;what=del_email&amp;pid=".$_GET['mid']."\">".ADMIN_REMOVE_STATS_ENTRY."</A>");
+                       LOAD_TEMPLATE("admin_settings_saved", false, "<A href=\"".URL."/modules.php?module=admin&amp;what=del_email&amp;pid=".bigintval($_GET['mid'])."\">".ADMIN_REMOVE_STATS_ENTRY."</A>");
                }
        } else {
                // Mail already deleted!
@@ -103,11 +128,13 @@ ON s.pool_id=%d LIMIT 1",
        // Load data from bonus mail
        $result = SQL_QUERY_ESC("SELECT id, subject, url, timestamp FROM "._MYSQL_PREFIX."_bonus WHERE id=%d",
         array(bigintval($_GET['bid'])), __FILE__, __LINE__);
-       list ($id, $subject, $url, $timestamp) = SQL_FETCHROW($result);
-       SQL_FREERESULT($result);
 
        // Delete mail only once
-       if ($id > 0) {
+       if (SQL_NUMROWS($result) == 1) {
+               // Load data
+               list ($id, $subject, $url, $timestamp) = SQL_FETCHROW($result);
+               SQL_FREERESULT($result);
+
                // Delete bonus mail entirely from database
                $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_bonus WHERE id=%d LIMIT 1",
                 array(bigintval($_GET['bid'])), __FILE__, __LINE__);
index 46154a4..5cc8edd 100644 (file)
@@ -270,6 +270,7 @@ function ADD_DESCR($ACC_LVL, $file, $return = false, $output = true)
                        if (($type == "what") || (($type == "action") && (!isset($_GET['what'])) && ($GLOBALS['what'] != "welcome"))) {
                                //* DEBUG: */ echo __LINE__."+".$type."+<br />\n";
                                $OUT .= "</DIV><br />\n";
+                               $DEPTH="0";
                        }
                }
        }
@@ -1035,21 +1036,17 @@ function ADD_POINTS_REFSYSTEM($uid, $points, $send_notify=false, $rid="0", $lock
        global $DEPTH, $_CONFIG, $DATA, $link;
 
        // When $uid = 0 add points to jackpot
-       if ($uid == "0")
-       {
+       if ($uid == "0") {
                // Add points to jackpot
                ADD_JACKPOT($points);
                return;
        }
 
        // Count up referral depth
-       if (empty($DEPTH))
-       {
+       if (empty($DEPTH)) {
                // Initialialize referral system
                $DEPTH = "0";
-       }
-        else
-       {
+       } else {
                // Increase referral level
                $DEPTH++;
        }
@@ -1059,49 +1056,57 @@ function ADD_POINTS_REFSYSTEM($uid, $points, $send_notify=false, $rid="0", $lock
 
        $result_user = SQL_QUERY_ESC("SELECT refid, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d AND status='CONFIRMED' LIMIT 1",
         array(bigintval($uid)), __FILE__, __LINE__);
-       if (SQL_NUMROWS($result_user) == 1)
-       {
+       //* DEBUG */ echo "+".SQL_NUMROWS($result_user).":".$points."+<br />\n";
+       if (SQL_NUMROWS($result_user) == 1) {
                // This is the user and his ref
                list ($ref, $email) = SQL_FETCHROW($result_user);
                SQL_FREERESULT($result_user);
+
                $result = SQL_QUERY_ESC("SELECT percents FROM "._MYSQL_PREFIX."_refdepths WHERE level='%s' LIMIT 1",
                 array(bigintval($DEPTH)), __FILE__, __LINE__);
-               if (SQL_NUMROWS($result) == 1)
-               {
+               //* DEBUG */ echo "DEPTH:".$DEPTH."<br />\n";
+               if (SQL_NUMROWS($result) == 1) {
                        list($per) = SQL_FETCHROW($result);
                        SQL_FREERESULT($result);
                        $P = $points * $per / 100;
+                       //* DEBUG */ echo "ADD:".$P."<br />\n";
 
                        // Update points...
                        $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_points SET %s=%s+%s WHERE userid=%d AND ref_depth=%d LIMIT 1",
                         array($data, $data, $P, bigintval($uid), bigintval($DEPTH)), __FILE__, __LINE__);
-                       if (SQL_AFFECTEDROWS($link, __FILE__, __LINE__) == 0)
-                       {
+                       if (SQL_AFFECTEDROWS($link, __FILE__, __LINE__) == 0) {
                                // First ref in this level! :-)
                                $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_points (userid, ref_depth, %s) VALUES (%d, %d, %s)",
                                 array($data, bigintval($uid), bigintval($DEPTH), $P), __FILE__, __LINE__);
                        }
 
                        // Update mediadata as well
-                       if (GET_EXT_VERSION("mediadata") >= "0.0.4")
-                       {
+                       if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
                                // Update database
                                MEDIA_UPDATE_ENTRY(array("total_points"), "add", $P);
                        }
 
                        // Points updated, maybe I shall send him an email?
-                       if (($send_notify) && ($ref > 0) && (!$locked))
-                       {
+                       if (($send_notify) && ($ref > 0) && (!$locked)) {
                                //              0                1      2              3
                                $DATA = array($per, bigintval($DEPTH), $P, bigintval($ref));
                                $msg = LOAD_EMAIL_TEMPLATE("confirm-referral", "", bigintval($uid));
 
                                SEND_EMAIL($email, THANX_REFERRAL_ONE, $msg);
+                       } elseif (($send_notify) && ($ref == 0) && (!$locked) && ($add_mode == "direct") && (!defined('__POINTS_VALUE'))) {
+                               // Direct payment shall be notified about
+                               define('__POINTS_VALUE', $P);
+
+                               // Load message
+                               $msg = LOAD_EMAIL_TEMPLATE("add-points", REASON_DIRECT_PAYMENT, $uid);
+
+                               // And sent it away
+                               SEND_EMAIL($email, SUBJECT_DIRECT_PAYMENT, $msg);
+                               LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_POINTS_ADDED);
                        }
 
                        // Maybe there's another ref?
-                       if (($ref > 0) && ($points > 0) && ($ref != $uid) && ($add_mode == "ref"))
-                       {
+                       if (($ref > 0) && ($points > 0) && ($ref != $uid) && ($add_mode == "ref")) {
                                // Then let's credit him here...
                                ADD_POINTS_REFSYSTEM($ref, $points, $send_notify, $ref, $locked);
                        }