Renamed script to baseUrl to make it more clear
[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('admin-del_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                                         $cat = '';
89                                         $DATA = '';
90                                         $PROBLEM = '{--ADMIN_GENERAL_MAIL_PROBLEM--}';
91                                         $result_data = false;
92
93                                         // Load data from stats table...
94                                         // @TODO Rewrite this to includes/filter
95                                         switch ($type) {
96                                                 case 'NORMAL':
97                                                         $result_data = SQL_QUERY_ESC("SELECT `subject`, `timestamp_ordered` AS `timestamp`, `cat_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
98                                                                 array(bigintval($id)), __FILE__, __LINE__);
99                                                         $type = 'mailid'; $DATA = $id; $PROBLEM = '{--NORMAL_MAIL_PROBLEM--}';
100                                                         $LINK = '<a href="{%url=mailid.php?userid=' . getRequestParameter('userid') . '&amp;mailid=' . $id . '%}" target="_blank">' . $id . '</a>';
101                                                         break;
102
103                                                 case 'BONUS':
104                                                         $result_data = SQL_QUERY_ESC("SELECT `subject`, `timestamp`, `cat_id` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
105                                                                 array(bigintval($id2)), __FILE__, __LINE__);
106                                                         $type = 'bonusid'; $DATA = $id2; $PROBLEM = '{--BONUS_MAIL_PROBLEM--}';
107                                                         $LINK = '<a href="{%url=mailid.php?userid=' . getRequestParameter('userid') . '&amp;bonusid=' . $id2 . '%}" target="_blank">' . $id2 . '</a>';
108                                                         break;
109
110                                                 default: // Problem in application detected!
111                                                         // Log the error
112                                                         logDebugMessage(__FILE__, __LINE__, sprintf("Invalid email type %s detected.", $type));
113                                                         break;
114                                         } // END - switch
115
116                                         // Do we have an entry?
117                                         if (SQL_NUMROWS($result_data) == 1) {
118                                                 // Mail was found
119                                                 $content = SQL_FETCHARRAY($result_data);
120
121                                                 // Fix empty subject
122                                                 if (empty($content['subject'])) $content['subject'] = '{--DEFAULT_SUBJECT_LINE--}';
123
124                                                 // Prepare data for the row template
125                                                 $content = array(
126                                                         'link'      => $LINK,
127                                                         'subject'   => $content['subject'],
128                                                         'timestamp' => generateDateTime($content['timestamp'], 0),
129                                                         'cat_id'    => $content['cat_id'],
130                                                 );
131
132                                                 // Load row template
133                                                 $OUT .= loadTemplate('admin_list_links_row', true, $content);
134                                         } else {
135                                                 // Load template for error
136                                                 $OUT .= loadTemplate('admin_list_links_problem', true,
137                                                         array(
138                                                                 'problem'       => $PROBLEM,
139                                                                 'data'          => $DATA
140                                                         )
141                                                 );
142                                         }
143
144                                         // Free result
145                                         SQL_FREERESULT($result_data);
146                                 } // END - while
147
148                                 // Remember list in constant for the template
149                                 $content['surname'] = getUserData('surname');
150                                 $content['family']  = getUserData('family');
151                                 $content['email']   = '<a href="' . generateEmailLink(getUserData('email'), 'user_data') . '">' . getUserData('email') . '</a>';
152                                 $content['rows']    = $OUT;
153                                 $content['nums']    = SQL_NUMROWS($result);
154                                 $content['userid']  = bigintval(getRequestParameter('userid'));
155
156                                 // Free memory
157                                 SQL_FREERESULT($result);
158
159                                 // Load final template
160                                 loadTemplate('admin_list_links', false, $content);
161                         }
162                 } else {
163                         // No mails left to confirm
164                         displayMessage(getMaskedMessage('ADMIN_MEMBER_LINKS', bigintval(getRequestParameter('userid'))));
165                 }
166         } else {
167                 // User not found
168                 displayMessage(getMaskedMessage('ADMIN_MEMBER_404', bigintval(getRequestParameter('userid'))));
169         }
170 } else {
171         // Output selection form with all confirmed user accounts listed
172         addMemberSelectionBox();
173 }
174
175 // [EOF]
176 ?>