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