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