f64ae4ce2fe8c0fe80dd6bdfc2bb952b0cdd0127
[mailer.git] / inc / modules / member / what-unconfirmed.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 10/19/2003 *
4  * ===================                          Last change: 07/13/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-unconfirmed.php                             *
8  * -------------------------------------------------------------------- *
9  * Short description : Unconfirmed mails                                *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Unbestaetigte Mails                              *
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 - 2012 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')) {
40         exit();
41 } elseif (!isMember()) {
42         redirectToIndexMemberOnlyModule();
43 }
44
45 // Add description as navigation point
46 addYouAreHereLink('member', __FILE__);
47
48 // Essential extension ext-mailid must be active
49 if (!isExtensionActive('mailid')) {
50         displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=mailid%}');
51         return;
52 } // END - if
53
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
58         `id`,
59         `subject`,
60         `timestamp`,
61         `cat_id`,
62         `points`,
63         `text`,
64         `is_notify`,
65         `data_type`,
66         `time`,
67         `url`
68 FROM
69         `{?_MYSQL_PREFIX?}_bonus`
70 WHERE
71         `id`=%s
72 LIMIT 1',
73                 array(bigintval(getRequestElement('bonusid'))), __FILE__, __LINE__);
74
75         // Load data
76         $content = SQL_FETCHARRAY($result_data);
77
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'] . '%}';
82
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'] . '%}';
87
88                 // Get the timestamp from the mail
89                 $confirmedStamp = getEpocheTimeFromUserStats('bonusid', $content['id']);
90
91                 // Have confirmed it?
92                 if ($confirmedStamp > 0) {
93                         // Get timestamp from insert
94                         $content['user_mail_status'] = '{%message,MEMBER_MAIL_BONUS_CONFIRMED_ON=' . generateDateTime($confirmedStamp, '2') . '%}';
95                 } // END - if
96         } // END - if
97
98         // Display it depending on mail (data) type
99         loadTemplate('member_mail_bonus_' . strtolower($content['data_type']), FALSE, $content);
100
101         // Free result
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
106         s.`id`,
107         s.`subject`,
108         `p`.`text`,
109         s.`timestamp_ordered` AS `timestamp`,
110         s.`cat_id`,
111         pay.`price` AS `points`,
112         `p`.`sender`,
113         pay.`time`,
114         `p`.`data_type`
115 FROM
116         `{?_MYSQL_PREFIX?}_user_stats` AS `s`
117 LEFT JOIN
118         `{?_MYSQL_PREFIX?}_pool` AS `p`
119 ON
120         s.pool_id=p.id
121 LEFT JOIN
122         `{?_MYSQL_PREFIX?}_payments` AS `pay`
123 ON
124         `p`.`payment_id`=pay.`id`
125 WHERE
126         s.`id`=%s
127 LIMIT 1",
128                 array(bigintval(getRequestElement('mailid'))), __FILE__, __LINE__);
129
130         // Load data
131         $content = SQL_FETCHARRAY($result_data);
132
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'] . '%}';
137
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'] . '%}';
142
143                 // Get the timestamp from the mail
144                 $confirmedStamp = getEpocheTimeFromUserStats('mailid', $content['id']);
145
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') . '%}';
150                 } // END - if
151         } // END - if
152
153         // Display it depending on mail (data) type
154         loadTemplate('member_mail_normal_' . strtolower($content['data_type']), FALSE, $content);
155
156         // Free result
157         SQL_FREERESULT($result_data);
158 }
159
160 if (isExtensionActive('bonus')) {
161         // Load bonus id
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__);
164 } else {
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__);
168 }
169
170 // Mails left for confirmation?
171 if (!SQL_HASZERONUMS($result)) {
172         // Please confirm these mails!
173         $sum = '0'; $OUT = '';
174
175         // Init content
176         $content = array();
177
178         // @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
179         while ($row = SQL_FETCHARRAY($result)) {
180                 // Load data from stats table...
181                 $cat = '';
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']) {
186                         case 'NORMAL':
187                                 $result_data = SQL_QUERY_ESC("SELECT
188         s.`subject`,
189         s.`timestamp_ordered` AS `timestamp`,
190         s.`cat_id`,
191         s.`payment_id`,
192         `p`.`sender`
193 FROM
194         `{?_MYSQL_PREFIX?}_user_stats` AS `s`
195 LEFT JOIN
196         `{?_MYSQL_PREFIX?}_pool` AS `p`
197 ON
198         s.`pool_id`=`p`.`id`
199 WHERE
200         s.`id`=%s
201 LIMIT 1",
202                                         array(bigintval($row['stats_id'])), __FILE__, __LINE__);
203                                 $row['link_type'] = 'mailid';
204                                 $data = $row['stats_id'];
205                                 $message = '{--NORMAL_MAIL_PROBLEM--}';
206                                 break;
207
208                         case 'BONUS':
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--}';
214                                 break;
215
216                         default: // Unknown type detected!
217                                 reportBug(__FILE__, __LINE__, sprintf("Unknown mail type %s detected.", $row['link_type']));
218                                 break;
219                 } // END - switch
220
221                 // Data found to this mail?
222                 if ((SQL_NUMROWS($result_data) == 1) && (($row['link_type'] == 'mailid') || ($row['link_type'] == 'bonusid'))) {
223                         // Mail was found
224                         list($subject, $timestamp, $cat, $pay, $sender) = SQL_FETCHROW($result_data);
225
226                         // Subject line found?
227                         if (empty($subject)) {
228                                 // No subject line!
229                                 $subject = '{--DEFAULT_SUBJECT--}';
230                         } // END - if
231
232                         // Prepare sender id
233                         if ((isValidId($sender)) && ($row['link_type'] == 'mailid')) {
234                                 // Sender id
235                                 $sender = bigintval($sender);
236                         } elseif ($row['link_type'] == 'bonusid') {
237                                 // Is admin
238                                 $sender = '{--USERNAME_ADMIN_SHORT--}';
239                         } else {
240                                 // Deleted
241                                 $sender = '{--EMAIL_STATUS_DELETED--}';
242                         }
243
244                         // Prepare data for template
245                         $content = array(
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,
251                                 'sender'    => $sender,
252                                 'timestamp' => generateDateTime($timestamp, 2),
253                                 'points'    => $pay,
254                         );
255
256                         // Load row template
257                         if (isShowPointsUnconfirmedEnabled()) {
258                                 $OUT .= loadTemplate('member_list_unconfirmed_row', TRUE, $content);
259                         } else {
260                                 $OUT .= loadTemplate('member_list_unconfirmed_nopoints_row', TRUE, $content);
261                         }
262
263                         // Count points
264                         $sum += $pay;
265                 } else {
266                         // Prepare data for template
267                         $content = array(
268                                 'data'    => $data,
269                                 'message' => $message,
270                         );
271
272                         // Display points or not?
273                         if (isShowPointsUnconfirmedEnabled()) {
274                                 $OUT .= loadTemplate('member_list_unconfirmed_404_row', TRUE, $content);
275                         } else {
276                                 $OUT .= loadTemplate('member_list_unconfirmed_nopoints_404_row', TRUE, $content);
277                         }
278                 }
279
280                 // Free result
281                 SQL_FREERESULT($result_data);
282         } // END - while
283
284         // Free memory
285         SQL_FREERESULT($result);
286
287         // Remember total points
288         $content['total_points'] = $sum;
289
290         // Remember all generated rows in constant for the template
291         $content['rows'] = $OUT;
292
293         // Load main template
294         if (isShowPointsUnconfirmedEnabled()) {
295                 loadTemplate('member_list_unconfirmed', FALSE, $content);
296         } else {
297                 loadTemplate('member_list_unconfirmed_nopoints', FALSE, $content);
298         }
299 } else {
300         // No mails left to confirm... :)
301         displayMessage('{--MEMBER_NO_MAILS_TO_CONFIRM--}');
302 }
303
304 // [EOF]
305 ?>