A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[mailer.git] / inc / modules / admin / what-list_links.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 01/28/2004 *
4  * ================                             Last change: 12/13/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-list_links.php                              *
8  * -------------------------------------------------------------------- *
9  * Short description : List unconfirmed mails of a member               *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Unbestaetigte Mails eines Mitgliedes 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 if (!REQUEST_ISSET_GET('del')) REQUEST_SET_GET('del', "");
47
48 if (REQUEST_ISSET_GET(('uid'))) {
49         // Check if the user already exists
50         $result = SQL_QUERY_ESC("SELECT surname, family, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
51                 array(bigintval(REQUEST_GET('uid'))), __FILE__, __LINE__);
52
53          // Is there an entry?
54         if (SQL_NUMROWS($result) == 1) {
55                 // Loads surname, family's name and the email address
56                 list($sname, $fname, $email) = SQL_FETCHROW($result);
57                 SQL_FREERESULT($result);
58
59                 // Grab user's all unconfirmed mails
60                 if (EXT_IS_ACTIVE("bonus")) {
61                         // Load bonus ID
62                         $result = SQL_QUERY_ESC("SELECT stats_id, bonus_id, link_type FROM `{!_MYSQL_PREFIX!}_user_links` WHERE userid=%s ORDER BY `id`",
63                                 array(bigintval(REQUEST_GET('uid'))), __FILE__, __LINE__);
64                 } else {
65                         // Load stats ID (2nd will be ignored later! But it is needed for the same fetchrow command)
66                         $result = SQL_QUERY_ESC("SELECT stats_id, stats_id, link_type FROM `{!_MYSQL_PREFIX!}_user_links` WHERE userid=%s ORDER BY `id`",
67                                 array(bigintval(REQUEST_GET('uid'))), __FILE__, __LINE__);
68                 }
69
70                 // Get number of rows from the query
71                 $nums = SQL_NUMROWS($result);
72
73                 if ($nums > 0) {
74                         // Some unconfirmed mails left
75                         if (REQUEST_GET('del') == "all") {
76                                 // Delete all unconfirmed mails by this user
77                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_links` WHERE userid=%s LIMIT %s",
78                                         array(bigintval(REQUEST_GET('uid')), $nums), __FILE__, __LINE__);
79
80                                 // Prepare mail and send it away
81                                 $msg = LOAD_EMAIL_TEMPLATE("admin-del_links", $nums, bigintval(REQUEST_GET('uid')));
82                                 SEND_EMAIL($email, getMessage('ADMIN_DEL_LINK_SUBJ'), $msg);
83
84                                 // Display message
85                                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_LINKS_DELETED'));
86                         } else {
87                                 // Init variables
88                                 $OUT = ""; $SW = 2;
89
90                                 // List all unconfirmed mails
91                                 // @TODO Find a way to rewrite this. See some lines above for different queries
92                                 while (list($id, $id2, $type) = SQL_FETCHROW($result)) {
93                                         // Initializes some variables
94                                         $cat = "";
95                                         $DATA = "";
96                                         $PROBLEM = getMessage('GENERAL_MAIL_PROBLEM');
97                                         $result_data = false; // Closes Bug #58
98
99                                         // Load data from stats table...
100                                         switch ($type)
101                                         {
102                                         case "NORMAL":
103                                                 $result_data = SQL_QUERY_ESC("SELECT subject, timestamp_ordered, cat_id FROM `{!_MYSQL_PREFIX!}_user_stats` WHERE id=%s LIMIT 1",
104                                                         array(bigintval($id)), __FILE__, __LINE__);
105                                                 $type = "mailid"; $DATA = $id; $PROBLEM = getMessage('NORMAL_MAIL_PROBLEM');
106                                                 $LINK = "<a href=\"{!URL!}/mailid.php?uid=".REQUEST_GET('uid')."&amp;mailid=".$id."\" target=\"_blank\">".$id."</a>";
107                                                 break;
108
109                                         case "BONUS":
110                                                 $result_data = SQL_QUERY_ESC("SELECT subject, timestamp, cat_id FROM `{!_MYSQL_PREFIX!}_bonus` WHERE id=%s LIMIT 1",
111                                                         array(bigintval($id2)), __FILE__, __LINE__);
112                                                 $type = "bonusid"; $DATA = $id2; $PROBLEM = getMessage('BONUS_MAIL_PROBLEM');
113                                                 $LINK = "<a href=\"{!URL!}/mailid.php?uid=".REQUEST_GET('uid')."&amp;bonusid=".$id2."\" target=\"_blank\">".$id2."</a>";
114                                                 break;
115
116                                         default: // Problem in application detected!
117                                                 // Log the error
118                                                 DEBUG_LOG(__FILE__, __LINE__, sprintf("Invalid email type %s detected.", $type));
119                                                 break;
120                                         }
121
122                                         if (SQL_NUMROWS($result_data) == 1) {
123                                                 // Mail was found!
124                                                 list($subject, $timestamp, $cat) = SQL_FETCHROW($result_data);
125                                                 SQL_FREERESULT($result_data);
126                                                 if (empty($subject)) $subject = getMessage('DEFAULT_SUBJECT_LINE');
127
128                                                 // Prepare data for the row template
129                                                 $content = array(
130                                                         'sw'    => $SW,
131                                                         'link'  => $LINK,
132                                                         'subj'  => $subject,
133                                                         'stamp' => MAKE_DATETIME($timestamp, "0"),
134                                                         'cat'   => GET_CATEGORY($cat),
135                                                 );
136
137                                                 // Load row template
138                                                 $OUT .= LOAD_TEMPLATE("admin_list_links_row", true, $content);
139                                         } else {
140                                                 // Load template for error
141                                                 $OUT .= LOAD_TEMPLATE("admin_list_links_problem",
142                                                         array(
143                                                                 'sw'            => $SW,
144                                                                 'problem'       => $PROBLEM,
145                                                                 'data'          => $DATA
146                                                         )
147                                                 );
148                                         }
149                                         $SW = 3 - $SW;
150                                 }
151
152                                 // Free memory
153                                 SQL_FREERESULT($result);
154
155                                 // Remember list in constant for the template
156                                 define('__SNAME_VALUE', $sname);
157                                 define('__FNAME_VALUE', $fname);
158                                 define('__EMAIL_VALUE', "<a href=\"".CREATE_EMAIL_LINK($email, "user_data")."\">".$email."</a>");
159                                 define('__EMAIL_LIST' , $OUT);
160                                 define('__NUMS_VALUE' , $nums);
161                                 define('__UID'        , bigintval(REQUEST_GET('uid')));
162
163                                 // Load final template
164                                 LOAD_TEMPLATE("admin_list_links");
165                         }
166                 } else {
167                         // No mails left to confirm
168                         LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('ADMIN_MEMBER_LINKS'), REQUEST_GET('uid')));
169                 }
170         } else {
171                 // User not found
172                 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('ADMIN_MEMBER_404'), REQUEST_GET('uid')));
173         }
174 } else {
175         // Output selection form with all confirmed user accounts listed
176         ADD_MEMBER_SELECTION_BOX();
177 }
178
179 //
180 ?>