Code style changed, ext-user continued:
[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         po.`url`,
74         po.`subject`,
75         po.`sender`,
76         pay.`payment`,
77         po.`payment_id`
78 FROM
79         `{?_MYSQL_PREFIX?}_pool` AS `po`
80 INNER JOIN
81         `{?_MYSQL_PREFIX?}_payments` AS `pay`
82 ON
83         po.`payment_id`=pay.`id`
84 WHERE
85         po.`id`=%s
86 LIMIT 1',
87                                         array($id), __FILE__, __LINE__);
88
89                                 // Update wents fine?
90                                 if (SQL_NUMROWS($result) == 1) {
91                                         // Load data
92                                         $content = SQL_FETCHARRAY($result);
93
94                                         // Is the surfbar installed?
95                                         // @TODO Rewrite these if-blocks to a filter
96                                         if ((isExtensionActive('surfbar')) && (getConfig('surfbar_migrate_order') == 'Y')) {
97                                                 // Then "migrate" the URL to the surfbar
98                                                 doSurfbarAdminMigrateUrl($content['url'], $content['sender']);
99                                         } // END - if
100
101                                         // Check for bonus extension version >= 0.4.4 for the order bonus
102                                         if ((isExtensionInstalledAndNewer('bonus', '0.4.4')) && (isBonusRallyeActive())) {
103                                                 // Add points directly
104                                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `bonus_order`=`bonus_order`+{?bonus_order?} WHERE `userid`=%s LIMIT 1",
105                                                         array(bigintval($content['sender'])), __FILE__, __LINE__);
106
107                                                 // Subtract bonus points from system
108                                                 handleBonusPoints(getConfig('bonus_order'), $content['sender']);
109                                         } // END - if
110
111                                         // Load email template
112                                         $message_user = loadEmailTemplate('member_order_accepted', $content, $content['sender']);
113
114                                         // Send email
115                                         sendEmail($content['sender'], '{--MEMBER_ORDER_ACCEPTED--}', $message_user);
116
117                                         // Unlock selected email
118                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `data_type`='NEW' WHERE `id`=%s AND `data_type`='ADMIN' LIMIT 1",
119                                                 array($id), __FILE__, __LINE__);
120                                 } // END - if
121
122                                 // Free result
123                                 SQL_FREERESULT($result);
124                         } // END - foreach
125
126                         // Set message
127                         $message = '{--ADMIN_MAILS_ACTIVATED--}';
128                 } else {
129                         // Nothing checked!
130                         $message = '{--ADMIN_MAILS_NOTHING_CHECKED--}';
131                 }
132
133                 // Mails unlocked for mail delivery
134                 displayMessage($message);
135         } elseif (isPostRequestElementSet('reject')) {
136                 if (ifPostContainsSelections()) {
137                         // Reject mail orders
138                         $OUT = '';
139                         foreach (postRequestElement('sel') as $id => $value) {
140                                 // Secure id number
141                                 $id = bigintval($id);
142
143                                 // Load URL and subject from pool
144                                 $result = SQL_QUERY_ESC("SELECT `url`, `subject`, `sender` FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
145                                         array($id), __FILE__, __LINE__);
146
147                                 // Load data
148                                 $content = SQL_FETCHARRAY($result);
149
150                                 // Free result
151                                 SQL_FREERESULT($result);
152
153                                 // Load email template and send it away
154                                 $message_user = loadEmailTemplate('member_order_rejected', $content, $content['sender']);
155                                 sendEmail($content['sender'], '{--MEMBER_ORDER_REJECTED--}', $message_user);
156
157                                 // If you do not enter an URL to redirect to, your URL will be set!
158                                 if ((!isPostRequestElementSet('redirect')) || (postRequestElement('redirect') == 'http://')) {
159                                         setPostRequestElement('redirect', getUrl());
160                                 } // END - if
161
162                                 // Redirect URL
163                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `url`='%s',`data_type`='NEW' WHERE `id`=%s LIMIT 1",
164                                         array(postRequestElement('redirect'), $id),__FILE__, __LINE__);
165
166                                 // Prepare data for the row template
167                                 $content = array(
168                                         'id'  => $id,
169                                         'url' => postRequestElement('url', $id),
170                                 );
171
172                                 // Load row template and switch colors
173                                 $OUT .= loadTemplate('admin_unlock_emails_redir_row', TRUE, $content);
174                         } // END - foreach
175
176                         // Load main template
177                         loadTemplate('admin_unlock_emails_redir', FALSE, $OUT);
178                 } else {
179                         // Nothing selected
180                         displayMessage('{--ADMIN_MAILS_NOTHING_CHECKED--}');
181                 }
182         } elseif ((isFormSent('lock')) && (ifPostContainsSelections()) && (isUrlBlacklistEnabled())) {
183                 // Lock URLs
184                 foreach (postRequestElement('sel') as $id => $url) {
185                         // Secure id number
186                         $id = bigintval($id);
187
188                         // Lookup in blacklist
189                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_url_blacklist` WHERE `url`='%s' LIMIT 1",
190                                 array($url), __FILE__, __LINE__);
191                         if (SQL_HASZERONUMS($result)) {
192                                 // Did not find a record so we can add it... :)
193                                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_url_blacklist` (`url`, `pool_id`) VALUES ('%s',%s)",
194                                         array($url, $id), __FILE__, __LINE__);
195                         } // END - if
196
197                         // Free memory
198                         SQL_FREERESULT($result);
199                 } // END - foreach
200
201                 // Output message
202                 displayMessage('{--ADMIN_URLS_BLOCKED--}');
203         } elseif ((!isFormSent('lock')) && (!isFormSent('accept')) && (!isFormSent('reject'))) {
204                 // Mail orders are in pool so we can display them
205                 $OUT = '';
206                 while ($content = SQL_FETCHARRAY($result_main)) {
207                         // Prepare data for the template
208                         $content['timestamp'] = generateDateTime($content['timestamp'], 2);
209
210                         // Load row template and switch colors
211                         $OUT .= loadTemplate('admin_unlock_emails_row', TRUE, $content);
212                 } // END - while
213
214                 // Free memory
215                 SQL_FREERESULT($result_main);
216
217                 // Remember in array
218                 $content['rows'] = $OUT;
219
220                 // Load main template
221                 loadTemplate('admin_unlock_emails', FALSE, $content);
222         } elseif ((isFormSent('lock')) && (!isUrlBlacklistEnabled())) {
223                 // URL blacklist not activated
224                 displayMessage('{--ADMIN_URL_BLACKLIST_DISABLED--}');
225         } else {
226                 // Wrong call!
227                 displayMessage('{--ADMIN_WRONG_CALL--}');
228         }
229 } else {
230         // No mail orders fond
231         displayMessage('{--ADMIN_NO_MAILS_IN_POOL--}');
232 }
233
234 // [EOF]
235 ?>