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