Cast added due to API changes in PHP 5.3.1
[mailer.git] / inc / gen_mediadata.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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 - 2009 by Roland Haeder                           *
21  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42         die();
43 }
44
45 // Init variables
46 $bsent = '0'; $bclicks = '0'; $bcount = '0';
47
48 // Check for normal mails
49 $result_media = SQL_QUERY('SELECT
50         SUM(`max_rec`) AS max_rec,
51         SUM(`clicks`) AS clicks
52 FROM
53         `{?_MYSQL_PREFIX?}_user_stats`', __FILE__, __LINE__);
54 list($nsent, $nclicks) = SQL_FETCHROW($result_media);
55 if (empty($nsent))   $nsent   = '0';
56 if (empty($nclicks)) $nclicks = '0';
57
58 // Free memory
59 SQL_FREERESULT($result_media);
60
61 // Count mail orders
62 $ncount = countSumTotalData('', 'user_stats', 'id', '', true);
63
64 // Check for bonus extension
65 if (isExtensionActive('bonus')) {
66         // Count bonus mails
67         $bcount = countSumTotalData('', 'bonus', 'id', '', true);
68
69         // Check for bonus mails
70         $result_media = SQL_QUERY('SELECT SUM(mails_sent) AS bonus_sent, SUM(clicks) AS bonus_clicks
71 FROM `{?_MYSQL_PREFIX?}_bonus`', __FILE__, __LINE__);
72         list($bsent, $bclicks) = SQL_FETCHROW($result_media);
73         if (empty($bsent))   $bsent   = '0';
74         if (empty($bclicks)) $bclicks = '0';
75 } // END - if
76
77 // Load (maybe) missing file
78 loadIncludeOnce('inc/libs/mediadata_functions.php');
79
80 // Insert info to database
81 updateMediadataEntry(array('total_send'  , 'normal_send')  , 'init', $nsent);
82 updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'init', $nclicks);
83 updateMediadataEntry(array('total_orders', 'normal_orders'), 'init', $ncount);
84 updateMediadataEntry(array('total_send'  , 'bonus_send' )  , 'init', $bsent);
85 updateMediadataEntry(array('total_clicks', 'bonus_clicks') , 'init', $bclicks);
86 updateMediadataEntry(array('total_orders', 'bonus_orders') , 'init', $bcount);
87
88 // Aquire total used points
89 $result = SQL_QUERY('SELECT SUM(`used_points`) AS used_points FROM `{?_MYSQL_PREFIX?}_user_data`', __FILE__, __LINE__);
90 list($used) = SQL_FETCHROW($result);
91 SQL_FREERESULT($result);
92
93 // ... and total points
94 $result = SQL_QUERY('SELECT SUM(`points`) AS points FROM `{?_MYSQL_PREFIX?}_user_points`', __FILE__, __LINE__);
95 list($points) = SQL_FETCHROW($result);
96 SQL_FREERESULT($result);
97
98 // Update database
99 updateMediadataEntry(array('total_points'), 'init', ($points - $used));
100
101 // [EOF]
102 ?>