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