The usual asset of bugfixes/improvements:
[mailer.git] / inc / modules / admin / what-email_details.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 09/28/2003 *
4  * ===================                          Last change: 10/29/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-email_details.php                           *
8  * -------------------------------------------------------------------- *
9  * Short description : See all email details of ordered mails           *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Alle Details einer gebuchten Mail ansehen        *
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, 2010 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 // Normal mails ordered by your members
47 $sql = "SELECT
48         `id`, `sender`, `subject`, `text`, `receivers`, `payment_id`, `data_type`, `timestamp`, `url`, `target_send`, `mails_sent`, `cat_id`
49 FROM
50         `{?_MYSQL_PREFIX?}_pool`
51 WHERE
52         `data_type` IN('ADMIN','TEMP','NEW','ACTIVE')
53 ORDER BY
54         `timestamp` DESC";
55
56 $WHO = '';
57 $SQL2 = '';
58
59 if (isGetRequestParameterSet('mid')) {
60         // Only a specific mail shall be displayed
61         $sql = sprintf("SELECT
62         `id`, `sender`, `subject`, `text`, `receivers`, `payment_id`, `data_type`, `timestamp`, `url`, `target_send`, `cat_id`
63 FROM
64         `{?_MYSQL_PREFIX?}_pool`
65 WHERE
66         `id`=%s
67 LIMIT 1",
68                 bigintval(getRequestParameter('mid'))
69         );
70         $WHO = '{--MAIL_ID--}' . ': ' . getRequestParameter('mid');
71 } elseif (isGetRequestParameterSet('userid')) {
72         // All mails by a specific member shall be displayed
73         $sql = sprintf("SELECT
74         `id`, `sender`, `subject`, `text`, `receivers`, `payment_id`, `data_type`, `timestamp`, `url`, `target_send`, `cat_id`
75 FROM
76         `{?_MYSQL_PREFIX?}_pool`
77 WHERE
78         `sender`=%s
79 ORDER BY
80         `timestamp` DESC",
81                 bigintval(getRequestParameter('userid'))
82         );
83         $WHO = '{--USER_ID--}' . ': ' . getRequestParameter('userid');
84 }
85
86 // Init result_bonus
87 $result_bonus = false;
88
89 if ((isExtensionActive('bonus')) && (empty($WHO))) {
90         // Check for maximum pages
91         $result_bonus = SQL_QUERY("SELECT
92         `id`, `subject`, `text`, `receivers`, `points`, `time`, `data_type`, `timestamp`, `url`, `cat_id`, `target_send`, `mails_sent`, `clicks`,
93         (`mails_sent` - `clicks`) AS `unconfirmed`
94 FROM
95         `{?_MYSQL_PREFIX?}_bonus`
96 WHERE
97         `is_notify`='N'
98 ORDER BY
99         `timestamp` DESC", __FILE__, __LINE__);
100 }
101
102 // Check for maximum pages
103 $result_normal = SQL_QUERY($sql, __FILE__, __LINE__);
104
105 // Set offset an current page to default values
106 if (!isGetRequestParameterSet('page')) setGetRequestParameter('page', 1);
107
108 if (!isGetRequestParameterSet('offset')) {
109         if (isConfigEntrySet('mails_page')) {
110                 // Set config entry
111                 setGetRequestParameter('offset', getConfig('mails_page'));
112         } else {
113                 // Set default one
114                 setGetRequestParameter('offset', 10);
115         }
116 } // END - if
117
118 // Add limitation to SQL string
119 if (!isGetRequestParameterSet('mid')) {
120         // Create limitation line
121         $add = ' LIMIT ' . (bigintval(getRequestParameter('offset')) * bigintval(getRequestParameter('page')) - bigintval(getRequestParameter('offset'))) . ', ' . bigintval(getRequestParameter('offset'));
122
123         // For normal mails
124         $sql .= $add;
125
126         // For bonus mails
127         if (!empty($SQL2)) $SQL2 .= $add;
128 } // END - if
129
130 // Run SQL query for normal mails
131 $result_list = SQL_QUERY($sql, __FILE__, __LINE__);
132 if ((!empty($SQL2)) && (empty($WHO))) $result_bonus = SQL_QUERY($SQL2, __FILE__, __LINE__);
133
134 // Calculate pages
135 $numPages = '0';
136 if (isConfigEntrySet('mails_page')) {
137         $numPages = round(SQL_NUMROWS($result_normal) / getConfig('mails_page') + 0.3);
138 } // END - if
139
140 // Free result
141 SQL_FREERESULT($result_normal);
142
143 $MAIL = false;
144 if (!SQL_HASZERONUMS($result_list)) {
145         // Init rows
146         $OUT = '';
147
148         // Walk through all entries
149         while ($content = SQL_FETCHARRAY($result_list)) {
150                 // Unconfirmed mails and sent mails
151                 $result_uncon = SQL_QUERY_ESC("SELECT (`max_rec` - `clicks`) AS `unconfirmed` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
152                         array(bigintval($content['id'])), __FILE__, __LINE__);
153
154                 // Load and merge data
155                 $content = merge_array($content, SQL_FETCHARRAY($result_uncon));
156
157                 // Free result
158                 SQL_FREERESULT($result_uncon);
159
160                 // Unconfirmed mails
161                 $content['unconfirmed'] = generateUnconfirmedAdminLink($content['id'], ($content['unconfirmed']), 'mid');
162
163                 // Prepare content
164                 $content['timestamp']   = generateDateTime($content['timestamp'], 0);
165
166                 // Load row template
167                 $OUT .= loadTemplate('admin_list_emails_row', true, $content);
168         } // END - while
169
170         // Free memory
171         SQL_FREERESULT($result_list);
172
173         // Add navigation (with change box and colspan=3)
174         $content['nav'] = addEmailNavigation($numPages, getConfig('mails_page'), false, 3, true);
175
176         // Prepare content
177         $content['rows'] = $OUT;
178         $content['who'] = $WHO;
179
180         // Mail orders are in pool so we can display them
181         loadTemplate('admin_list_emails', false, $content);
182
183         $MAIL = true;
184         if ((isExtensionActive('bonus')) && (empty($WHO))) {
185                 // Only check if bonus extension is active
186                 if (!SQL_HASZERONUMS($result_bonus)) outputHtml('<br /><br />');
187         } // END - if
188 } // END - if
189
190 if ((isExtensionActive('bonus')) && (empty($WHO))) {
191         // Load bonus mails only when extension is active
192         if (!SQL_HASZERONUMS($result_bonus)) {
193                 // Calculate pages
194                 $numPages = round(SQL_NUMROWS($result_bonus) / getConfig('mails_page') + 0.5);
195
196                 // List emails
197                 $OUT = '';
198                 while ($content = SQL_FETCHARRAY($result_bonus)) {
199                         // Add link to list_unconfirmed what-file
200                         $content['unconfirmed'] = generateUnconfirmedAdminLink($content['id'], $content['unconfirmed']);
201
202                         // Prepare content
203                         $content['timestamp']   = generateDateTime($content['timestamp'], 0);
204
205                         // Load row template
206                         $OUT .= loadTemplate('admin_list_bonus_emails_row', true, $content);
207                 } // END - while
208
209                 // Add navigation (without change box but with colspan=3)
210                 $content['nav'] = addEmailNavigation($numPages, getConfig('mails_page'), false, 3, true);
211
212                 // Prepare content
213                 $content['rows'] = $OUT;
214
215                 // Load main template
216                 loadTemplate('admin_list_bonus_emails', false, $content);
217                 $MAIL = true;
218         } // END - if
219 } // END - if
220
221 if ($MAIL === false) {
222         // No mail orders fond
223         loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_MAILS_IN_POOL--}');
224 } // END - if
225
226 // [EOF]
227 ?>