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