Heacy rewrite/cleanup:
[mailer.git] / inc / modules / admin / what-unlock_emails.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 // Check for mails
47 $result_main = sqlQuery("SELECT
48         `id`,
49         `url`,
50         `subject`,
51         `text`,
52         `sender`,
53         `timestamp`,
54         `target_send`,
55         `payment_id`,
56         `cat_id`
57 FROM
58         `{?_MYSQL_PREFIX?}_pool`
59 WHERE
60         `data_type`='ADMIN'
61 ORDER BY
62         `timestamp` ASC", __FILE__, __LINE__);
63
64 if ((!ifSqlHasZeroNums($result_main)) || (isFormSent('lock'))) {
65         if (isFormSent('accept')) {
66                 if (ifPostContainsSelections()) {
67                         // Accept mail orders
68                         foreach (postRequestElement('sel') as $id => $value) {
69                                 // Secure id number
70                                 $id = bigintval($id);
71
72                                 // Get pool data from given id
73                                 $content = getPoolDataFromId($id);
74
75                                 // Found some data?
76                                 if (isFilledArray($content)) {
77                                         // Is the surfbar installed?
78                                         // @TODO Rewrite these if-blocks to a filter
79                                         if ((isExtensionActive('surfbar')) && (getConfig('surfbar_migrate_order') == 'Y')) {
80                                                 // Then "migrate" the URL to the surfbar
81                                                 doSurfbarAdminMigrateUrl($content['url'], $content['sender']);
82                                         } // END - if
83
84                                         // Check for bonus extension version >= 0.4.4 for the order bonus
85                                         if ((isExtensionInstalledAndNewer('bonus', '0.4.4')) && (isBonusRallyeActive())) {
86                                                 // Add points directly
87                                                 sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `bonus_order`=`bonus_order`+{?bonus_order?} WHERE `userid`=%s LIMIT 1",
88                                                         array(bigintval($content['sender'])), __FILE__, __LINE__);
89
90                                                 // Subtract bonus points from system
91                                                 handleBonusPoints(getBonusOrder(), $content['sender']);
92                                         } // END - if
93
94                                         // Load email template
95                                         $message_user = loadEmailTemplate('member_order_accepted', $content, $content['sender']);
96
97                                         // Send email
98                                         sendEmail($content['sender'], '{--MEMBER_ORDER_ACCEPTED--}', $message_user);
99
100                                         // Unlock selected email
101                                         updatePoolDataById($id, 'data_type', 'NEW', NULL, " AND `data_type`='ADMIN'");
102                                 } // END - if
103                         } // END - foreach
104
105                         // Set message
106                         $message = '{--ADMIN_MAILS_ACTIVATED--}';
107                 } else {
108                         // Nothing checked!
109                         $message = '{--ADMIN_MAILS_NOTHING_CHECKED--}';
110                 }
111
112                 // Mails unlocked for mail delivery
113                 displayMessage($message);
114         } elseif (isPostRequestElementSet('reject')) {
115                 if (ifPostContainsSelections()) {
116                         // Reject mail orders
117                         $OUT = '';
118                         foreach (postRequestElement('sel') as $id => $value) {
119                                 // Secure id number
120                                 $id = bigintval($id);
121
122                                 // Get pool data from given id
123                                 $content = getPoolDataFromId($id);
124
125                                 // Load email template and send it away
126                                 $message_user = loadEmailTemplate('member_order_rejected', $content, $content['sender']);
127                                 sendEmail($content['sender'], '{--MEMBER_ORDER_REJECTED--}', $message_user);
128
129                                 // If you do not enter an URL to redirect to, your URL will be set!
130                                 if ((!isPostRequestElementSet('redirect')) || (postRequestElement('redirect') == 'http://')) {
131                                         setPostRequestElement('redirect', getUrl());
132                                 } // END - if
133
134                                 // Redirect URL
135                                 updatePoolDataById($id, NULL, array('url' => postRequestElement('redirect'), 'data_type' => 'NEW'));
136
137                                 // Prepare data for the row template
138                                 $content = array(
139                                         'id'  => $id,
140                                         'url' => postRequestElement('url', $id),
141                                 );
142
143                                 // Load row template and switch colors
144                                 $OUT .= loadTemplate('admin_unlock_emails_redir_row', TRUE, $content);
145                         } // END - foreach
146
147                         // Load main template
148                         loadTemplate('admin_unlock_emails_redir', FALSE, $OUT);
149                 } else {
150                         // Nothing selected
151                         displayMessage('{--ADMIN_MAILS_NOTHING_CHECKED--}');
152                 }
153         } elseif ((isFormSent('lock')) && (ifPostContainsSelections()) && (isExtensionActive('blacklist')) && (isUrlBlacklistEnabled())) {
154                 // Lock URLs
155                 foreach (postRequestElement('sel') as $id => $url) {
156                         // Secure id number
157                         $id = bigintval($id);
158
159                         // Lookup in blacklist
160                         insertUrlInBlacklist($url);
161                 } // END - foreach
162
163                 // Output message
164                 displayMessage('{--ADMIN_URLS_BLOCKED--}');
165         } elseif ((!isFormSent('lock')) && (!isFormSent('accept')) && (!isFormSent('reject'))) {
166                 // Mail orders are in pool so we can display them
167                 $OUT = '';
168                 while ($content = sqlFetchArray($result_main)) {
169                         // Prepare data for the template
170                         $content['timestamp'] = generateDateTime($content['timestamp'], 2);
171
172                         // Load row template and switch colors
173                         $OUT .= loadTemplate('admin_unlock_emails_row', TRUE, $content);
174                 } // END - while
175
176                 // Free memory
177                 sqlFreeResult($result_main);
178
179                 // Remember in array
180                 $content['rows'] = $OUT;
181
182                 // Load main template
183                 loadTemplate('admin_unlock_emails', FALSE, $content);
184         } elseif ((isFormSent('lock')) && ((!isExtensionActive('blacklist')) || (!isUrlBlacklistEnabled()))) {
185                 // URL blacklist not activated
186                 displayMessage('{--ADMIN_URL_BLACKLIST_DISABLED--}');
187         } else {
188                 // Wrong call!
189                 displayMessage('{--ADMIN_WRONG_CALL--}');
190         }
191 } else {
192         // No mail orders fond
193         displayMessage('{--ADMIN_NO_MAILS_IN_POOL--}');
194 }
195
196 // [EOF]
197 ?>