Huge rewrite of default parameters, ext-network continued:
[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  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
41         die();
42 } // END - if
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
47 // Define some variables
48 global $DATA;
49
50 // Check for mails
51 $result_main = SQL_QUERY("SELECT
52         `id`,`sender`,`subject`,`payment_id` AS `payment`,`timestamp`,`url`,`target_send`,`cat_id` AS category
53 FROM
54         `{?_MYSQL_PREFIX?}_pool`
55 WHERE
56         `data_type`='ADMIN'
57 ORDER BY
58         `timestamp` ASC", __FILE__, __LINE__);
59
60 if ((SQL_NUMROWS($result_main) > 0) || (isPostRequestElementSet('lock'))) {
61         // Count checked checkboxes
62         $SEL = '0';
63         if (isPostRequestElementSet('sel')) {
64                 // Are there checked boxes?
65                 if (count(postRequestElement('sel')) > 0) {
66                         // Count now... We use an own function for now
67                         $SEL = countPostSelection();
68                 } // END - if
69         } // END - if
70
71         if (isPostRequestElementSet('accept')) {
72                 if ($SEL > 0) {
73                         // Accept mail orders
74                         foreach (postRequestElement('sel') as $id => $value) {
75                                 // Secure id number
76                                 $id = bigintval($id);
77
78                                 // Order placed in queue...
79                                 $result = SQL_QUERY_ESC("SELECT
80         po.url, po.subject, po.sender, pay.payment, po.payment_id
81 FROM
82         `{?_MYSQL_PREFIX?}_pool` AS po
83 INNER JOIN
84         `{?_MYSQL_PREFIX?}_payments` AS pay
85 ON
86         po.payment_id=pay.id
87 WHERE
88         po.id=%s
89 LIMIT 1",
90                                         array($id), __FILE__, __LINE__);
91
92                                 // Update wents fine?
93                                 if (SQL_NUMROWS($result) == 1) {
94                                         // Load data
95                                         $content = SQL_FETCHARRAY($result);
96
97                                         // Free result
98                                         SQL_FREERESULT($result);
99
100                                         // Is the surfbar installed?
101                                         // @TODO Rewrite these if-blocks to a filter
102                                         if ((isExtensionActive('surfbar')) && (getConfig('surfbar_migrate_order') == 'Y')) {
103                                                 // Then "migrate" the URL to the surfbar
104                                                 SURFBAR_ADMIN_MIGRATE_URL($content['url'], $content['sender']);
105                                         } // END - if
106
107                                         // Check for bonus extension version >= 0.4.4 for the order bonus
108                                         if ((getExtensionVersion('bonus') >= '0.4.4') && (getConfig('bonus_active') == 'Y')) {
109                                                 // Add points directly
110                                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `bonus_order`=`bonus_order`+".getConfig('bonus_order')." WHERE `userid`=%s LIMIT 1",
111                                                         array(bigintval($content['sender'])), __FILE__, __LINE__);
112
113                                                 // Subtract bonus points from system
114                                                 handleBonusPoints(getConfig('bonus_order'));
115                                         } // END - if
116
117                                         // Load email template
118                                         $message_user = loadEmailTemplate('order-accept', $content, $content['sender']);
119
120                                         // Send email
121                                         sendEmail($content['sender'], getMessage('MEMBER_ORDER_ACCEPTED'), $message_user);
122
123                                         // Unlock selected email
124                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `data_type`='NEW' WHERE `id`=%s AND `data_type`='ADMIN' LIMIT 1",
125                                                 array($id), __FILE__, __LINE__);
126                                 } // END - if
127                         } // END - foreach
128
129                         // Set message
130                         $message = getMessage('ADMIN_MAILS_ACTIVATED');
131                 } else {
132                         // Nothing checked!
133                         $message = getMessage('ADMIN_MAILS_NOTHING_CHECKED');
134                 }
135
136                 // Mails unlocked for mail delivery
137                 loadTemplate('admin_settings_saved', false, $message);
138         } elseif (isPostRequestElementSet(('reject'))) {
139                 if ($SEL > 0) {
140                         // Reject mail orders
141                         $OUT = ''; $SW = 2;
142                         foreach (postRequestElement('sel') as $id => $value) {
143                                 // Secure id number
144                                 $id = bigintval($id);
145
146                                 // Load URL and subject from pool
147                                 $result = SQL_QUERY_ESC("SELECT `url`, `subject`, `sender` FROM `{?_MYSQL_PREFIX?}_pool` WHERE `id`=%s LIMIT 1",
148                                         array($id), __FILE__, __LINE__);
149
150                                 // Load data
151                                 $content = SQL_FETCHARRAY($result);
152
153                                 // Free result
154                                 SQL_FREERESULT($result);
155
156                                 // Load email template and send it away
157                                 $message_user = loadEmailTemplate('order-reject', $content, $content['sender']);
158                                 sendEmail($content['sender'], getMessage('MEMBER_ORDER_REJECTED'), $message_user);
159
160                                 // If you do not enter an URL to redirect to, your URL will be set!
161                                 if ((!isPostRequestElementSet(('redirect'))) || (postRequestElement('redirect') == 'http://')) setRequestPostElement('redirect', getConfig('URL'));
162
163                                 // Redirect URL
164                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET url='%s', `data_type`='NEW' WHERE `id`=%s LIMIT 1",
165                                         array(postRequestElement('redirect'), $id),__FILE__, __LINE__);
166
167                                 // Prepare data for the row template
168                                 $content = array(
169                                         'sw'  => $SW,
170                                         'id'  => $id,
171                                         'url' => postRequestElement('url', $id),
172                                 );
173
174                                 // Load row template and switch colors
175                                 $OUT .= loadTemplate('admin_unlock_emails_redir_row', true, $content);
176                                 $SW = 3 - $SW;
177                         }
178
179                         // Load main template
180                         loadTemplate('admin_unlock_emails_redir', false, $OUT);
181                 } else {
182                         // Nothing selected
183                         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_MAILS_NOTHING_CHECKED'));
184                 }
185         } elseif ((isPostRequestElementSet('lock')) && ($SEL > 0) && (getConfig('url_blacklist') == 'Y')) {
186                 // Lock URLs
187                 foreach (postRequestElement('sel') as $id => $url) {
188                         // Secure id number
189                         $id = bigintval($id);
190
191                         // Lookup in blacklist
192                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_url_blacklist` WHERE `url`='%s' LIMIT 1",
193                                 array($url), __FILE__, __LINE__);
194                         if (SQL_NUMROWS($result) == '0') {
195                                 // Did not find a record so we can add it... :)
196                                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_url_blacklist` (`url`,`pool_id`) VALUES ('%s',%s)",
197                                         array($url, $id), __FILE__, __LINE__);
198                         } // END - if
199
200                         // Free memory
201                         SQL_FREERESULT($result);
202                 } // END - foreach
203
204                 // Output message
205                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_URLS_BLOCKED'));
206         } elseif ((!isPostRequestElementSet('lock')) && (!isPostRequestElementSet('accept')) && (!isPostRequestElementSet(('reject'))) && (getConfig('url_blacklist') == 'Y')) {
207                 // Mail orders are in pool so we can display them
208                 $OUT = ''; $SW = 2;
209                 while ($content = SQL_FETCHARRAY($result_main)) {
210                         // Prepare data for the template
211                         $content = array(
212                                 'sw'          => $SW,
213                                 'id'          => $content['id'],
214                                 'sender'      => $content['sender'],
215                                 'u_link'      => generateUserProfileLink($content['sender']),
216                                 'subject'     => $content['subject'],
217                                 'tester'      => generateFrametesterUrl($content['url']),
218                                 'url'         => $content['url'],
219                                 'cat_title'   => str_replace("\"", '&quot;', getCategory($content['category'])),
220                                 'cat_link'    => $content['category'],
221                                 'pay_title'   => str_replace("\"", '&quot;', getPaymentTitlePrice($content['payment'], true)),
222                                 'pay_link'    => $content['payment'],
223                                 'timestamp'   => generateDateTime($content['timestamp'], 2),
224                                 'target_send' => $content['target_send'],
225                         );
226
227                         // Load row template and switch colors
228                         $OUT .= loadTemplate('admin_unlock_emails_row', true, $content);
229                         $SW = 3 - $SW;
230                 } // END - while
231
232                 // Free memory
233                 SQL_FREERESULT($result_main);
234
235                 // Remember in array
236                 $content['rows'] = $OUT;
237
238                 // Load main template
239                 loadTemplate('admin_unlock_emails', false, $content);
240         } elseif ((isPostRequestElementSet('lock')) && (getConfig('url_blacklist') != 'Y')) {
241                 // URL blacklist not activated
242                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_URL_BLACKLIST_DISABLED'));
243         } else {
244                 // Wrong call!
245                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_WRONG_CALL'));
246         }
247 } else {
248         // No mail orders fond
249         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MAILS_IN_POOL'));
250 }
251
252 // [EOF]
253 ?>