bb59e8151c12e29adf10f5f97a6b02178467ad68
[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, 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_HASZERONUMS($result)) {
137         // Please confirm these mails!
138         $sum = '0'; $OUT = '';
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 = '{--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 = '{--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 = '{--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 = '{--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 = '{--USERNAME_ADMIN_SHORT--}';
200                         } else {
201                                 // Deleted
202                                 $sender = '{--EMAIL_STATUS_DELETED--}';
203                         }
204
205                         // Prepare data for template
206                         $content = array(
207                                 'data'      => bigintval($DATA),
208                                 'type'      => $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                                 'probl' => $PROBLEM,
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 ?>