Renamed function so it might be more understandable
[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  *           Moded What-email_details.php   / also Editet !             *
38  * Auf langsammen Servern (wie mein z.B Dauert das Laden)               *
39  * enorm hoch zu lang. Jetzt werden nur auftraege aufgelistet die       *
40  * NEU sind ( DB NEW) oder ADMIN freischalten muss (DB ADMIN )          *
41  * oder noch als TEMP gespecihert sind                                  *
42  * der rest der schon als SEND sich melden darf wird per                *
43  * what-email_archiv .php aufgerufen                                    *
44  * beste gruesse Robert Niedziela / www.personal-webserver.de           *
45  * oder auch www.mc-p.org                                               *
46  ************************************************************************/
47
48 // Some security stuff...
49 if ((!defined('__SECURITY')) || (!isAdmin())) {
50         die();
51 } // END - if
52
53 // Add description as navigation point
54 addYouAreHereLink('admin', __FILE__);
55
56 // Normal mails ordered by your members
57 $sql = "SELECT
58         `id`, `sender`, `subject`, `text`, `receivers`, `payment_id`, `data_type`, `timestamp`, `url`, `target_send`, `cat_id`
59 FROM
60         `{?_MYSQL_PREFIX?}_pool`
61 WHERE
62         `data_type` IN('ADMIN','TEMP','NEW','ACTIVE')
63 ORDER BY
64         `timestamp` DESC";
65
66 $WHO = '';
67 $SQL2 = '';
68
69 if (isGetRequestParameterSet('mid')) {
70         // Only a specific mail shall be displayed
71         $sql = sprintf("SELECT
72         `id`, `sender`, `subject`, `text`, `receivers`, `payment_id`, `data_type`, `timestamp`, `url`, `target_send`, `cat_id`
73 FROM
74         `{?_MYSQL_PREFIX?}_pool`
75 WHERE
76         `id`=%s
77 LIMIT 1",
78                 bigintval(getRequestParameter('mid'))
79         );
80         $WHO = '{--MAIL_ID--}' . ': ' . getRequestParameter('mid');
81 } elseif (isGetRequestParameterSet('userid')) {
82         // All mails by a specific member shall be displayed
83         $sql = sprintf("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`=%s
89 ORDER BY
90         `timestamp` DESC",
91                 bigintval(getRequestParameter('userid'))
92         );
93         $WHO = '{--USER_ID--}' . ': ' . getRequestParameter('userid');
94 }
95
96 // Init result_bonus
97 $result_bonus = false;
98
99 if ((isExtensionActive('bonus')) && (empty($WHO))) {
100         // Check for maximum pages
101         $result_bonus = SQL_QUERY("SELECT
102         `id`, `subject`, `text`, `receivers`, `points`, `time`, `data_type`, `timestamp`, `url`, `cat_id`, `target_send`, `mails_sent`, `clicks`,
103         (`mails_sent` - `clicks`) AS `unconfirmed`
104 FROM
105         `{?_MYSQL_PREFIX?}_bonus`
106 WHERE
107         `is_notify`='N'
108 ORDER BY
109         `timestamp` DESC", __FILE__, __LINE__);
110 }
111
112 // Check for maximum pages
113 $result_normal = SQL_QUERY($sql, __FILE__, __LINE__);
114
115 // Set offset an current page to default values
116 if (!isGetRequestParameterSet('page')) setGetRequestParameter('page', 1);
117
118 if (!isGetRequestParameterSet('offset')) {
119         if (isConfigEntrySet('mails_page')) {
120                 // Set config entry
121                 setGetRequestParameter('offset', getConfig('mails_page'));
122         } else {
123                 // Set default one
124                 setGetRequestParameter('offset', 10);
125         }
126 } // END - if
127
128 // Add limitation to SQL string
129 if (!isGetRequestParameterSet('mid')) {
130         // Create limitation line
131         $add = ' LIMIT ' . (bigintval(getRequestParameter('offset')) * bigintval(getRequestParameter('page')) - bigintval(getRequestParameter('offset'))) . ', ' . bigintval(getRequestParameter('offset'));
132
133         // For normal mails
134         $sql .= $add;
135
136         // For bonus mails
137         if (!empty($SQL2)) $SQL2 .= $add;
138 } // END - if
139
140 // Run SQL query for normal mails
141 $result_list = SQL_QUERY($sql, __FILE__, __LINE__);
142 if ((!empty($SQL2)) && (empty($WHO))) $result_bonus = SQL_QUERY($SQL2, __FILE__, __LINE__);
143
144 // Calculate pages
145 $numPages = '0';
146 if (isConfigEntrySet('mails_page')) {
147         $numPages = round(SQL_NUMROWS($result_normal) / getConfig('mails_page') + 0.3);
148 } // END - if
149
150 // Free result
151 SQL_FREERESULT($result_normal);
152
153 $MAIL = false;
154 if (!SQL_HASZERONUMS($result_list)) {
155         // Init rows
156         $OUT = '';
157
158         // Walk through all entries
159         while ($content = SQL_FETCHARRAY($result_list)) {
160                 // Unconfirmed mails and sent mails
161                 $result_uncon = SQL_QUERY_ESC("SELECT (`max_rec` - `clicks`) AS `unconfirmed` FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `pool_id`=%s LIMIT 1",
162                         array(bigintval($content['id'])), __FILE__, __LINE__);
163
164                 // Load and merge data
165                 $content = merge_array($content, SQL_FETCHARRAY($result_uncon));
166
167                 // Free result
168                 SQL_FREERESULT($result_uncon);
169
170                 // Unconfirmed mails
171                 $content['unconfirmed'] = generateUnconfirmedAdminLink($content['id'], ($content['unconfirmed']), 'mid');
172
173                 // Prepare content
174                 $content['timestamp']   = generateDateTime($content['timestamp'], 0);
175
176                 // Load row template
177                 $OUT .= loadTemplate('admin_list_emails_row', true, $content);
178         } // END - while
179
180         // Free memory
181         SQL_FREERESULT($result_list);
182
183         // Add navigation (with change box and colspan=3)
184         $content['nav'] = addEmailNavigation($numPages, getConfig('mails_page'), false, 3, true);
185
186         // Prepare content
187         $content['rows'] = $OUT;
188         $content['who'] = $WHO;
189
190         // Mail orders are in pool so we can display them
191         loadTemplate('admin_list_emails', false, $content);
192
193         $MAIL = true;
194         if ((isExtensionActive('bonus')) && (empty($WHO))) {
195                 // Only check if bonus extension is active
196                 if (!SQL_HASZERONUMS($result_bonus)) outputHtml('<br /><br />');
197         } // END - if
198 } // END - if
199
200 if ((isExtensionActive('bonus')) && (empty($WHO))) {
201         // Load bonus mails only when extension is active
202         if (!SQL_HASZERONUMS($result_bonus)) {
203                 // Calculate pages
204                 $numPages = round(SQL_NUMROWS($result_bonus) / getConfig('mails_page') + 0.5);
205
206                 // List emails
207                 $OUT = '';
208                 while ($content = SQL_FETCHARRAY($result_bonus)) {
209                         // Add link to list_unconfirmed what-file
210                         $content['unconfirmed'] = generateUnconfirmedAdminLink($content['id'], $content['unconfirmed']);
211
212                         // Prepare content
213                         $content['timestamp']   = generateDateTime($content['timestamp'], 0);
214
215                         // Load row template
216                         $OUT .= loadTemplate('admin_list_bonus_emails_row', true, $content);
217                 } // END - while
218
219                 // Add navigation (without change box but with colspan=3)
220                 $content['nav'] = addEmailNavigation($numPages, getConfig('mails_page'), false, 3, true);
221
222                 // Prepare content
223                 $content['rows'] = $OUT;
224
225                 // Load main template
226                 loadTemplate('admin_list_bonus_emails', false, $content);
227                 $MAIL = true;
228         } // END - if
229 } // END - if
230
231 if ($MAIL === false) {
232         // No mail orders fond
233         loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_MAILS_IN_POOL--}');
234 } // END - if
235
236 // [EOF]
237 ?>