fooRequestElementBar() functions renamed, adding of request parameters added:
[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  : 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 }
45
46 // Add description as navigation point
47 addMenuDescription('member', __FILE__);
48
49 // Shall we display a mail?
50 if ((isGetRequestParameterSet('bonusid')) && (isExtensionActive('bonus'))) {
51         // Display bonus mail by loading it's full data
52         $result_data = SQL_QUERY_ESC("SELECT
53         `id`, `subject`, `timestamp`, `cat_id`, `points`, `text`, `is_notify`, `data_type`, `time`, `url`
54 FROM
55         `{?_MYSQL_PREFIX?}_bonus`
56 WHERE
57         `id`=%s
58 LIMIT 1",
59                 array(bigintval(getRequestParameter('bonusid'))), __FILE__, __LINE__);
60
61         // Load data
62         $content = SQL_FETCHARRAY($result_data);
63
64         // Translate some data
65         $content['timestamp'] = generateDateTime($content['timestamp'], 2);
66         $content['category']  = getCategory($content['cat_id']);
67         $content['points']    = translateComma($content['points']);
68         $content['is_notify'] = translateYesNo($content['is_notify']);
69         $content['sender']    = getMessage('USERNAME_ADMIN_SHORT');
70         $content['time']      = createFancyTime($content['time']);
71         $content['userid']    = getMemberId();
72
73         // Get timestamp from insert
74         $content['user_status'] = getMaskedMessage('MEMBER_MAIL_BONUS_CONFIRMED_ON',
75                 generateDateTime(getTimestampFromUserStats('bonusid', $content['id']), 2)
76         );
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, 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['category']  = getCategory($content['cat_id']);
108         $content['points']    = translateComma($content['points']);
109         $content['time']      = createFancyTime($content['time']);
110         $content['userid']    = getMemberId();
111
112         // Get timestamp from insert
113         $content['user_status'] = getMaskedMessage('MEMBER_MAIL_NORMAL_CONFIRMED_ON',
114                 generateDateTime(getTimestampFromUserStats('mailid', $content['id']), 2)
115         );
116
117         // Display it depending on mail (data) type
118         loadTemplate('member_mail_normal_'.strtolower($content['data_type']), false, $content);
119
120         // Free result
121         SQL_FREERESULT($result_data);
122 }
123
124 if (isExtensionActive('bonus')) {
125         // Load bonus id
126         $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",
127                 array(getMemberId()), __FILE__, __LINE__);
128 } else {
129         // Don't load bonus id
130         $result = SQL_QUERY_ESC("SELECT `stats_id`, `stats_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s ORDER BY `stats_id` DESC",
131                 array(getMemberId()), __FILE__, __LINE__);
132 }
133
134 // Mails left for confirmation?
135 if (SQL_NUMROWS($result) > 0) {
136         // Please confirm these mails!
137         $sum = '0'; $OUT = ''; $SW = 2;
138
139         // Init content
140         $content = array();
141
142         // @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
143         while (list($id, $id2, $type) = SQL_FETCHROW($result)) {
144                 // Load data from stats table...
145                 $cat = '';
146                 $result_data = false;
147                 $PROBLEM = getMessage('MEMBER_GENERAL_MAIL_PROBLEM');
148                 $DATA = $id . '/' . $id2 . '/' . $type;
149                 switch ($type) {
150                         case 'NORMAL':
151                                 $result_data = SQL_QUERY_ESC("SELECT
152         s.subject, s.timestamp_ordered, s.cat_id, s.payment_id, p.sender
153 FROM
154         `{?_MYSQL_PREFIX?}_user_stats` AS s
155 LEFT JOIN
156         `{?_MYSQL_PREFIX?}_pool` AS p
157 ON
158         s.pool_id=p.id
159 WHERE
160         s.id=%s
161 LIMIT 1",
162                                         array(bigintval($id)), __FILE__, __LINE__);
163                                 $type = 'mailid';
164                                 $DATA = $id;
165                                 $PROBLEM = getMessage('NORMAL_MAIL_PROBLEM');
166                                 break;
167
168                         case 'BONUS':
169                                 $result_data = SQL_QUERY_ESC("SELECT subject, timestamp, cat_id, points, 0 FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
170                                         array(bigintval($id2)), __FILE__, __LINE__);
171                                 $type = 'bonusid';
172                                 $DATA = $id2;
173                                 $PROBLEM = getMessage('BONUS_MAIL_PROBLEM');
174                                 break;
175
176                         default: // Unknown type detected!
177                                 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown mail type %s detected.", $type));
178                                 break;
179                 }
180
181                 // Data found to this mail?
182                 if ((SQL_NUMROWS($result_data) == 1) && (($type == 'mailid') || ($type == 'bonusid'))) {
183                         // Mail was found!
184                         list($subject, $timestamp, $cat, $pay, $sender) = SQL_FETCHROW($result_data);
185
186                         // Subject line found?
187                         if (empty($subject)) {
188                                 // No subject line!
189                                 $subject = getMessage('DEFAULT_SUBJECT_LINE');
190                         } // END - if
191
192                         // Prepare sender id
193                         if (($sender > 0) && ($type == 'mailid')) {
194                                 // Sender id
195                                 $sender = bigintval($sender);
196                         } elseif ($type == 'bonusid') {
197                                 // Is admin
198                                 $sender = getMessage('USERNAME_ADMIN_SHORT');
199                         } else {
200                                 // Deleted
201                                 $sender = getMessage('EMAIL_STATUS_DELETED');
202                         }
203
204                         // Prepare data for template
205                         $content = array(
206                                 'sw'        => $SW,
207                                 'userid'    => getMemberId(),
208                                 'data'      => bigintval($DATA),
209                                 'type'      => $type,
210                                 'subject'   => $subject,
211                                 'sender'    => $sender,
212                                 'timestamp' => generateDateTime($timestamp, 2),
213                                 'cat'       => getCategory($cat),
214                                 'points'    => translateComma($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'] = translateComma($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 ?>