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