A lot more naming conventions applied
[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 ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN()))
46 {
47         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
48         require($INC);
49 }
50
51 // Add description as navigation point
52 ADD_DESCR("admin", basename(__FILE__));
53
54 // Normal mails ordered by your members
55 //              0     1       2       3       4           5          6          7       8        9          10
56 $SQL = "SELECT id, sender, subject, text, receivers, payment_id, data_type, timestamp, url, target_send, cat_id
57  FROM "._MYSQL_PREFIX."_pool
58  WHERE data_type IN('ADMIN', 'TEMP', 'NEW', 'ACTIVE')
59  ORDER BY timestamp DESC";
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 {
86         // Bonus mails sent by you
87         //               0     1       2        3        4      5       6          7       8      9         10          11        12
88         $SQL2 = "SELECT id, subject, text, receivers, points, time, data_type, timestamp, url, cat_id, target_send, mails_sent, clicks
89          FROM "._MYSQL_PREFIX."_bonus
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 {
127         // Mail orders are in pool so we can display them
128         OUTPUT_HTML("<DIV align=\"center\">
129 <TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"admin_table dashed\" width=\"99%\">
130 <TR>
131   <TD colspan=\"3\" align=\"center\" height=\"25\" class=\"admin_title\">
132     <STRONG class=\"admin_done\">".ADMIN_POOL_CONTENT." (".$WHO.")</STRONG>
133   </TD>
134 </TR>");
135
136         // Add navigation (with change box and colspan=3)
137         if ($PAGES > 1) ADD_EMAIL_NAV($PAGES, $CONFIG['mails_page'], false, "3");
138
139         while ($pool = SQL_FETCHROW($result_list))
140         {
141                 // Unconfirmed mails and sent mails
142                 $result_uncon = SQL_QUERY_ESC("SELECT max_rec, clicks FROM "._MYSQL_PREFIX."_user_stats WHERE pool_id=%d LIMIT 1",
143                  array(bigintval($pool[0])), __FILE__, __LINE__);
144                 list($sent, $clicks) = SQL_FETCHROW($result_uncon);
145                 SQL_FREERESULT($result_uncon);
146
147                 // Unconfirmed mails
148                 $unconfirmed = $sent - $clicks;
149                 if ($unconfirmed > 0)
150                 {
151                         // Add link to list_unconfirmed what-file
152                         $unconfirmed = "<STRONG><A href=\"".URL."/modules.php?module=admin&amp;what=list_unconfirmed&amp;mid=".$pool[0]."\">".$unconfirmed."</A></STRONG>";
153                 }
154                  elseif ($unconfirmed < 0)
155                 {
156                         // Sometimes rarely displayed minus values will be "fixed" to zero
157                         $unconfirmed = "0";
158                 }
159
160                 // List mail
161                 OUTPUT_HTML("<TR>
162   <TD class=\"bottom top2 right\" width=\"23%\" align=\"center\">
163     ".EMAIL_SENDER.":<BR>
164     <STRONG class=\"admin_misc\">".ADMIN_USER_PROFILE_LINK($pool[1])."</STRONG>
165   </TD>
166   <TD class=\"bottom top2 right\" width=\"23%\" align=\"center\">
167     ".EMAIL_SUBJECT.":<BR>
168     <STRONG class=\"admin_misc\">".COMPILE_CODE($pool[2])."</STRONG>
169   </TD>
170   <TD class=\"bottom top2\" width=\"54%\" align=\"center\">
171     ".EMAIL_TEXT.":<BR>
172     <STRONG class=\"admin_misc\">".COMPILE_CODE($pool[3])."</STRONG>
173   </TD>
174 </TR>
175 <TR><TD height=\"5\" colspan=\"3\"></TD></TR>
176 <TR>
177   <TD colspan=\"2\" align=\"center\" class=\"top bottom right\">
178     ".EMAIL_PAYMENT.":<BR>
179     <STRONG class=\"admin_misc\">".GET_PAYMENT($pool[5])."
180   </TD>
181   <TD align=\"center\" class=\"top bottom\">
182     ".EMAIL_CATEGORY.":<BR>
183     <STRONG class=\"admin_misc\">".GET_CATEGORY($pool[10])."
184   </TD>
185 </TR>
186 <TR><TD height=\"5\" colspan=\"3\"></TD></TR>
187 <TR>
188   <TD align=\"center\" class=\"top bottom right\">
189     ".EMAIL_RECEIVERS.":<BR>
190     <STRONG class=\"admin_misc\">".$sent."</STRONG> (".EMAIL_RUIDS.": <STRONG class=\"admin_misc\">".str_replace(";", ", ", $pool[4])."</STRONG>)
191   </TD>
192   <TD align=\"center\" class=\"top bottom right\">
193     ".USERS_LINKS.":<BR>
194     <STRONG class=\"admin_misc\">".$unconfirmed."</STRONG>
195   </TD>
196   <TD align=\"center\" class=\"top bottom\">
197     ".EMAIL_POOL_TYPE.":<BR>
198     <STRONG class=\"admin_misc\">".GET_POOL_TYPE($pool[6])."</STRONG>
199   </TD>
200 </TR>
201 <TR><TD height=\"5\" colspan=\"3\"></TD></TR>
202 <TR>
203   <TD align=\"center\" class=\"top right\">
204     ".EMAIL_TSEND.":<BR>
205     <STRONG class=\"admin_misc\">".$pool[9]."</STRONG>
206   </TD>
207   <TD align=\"center\" class=\"top right\">
208     ".EMAIL_URL.":<BR>
209     <STRONG class=\"admin_misc\"><A href=\"".FRAMETESTER($pool[8])."\" target=\"_blank\">".EMAIL_URL_TEST."</A></STRONG>
210   </TD>
211   <TD align=\"center\" class=\"top\">
212     ".EMAIL_TIMESTAMP.":<BR>
213     <STRONG class=\"admin_misc\">".MAKE_DATETIME($pool[7], "0")."</STRONG>
214   </TD>
215 </TR>
216 <TR>
217   <TD align=\"center\" class=\"top2 admin_del_link\" colspan=\"3\">
218     <A href=\"".URL."/modules.php?module=admin&amp;what=del_email&amp;mid=".$pool[0]."\">".ADMIN_DELETE_NORMAL_MAIL."</A>
219   </TD>
220 </TR>");
221         }
222
223         // Free memory
224         SQL_FREERESULT($result_list);
225
226         // Add navigation (without change box but with colspan=3)
227         if ($PAGES > 1) ADD_EMAIL_NAV($PAGES, $CONFIG['mails_page'], false, "3");
228
229         // Output footer
230         OUTPUT_HTML("</TABLE>
231 </DIV>");
232         $MAIL = true;
233         if ((EXT_IS_ACTIVE("bonus")) && ($WHO == _ALL))
234         {
235                 // Check only if bonus extension is active
236                 if (SQL_NUMROWS($result_bonus) > 0) OUTPUT_HTML("<BR><BR>");
237         }
238 }
239
240 if ((EXT_IS_ACTIVE("bonus")) && ($WHO == _ALL))
241 {
242         // Load bonus mails only when extension is active
243         if (SQL_NUMROWS($result_bonus) > 0)
244         {
245                 // Mail orders are in pool so we can display them
246                 OUTPUT_HTML("<DIV align=\"center\">
247 <TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"admin_table dashed\" width=\"99%\">
248 <TR>
249   <TD colspan=\"3\" align=\"center\" height=\"25\" class=\"admin_title\">
250     <STRONG class=\"admin_done\">".ADMIN_BONUS_CONTENT."</STRONG>
251   </TD>
252 </TR>");
253                 // Calculate pages
254                 $PAGES = round(SQL_NUMROWS($result_bonus) / $CONFIG['mails_page'] + 0.5);
255
256                 // Add navigation (with change box and colspan=3)
257                 if ($PAGES > 1) ADD_EMAIL_NAV($PAGES, $CONFIG['mails_page'], true, "3");
258
259                 // List emails
260                 while ($bonus = SQL_FETCHROW($result_bonus))
261                 {
262                         // Unconfirmed mails
263                         $unconfirmed = $bonus[11] - $bonus[12];
264                         if ($unconfirmed > 0)
265                         {
266                                 // Add link to list_unconfirmed what-file
267                                 $unconfirmed = "<STRONG><A href=\"".URL."/modules.php?module=admin&amp;what=list_unconfirmed&amp;bid=".$bonus[0]."\">".$unconfirmed."</A></STRONG>";
268                         }
269
270                         OUTPUT_HTML("<TR>
271   <TD class=\"bottom top2 right\" colspan=\"2\" width=\"46%\" align=\"center\">
272     ".EMAIL_SUBJECT.":<BR>
273     <STRONG class=\"admin_misc\">".$bonus[1]."</STRONG>
274   </TD>
275   <TD class=\"bottom top2\" width=\"54%\" align=\"center\">
276     ".EMAIL_TEXT.":<BR>
277     <STRONG class=\"admin_misc\">".$bonus[2]."</STRONG>
278   </TD>
279 </TR>
280 <TR><TD height=\"5\" colspan=\"3\"></TD></TR>
281 <TR>
282   <TD align=\"center\" class=\"top bottom right\" width=\"23%\">
283     ".EMAIL_POINTS.":<BR>
284     <STRONG class=\"admin_misc\">".$bonus[4]." ".POINTS."
285   </TD>
286   <TD align=\"center\" class=\"top bottom right\" width=\"23%\">
287     ".EMAIL_SECONDS.":<BR>
288     <STRONG class=\"admin_misc\">".$bonus[5]." ".SECS."
289   </TD>
290   <TD align=\"center\" class=\"top bottom\">
291     ".EMAIL_CATEGORY.":<BR>
292     <STRONG class=\"admin_misc\">".GET_CATEGORY($bonus[9])."
293   </TD>
294 </TR>
295 <TR><TD height=\"5\" colspan=\"3\"></TD></TR>
296 <TR>
297   <TD align=\"center\" class=\"top bottom right\">
298     ".EMAIL_RECEIVERS.":<BR>
299     <STRONG class=\"admin_misc\">".$bonus[11]."</STRONG> (".EMAIL_RUIDS.": <STRONG class=\"admin_misc\">".str_replace(";", ", ", $bonus[3])."</STRONG>)
300   </TD>
301   <TD align=\"center\" class=\"top bottom right\">
302     ".USERS_LINKS.":<BR>
303     <STRONG class=\"admin_misc\">".$unconfirmed."</STRONG>
304   </TD>
305   <TD align=\"center\" class=\"top bottom\">
306     ".EMAIL_POOL_TYPE.":<BR>
307     <STRONG class=\"admin_misc\">".GET_POOL_TYPE($bonus[6])."</STRONG>
308   </TD>
309 </TR>
310 <TR><TD height=\"5\" colspan=\"3\"></TD></TR>
311 <TR>
312   <TD align=\"center\" class=\"top right\">
313     ".EMAIL_TSEND.":<BR>
314     <STRONG class=\"admin_misc\">".$bonus[10]."</STRONG>
315   </TD>
316   <TD align=\"center\" class=\"top right\">
317     ".EMAIL_URL.":<BR>
318     <STRONG class=\"admin_misc\"><A href=\"".FRAMETESTER($bonus[8])."\" target=\"_blank\">".EMAIL_URL_TEST."</A></STRONG>
319   </TD>
320   <TD align=\"center\" class=\"top\">
321     ".EMAIL_TIMESTAMP.":<BR>
322     <STRONG class=\"admin_misc\">".MAKE_DATETIME($bonus[7], "0")."</STRONG>
323   </TD>
324 </TR>
325 <TR>
326   <TD align=\"center\" class=\"top2 admin_del_link\" colspan=\"3\">
327     <A href=\"".URL."/modules.php?module=admin&amp;what=del_email&amp;bid=".$bonus[0]."\">".ADMIN_DELETE_BONUS_MAIL."</A>
328   </TD>
329 </TR>");
330                 }
331
332                 // Add navigation (without change box but with colspan=3)
333                 if ($PAGES > 1) ADD_EMAIL_NAV($PAGES, $CONFIG['mails_page'], false, "3");
334
335                 // Output footer
336                 OUTPUT_HTML("</TABLE>
337 </DIV>");
338                 $MAIL = true;
339         }
340 }
341
342 if (!$MAIL)
343 {
344         // No mail orders fond
345         OUTPUT_HTML("<SPAN class=\"admin_failed\">".ADMIN_NO_MAILS_IN_POOL."</SPAN>");
346 }
347 //
348 ?>