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