e12ea8eb2bf3e6f304506421adc780f1180dc7c5
[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  * 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`, `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['category']  = getCategory($content['cat_id']);
68         $content['points']    = translateComma($content['points']);
69         $content['is_notify'] = translateYesNo($content['is_notify']);
70         $content['sender']    = getMessage('USERNAME_ADMIN_SHORT');
71         $content['time']      = createFancyTime($content['time']);
72         $content['userid']    = getMemberId();
73
74         // Get timestamp from insert
75         $content['user_status'] = getMaskedMessage('MEMBER_MAIL_BONUS_CONFIRMED_ON',
76                 generateDateTime(getTimestampFromUserStats('bonusid', $content['id']), 2)
77         );
78
79         // Display it depending on mail (data) type
80         loadTemplate('member_mail_bonus_'.strtolower($content['data_type']), false, $content);
81
82         // Free result
83         SQL_FREERESULT($result_data);
84 } elseif (isGetRequestParameterSet(('mailid'))) {
85         // Display regular member mail by loading its full data
86         $result_data = SQL_QUERY_ESC("SELECT
87         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
88 FROM
89         `{?_MYSQL_PREFIX?}_user_stats` AS s
90 LEFT JOIN
91         `{?_MYSQL_PREFIX?}_pool` AS p
92 ON
93         s.pool_id=p.id
94 LEFT JOIN
95         `{?_MYSQL_PREFIX?}_payments` AS pay
96 ON
97         p.payment_id=pay.id
98 WHERE
99         s.id=%s
100 LIMIT 1",
101                 array(bigintval(getRequestParameter('mailid'))), __FILE__, __LINE__);
102
103         // Load data
104         $content = SQL_FETCHARRAY($result_data);
105
106         // Translate some data
107         $content['timestamp'] = generateDateTime($content['timestamp'], 2);
108         $content['category']  = getCategory($content['cat_id']);
109         $content['points']    = translateComma($content['points']);
110         $content['time']      = createFancyTime($content['time']);
111         $content['userid']    = getMemberId();
112
113         // Get timestamp from insert
114         $content['user_status'] = getMaskedMessage('MEMBER_MAIL_NORMAL_CONFIRMED_ON',
115                 generateDateTime(getTimestampFromUserStats('mailid', $content['id']), 2)
116         );
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                                 'cat'       => getCategory($cat),
215                                 'points'    => translateComma($pay),
216                         );
217
218                         // Load row template
219                         if (getConfig('show_points_unconfirmed') == 'Y') {
220                                 $OUT .= loadTemplate('member_unconfirmed_row', true, $content);
221                         } else {
222                                 $OUT .= loadTemplate('member_unconfirmed_row_nopoints', true, $content);
223                         }
224
225                         // Count points
226                         $sum += $pay;
227                 } else {
228                         // Prepare data for template
229                         $content = array(
230                                 'sw'    => $SW,
231                                 'data'  => $DATA,
232                                 'probl' => $PROBLEM,
233                         );
234
235                         // Display points or not?
236                         if (getConfig('show_points_unconfirmed') == 'Y') {
237                                 $OUT .= loadTemplate('member_unconfirmed_404', true, $content);
238                         } else {
239                                 $OUT .= loadTemplate('member_unconfirmed_404_nopoints', true, $content);
240                         }
241                 }
242
243                 // Free result
244                 SQL_FREERESULT($result_data);
245
246                 // Switch color
247                 $SW = 3 - $SW;
248         } // END - while
249
250         // Free memory
251         SQL_FREERESULT($result);
252
253         // Remember total points
254         $content['total_points'] = translateComma($sum);
255
256         // Remember all generated rows in constant for the template
257         $content['rows'] = $OUT;
258
259         // Load main template
260         if (getConfig('show_points_unconfirmed') == 'Y') {
261                 loadTemplate('member_unconfirmed_table', false, $content);
262         } else {
263                 loadTemplate('member_unconfirmed_table_nopoints', false, $content);
264         }
265 } else {
266         // No mails left to confirm... :)
267         loadTemplate('admin_settings_saved', false, getMessage('MEMBER_NO_MAILS_TO_CONFIRM'));
268 }
269
270 // [EOF]
271 ?>