More misc fixes and rewrites (sorry, lame description)
[mailer.git] / inc / modules / admin / what-unlock_emails.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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 - 2008 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')) || (!IS_ADMIN())) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 }
44
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
47
48 // Define some variables
49 global $DATA;
50
51 // Check for mails
52 $result_main = SQL_QUERY("SELECT `id`,`sender`,`subject`,`payment_id` AS `payment`,`timestamp`,`url`,`target_send`,`cat_id` AS `category`
53 FROM `{!_MYSQL_PREFIX!}_pool`
54 WHERE `data_type`='ADMIN'
55 ORDER BY `timestamp` ASC", __FILE__, __LINE__);
56
57 if ((SQL_NUMROWS($result_main) > 0) || (REQUEST_ISSET_POST('lock'))) {
58         // Count checked checkboxes
59         $SEL = 0;
60         if (REQUEST_ISSET_POST('sel')) {
61                 // Are there checked boxes?
62                 if (count(REQUEST_POST('sel')) > 0) {
63                         // Count now... We use an own function for now
64                         $SEL = countPostSelection();
65                 } // END - if
66         } // END - if
67
68         if (REQUEST_ISSET_POST('accept')) {
69                 if ($SEL > 0) {
70                         // Accept mail orders
71                         foreach (REQUEST_POST('sel') as $id => $value) {
72                                 // Secure ID number
73                                 $id = bigintval($id);
74
75                                 // Order placed in queue...
76                                 $result = SQL_QUERY_ESC("SELECT
77         po.url, po.subject, po.sender, pay.payment, 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                                         $DATA = SQL_FETCHARRAY($result);
93
94                                         // Free result
95                                         SQL_FREERESULT($result);
96
97                                         // Is the surfbar installed?
98                                         if ((EXT_IS_ACTIVE('surfbar')) && (getConfig('surfbar_migrate_order') == 'Y')) {
99                                                 // Then "migrate" the URL to the surfbar
100                                                 SURFBAR_ADMIN_MIGRATE_URL($DATA['url'], $DATA['sender']);
101                                         } // END - if
102
103                                         // Check for bonus extension version >= 0.4.4 for the order bonus
104                                         if ((GET_EXT_VERSION('bonus') >= '0.4.4') && (getConfig('bonus_active') == 'Y')) {
105                                                 // Add points directly
106                                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET `bonus_order`=`bonus_order`+".getConfig('bonus_order')." WHERE `userid`=%s LIMIT 1",
107                                                         array(bigintval($DATA['sender'])), __FILE__, __LINE__);
108
109                                                 // Subtract bonus points from system
110                                                 BONUS_POINTS_HANDLER(getConfig('bonus_order'));
111                                         } // END - if
112
113                                         // Load email template
114                                         $message_user = LOAD_EMAIL_TEMPLATE('order-accept', array(), $DATA['sender']);
115
116                                         // Send email
117                                         sendEmail($DATA['sender'], MEMBER_ORDER_ACCEPTED, $message_user);
118
119                                         // Unlock selected email
120                                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_pool` SET `data_type`='NEW' WHERE `id`=%s AND `data_type`='ADMIN' LIMIT 1",
121                                                 array($id), __FILE__, __LINE__);
122                                 } // END - if
123                         } // END - foreach
124
125                         // Set message
126                         $message = getMessage('ADMIN_MAILS_ACTIVATED');
127                 } else {
128                         // Nothing checked!
129                         $message = getMessage('ADMIN_MAILS_NOTHING_CHECKED');
130                 }
131
132                 // Mails unlocked for mail delivery
133                 LOAD_TEMPLATE('admin_settings_saved', false, $message);
134         } elseif (REQUEST_ISSET_POST(('reject'))) {
135                 if ($SEL > 0) {
136                         // Reject mail orders
137                         $OUT = ''; $SW = 2;
138                         foreach (REQUEST_POST('sel') as $id => $value) {
139                                 // Secure ID number
140                                 $id = bigintval($id);
141
142                                 // Load URL and subject from pool
143                                 $result = SQL_QUERY_ESC("SELECT `url`, `subject`, `sender` FROM `{!_MYSQL_PREFIX!}_pool` WHERE `id`=%s LIMIT 1",
144                                         array($id), __FILE__, __LINE__);
145
146                                 // Load data
147                                 $DATA = SQL_FETCHARRAY($result);
148
149                                 // Free result
150                                 SQL_FREERESULT($result);
151
152                                 // Load email template and send it away
153                                 $message_user = LOAD_EMAIL_TEMPLATE('order-reject', array(), $DATA['sender']);
154                                 sendEmail($DATA['sender'], getMessage('MEMBER_ORDER_REJECTED'), $message_user);
155
156                                 // If you do not enter an URL to redirect to, your URL will be set!
157                                 if ((!REQUEST_ISSET_POST(('redirect'))) || (REQUEST_POST('redirect') == 'http://')) REQUEST_SET_POST('redirect', constant('URL'));
158
159                                 // Redirect URL
160                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_pool` SET url='%s', `data_type`='NEW' WHERE `id`=%s LIMIT 1",
161                                         array(REQUEST_POST('redirect'), $id),__FILE__, __LINE__);
162
163                                 // Prepare data for the row template
164                                 $content = array(
165                                         'sw'  => $SW,
166                                         'id'  => $id,
167                                         'url' => REQUEST_POST('url', $id),
168                                 );
169
170                                 // Load row template and switch colors
171                                 $OUT .= LOAD_TEMPLATE('admin_unlock_emails_redir_row', true, $content);
172                                 $SW = 3 - $SW;
173                         }
174                         define('__URL_ROWS', $OUT);
175
176                         // Load main template
177                         LOAD_TEMPLATE('admin_unlock_emails_redir');
178                 } else {
179                         // Nothing selected
180                         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_MAILS_NOTHING_CHECKED'));
181                 }
182         } elseif ((REQUEST_ISSET_POST('lock')) && ($SEL > 0) && (getConfig('url_blacklist') == 'Y')) {
183                 // Lock URLs
184                 foreach (REQUEST_POST('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_NUMROWS($result) == 0) {
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                 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_URLS_BLOCKED'));
203         } elseif ((!REQUEST_ISSET_POST('lock')) && (!REQUEST_ISSET_POST('accept')) && (!REQUEST_ISSET_POST(('reject'))) && (getConfig('url_blacklist') == 'Y')) {
204                 // Mail orders are in pool so we can display them
205                 $OUT = ''; $SW = 2;
206                 while ($content = SQL_FETCHARRAY($result_main)) {
207                         // Prepare data for the template
208                         $content = array(
209                                 'sw'        => $SW,
210                                 'id'        => $content['id'],
211                                 'sender'    => $content['sender'],
212                                 'u_link'    => generateUserProfileLink($content['sender']),
213                                 'subj'      => COMPILE_CODE($content['subject']),
214                                 'tester'    => FRAMETESTER($content['url']),
215                                 'url'       => $content['url'],
216                                 'cat_title' => str_replace("\"", "&quot;", getCategory($content['category'])),
217                                 'cat_link'  => $content['category'],
218                                 'pay_title' => str_replace("\"", "&quot;", getPaymentTitlePrice($content['payment'], true)),
219                                 'pay_link'  => $content['payment'],
220                                 'ordered'   => generateDateTime($content['timestamp'], '2'),
221                                 'tsend'     => $content['target_send'],
222                         );
223
224                         // Load row template and switch colors
225                         $OUT .= LOAD_TEMPLATE('admin_unlock_emails_row', true, $content);
226                         $SW = 3 - $SW;
227                 } // END - while
228
229                 // Free memory
230                 SQL_FREERESULT($result_main);
231                 define('__UNLOCK_ROWS', $OUT);
232
233                 // Prepare rejection URL
234                 $REJECT = 'http://';
235                 if (GET_EXT_VERSION('other') >= '0.1.6') $REJECT = getConfig('reject_url');
236                 define('__REJECT_URL', $REJECT);
237
238                 // Load main template
239                 LOAD_TEMPLATE('admin_unlock_emails');
240         } elseif ((REQUEST_ISSET_POST('lock')) && (getConfig('url_blacklist') != 'Y')) {
241                 // URL blacklist not activated
242                 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_URL_BLACKLIST_DISABLED'));
243         } else {
244                 // Wrong call!
245                 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_WRONG_CALL'));
246         }
247 } else {
248         // No mail orders fond
249         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_NO_MAILS_IN_POOL'));
250 }
251
252 //
253 ?>