2 /************************************************************************
3 * MXChange v0.2.1 Start: 10/22/2005 *
4 * =============== Last change: 10/22/2005 *
6 * -------------------------------------------------------------------- *
7 * File : monthly_beg.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Monthly begging rallye *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Monatliche Bettelrallye *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38 } elseif (!EXT_IS_ACTIVE("beg")) {
42 // Do not execute when script is in CSS mode or no daily reset
43 if (($CSS == 1) || (!defined('__DAILY_RESET')) || ($_CONFIG['beg_rallye'] == "N")) return;
44 //* DEBUG: */ echo basename(__FILE__)."<br />\n";
46 // Get current month (2 digits)
47 $curr = date("m", time());
49 // Check if month is done
50 if (($curr != $_CONFIG['last_month']) && ($_CONFIG['last_month'] > 0) && ($_CONFIG['beg_ranks'] > 0) && ($CSS != 1)) {
51 // Extension "autopurge" is inactive or purging of inactive accounts is deactivated
52 $whereStatement1 = "";
53 $whereStatement2 = bigintval($_CONFIG['beg_ranks']);
55 // Let's check if there are some points left we can "pay"...
56 if (EXT_IS_ACTIVE("autopurge")) {
57 // Use last online stamp only when autopurge for inactive members is activated
58 if (($_CONFIG['ap_inactive_since'] > 0) && ($_CONFIG['beg_active'] == "Y")) {
59 // Okay, include last online timestamp
60 $whereStatement1 = sprintf(" AND last_online >= (UNIX_TIMESTAMP() - %s)", bigintval($_CONFIG['ap_inactive_since']));;
61 $whereStatement2 = bigintval($_CONFIG['beg_ranks']);
65 // SQL string to check for accounts
66 $result_main = SQL_QUERY_ESC("SELECT userid, email, gender, surname, family, beg_points AS points
67 FROM "._MYSQL_PREFIX."_user_data
68 WHERE status='CONFIRMED'".$whereStatement1." AND beg_points > 0
69 ORDER BY beg_points DESC, userid
71 array($whereStatement2), __FILE__, __LINE__);
73 if (SQL_NUMROWS($result_main) > 0) {
74 // Load our winners...
75 while ($content = SQL_FETCHARRAY($result_main)) {
76 // Add points to user's account directly
77 ADD_POINTS_REFSYSTEM("monthly_beg", $content['userid'], $content['points'], false, "0", false, "direct");
79 // Translate gender/points
80 $content['gender'] = TRANSLATE_GENDER($content['gender']);
81 $content['points'] = TRANSLATE_COMMA($content['points']);
83 // Load email template and email it away
84 $msg = LOAD_EMAIL_TEMPLATE("member_beg", $content, bigintval($content['userid']));
85 SEND_EMAIL($content['email'], BEG_MONTHLY_RALLYE, $msg);
89 $result = SQL_QUERY("UPDATE "._MYSQL_PREFIX."_user_data SET beg_points=0.00000 WHERE beg_points > 0", __FILE__, __LINE__);
93 SQL_FREERESULT($result_main);