23502f4ed31d66eb1a5c98ecc1bf70fc9138e105
[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 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.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         die();
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 ((isGetRequestParameterSet('bonusid')) && (isExtensionActive('bonus'))) {
56         // Display bonus mail by loading it's full data
57         $result_data = SQL_QUERY_ESC("SELECT
58         `id`,`subject`,`timestamp`,`cat_id`,`points`,`text`,`is_notify`,`data_type`,`time`,`url`
59 FROM
60         `{?_MYSQL_PREFIX?}_bonus`
61 WHERE
62         `id`=%s
63 LIMIT 1",
64                 array(bigintval(getRequestParameter('bonusid'))), __FILE__, __LINE__);
65
66         // Load data
67         $content = SQL_FETCHARRAY($result_data);
68
69         // Translate some data
70         $content['timestamp'] = generateDateTime($content['timestamp'], '2');
71         $content['userid'] = getMemberId();
72         $content['user_mail_status'] = '{%message,MEMBER_MAIL_BONUS_CONFIRMED_UNKNOWN=' . $content['id'] . '%}';
73
74         // Is ext-user active?
75         if (isExtensionActive('user')) {
76                 // Default is never confirmed
77                 $content['user_mail_status'] = '{%message,MEMBER_MAIL_BONUS_NEVER_CONFIRMED=' . $content['id'] . '%}';
78
79                 // Get the timestamp from the mail
80                 $confirmedStamp = getEpocheTimeFromUserStats('bonusid', $content['id']);
81
82                 // Have confirmed it?
83                 if ($confirmedStamp > 0) {
84                         // Get timestamp from insert
85                         $content['user_mail_status'] = '{%message,MEMBER_MAIL_BONUS_CONFIRMED_ON=' . generateDateTime($confirmedStamp, '2') . '%}';
86                 } // END - if
87         } // END - if
88
89         // Display it depending on mail (data) type
90         loadTemplate('member_mail_bonus_' . strtolower($content['data_type']), false, $content);
91
92         // Free result
93         SQL_FREERESULT($result_data);
94 } elseif (isGetRequestParameterSet('mailid')) {
95         // Display regular member mail by loading its full data
96         $result_data = SQL_QUERY_ESC("SELECT
97         s.id, s.subject, p.text, s.timestamp_ordered AS `timestamp`,
98         s.cat_id, pay.price AS `points`, p.sender, pay.time, p.data_type
99 FROM
100         `{?_MYSQL_PREFIX?}_user_stats` AS s
101 LEFT JOIN
102         `{?_MYSQL_PREFIX?}_pool` AS p
103 ON
104         s.pool_id=p.id
105 LEFT JOIN
106         `{?_MYSQL_PREFIX?}_payments` AS pay
107 ON
108         p.payment_id=pay.id
109 WHERE
110         s.id=%s
111 LIMIT 1",
112                 array(bigintval(getRequestParameter('mailid'))), __FILE__, __LINE__);
113
114         // Load data
115         $content = SQL_FETCHARRAY($result_data);
116
117         // Translate some data
118         $content['timestamp'] = generateDateTime($content['timestamp'], '2');
119         $content['userid'] = getMemberId();
120         $content['user_mail_status'] = '{%message,MEMBER_MAIL_NORMAL_CONFIRMED_UNKNOWN=' . $content['id'] . '%}';
121
122         // Is ext-user active?
123         if (isExtensionActive('user')) {
124                 // Default is never confirmed
125                 $content['user_mail_status'] = '{%message,MEMBER_MAIL_NORMAL_NEVER_CONFIRMED=' . $content['id'] . '%}';
126
127                 // Get the timestamp from the mail
128                 $confirmedStamp = getEpocheTimeFromUserStats('mailid', $content['id']);
129
130                 // Have confirmed it?
131                 if ($confirmedStamp > 0) {
132                         // Get timestamp from insert
133                         $content['user_mail_status'] = '{%message,MEMBER_MAIL_NORMAL_CONFIRMED_ON=' . generateDateTime($confirmedStamp, '2') . '%}';
134                 } // END - if
135         } // END - if
136
137         // Display it depending on mail (data) type
138         loadTemplate('member_mail_normal_' . strtolower($content['data_type']), false, $content);
139
140         // Free result
141         SQL_FREERESULT($result_data);
142 }
143
144 if (isExtensionActive('bonus')) {
145         // Load bonus id
146         $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",
147                 array(getMemberId()), __FILE__, __LINE__);
148 } else {
149         // Don't load bonus id if ext-bonus is not installed
150         $result = SQL_QUERY_ESC("SELECT `stats_id`,`link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s ORDER BY `stats_id` DESC",
151                 array(getMemberId()), __FILE__, __LINE__);
152 }
153
154 // Mails left for confirmation?
155 if (!SQL_HASZERONUMS($result)) {
156         // Please confirm these mails!
157         $sum = '0'; $OUT = '';
158
159         // Init content
160         $content = array();
161
162         // @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
163         while ($row = SQL_FETCHARRAY($result)) {
164                 // Load data from stats table...
165                 $cat = '';
166                 $result_data = false;
167                 $message = '{--MEMBER_GENERAL_MAIL_PROBLEM--}';
168                 $data = $row['stats_id'] . '/' . $row['bonus_id'] . '/' . $row['link_type'];
169                 switch ($row['link_type']) {
170                         case 'NORMAL':
171                                 $result_data = SQL_QUERY_ESC("SELECT
172         s.subject, s.timestamp_ordered, s.cat_id, s.payment_id, p.sender
173 FROM
174         `{?_MYSQL_PREFIX?}_user_stats` AS s
175 LEFT JOIN
176         `{?_MYSQL_PREFIX?}_pool` AS p
177 ON
178         s.pool_id=p.id
179 WHERE
180         s.id=%s
181 LIMIT 1",
182                                         array(bigintval($row['stats_id'])), __FILE__, __LINE__);
183                                 $row['link_type'] = 'mailid';
184                                 $data = $row['stats_id'];
185                                 $message = '{--NORMAL_MAIL_PROBLEM--}';
186                                 break;
187
188                         case 'BONUS':
189                                 $result_data = SQL_QUERY_ESC("SELECT `subject`,`timestamp`,`cat_id`,`points`, 0 FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
190                                         array(bigintval($row['bonus_id'])), __FILE__, __LINE__);
191                                 $row['link_type'] = 'bonusid';
192                                 $data = $row['bonus_id'];
193                                 $message = '{--BONUS_MAIL_PROBLEM--}';
194                                 break;
195
196                         default: // Unknown type detected!
197                                 debug_report_bug(__FILE__, __LINE__, sprintf("Unknown mail type %s detected.", $row['link_type']));
198                                 break;
199                 }
200
201                 // Data found to this mail?
202                 if ((SQL_NUMROWS($result_data) == 1) && (($row['link_type'] == 'mailid') || ($row['link_type'] == 'bonusid'))) {
203                         // Mail was found
204                         list($subject, $timestamp, $cat, $pay, $sender) = SQL_FETCHROW($result_data);
205
206                         // Subject line found?
207                         if (empty($subject)) {
208                                 // No subject line!
209                                 $subject = '{--DEFAULT_SUBJECT_LINE--}';
210                         } // END - if
211
212                         // Prepare sender id
213                         if ((isValidUserId($sender)) && ($row['link_type'] == 'mailid')) {
214                                 // Sender id
215                                 $sender = bigintval($sender);
216                         } elseif ($row['link_type'] == 'bonusid') {
217                                 // Is admin
218                                 $sender = '{--USERNAME_ADMIN_SHORT--}';
219                         } else {
220                                 // Deleted
221                                 $sender = '{--EMAIL_STATUS_DELETED--}';
222                         }
223
224                         // Prepare data for template
225                         $content = array(
226                                 'data'      => bigintval($data),
227                                 // @TODO This 'userid' cannot be saved because of encapsulated EL code
228                                 'userid'    => getMemberId(),
229                                 'link_type' => $row['link_type'],
230                                 'subject'   => $subject,
231                                 'sender'    => $sender,
232                                 'timestamp' => generateDateTime($timestamp, 2),
233                                 'points'    => $pay,
234                         );
235
236                         // Load row template
237                         if (getConfig('show_points_unconfirmed') == 'Y') {
238                                 $OUT .= loadTemplate('member_unconfirmed_row', true, $content);
239                         } else {
240                                 $OUT .= loadTemplate('member_unconfirmed_row_nopoints', true, $content);
241                         }
242
243                         // Count points
244                         $sum += $pay;
245                 } else {
246                         // Prepare data for template
247                         $content = array(
248                                 'data'    => $data,
249                                 'message' => $message,
250                         );
251
252                         // Display points or not?
253                         if (getConfig('show_points_unconfirmed') == 'Y') {
254                                 $OUT .= loadTemplate('member_unconfirmed_404', true, $content);
255                         } else {
256                                 $OUT .= loadTemplate('member_unconfirmed_404_nopoints', true, $content);
257                         }
258                 }
259
260                 // Free result
261                 SQL_FREERESULT($result_data);
262         } // END - while
263
264         // Free memory
265         SQL_FREERESULT($result);
266
267         // Remember total points
268         $content['total_points'] = $sum;
269
270         // Remember all generated rows in constant for the template
271         $content['rows'] = $OUT;
272
273         // Load main template
274         if (getConfig('show_points_unconfirmed') == 'Y') {
275                 loadTemplate('member_unconfirmed_table', false, $content);
276         } else {
277                 loadTemplate('member_unconfirmed_table_nopoints', false, $content);
278         }
279 } else {
280         // No mails left to confirm... :)
281         displayMessage('{--MEMBER_NO_MAILS_TO_CONFIRM--}');
282 }
283
284 // [EOF]
285 ?>