Mailer project continued:
[mailer.git] / inc / daily / daily_100_bonus.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 10/25/2009 *
4  * ===================                          Last change: 06/20/2010 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : daily_100_bonus.php                              *
8  * -------------------------------------------------------------------- *
9  * Short description : Check for 100% click rate order                  *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Nach Mailbestaetigungen mit 100% Klickrate s.    *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } elseif ((!isHtmlOutputMode()) || (!isResetModeEnabled())) {
42         // Do not execute when script is in CSS mode or no daily reset
43         return;
44 } elseif (!isExtensionActive('bonus')) {
45         logDebugMessage(__FILE__, __LINE__, 'Not resetting, needed extension disabled.');
46         return;
47 }
48
49 // Debug line
50 //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'Daily reset started.');
51
52 // Check for 100% klickrate mails
53 $result_bonus = SQL_QUERY("SELECT
54         `id`,
55         `userid`,
56         `subject`,
57         `timestamp_ordered`,
58         `clicks`,
59         `url`
60 FROM
61         `{?_MYSQL_PREFIX?}_user_stats`
62 WHERE
63         `max_rec`=`clicks` AND
64         `clicks` > 0 AND
65         `bonus_stats_active`='N'
66 ORDER BY
67         `userid` ASC", __FILE__, __LINE__);
68
69 if (!SQL_HASZERONUMS($result_bonus)) {
70         // We found some mail orders...
71         while ($content = SQL_FETCHARRAY($result_bonus)) {
72                 // Add points
73                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `bonus_stats`=`bonus_stats`+{?bonus_stats?} WHERE `userid`=%s LIMIT 1",
74                         array(bigintval($content['userid'])), __FILE__, __LINE__);
75
76                 // Translate some data
77                 $content['timestamp'] = generateDateTime($content['timestamp_ordered'], 2);
78
79                 // Load email template and send email
80                 $message = loadEmailTemplate('member_stats_bonus', $content, bigintval($content['userid']));
81                 sendEmail($content['userid'], '{--MEMBER_BONUS_STATS_SUBJECT--}', $message);
82
83                 // Update database
84                 $result_update = SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_stats` SET `bonus_stats_active`='Y' WHERE `id`=%s LIMIT 1",
85                         array(bigintval($content['id'])), __FILE__, __LINE__);
86         } // END - while
87
88         // Handle bonus points
89         handleBonusPoints(getConfig('bonus_stats'), $content['userid']);
90 } // END - if
91
92 // Free memory
93 SQL_FREERESULT($result_bonus);
94
95 // Debug line
96 //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'Daily reset ended.');
97
98 // [EOF]
99 ?>