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`,
111 pay.`price` AS `points`,
116 `{?_MYSQL_PREFIX?}_user_stats` AS `s`
118 `{?_MYSQL_PREFIX?}_pool` AS `p`
122 `{?_MYSQL_PREFIX?}_payments` AS `pay`
124 p.`payment_id`=pay.`id`
128 array(bigintval(getRequestElement('mailid'))), __FILE__, __LINE__);
131 $content = SQL_FETCHARRAY($result_data);
133 // Translate some data
134 $content['timestamp'] = generateDateTime($content['timestamp'], '2');
135 $content['userid'] = getMemberId();
136 $content['user_mail_status'] = '{%message,MEMBER_MAIL_NORMAL_CONFIRMED_UNKNOWN=' . $content['id'] . '%}';
138 // Is ext-user active?
139 if (isExtensionActive('user')) {
140 // Default is never confirmed
141 $content['user_mail_status'] = '{%message,MEMBER_MAIL_NORMAL_NEVER_CONFIRMED=' . $content['id'] . '%}';
143 // Get the timestamp from the mail
144 $confirmedStamp = getEpocheTimeFromUserStats('mailid', $content['id']);
146 // Have confirmed it?
147 if ($confirmedStamp > 0) {
148 // Get timestamp from insert
149 $content['user_mail_status'] = '{%message,MEMBER_MAIL_NORMAL_CONFIRMED_ON=' . generateDateTime($confirmedStamp, '2') . '%}';
153 // Display it depending on mail (data) type
154 loadTemplate('member_mail_normal_' . strtolower($content['data_type']), FALSE, $content);
157 SQL_FREERESULT($result_data);
160 if (isExtensionActive('bonus')) {
162 $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",
163 array(getMemberId()), __FILE__, __LINE__);
165 // Don't load bonus id if ext-bonus is not installed
166 $result = SQL_QUERY_ESC("SELECT `stats_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s ORDER BY `stats_id` DESC",
167 array(getMemberId()), __FILE__, __LINE__);
170 // Mails left for confirmation?
171 if (!SQL_HASZERONUMS($result)) {
172 // Please confirm these mails!
173 $sum = '0'; $OUT = '';
178 // @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
179 while ($row = SQL_FETCHARRAY($result)) {
180 // Load data from stats table...
182 $result_data = FALSE;
183 $message = '{--MEMBER_GENERAL_MAIL_PROBLEM--}';
184 $data = $row['stats_id'] . '/' . $row['bonus_id'] . '/' . $row['link_type'];
185 switch ($row['link_type']) {
187 $result_data = SQL_QUERY_ESC("SELECT
189 s.`timestamp_ordered` AS `timestamp`,
194 `{?_MYSQL_PREFIX?}_user_stats` AS `s`
196 `{?_MYSQL_PREFIX?}_pool` AS `p`
202 array(bigintval($row['stats_id'])), __FILE__, __LINE__);
203 $row['link_type'] = 'mailid';
204 $data = $row['stats_id'];
205 $message = '{--NORMAL_MAIL_PROBLEM--}';
209 $result_data = SQL_QUERY_ESC("SELECT `subject`, `timestamp`, `cat_id`, `points`, NULL FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
210 array(bigintval($row['bonus_id'])), __FILE__, __LINE__);
211 $row['link_type'] = 'bonusid';
212 $data = $row['bonus_id'];
213 $message = '{--BONUS_MAIL_PROBLEM--}';
216 default: // Unknown type detected!
217 reportBug(__FILE__, __LINE__, sprintf("Unknown mail type %s detected.", $row['link_type']));
221 // Data found to this mail?
222 if ((SQL_NUMROWS($result_data) == 1) && (($row['link_type'] == 'mailid') || ($row['link_type'] == 'bonusid'))) {
224 list($subject, $timestamp, $cat, $pay, $sender) = SQL_FETCHROW($result_data);
226 // Subject line found?
227 if (empty($subject)) {
229 $subject = '{--DEFAULT_SUBJECT--}';
233 if ((isValidUserId($sender)) && ($row['link_type'] == 'mailid')) {
235 $sender = bigintval($sender);
236 } elseif ($row['link_type'] == 'bonusid') {
238 $sender = '{--USERNAME_ADMIN_SHORT--}';
241 $sender = '{--EMAIL_STATUS_DELETED--}';
244 // Prepare data for template
246 'data' => bigintval($data),
247 // @TODO This 'userid' cannot be saved because of encapsulated EL code
248 'userid' => getMemberId(),
249 'link_type' => $row['link_type'],
250 'subject' => $subject,
252 'timestamp' => generateDateTime($timestamp, 2),
257 if (getConfig('show_points_unconfirmed') == 'Y') {
258 $OUT .= loadTemplate('member_unconfirmed_row', TRUE, $content);
260 $OUT .= loadTemplate('member_unconfirmed_row_nopoints', TRUE, $content);
266 // Prepare data for template
269 'message' => $message,
272 // Display points or not?
273 if (getConfig('show_points_unconfirmed') == 'Y') {
274 $OUT .= loadTemplate('member_unconfirmed_404', TRUE, $content);
276 $OUT .= loadTemplate('member_unconfirmed_404_nopoints', TRUE, $content);
281 SQL_FREERESULT($result_data);
285 SQL_FREERESULT($result);
287 // Remember total points
288 $content['total_points'] = $sum;
290 // Remember all generated rows in constant for the template
291 $content['rows'] = $OUT;
293 // Load main template
294 if (getConfig('show_points_unconfirmed') == 'Y') {
295 loadTemplate('member_unconfirmed_table', FALSE, $content);
297 loadTemplate('member_unconfirmed_table_nopoints', FALSE, $content);
300 // No mails left to confirm... :)
301 displayMessage('{--MEMBER_NO_MAILS_TO_CONFIRM--}');