More queries now depends on UNIX_TIMESTAMP() SQL function, wrong index in autopurge...
[mailer.git] / inc / gen_mediadata.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/08/2005 *
4  * ===============                              Last change: 01/01/2006 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : gen_mediadata.php                                *
8  * -------------------------------------------------------------------- *
9  * Short description : Checks for existing mail orders                  *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Prueft bestehende Mailbuchungen                  *
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
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Check for normal mails
41 $result_media = SQL_QUERY("SELECT SUM(max_rec) AS max_rec, SUM(clicks) AS clicks
42 FROM "._MYSQL_PREFIX."_user_stats", __FILE__, __LINE__);
43 list($nsent, $nclicks) = SQL_FETCHROW($result_media);
44 if (empty($nsent))   $nsent   = 0;
45 if (empty($nclicks)) $nclicks = 0;
46
47 // Free memory
48 SQL_FREERESULT($result_media);
49
50 // Count mail orders
51 $result_media = SQL_QUERY("SELECT COUNT(id) FROM "._MYSQL_PREFIX."_user_stats", __FILE__, __LINE__);
52 list($ncount) = SQL_FETCHROW($result_media);
53 SQL_FREERESULT($result_media);
54 $result_media = SQL_QUERY("SELECT COUNT(id) FROM "._MYSQL_PREFIX."_bonus", __FILE__, __LINE__);
55 list($bcount) = SQL_FETCHROW($result_media);
56 SQL_FREERESULT($result_media);
57
58 // Check for bonus extension
59 if (EXT_IS_ACTIVE("bonus"))
60 {
61         // Check for bonus mails
62         $result_media = SQL_QUERY("SELECT SUM(mails_sent) AS bonus_sent, SUM(clicks) AS bonus_clicks
63 FROM "._MYSQL_PREFIX."_bonus", __FILE__, __LINE__);
64         list($bsent, $bclicks) = SQL_FETCHROW($result_media);
65         if (empty($bsent))   $bsent   = 0;
66         if (empty($bclicks)) $bclicks = 0;
67 }
68  else
69 {
70         // Not found!
71         $bsent = 0; $bclicks = 0;
72 }
73
74 // Load (maybe) missing file
75 require_once(PATH."inc/libs/mediadata_functions.php");
76
77 // Insert info to database
78 MEDIA_UPDATE_ENTRY(array("total_send"  , "normal_send")  , "init", $nsent);
79 MEDIA_UPDATE_ENTRY(array("total_clicks", "normal_clicks"), "init", $nclicks);
80 MEDIA_UPDATE_ENTRY(array("total_orders", "normal_orders"), "init", $ncount);
81 MEDIA_UPDATE_ENTRY(array("total_send"  , "bonus_send" )  , "init", $bsent);
82 MEDIA_UPDATE_ENTRY(array("total_clicks", "bonus_clicks") , "init", $bclicks);
83 MEDIA_UPDATE_ENTRY(array("total_orders", "bonus_orders") , "init", $bcount);
84
85 // Aquire total used points
86 $result = SQL_QUERY("SELECT SUM(used_points) AS used_points FROM "._MYSQL_PREFIX."_user_data", __FILE__, __LINE__);
87 list($used) = SQL_FETCHROW($result);
88 SQL_FREERESULT($result);
89
90 // ... and total points
91 $result = SQL_QUERY("SELECT SUM(points) AS points FROM "._MYSQL_PREFIX."_user_points", __FILE__, __LINE__);
92 list($points) = SQL_FETCHROW($result);
93 SQL_FREERESULT($result);
94
95 // Update database
96 MEDIA_UPDATE_ENTRY(array("total_points"), "init", ($points - $used));
97
98 //
99 ?>