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 - 2008 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')) || (!IS_ADMIN())) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
48 // Define some variables
52 $result_main = SQL_QUERY("SELECT `id`,`sender`,`subject`,`payment_id` AS `payment`,`timestamp`,`url`,`target_send`,`cat_id` AS `category`
53 FROM `{!_MYSQL_PREFIX!}_pool`
54 WHERE `data_type`='ADMIN'
55 ORDER BY `timestamp` ASC", __FILE__, __LINE__);
57 if ((SQL_NUMROWS($result_main) > 0) || (REQUEST_ISSET_POST('lock'))) {
58 // Count checked checkboxes
60 if (REQUEST_ISSET_POST('sel')) {
61 // Are there checked boxes?
62 if (count(REQUEST_POST('sel')) > 0) {
63 // Count now... We use an own function for now
64 $SEL = countPostSelection();
68 if (REQUEST_ISSET_POST('accept')) {
71 foreach (REQUEST_POST('sel') as $id => $value) {
75 // Order placed in queue...
76 $result = SQL_QUERY_ESC("SELECT
77 po.url, po.subject, po.sender, pay.payment, po.payment_id
79 `{!_MYSQL_PREFIX!}_pool` AS po
81 `{!_MYSQL_PREFIX!}_payments` AS pay
87 array($id), __FILE__, __LINE__);
90 if (SQL_NUMROWS($result) == 1) {
92 $DATA = SQL_FETCHARRAY($result);
95 SQL_FREERESULT($result);
97 // Is the surfbar installed?
98 if ((EXT_IS_ACTIVE('surfbar')) && (getConfig('surfbar_migrate_order') == 'Y')) {
99 // Then "migrate" the URL to the surfbar
100 SURFBAR_ADMIN_MIGRATE_URL($DATA['url'], $DATA['sender']);
103 // Check for bonus extension version >= 0.4.4 for the order bonus
104 if ((GET_EXT_VERSION('bonus') >= '0.4.4') && (getConfig('bonus_active') == 'Y')) {
105 // Add points directly
106 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET `bonus_order`=`bonus_order`+".getConfig('bonus_order')." WHERE `userid`=%s LIMIT 1",
107 array(bigintval($DATA['sender'])), __FILE__, __LINE__);
109 // Subtract bonus points from system
110 BONUS_POINTS_HANDLER(getConfig('bonus_order'));
113 // Load email template
114 $message_user = LOAD_EMAIL_TEMPLATE('order-accept', array(), $DATA['sender']);
117 sendEmail($DATA['sender'], MEMBER_ORDER_ACCEPTED, $message_user);
119 // Unlock selected email
120 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_pool` SET `data_type`='NEW' WHERE `id`=%s AND `data_type`='ADMIN' LIMIT 1",
121 array($id), __FILE__, __LINE__);
126 $message = getMessage('ADMIN_MAILS_ACTIVATED');
129 $message = getMessage('ADMIN_MAILS_NOTHING_CHECKED');
132 // Mails unlocked for mail delivery
133 LOAD_TEMPLATE('admin_settings_saved', false, $message);
134 } elseif (REQUEST_ISSET_POST(('reject'))) {
136 // Reject mail orders
138 foreach (REQUEST_POST('sel') as $id => $value) {
140 $id = bigintval($id);
142 // Load URL and subject from pool
143 $result = SQL_QUERY_ESC("SELECT `url`, `subject`, `sender` FROM `{!_MYSQL_PREFIX!}_pool` WHERE `id`=%s LIMIT 1",
144 array($id), __FILE__, __LINE__);
147 $DATA = SQL_FETCHARRAY($result);
150 SQL_FREERESULT($result);
152 // Load email template and send it away
153 $message_user = LOAD_EMAIL_TEMPLATE('order-reject', array(), $DATA['sender']);
154 sendEmail($DATA['sender'], getMessage('MEMBER_ORDER_REJECTED'), $message_user);
156 // If you do not enter an URL to redirect to, your URL will be set!
157 if ((!REQUEST_ISSET_POST(('redirect'))) || (REQUEST_POST('redirect') == 'http://')) REQUEST_SET_POST('redirect', constant('URL'));
160 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_pool` SET url='%s', `data_type`='NEW' WHERE `id`=%s LIMIT 1",
161 array(REQUEST_POST('redirect'), $id),__FILE__, __LINE__);
163 // Prepare data for the row template
167 'url' => REQUEST_POST('url', $id),
170 // Load row template and switch colors
171 $OUT .= LOAD_TEMPLATE('admin_unlock_emails_redir_row', true, $content);
174 define('__URL_ROWS', $OUT);
176 // Load main template
177 LOAD_TEMPLATE('admin_unlock_emails_redir');
180 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_MAILS_NOTHING_CHECKED'));
182 } elseif ((REQUEST_ISSET_POST('lock')) && ($SEL > 0) && (getConfig('url_blacklist') == 'Y')) {
184 foreach (REQUEST_POST('sel') as $id => $url) {
186 $id = bigintval($id);
188 // Lookup in blacklist
189 $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_url_blacklist` WHERE `url`='%s' LIMIT 1",
190 array($url), __FILE__, __LINE__);
191 if (SQL_NUMROWS($result) == 0) {
192 // Did not find a record so we can add it... :)
193 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_url_blacklist` (`url`,`pool_id`) VALUES ('%s',%s)",
194 array($url, $id), __FILE__, __LINE__);
198 SQL_FREERESULT($result);
202 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_URLS_BLOCKED'));
203 } elseif ((!REQUEST_ISSET_POST('lock')) && (!REQUEST_ISSET_POST('accept')) && (!REQUEST_ISSET_POST(('reject'))) && (getConfig('url_blacklist') == 'Y')) {
204 // Mail orders are in pool so we can display them
206 while ($content = SQL_FETCHARRAY($result_main)) {
207 // Prepare data for the template
210 'id' => $content['id'],
211 'sender' => $content['sender'],
212 'u_link' => generateUserProfileLink($content['sender']),
213 'subj' => COMPILE_CODE($content['subject']),
214 'tester' => FRAMETESTER($content['url']),
215 'url' => $content['url'],
216 'cat_title' => str_replace("\"", """, getCategory($content['category'])),
217 'cat_link' => $content['category'],
218 'pay_title' => str_replace("\"", """, getPaymentTitlePrice($content['payment'], true)),
219 'pay_link' => $content['payment'],
220 'ordered' => generateDateTime($content['timestamp'], '2'),
221 'tsend' => $content['target_send'],
224 // Load row template and switch colors
225 $OUT .= LOAD_TEMPLATE('admin_unlock_emails_row', true, $content);
230 SQL_FREERESULT($result_main);
231 define('__UNLOCK_ROWS', $OUT);
233 // Prepare rejection URL
235 if (GET_EXT_VERSION('other') >= '0.1.6') $REJECT = getConfig('reject_url');
236 define('__REJECT_URL', $REJECT);
238 // Load main template
239 LOAD_TEMPLATE('admin_unlock_emails');
240 } elseif ((REQUEST_ISSET_POST('lock')) && (getConfig('url_blacklist') != 'Y')) {
241 // URL blacklist not activated
242 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_URL_BLACKLIST_DISABLED'));
245 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_WRONG_CALL'));
248 // No mail orders fond
249 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_NO_MAILS_IN_POOL'));