cd3fdb2ec2dead7b9d1b6a3f4ebff033317c2692
[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 } // END - if
44
45 // Init array/varriable
46 $bcount = '0';
47 $content = array(
48         'normal_send'   => 0,
49         'normal_clicks' => 0,
50         'bonus_send'    => 0,
51         'bonus_clicks'  => 0
52 );
53
54 // Check for normal mails
55 $result_media = SQL_QUERY('SELECT
56         SUM(`max_rec`) AS `normal_send`,
57         SUM(`clicks`) AS `normal_clicks`
58 FROM
59         `{?_MYSQL_PREFIX?}_user_stats`', __FILE__, __LINE__);
60 $content = merge_array($content, SQL_FETCHARRAY($result_media));
61
62 // Free memory
63 SQL_FREERESULT($result_media);
64
65 // Check for bonus extension
66 if (isExtensionActive('bonus')) {
67         // Count bonus mails
68         $bcount = countSumTotalData('', 'bonus', 'id', '', true);
69
70         // Check for bonus mails
71         $result_media = SQL_QUERY('SELECT
72         SUM(`mails_send`) AS `bonus_send`,
73         SUM(`clicks`) AS `bonus_clicks`
74 FROM
75         `{?_MYSQL_PREFIX?}_bonus`', __FILE__, __LINE__);
76         $content = merge_array($content, SQL_FETCHARRAY($result_media));
77
78         // Free memory
79         SQL_FREERESULT($result_media);
80 } // END - if
81
82 // Load (maybe) missing file
83 loadIncludeOnce('inc/libs/mediadata_functions.php');
84
85 // Insert info to database
86 updateMediadataEntry(array('total_send'  , 'normal_send')  , 'init', $content['normal_send']);
87 updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'init', $content['normal_clicks']);
88 updateMediadataEntry(array('total_orders', 'normal_orders'), 'init', countSumTotalData('', 'user_stats', 'id', '', true));
89 updateMediadataEntry(array('total_send'  , 'bonus_send' )  , 'init', $content['bonus_send']);
90 updateMediadataEntry(array('total_clicks', 'bonus_clicks') , 'init', $content['bonus_clicks']);
91 updateMediadataEntry(array('total_orders', 'bonus_orders') , 'init', $bcount);
92
93 // Aquire total used points
94 $used = countSumTotalData('', 'user_data', 'used_points', '');
95
96 // ... and total points
97 $points = countSumTotalData('', 'user_points', 'points', '');
98
99 // Update database
100 updateMediadataEntry(array('total_points'), 'init', ($points - $used));
101
102 // [EOF]
103 ?>