A lot double-quotes rewritten to single-quotes, some redirect URLs fixed
[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 - 2008 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')) || (!IS_ADMIN())) {
51         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
52         require($INC);
53 }
54
55 // Add description as navigation point
56 ADD_DESCR('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 = _ALL;
66 $SQL2 = '';
67
68 if (REQUEST_ISSET_GET(('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(REQUEST_GET('mid'))."'
74          LIMIT 1";
75         $WHO = MAIL_ID.": ".REQUEST_GET('mid');
76 } elseif (REQUEST_ISSET_GET('uid')) {
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(REQUEST_GET('uid'))."'
82 ORDER by timestamp DESC";
83         $WHO = USER_ID.": ".REQUEST_GET('uid');
84 }
85
86 if ((EXT_IS_ACTIVE('bonus')) && ($WHO == _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 (!REQUEST_ISSET_GET('page')) REQUEST_SET_GET('page', "1");
103
104 if (!REQUEST_ISSET_GET('offset')) {
105         if (isConfigEntrySet('mails_page')) {
106                 // Set config entry
107                 REQUEST_SET_GET('offset', getConfig('mails_page'));
108         } else {
109                 // Set default one
110                 REQUEST_SET_GET('offset', 10);
111         }
112 } // END - if
113
114 // Add limitation to SQL string
115 if (!REQUEST_ISSET_GET(('mid'))) {
116         // Create limitation line
117         $add = " LIMIT ".(bigintval(REQUEST_GET('offset')) * bigintval(REQUEST_GET('page')) - bigintval(REQUEST_GET('offset'))).", ".bigintval(REQUEST_GET('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 == _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'] = ADMIN_USER_PROFILE_LINK($pool['sender']);
165                 $content['subject']     = COMPILE_CODE($pool['subject']);
166                 $content['text']        = COMPILE_CODE($pool['text']);
167                 $content['payment']     = GET_PAYMENT($pool['payment_id']);
168                 $content['category']    = GET_CATEGORY($pool['cat_id']);
169                 $content['receivers']   = str_replace(';', ", ", $pool['receivers']);
170                 $content['type']        = TRANSLATE_POOL_TYPE($pool['data_type']);
171                 $content['frametester'] = FRAMETESTER($pool['url']);
172                 $content['url']         = COMPILE_CODE($pool['url']);
173                 $content['timestamp']   = MAKE_DATETIME($pool['timestamp'], "0");
174
175                 // Load row template
176                 $OUT .= LOAD_TEMPLATE("admin_list_emails_row", true, $content);
177         } // END - while
178
179         // Free memory
180         SQL_FREERESULT($result_list);
181
182         // Add navigation (with change box and colspan=3)
183         $content['nav'] = '';
184         if ($PAGES > 1) $content['nav'] = ADD_EMAIL_NAV($PAGES, 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         LOAD_TEMPLATE("admin_list_emails", false, $content);
192
193         $MAIL = true;
194         if ((EXT_IS_ACTIVE('bonus')) && ($WHO == _ALL)) {
195                 // Check only if bonus extension is active
196                 if (SQL_NUMROWS($result_bonus) > 0) OUTPUT_HTML("<br /><br />");
197         }
198 }
199
200 if ((EXT_IS_ACTIVE('bonus')) && ($WHO == _ALL)) {
201         // Load bonus mails only when extension is active
202         if (SQL_NUMROWS($result_bonus) > 0) {
203                 // Calculate pages
204                 $PAGES = round(SQL_NUMROWS($result_bonus) / getConfig('mails_page') + 0.5);
205
206                 // List emails
207                 $OUT = ''; $content = array();
208                 while ($bonus = SQL_FETCHARRAY($result_bonus)) {
209                         // Calculate unconfirmed emails
210                         $bonus['unconfirmed'] = $bonus['mails_sent'] - $bonus['clicks'];
211
212                         // Add link?
213                         if ($bonus['unconfirmed'] > 0) {
214                                 // Add link to list_unconfirmed what-file
215                                 $bonus['unconfirmed'] = "<strong><a href=\"{!URL!}/modules.php?module=admin&amp;what=list_unconfirmed&amp;bid=".$bonus['id']."\">".$bonus['unconfirmed']."</a></strong>";
216                         } // END - if
217
218                         // Prepare content
219                         $content = $bonus;
220                         $content['time']        = CREATE_FANCY_TIME($content['time']);
221                         $content['category']    = GET_CATEGORY($content['cat_id']);
222                         $content['receivers']   = str_replace(';', ", ", $content['receivers']);
223                         $content['type']        = TRANSLATE_POOL_TYPE($content['data_type']);
224                         $content['frametester'] = FRAMETESTER($content['url']);
225                         $content['timestamp']   = MAKE_DATETIME($content['timestamp'], "0");
226
227                         // Load row template
228                         $OUT .= LOAD_TEMPLATE("admin_list_bonus_emails_row", true, $content);
229                 } // END - while
230
231                 // Add navigation (without change box but with colspan=3)
232                 $content['nav'] = '';
233                 if ($PAGES > 1) $content['nav'] = ADD_EMAIL_NAV($PAGES, getConfig('mails_page'), false, "3", true);
234
235                 // Prepare content
236                 $content['rows'] = $OUT;
237
238                 // Load main template
239                 LOAD_TEMPLATE("admin_list_bonus_emails", false, $content);
240                 $MAIL = true;
241         } // END - if
242 } // END - if
243
244 if (!$MAIL) {
245         // No mail orders fond
246         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_NO_MAILS_IN_POOL'));
247 } // END - if
248
249 //
250 ?>