1dbaf06ffbeadc03ed0af6346c555ec4446e0920
[mailer.git] / inc / modules / admin / what-list_beg.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/22/2005 *
4  * ================                             Last change: 10/22/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-list_beg.php                                *
8  * -------------------------------------------------------------------- *
9  * Short description : List members in begging-rallye                   *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Mitglieder in Bettel-Rallye auflisten            *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
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.                                  *
22  *                                                                      *
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.                         *
27  *                                                                      *
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,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39 // Add description as navigation point
40 ADD_DESCR("admin", __FILE__);
41
42 if (getConfig('beg_rallye') == "Y") {
43         // Shall I withdraw now?
44         if (REQUEST_ISSET_POST(('withdraw'))) {
45                 // Okay, let's prepare...
46                 $curr = date("m", time()) - 1;
47                 if (strlen($curr) == 1) $curr = "0".$curr;
48                 UPDATE_CONFIG("last_month", $curr);
49                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_BEG_WITHDRAW_PREPARED'));
50         } // END - if
51
52         // Autopurge installed?
53         $lastOnline = "%s"; $ONLINE = "";
54         if (EXT_IS_ACTIVE("autopurge")) {
55                 // Use last online timestamp to keep inactive members away from here
56                 $lastOnline   = " AND last_online >= (UNIX_TIMESTAMP() - %s)";
57                 $ONLINE = getConfig('ap_inactive_since');
58         } // END - if
59
60         // Check if at least one is in the active rallye
61         $result = SQL_QUERY_ESC("SELECT userid, email, gender, surname, family, beg_points, last_online
62 FROM `{!_MYSQL_PREFIX!}_user_data`
63 WHERE `status`='CONFIRMED' AND beg_points > 0".$lastOnline."
64 ORDER BY beg_points DESC, last_online DESC, userid",
65          array($ONLINE), __FILE__, __LINE__);
66
67         if (SQL_NUMROWS($result) > 0) {
68                 // List users
69                 $OUT = "";$SW = 2; $cnt = 1; $total = 0;
70                 while ($content = SQL_FETCHARRAY($result)) {
71                         // Init variables
72                         $WIN1 = ""; $WIN2 = "";
73                         if ($cnt <= getConfig('beg_ranks')) {
74                                 // Maybe he can win his active beg?
75                                 $WIN1 = "<strong>";
76                                 $WIN2 = "</strong>";
77                         } // END - if
78
79                         // Prepare content
80                         // @TODO Rewrite templates so s/fname will be replaced by surname/family
81                         // @TODO to shorten this block. Please also do so with uid->userid
82                         $content = array(
83                                 'uid'    => $content['userid'],
84                                 'email'  => CREATE_EMAIL_LINK($content['email'], "user_data"),
85                                 'gender' => TRANSLATE_GENDER($content['gender']),
86                                 'sname'  => $content['surname'],
87                                 'fname'  => $content['family'],
88                                 'turbo'  => TRANSLATE_COMMA($content['beg_points']),
89                                 'last'   => MAKE_DATETIME($content['last_online'], "2"),
90                                 'sw'     => $SW,
91                                 'win1'   => $WIN1,
92                                 'win2'   => $WIN2,
93                                 'cnt'    => $cnt,
94                         );
95
96                         // Load template and add it
97                         $OUT .= LOAD_TEMPLATE("admin_list_beg_rows", true, $content);
98                         $SW = 3 - $SW; $cnt++; $total += $content['beg_points'];
99                 }
100                 define('__BEG_ROWS', $OUT);
101                 define('__TOTAL', TRANSLATE_COMMA($total));
102
103                 // Check if we need to display form or not with manuel withdraw
104                 if (getConfig('last_month') == date("m", time())) {
105                         // Load form
106                         define('__BEG_WITHDRAW_FORM', LOAD_TEMPLATE("admin_list_beg_form", true));
107                 } else {
108                         // Display message "no manual withdraw possible"
109                         define('__BEG_WITHDRAW_FORM', "<div class=\"admin_failed\">{--ADMIN_BEG_ALREADY_WITHDRAW--}</div>");
110                 }
111
112                 // Prepare constant for timemark
113                 if (EXT_IS_ACTIVE("autopurge")) {
114                         define('__AUTOPURGE_TIMEOUT', MAKE_DATETIME(time() - getConfig('ap_inactive_since'), "2"));
115                 } else {
116                         define('__AUTOPURGE_TIMEOUT', sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), "autopurge"));
117                 }
118
119                 // Load final template
120                 LOAD_TEMPLATE("admin_list_beg");
121         } else {
122                 // No one has joined the begging rallye...
123                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_BEG_NO_RALLYE'));
124         }
125 } else {
126         // Rallye deactivated
127         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_BEG_RALLYE_DEACTIVATED'));
128 }
129
130 //
131 ?>