b0c69441bbb6a0a5d546b0fb0677a4557db46977
[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  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 } // END - if
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
48 if (!isExtensionActive('mailid')) {
49         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('mailid'));
50         return;
51 } // END - if
52
53 if (isGetRequestParameterSet('userid')) {
54         // Check if the user already exists
55         if (fetchUserData(getRequestParameter('userid'))) {
56                 // Grab user's all unconfirmed mails
57                 // @TODO Try to rewrite this to a filter
58                 if (isExtensionActive('bonus')) {
59                         // Load bonus id
60                         $result = SQL_QUERY_ESC("SELECT `stats_id`, `bonus_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s ORDER BY `id` ASC",
61                                 array(bigintval(getRequestParameter('userid'))), __FILE__, __LINE__);
62                 } else {
63                         // Load stats id (2nd will be ignored later! But it is needed for the same fetchrow command)
64                         $result = SQL_QUERY_ESC("SELECT `stats_id`, `stats_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s ORDER BY `id` ASC",
65                                 array(bigintval(getRequestParameter('userid'))), __FILE__, __LINE__);
66                 }
67
68                 // Get number of rows from the query
69                 $nums = SQL_NUMROWS($result);
70
71                 if ($nums > 0) {
72                         // Some unconfirmed mails left
73                         if (getRequestParameter('del') == "all") {
74                                 // Delete all unconfirmed mails by this user
75                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s LIMIT %s",
76                                         array(bigintval(getRequestParameter('userid')), $nums), __FILE__, __LINE__);
77
78                                 // Prepare mail and send it away
79                                 $message = loadEmailTemplate('admin-del_links', $nums, bigintval(getRequestParameter('userid')));
80                                 sendEmail(getUserData('email'), getMessage('ADMIN_DEL_LINK_SUBJ'), $message);
81
82                                 // Display message
83                                 loadTemplate('admin_settings_saved', false, '{--ADMIN_LINKS_DELETED--}');
84                         } else {
85                                 // Init variables
86                                 $OUT = ''; $SW = 2;
87
88                                 // List all unconfirmed mails
89                                 // @TODO Find a way to rewrite this. See some lines above for different queries
90                                 while (list($id, $id2, $type) = SQL_FETCHROW($result)) {
91                                         // Initializes some variables
92                                         $cat = '';
93                                         $DATA = '';
94                                         $PROBLEM = getMessage('GENERAL_MAIL_PROBLEM');
95                                         $result_data = false; // Closes Bug #58
96
97                                         // Load data from stats table...
98                                         // @TODO Rewrite this to includes/filter
99                                         switch ($type) {
100                                                 case 'NORMAL':
101                                                         $result_data = SQL_QUERY_ESC("SELECT `subject`, `timestamp_ordered` AS `timestamp`, `cat_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
102                                                                 array(bigintval($id)), __FILE__, __LINE__);
103                                                         $type = 'mailid'; $DATA = $id; $PROBLEM = getMessage('NORMAL_MAIL_PROBLEM');
104                                                         $LINK = '<a href="{%url=mailid.php?userid=' . getRequestParameter('userid') . '&amp;mailid=' . $id . '%}" target="_blank">' . $id . '</a>';
105                                                         break;
106
107                                                 case 'BONUS':
108                                                         $result_data = SQL_QUERY_ESC("SELECT `subject`, `timestamp`, `cat_id` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
109                                                                 array(bigintval($id2)), __FILE__, __LINE__);
110                                                         $type = 'bonusid'; $DATA = $id2; $PROBLEM = getMessage('BONUS_MAIL_PROBLEM');
111                                                         $LINK = '<a href="{%url=mailid.php?userid=' . getRequestParameter('userid') . '&amp;bonusid=' . $id2 . '%}" target="_blank">' . $id2 . '</a>';
112                                                         break;
113
114                                                 default: // Problem in application detected!
115                                                         // Log the error
116                                                         logDebugMessage(__FILE__, __LINE__, sprintf("Invalid email type %s detected.", $type));
117                                                         break;
118                                         } // END - switch
119
120                                         if (SQL_NUMROWS($result_data) == 1) {
121                                                 // Mail was found!
122                                                 $content = SQL_FETCHARRAY($result_data);
123
124                                                 // Fix empty subject
125                                                 if (empty($content['subject'])) $content['subject'] = getMessage('DEFAULT_SUBJECT_LINE');
126
127                                                 // Prepare data for the row template
128                                                 $content = array(
129                                                         'sw'        => $SW,
130                                                         'link'      => $LINK,
131                                                         'subject'   => $content['subject'],
132                                                         'timestamp' => generateDateTime($content['timestamp'], 0),
133                                                         'cat'       => getCategory($content['cat_id']),
134                                                 );
135
136                                                 // Load row template
137                                                 $OUT .= loadTemplate('admin_list_links_row', true, $content);
138                                         } else {
139                                                 // Load template for error
140                                                 $OUT .= loadTemplate('admin_list_links_problem', true,
141                                                         array(
142                                                                 'sw'            => $SW,
143                                                                 'problem'       => $PROBLEM,
144                                                                 'data'          => $DATA
145                                                         )
146                                                 );
147                                         }
148
149                                         // Switch color and free result
150                                         $SW = 3 - $SW;
151                                         SQL_FREERESULT($result_data);
152                                 } // END - while
153
154                                 // Free memory
155                                 SQL_FREERESULT($result);
156
157                                 // Remember list in constant for the template
158                                 $content['surname'] = getUserData('surname');
159                                 $content['family']  = getUserData('family');
160                                 $content['email']   = '<a href="' . generateEmailLink(getUserData('email'), 'user_data') . '">' . getUserData('email') . '</a>';
161                                 $content['rows']    = $OUT;
162                                 $content['nums']    = $nums;
163                                 $content['userid']  = bigintval(getRequestParameter('userid'));
164
165                                 // Load final template
166                                 loadTemplate('admin_list_links', false, $content);
167                         }
168                 } else {
169                         // No mails left to confirm
170                         loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_MEMBER_LINKS', bigintval(getRequestParameter('userid'))));
171                 }
172         } else {
173                 // User not found
174                 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_MEMBER_404', bigintval(getRequestParameter('userid'))));
175         }
176 } else {
177         // Output selection form with all confirmed user accounts listed
178         addMemberSelectionBox();
179 }
180
181 // [EOF]
182 ?>