Even more rewrites/fixes from EL branch (please report any broken part after you...
[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  * 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  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42         die();
43 } elseif (!isMember()) {
44         redirectToIndexMemberOnlyModule();
45 }
46
47 // Add description as navigation point
48 addMenuDescription('member', __FILE__);
49
50 // Shall we display a mail?
51 if ((isGetRequestParameterSet('bonusid')) && (isExtensionActive('bonus'))) {
52         // Display bonus mail by loading it's full data
53         $result_data = SQL_QUERY_ESC("SELECT
54         `id`, `subject`, `timestamp`, `cat_id` AS `category`, `points`, `text`, `is_notify`, `data_type`, `time`, `url`
55 FROM
56         `{?_MYSQL_PREFIX?}_bonus`
57 WHERE
58         `id`=%s
59 LIMIT 1",
60                 array(bigintval(getRequestParameter('bonusid'))), __FILE__, __LINE__);
61
62         // Load data
63         $content = SQL_FETCHARRAY($result_data);
64
65         // Translate some data
66         $content['timestamp']   = generateDateTime($content['timestamp'], 2);
67         $content['userid']      = getMemberId();
68         $content['user_status'] = getMaskedMessage('MEMBER_MAIL_BONUS_CONFIRMED_UNKNOWN', $content['id']);
69
70         // Is ext-user installed?
71         if (isExtensionInstalled('user')) {
72                 // Get timestamp from insert
73                 $content['user_status'] = getMaskedMessage('MEMBER_MAIL_BONUS_CONFIRMED_ON',
74                         generateDateTime(getTimestampFromUserStats('bonusid', $content['id']), 2)
75                 );
76         } // END - if
77
78         // Display it depending on mail (data) type
79         loadTemplate('member_mail_bonus_'.strtolower($content['data_type']), false, $content);
80
81         // Free result
82         SQL_FREERESULT($result_data);
83 } elseif (isGetRequestParameterSet(('mailid'))) {
84         // Display regular member mail by loading its full data
85         $result_data = SQL_QUERY_ESC("SELECT
86         s.id, s.subject, p.text, s.timestamp_ordered AS `timestamp`, s.cat_id AS `category`, pay.price AS points, p.sender, pay.time, p.data_type
87 FROM
88         `{?_MYSQL_PREFIX?}_user_stats` AS s
89 LEFT JOIN
90         `{?_MYSQL_PREFIX?}_pool` AS p
91 ON
92         s.pool_id=p.id
93 LEFT JOIN
94         `{?_MYSQL_PREFIX?}_payments` AS pay
95 ON
96         p.payment_id=pay.id
97 WHERE
98         s.id=%s
99 LIMIT 1",
100                 array(bigintval(getRequestParameter('mailid'))), __FILE__, __LINE__);
101
102         // Load data
103         $content = SQL_FETCHARRAY($result_data);
104
105         // Translate some data
106         $content['timestamp']   = generateDateTime($content['timestamp'], 2);
107         $content['userid']      = getMemberId();
108         $content['user_status'] = getMaskedMessage('MEMBER_MAIL_NORMAL_CONFIRMED_UNKNOWN', $content['id']);
109
110         // Is ext-user installed?
111         if (isExtensionInstalled('user')) {
112                 // Get timestamp from insert
113                 $content['user_status'] = getMaskedMessage('MEMBER_MAIL_NORMAL_CONFIRMED_ON',
114                         generateDateTime(getTimestampFromUserStats('mailid', $content['id']), 2)
115                 );
116         } // END - if
117
118         // Display it depending on mail (data) type
119         loadTemplate('member_mail_normal_'.strtolower($content['data_type']), false, $content);
120
121         // Free result
122         SQL_FREERESULT($result_data);
123 }
124
125 if (isExtensionActive('bonus')) {
126         // Load bonus id
127         $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",
128                 array(getMemberId()), __FILE__, __LINE__);
129 } else {
130         // Don't load bonus id
131         $result = SQL_QUERY_ESC("SELECT `stats_id`, `stats_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s ORDER BY `stats_id` DESC",
132                 array(getMemberId()), __FILE__, __LINE__);
133 }
134
135 // Mails left for confirmation?
136 if (SQL_NUMROWS($result) > 0) {
137         // Please confirm these mails!
138         $sum = '0'; $OUT = ''; $SW = 2;
139
140         // Init content
141         $content = array();
142
143         // @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
144         while (list($id, $id2, $type) = SQL_FETCHROW($result)) {
145                 // Load data from stats table...
146                 $cat = '';
147                 $result_data = false;
148                 $PROBLEM = getMessage('MEMBER_GENERAL_MAIL_PROBLEM');
149                 $DATA = $id . '/' . $id2 . '/' . $type;
150                 switch ($type) {
151                         case 'NORMAL':
152                                 $result_data = SQL_QUERY_ESC("SELECT
153         s.subject, s.timestamp_ordered, s.cat_id, s.payment_id, p.sender
154 FROM
155         `{?_MYSQL_PREFIX?}_user_stats` AS s
156 LEFT JOIN
157         `{?_MYSQL_PREFIX?}_pool` AS p
158 ON
159         s.pool_id=p.id
160 WHERE
161         s.id=%s
162 LIMIT 1",
163                                         array(bigintval($id)), __FILE__, __LINE__);
164                                 $type = 'mailid';
165                                 $DATA = $id;
166                                 $PROBLEM = getMessage('NORMAL_MAIL_PROBLEM');
167                                 break;
168
169                         case 'BONUS':
170                                 $result_data = SQL_QUERY_ESC("SELECT subject, timestamp, cat_id, points, 0 FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
171                                         array(bigintval($id2)), __FILE__, __LINE__);
172                                 $type = 'bonusid';
173                                 $DATA = $id2;
174                                 $PROBLEM = getMessage('BONUS_MAIL_PROBLEM');
175                                 break;
176
177                         default: // Unknown type detected!
178                                 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown mail type %s detected.", $type));
179                                 break;
180                 }
181
182                 // Data found to this mail?
183                 if ((SQL_NUMROWS($result_data) == 1) && (($type == 'mailid') || ($type == 'bonusid'))) {
184                         // Mail was found!
185                         list($subject, $timestamp, $cat, $pay, $sender) = SQL_FETCHROW($result_data);
186
187                         // Subject line found?
188                         if (empty($subject)) {
189                                 // No subject line!
190                                 $subject = getMessage('DEFAULT_SUBJECT_LINE');
191                         } // END - if
192
193                         // Prepare sender id
194                         if (($sender > 0) && ($type == 'mailid')) {
195                                 // Sender id
196                                 $sender = bigintval($sender);
197                         } elseif ($type == 'bonusid') {
198                                 // Is admin
199                                 $sender = getMessage('USERNAME_ADMIN_SHORT');
200                         } else {
201                                 // Deleted
202                                 $sender = getMessage('EMAIL_STATUS_DELETED');
203                         }
204
205                         // Prepare data for template
206                         $content = array(
207                                 'sw'        => $SW,
208                                 'userid'    => getMemberId(),
209                                 'data'      => bigintval($DATA),
210                                 'type'      => $type,
211                                 'subject'   => $subject,
212                                 'sender'    => $sender,
213                                 'timestamp' => generateDateTime($timestamp, 2),
214                                 'points'    => $pay,
215                         );
216
217                         // Load row template
218                         if (getConfig('show_points_unconfirmed') == 'Y') {
219                                 $OUT .= loadTemplate('member_unconfirmed_row', true, $content);
220                         } else {
221                                 $OUT .= loadTemplate('member_unconfirmed_row_nopoints', true, $content);
222                         }
223
224                         // Count points
225                         $sum += $pay;
226                 } else {
227                         // Prepare data for template
228                         $content = array(
229                                 'sw'    => $SW,
230                                 'data'  => $DATA,
231                                 'probl' => $PROBLEM,
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
245                 // Switch color
246                 $SW = 3 - $SW;
247         } // END - while
248
249         // Free memory
250         SQL_FREERESULT($result);
251
252         // Remember total points
253         $content['total_points'] = $sum;
254
255         // Remember all generated rows in constant for the template
256         $content['rows'] = $OUT;
257
258         // Load main template
259         if (getConfig('show_points_unconfirmed') == 'Y') {
260                 loadTemplate('member_unconfirmed_table', false, $content);
261         } else {
262                 loadTemplate('member_unconfirmed_table_nopoints', false, $content);
263         }
264 } else {
265         // No mails left to confirm... :)
266         loadTemplate('admin_settings_saved', false, getMessage('MEMBER_NO_MAILS_TO_CONFIRM'));
267 }
268
269 // [EOF]
270 ?>