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