2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 10/19/2003 *
4 * =================== Last change: 07/13/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-unconfirmed.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Unconfirmed mails *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Unbestaetigte Mails *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2012 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
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. *
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. *
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, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
41 } elseif (!isMember()) {
42 redirectToIndexMemberOnlyModule();
45 // Add description as navigation point
46 addYouAreHereLink('member', __FILE__);
48 // Essential extension ext-mailid must be active
49 if (!isExtensionActive('mailid')) {
50 displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=mailid%}');
54 // Shall we display a mail?
55 if ((isGetRequestElementSet('bonusid')) && (isExtensionActive('bonus'))) {
56 // Display bonus mail by loading it's full data
57 $result_data = SQL_QUERY_ESC('SELECT
69 `{?_MYSQL_PREFIX?}_bonus`
73 array(bigintval(getRequestElement('bonusid'))), __FILE__, __LINE__);
76 $content = SQL_FETCHARRAY($result_data);
78 // Translate some data
79 $content['timestamp'] = generateDateTime($content['timestamp'], '2');
80 $content['userid'] = getMemberId();
81 $content['user_mail_status'] = '{%message,MEMBER_MAIL_BONUS_CONFIRMED_UNKNOWN=' . $content['id'] . '%}';
83 // Is ext-user active?
84 if (isExtensionActive('user')) {
85 // Default is never confirmed
86 $content['user_mail_status'] = '{%message,MEMBER_MAIL_BONUS_NEVER_CONFIRMED=' . $content['id'] . '%}';
88 // Get the timestamp from the mail
89 $confirmedStamp = getEpocheTimeFromUserStats('bonusid', $content['id']);
92 if ($confirmedStamp > 0) {
93 // Get timestamp from insert
94 $content['user_mail_status'] = '{%message,MEMBER_MAIL_BONUS_CONFIRMED_ON=' . generateDateTime($confirmedStamp, '2') . '%}';
98 // Display it depending on mail (data) type
99 loadTemplate('member_mail_bonus_' . strtolower($content['data_type']), FALSE, $content);
102 SQL_FREERESULT($result_data);
103 } elseif (isGetRequestElementSet('mailid')) {
104 // Display regular member mail by loading its full data
105 $result_data = SQL_QUERY_ESC("SELECT
109 `s`.`timestamp_ordered` AS `timestamp`,
115 `{?_MYSQL_PREFIX?}_user_stats` AS `s`
117 `{?_MYSQL_PREFIX?}_pool` AS `p`
123 array(bigintval(getRequestElement('mailid'))), __FILE__, __LINE__);
126 $content = SQL_FETCHARRAY($result_data);
128 // Translate some data
129 $content['timestamp'] = generateDateTime($content['timestamp'], '2');
130 // @TODO This call cannot be saved as EL code cannot be "framed" in other EL code
131 $content['userid'] = getMemberId();
132 $content['user_mail_status'] = '{%message,MEMBER_MAIL_NORMAL_CONFIRMED_UNKNOWN=' . $content['id'] . '%}';
134 // Is ext-user active?
135 if (isExtensionActive('user')) {
136 // Default is never confirmed
137 $content['user_mail_status'] = '{%message,MEMBER_MAIL_NORMAL_NEVER_CONFIRMED=' . $content['id'] . '%}';
139 // Get the timestamp from the mail
140 $confirmedStamp = getEpocheTimeFromUserStats('mailid', $content['id']);
142 // Have confirmed it?
143 if ($confirmedStamp > 0) {
144 // Get timestamp from insert
145 $content['user_mail_status'] = '{%message,MEMBER_MAIL_NORMAL_CONFIRMED_ON=' . generateDateTime($confirmedStamp, '2') . '%}';
149 // Display it depending on mail (data) type
150 loadTemplate('member_mail_normal_' . strtolower($content['data_type']), FALSE, $content);
153 SQL_FREERESULT($result_data);
156 if (isExtensionActive('bonus')) {
158 $result = SQL_QUERY_ESC("SELECT `stats_id`, `bonus_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s ORDER BY `bonus_id` DESC, stats_id DESC",
159 array(getMemberId()), __FILE__, __LINE__);
161 // Don't load bonus id if ext-bonus is not installed
162 $result = SQL_QUERY_ESC("SELECT `stats_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s ORDER BY `stats_id` DESC",
163 array(getMemberId()), __FILE__, __LINE__);
166 // Mails left for confirmation?
167 if (!SQL_HASZERONUMS($result)) {
168 // Please confirm these mails!
169 $sum = '0'; $OUT = '';
174 // @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
175 while ($row = SQL_FETCHARRAY($result)) {
176 // Load data from stats table...
178 $result_data = FALSE;
179 $message = '{--MEMBER_GENERAL_MAIL_PROBLEM--}';
180 $data = $row['stats_id'] . '/' . $row['bonus_id'] . '/' . $row['link_type'];
181 switch ($row['link_type']) {
183 $result_data = SQL_QUERY_ESC("SELECT
185 `s`.`timestamp_ordered` AS `timestamp`,
190 `{?_MYSQL_PREFIX?}_user_stats` AS `s`
192 `{?_MYSQL_PREFIX?}_pool` AS `p`
194 `s`.`pool_id`=`p`.`id`
198 array(bigintval($row['stats_id'])), __FILE__, __LINE__);
199 $row['link_type'] = 'mailid';
200 $data = $row['stats_id'];
201 $message = '{--NORMAL_MAIL_PROBLEM--}';
205 $result_data = SQL_QUERY_ESC("SELECT `subject`, `timestamp`, `cat_id`, `points`, NULL FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
206 array(bigintval($row['bonus_id'])), __FILE__, __LINE__);
207 $row['link_type'] = 'bonusid';
208 $data = $row['bonus_id'];
209 $message = '{--BONUS_MAIL_PROBLEM--}';
212 default: // Unknown type detected!
213 reportBug(__FILE__, __LINE__, sprintf("Unknown mail type %s detected.", $row['link_type']));
217 // Data found to this mail?
218 if ((SQL_NUMROWS($result_data) == 1) && (($row['link_type'] == 'mailid') || ($row['link_type'] == 'bonusid'))) {
220 $rowData = SQL_FETCHARRAY($result_data);
222 // Subject line found?
223 if (empty($rowData['subject'])) {
225 $rowData['subject'] = '{--DEFAULT_SUBJECT--}';
229 if ((isValidId($rowData['sender'])) && ($row['link_type'] == 'mailid')) {
231 $rowData['sender'] = bigintval($rowData['sender']);
232 } elseif ($row['link_type'] == 'bonusid') {
234 $rowData['sender'] = '{--USERNAME_ADMIN_SHORT--}';
237 $rowData['sender'] = '{--EMAIL_STATUS_DELETED--}';
240 // Prepare data for template
241 // @TODO cat_id is unused
243 'data' => bigintval($data),
244 // @TODO This 'userid' cannot be saved because of encapsulated EL code
245 'userid' => getMemberId(),
246 'link_type' => $row['link_type'],
247 'subject' => $rowData['subject'],
248 'sender' => $rowData['sender'],
249 'timestamp_ordered' => generateDateTime($rowData['timestamp_ordered'], 2),
250 'payment_id' => $rowData['payment_id'],
254 if (isShowPointsUnconfirmedEnabled()) {
255 $OUT .= loadTemplate('member_list_unconfirmed_row', TRUE, $rowData);
257 $OUT .= loadTemplate('member_list_unconfirmed_nopoints_row', TRUE, $rowData);
260 // Count points (price)
261 $sum += getPaymentPrice($rowData['payment_id']);
263 // Prepare data for template
266 'message' => $message,
269 // Display points or not?
270 if (isShowPointsUnconfirmedEnabled()) {
271 $OUT .= loadTemplate('member_list_unconfirmed_404_row', TRUE, $rowData);
273 $OUT .= loadTemplate('member_list_unconfirmed_nopoints_404_row', TRUE, $rowData);
278 SQL_FREERESULT($result_data);
282 SQL_FREERESULT($result);
284 // Remember total points
285 $content['total_points'] = $sum;
287 // Remember all generated rows in constant for the template
288 $content['rows'] = $OUT;
290 // Load main template
291 if (isShowPointsUnconfirmedEnabled()) {
292 loadTemplate('member_list_unconfirmed', FALSE, $content);
294 loadTemplate('member_list_unconfirmed_nopoints', FALSE, $content);
297 // No mails left to confirm... :)
298 displayMessage('{--MEMBER_NO_MAILS_TO_CONFIRM--}');