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