2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 09/28/2003 *
4 * =================== Last change: 07/13/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-unlock_emails.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Unlock ordered emails *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Werbebuchungen freigeben *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009, 2010 by Mailer Developer Team *
20 * For more information visit: http://www.mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
47 $result_main = SQL_QUERY("SELECT
48 `id`, `sender`, `subject`, `payment_id`, `timestamp`, `url`, `target_send`, `cat_id`
50 `{?_MYSQL_PREFIX?}_pool`
54 `timestamp` ASC", __FILE__, __LINE__);
56 if ((!SQL_HASZERONUMS($result_main)) || (isFormSent('lock'))) {
57 if (isFormSent('accept')) {
58 if (ifPostContainsSelections()) {
60 foreach (postRequestParameter('sel') as $id => $value) {
64 // Order placed in queue...
65 $result = SQL_QUERY_ESC("SELECT
66 po.url, po.subject, po.sender, pay.payment, po.payment_id
68 `{?_MYSQL_PREFIX?}_pool` AS po
70 `{?_MYSQL_PREFIX?}_payments` AS pay
76 array($id), __FILE__, __LINE__);
79 if (SQL_NUMROWS($result) == 1) {
81 $content = SQL_FETCHARRAY($result);
83 // Is the surfbar installed?
84 // @TODO Rewrite these if-blocks to a filter
85 if ((isExtensionActive('surfbar')) && (getConfig('surfbar_migrate_order') == 'Y')) {
86 // Then "migrate" the URL to the surfbar
87 SURFBAR_ADMIN_MIGRATE_URL($content['url'], $content['sender']);
90 // Check for bonus extension version >= 0.4.4 for the order bonus
91 if ((isExtensionInstalledAndNewer('bonus', '0.4.4')) && (isBonusRallyeActive())) {
92 // Add points directly
93 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `bonus_order`=`bonus_order`+{?bonus_order?} WHERE `userid`=%s LIMIT 1",
94 array(bigintval($content['sender'])), __FILE__, __LINE__);
96 // Subtract bonus points from system
97 handleBonusPoints(getConfig('bonus_order'));
100 // Load email template
101 $message_user = loadEmailTemplate('order-accept', $content, $content['sender']);
104 sendEmail($content['sender'], '{--MEMBER_ORDER_ACCEPTED--}', $message_user);
106 // Unlock selected email
107 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `data_type`='NEW' WHERE `id`=%s AND `data_type`='ADMIN' LIMIT 1",
108 array($id), __FILE__, __LINE__);
112 SQL_FREERESULT($result);
116 $message = '{--ADMIN_MAILS_ACTIVATED--}';
119 $message = '{--ADMIN_MAILS_NOTHING_CHECKED--}';
122 // Mails unlocked for mail delivery
123 loadTemplate('admin_settings_saved', false, $message);
124 } elseif (isPostRequestParameterSet('reject')) {
125 if (ifPostContainsSelections()) {
126 // Reject mail orders
128 foreach (postRequestParameter('sel') as $id => $value) {
130 $id = bigintval($id);
132 // Load URL and subject from pool
133 $result = SQL_QUERY_ESC("SELECT `url`, `subject`, `sender` FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
134 array($id), __FILE__, __LINE__);
137 $content = SQL_FETCHARRAY($result);
140 SQL_FREERESULT($result);
142 // Load email template and send it away
143 $message_user = loadEmailTemplate('order-reject', $content, $content['sender']);
144 sendEmail($content['sender'], '{--MEMBER_ORDER_REJECTED--}', $message_user);
146 // If you do not enter an URL to redirect to, your URL will be set!
147 if ((!isPostRequestParameterSet('redirect')) || (postRequestParameter('redirect') == 'http://')) setPostRequestParameter('redirect', getUrl());
150 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET url='%s', `data_type`='NEW' WHERE `id`=%s LIMIT 1",
151 array(postRequestParameter('redirect'), $id),__FILE__, __LINE__);
153 // Prepare data for the row template
156 'url' => postRequestParameter('url', $id),
159 // Load row template and switch colors
160 $OUT .= loadTemplate('admin_unlock_emails_redir_row', true, $content);
163 // Load main template
164 loadTemplate('admin_unlock_emails_redir', false, $OUT);
167 loadTemplate('admin_settings_saved', false, '{--ADMIN_MAILS_NOTHING_CHECKED--}');
169 } elseif ((isFormSent('lock')) && (ifPostContainsSelections()) && (isUrlBlacklistEnabled())) {
171 foreach (postRequestParameter('sel') as $id => $url) {
173 $id = bigintval($id);
175 // Lookup in blacklist
176 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_url_blacklist` WHERE `url`='%s' LIMIT 1",
177 array($url), __FILE__, __LINE__);
178 if (SQL_HASZERONUMS($result)) {
179 // Did not find a record so we can add it... :)
180 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_url_blacklist` (`url`,`pool_id`) VALUES ('%s',%s)",
181 array($url, $id), __FILE__, __LINE__);
185 SQL_FREERESULT($result);
189 loadTemplate('admin_settings_saved', false, '{--ADMIN_URLS_BLOCKED--}');
190 } elseif ((!isFormSent('lock')) && (!isFormSent('accept')) && (!isFormSent('reject'))) {
191 // Mail orders are in pool so we can display them
193 while ($content = SQL_FETCHARRAY($result_main)) {
194 // Prepare data for the template
195 $content['timestamp'] = generateDateTime($content['timestamp'], 2);
197 // Load row template and switch colors
198 $OUT .= loadTemplate('admin_unlock_emails_row', true, $content);
202 SQL_FREERESULT($result_main);
205 $content['rows'] = $OUT;
207 // Load main template
208 loadTemplate('admin_unlock_emails', false, $content);
209 } elseif ((isFormSent('lock')) && (!isUrlBlacklistEnabled())) {
210 // URL blacklist not activated
211 loadTemplate('admin_settings_saved', false, '{--ADMIN_URL_BLACKLIST_DISABLED--}');
214 loadTemplate('admin_settings_saved', false, '{--ADMIN_WRONG_CALL--}');
217 // No mail orders fond
218 loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_MAILS_IN_POOL--}');