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