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