Renamed all SQL-related functions to camel-case notation
[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 - 2013 by Mailer Developer Team                   *
20  * For more information visit: http://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('{%pipe,generateExtensionInactiveNotInstalledMessage=mailid%}');
48         return;
49 } // END - if
50
51 if (isGetRequestElementSet('userid')) {
52         // Check if the user already exists
53         if (fetchUserData(getRequestElement('userid'))) {
54                 // Default is ext-bonus is not installed
55                 $rowName = 'stats_id';
56
57                 // Is ext-bonus installed?
58                 if (isExtensionActive('bonus')) {
59                         // Use bonus_id
60                         $linkDataName = 'bonus_id';
61                 } // END - if
62
63                 // Load user links data
64                 $result = sqlQueryEscaped("SELECT `userid`, `stats_id`, `%s`, `link_type` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s ORDER BY `id` ASC",
65                         array(
66                                 $linkDataName,
67                                 bigintval(getRequestElement('userid'))
68                         ), __FILE__, __LINE__);
69
70                 // Are there some entries?
71                 if (!ifSqlHasZeroNums($result)) {
72                         // Some unconfirmed mails left
73                         if (getRequestElement('delete') == 'all') {
74                                 // Delete all unconfirmed mails by this user
75                                 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `userid`=%s LIMIT %s",
76                                         array(bigintval(getRequestElement('userid')), sqlNumRows($result)), __FILE__, __LINE__);
77
78                                 // Prepare mail and send it away
79                                 $message = loadEmailTemplate('member_delete_links', sqlNumRows($result), bigintval(getRequestElement('userid')));
80                                 sendEmail(getUserData('userid'), '{--ADMIN_DELETE_LINK_SUBJECT--}', $message);
81
82                                 // Display message
83                                 displayMessage('{--ADMIN_LINKS_DELETED--}');
84                         } else {
85                                 // Init variables
86                                 $OUT = '';
87
88                                 // List all unconfirmed mails
89                                 while ($linkData = sqlFetchArray($result)) {
90                                         // Initializes all other elements
91                                         $linkData['mail_id'] = '';
92                                         $linkData['problem'] = '{--ADMIN_GENERAL_MAIL_PROBLEM--}';
93                                         $result_data = FALSE;
94
95                                         // Load data from stats table...
96                                         // @TODO Rewrite this to includes/filter
97                                         switch ($linkData['link_type']) {
98                                                 case 'NORMAL':
99                                                         $result_data = sqlQueryEscaped("SELECT `subject`, `timestamp_ordered` AS `timestamp`, `cat_id` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `id`=%s LIMIT 1",
100                                                                 array(bigintval($linkData['stats_id'])), __FILE__, __LINE__);
101                                                         $linkData['link_type'] = 'mailid';
102                                                         $linkData['mail_id']   = $linkData['stats_id'];
103                                                         $linkData['problem']   = '{--NORMAL_MAIL_PROBLEM--}';
104                                                         break;
105
106                                                 case 'BONUS':
107                                                         $result_data = sqlQueryEscaped("SELECT `subject`, `timestamp`, `cat_id` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1",
108                                                                 array(bigintval($linkData['bonus_id'])), __FILE__, __LINE__);
109                                                         $linkData['link_type'] = 'bonusid';
110                                                         $linkData['mail_id']   = $linkData['bonus_id'];
111                                                         $linkData['problem']   = '{--BONUS_MAIL_PROBLEM--}';
112                                                         break;
113
114                                                 default: // Problem in application detected!
115                                                         reportBug(__FILE__, __LINE__, sprintf("Invalid email type %s detected.", $linkData['link_type']));
116                                                         break;
117                                         } // END - switch
118
119                                         // Is there an entry?
120                                         if (sqlNumRows($result_data) == 1) {
121                                                 // Mail was found
122                                                 $mailData = merge_array($linkData, sqlFetchArray($result_data));
123
124                                                 // Fix empty subject
125                                                 if (empty($mailData['subject'])) {
126                                                         // The subject line is empty so we use the default
127                                                         $mailData['subject'] = '{--DEFAULT_SUBJECT--}';
128                                                 } // END - if
129
130                                                 // Prepare data for the row template
131                                                 $mailData['timestamp'] = generateDateTime($mailData['timestamp'], 0);
132
133                                                 // Load row template
134                                                 $OUT .= loadTemplate('admin_list_links_row', TRUE, $mailData);
135                                         } else {
136                                                 // Load template for error
137                                                 $OUT .= loadTemplate('admin_list_links_problem', TRUE, $linkData);
138                                         }
139
140                                         // Free result
141                                         sqlFreeResult($result_data);
142                                 } // END - while
143
144                                 // Remember list in constant for the template
145                                 $content = array(
146                                         'email'   => '<a href="' . generateEmailLink(getUserData('email'), 'user_data') . '">' . getUserData('email') . '</a>',
147                                         'rows'    => $OUT,
148                                         'nums'    => sqlNumRows($result),
149                                         'userid'  => bigintval(getRequestElement('userid')),
150                                 );
151
152                                 // Free memory
153                                 sqlFreeResult($result);
154
155                                 // Load final template
156                                 loadTemplate('admin_list_links', FALSE, $content);
157                         }
158                 } else {
159                         // No mails left to confirm
160                         displayMessage('{%message,ADMIN_NO_UNCONFIRMED_MAILS_LEFT=' . bigintval(getRequestElement('userid')) . '%}');
161                 }
162         } else {
163                 // User not found
164                 displayMessage('{%message,ADMIN_MEMBER_404=' . bigintval(getRequestElement('userid')) . '%}');
165         }
166 } else {
167         // Output selection form with all confirmed user accounts listed
168         addMemberSelectionBox();
169 }
170
171 // [EOF]
172 ?>