c26b9bcda13835111ae91f95fa675c518bd6dfcb
[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, timestamp, url, target_send, cat_id FROM "._MYSQL_PREFIX."_pool WHERE data_type='ADMIN' ORDER BY timestamp", __FILE__, __LINE__);
48
49 if ((SQL_NUMROWS($result_main) > 0) || (isset($_POST['lock']))) {
50         // Count checked checkboxes
51         $SEL = 0;
52         if (isset($_POST['sel'])) {
53                 // Are there checked boxes?
54                 if (count($_POST['sel']) > 0) {
55                         // Count now... We use an own function for now
56                         $SEL = SELECTION_COUNT($_POST['sel']);
57                 } // END - if
58         } // END - if
59
60         if (isset($_POST['accept'])) {
61                 if ($SEL > 0) {
62                         // Accept mail orders
63                         foreach ($_POST['sel'] as $id => $value) {
64                                 // Secure ID number
65                                 $id = bigintval($id);
66
67                                 // Order placed in queue...
68                                 $result = SQL_QUERY_ESC("SELECT po.url, po.subject, po.sender, pay.payment, po.payment_id
69 FROM "._MYSQL_PREFIX."_pool AS po
70 INNER JOIN "._MYSQL_PREFIX."_payments AS pay
71 ON po.payment_id=pay.id
72 WHERE po.id=%s
73 LIMIT 1",
74                                         array($id), __FILE__, __LINE__);
75
76                                 // Update wents fine?
77                                 if (SQL_NUMROWS($result) == 1) {
78                                         // Load data
79                                         $DATA = SQL_FETCHARRAY($result);
80
81                                         // Free result
82                                         SQL_FREERESULT($result);
83
84                                         // Is the surfbar installed?
85                                         if ((EXT_IS_ACTIVE("surfbar")) && (getConfig('surfbar_migrate_order') == "Y")) {
86                                                 // Then "migrate" the URL to the surfbar
87                                                 SURFBAR_ADMIN_MIGRATE_URL($DATA['url'], $DATA['sender']);
88                                         } // END - if
89
90                                         // Check for bonus extension version >= 0.4.4 for the order bonus
91                                         if ((GET_EXT_VERSION("bonus") >= "0.4.4") && (getConfig('bonus_active') == "Y")) {
92                                                 // Add points directly
93                                                 $result = SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_user_data` SET bonus_order=bonus_order+".getConfig('bonus_order')." WHERE userid=%s LIMIT 1",
94                                                         array(bigintval($DATA['sender'])), __FILE__, __LINE__);
95
96                                                 // Subtract bonus points from system
97                                                 BONUS_POINTS_HANDLER(getConfig('bonus_order'));
98                                         } // END - if
99
100                                         // Load email template
101                                         $msg_user = LOAD_EMAIL_TEMPLATE("order-accept", array(), $DATA['sender']);
102
103                                         // Send email
104                                         SEND_EMAIL($DATA['sender'], MEMBER_ORDER_ACCEPTED, $msg_user);
105
106                                         // Unlock selected email
107                                         $result = 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                         } // END - foreach
111
112                         // Set message
113                         $MSG = ADMIN_MAILS_ACTIVATED;
114                 } else {
115                         // Nothing checked!
116                         $MSG = ADMIN_MAILS_NOTHING_CHECKED;
117                 }
118
119                 // Mails unlocked for mail delivery
120                 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
121         } elseif (isset($_POST['reject'])) {
122                 if ($SEL > 0) {
123                         // Reject mail orders
124                         $SW = 2; $OUT = "";
125                         foreach ($_POST['sel'] as $id => $value) {
126                                 // Secure ID number
127                                 $id = bigintval($id);
128
129                                 // Load URL and subject from pool
130                                 $result = SQL_QUERY_ESC("SELECT url, subject, sender FROM "._MYSQL_PREFIX."_pool WHERE id=%s LIMIT 1",
131                                         array($id), __FILE__, __LINE__);
132
133                                 // Load data
134                                 $DATA = SQL_FETCHARRAY($result);
135
136                                 // Free result
137                                 SQL_FREERESULT($result);
138
139                                 // Load email template and send it away
140                                 $msg_user = LOAD_EMAIL_TEMPLATE("order-reject", array(), $DATA['sender']);
141                                 SEND_EMAIL($DATA['sender'], MEMBER_ORDER_REJECTED, $msg_user);
142
143                                 // If you do not enter an URL to redirect to, your URL will be set!
144                                 if ((empty($_POST['redirect'])) || ($_POST['redirect'] == "http://")) $_POST['redirect'] = URL;
145
146                                 // Redirect URL
147                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET url='%s', data_type='NEW' WHERE id=%s LIMIT 1",
148                                         array($_POST['redirect'], $id),__FILE__, __LINE__);
149
150                                 // Prepare data for the row template
151                                 $content = array(
152                                         'sw'  => $SW,
153                                         'id'  => $id,
154                                         'url' => $_POST['url'][$id],
155                                 );
156
157                                 // Load row template and switch colors
158                                 $OUT .= LOAD_TEMPLATE("admin_unlock_emails_redir_row", true, $content);
159                                 $SW = 3 - $SW;
160                         }
161                         define('__URL_ROWS', $OUT);
162
163                         // Load main template
164                         LOAD_TEMPLATE("admin_unlock_emails_redir");
165                 } else {
166                         // Nothing selected
167                         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_MAILS_NOTHING_CHECKED);
168                 }
169         } elseif ((isset($_POST['lock'])) || ($SEL > 0)) {
170                 if ($SEL > 0) {
171                         // Lock URLs
172                         foreach ($_POST['sel'] as $id => $url) {
173                                 // Lookup in blacklist
174                                 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_url_blist WHERE url='%s' LIMIT 1",
175                                         array($url), __FILE__, __LINE__);
176                                 if (SQL_NUMROWS($result) == 0) {
177                                         // Did not find a record so we can add it... :)
178                                         $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_url_blist (url, timestamp) VALUES ('%s', UNIX_TIMESTAMP())",
179                                                 array($url), __FILE__, __LINE__);
180                                 } else {
181                                         // Free memory
182                                         SQL_FREERESULT($result);
183                                 }
184                         }
185
186                         // Set message
187                         $MSG = ADMIN_URLS_BLOCKED;
188                 } else {
189                         // Nothing selected
190                         $MSG = ADMIN_MAILS_NOTHING_CHECKED;
191                 }
192                 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
193         } elseif ((empty($_POST['lock'])) && (empty($_POST['accept'])) && (empty($_POST['reject']))) {
194                 // Mail orders are in pool so we can display them
195                 $SW = 2; $OUT = "";
196                 while (list($id, $sender, $subj, $pay, $time, $url, $tsend, $cat) = SQL_FETCHROW($result_main))
197                 {
198                         // Prepare data for the template
199                         $content = array(
200                                 'sw'        => $SW,
201                                 'id'        => $id,
202                                 'sender'    => $sender,
203                                 'u_link'    => ADMIN_USER_PROFILE_LINK($sender),
204                                 'subj'      => COMPILE_CODE($subj),
205                                 'tester'    => FRAMETESTER($url),
206                                 'url'       => $url,
207                                 'cat_title' => str_replace("\"", "&quot;", GET_CATEGORY($cat)),
208                                 'cat_link'  => $cat,
209                                 'pay_title' => str_replace("\"", "&quot;", GET_PAYMENT($pay, true)),
210                                 'pay_link'  => $pay,
211                                 'ordered'   => MAKE_DATETIME($time, "2"),
212                                 'tsend'     => $tsend,
213                         );
214
215                         // Load row template and switch colors
216                         $OUT .= LOAD_TEMPLATE("admin_unlock_emails_row", true, $content);
217                         $SW = 3 - $SW;
218                 }
219
220                 // Free memory
221                 SQL_FREERESULT($result_main);
222                 define('__UNLOCK_ROWS', $OUT);
223
224                 // Prepare rejection URL
225                 $REJECT = "http://";
226                 if (GET_EXT_VERSION("other") >= "0.1.6") $REJECT = getConfig('reject_url');
227                 define('__REJECT_URL', $REJECT);
228
229                 // Load main template
230                 LOAD_TEMPLATE("admin_unlock_emails");
231         } else {
232                 // Wrong call!
233                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_WRONG_CALL);
234         }
235 } else {
236         // No mail orders fond
237         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NO_MAILS_IN_POOL);
238 }
239
240 //
241 ?>