A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[mailer.git] / inc / modules / admin / what-list_unconfirmed.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/09/2004 *
4  * ================                             Last change: 10/31/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-list_unconfirmed.php                        *
8  * -------------------------------------------------------------------- *
9  * Short description : List unconfirmed mail links                      *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Unbest. Mail-Links auflisten                     *
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')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } elseif (!EXT_IS_ACTIVE("mailid")) {
39         addFatalMessage(__FILE__, __LINE__, getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), "mailid");
40         return;
41 }
42
43 // Add description as navigation point
44 ADD_DESCR("admin", __FILE__);
45
46 // Don't load the admin_list_unconfirmed template by default
47 $listed = false;
48
49 if (REQUEST_ISSET_GET(('mid'))) {
50         // List confirmation links from your member's mail orders
51         define('__LIST_UNCON_TITLE', getMessage('LIST_UNCONFIRMED_MEMBER_LINKS'));
52
53         // SQL query for mail data
54         $sql = "SELECT DISTINCT s.id, p.sender, p.subject, p.text, p.url, p.timestamp, s.max_rec  FROM `{!_MYSQL_PREFIX!}_pool` AS p
55 LEFT JOIN `{!_MYSQL_PREFIX!}_user_stats` AS s
56 ON p.id=s.pool_id
57 WHERE p.id='".REQUEST_GET('mid')."' LIMIT 1";
58
59         // Column, type and ID for member's mail
60         $col = "stats_id"; $type = "NORMAL"; $ID = "-1";
61
62         // Load admin_list_unconfirmed template
63         $listed = true; $DATA = REQUEST_GET('mid'); $LINK = "mailid";
64 } elseif ((REQUEST_ISSET_GET(('bid'))) && (EXT_IS_ACTIVE("bonus"))) {
65         // List confirmation links from bonus mails
66         define('__LIST_UNCON_TITLE', getMessage('LIST_UNCONFIRMED_BONUS_LINKS'));
67
68         // SQL query for mail data (both ids are required for compatiblity to above normal mail
69         $sql = "SELECT id, id, subject, text, url, timestamp, mails_sent FROM `{!_MYSQL_PREFIX!}_bonus` WHERE id='".REQUEST_GET('bid')."' LIMIT 1";
70
71         // Column, type and ID for member's mail
72         $col = "bonus_id"; $type = "BONUS"; $ID = REQUEST_GET('bid');
73
74         // Load admin_list_unconfirmed template
75         $listed = true; $DATA = $ID; $LINK = "bonusid";
76 } else {
77         // "Please do not call me directly."
78         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_CALL_NOT_DIRECTLY'));
79 }
80
81 // Shall I display links or not?
82 if ($listed === true) {
83         // Load mail data
84         $result = SQL_QUERY($sql, __FILE__, __LINE__);
85         if (SQL_NUMROWS($result) == 1) {
86                 // Mail order / bonus mail found!
87                 // @TODO Rewrite this to $content = SQL_FETCHARRAY(), look some lines above for two differrent queries
88                 list($stats_id, $sender, $subj, $text, $url, $stamp, $max) = SQL_FETCHROW($result);
89                 SQL_FREERESULT($result);
90
91                 // Transfer data to constants for the template
92                 if (($stats_id > 0) && ($ID == "-1")) $ID = $stats_id;
93                 if ($col == "bonus_id") $sender = 0;
94
95                 // @TODO Rewrite these constants
96                 define('__LIST_UNCON_SENDER' , $sender);
97                 define('__LIST_UNCON_SUBJECT', COMPILE_CODE($subj));
98                 define('__LIST_UNCON_TEXT'   , COMPILE_CODE($text));
99                 define('__LIST_UNCON_URL'    , encodeString($url));
100                 define('__LIST_UNCON_STAMP'  , MAKE_DATETIME($stamp, "2"));
101
102                 // Load unconfirmed mail links. Hmmm, this select query is pretty cool
103                 // but it does only show unconfirmed mail links from existing user
104                 // accounts. So if you have delete one you did not see those links
105                 //
106                 $result = SQL_QUERY_ESC("SELECT DISTINCT l.userid, u.status, u.surname, u.family, u.gender, u.email
107 FROM `{!_MYSQL_PREFIX!}_user_links` AS l
108 LEFT JOIN `{!_MYSQL_PREFIX!}_user_data` AS u
109 ON l.userid=u.userid
110 WHERE l.%s='%s' ORDER BY l.userid LIMIT %s",
111                         array($col, $ID, bigintval($max)),__FILE__, __LINE__);
112                 $unconfirmed = SQL_NUMROWS($result);
113
114                 // @TODO Rewrite this constant
115                 define('__LIST_UNCO_UNCONFIRMED', $unconfirmed);
116
117                 if ($unconfirmed > 0) {
118                         // At least one link left to confirm
119                         $OUT = LOAD_TEMPLATE("admin_list_unconfirmed_header", true);
120                         $SW = 2;
121                         while ($content = SQL_FETCHARRAY($result)) {
122                                 // Prepare data for the row template
123                                 // @TODO Rewritings: uid->userid
124                                 $content = array(
125                                         'sw'     => $SW,
126                                         'u_link' => ADMIN_USER_PROFILE_LINK($content['userid']),
127                                         'uid'    => $content['userid'],
128                                         'link'   => $LINK,
129                                         'id'     => $ID,
130                                         'email'  => "<a href=\"".CREATE_EMAIL_LINK($content['email'], "user_data")."\">".TRANSLATE_GENDER($content['gender'])." ".$content['surname']." ".$content['family']."</a>",
131                                         'status' => TRANSLATE_STATUS($content['status']),
132                                 );
133
134                                 // Load row template and switch colors
135                                 $OUT .= LOAD_TEMPLATE("admin_list_unconfirmed_row", true, $content);
136                                 $SW = 3 - $SW;
137                         }
138                         $OUT .= "</table>\n";
139
140                         // Free memory
141                         SQL_FREERESULT($result);
142
143                         // Store table rows in a constant
144                         define('__LIST_UNCON_LISTING', $OUT);
145                 } else {
146                         // All links are confirmed... strange, you shall normally not get a link to this place in this scenario... hmmm.
147                         define('__LIST_UNCON_LISTING', LOAD_TEMPLATE("admin_settings_saved", true, getMessage('ADMIN_UNCONFIRMED_NO_LINK_LEFT')));
148                 }
149
150                 // Load final template
151                 LOAD_TEMPLATE("admin_list_unconfirmed");
152         } elseif (REQUEST_GET('mid') > 0) {
153                 // Data in pool or in user_stats not found, so let's find out where data is missing
154                 $result1 = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_pool` WHERE id=%s LIMIT 1",
155                         array(bigintval($ID)), __FILE__, __LINE__);
156                 $result2 = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_user_stats` WHERE pool_id=%s LIMIT 1",
157                         array(bigintval($ID)), __FILE__, __LINE__);
158                 if (SQL_NUMROWS($result1) == 1) {
159                         // pool table
160                         LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('ADMIN_UNCONFIRMED_POOL_MISSING', $ID)));
161                 } elseif (SQL_NUMROWS($result2) == 1) {
162                         // user_stats table
163                         LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('ADMIN_UNCONFIRMED_STATS_MISSING', $ID)));
164                 } else {
165                         // both or link is invalid
166                         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_UNCONFIRMED_INVALID_LINK'));
167                 }
168
169                 // Free memory
170                 SQL_FREERESULT($result1);
171                 SQL_FREERESULT($result2);
172         } elseif (REQUEST_ISSET_GET(('bid'))) {
173                 // Data in bonus table not found
174                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_UNCONFIRMED_INVALID_LINK'));
175         }
176 }
177
178 //
179 ?>