The yearly copyright-update commit. 2009, 2010 are now copyrighted on the developer...
[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  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 } // END - if
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
48 // Check for mails
49 $result_main = SQL_QUERY("SELECT
50         `id`,`sender`,`subject`,`payment_id` AS `payment`,`timestamp`,`url`,`target_send`,`cat_id` AS category
51 FROM
52         `{?_MYSQL_PREFIX?}_pool`
53 WHERE
54         `data_type`='ADMIN'
55 ORDER BY
56         `timestamp` ASC", __FILE__, __LINE__);
57
58 if ((SQL_NUMROWS($result_main) > 0) || (isPostRequestParameterSet('lock'))) {
59         if (isPostRequestParameterSet('accept')) {
60                 if (countPostSelection() > 0) {
61                         // Accept mail orders
62                         foreach (postRequestParameter('sel') as $id => $value) {
63                                 // Secure id number
64                                 $id = bigintval($id);
65
66                                 // Order placed in queue...
67                                 $result = SQL_QUERY_ESC("SELECT
68         po.url, po.subject, po.sender, pay.payment, po.payment_id
69 FROM
70         `{?_MYSQL_PREFIX?}_pool` AS po
71 INNER JOIN
72         `{?_MYSQL_PREFIX?}_payments` AS pay
73 ON
74         po.payment_id=pay.id
75 WHERE
76         po.id=%s
77 LIMIT 1",
78                                         array($id), __FILE__, __LINE__);
79
80                                 // Update wents fine?
81                                 if (SQL_NUMROWS($result) == 1) {
82                                         // Load data
83                                         $content = SQL_FETCHARRAY($result);
84
85                                         // Free result
86                                         SQL_FREERESULT($result);
87
88                                         // Is the surfbar installed?
89                                         // @TODO Rewrite these if-blocks to a filter
90                                         if ((isExtensionActive('surfbar')) && (getConfig('surfbar_migrate_order') == 'Y')) {
91                                                 // Then "migrate" the URL to the surfbar
92                                                 SURFBAR_ADMIN_MIGRATE_URL($content['url'], $content['sender']);
93                                         } // END - if
94
95                                         // Check for bonus extension version >= 0.4.4 for the order bonus
96                                         if ((getExtensionVersion('bonus') >= '0.4.4') && (getConfig('bonus_active') == 'Y')) {
97                                                 // Add points directly
98                                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `bonus_order`=`bonus_order`+".getConfig('bonus_order')." WHERE `userid`=%s LIMIT 1",
99                                                         array(bigintval($content['sender'])), __FILE__, __LINE__);
100
101                                                 // Subtract bonus points from system
102                                                 handleBonusPoints(getConfig('bonus_order'));
103                                         } // END - if
104
105                                         // Load email template
106                                         $message_user = loadEmailTemplate('order-accept', $content, $content['sender']);
107
108                                         // Send email
109                                         sendEmail($content['sender'], getMessage('MEMBER_ORDER_ACCEPTED'), $message_user);
110
111                                         // Unlock selected email
112                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `data_type`='NEW' WHERE `id`=%s AND `data_type`='ADMIN' LIMIT 1",
113                                                 array($id), __FILE__, __LINE__);
114                                 } // END - if
115                         } // END - foreach
116
117                         // Set message
118                         $message = getMessage('ADMIN_MAILS_ACTIVATED');
119                 } else {
120                         // Nothing checked!
121                         $message = getMessage('ADMIN_MAILS_NOTHING_CHECKED');
122                 }
123
124                 // Mails unlocked for mail delivery
125                 loadTemplate('admin_settings_saved', false, $message);
126         } elseif (isPostRequestParameterSet(('reject'))) {
127                 if (countPostSelection() > 0) {
128                         // Reject mail orders
129                         $OUT = ''; $SW = 2;
130                         foreach (postRequestParameter('sel') as $id => $value) {
131                                 // Secure id number
132                                 $id = bigintval($id);
133
134                                 // Load URL and subject from pool
135                                 $result = SQL_QUERY_ESC("SELECT `url`, `subject`, `sender` FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
136                                         array($id), __FILE__, __LINE__);
137
138                                 // Load data
139                                 $content = SQL_FETCHARRAY($result);
140
141                                 // Free result
142                                 SQL_FREERESULT($result);
143
144                                 // Load email template and send it away
145                                 $message_user = loadEmailTemplate('order-reject', $content, $content['sender']);
146                                 sendEmail($content['sender'], getMessage('MEMBER_ORDER_REJECTED'), $message_user);
147
148                                 // If you do not enter an URL to redirect to, your URL will be set!
149                                 if ((!isPostRequestParameterSet('redirect')) || (postRequestParameter('redirect') == 'http://')) setPostRequestParameter('redirect', getConfig('URL'));
150
151                                 // Redirect URL
152                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET url='%s', `data_type`='NEW' WHERE `id`=%s LIMIT 1",
153                                         array(postRequestParameter('redirect'), $id),__FILE__, __LINE__);
154
155                                 // Prepare data for the row template
156                                 $content = array(
157                                         'sw'  => $SW,
158                                         'id'  => $id,
159                                         'url' => postRequestParameter('url', $id),
160                                 );
161
162                                 // Load row template and switch colors
163                                 $OUT .= loadTemplate('admin_unlock_emails_redir_row', true, $content);
164                                 $SW = 3 - $SW;
165                         }
166
167                         // Load main template
168                         loadTemplate('admin_unlock_emails_redir', false, $OUT);
169                 } else {
170                         // Nothing selected
171                         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_MAILS_NOTHING_CHECKED'));
172                 }
173         } elseif ((isPostRequestParameterSet('lock')) && (countPostSelection() > 0) && (getConfig('url_blacklist') == 'Y')) {
174                 // Lock URLs
175                 foreach (postRequestParameter('sel') as $id => $url) {
176                         // Secure id number
177                         $id = bigintval($id);
178
179                         // Lookup in blacklist
180                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_url_blacklist` WHERE `url`='%s' LIMIT 1",
181                                 array($url), __FILE__, __LINE__);
182                         if (SQL_NUMROWS($result) == '0') {
183                                 // Did not find a record so we can add it... :)
184                                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_url_blacklist` (`url`,`pool_id`) VALUES ('%s',%s)",
185                                         array($url, $id), __FILE__, __LINE__);
186                         } // END - if
187
188                         // Free memory
189                         SQL_FREERESULT($result);
190                 } // END - foreach
191
192                 // Output message
193                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_URLS_BLOCKED'));
194         } elseif ((!isPostRequestParameterSet('lock')) && (!isPostRequestParameterSet('accept')) && (!isPostRequestParameterSet('reject'))) {
195                 // Mail orders are in pool so we can display them
196                 $OUT = ''; $SW = 2;
197                 while ($content = SQL_FETCHARRAY($result_main)) {
198                         // Prepare data for the template
199                         $content = array(
200                                 'sw'          => $SW,
201                                 'id'          => $content['id'],
202                                 'sender'      => $content['sender'],
203                                 'u_link'      => generateUserProfileLink($content['sender']),
204                                 'subject'     => $content['subject'],
205                                 'tester'      => generateFrametesterUrl($content['url']),
206                                 'url'         => $content['url'],
207                                 'cat_title'   => str_replace("\"", '&quot;', getCategory($content['category'])),
208                                 'cat_link'    => $content['category'],
209                                 'pay_title'   => str_replace("\"", '&quot;', getPaymentTitlePrice($content['payment'], true)),
210                                 'pay_link'    => $content['payment'],
211                                 'timestamp'   => generateDateTime($content['timestamp'], 2),
212                                 'target_send' => $content['target_send'],
213                         );
214
215                         // Load row template and switch colors
216                         $OUT .= loadTemplate('admin_unlock_emails_row', true, $content);
217                         $SW = 3 - $SW;
218                 } // END - while
219
220                 // Free memory
221                 SQL_FREERESULT($result_main);
222
223                 // Remember in array
224                 $content['rows'] = $OUT;
225
226                 // Load main template
227                 loadTemplate('admin_unlock_emails', false, $content);
228         } elseif ((isPostRequestParameterSet('lock')) && (getConfig('url_blacklist') != 'Y')) {
229                 // URL blacklist not activated
230                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_URL_BLACKLIST_DISABLED'));
231         } else {
232                 // Wrong call!
233                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_WRONG_CALL'));
234         }
235 } else {
236         // No mail orders fond
237         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MAILS_IN_POOL'));
238 }
239
240 // [EOF]
241 ?>