Fixed logfile writing in installation phase, .revision is now ignored
[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  * $Revision:: 856                                                    $ *
14  * $Date:: 2009-03-06 20:24:32 +0100 (Fr, 06. Mär 2009)              $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author:: stelzi                                                   $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
42         require($INC);
43 }
44
45 // Init variables
46 $bsent = 0; $bclicks = 0; $bcount = 0;
47
48 // Check for normal mails
49 $result_media = SQL_QUERY("SELECT SUM(max_rec) AS max_rec, SUM(clicks) AS clicks
50 FROM `{!_MYSQL_PREFIX!}_user_stats`", __FILE__, __LINE__);
51 list($nsent, $nclicks) = SQL_FETCHROW($result_media);
52 if (empty($nsent))   $nsent   = 0;
53 if (empty($nclicks)) $nclicks = 0;
54
55 // Free memory
56 SQL_FREERESULT($result_media);
57
58 // Count mail orders
59 $result_media = SQL_QUERY("SELECT COUNT(id) FROM `{!_MYSQL_PREFIX!}_user_stats`", __FILE__, __LINE__);
60 list($ncount) = SQL_FETCHROW($result_media);
61 SQL_FREERESULT($result_media);
62
63 // Check for bonus extension
64 if (EXT_IS_ACTIVE("bonus")) {
65         // Count bonus mails
66         $result_media = SQL_QUERY("SELECT COUNT(id) FROM `{!_MYSQL_PREFIX!}_bonus`", __FILE__, __LINE__);
67         list($bcount) = SQL_FETCHROW($result_media);
68         SQL_FREERESULT($result_media);
69
70         // Check for bonus mails
71         $result_media = SQL_QUERY("SELECT SUM(mails_sent) AS bonus_sent, SUM(clicks) AS bonus_clicks
72 FROM `{!_MYSQL_PREFIX!}_bonus`", __FILE__, __LINE__);
73         list($bsent, $bclicks) = SQL_FETCHROW($result_media);
74         if (empty($bsent))   $bsent   = 0;
75         if (empty($bclicks)) $bclicks = 0;
76 } // END - if
77
78 // Load (maybe) missing file
79 LOAD_INC_ONCE("inc/libs/mediadata_functions.php");
80
81 // Insert info to database
82 MEDIA_UPDATE_ENTRY(array("total_send"  , "normal_send")  , "init", $nsent);
83 MEDIA_UPDATE_ENTRY(array("total_clicks", "normal_clicks"), "init", $nclicks);
84 MEDIA_UPDATE_ENTRY(array("total_orders", "normal_orders"), "init", $ncount);
85 MEDIA_UPDATE_ENTRY(array("total_send"  , "bonus_send" )  , "init", $bsent);
86 MEDIA_UPDATE_ENTRY(array("total_clicks", "bonus_clicks") , "init", $bclicks);
87 MEDIA_UPDATE_ENTRY(array("total_orders", "bonus_orders") , "init", $bcount);
88
89 // Aquire total used points
90 $result = SQL_QUERY("SELECT SUM(used_points) AS used_points FROM `{!_MYSQL_PREFIX!}_user_data`", __FILE__, __LINE__);
91 list($used) = SQL_FETCHROW($result);
92 SQL_FREERESULT($result);
93
94 // ... and total points
95 $result = SQL_QUERY("SELECT SUM(points) AS points FROM `{!_MYSQL_PREFIX!}_user_points`", __FILE__, __LINE__);
96 list($points) = SQL_FETCHROW($result);
97 SQL_FREERESULT($result);
98
99 // Update database
100 MEDIA_UPDATE_ENTRY(array("total_points"), "init", ($points - $used));
101
102 //
103 ?>