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