Possible better fix
[mailer.git] / inc / modules / member / what-unconfirmed.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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  : Unbest&auml;tigte Mails                              *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 } elseif (!isMember()) {
43         redirectToIndexMemberOnlyModule();
44 } elseif ((!isExtensionActive('mailid')) && (!isAdmin())) {
45         redirectToUrl('modules.php?module=login');
46 }
47
48 // Add description as navigation point
49 addMenuDescription('member', __FILE__);
50
51 // Shall we display a mail?
52 if ((isGetRequestElementSet('bonusid')) && (isExtensionActive('bonus'))) {
53         // Display bonus mail by loading it's full data
54         $result_data = SQL_QUERY_ESC("SELECT
55         `id`, `subject`, `timestamp`, `cat_id`, `points`, `text`, `is_notify`, `data_type`, `time`, `url`
56 FROM
57         `{?_MYSQL_PREFIX?}_bonus`
58 WHERE
59         `id`=%s
60 LIMIT 1",
61                 array(bigintval(getRequestElement('bonusid'))), __FILE__, __LINE__);
62
63         // Load data
64         $content = SQL_FETCHARRAY($result_data);
65
66         // Translate some data
67         $content['timestamp'] = generateDateTime($content['timestamp'], 2);
68         $content['category']  = getCategory($content['cat_id']);
69         $content['points']    = translateComma($content['points']);
70         $content['is_notify'] = translateYesNo($content['is_notify']);
71         $content['sender']    = getMessage('_ADMIN_SHORT');
72         $content['time']      = createFancyTime($content['time']);
73         $content['userid']    = getUserId();
74
75         // Get timestamp from insert
76         $content['user_status'] = sprintf(getMessage('MEMBER_MAIL_BONUS_CONFIRMED_ON'),
77                 generateDateTime(getTimestampFromUserStats('bonusid', $content['id']), 2)
78         );
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 (isGetRequestElementSet(('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`, s.cat_id, pay.price AS points, p.sender, pay.time, p.data_type
89 FROM
90         `{?_MYSQL_PREFIX?}_user_stats` AS s
91 LEFT JOIN
92         `{?_MYSQL_PREFIX?}_pool` AS p
93 ON
94         s.pool_id=p.id
95 LEFT JOIN
96         `{?_MYSQL_PREFIX?}_payments` AS pay
97 ON
98         p.payment_id=pay.id
99 WHERE
100         s.id=%s
101 LIMIT 1",
102                 array(bigintval(getRequestElement('mailid'))), __FILE__, __LINE__);
103
104         // Load data
105         $content = SQL_FETCHARRAY($result_data);
106
107         // Translate some data
108         $content['timestamp'] = generateDateTime($content['timestamp'], 2);
109         $content['category']  = getCategory($content['cat_id']);
110         $content['points']    = translateComma($content['points']);
111         $content['time']      = createFancyTime($content['time']);
112         $content['userid']    = getUserId();
113
114         // Get timestamp from insert
115         $content['user_status'] = sprintf(getMessage('MEMBER_MAIL_NORMAL_CONFIRMED_ON'),
116                 generateDateTime(getTimestampFromUserStats('mailid', $content['id']), 2)
117         );
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(getUserId()), __FILE__, __LINE__);
130 } else {
131         // Don't load bonus ID
132         $result = SQL_QUERY_ESC("SELECT `stats_id`, `stats_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s ORDER BY `stats_id` DESC",
133                 array(getUserId()), __FILE__, __LINE__);
134 }
135
136 // Mails left for confirmation?
137 if (SQL_NUMROWS($result) > 0) {
138         // Please confirm these mails!
139         $sum = 0; $OUT = ''; $SW = 2;
140
141         // Init content
142         $content = array();
143
144         // @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
145         while (list($id, $id2, $type) = SQL_FETCHROW($result)) {
146                 // Load data from stats table...
147                 $cat = '';
148                 $result_data = false;
149                 $PROBLEM = '';
150                 $DATA = $content;
151                 switch ($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($id)), __FILE__, __LINE__);
165                                 $type = 'mailid';
166                                 $DATA = $id;
167                                 $PROBLEM = getMessage('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($id2)), __FILE__, __LINE__);
173                                 $type = 'bonusid';
174                                 $DATA = $id2;
175                                 $PROBLEM = getMessage('BONUS_MAIL_PROBLEM');
176                                 break;
177
178                         default: // Unknown type detected!
179                                 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown mail type %s detected.", $type));
180                                 break;
181                 }
182
183                 // Data found to this mail?
184                 if ((SQL_NUMROWS($result_data) == 1) && (($type == 'mailid') || ($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 = getMessage('DEFAULT_SUBJECT_LINE');
192                         } // END - if
193
194                         // Prepare sender id
195                         if (($sender > 0) && ($type == 'mailid')) {
196                                 // Sender id
197                                 $sender = bigintval($sender);
198                         } elseif ($type == 'bonusid') {
199                                 // Is admin
200                                 $sender = getMessage('_ADMIN_SHORT');
201                         } else {
202                                 // Deleted
203                                 $sender = getMessage('EMAIL_STATUS_DELETED');
204                         }
205
206                         // Prepare data for template
207                         $content = array(
208                                 'sw'      => $SW,
209                                 'userid'  => getUserId(),
210                                 'data'    => bigintval($DATA),
211                                 'type'    => $type,
212                                 'subject' => $subject,
213                                 'sender'  => $sender,
214                                 'stamp'   => generateDateTime($timestamp, 2),
215                                 'cat'     => getCategory($cat),
216                                 'points'  => translateComma($pay),
217                         );
218
219                         // Load row template
220                         if (getConfig('show_points_unconfirmed') == 'Y') {
221                                 $OUT .= loadTemplate('member_unconfirmed_row', true, $content);
222                         } else {
223                                 $OUT .= loadTemplate('member_unconfirmed_row_nopoints', true, $content);
224                         }
225
226                         // Count points
227                         $sum += $pay;
228                 } else {
229                         // Prepare data for template
230                         $content = array(
231                                 'sw'    => $SW,
232                                 'data'  => $DATA,
233                                 'probl' => $PROBLEM,
234                         );
235
236                         // Display points or not?
237                         if (getConfig('show_points_unconfirmed') == 'Y') {
238                                 $OUT .= loadTemplate('member_unconfirmed_404', true, $content);
239                         } else {
240                                 $OUT .= loadTemplate('member_unconfirmed_404_nopoints', true, $content);
241                         }
242                 }
243
244                 // Free result
245                 SQL_FREERESULT($result_data);
246
247                 // Switch color
248                 $SW = 3 - $SW;
249         } // END - while
250
251         // Free memory
252         SQL_FREERESULT($result);
253
254         // Remember total points
255         $content['total_points'] = translateComma($sum);
256
257         // Remember all generated rows in constant for the template
258         $content['rows'] = $OUT;
259
260         // Load main template
261         if (getConfig('show_points_unconfirmed') == 'Y') {
262                 loadTemplate('member_unconfirmed_table', false, $content);
263         } else {
264                 loadTemplate('member_unconfirmed_table_nopoints', false, $content);
265         }
266 } else {
267         // No mails left to confirm... :)
268         loadTemplate('admin_settings_saved', false, getMessage('MEMBER_NO_MAILS_TO_CONFIRM'));
269 }
270
271 // [EOF]
272 ?>