New wrapper functions introduced, TODOs.txt updated
[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 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.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`, `sender`, `subject`, `payment_id`, `timestamp`, `url`, `target_send`, `cat_id`
49 FROM
50         `{?_MYSQL_PREFIX?}_pool`
51 WHERE
52         `data_type`='ADMIN'
53 ORDER BY
54         `timestamp` ASC", __FILE__, __LINE__);
55
56 if ((!SQL_HASZERONUMS($result_main)) || (isFormSent('lock'))) {
57         if (isFormSent('accept')) {
58                 if (ifPostContainsSelections()) {
59                         // Accept mail orders
60                         foreach (postRequestParameter('sel') as $id => $value) {
61                                 // Secure id number
62                                 $id = bigintval($id);
63
64                                 // Order placed in queue...
65                                 $result = SQL_QUERY_ESC("SELECT
66         po.`url`, po.`subject`, po.`sender`, pay.`payment`, po.`payment_id`
67 FROM
68         `{?_MYSQL_PREFIX?}_pool` AS `po`
69 INNER JOIN
70         `{?_MYSQL_PREFIX?}_payments` AS `pay`
71 ON
72         po.`payment_id`=pay.`id`
73 WHERE
74         po.`id`=%s
75 LIMIT 1",
76                                         array($id), __FILE__, __LINE__);
77
78                                 // Update wents fine?
79                                 if (SQL_NUMROWS($result) == 1) {
80                                         // Load data
81                                         $content = SQL_FETCHARRAY($result);
82
83                                         // Is the surfbar installed?
84                                         // @TODO Rewrite these if-blocks to a filter
85                                         if ((isExtensionActive('surfbar')) && (getConfig('surfbar_migrate_order') == 'Y')) {
86                                                 // Then "migrate" the URL to the surfbar
87                                                 SURFBAR_ADMIN_MIGRATE_URL($content['url'], $content['sender']);
88                                         } // END - if
89
90                                         // Check for bonus extension version >= 0.4.4 for the order bonus
91                                         if ((isExtensionInstalledAndNewer('bonus', '0.4.4')) && (isBonusRallyeActive())) {
92                                                 // Add points directly
93                                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `bonus_order`=`bonus_order`+{?bonus_order?} WHERE `userid`=%s LIMIT 1",
94                                                         array(bigintval($content['sender'])), __FILE__, __LINE__);
95
96                                                 // Subtract bonus points from system
97                                                 handleBonusPoints(getConfig('bonus_order'));
98                                         } // END - if
99
100                                         // Load email template
101                                         $message_user = loadEmailTemplate('order-accept', $content, $content['sender']);
102
103                                         // Send email
104                                         sendEmail($content['sender'], '{--MEMBER_ORDER_ACCEPTED--}', $message_user);
105
106                                         // Unlock selected email
107                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `data_type`='NEW' WHERE `id`=%s AND `data_type`='ADMIN' LIMIT 1",
108                                                 array($id), __FILE__, __LINE__);
109                                 } // END - if
110
111                                 // Free result
112                                 SQL_FREERESULT($result);
113                         } // END - foreach
114
115                         // Set message
116                         $message = '{--ADMIN_MAILS_ACTIVATED--}';
117                 } else {
118                         // Nothing checked!
119                         $message = '{--ADMIN_MAILS_NOTHING_CHECKED--}';
120                 }
121
122                 // Mails unlocked for mail delivery
123
124                 displayMessage($message);
125         } elseif (isPostRequestParameterSet('reject')) {
126                 if (ifPostContainsSelections()) {
127                         // Reject mail orders
128                         $OUT = '';
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'], '{--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://')) {
149                                         setPostRequestParameter('redirect', getUrl());
150                                 } // END - if
151
152                                 // Redirect URL
153                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `url`='%s', `data_type`='NEW' WHERE `id`=%s LIMIT 1",
154                                         array(postRequestParameter('redirect'), $id),__FILE__, __LINE__);
155
156                                 // Prepare data for the row template
157                                 $content = array(
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                         } // END - foreach
165
166                         // Load main template
167                         loadTemplate('admin_unlock_emails_redir', false, $OUT);
168                 } else {
169                         // Nothing selected
170                         displayMessage('{--ADMIN_MAILS_NOTHING_CHECKED--}');
171                 }
172         } elseif ((isFormSent('lock')) && (ifPostContainsSelections()) && (isUrlBlacklistEnabled())) {
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_HASZERONUMS($result)) {
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                 displayMessage('{--ADMIN_URLS_BLOCKED--}');
193         } elseif ((!isFormSent('lock')) && (!isFormSent('accept')) && (!isFormSent('reject'))) {
194                 // Mail orders are in pool so we can display them
195                 $OUT = '';
196                 while ($content = SQL_FETCHARRAY($result_main)) {
197                         // Prepare data for the template
198                         $content['timestamp'] = generateDateTime($content['timestamp'], 2);
199
200                         // Load row template and switch colors
201                         $OUT .= loadTemplate('admin_unlock_emails_row', true, $content);
202                 } // END - while
203
204                 // Free memory
205                 SQL_FREERESULT($result_main);
206
207                 // Remember in array
208                 $content['rows'] = $OUT;
209
210                 // Load main template
211                 loadTemplate('admin_unlock_emails', false, $content);
212         } elseif ((isFormSent('lock')) && (!isUrlBlacklistEnabled())) {
213                 // URL blacklist not activated
214                 displayMessage('{--ADMIN_URL_BLACKLIST_DISABLED--}');
215         } else {
216                 // Wrong call!
217                 displayMessage('{--ADMIN_WRONG_CALL--}');
218         }
219 } else {
220         // No mail orders fond
221         displayMessage('{--ADMIN_NO_MAILS_IN_POOL--}');
222 }
223
224 // [EOF]
225 ?>