More constant rewrites
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
42
43 // Define some variables
44 global $DATA;
45
46 // Check for mails
47 $result_main = SQL_QUERY("SELECT `id`, `sender`, `subject`, `payment_id` AS `payment`, `timestamp`, `url`, `target_send`, `cat_id` AS `category`
48 FROM `{!_MYSQL_PREFIX!}_pool`
49 WHERE `data_type`='ADMIN'
50 ORDER BY `timestamp` ASC", __FILE__, __LINE__);
51
52 if ((SQL_NUMROWS($result_main) > 0) || (REQUEST_ISSET_POST(('lock')))) {
53         // Count checked checkboxes
54         $SEL = 0;
55         if (REQUEST_ISSET_POST('sel')) {
56                 // Are there checked boxes?
57                 if (count(REQUEST_POST('sel')) > 0) {
58                         // Count now... We use an own function for now
59                         $SEL = SELECTION_COUNT(REQUEST_POST('sel'));
60                 } // END - if
61         } // END - if
62
63         if (REQUEST_ISSET_POST(('accept'))) {
64                 if ($SEL > 0) {
65                         // Accept mail orders
66                         foreach (REQUEST_POST('sel') as $id => $value) {
67                                 // Secure ID number
68                                 $id = bigintval($id);
69
70                                 // Order placed in queue...
71                                 $result = SQL_QUERY_ESC("SELECT po.url, po.subject, po.sender, pay.payment, po.payment_id
72 FROM `{!_MYSQL_PREFIX!}_pool` AS po
73 INNER JOIN `{!_MYSQL_PREFIX!}_payments` AS pay
74 ON po.payment_id=pay.id
75 WHERE 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                                         $DATA = SQL_FETCHARRAY($result);
83
84                                         // Free result
85                                         SQL_FREERESULT($result);
86
87                                         // Is the surfbar installed?
88                                         if ((EXT_IS_ACTIVE("surfbar")) && (getConfig('surfbar_migrate_order') == "Y")) {
89                                                 // Then "migrate" the URL to the surfbar
90                                                 SURFBAR_ADMIN_MIGRATE_URL($DATA['url'], $DATA['sender']);
91                                         } // END - if
92
93                                         // Check for bonus extension version >= 0.4.4 for the order bonus
94                                         if ((GET_EXT_VERSION("bonus") >= "0.4.4") && (getConfig('bonus_active') == "Y")) {
95                                                 // Add points directly
96                                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET bonus_order=bonus_order+".getConfig('bonus_order')." WHERE userid=%s LIMIT 1",
97                                                         array(bigintval($DATA['sender'])), __FILE__, __LINE__);
98
99                                                 // Subtract bonus points from system
100                                                 BONUS_POINTS_HANDLER(getConfig('bonus_order'));
101                                         } // END - if
102
103                                         // Load email template
104                                         $msg_user = LOAD_EMAIL_TEMPLATE("order-accept", array(), $DATA['sender']);
105
106                                         // Send email
107                                         SEND_EMAIL($DATA['sender'], MEMBER_ORDER_ACCEPTED, $msg_user);
108
109                                         // Unlock selected email
110                                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_pool` SET data_type='NEW' WHERE id=%s AND data_type='ADMIN' LIMIT 1",
111                                                 array($id), __FILE__, __LINE__);
112                                 } // END - if
113                         } // END - foreach
114
115                         // Set message
116                         $MSG = ADMIN_MAILS_ACTIVATED;
117                 } else {
118                         // Nothing checked!
119                         $MSG = ADMIN_MAILS_NOTHING_CHECKED;
120                 }
121
122                 // Mails unlocked for mail delivery
123                 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
124         } elseif (REQUEST_ISSET_POST(('reject'))) {
125                 if ($SEL > 0) {
126                         // Reject mail orders
127                         $SW = 2; $OUT = "";
128                         foreach (REQUEST_POST('sel') as $id => $value) {
129                                 // Secure ID number
130                                 $id = bigintval($id);
131
132                                 // Load URL and subject from pool
133                                 $result = SQL_QUERY_ESC("SELECT url, subject, sender FROM `{!_MYSQL_PREFIX!}_pool` WHERE id=%s LIMIT 1",
134                                         array($id), __FILE__, __LINE__);
135
136                                 // Load data
137                                 $DATA = SQL_FETCHARRAY($result);
138
139                                 // Free result
140                                 SQL_FREERESULT($result);
141
142                                 // Load email template and send it away
143                                 $msg_user = LOAD_EMAIL_TEMPLATE("order-reject", array(), $DATA['sender']);
144                                 SEND_EMAIL($DATA['sender'], MEMBER_ORDER_REJECTED, $msg_user);
145
146                                 // If you do not enter an URL to redirect to, your URL will be set!
147                                 if ((!REQUEST_ISSET_POST(('redirect'))) || (REQUEST_POST('redirect') == "http://")) REQUEST_SET_POST('redirect', constant('URL'));
148
149                                 // Redirect URL
150                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_pool` SET url='%s', data_type='NEW' WHERE id=%s LIMIT 1",
151                                         array(REQUEST_POST('redirect'), $id),__FILE__, __LINE__);
152
153                                 // Prepare data for the row template
154                                 $content = array(
155                                         'sw'  => $SW,
156                                         'id'  => $id,
157                                         'url' => REQUEST_POST('url', $id),
158                                 );
159
160                                 // Load row template and switch colors
161                                 $OUT .= LOAD_TEMPLATE("admin_unlock_emails_redir_row", true, $content);
162                                 $SW = 3 - $SW;
163                         }
164                         define('__URL_ROWS', $OUT);
165
166                         // Load main template
167                         LOAD_TEMPLATE("admin_unlock_emails_redir");
168                 } else {
169                         // Nothing selected
170                         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_MAILS_NOTHING_CHECKED'));
171                 }
172         } elseif ((REQUEST_ISSET_POST(('lock'))) && ($SEL > 0) && (getConfig('url_blacklist') == "Y")) {
173                 // Lock URLs
174                 foreach (REQUEST_POST('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                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_URLS_BLOCKED'));
193         } elseif ((!REQUEST_ISSET_POST(('lock'))) && (!REQUEST_ISSET_POST(('accept'))) && (!REQUEST_ISSET_POST(('reject'))) && (getConfig('url_blacklist') == "Y")) {
194                 // Mail orders are in pool so we can display them
195                 $SW = 2; $OUT = "";
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'    => ADMIN_USER_PROFILE_LINK($content['sender']),
203                                 'subj'      => COMPILE_CODE($content['subject']),
204                                 'tester'    => FRAMETESTER($content['url']),
205                                 'url'       => $content['url'],
206                                 'cat_title' => str_replace("\"", "&quot;", GET_CATEGORY($content['category'])),
207                                 'cat_link'  => $content['category'],
208                                 'pay_title' => str_replace("\"", "&quot;", GET_PAYMENT($content['payment'], true)),
209                                 'pay_link'  => $content['payment'],
210                                 'ordered'   => MAKE_DATETIME($content['timestamp'], "2"),
211                                 'tsend'     => $content['target_send'],
212                         );
213
214                         // Load row template and switch colors
215                         $OUT .= LOAD_TEMPLATE("admin_unlock_emails_row", true, $content);
216                         $SW = 3 - $SW;
217                 } // END - while
218
219                 // Free memory
220                 SQL_FREERESULT($result_main);
221                 define('__UNLOCK_ROWS', $OUT);
222
223                 // Prepare rejection URL
224                 $REJECT = "http://";
225                 if (GET_EXT_VERSION("other") >= "0.1.6") $REJECT = getConfig('reject_url');
226                 define('__REJECT_URL', $REJECT);
227
228                 // Load main template
229                 LOAD_TEMPLATE("admin_unlock_emails");
230         } elseif ((REQUEST_ISSET_POST(('lock'))) && (getConfig('url_blacklist') != "Y")) {
231                 // URL blacklist not activated
232                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_URL_BLACKLIST_DISABLED'));
233         } else {
234                 // Wrong call!
235                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_WRONG_CALL'));
236         }
237 } else {
238         // No mail orders fond
239         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_NO_MAILS_IN_POOL'));
240 }
241
242 //
243 ?>