A lot double-quotes rewritten to single-quotes, some redirect URLs fixed
[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  : 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 - 2008 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         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 } elseif (!IS_MEMBER()) {
44         LOAD_URL('modules.php?module=index');
45 } elseif ((!EXT_IS_ACTIVE('mailid')) && (!IS_ADMIN())) {
46         LOAD_URL("modules.php?module=login");
47 }
48
49 // Add description as navigation point
50 ADD_DESCR('member', __FILE__);
51
52 // Shall we display a mail?
53 if ((REQUEST_ISSET_GET(('bonusid'))) && (EXT_IS_ACTIVE('bonus'))) {
54         // Display bonus mail by loading it's full data
55         $result_data = SQL_QUERY_ESC("SELECT id, subject, timestamp, cat_id, points, text, is_notify, data_type, time, url
56 FROM `{!_MYSQL_PREFIX!}_bonus`
57 WHERE id=%s LIMIT 1",
58                 array(bigintval(REQUEST_GET('bonusid'))), __FILE__, __LINE__);
59
60         // Load data
61         $content = SQL_FETCHARRAY($result_data);
62
63         // "Translate some data
64         $content['subject']   = COMPILE_CODE($content['subject']);
65         $content['text']      = COMPILE_CODE($content['text']);
66         $content['timestamp'] = MAKE_DATETIME($content['timestamp'], "2");
67         $content['category']  = GET_CATEGORY($content['cat_id']);
68         $content['points']    = TRANSLATE_COMMA($content['points']);
69         $content['is_notify'] = TRANSLATE_YESNO($content['is_notify']);
70         $content['sender']    = _ADMIN_SHORT;
71         $content['time']      = CREATE_FANCY_TIME($content['time']);
72         $content['uid']       = getUserId();
73
74         // Get timestamp from insert
75         $content['user_status'] = sprintf(getMessage('MEMBER_MAIL_BONUS_CONFIRMED_ON'),
76                 MAKE_DATETIME(USER_STATS_GET_TIMESTAMP('bonusid', $content['id']), "2")
77         );
78
79         // Display it depending on mail (data) type
80         LOAD_TEMPLATE("member_mail_bonus_".strtolower($content['data_type']), false, $content);
81
82         // Free result
83         SQL_FREERESULT($result_data);
84 } elseif (REQUEST_ISSET_GET(('mailid'))) {
85         // Display regular member mail by loading its full data
86         $result_data = SQL_QUERY_ESC("SELECT 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 `{!_MYSQL_PREFIX!}_user_stats` AS s
88 LEFT JOIN `{!_MYSQL_PREFIX!}_pool` AS p
89 ON s.pool_id=p.id
90 LEFT JOIN `{!_MYSQL_PREFIX!}_payments` AS pay
91 ON p.payment_id=pay.id
92 WHERE s.id=%s LIMIT 1",
93                 array(bigintval(REQUEST_GET('mailid'))), __FILE__, __LINE__);
94
95         // Load data
96         $content = SQL_FETCHARRAY($result_data);
97
98         // "Translate some data
99         $content['subject']   = COMPILE_CODE($content['subject']);
100         $content['text']      = COMPILE_CODE($content['text']);
101         $content['timestamp'] = MAKE_DATETIME($content['timestamp'], "2");
102         $content['category']  = GET_CATEGORY($content['cat_id']);
103         $content['points']    = TRANSLATE_COMMA($content['points']);
104         $content['time']      = CREATE_FANCY_TIME($content['time']);
105         $content['uid']       = getUserId();
106
107         // Get timestamp from insert
108         $content['user_status'] = sprintf(getMessage('MEMBER_MAIL_NORMAL_CONFIRMED_ON'),
109                 MAKE_DATETIME(USER_STATS_GET_TIMESTAMP('mailid', $content['id']), "2")
110         );
111
112         // Display it depending on mail (data) type
113         LOAD_TEMPLATE("member_mail_normal_".strtolower($content['data_type']), false, $content);
114
115         // Free result
116         SQL_FREERESULT($result_data);
117 }
118
119 if (EXT_IS_ACTIVE('bonus')) {
120         // Load bonus ID
121         $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",
122                 array(getUserId()), __FILE__, __LINE__);
123 } else {
124         // Don't load bonus ID
125         $result = SQL_QUERY_ESC("SELECT stats_id, stats_id, link_type FROM `{!_MYSQL_PREFIX!}_user_links` WHERE userid=%s ORDER BY stats_id DESC",
126                 array(getUserId()), __FILE__, __LINE__);
127 }
128
129 // Mails left for confirmation?
130 if (SQL_NUMROWS($result) > 0) {
131         // Please confirm these mails!
132         $sum = 0; $OUT = ''; $SW = 2;
133
134         // @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
135         while (list($id, $id2, $type) = SQL_FETCHROW($result)) {
136                 // Load data from stats table...
137                 $cat = ''; $result_data = false;
138                 switch ($type)
139                 {
140                 case "NORMAL":
141                         $result_data = SQL_QUERY_ESC("SELECT s.subject, s.timestamp_ordered, s.cat_id, s.payment_id, p.sender
142 FROM `{!_MYSQL_PREFIX!}_user_stats` AS s
143 LEFT JOIN `{!_MYSQL_PREFIX!}_pool` AS p
144 ON s.pool_id=p.id
145 WHERE s.id=%s
146 LIMIT 1",
147                                 array(bigintval($id)), __FILE__, __LINE__);
148                         $type = 'mailid'; $DATA = $id; $PROBLEM = getMessage('NORMAL_MAIL_PROBLEM');
149                         break;
150
151                 case "BONUS":
152                         $result_data = SQL_QUERY_ESC("SELECT subject, timestamp, cat_id, points, 0 FROM `{!_MYSQL_PREFIX!}_bonus` WHERE id=%s LIMIT 1",
153                          array(bigintval($id2)), __FILE__, __LINE__);
154                         $type = 'bonusid'; $DATA = $id2; $PROBLEM = getMessage('BONUS_MAIL_PROBLEM');
155                         break;
156
157                 default: // Unknown type detected!
158                         DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown mail type %s detected.", $type));
159                         break;
160                 }
161
162                 // Data found to this mail?
163                 if ((SQL_NUMROWS($result_data) == 1) && (($type == 'mailid') || ($type == 'bonusid'))) {
164                         // Mail was found!
165                         list($subject, $timestamp, $cat, $pay, $sender) = SQL_FETCHROW($result_data);
166
167                         // Subject line found?
168                         if (empty($subject)) {
169                                 // No subject line!
170                                 $subject = getMessage('DEFAULT_SUBJECT_LINE');
171                         } else {
172                                 // Compile it
173                                 $subject = COMPILE_CODE($subject);
174                         }
175
176                         // Prepare sender id
177                         if (($sender > 0) && ($type == 'mailid')) {
178                                 // Sender id
179                                 $sender = bigintval($sender);
180                         } elseif ($type == 'bonusid') {
181                                 // Is admin
182                                 $sender = getMessage('_ADMIN_SHORT');
183                         } else {
184                                 // Deleted
185                                 $sender = getMessage('EMAIL_STATUS_DELETED');
186                         }
187
188                         // Prepare data for template
189                         $content = array(
190                                 'sw'      => $SW,
191                                 'uid'     => getUserId(),
192                                 'data'    => bigintval($DATA),
193                                 'type'    => $type,
194                                 'subject' => $subject,
195                                 'sender'  => $sender,
196                                 'stamp'   => MAKE_DATETIME($timestamp, "2"),
197                                 'cat'     => GET_CATEGORY($cat),
198                                 'points'  => TRANSLATE_COMMA($pay),
199                         );
200
201                         // Load row template
202                         if (getConfig('show_points_unconfirmed') == 'Y') {
203                                 $OUT .= LOAD_TEMPLATE("member_unconfirmed_row", true, $content);
204                         } else {
205                                 $OUT .= LOAD_TEMPLATE("member_unconfirmed_row_nopoints", true, $content);
206                         }
207
208                         // Count points
209                         $sum += $pay;
210                 } else {
211                         // Prepare data for template
212                         $content = array(
213                                 'sw'    => $SW,
214                                 'data'  => $DATA,
215                                 'probl' => $PROBLEM,
216                         );
217
218                         // Display points or not?
219                         if (getConfig('show_points_unconfirmed') == 'Y') {
220                                 $OUT .= LOAD_TEMPLATE("member_unconfirmed_404", true, $content);
221                         } else {
222                                 $OUT .= LOAD_TEMPLATE("member_unconfirmed_404_nopoints", true, $content);
223                         }
224                 }
225
226                 // Free result
227                 SQL_FREERESULT($result_data);
228
229                 // Switch color
230                 $SW = 3 - $SW;
231         } // END - while
232
233         // Free memory
234         SQL_FREERESULT($result);
235
236         // Remember total points
237         define('__TOTAL_POINTS', TRANSLATE_COMMA($sum));
238
239         // Remember all generated rows in constant for the template
240         define('__UNCONFIRMED_ROWS', $OUT);
241
242         // Load main template
243         if (getConfig('show_points_unconfirmed') == 'Y') {
244                 LOAD_TEMPLATE("member_unconfirmed_table");
245         } else {
246                 LOAD_TEMPLATE("member_unconfirmed_table_nopoints");
247         }
248 } else {
249         // No mails left to confirm... :)
250         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('MEMBER_NO_MAILS_TO_CONFIRM'));
251 }
252
253 //
254 ?>