All database names are now 'back-ticked' and constant _MYSQL_PREFIX is wrapped. Partl...
[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 (!empty($_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($_GET['mid'])."'
69          LIMIT 1";
70         $WHO = MAIL_ID.": ".$_GET['mid'];
71 } elseif (!empty($_GET['u_id'])) {
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($_GET['u_id'])."'
77 ORDER by timestamp DESC";
78         $WHO = USER_ID.": ".$_GET['u_id'];
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 (empty($_GET['page']))   $_GET['page']   = "1";
98 if (empty($_GET['offset'])) $_GET['offset'] = getConfig('mails_page');
99
100 // Add limitation to SQL string
101 if (empty($_GET['mid'])) {
102         // Create limitation line
103         $ADD = " LIMIT ".(bigintval($_GET['offset']) * bigintval($_GET['page']) - bigintval($_GET['offset'])).", ".bigintval($_GET['offset']);
104
105         // For normal mails
106         $SQL .= $ADD;
107
108         // For bonus mails
109         if (!empty($SQL2)) $SQL2 .= $ADD;
110 } // END - if
111
112 // Run SQL query for normal mails
113 $result_list = SQL_QUERY($SQL, __FILE__, __LINE__);
114 if ((!empty($SQL2)) && ($WHO == _ALL)) $result_bonus = SQL_QUERY($SQL2, __FILE__, __LINE__);
115
116 // Calculate pages
117 $PAGES = round(SQL_NUMROWS($result_normal) / getConfig('mails_page') + 0.3);
118 SQL_FREERESULT($result_normal);
119
120 $MAIL = false;
121 if (SQL_NUMROWS($result_list) > 0) {
122         // Init rows
123         $OUT = ""; $content = array();
124
125         // Walk through all entries
126         while ($pool = SQL_FETCHARRAY($result_list)) {
127                 // Unconfirmed mails and sent mails
128                 $result_uncon = SQL_QUERY_ESC("SELECT max_rec, clicks FROM `{!MYSQL_PREFIX!}_user_stats` WHERE pool_id=%s LIMIT 1",
129                  array(bigintval($pool['id'])), __FILE__, __LINE__);
130                 list($pool['sent_email'], $pool['clicks']) = SQL_FETCHROW($result_uncon);
131                 SQL_FREERESULT($result_uncon);
132
133                 // Unconfirmed mails
134                 $pool['unconfirmed'] = $pool['sent_email'] - $pool['clicks'];
135                 if ($pool['unconfirmed'] > 0) {
136                         // Add link to list_unconfirmed what-file
137                         $pool['unconfirmed'] = "<strong><a href=\"".URL."/modules.php?module=admin&amp;what=list_unconfirmed&amp;mid=".$pool['id']."\">".$pool['unconfirmed']."</a></strong>";
138                 } elseif ($pool['unconfirmed'] < 0) {
139                         // Sometimes rarely displayed minus values will be "fixed" to zero
140                         $pool['unconfirmed'] = 0;
141                 }
142
143                 // Prepare content
144                 $content = $pool;
145                 $content['sender_link'] = ADMIN_USER_PROFILE_LINK($pool['sender']);
146                 $content['subject']     = COMPILE_CODE($pool['subject']);
147                 $content['text']        = COMPILE_CODE($pool['text']);
148                 $content['payment']     = GET_PAYMENT($pool['payment_id']);
149                 $content['category']    = GET_CATEGORY($pool['cat_id']);
150                 $content['receivers']   = str_replace(";", ", ", $pool['receivers']);
151                 $content['type']        = TRANSLATE_POOL_TYPE($pool['data_type']);
152                 $content['frametester'] = FRAMETESTER($pool['url']);
153                 $content['url']         = COMPILE_CODE($pool['url']);
154                 $content['timestamp']   = MAKE_DATETIME($pool['timestamp'], "0");
155
156                 // Load row template
157                 $OUT .= LOAD_TEMPLATE("admin_list_emails_row", true, $content);
158         } // END - while
159
160         // Free memory
161         SQL_FREERESULT($result_list);
162
163         // Add navigation (with change box and colspan=3)
164         $content['nav'] = "";
165         if ($PAGES > 1) $content['nav'] = ADD_EMAIL_NAV($PAGES, getConfig('mails_page'), false, "3", true);
166
167         // Prepare content
168         $content['rows'] = $OUT;
169         $content['who'] = $WHO;
170
171         // Mail orders are in pool so we can display them
172         LOAD_TEMPLATE("admin_list_emails", false, $content);
173
174         $MAIL = true;
175         if ((EXT_IS_ACTIVE("bonus")) && ($WHO == _ALL)) {
176                 // Check only if bonus extension is active
177                 if (SQL_NUMROWS($result_bonus) > 0) OUTPUT_HTML("<br /><br />");
178         }
179 }
180
181 if ((EXT_IS_ACTIVE("bonus")) && ($WHO == _ALL)) {
182         // Load bonus mails only when extension is active
183         if (SQL_NUMROWS($result_bonus) > 0) {
184                 // Calculate pages
185                 $PAGES = round(SQL_NUMROWS($result_bonus) / getConfig('mails_page') + 0.5);
186
187                 // List emails
188                 $OUT = ""; $content = array();
189                 while ($bonus = SQL_FETCHARRAY($result_bonus)) {
190                         // Calculate unconfirmed emails
191                         $bonus['unconfirmed'] = $bonus['mails_sent'] - $bonus['clicks'];
192
193                         // Add link?
194                         if ($bonus['unconfirmed'] > 0) {
195                                 // Add link to list_unconfirmed what-file
196                                 $bonus['unconfirmed'] = "<strong><a href=\"".URL."/modules.php?module=admin&amp;what=list_unconfirmed&amp;bid=".$bonus['id']."\">".$bonus['unconfirmed']."</a></strong>";
197                         } // END - if
198
199                         // Prepare content
200                         $content = $bonus;
201                         $content['time']        = CREATE_FANCY_TIME($content['time']);
202                         $content['category']    = GET_CATEGORY($content['cat_id']);
203                         $content['receivers']   = str_replace(";", ", ", $content['receivers']);
204                         $content['type']        = TRANSLATE_POOL_TYPE($content['data_type']);
205                         $content['frametester'] = FRAMETESTER($content['url']);
206                         $content['timestamp']   = MAKE_DATETIME($content['timestamp'], "0");
207
208                         // Load row template
209                         $OUT .= LOAD_TEMPLATE("admin_list_bonus_emails_row", true, $content);
210                 } // END - while
211
212                 // Add navigation (without change box but with colspan=3)
213                 $content['nav'] = "";
214                 if ($PAGES > 1) $content['nav'] = ADD_EMAIL_NAV($PAGES, getConfig('mails_page'), false, "3", true);
215
216                 // Prepare content
217                 $content['rows'] = $OUT;
218
219                 // Load main template
220                 LOAD_TEMPLATE("admin_list_bonus_emails", false, $content);
221                 $MAIL = true;
222         } // END - if
223 } // END - if
224
225 if (!$MAIL) {
226         // No mail orders fond
227         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NO_MAILS_IN_POOL);
228 } // END - if
229
230 //
231 ?>