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