New extension added, more EL-rewrites, naming-convention applied:
[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  * 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 - 2009 by Roland Haeder                           *
21  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  * -------------------------------------------------------------------- *
39  *           Moded What-email_details.php   / also Editet !             *
40  * Auf langsammen Servern (wie mein z.B Dauert das Laden)               *
41  * enorm hoch zu lang. Jetzt werden nur auftraege aufgelistet die       *
42  * NEU sind ( DB NEW) oder ADMIN freischalten muss (DB ADMIN )          *
43  * oder noch als TEMP gespecihert sind                                  *
44  * der rest der schon als SEND sich melden darf wird per                *
45  * what-email_archiv .php aufgerufen                                    *
46  * beste gruesse Robert Niedziela / www.personal-webserver.de           *
47  * oder auch www.mc-p.org                                               *
48  ************************************************************************/
49
50 // Some security stuff...
51 if ((!defined('__SECURITY')) || (!isAdmin())) {
52         die();
53 }
54
55 // Add description as navigation point
56 addMenuDescription('admin', __FILE__);
57
58 // Normal mails ordered by your members
59 $sql = "SELECT
60         `id`, `sender`, `subject`, `text`, `receivers`, `payment_id`, `data_type`, `timestamp`, `url`, `target_send`, `cat_id`
61 FROM
62         `{?_MYSQL_PREFIX?}_pool`
63 WHERE
64         `data_type` IN('ADMIN','TEMP','NEW','ACTIVE')
65 ORDER BY
66         `timestamp` DESC";
67
68 $WHO = getMessage('_ALL');
69 $SQL2 = '';
70
71 if (isGetRequestParameterSet(('mid'))) {
72         // Only a specific mail shall be displayed
73         $sql = "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         `id`='".bigintval(getRequestParameter('mid'))."'
79 LIMIT 1";
80         $WHO = getMessage('MAIL_ID') . ': ' . getRequestParameter('mid');
81 } elseif (isGetRequestParameterSet('userid')) {
82         // All mails by a specific member shall be displayed
83         $sql = "SELECT
84         `id`, `sender`, `subject`, `text`, `receivers`, `payment_id`, `data_type`, `timestamp`, `url`, `target_send`, `cat_id`
85 FROM
86         `{?_MYSQL_PREFIX?}_pool`
87 WHERE
88         `sender`='".bigintval(getRequestParameter('userid'))."'
89 ORDER BY
90         `timestamp` DESC";
91         $WHO = getMessage('USER_ID') . ': ' . getRequestParameter('userid');
92 }
93
94 // Init result_bonus
95 $result_bonus = false;
96
97 if ((isExtensionActive('bonus')) && ($WHO == getMessage('_ALL'))) {
98         // Check for maximum pages
99         $result_bonus = SQL_QUERY("SELECT
100         `id`, `subject`, `text`, `receivers`, `points`, `time`, `data_type`, `timestamp`, `url`, `cat_id`, `target_send`, `mails_sent`, `clicks`
101         (`mails_sent` - `clicks`) AS `unconfirmed`
102 FROM
103         `{?_MYSQL_PREFIX?}_bonus`
104 WHERE
105         `is_notify`='N'
106 ORDER BY
107         `timestamp` DESC", __FILE__, __LINE__);
108 }
109
110 // Check for maximum pages
111 $result_normal = SQL_QUERY($sql, __FILE__, __LINE__);
112
113 // Set offset an current page to default values
114 if (!isGetRequestParameterSet('page')) setGetRequestParameter('page', 1);
115
116 if (!isGetRequestParameterSet('offset')) {
117         if (isConfigEntrySet('mails_page')) {
118                 // Set config entry
119                 setGetRequestParameter('offset', getConfig('mails_page'));
120         } else {
121                 // Set default one
122                 setGetRequestParameter('offset', 10);
123         }
124 } // END - if
125
126 // Add limitation to SQL string
127 if (!isGetRequestParameterSet(('mid'))) {
128         // Create limitation line
129         $add = ' LIMIT ' . (bigintval(getRequestParameter('offset')) * bigintval(getRequestParameter('page')) - bigintval(getRequestParameter('offset'))) . ', ' . bigintval(getRequestParameter('offset'));
130
131         // For normal mails
132         $sql .= $add;
133
134         // For bonus mails
135         if (!empty($SQL2)) $SQL2 .= $add;
136 } // END - if
137
138 // Run SQL query for normal mails
139 $result_list = SQL_QUERY($sql, __FILE__, __LINE__);
140 if ((!empty($SQL2)) && ($WHO == getMessage('_ALL'))) $result_bonus = SQL_QUERY($SQL2, __FILE__, __LINE__);
141
142 // Calculate pages
143 $numPages = '0';
144 if (isConfigEntrySet('mails_page')) {
145         $numPages = round(SQL_NUMROWS($result_normal) / getConfig('mails_page') + 0.3);
146 } // END - if
147
148 // Free result
149 SQL_FREERESULT($result_normal);
150
151 $MAIL = false;
152 if (SQL_NUMROWS($result_list) > 0) {
153         // Init rows
154         $OUT = '';
155
156         // Walk through all entries
157         while ($content = SQL_FETCHARRAY($result_list)) {
158                 // Unconfirmed mails and sent mails
159                 $result_uncon = SQL_QUERY_ESC("SELECT (`max_rec` - `clicks`) AS `unconfirmed` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
160                         array(bigintval($content['id'])), __FILE__, __LINE__);
161
162                 // Load and merge data
163                 $content = merge_array($content, SQL_FETCHARRAY($result_uncon));
164
165                 // Free result
166                 SQL_FREERESULT($result_uncon);
167
168                 // Unconfirmed mails
169                 $content['unconfirmed'] = generateUnconfirmedAdminLink($content['id'], ($content['unconfirmed']), 'mid');
170
171                 // Prepare content
172                 $content['timestamp']   = generateDateTime($content['timestamp'], 0);
173
174                 // Load row template
175                 $OUT .= loadTemplate('admin_list_emails_row', true, $content);
176         } // END - while
177
178         // Free memory
179         SQL_FREERESULT($result_list);
180
181         // Add navigation (with change box and colspan=3)
182         $content['nav'] = addEmailNavigation($numPages, getConfig('mails_page'), false, 3, true);
183
184         // Prepare content
185         $content['rows'] = $OUT;
186         $content['who'] = $WHO;
187
188         // Mail orders are in pool so we can display them
189         loadTemplate('admin_list_emails', false, $content);
190
191         $MAIL = true;
192         if ((isExtensionActive('bonus')) && ($WHO == getMessage('_ALL'))) {
193                 // Only check if bonus extension is active
194                 if (SQL_NUMROWS($result_bonus) > 0) outputHtml('<br /><br />');
195         } // END - if
196 }
197
198 if ((isExtensionActive('bonus')) && ($WHO == getMessage('_ALL'))) {
199         // Load bonus mails only when extension is active
200         if (SQL_NUMROWS($result_bonus) > 0) {
201                 // Calculate pages
202                 $numPages = round(SQL_NUMROWS($result_bonus) / getConfig('mails_page') + 0.5);
203
204                 // List emails
205                 $OUT = '';
206                 while ($content = SQL_FETCHARRAY($result_bonus)) {
207                         // Add link to list_unconfirmed what-file
208                         $content['unconfirmed'] = generateUnconfirmedAdminLink($content['id'], $content['unconfirmed']);
209
210                         // Prepare content
211                         $content['timestamp']   = generateDateTime($content['timestamp'], 0);
212
213                         // Load row template
214                         $OUT .= loadTemplate('admin_list_bonus_emails_row', true, $content);
215                 } // END - while
216
217                 // Add navigation (without change box but with colspan=3)
218                 $content['nav'] = addEmailNavigation($numPages, getConfig('mails_page'), false, 3, true);
219
220                 // Prepare content
221                 $content['rows'] = $OUT;
222
223                 // Load main template
224                 loadTemplate('admin_list_bonus_emails', false, $content);
225                 $MAIL = true;
226         } // END - if
227 } // END - if
228
229 if ($MAIL === false) {
230         // No mail orders fond
231         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_MAILS_IN_POOL'));
232 } // END - if
233
234 // [EOF]
235 ?>