]> git.mxchange.org Git - mailer.git/blob - inc/modules/member/what-unconfirmed.php
d2fe6db28ba3467557ed849761b221e96b704b05
[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         `p`.`payment_id`,
112         `p`.`sender`,
113         `p`.`data_type`
114 FROM
115         `{?_MYSQL_PREFIX?}_user_stats` AS `s`
116 LEFT JOIN
117         `{?_MYSQL_PREFIX?}_pool` AS `p`
118 ON
119         s.pool_id=p.id
120 WHERE
121         `s`.`id`=%s
122 LIMIT 1",
123                 array(bigintval(getRequestElement('mailid'))), __FILE__, __LINE__);
124
125         // Load data
126         $content = SQL_FETCHARRAY($result_data);
127
128         // Get price/time to avoid one JOIN
129         $content['price'] = getPaymentPrice($content['payment_id']);
130         $content['time']  = getPaymentData($content['payment_id'], 'time');
131
132         // Translate some data
133         $content['timestamp'] = generateDateTime($content['timestamp'], '2');
134         $content['userid'] = getMemberId();
135         $content['user_mail_status'] = '{%message,MEMBER_MAIL_NORMAL_CONFIRMED_UNKNOWN=' . $content['id'] . '%}';
136
137         // Is ext-user active?
138         if (isExtensionActive('user')) {
139                 // Default is never confirmed
140                 $content['user_mail_status'] = '{%message,MEMBER_MAIL_NORMAL_NEVER_CONFIRMED=' . $content['id'] . '%}';
141
142                 // Get the timestamp from the mail
143                 $confirmedStamp = getEpocheTimeFromUserStats('mailid', $content['id']);
144
145                 // Have confirmed it?
146                 if ($confirmedStamp > 0) {
147                         // Get timestamp from insert
148                         $content['user_mail_status'] = '{%message,MEMBER_MAIL_NORMAL_CONFIRMED_ON=' . generateDateTime($confirmedStamp, '2') . '%}';
149                 } // END - if
150         } // END - if
151
152         // Display it depending on mail (data) type
153         loadTemplate('member_mail_normal_' . strtolower($content['data_type']), FALSE, $content);
154
155         // Free result
156         SQL_FREERESULT($result_data);
157 }
158
159 if (isExtensionActive('bonus')) {
160         // Load bonus id
161         $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",
162                 array(getMemberId()), __FILE__, __LINE__);
163 } else {
164         // Don't load bonus id if ext-bonus is not installed
165         $result = SQL_QUERY_ESC("SELECT `stats_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s ORDER BY `stats_id` DESC",
166                 array(getMemberId()), __FILE__, __LINE__);
167 }
168
169 // Mails left for confirmation?
170 if (!SQL_HASZERONUMS($result)) {
171         // Please confirm these mails!
172         $sum = '0'; $OUT = '';
173
174         // Init content
175         $content = array();
176
177         // @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
178         while ($row = SQL_FETCHARRAY($result)) {
179                 // Load data from stats table...
180                 $cat = '';
181                 $result_data = FALSE;
182                 $message = '{--MEMBER_GENERAL_MAIL_PROBLEM--}';
183                 $data = $row['stats_id'] . '/' . $row['bonus_id'] . '/' . $row['link_type'];
184                 switch ($row['link_type']) {
185                         case 'NORMAL':
186                                 $result_data = SQL_QUERY_ESC("SELECT
187         `s`.`subject`,
188         `s`.`timestamp_ordered` AS `timestamp`,
189         `s`.`cat_id`,
190         `s`.`payment_id`,
191         `p`.`sender`
192 FROM
193         `{?_MYSQL_PREFIX?}_user_stats` AS `s`
194 LEFT JOIN
195         `{?_MYSQL_PREFIX?}_pool` AS `p`
196 ON
197         `s`.`pool_id`=`p`.`id`
198 WHERE
199         `s`.`id`=%s
200 LIMIT 1",
201                                         array(bigintval($row['stats_id'])), __FILE__, __LINE__);
202                                 $row['link_type'] = 'mailid';
203                                 $data = $row['stats_id'];
204                                 $message = '{--NORMAL_MAIL_PROBLEM--}';
205                                 break;
206
207                         case 'BONUS':
208                                 $result_data = SQL_QUERY_ESC("SELECT `subject`, `timestamp`, `cat_id`, `points`, NULL FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
209                                         array(bigintval($row['bonus_id'])), __FILE__, __LINE__);
210                                 $row['link_type'] = 'bonusid';
211                                 $data = $row['bonus_id'];
212                                 $message = '{--BONUS_MAIL_PROBLEM--}';
213                                 break;
214
215                         default: // Unknown type detected!
216                                 reportBug(__FILE__, __LINE__, sprintf("Unknown mail type %s detected.", $row['link_type']));
217                                 break;
218                 } // END - switch
219
220                 // Data found to this mail?
221                 if ((SQL_NUMROWS($result_data) == 1) && (($row['link_type'] == 'mailid') || ($row['link_type'] == 'bonusid'))) {
222                         // Mail was found
223                         $rowData = SQL_FETCHARRAY($result_data);
224
225                         // Subject line found?
226                         if (empty($rowData['subject'])) {
227                                 // No subject line!
228                                 $rowData['subject'] = '{--DEFAULT_SUBJECT--}';
229                         } // END - if
230
231                         // Prepare sender id
232                         if ((isValidId($rowData['sender'])) && ($row['link_type'] == 'mailid')) {
233                                 // Sender id
234                                 $rowData['sender'] = bigintval($rowData['sender']);
235                         } elseif ($row['link_type'] == 'bonusid') {
236                                 // Is admin
237                                 $rowData['sender'] = '{--USERNAME_ADMIN_SHORT--}';
238                         } else {
239                                 // Deleted
240                                 $rowData['sender'] = '{--EMAIL_STATUS_DELETED--}';
241                         }
242
243                         // Prepare data for template
244                         // @TODO cat_id is unused
245                         $rowData = 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'           => $rowData['subject'],
251                                 'sender'            => $rowData['sender'],
252                                 'timestamp_ordered' => generateDateTime($rowData['timestamp_ordered'], 2),
253                                 'payment_id'        => $rowData['payment_id'],
254                         );
255
256                         // Load row template
257                         if (isShowPointsUnconfirmedEnabled()) {
258                                 $OUT .= loadTemplate('member_list_unconfirmed_row', TRUE, $rowData);
259                         } else {
260                                 $OUT .= loadTemplate('member_list_unconfirmed_nopoints_row', TRUE, $rowData);
261                         }
262
263                         // Count points (price)
264                         $sum += getPaymentPrice($rowData['payment_id']);
265                 } else {
266                         // Prepare data for template
267                         $rowData = 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, $rowData);
275                         } else {
276                                 $OUT .= loadTemplate('member_list_unconfirmed_nopoints_404_row', TRUE, $rowData);
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 ?>