8bdde01352e79689ff03038137df9dd2bffd761a
[mailer.git] / inc / modules / admin / what-unlock_emails.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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         // Count checked checkboxes
62         $SEL = 0;
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();
68                 } // END - if
69         } // END - if
70
71         if (isPostRequestElementSet('accept')) {
72                 if ($SEL > 0) {
73                         // Accept mail orders
74                         foreach (postRequestElement('sel') as $id => $value) {
75                                 // Secure ID number
76                                 $id = bigintval($id);
77
78                                 // Order placed in queue...
79                                 $result = SQL_QUERY_ESC("SELECT
80         po.url, po.subject, po.sender, pay.payment, po.payment_id
81 FROM
82         `{?_MYSQL_PREFIX?}_pool` AS po
83 INNER JOIN
84         `{?_MYSQL_PREFIX?}_payments` AS pay
85 ON
86         po.payment_id=pay.id
87 WHERE
88         po.id=%s
89 LIMIT 1",
90                                         array($id), __FILE__, __LINE__);
91
92                                 // Update wents fine?
93                                 if (SQL_NUMROWS($result) == 1) {
94                                         // Load data
95                                         $DATA = SQL_FETCHARRAY($result);
96
97                                         // Free result
98                                         SQL_FREERESULT($result);
99
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']);
105                                         } // END - if
106
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__);
112
113                                                 // Subtract bonus points from system
114                                                 handleBonusPoints(getConfig('bonus_order'));
115                                         } // END - if
116
117                                         // Load email template
118                                         $message_user = loadEmailTemplate('order-accept', array(), $DATA['sender']);
119
120                                         // Send email
121                                         sendEmail($DATA['sender'], getMessage('MEMBER_ORDER_ACCEPTED'), $message_user);
122
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__);
126                                 } // END - if
127                         } // END - foreach
128
129                         // Set message
130                         $message = getMessage('ADMIN_MAILS_ACTIVATED');
131                 } else {
132                         // Nothing checked!
133                         $message = getMessage('ADMIN_MAILS_NOTHING_CHECKED');
134                 }
135
136                 // Mails unlocked for mail delivery
137                 loadTemplate('admin_settings_saved', false, $message);
138         } elseif (isPostRequestElementSet(('reject'))) {
139                 if ($SEL > 0) {
140                         // Reject mail orders
141                         $OUT = ''; $SW = 2;
142                         foreach (postRequestElement('sel') as $id => $value) {
143                                 // Secure ID number
144                                 $id = bigintval($id);
145
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__);
149
150                                 // Load data
151                                 $DATA = SQL_FETCHARRAY($result);
152
153                                 // Free result
154                                 SQL_FREERESULT($result);
155
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);
159
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'));
162
163                                 // Redirect 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__);
166
167                                 // Prepare data for the row template
168                                 $content = array(
169                                         'sw'  => $SW,
170                                         'id'  => $id,
171                                         'url' => postRequestElement('url', $id),
172                                 );
173
174                                 // Load row template and switch colors
175                                 $OUT .= loadTemplate('admin_unlock_emails_redir_row', true, $content);
176                                 $SW = 3 - $SW;
177                         }
178
179                         // Load main template
180                         loadTemplate('admin_unlock_emails_redir', false, $OUT);
181                 } else {
182                         // Nothing selected
183                         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_MAILS_NOTHING_CHECKED'));
184                 }
185         } elseif ((isPostRequestElementSet('lock')) && ($SEL > 0) && (getConfig('url_blacklist') == 'Y')) {
186                 // Lock URLs
187                 foreach (postRequestElement('sel') as $id => $url) {
188                         // Secure id number
189                         $id = bigintval($id);
190
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__);
198                         } // END - if
199
200                         // Free memory
201                         SQL_FREERESULT($result);
202                 } // END - foreach
203
204                 // Output message
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
208                 $OUT = ''; $SW = 2;
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
212                         $content = array(
213                                 'sw'        => $SW,
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("\"", '&quot;', getCategory($content['category'])),
221                                 'cat_link'  => $content['category'],
222                                 'pay_title' => str_replace("\"", '&quot;', getPaymentTitlePrice($content['payment'], true)),
223                                 'pay_link'  => $content['payment'],
224                                 'ordered'   => generateDateTime($content['timestamp'], '2'),
225                                 'tsend'     => $content['target_send'],
226                         );
227
228                         // Load row template and switch colors
229                         $OUT .= loadTemplate('admin_unlock_emails_row', true, $content);
230                         $SW = 3 - $SW;
231                 } // END - while
232
233                 // Free memory
234                 SQL_FREERESULT($result_main);
235
236                 // Remember in array
237                 $content['rows'] = $OUT;
238
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'));
244         } else {
245                 // Wrong call!
246                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_WRONG_CALL'));
247         }
248 } else {
249         // No mail orders fond
250         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MAILS_IN_POOL'));
251 }
252
253 // [EOF]
254 ?>