Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / admin / what-list_beg.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2015 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')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 if (isBegRallyeEnabled()) {
47         // Shall I withdraw now?
48         if (isPostRequestElementSet('withdraw')) {
49                 // Okay, let's prepare...
50                 $curr = padLeftZero(getMonth() - 1, 2);
51                 updateConfiguration('last_monthly', $curr);
52                 displayMessage('{--ADMIN_BEG_WITHDRAW_PREPARED--}');
53         } // END - if
54
55         // Init variable
56         $lastOnline = '';
57
58         // Autopurge installed?
59         if ((isExtensionActive('autopurge')) && (isBegActiveEnabled()) && ((getApInactiveSince() > 0))) {
60                 // Use last online timestamp to keep inactive members away from here
61                 $lastOnline   = ' AND (UNIX_TIMESTAMP() - `last_online`) < {?ap_inactive_since?}';
62         } // END - if
63
64         // Check if at least one is in the active rallye
65         $result = sqlQuery("SELECT
66         `userid`,
67         `email`,
68         `beg_points`,
69         `last_online`
70 FROM
71         `{?_MYSQL_PREFIX?}_user_data`
72 WHERE
73         `status`='CONFIRMED' AND
74         `beg_points` > 0
75         " . $lastOnline . "
76         " . runFilterChain('user_exclusion_sql', ' ') . "
77 ORDER BY
78         `beg_points` DESC,
79         `last_online` DESC,
80         `userid` ASC", __FILE__, __LINE__);
81
82         if (!ifSqlHasZeroNumRows($result)) {
83                 // List users
84                 $OUT = ''; $count = 1; $total = '0';
85                 while ($content = sqlFetchArray($result)) {
86                         // Init variables
87                         $WIN1 = '';
88                         $WIN2 = '';
89
90                         // Maybe he can win his active beg?
91                         if ($count <= getBegRanks()) {
92                                 // Mark him
93                                 $WIN1 = '<strong>';
94                                 $WIN2 = '</strong>';
95                         } // END - if
96
97                         // Prepare content
98                         $row = array(
99                                 'userid'      => $content['userid'],
100                                 'email'       => generateEmailLink($content['email'], 'user_data'),
101                                 'last_online' => generateDateTime($content['last_online'], '2'),
102                                 'win1'        => $WIN1,
103                                 'win2'        => $WIN2,
104                                 'count'       => $count,
105                         );
106
107                         // Load template and add it
108                         $OUT .= loadTemplate('admin_list_beg_rows', TRUE, $row);
109                         $count++;
110                         $total += $content['beg_points'];
111                 } // END - while
112
113                 $content['rows']  = $OUT;
114                 $content['total_points'] = $total;
115
116                 // Check if we need to display form or not with manuel withdraw
117                 if (getLastMonthly() == getMonth()) {
118                         // Load form
119                         $content['withdraw_form'] = loadTemplate('admin_list_beg_form', TRUE);
120                 } else {
121                         // Display message "no manual withdraw possible"
122                         $content['withdraw_form'] = returnMessage('{--ADMIN_BEG_ALREADY_WITHDRAW--}');
123                 }
124
125                 // Prepare constant for timemark
126                 if (isExtensionActive('autopurge')) {
127                         $content['autopurge_timeout'] = generateDateTime(time() - getApInactiveSince(), 2);
128                 } else {
129                         $content['autopurge_timeout'] = returnMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=autopurge%}');
130                 }
131
132                 // Load final template
133                 loadTemplate('admin_list_beg', FALSE, $content);
134         } else {
135                 // No one has joined the begging rallye...
136                 displayMessage('{--ADMIN_BEG_NO_RALLYE--}');
137         }
138 } else {
139         // Rallye deactivated
140         displayMessage('{--ADMIN_BEG_RALLYE_DEACTIVATED--}');
141 }
142
143 // [EOF]
144 ?>