93eccb434375855a942c0dcb6c6a655860df627b
[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 - 2015 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 // 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`,
56         `sender`,
57         `subject`,
58         `text`,
59         `receivers`,
60         `payment_id`,
61         `data_type`,
62         `timestamp`,
63         `url`,
64         `target_send`,
65         `mails_sent`,
66         `cat_id`
67 FROM
68         `{?_MYSQL_PREFIX?}_pool`
69 WHERE
70         `data_type` IN('ADMIN','TEMP','NEW','ACTIVE')
71 ORDER BY
72         `timestamp` DESC";
73
74 $WHO = '';
75 $SQL2 = '';
76
77 if ((isPostRequestElementSet('id')) && (isGetRequestElementSet('type')) && (postRequestElement('type') == 'normal')) {
78         // Only a specific mail shall be displayed
79         $sql = sprintf('SELECT
80         `id`,
81         `sender`,
82         `subject`,
83         `text`,
84         `receivers`,
85         `payment_id`,
86         `data_type`,
87         `timestamp`,
88         `url`,
89         `target_send`,
90         `mails_sent`,
91         `cat_id`
92 FROM
93         `{?_MYSQL_PREFIX?}_pool`
94 WHERE
95         `id`=%s
96 LIMIT 1',
97                 bigintval(getRequestElement('id'))
98         );
99         $WHO = '{--MAIL_ID--}' . ': ' . getRequestElement('id');
100 } elseif (isGetRequestElementSet('userid')) {
101         // All mails by a specific member shall be displayed
102         $sql = sprintf('SELECT
103         `id`,
104         `sender`,
105         `subject`,
106         `text`,
107         `receivers`,
108         `payment_id`,
109         `data_type`,
110         `timestamp`,
111         `url`,
112         `target_send`,
113         `mails_sent`,
114         `cat_id`
115 FROM
116         `{?_MYSQL_PREFIX?}_pool`
117 WHERE
118         `sender`=%s
119 ORDER BY
120         `timestamp` DESC',
121                 bigintval(getRequestElement('userid'))
122         );
123         $WHO = '{--USER_ID--}' . ': ' . getRequestElement('userid');
124 }
125
126 // Init result_bonus
127 $result_bonus = FALSE;
128
129 if ((isExtensionActive('bonus')) && (empty($WHO))) {
130         // Check for maximum pages
131         $result_bonus = sqlQuery("SELECT
132         `id`,
133         `subject`,
134         `text`,
135         `receivers`,
136         `points`,
137         `time`,
138         `data_type`,
139         `timestamp`,
140         `url`,
141         `cat_id`,
142         `target_send`,
143         `mails_sent`,
144         `clicks`,
145         (`mails_sent` - `clicks`) AS `unconfirmed`
146 FROM
147         `{?_MYSQL_PREFIX?}_bonus`
148 WHERE
149         `is_notify`='N'
150 ORDER BY
151         `timestamp` DESC", __FILE__, __LINE__);
152 } // END - if
153
154 // Check for maximum pages
155 $result_normal = sqlQuery($sql, __FILE__, __LINE__);
156
157 // Set offset an current page to default values
158 if (!isGetRequestElementSet('page')) setGetRequestElement('page', 1);
159
160 if (!isGetRequestElementSet('offset')) {
161         if (isConfigEntrySet('mails_page')) {
162                 // Set config entry
163                 setGetRequestElement('offset', getMailsPage());
164         } else {
165                 // Set default one
166                 setGetRequestElement('offset', 10);
167         }
168 } // END - if
169
170 // Add limitation to SQL string
171 if (!(isPostRequestElementSet('id')) && (isGetRequestElementSet('type')) && (postRequestElement('type') == 'normal')) {
172         // Create limitation line
173         $add = ' LIMIT ' . (bigintval(getRequestElement('offset')) * bigintval(getRequestElement('page')) - bigintval(getRequestElement('offset'))) . ', ' . bigintval(getRequestElement('offset'));
174
175         // For normal mails
176         $sql .= $add;
177
178         // For bonus mails
179         if (!empty($SQL2)) $SQL2 .= $add;
180 } // END - if
181
182 // Run SQL query for normal mails
183 $result_list = sqlQuery($sql, __FILE__, __LINE__);
184 if ((!empty($SQL2)) && (empty($WHO))) {
185         $result_bonus = sqlQuery($SQL2, __FILE__, __LINE__);
186 } // END - if
187
188 // Calculate pages
189 $numPages = '0';
190 if (isConfigEntrySet('mails_page')) {
191         $numPages = round(sqlNumRows($result_normal) / getMailsPage() + 0.3);
192 } // END - if
193
194 // Free result
195 sqlFreeResult($result_normal);
196
197 $MAIL = FALSE;
198 if (!ifSqlHasZeroNums($result_list)) {
199         // Init rows
200         $OUT = '';
201
202         // Walk through all entries
203         while ($content = sqlFetchArray($result_list)) {
204                 // Unconfirmed mails and sent mails
205                 $result_uncon = sqlQueryEscaped("SELECT (`max_rec` - `clicks`) AS `unconfirmed` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
206                         array(bigintval($content['id'])), __FILE__, __LINE__);
207
208                 // Load and merge data
209                 $content = merge_array($content, sqlFetchArray($result_uncon));
210
211                 // Free result
212                 sqlFreeResult($result_uncon);
213
214                 // Unconfirmed mails
215                 $content['unconfirmed'] = generateUnconfirmedAdminLink($content['id'], ($content['unconfirmed']), 'normal');
216
217                 // Prepare content
218                 $content['timestamp']   = generateDateTime($content['timestamp'], 0);
219
220                 // Load row template
221                 $OUT .= loadTemplate('admin_list_emails_row', TRUE, $content);
222         } // END - while
223
224         // Free memory
225         sqlFreeResult($result_list);
226
227         // Add navigation (with change box and colspan=3)
228         $content['nav'] = addEmailNavigation($numPages, getMailsPage(), FALSE, 3, TRUE);
229
230         // Prepare content
231         $content['rows'] = $OUT;
232         $content['who'] = $WHO;
233
234         // Mail orders are in pool so we can display them
235         loadTemplate('admin_list_emails', FALSE, $content);
236
237         $MAIL = TRUE;
238         if ((isExtensionActive('bonus')) && (empty($WHO))) {
239                 // Only check if bonus extension is active
240                 if (!ifSqlHasZeroNums($result_bonus)) outputHtml('<br /><br />');
241         } // END - if
242 } // END - if
243
244 if ((isExtensionActive('bonus')) && (empty($WHO))) {
245         // Load bonus mails only when extension is active
246         if (!ifSqlHasZeroNums($result_bonus)) {
247                 // Calculate pages
248                 $numPages = round(sqlNumRows($result_bonus) / getMailsPage() + 0.5);
249
250                 // List emails
251                 $OUT = '';
252                 while ($content = sqlFetchArray($result_bonus)) {
253                         // Add link to list_unconfirmed what-file
254                         $content['unconfirmed'] = generateUnconfirmedAdminLink($content['id'], $content['unconfirmed'], 'bonus');
255
256                         // Prepare content
257                         $content['timestamp']   = generateDateTime($content['timestamp'], 0);
258
259                         // Load row template
260                         $OUT .= loadTemplate('admin_list_bonus_emails_row', TRUE, $content);
261                 } // END - while
262
263                 // Add navigation (without change box but with colspan=3)
264                 $content['nav'] = addEmailNavigation($numPages, getMailsPage(), FALSE, 3, TRUE);
265
266                 // Prepare content
267                 $content['rows'] = $OUT;
268
269                 // Load main template
270                 loadTemplate('admin_list_bonus_emails', FALSE, $content);
271                 $MAIL = TRUE;
272         } // END - if
273 } // END - if
274
275 if ($MAIL === FALSE) {
276         // No mail orders fond
277         displayMessage('{--ADMIN_NO_MAILS_IN_POOL--}');
278 } // END - if
279
280 // [EOF]
281 ?>