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 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
47 // Define some variables
51 $result_main = SQL_QUERY("SELECT
52 `id`,`sender`,`subject`,`payment_id` AS `payment`,`timestamp`,`url`,`target_send`,`cat_id` AS category
54 `{?_MYSQL_PREFIX?}_pool`
58 `timestamp` ASC", __FILE__, __LINE__);
60 if ((SQL_NUMROWS($result_main) > 0) || (isPostRequestElementSet('lock'))) {
61 if (isPostRequestElementSet('accept')) {
62 if (countPostSelection() > 0) {
64 foreach (postRequestElement('sel') as $id => $value) {
68 // Order placed in queue...
69 $result = SQL_QUERY_ESC("SELECT
70 po.url, po.subject, po.sender, pay.payment, po.payment_id
72 `{?_MYSQL_PREFIX?}_pool` AS po
74 `{?_MYSQL_PREFIX?}_payments` AS pay
80 array($id), __FILE__, __LINE__);
83 if (SQL_NUMROWS($result) == 1) {
85 $content = SQL_FETCHARRAY($result);
88 SQL_FREERESULT($result);
90 // Is the surfbar installed?
91 // @TODO Rewrite these if-blocks to a filter
92 if ((isExtensionActive('surfbar')) && (getConfig('surfbar_migrate_order') == 'Y')) {
93 // Then "migrate" the URL to the surfbar
94 SURFBAR_ADMIN_MIGRATE_URL($content['url'], $content['sender']);
97 // Check for bonus extension version >= 0.4.4 for the order bonus
98 if ((getExtensionVersion('bonus') >= '0.4.4') && (getConfig('bonus_active') == 'Y')) {
99 // Add points directly
100 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `bonus_order`=`bonus_order`+".getConfig('bonus_order')." WHERE `userid`=%s LIMIT 1",
101 array(bigintval($content['sender'])), __FILE__, __LINE__);
103 // Subtract bonus points from system
104 handleBonusPoints(getConfig('bonus_order'));
107 // Load email template
108 $message_user = loadEmailTemplate('order-accept', $content, $content['sender']);
111 sendEmail($content['sender'], getMessage('MEMBER_ORDER_ACCEPTED'), $message_user);
113 // Unlock selected email
114 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `data_type`='NEW' WHERE `id`=%s AND `data_type`='ADMIN' LIMIT 1",
115 array($id), __FILE__, __LINE__);
120 $message = getMessage('ADMIN_MAILS_ACTIVATED');
123 $message = getMessage('ADMIN_MAILS_NOTHING_CHECKED');
126 // Mails unlocked for mail delivery
127 loadTemplate('admin_settings_saved', false, $message);
128 } elseif (isPostRequestElementSet(('reject'))) {
129 if (countPostSelection() > 0) {
130 // Reject mail orders
132 foreach (postRequestElement('sel') as $id => $value) {
134 $id = bigintval($id);
136 // Load URL and subject from pool
137 $result = SQL_QUERY_ESC("SELECT `url`, `subject`, `sender` FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
138 array($id), __FILE__, __LINE__);
141 $content = SQL_FETCHARRAY($result);
144 SQL_FREERESULT($result);
146 // Load email template and send it away
147 $message_user = loadEmailTemplate('order-reject', $content, $content['sender']);
148 sendEmail($content['sender'], getMessage('MEMBER_ORDER_REJECTED'), $message_user);
150 // If you do not enter an URL to redirect to, your URL will be set!
151 if ((!isPostRequestElementSet(('redirect'))) || (postRequestElement('redirect') == 'http://')) setRequestPostElement('redirect', getConfig('URL'));
154 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET url='%s', `data_type`='NEW' WHERE `id`=%s LIMIT 1",
155 array(postRequestElement('redirect'), $id),__FILE__, __LINE__);
157 // Prepare data for the row template
161 'url' => postRequestElement('url', $id),
164 // Load row template and switch colors
165 $OUT .= loadTemplate('admin_unlock_emails_redir_row', true, $content);
169 // Load main template
170 loadTemplate('admin_unlock_emails_redir', false, $OUT);
173 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_MAILS_NOTHING_CHECKED'));
175 } elseif ((isPostRequestElementSet('lock')) && (countPostSelection() > 0) && (getConfig('url_blacklist') == 'Y')) {
177 foreach (postRequestElement('sel') as $id => $url) {
179 $id = bigintval($id);
181 // Lookup in blacklist
182 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_url_blacklist` WHERE `url`='%s' LIMIT 1",
183 array($url), __FILE__, __LINE__);
184 if (SQL_NUMROWS($result) == '0') {
185 // Did not find a record so we can add it... :)
186 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_url_blacklist` (`url`,`pool_id`) VALUES ('%s',%s)",
187 array($url, $id), __FILE__, __LINE__);
191 SQL_FREERESULT($result);
195 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_URLS_BLOCKED'));
196 } elseif ((!isPostRequestElementSet('lock')) && (!isPostRequestElementSet('accept')) && (!isPostRequestElementSet(('reject'))) && (getConfig('url_blacklist') == 'Y')) {
197 // Mail orders are in pool so we can display them
199 while ($content = SQL_FETCHARRAY($result_main)) {
200 // Prepare data for the template
203 'id' => $content['id'],
204 'sender' => $content['sender'],
205 'u_link' => generateUserProfileLink($content['sender']),
206 'subject' => $content['subject'],
207 'tester' => generateFrametesterUrl($content['url']),
208 'url' => $content['url'],
209 'cat_title' => str_replace("\"", '"', getCategory($content['category'])),
210 'cat_link' => $content['category'],
211 'pay_title' => str_replace("\"", '"', getPaymentTitlePrice($content['payment'], true)),
212 'pay_link' => $content['payment'],
213 'timestamp' => generateDateTime($content['timestamp'], 2),
214 'target_send' => $content['target_send'],
217 // Load row template and switch colors
218 $OUT .= loadTemplate('admin_unlock_emails_row', true, $content);
223 SQL_FREERESULT($result_main);
226 $content['rows'] = $OUT;
228 // Load main template
229 loadTemplate('admin_unlock_emails', false, $content);
230 } elseif ((isPostRequestElementSet('lock')) && (getConfig('url_blacklist') != 'Y')) {
231 // URL blacklist not activated
232 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_URL_BLACKLIST_DISABLED'));
235 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_WRONG_CALL'));
238 // No mail orders fond
239 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MAILS_IN_POOL'));