Fix for URL detection
[mailer.git] / inc / modules / admin / what-unlock_emails.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 09/28/2003 *
4  * ===================                          Last change: 07/13/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-unlock_emails.php                           *
8  * -------------------------------------------------------------------- *
9  * Short description : Unlock ordered emails                            *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Werbebuchungen freigeben                         *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
41         die();
42 } // END - if
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
47 // Define some variables
48 global $DATA;
49
50 // Check for mails
51 $result_main = SQL_QUERY("SELECT
52         `id`,`sender`,`subject`,`payment_id` AS `payment`,`timestamp`,`url`,`target_send`,`cat_id` AS category
53 FROM
54         `{?_MYSQL_PREFIX?}_pool`
55 WHERE
56         `data_type`='ADMIN'
57 ORDER BY
58         `timestamp` ASC", __FILE__, __LINE__);
59
60 if ((SQL_NUMROWS($result_main) > 0) || (isPostRequestElementSet('lock'))) {
61         if (isPostRequestElementSet('accept')) {
62                 if (countPostSelection() > 0) {
63                         // Accept mail orders
64                         foreach (postRequestElement('sel') as $id => $value) {
65                                 // Secure id number
66                                 $id = bigintval($id);
67
68                                 // Order placed in queue...
69                                 $result = SQL_QUERY_ESC("SELECT
70         po.url, po.subject, po.sender, pay.payment, po.payment_id
71 FROM
72         `{?_MYSQL_PREFIX?}_pool` AS po
73 INNER JOIN
74         `{?_MYSQL_PREFIX?}_payments` AS pay
75 ON
76         po.payment_id=pay.id
77 WHERE
78         po.id=%s
79 LIMIT 1",
80                                         array($id), __FILE__, __LINE__);
81
82                                 // Update wents fine?
83                                 if (SQL_NUMROWS($result) == 1) {
84                                         // Load data
85                                         $content = SQL_FETCHARRAY($result);
86
87                                         // Free result
88                                         SQL_FREERESULT($result);
89
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']);
95                                         } // END - if
96
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__);
102
103                                                 // Subtract bonus points from system
104                                                 handleBonusPoints(getConfig('bonus_order'));
105                                         } // END - if
106
107                                         // Load email template
108                                         $message_user = loadEmailTemplate('order-accept', $content, $content['sender']);
109
110                                         // Send email
111                                         sendEmail($content['sender'], getMessage('MEMBER_ORDER_ACCEPTED'), $message_user);
112
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__);
116                                 } // END - if
117                         } // END - foreach
118
119                         // Set message
120                         $message = getMessage('ADMIN_MAILS_ACTIVATED');
121                 } else {
122                         // Nothing checked!
123                         $message = getMessage('ADMIN_MAILS_NOTHING_CHECKED');
124                 }
125
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
131                         $OUT = ''; $SW = 2;
132                         foreach (postRequestElement('sel') as $id => $value) {
133                                 // Secure id number
134                                 $id = bigintval($id);
135
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__);
139
140                                 // Load data
141                                 $content = SQL_FETCHARRAY($result);
142
143                                 // Free result
144                                 SQL_FREERESULT($result);
145
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);
149
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'));
152
153                                 // Redirect 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__);
156
157                                 // Prepare data for the row template
158                                 $content = array(
159                                         'sw'  => $SW,
160                                         'id'  => $id,
161                                         'url' => postRequestElement('url', $id),
162                                 );
163
164                                 // Load row template and switch colors
165                                 $OUT .= loadTemplate('admin_unlock_emails_redir_row', true, $content);
166                                 $SW = 3 - $SW;
167                         }
168
169                         // Load main template
170                         loadTemplate('admin_unlock_emails_redir', false, $OUT);
171                 } else {
172                         // Nothing selected
173                         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_MAILS_NOTHING_CHECKED'));
174                 }
175         } elseif ((isPostRequestElementSet('lock')) && (countPostSelection() > 0) && (getConfig('url_blacklist') == 'Y')) {
176                 // Lock URLs
177                 foreach (postRequestElement('sel') as $id => $url) {
178                         // Secure id number
179                         $id = bigintval($id);
180
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__);
188                         } // END - if
189
190                         // Free memory
191                         SQL_FREERESULT($result);
192                 } // END - foreach
193
194                 // Output message
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
198                 $OUT = ''; $SW = 2;
199                 while ($content = SQL_FETCHARRAY($result_main)) {
200                         // Prepare data for the template
201                         $content = array(
202                                 'sw'          => $SW,
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("\"", '&quot;', getCategory($content['category'])),
210                                 'cat_link'    => $content['category'],
211                                 'pay_title'   => str_replace("\"", '&quot;', getPaymentTitlePrice($content['payment'], true)),
212                                 'pay_link'    => $content['payment'],
213                                 'timestamp'   => generateDateTime($content['timestamp'], 2),
214                                 'target_send' => $content['target_send'],
215                         );
216
217                         // Load row template and switch colors
218                         $OUT .= loadTemplate('admin_unlock_emails_row', true, $content);
219                         $SW = 3 - $SW;
220                 } // END - while
221
222                 // Free memory
223                 SQL_FREERESULT($result_main);
224
225                 // Remember in array
226                 $content['rows'] = $OUT;
227
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'));
233         } else {
234                 // Wrong call!
235                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_WRONG_CALL'));
236         }
237 } else {
238         // No mail orders fond
239         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MAILS_IN_POOL'));
240 }
241
242 // [EOF]
243 ?>