<?php
/************************************************************************
- * MXChange v0.2.1 Start: 02/12/2004 *
- * ================ Last change: 02/27/2004 *
+ * Mailer v0.2.1-FINAL Start: 02/12/2004 *
+ * =================== Last change: 02/27/2004 *
* *
* -------------------------------------------------------------------- *
* File : what-del_email.php *
* web : http://mc-p.mcserver.de *
* *
* -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder *
+ * Copyright (c) 2003 - 2009 by Roland Haeder *
+ * Copyright (c) 2009, 2010 by Mailer Developer Team *
* For more information visit: http://www.mxchange.org *
* *
* This program is free software; you can redistribute it and/or modify *
************************************************************************/
// Some security stuff...
-if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN()))
-{
- $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
- require($INC);
-}
+if ((!defined('__SECURITY')) || (!isAdmin())) {
+ die();
+} // END - if
// Add description as navigation point
-ADD_DESCR("admin", basename(__FILE__));
-OPEN_TABLE("100%", "admin_content admin_content_align", "");
-if (!empty($_GET['mid']))
-{
+addMenuDescription('admin', __FILE__);
+
+// Init counter for deleted mails
+$cnt = '0';
+
+if (isGetRequestParameterSet('mid')) {
// Load email data
- $result = SQL_QUERY_ESC("SELECT id, sender, subject, url, timestamp 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);
+ $result = SQL_QUERY_ESC("SELECT `id`, `sender`, `subject`, `url`, `timestamp`, `cat_id`, `payment_id` FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
+ array(bigintval(getRequestParameter('mid'))), __FILE__, __LINE__);
// Delete mail only once
- if ($sender > 0)
- {
+ if (SQL_NUMROWS($result) == 1) {
+ // Load data
+ $content = SQL_FETCHARRAY($result);
+
+ // Get points we shall pay back per mail
+ // @TODO Unused: $price = getPaymentPoints($content['payment_id'], 'price');
+ // @TODO Unused: cat_id, payment_id
+
// Prepare data for the template
- define('__ID' , $id);
- define('__SENDER' , ADMIN_USER_PROFILE_LINK($sender));
- define('__SUBJECT', $subject);
- define('__URL' , DEREFERER($url));
- define('__ORDERED', MAKE_DATETIME($timestamp, "0"));
+ $content['timestamp'] = generateDateTime($content['timestamp'], 0);
// Load template
- LOAD_TEMPLATE("admin_del_email_normal");
-
- // Transfer data to data array
- $DATA = array($url, $subject);
+ loadTemplate('admin_del_email_normal', false, $content);
// Load email template and send the email away
- $msg_user = LOAD_EMAIL_TEMPLATE("order-deleted", "", $sender);
- 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__);
+ $message_user = loadEmailTemplate('order-deleted', $content, $sender);
+ sendEmail($sender, '{--MEMBER_ORDER_DELETED--}', $message_user);
// 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",
- array(bigintval($_GET['mid'])), __FILE__, __LINE__);
- if (SQL_NUMROWS($result) == 1)
- {
+ $result_pool = SQL_QUERY_ESC("SELECT
+ s.id
+FROM
+ `{?_MYSQL_PREFIX?}_user_stats` AS s
+LEFT JOIN
+ `{?_MYSQL_PREFIX?}_pool` AS p
+ON
+ s.pool_id=p.id
+WHERE
+ s.`pool_id`=%s
+LIMIT 1",
+ array(bigintval(getRequestParameter('mid'))), __FILE__, __LINE__);
+ if (SQL_NUMROWS($result_pool) == 1) {
// Fetch stats id
- list($stats_id) = SQL_FETCHROW($result);
- SQL_FREERESULT($result);
+ list($stats_id) = SQL_FETCHROW($result_pool);
+
+ // Get all user links
+ $links = countSumTotalData($stats_id, 'user_links', 'userid', 'stats_id', true);
+
+ // Reset sent mails for recipient(s)
+ reduceRecipientReceivedMails('stats_id', getRequestParameter('mid'), $links);
+
+ // Calc total points and pay them back
+ $totalPoints = $links * $price;
+
+ // Shall we pay the points back to the user?
+ if ($totalPoints == 0) {
+ // No points repayed!
+ loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_POINTS_REPAYED--}');
+ } elseif (getConfig('repay_deleted_mails') != 'SHRED') {
+ //* DEBUG: */ debugOutput($stats_id.':'.$totalPoints.'/'.$links.'/'.$price);
+ // Shall we payback to user or jackpot?
+ if (getConfig('repay_deleted_mails') == 'JACKPOT') {
+ // Set jackpot
+ $sender = '0';
+ } // END - if
+
+ // Pay back points
+ //* DEBUG: */ debugOutput('PAYBACK:'.$sender);
+ addPointsDirectly('mail_deleted', $sender, $totalPoints);
+
+ // Output message
+ if (getConfig('repay_deleted_mails') == 'REPAY') {
+ // Repayed
+ loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_POINTS_REPAYED',
+ translateComma($totalPoints)
+ ));
+ } else {
+ // To jackpot
+ loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_POINTS_TO_JACKPOT',
+ translateComma($totalPoints)
+ ));
+ }
+ } else {
+ // Points shredded!
+ loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_POINTS_SHREDDED', translateComma($totalPoints)));
+ }
// 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__);
+ SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s",
+ array(bigintval($stats_id)), __FILE__, __LINE__);
+ $cnt += SQL_AFFECTEDROWS();
- // Output link for manually removing stats entry
- LOAD_TEMPLATE ("admin_settings_saved", false, "<A href=\"".URL."/modules.php?module=admin&what=del_email&pid=".$_GET['mid']."\">".ADMIN_REMOVE_STATS_ENTRY."</A>");
- }
- }
- else
- {
+ // Load template for link
+ loadTemplate('admin_settings_saved', false, '<a href="{%url=modules.php?module=admin&what=del_email&pid=' . bigintval(getRequestParameter('mid')) . '%}">{--ADMIN_REMOVE_STATS_ENTRY--}</a>');
+ } // END - if
+
+ // Free the result
+ SQL_FREERESULT($result_pool);
+
+ // Delete mail from queue
+ SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
+ array(bigintval(getRequestParameter('mid'))), __FILE__, __LINE__);
+ $cnt += SQL_AFFECTEDROWS();
+
+ // Output link for manually removing stats entry
+ outputHtml(getMaskedMessage('ADMIN_DELETED_MAILS_COUNT', $cnt));
+ } else {
// Mail already deleted!
- LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NORMAL_MAIL_ALREADY_DELETED);
+ loadTemplate('admin_settings_saved', false, '{--ADMIN_NORMAL_MAIL_ALREADY_DELETED--}');
}
-}
- elseif (!empty($_GET['pid']))
-{
+
+ // Free result
+ SQL_FREERESULT($result);
+} elseif (isGetRequestParameterSet('pid')) {
// Remove stats entries
- $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_stats WHERE pool_id=%d LIMIT 1",
- array(bigintval($_GET['pid'])), __FILE__, __LINE__);
- LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_USER_STATS_REMOVED);
-}
- elseif ((!empty($_GET['bid'])) && (EXT_IS_ACTIVE("bonus")))
-{
+ SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
+ array(bigintval(getRequestParameter('pid'))), __FILE__, __LINE__);
+
+ // Output message
+ loadTemplate('admin_settings_saved', false, '{--ADMIN_USER_STATS_REMOVED--}');
+} elseif ((isGetRequestParameterSet('bid')) && (isExtensionActive('bonus'))) {
// 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);
+ $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp`, `mails_sent` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
+ array(bigintval(getRequestParameter('bid'))), __FILE__, __LINE__);
// Delete mail only once
- if ($id > 0)
- {
+ if (SQL_NUMROWS($result) == 1) {
+ // Load data
+ $content = SQL_FETCHARRAY($result);
+
+ // Reset sent mails for recipient(s)
+ reduceRecipientReceivedMails('bonus_id', getRequestParameter('bid'), $content['mails_sent']);
+
+ // Init counter for deleted mails
+ $cnt = '0';
+
// 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__);
- $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE bonus_id=%d",
- array(bigintval($_GET['bid'])), __FILE__, __LINE__);
+ SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
+ array(bigintval(getRequestParameter('bid'))), __FILE__, __LINE__);
+ $cnt += SQL_AFFECTEDROWS();
+ SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
+ array(bigintval(getRequestParameter('bid'))), __FILE__, __LINE__);
+ $cnt += SQL_AFFECTEDROWS();
// Prepare data for the template
- define('__ID' , $id);
- define('__SUBJECT', $subject);
- define('__URL' , DEREFERER($url));
- define('__ORDERED', MAKE_DATETIME($timestamp, "0"));
+ $content['timestamp'] = generateDateTime($content['timestamp'], 0);
+ $content['cnt'] = $cnt;
// Load template
- LOAD_TEMPLATE("admin_del_email_bonus");
+ loadTemplate('admin_del_email_bonus', false, $content);
+ } else {
+ // Mail already deleted!
+ loadTemplate('admin_settings_saved', false, '{--ADMIN_BONUS_MAIL_ALREADY_DELETED--}');
}
- else
- {
+
+ // Free result
+ SQL_FREERESULT($result);
+} elseif ((isGetRequestParameterSet('nid')) && (isExtensionInstalledAndNewer('bonus', '0.8.7'))) {
+ // Load data from bonus mail
+ $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
+ array(bigintval(getRequestParameter('nid'))), __FILE__, __LINE__);
+
+ // Delete mail only once
+ if (SQL_NUMROWS($result) == 1) {
+ // Load data
+ $content = SQL_FETCHARRAY($result);
+
+ // Init counter for deleted mails
+ $cnt = '0';
+
+ // Delete bonus mail entirely from database
+ SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
+ array(bigintval(getRequestParameter('nid'))), __FILE__, __LINE__);
+ $cnt += SQL_AFFECTEDROWS();
+ SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
+ array(bigintval(getRequestParameter('nid'))), __FILE__, __LINE__);
+ $cnt += SQL_AFFECTEDROWS();
+
+ // Prepare data for the template
+ $content['timestamp'] = generateDateTime($content['timestamp'], 0);
+ $content['cnt'] = $cnt;
+
+ // Load template
+ loadTemplate('admin_del_email_notify', false, $content);
+ } else {
// Mail already deleted!
- LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_BONUS_MAIL_ALREADY_DELETED);
+ loadTemplate('admin_settings_saved', false, '{--ADMIN_NOTIFY_MAIL_ALREADY_DELETED--}');
}
-}
- else
-{
+
+ // Free result
+ SQL_FREERESULT($result);
+} else {
// No mail orders fond
- LOAD_TEMPLATE ("admin_settings_saved", false, ADMIN_WRONG_CALL);
+ loadTemplate('admin_settings_saved', false, '{--ADMIN_WRONG_CALL--}');
}
-CLOSE_TABLE();
-//
+
+// [EOF]
?>