Naming convention applied, ext-network menu resorted:
[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                 // Do we have some entries?
69                 if (SQL_NUMROWS($result) > 0) {
70                         // Some unconfirmed mails left
71                         if (getRequestParameter('del') == "all") {
72                                 // Delete all unconfirmed mails by this user
73                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s LIMIT %s",
74                                         array(bigintval(getRequestParameter('userid')), SQL_NUMROWS($result)), __FILE__, __LINE__);
75
76                                 // Prepare mail and send it away
77                                 $message = loadEmailTemplate('admin-del_links', SQL_NUMROWS($result), bigintval(getRequestParameter('userid')));
78                                 sendEmail(getUserData('email'), '{--ADMIN_DELETE_LINK_SUBJECT--}', $message);
79
80                                 // Display message
81                                 loadTemplate('admin_settings_saved', false, '{--ADMIN_LINKS_DELETED--}');
82                         } else {
83                                 // Init variables
84                                 $OUT = '';
85
86                                 // List all unconfirmed mails
87                                 // @TODO Find a way to rewrite this. See some lines above for different queries
88                                 while (list($id, $id2, $type) = SQL_FETCHROW($result)) {
89                                         // Initializes some variables
90                                         $cat = '';
91                                         $DATA = '';
92                                         $PROBLEM = '{--ADMIN_GENERAL_MAIL_PROBLEM--}';
93                                         $result_data = false; // Closes Bug #58
94
95                                         // Load data from stats table...
96                                         // @TODO Rewrite this to includes/filter
97                                         switch ($type) {
98                                                 case 'NORMAL':
99                                                         $result_data = SQL_QUERY_ESC("SELECT `subject`, `timestamp_ordered` AS `timestamp`, `cat_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
100                                                                 array(bigintval($id)), __FILE__, __LINE__);
101                                                         $type = 'mailid'; $DATA = $id; $PROBLEM = '{--NORMAL_MAIL_PROBLEM--}';
102                                                         $LINK = '<a href="{%url=mailid.php?userid=' . getRequestParameter('userid') . '&amp;mailid=' . $id . '%}" target="_blank">' . $id . '</a>';
103                                                         break;
104
105                                                 case 'BONUS':
106                                                         $result_data = SQL_QUERY_ESC("SELECT `subject`, `timestamp`, `cat_id` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
107                                                                 array(bigintval($id2)), __FILE__, __LINE__);
108                                                         $type = 'bonusid'; $DATA = $id2; $PROBLEM = '{--BONUS_MAIL_PROBLEM--}';
109                                                         $LINK = '<a href="{%url=mailid.php?userid=' . getRequestParameter('userid') . '&amp;bonusid=' . $id2 . '%}" target="_blank">' . $id2 . '</a>';
110                                                         break;
111
112                                                 default: // Problem in application detected!
113                                                         // Log the error
114                                                         logDebugMessage(__FILE__, __LINE__, sprintf("Invalid email type %s detected.", $type));
115                                                         break;
116                                         } // END - switch
117
118                                         // Do we have an entry?
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'] = '{--DEFAULT_SUBJECT_LINE--}';
125
126                                                 // Prepare data for the row template
127                                                 $content = array(
128                                                         'link'      => $LINK,
129                                                         'subject'   => $content['subject'],
130                                                         'timestamp' => generateDateTime($content['timestamp'], 0),
131                                                         'cat_id'    => $content['cat_id'],
132                                                 );
133
134                                                 // Load row template
135                                                 $OUT .= loadTemplate('admin_list_links_row', true, $content);
136                                         } else {
137                                                 // Load template for error
138                                                 $OUT .= loadTemplate('admin_list_links_problem', true,
139                                                         array(
140                                                                 'problem'       => $PROBLEM,
141                                                                 'data'          => $DATA
142                                                         )
143                                                 );
144                                         }
145
146                                         // Free result
147                                         SQL_FREERESULT($result_data);
148                                 } // END - while
149
150                                 // Remember list in constant for the template
151                                 $content['surname'] = getUserData('surname');
152                                 $content['family']  = getUserData('family');
153                                 $content['email']   = '<a href="' . generateEmailLink(getUserData('email'), 'user_data') . '">' . getUserData('email') . '</a>';
154                                 $content['rows']    = $OUT;
155                                 $content['nums']    = SQL_NUMROWS($result);
156                                 $content['userid']  = bigintval(getRequestParameter('userid'));
157
158                                 // Free memory
159                                 SQL_FREERESULT($result);
160
161                                 // Load final template
162                                 loadTemplate('admin_list_links', false, $content);
163                         }
164                 } else {
165                         // No mails left to confirm
166                         loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_MEMBER_LINKS', bigintval(getRequestParameter('userid'))));
167                 }
168         } else {
169                 // User not found
170                 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_MEMBER_404', bigintval(getRequestParameter('userid'))));
171         }
172 } else {
173         // Output selection form with all confirmed user accounts listed
174         addMemberSelectionBox();
175 }
176
177 // [EOF]
178 ?>