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