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