Filters for configurable userid exclusion added:
[mailer.git] / inc / modules / admin / what-list_unconfirmed.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 if (!isExtensionActive('mailid')) {
47         displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=mailid%}');
48         return;
49 } // END - if
50
51 // Don't load the admin_list_unconfirmed template by default
52 $listed = FALSE;
53
54 // Init query
55 $sql = '';
56
57 // List confirmation links from normal or bonus mails
58 if (isGetRequestElementSet('mid')) {
59         // SQL query for mail data
60         $sql = sprintf("SELECT
61         s.`id`,
62         `p`.`sender`,
63         `p`.`subject`,
64         `p`.`text`,
65         `p`.`url`,
66         `p`.`timestamp`,
67         s.`max_rec`
68 FROM
69         `{?_MYSQL_PREFIX?}_pool` AS `p`
70 LEFT JOIN
71         `{?_MYSQL_PREFIX?}_user_stats` AS `s`
72 ON
73         `p`.`id`=s.`pool_id`
74 WHERE
75         `p`.`id`=%s
76 LIMIT 1",
77                 bigintval(getRequestElement('mid'))
78         );
79
80         // Column, type and id for member's mail
81         $col = 'stats_id';
82         $type = 'NORMAL';
83         $ID = -1;
84
85         // Load admin_list_unconfirmed template
86         $listed = TRUE;
87         $DATA = getRequestElement('mid');
88         $mailType = 'mailid';
89 } elseif ((isGetRequestElementSet('bid')) && (isExtensionActive('bonus'))) {
90         // @TODO This constant might be unused? define('__LIST_UNCON_TITLE', '{--ADMIN_LIST_UNCONFIRMED_BONUS_LINKS--}');
91
92         // SQL query for mail data (both ids are required for compatiblity to above normal mail
93         // @TODO `id` has been used two times???
94         $sql = sprintf("SELECT
95         `id`,
96         `id` AS `sender`,
97         `subject`,
98         `text`,
99         `url`,
100         `timestamp`,
101         `mails_sent` AS `max_rec`
102 FROM
103         `{?_MYSQL_PREFIX?}_bonus`
104 WHERE
105         `id`=%s
106 LIMIT 1",
107                 bigintval(getRequestElement('bid'))
108         );
109
110         // Column, type and id for member's mail
111         $col = 'bonus_id';
112         $type = 'BONUS';
113         $ID = getRequestElement('bid');
114
115         // Load admin_list_unconfirmed template
116         $listed = TRUE;
117         $DATA = $ID;
118         $mailType = 'bonusid';
119 } else {
120         // @TODO "Please do not call me directly." Should be rewritten to a nice selection depending on ext-bonus
121         displayMessage('{--ADMIN_CALL_NOT_DIRECTLY--}');
122 }
123
124 // Shall I display links or not?
125 if (($listed === TRUE) && (!empty($sql))) {
126         // Load mail data
127         $result_master = SQL_QUERY($sql, __FILE__, __LINE__);
128
129         // Is there an entry?
130         if (SQL_NUMROWS($result_master) == 1) {
131                 // Mail order / bonus mail found
132                 $poolData = SQL_FETCHARRAY($result_master);
133
134                 // If there is a pool id and $ID is not set, we take it
135                 if (($poolData['id'] > 0) && ($ID == '-1')) {
136                         $ID = $poolData['id'];
137                 } // END - if
138
139                 // Bonus mails do always have a sender 'NULL'
140                 if ($col == 'bonus_id') {
141                         $poolData['sender'] = NULL;
142                 } // END - if
143
144                 // Load unconfirmed mail links. Hmmm, this select query is pretty cool
145                 // but it does only show unconfirmed mail links from existing user
146                 // accounts. So if you have delete one you did not see those links
147                 $result = SQL_QUERY_ESC("SELECT
148         l.`userid`,
149         `u`.`status`,
150         `u`.`surname`,
151         `u`.`family`,
152         `u`.`gender`,
153         `u`.`email`
154 FROM
155         `{?_MYSQL_PREFIX?}_user_links` AS `l`
156 LEFT JOIN
157         `{?_MYSQL_PREFIX?}_user_data` AS `u`
158 ON
159         l.`userid`=`u`.`userid`
160 WHERE
161         l.`%s`=%s
162 ORDER BY
163         l.`userid` ASC
164 LIMIT %s",
165                         array(
166                                 $col,
167                                 $ID,
168                                 bigintval($poolData['max_rec'])
169                         ),__FILE__, __LINE__);
170
171                 // Are there entries?
172                 if (!SQL_HASZERONUMS($result)) {
173                         // At least one link left to confirm
174                         $OUT = '';
175                         while ($row = SQL_FETCHARRAY($result)) {
176                                 // User data found? We can take any field of u.
177                                 if (!is_null($row['status'])) {
178                                         // Prepare data for the row template
179                                         $row = array(
180                                                 'userid' => $row['userid'],
181                                                 'link'   => $mailType,
182                                                 'id'     => $ID,
183                                                 'email'  => '<a href="' . generateEmailLink($row['email'], 'user_data') . '">{%pipe,translateGender=' . $row['gender'] . '%} ' . $row['surname'] . ' ' . $row['family'] . '</a>',
184                                                 'status' => $row['status'],
185                                         );
186
187                                         // Load row template and switch colors
188                                         $OUT .= loadTemplate('admin_list_unconfirmed_row', TRUE, $row);
189                                 } else {
190                                         // No user data found
191                                         $OUT .= loadTemplate('admin_list_unconfirmed_row_404', TRUE, $row);
192                                 }
193                         } // END - while
194
195                         // Render it in our new listing
196                         $OUT = loadTemplate('admin_list_unconfirmed_list', TRUE, $OUT);
197                 } else {
198                         // All links are confirmed... strange, you shall normally not get a link to this place in this scenario... hmmm.
199                         $OUT = displayMessage('{--ADMIN_UNCONFIRMED_NO_LINK_LEFT--}', TRUE);
200                 }
201
202                 // Prepare content
203                 $content                = $poolData;
204                 $content['unconfirmed'] = SQL_NUMROWS($result);
205                 $content['timestamp']   = generateDateTime($poolData['timestamp'], 2);
206                 $content['rows']        = $OUT;
207
208                 // Free memory
209                 SQL_FREERESULT($result);
210
211                 // Load final template
212                 loadTemplate('admin_list_unconfirmed', FALSE, $content);
213         } elseif (getRequestElement('mid') > 0) {
214                 // Data in pool or in user_stats not found, so let's find out where data is missing
215                 if (countSumTotalData(bigintval($ID), 'pool', 'id', 'id', TRUE) == 1) {
216                         // pool table
217                         displayMessage('{%message,ADMIN_UNCONFIRMED_POOL_MISSING=' . $ID . '%}');
218                 } elseif (countSumTotalData(bigintval($ID), 'user_stats', 'id', 'pool_id', TRUE) == 1) {
219                         // user_stats table
220                         displayMessage('{%message,ADMIN_UNCONFIRMED_STATS_MISSING=' . $ID . '%}');
221                 } else {
222                         // both or link is invalid
223                         displayMessage('{--ADMIN_UNCONFIRMED_INVALID_LINK--}');
224                 }
225         } elseif (isGetRequestElementSet('bid')) {
226                 // Data in bonus table not found
227                 displayMessage('{--ADMIN_UNCONFIRMED_INVALID_LINK--}');
228         }
229
230         // Free result
231         SQL_FREERESULT($result_master);
232 } // END - if
233
234 // [EOF]
235 ?>