A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } elseif (!IS_MEMBER()) {
39         LOAD_URL("modules.php?module=index");
40 } elseif ((!EXT_IS_ACTIVE("mailid")) && (!IS_ADMIN())) {
41         LOAD_URL("modules.php?module=login");
42 }
43
44 // Add description as navigation point
45 ADD_DESCR("member", __FILE__);
46
47 // Shall we display a mail?
48 if ((REQUEST_ISSET_GET(('bonusid'))) && (EXT_IS_ACTIVE("bonus"))) {
49         // Display bonus mail by loading it's full data
50         $result_data = SQL_QUERY_ESC("SELECT id, subject, timestamp, cat_id, points, text, is_notify, data_type, time, url
51 FROM `{!_MYSQL_PREFIX!}_bonus`
52 WHERE id=%s LIMIT 1",
53                 array(bigintval(REQUEST_GET('bonusid'))), __FILE__, __LINE__);
54
55         // Load data
56         $content = SQL_FETCHARRAY($result_data);
57
58         // "Translate some data
59         $content['subject']   = COMPILE_CODE($content['subject']);
60         $content['text']      = COMPILE_CODE($content['text']);
61         $content['timestamp'] = MAKE_DATETIME($content['timestamp'], "2");
62         $content['category']  = GET_CATEGORY($content['cat_id']);
63         $content['points']    = TRANSLATE_COMMA($content['points']);
64         $content['is_notify'] = TRANSLATE_YESNO($content['is_notify']);
65         $content['sender']    = _ADMIN_SHORT;
66         $content['time']      = CREATE_FANCY_TIME($content['time']);
67         $content['uid']       = $GLOBALS['userid'];
68
69         // Get timestamp from insert
70         $content['user_status'] = sprintf(getMessage('MEMBER_MAIL_BONUS_CONFIRMED_ON'),
71                 MAKE_DATETIME(USER_STATS_GET_TIMESTAMP("bonusid", $content['id']), "2")
72         );
73
74         // Display it depending on mail (data) type
75         LOAD_TEMPLATE("member_mail_bonus_".strtolower($content['data_type']), false, $content);
76
77         // Free result
78         SQL_FREERESULT($result_data);
79 } elseif (REQUEST_ISSET_GET(('mailid'))) {
80         // Display regular member mail by loading its full data
81         $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
82 FROM `{!_MYSQL_PREFIX!}_user_stats` AS s
83 LEFT JOIN `{!_MYSQL_PREFIX!}_pool` AS p
84 ON s.pool_id=p.id
85 LEFT JOIN `{!_MYSQL_PREFIX!}_payments` AS pay
86 ON p.payment_id=pay.id
87 WHERE s.id=%s LIMIT 1",
88                 array(bigintval(REQUEST_GET('mailid'))), __FILE__, __LINE__);
89
90         // Load data
91         $content = SQL_FETCHARRAY($result_data);
92
93         // "Translate some data
94         $content['subject']   = COMPILE_CODE($content['subject']);
95         $content['text']      = COMPILE_CODE($content['text']);
96         $content['timestamp'] = MAKE_DATETIME($content['timestamp'], "2");
97         $content['category']  = GET_CATEGORY($content['cat_id']);
98         $content['points']    = TRANSLATE_COMMA($content['points']);
99         $content['time']      = CREATE_FANCY_TIME($content['time']);
100         $content['uid']       = $GLOBALS['userid'];
101
102         // Get timestamp from insert
103         $content['user_status'] = sprintf(getMessage('MEMBER_MAIL_NORMAL_CONFIRMED_ON'),
104                 MAKE_DATETIME(USER_STATS_GET_TIMESTAMP("mailid", $content['id']), "2")
105         );
106
107         // Display it depending on mail (data) type
108         LOAD_TEMPLATE("member_mail_normal_".strtolower($content['data_type']), false, $content);
109
110         // Free result
111         SQL_FREERESULT($result_data);
112 }
113
114 if (EXT_IS_ACTIVE("bonus")) {
115         // Load bonus ID
116         $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",
117                 array($GLOBALS['userid']), __FILE__, __LINE__);
118 } else {
119         // Don't load bonus ID
120         $result = SQL_QUERY_ESC("SELECT stats_id, stats_id, link_type FROM `{!_MYSQL_PREFIX!}_user_links` WHERE userid=%s ORDER BY stats_id DESC",
121                 array($GLOBALS['userid']), __FILE__, __LINE__);
122 }
123
124 // Mails left for confirmation?
125 if (SQL_NUMROWS($result) > 0) {
126         // Please confirm these mails!
127         $sum = 0; $OUT = ""; $SW = 2;
128
129         // @TODO Try to rewrite this to $content = SQL_FETCHARRAY()
130         while (list($id, $id2, $type) = SQL_FETCHROW($result)) {
131                 // Load data from stats table...
132                 $cat = ""; $result_data = false;
133                 switch ($type)
134                 {
135                 case "NORMAL":
136                         $result_data = SQL_QUERY_ESC("SELECT s.subject, s.timestamp_ordered, s.cat_id, s.payment_id, p.sender
137 FROM `{!_MYSQL_PREFIX!}_user_stats` AS s
138 LEFT JOIN `{!_MYSQL_PREFIX!}_pool` AS p
139 ON s.pool_id=p.id
140 WHERE s.id=%s
141 LIMIT 1",
142                                 array(bigintval($id)), __FILE__, __LINE__);
143                         $type = "mailid"; $DATA = $id; $PROBLEM = getMessage('NORMAL_MAIL_PROBLEM');
144                         break;
145
146                 case "BONUS":
147                         $result_data = SQL_QUERY_ESC("SELECT subject, timestamp, cat_id, points, 0 FROM `{!_MYSQL_PREFIX!}_bonus` WHERE id=%s LIMIT 1",
148                          array(bigintval($id2)), __FILE__, __LINE__);
149                         $type = "bonusid"; $DATA = $id2; $PROBLEM = getMessage('BONUS_MAIL_PROBLEM');
150                         break;
151
152                 default: // Unknown type detected!
153                         DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown mail type %s detected.", $type));
154                         break;
155                 }
156
157                 // Data found to this mail?
158                 if ((SQL_NUMROWS($result_data) == 1) && (($type == "mailid") || ($type == "bonusid"))) {
159                         // Mail was found!
160                         list($subject, $timestamp, $cat, $pay, $sender) = SQL_FETCHROW($result_data);
161
162                         // Subject line found?
163                         if (empty($subject)) {
164                                 // No subject line!
165                                 $subject = getMessage('DEFAULT_SUBJECT_LINE');
166                         } else {
167                                 // Compile it
168                                 $subject = COMPILE_CODE($subject);
169                         }
170
171                         // Prepare sender id
172                         if (($sender > 0) && ($type == "mailid")) {
173                                 // Sender id
174                                 $sender = bigintval($sender);
175                         } elseif ($type == "bonusid") {
176                                 // Is admin
177                                 $sender = getMessage('_ADMIN_SHORT');
178                         } else {
179                                 // Deleted
180                                 $sender = getMessage('EMAIL_STATUS_DELETED');
181                         }
182
183                         // Prepare data for template
184                         $content = array(
185                                 'sw'      => $SW,
186                                 'uid'     => $GLOBALS['userid'],
187                                 'data'    => bigintval($DATA),
188                                 'type'    => $type,
189                                 'subject' => $subject,
190                                 'sender'  => $sender,
191                                 'stamp'   => MAKE_DATETIME($timestamp, "2"),
192                                 'cat'     => GET_CATEGORY($cat),
193                                 'points'  => TRANSLATE_COMMA($pay),
194                         );
195
196                         // Load row template
197                         if (getConfig('show_points_unconfirmed') == "Y") {
198                                 $OUT .= LOAD_TEMPLATE("member_unconfirmed_row", true, $content);
199                         } else {
200                                 $OUT .= LOAD_TEMPLATE("member_unconfirmed_row_nopoints", true, $content);
201                         }
202
203                         // Count points
204                         $sum += $pay;
205                 } else {
206                         // Prepare data for template
207                         $content = array(
208                                 'sw'    => $SW,
209                                 'data'  => $DATA,
210                                 'probl' => $PROBLEM,
211                         );
212
213                         // Display points or not?
214                         if (getConfig('show_points_unconfirmed') == "Y") {
215                                 $OUT .= LOAD_TEMPLATE("member_unconfirmed_404", true, $content);
216                         } else {
217                                 $OUT .= LOAD_TEMPLATE("member_unconfirmed_404_nopoints", true, $content);
218                         }
219                 }
220
221                 // Free result
222                 SQL_FREERESULT($result_data);
223
224                 // Switch color
225                 $SW = 3 - $SW;
226         } // END - while
227
228         // Free memory
229         SQL_FREERESULT($result);
230
231         // Remember total points
232         define('__TOTAL_POINTS', TRANSLATE_COMMA($sum));
233
234         // Remember all generated rows in constant for the template
235         define('__UNCONFIRMED_ROWS', $OUT);
236
237         // Load main template
238         if (getConfig('show_points_unconfirmed') == "Y") {
239                 LOAD_TEMPLATE("member_unconfirmed_table");
240         } else {
241                 LOAD_TEMPLATE("member_unconfirmed_table_nopoints");
242         }
243 } else {
244         // No mails left to confirm... :)
245         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('MEMBER_NO_MAILS_TO_CONFIRM'));
246 }
247
248 //
249 ?>