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