2 /************************************************************************
3 * MXChange v0.2.1 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 // Count checked checkboxes
63 if (isPostRequestElementSet('sel')) {
64 // Are there checked boxes?
65 if (count(postRequestElement('sel')) > 0) {
66 // Count now... We use an own function for now
67 $SEL = countPostSelection();
71 if (isPostRequestElementSet('accept')) {
74 foreach (postRequestElement('sel') as $id => $value) {
78 // Order placed in queue...
79 $result = SQL_QUERY_ESC("SELECT
80 po.url, po.subject, po.sender, pay.payment, po.payment_id
82 `{?_MYSQL_PREFIX?}_pool` AS po
84 `{?_MYSQL_PREFIX?}_payments` AS pay
90 array($id), __FILE__, __LINE__);
93 if (SQL_NUMROWS($result) == 1) {
95 $DATA = SQL_FETCHARRAY($result);
98 SQL_FREERESULT($result);
100 // Is the surfbar installed?
101 // @TODO Rewrite these if-blocks to a filter
102 if ((isExtensionActive('surfbar')) && (getConfig('surfbar_migrate_order') == 'Y')) {
103 // Then "migrate" the URL to the surfbar
104 SURFBAR_ADMIN_MIGRATE_URL($DATA['url'], $DATA['sender']);
107 // Check for bonus extension version >= 0.4.4 for the order bonus
108 if ((getExtensionVersion('bonus') >= '0.4.4') && (getConfig('bonus_active') == 'Y')) {
109 // Add points directly
110 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `bonus_order`=`bonus_order`+".getConfig('bonus_order')." WHERE `userid`=%s LIMIT 1",
111 array(bigintval($DATA['sender'])), __FILE__, __LINE__);
113 // Subtract bonus points from system
114 handleBonusPoints(getConfig('bonus_order'));
117 // Load email template
118 $message_user = loadEmailTemplate('order-accept', array(), $DATA['sender']);
121 sendEmail($DATA['sender'], getMessage('MEMBER_ORDER_ACCEPTED'), $message_user);
123 // Unlock selected email
124 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `data_type`='NEW' WHERE `id`=%s AND `data_type`='ADMIN' LIMIT 1",
125 array($id), __FILE__, __LINE__);
130 $message = getMessage('ADMIN_MAILS_ACTIVATED');
133 $message = getMessage('ADMIN_MAILS_NOTHING_CHECKED');
136 // Mails unlocked for mail delivery
137 loadTemplate('admin_settings_saved', false, $message);
138 } elseif (isPostRequestElementSet(('reject'))) {
140 // Reject mail orders
142 foreach (postRequestElement('sel') as $id => $value) {
144 $id = bigintval($id);
146 // Load URL and subject from pool
147 $result = SQL_QUERY_ESC("SELECT `url`, `subject`, `sender` FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
148 array($id), __FILE__, __LINE__);
151 $DATA = SQL_FETCHARRAY($result);
154 SQL_FREERESULT($result);
156 // Load email template and send it away
157 $message_user = loadEmailTemplate('order-reject', array(), $DATA['sender']);
158 sendEmail($DATA['sender'], getMessage('MEMBER_ORDER_REJECTED'), $message_user);
160 // If you do not enter an URL to redirect to, your URL will be set!
161 if ((!isPostRequestElementSet(('redirect'))) || (postRequestElement('redirect') == 'http://')) setRequestPostElement('redirect', getConfig('URL'));
164 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET url='%s', `data_type`='NEW' WHERE `id`=%s LIMIT 1",
165 array(postRequestElement('redirect'), $id),__FILE__, __LINE__);
167 // Prepare data for the row template
171 'url' => postRequestElement('url', $id),
174 // Load row template and switch colors
175 $OUT .= loadTemplate('admin_unlock_emails_redir_row', true, $content);
179 // Load main template
180 loadTemplate('admin_unlock_emails_redir', false, $OUT);
183 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_MAILS_NOTHING_CHECKED'));
185 } elseif ((isPostRequestElementSet('lock')) && ($SEL > 0) && (getConfig('url_blacklist') == 'Y')) {
187 foreach (postRequestElement('sel') as $id => $url) {
189 $id = bigintval($id);
191 // Lookup in blacklist
192 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_url_blacklist` WHERE `url`='%s' LIMIT 1",
193 array($url), __FILE__, __LINE__);
194 if (SQL_NUMROWS($result) == 0) {
195 // Did not find a record so we can add it... :)
196 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_url_blacklist` (`url`,`pool_id`) VALUES ('%s',%s)",
197 array($url, $id), __FILE__, __LINE__);
201 SQL_FREERESULT($result);
205 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_URLS_BLOCKED'));
206 } elseif ((!isPostRequestElementSet('lock')) && (!isPostRequestElementSet('accept')) && (!isPostRequestElementSet(('reject'))) && (getConfig('url_blacklist') == 'Y')) {
207 // Mail orders are in pool so we can display them
209 while ($content = SQL_FETCHARRAY($result_main)) {
210 // Prepare data for the template
211 // @TODO Rewrite in template: subj->subject,ordered->timestamp,tsend->target_send
214 'id' => $content['id'],
215 'sender' => $content['sender'],
216 'u_link' => generateUserProfileLink($content['sender']),
217 'subj' => $content['subject'],
218 'tester' => generateFrametesterUrl($content['url']),
219 'url' => $content['url'],
220 'cat_title' => str_replace("\"", '"', getCategory($content['category'])),
221 'cat_link' => $content['category'],
222 'pay_title' => str_replace("\"", '"', getPaymentTitlePrice($content['payment'], true)),
223 'pay_link' => $content['payment'],
224 'ordered' => generateDateTime($content['timestamp'], '2'),
225 'tsend' => $content['target_send'],
228 // Load row template and switch colors
229 $OUT .= loadTemplate('admin_unlock_emails_row', true, $content);
234 SQL_FREERESULT($result_main);
237 $content['rows'] = $OUT;
239 // Load main template
240 loadTemplate('admin_unlock_emails', false, $content);
241 } elseif ((isPostRequestElementSet('lock')) && (getConfig('url_blacklist') != 'Y')) {
242 // URL blacklist not activated
243 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_URL_BLACKLIST_DISABLED'));
246 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_WRONG_CALL'));
249 // No mail orders fond
250 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MAILS_IN_POOL'));