Huge patchset (I don't recall all details):
[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 // Check for mails
48 $result_main = SQL_QUERY("SELECT
49         `id`,`sender`,`subject`,`payment_id` AS `payment`,`timestamp`,`url`,`target_send`,`cat_id` AS category
50 FROM
51         `{?_MYSQL_PREFIX?}_pool`
52 WHERE
53         `data_type`='ADMIN'
54 ORDER BY
55         `timestamp` ASC", __FILE__, __LINE__);
56
57 if ((SQL_NUMROWS($result_main) > 0) || (isPostRequestParameterSet('lock'))) {
58         if (isPostRequestParameterSet('accept')) {
59                 if (countPostSelection() > 0) {
60                         // Accept mail orders
61                         foreach (postRequestParameter('sel') as $id => $value) {
62                                 // Secure id number
63                                 $id = bigintval($id);
64
65                                 // Order placed in queue...
66                                 $result = SQL_QUERY_ESC("SELECT
67         po.url, po.subject, po.sender, pay.payment, po.payment_id
68 FROM
69         `{?_MYSQL_PREFIX?}_pool` AS po
70 INNER JOIN
71         `{?_MYSQL_PREFIX?}_payments` AS pay
72 ON
73         po.payment_id=pay.id
74 WHERE
75         po.id=%s
76 LIMIT 1",
77                                         array($id), __FILE__, __LINE__);
78
79                                 // Update wents fine?
80                                 if (SQL_NUMROWS($result) == 1) {
81                                         // Load data
82                                         $content = SQL_FETCHARRAY($result);
83
84                                         // Free result
85                                         SQL_FREERESULT($result);
86
87                                         // Is the surfbar installed?
88                                         // @TODO Rewrite these if-blocks to a filter
89                                         if ((isExtensionActive('surfbar')) && (getConfig('surfbar_migrate_order') == 'Y')) {
90                                                 // Then "migrate" the URL to the surfbar
91                                                 SURFBAR_ADMIN_MIGRATE_URL($content['url'], $content['sender']);
92                                         } // END - if
93
94                                         // Check for bonus extension version >= 0.4.4 for the order bonus
95                                         if ((getExtensionVersion('bonus') >= '0.4.4') && (getConfig('bonus_active') == 'Y')) {
96                                                 // Add points directly
97                                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `bonus_order`=`bonus_order`+".getConfig('bonus_order')." WHERE `userid`=%s LIMIT 1",
98                                                         array(bigintval($content['sender'])), __FILE__, __LINE__);
99
100                                                 // Subtract bonus points from system
101                                                 handleBonusPoints(getConfig('bonus_order'));
102                                         } // END - if
103
104                                         // Load email template
105                                         $message_user = loadEmailTemplate('order-accept', $content, $content['sender']);
106
107                                         // Send email
108                                         sendEmail($content['sender'], getMessage('MEMBER_ORDER_ACCEPTED'), $message_user);
109
110                                         // Unlock selected email
111                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `data_type`='NEW' WHERE `id`=%s AND `data_type`='ADMIN' LIMIT 1",
112                                                 array($id), __FILE__, __LINE__);
113                                 } // END - if
114                         } // END - foreach
115
116                         // Set message
117                         $message = getMessage('ADMIN_MAILS_ACTIVATED');
118                 } else {
119                         // Nothing checked!
120                         $message = getMessage('ADMIN_MAILS_NOTHING_CHECKED');
121                 }
122
123                 // Mails unlocked for mail delivery
124                 loadTemplate('admin_settings_saved', false, $message);
125         } elseif (isPostRequestParameterSet(('reject'))) {
126                 if (countPostSelection() > 0) {
127                         // Reject mail orders
128                         $OUT = ''; $SW = 2;
129                         foreach (postRequestParameter('sel') as $id => $value) {
130                                 // Secure id number
131                                 $id = bigintval($id);
132
133                                 // Load URL and subject from pool
134                                 $result = SQL_QUERY_ESC("SELECT `url`, `subject`, `sender` FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
135                                         array($id), __FILE__, __LINE__);
136
137                                 // Load data
138                                 $content = SQL_FETCHARRAY($result);
139
140                                 // Free result
141                                 SQL_FREERESULT($result);
142
143                                 // Load email template and send it away
144                                 $message_user = loadEmailTemplate('order-reject', $content, $content['sender']);
145                                 sendEmail($content['sender'], getMessage('MEMBER_ORDER_REJECTED'), $message_user);
146
147                                 // If you do not enter an URL to redirect to, your URL will be set!
148                                 if ((!isPostRequestParameterSet('redirect')) || (postRequestParameter('redirect') == 'http://')) setPostRequestParameter('redirect', getConfig('URL'));
149
150                                 // Redirect URL
151                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET url='%s', `data_type`='NEW' WHERE `id`=%s LIMIT 1",
152                                         array(postRequestParameter('redirect'), $id),__FILE__, __LINE__);
153
154                                 // Prepare data for the row template
155                                 $content = array(
156                                         'sw'  => $SW,
157                                         'id'  => $id,
158                                         'url' => postRequestParameter('url', $id),
159                                 );
160
161                                 // Load row template and switch colors
162                                 $OUT .= loadTemplate('admin_unlock_emails_redir_row', true, $content);
163                                 $SW = 3 - $SW;
164                         }
165
166                         // Load main template
167                         loadTemplate('admin_unlock_emails_redir', false, $OUT);
168                 } else {
169                         // Nothing selected
170                         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_MAILS_NOTHING_CHECKED'));
171                 }
172         } elseif ((isPostRequestParameterSet('lock')) && (countPostSelection() > 0) && (getConfig('url_blacklist') == 'Y')) {
173                 // Lock URLs
174                 foreach (postRequestParameter('sel') as $id => $url) {
175                         // Secure id number
176                         $id = bigintval($id);
177
178                         // Lookup in blacklist
179                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_url_blacklist` WHERE `url`='%s' LIMIT 1",
180                                 array($url), __FILE__, __LINE__);
181                         if (SQL_NUMROWS($result) == '0') {
182                                 // Did not find a record so we can add it... :)
183                                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_url_blacklist` (`url`,`pool_id`) VALUES ('%s',%s)",
184                                         array($url, $id), __FILE__, __LINE__);
185                         } // END - if
186
187                         // Free memory
188                         SQL_FREERESULT($result);
189                 } // END - foreach
190
191                 // Output message
192                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_URLS_BLOCKED'));
193         } elseif ((!isPostRequestParameterSet('lock')) && (!isPostRequestParameterSet('accept')) && (!isPostRequestParameterSet('reject'))) {
194                 // Mail orders are in pool so we can display them
195                 $OUT = ''; $SW = 2;
196                 while ($content = SQL_FETCHARRAY($result_main)) {
197                         // Prepare data for the template
198                         $content = array(
199                                 'sw'          => $SW,
200                                 'id'          => $content['id'],
201                                 'sender'      => $content['sender'],
202                                 'u_link'      => generateUserProfileLink($content['sender']),
203                                 'subject'     => $content['subject'],
204                                 'tester'      => generateFrametesterUrl($content['url']),
205                                 'url'         => $content['url'],
206                                 'cat_title'   => str_replace("\"", '&quot;', getCategory($content['category'])),
207                                 'cat_link'    => $content['category'],
208                                 'pay_title'   => str_replace("\"", '&quot;', getPaymentTitlePrice($content['payment'], true)),
209                                 'pay_link'    => $content['payment'],
210                                 'timestamp'   => generateDateTime($content['timestamp'], 2),
211                                 'target_send' => $content['target_send'],
212                         );
213
214                         // Load row template and switch colors
215                         $OUT .= loadTemplate('admin_unlock_emails_row', true, $content);
216                         $SW = 3 - $SW;
217                 } // END - while
218
219                 // Free memory
220                 SQL_FREERESULT($result_main);
221
222                 // Remember in array
223                 $content['rows'] = $OUT;
224
225                 // Load main template
226                 loadTemplate('admin_unlock_emails', false, $content);
227         } elseif ((isPostRequestParameterSet('lock')) && (getConfig('url_blacklist') != 'Y')) {
228                 // URL blacklist not activated
229                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_URL_BLACKLIST_DISABLED'));
230         } else {
231                 // Wrong call!
232                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_WRONG_CALL'));
233         }
234 } else {
235         // No mail orders fond
236         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MAILS_IN_POOL'));
237 }
238
239 // [EOF]
240 ?>