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