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