367c945f1a230c2e2710923265e8f626b397d5a4
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.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(generateExtensionInactiveNotInstalledMessage('mailid'));
48         return;
49 } // END - if
50
51 if (isGetRequestParameterSet('userid')) {
52         // Check if the user already exists
53         if (fetchUserData(getRequestParameter('userid'))) {
54                 // Grab user's all unconfirmed mails
55                 // @TODO Try to rewrite this to a filter
56                 if (isExtensionActive('bonus')) {
57                         // Load bonus id
58                         $result = SQL_QUERY_ESC("SELECT `stats_id`, `bonus_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s ORDER BY `id` ASC",
59                                 array(bigintval(getRequestParameter('userid'))), __FILE__, __LINE__);
60                 } else {
61                         // Load stats id (2nd will be ignored later! But it is needed for the same fetchrow command)
62                         $result = SQL_QUERY_ESC("SELECT `stats_id`, `stats_id`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s ORDER BY `id` ASC",
63                                 array(bigintval(getRequestParameter('userid'))), __FILE__, __LINE__);
64                 }
65
66                 // Do we have some entries?
67                 if (!SQL_HASZERONUMS($result)) {
68                         // Some unconfirmed mails left
69                         if (getRequestParameter('delete') == "all") {
70                                 // Delete all unconfirmed mails by this user
71                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s LIMIT %s",
72                                         array(bigintval(getRequestParameter('userid')), SQL_NUMROWS($result)), __FILE__, __LINE__);
73
74                                 // Prepare mail and send it away
75                                 $message = loadEmailTemplate('member_delete_links', SQL_NUMROWS($result), bigintval(getRequestParameter('userid')));
76                                 sendEmail(getUserData('email'), '{--ADMIN_DELETE_LINK_SUBJECT--}', $message);
77
78                                 // Display message
79                                 displayMessage('{--ADMIN_LINKS_DELETED--}');
80                         } else {
81                                 // Init variables
82                                 $OUT = '';
83
84                                 // List all unconfirmed mails
85                                 // @TODO Find a way to rewrite this. See some lines above for different queries
86                                 while (list($id, $id2, $type) = SQL_FETCHROW($result)) {
87                                         // Initializes all variables
88                                         $DATA = '';
89                                         $PROBLEM = '{--ADMIN_GENERAL_MAIL_PROBLEM--}';
90                                         $result_data = false;
91
92                                         // Load data from stats table...
93                                         // @TODO Rewrite this to includes/filter
94                                         switch ($type) {
95                                                 case 'NORMAL':
96                                                         $result_data = SQL_QUERY_ESC("SELECT `subject`, `timestamp_ordered` AS `timestamp`, `cat_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
97                                                                 array(bigintval($id)), __FILE__, __LINE__);
98                                                         $type = 'mailid'; $DATA = $id; $PROBLEM = '{--NORMAL_MAIL_PROBLEM--}';
99                                                         $LINK = '<a href="{%url=mailid.php?userid=' . getRequestParameter('userid') . '&amp;mailid=' . $id . '%}" target="_blank">' . $id . '</a>';
100                                                         break;
101
102                                                 case 'BONUS':
103                                                         $result_data = SQL_QUERY_ESC("SELECT `subject`, `timestamp`, `cat_id` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
104                                                                 array(bigintval($id2)), __FILE__, __LINE__);
105                                                         $type = 'bonusid'; $DATA = $id2; $PROBLEM = '{--BONUS_MAIL_PROBLEM--}';
106                                                         $LINK = '<a href="{%url=mailid.php?userid=' . getRequestParameter('userid') . '&amp;bonusid=' . $id2 . '%}" target="_blank">' . $id2 . '</a>';
107                                                         break;
108
109                                                 default: // Problem in application detected!
110                                                         // Log the error
111                                                         logDebugMessage(__FILE__, __LINE__, sprintf("Invalid email type %s detected.", $type));
112                                                         break;
113                                         } // END - switch
114
115                                         // Do we have an entry?
116                                         if (SQL_NUMROWS($result_data) == 1) {
117                                                 // Mail was found
118                                                 $content = SQL_FETCHARRAY($result_data);
119
120                                                 // Fix empty subject
121                                                 if (empty($content['subject'])) $content['subject'] = '{--DEFAULT_SUBJECT_LINE--}';
122
123                                                 // Prepare data for the row template
124                                                 $content = array(
125                                                         'link'      => $LINK,
126                                                         'subject'   => $content['subject'],
127                                                         'timestamp' => generateDateTime($content['timestamp'], 0),
128                                                         'cat_id'    => $content['cat_id'],
129                                                 );
130
131                                                 // Load row template
132                                                 $OUT .= loadTemplate('admin_list_links_row', true, $content);
133                                         } else {
134                                                 // Load template for error
135                                                 $OUT .= loadTemplate('admin_list_links_problem', true,
136                                                         array(
137                                                                 'problem'       => $PROBLEM,
138                                                                 'data'          => $DATA
139                                                         )
140                                                 );
141                                         }
142
143                                         // Free result
144                                         SQL_FREERESULT($result_data);
145                                 } // END - while
146
147                                 // Remember list in constant for the template
148                                 $content['surname'] = getUserData('surname');
149                                 $content['family']  = getUserData('family');
150                                 $content['email']   = '<a href="' . generateEmailLink(getUserData('email'), 'user_data') . '">' . getUserData('email') . '</a>';
151                                 $content['rows']    = $OUT;
152                                 $content['nums']    = SQL_NUMROWS($result);
153                                 $content['userid']  = bigintval(getRequestParameter('userid'));
154
155                                 // Free memory
156                                 SQL_FREERESULT($result);
157
158                                 // Load final template
159                                 loadTemplate('admin_list_links', false, $content);
160                         }
161                 } else {
162                         // No mails left to confirm
163                         displayMessage(getMaskedMessage('ADMIN_MEMBER_LINKS', bigintval(getRequestParameter('userid'))));
164                 }
165         } else {
166                 // User not found
167                 displayMessage(getMaskedMessage('ADMIN_MEMBER_404', bigintval(getRequestParameter('userid'))));
168         }
169 } else {
170         // Output selection form with all confirmed user accounts listed
171         addMemberSelectionBox();
172 }
173
174 // [EOF]
175 ?>