Bug 'return is not bool' fixed
[mailer.git] / inc / modules / admin / what-list_links.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  : Unbest&auml;tigte Mails eines Mitgliedes auflisten   *
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 - 2009 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')) || (!isAdmin())) {
41         die();
42 } // END - if
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
47 if (!isExtensionActive('mailid')) {
48         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('mailid'));
49         return;
50 } // END - if
51
52 if (isGetRequestParameterSet('userid')) {
53         // Check if the user already exists
54         if (fetchUserData(getRequestParameter('userid'))) {
55                 // Grab user's all unconfirmed mails
56                 // @TODO Try to rewrite this to a filter
57                 if (isExtensionActive('bonus')) {
58                         // Load bonus id
59                         $result = SQL_QUERY_ESC("SELECT `stats_id`, `bonus_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s ORDER BY `id`",
60                                 array(bigintval(getRequestParameter('userid'))), __FILE__, __LINE__);
61                 } else {
62                         // Load stats id (2nd will be ignored later! But it is needed for the same fetchrow command)
63                         $result = SQL_QUERY_ESC("SELECT `stats_id`, `stats_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s ORDER BY `id` ASC",
64                                 array(bigintval(getRequestParameter('userid'))), __FILE__, __LINE__);
65                 }
66
67                 // Get number of rows from the query
68                 $nums = SQL_NUMROWS($result);
69
70                 if ($nums > 0) {
71                         // Some unconfirmed mails left
72                         if (getRequestParameter('del') == "all") {
73                                 // Delete all unconfirmed mails by this user
74                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s LIMIT %s",
75                                         array(bigintval(getRequestParameter('userid')), $nums), __FILE__, __LINE__);
76
77                                 // Prepare mail and send it away
78                                 $message = loadEmailTemplate('admin-del_links', $nums, bigintval(getRequestParameter('userid')));
79                                 sendEmail(getUserData('email'), getMessage('ADMIN_DEL_LINK_SUBJ'), $message);
80
81                                 // Display message
82                                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_LINKS_DELETED'));
83                         } else {
84                                 // Init variables
85                                 $OUT = ''; $SW = 2;
86
87                                 // List all unconfirmed mails
88                                 // @TODO Find a way to rewrite this. See some lines above for different queries
89                                 while (list($id, $id2, $type) = SQL_FETCHROW($result)) {
90                                         // Initializes some variables
91                                         $cat = '';
92                                         $DATA = '';
93                                         $PROBLEM = getMessage('GENERAL_MAIL_PROBLEM');
94                                         $result_data = false; // Closes Bug #58
95
96                                         // Load data from stats table...
97                                         // @TODO Rewrite this to includes/filter
98                                         switch ($type) {
99                                                 case 'NORMAL':
100                                                         $result_data = SQL_QUERY_ESC("SELECT `subject`, `timestamp_ordered` AS `timestamp`, `cat_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
101                                                                 array(bigintval($id)), __FILE__, __LINE__);
102                                                         $type = 'mailid'; $DATA = $id; $PROBLEM = getMessage('NORMAL_MAIL_PROBLEM');
103                                                         $LINK = '<a href="{%url=mailid.php?userid=' . getRequestParameter('userid') . '&amp;mailid=' . $id . '%}" target="_blank">' . $id . '</a>';
104                                                         break;
105
106                                                 case 'BONUS':
107                                                         $result_data = SQL_QUERY_ESC("SELECT `subject`, `timestamp`, `cat_id` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
108                                                                 array(bigintval($id2)), __FILE__, __LINE__);
109                                                         $type = 'bonusid'; $DATA = $id2; $PROBLEM = getMessage('BONUS_MAIL_PROBLEM');
110                                                         $LINK = '<a href="{%url=mailid.php?userid=' . getRequestParameter('userid') . '&amp;bonusid=' . $id2 . '%}" target="_blank">' . $id2 . '</a>';
111                                                         break;
112
113                                                 default: // Problem in application detected!
114                                                         // Log the error
115                                                         logDebugMessage(__FILE__, __LINE__, sprintf("Invalid email type %s detected.", $type));
116                                                         break;
117                                         } // END - switch
118
119                                         if (SQL_NUMROWS($result_data) == 1) {
120                                                 // Mail was found!
121                                                 $content = SQL_FETCHARRAY($result_data);
122
123                                                 // Fix empty subject
124                                                 if (empty($content['subject'])) $content['subject'] = getMessage('DEFAULT_SUBJECT_LINE');
125
126                                                 // Prepare data for the row template
127                                                 $content = array(
128                                                         'sw'        => $SW,
129                                                         'link'      => $LINK,
130                                                         'subject'   => $content['subject'],
131                                                         'timestamp' => generateDateTime($content['timestamp'], 0),
132                                                         'cat'       => getCategory($content['cat_id']),
133                                                 );
134
135                                                 // Load row template
136                                                 $OUT .= loadTemplate('admin_list_links_row', true, $content);
137                                         } else {
138                                                 // Load template for error
139                                                 $OUT .= loadTemplate('admin_list_links_problem', true,
140                                                         array(
141                                                                 'sw'            => $SW,
142                                                                 'problem'       => $PROBLEM,
143                                                                 'data'          => $DATA
144                                                         )
145                                                 );
146                                         }
147
148                                         // Switch color and free result
149                                         $SW = 3 - $SW;
150                                         SQL_FREERESULT($result_data);
151                                 } // END - while
152
153                                 // Free memory
154                                 SQL_FREERESULT($result);
155
156                                 // Remember list in constant for the template
157                                 $content['surname'] = getUserData('surname');
158                                 $content['family']  = getUserData('family');
159                                 $content['email']   = '<a href="' . generateEmailLink(getUserData('email'), 'user_data') . '">' . getUserData('email') . '</a>';
160                                 $content['rows']    = $OUT;
161                                 $content['nums']    = $nums;
162                                 $content['userid']  = bigintval(getRequestParameter('userid'));
163
164                                 // Load final template
165                                 loadTemplate('admin_list_links', false, $content);
166                         }
167                 } else {
168                         // No mails left to confirm
169                         loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_MEMBER_LINKS', getRequestParameter('userid')));
170                 }
171         } else {
172                 // User not found
173                 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_MEMBER_404', getRequestParameter('userid')));
174         }
175 } else {
176         // Output selection form with all confirmed user accounts listed
177         addMemberSelectionBox();
178 }
179
180 // [EOF]
181 ?>