Complete rewrite of and , wrapper functions added, see bug #101
[mailer.git] / inc / modules / admin / what-email_archiv.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 09/28/2003 *
4  * ===============                              Last change: 04/03/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-email_archiv .php                           *
8  * -------------------------------------------------------------------- *
9  * Short description : See send emails details of ordered mails         *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Alle  Mails ansehen die versand wurden           *
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  * Mod-Copyright (c) 2004 by Robert Niedziela                           *
34  * www.megacomputing.de                                                 *
35  ************************************************************************/
36
37 // Some security stuff...
38 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
39         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40         require($INC);
41 }
42
43 // Add description as navigation point
44 ADD_DESCR("admin", __FILE__);
45
46 //             0     1        2      3        4          5           6          7      8         9        10
47 $SQL = "SELECT id, sender, subject, text, receivers, payment_id, data_type, timestamp, url, target_send, cat_id
48  FROM `{!_MYSQL_PREFIX!}_pool`
49  WHERE data_type='SEND' OR data_type='DELETED'
50  ORDER BY timestamp DESC";
51
52 // Check for maximum pages
53 $result_normal = SQL_QUERY($SQL, __FILE__, __LINE__);
54
55 // Set offset an current page to default values
56 if (!REQUEST_ISSET_GET(('page')))   REQUEST_GET('page')   = "1";
57 if (!REQUEST_ISSET_GET(('offset'))) REQUEST_SET_GET('offset', getConfig('mails_page'));
58
59 // Add limitation to SQL string
60 $SQL .= " LIMIT ".(REQUEST_GET('offset') * REQUEST_GET('page') - REQUEST_GET('offset')).", ".REQUEST_GET('offset');
61
62 // Run SQL query for normal mails
63 $result = SQL_QUERY($SQL, __FILE__, __LINE__);
64
65 // Calculate pages
66 $PAGES = round(SQL_NUMROWS($result_normal) / getConfig('mails_page') + 0.5);
67 SQL_FREERESULT($result_normal);
68
69 if (SQL_NUMROWS($result) > 0)
70 {
71         // Mail orders are in pool so we can display them
72
73         // Add navigation table rows
74         if ($PAGES > 1)
75         {
76                 define('__TOP_EMAIL_NAV'   , ADD_EMAIL_NAV($PAGES, getConfig('mails_page'), true , "3", true));
77                 define('__BOTTOM_EMAIL_NAV', ADD_EMAIL_NAV($PAGES, getConfig('mails_page'), false, "3", true));
78         }
79          else
80         {
81                 define('__TOP_EMAIL_NAV'   , "");
82                 define('__BOTTOM_EMAIL_NAV', "");
83         }
84
85         $SW = 2; $OUT = "";
86         while ($pool = SQL_FETCHROW($result))
87         {
88                 // Check sent mails and clicks
89                 $result_mails = SQL_QUERY_ESC("SELECT max_rec, clicks FROM `{!_MYSQL_PREFIX!}_user_stats` WHERE pool_id=%s LIMIT 1",
90                  array(bigintval($pool[0])), __FILE__, __LINE__);
91                 list($sent, $clicks) = SQL_FETCHROW($result_mails);
92                 SQL_FREERESULT($result_mails);
93
94                 // Unconfirmed mails
95                 $unconfirmed = $sent - $clicks;
96                 if ($unconfirmed > 0)
97                 {
98                         // Add link to list_unconfirmed what-file
99                         $unconfirmed = "<strong><a href=\"{!URL!}/modules.php?module=admin&amp;what=list_unconfirmed&amp;mid=".$pool[0]."\">".$unconfirmed."</a></strong>";
100                 }
101
102                 // Prepare data for the row template
103                 $content = array(
104                         'sw'          => $SW,
105                         'u_link'      => ADMIN_USER_PROFILE_LINK($pool[1]),
106                         'subj'        => COMPILE_CODE($pool[2]),
107                         'text'        => COMPILE_CODE($pool[3]),
108                         'pay'         => GET_PAYMENT($pool[5]),
109                         'cat'         => GET_CATEGORY($pool[10]),
110                         'sent'        => $sent,
111                         'ruids'       => str_replace(";", ", ", $pool[4]),
112                         'unconfirmed' => $unconfirmed,
113                         'type'        => TRANSLATE_POOL_TYPE($pool[6]),
114                         'tsend'       => $pool[9],
115                         'frametester' => FRAMETESTER($pool[8]),
116                         'url'         => COMPILE_CODE($pool[8]),
117                         'stamp'       => MAKE_DATETIME($pool[7], "0"),
118                         'mid'         => $pool[0],
119                 );
120
121                 // Load row template and switch colors
122                 $OUT .= LOAD_TEMPLATE("admin_email_archiv_row", true, $content);
123                 $SW = 3 - $SW;
124         }
125
126         // Free memory
127         SQL_FREERESULT($result);
128         define('__EMAIL_ROWS', $OUT);
129
130         // Load main template
131         LOAD_TEMPLATE("admin_email_archiv");
132 } else {
133         // No mail orders fond
134         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_NO_MAILS_IN_POOL'));
135 }
136 //
137 ?>