Complete rewrite of and , wrapper functions added, see bug #101
[mailer.git] / show_bonus.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 11/13/2004 *
4  * ===============                              Last change: 11/14/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : show_bonus.php                                   *
8  * -------------------------------------------------------------------- *
9  * Short description : Show ranking list for turbo-bonus                *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Rankliste fuer Turbo-Bonus anzeigen              *
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 // Load security stuff here (Oh, I hope this is not unsecure? Am I paranoia??? ;-) )
35 require("inc/libs/security_functions.php");
36
37 // Init "action" and "what"
38 $GLOBALS['startTime'] = microtime(true);
39 $GLOBALS['what'] = "";
40 $GLOBALS['action'] = "";
41
42 // Set this because we have no module in URI
43 $GLOBALS['module'] = "show_bonus";
44 $GLOBALS['output_mode'] = 0;
45
46 // Load the required file(s)
47 require("inc/config.php");
48
49 // Is the "bonus" extension active?
50 REDIRECT_ON_UNINSTALLED_EXTENSION("bonus");
51
52 // List only rankings when script is installed
53 if (isBooleanConstantAndTrue('mxchange_installed')) {
54         // Include header
55         LOAD_INC("inc/header.php");
56
57         if ((REQUEST_GET('uid') > 0) && (REQUEST_GET('d') > 0) && (REQUEST_ISSET_GET(('t')))) {
58                 // Set row name
59                 $t = "";
60                 switch (REQUEST_GET('t')) {
61                         case "bonusid": // Bonus mail
62                                 $t = "bonus_id";
63                                 break;
64
65                         case "mailid": // Regular member mail
66                                 $t = "mail_id";
67                                 break;
68
69                         default: // Invalid type
70                                 DEBUG_LOG(__FILE__, __LINE__, sprintf("Invalid type %s detected.", REQUEST_GET('t')));
71                                 break;
72                 } // END - switch
73
74                 // Valid type?
75                 if (!empty($t)) {
76                         // Check for data
77                         $result = SQL_QUERY_ESC("SELECT DISTINCT d.gender, d.surname, d.family, b.level, b.points
78 FROM `{!_MYSQL_PREFIX!}_user_data` AS d
79 RIGHT JOIN `{!_MYSQL_PREFIX!}_bonus_turbo` AS b
80 ON d.userid=b.userid
81 WHERE d.`status`='CONFIRMED' AND d.userid=%s AND b.%s=%s
82 LIMIT 1",
83                                 array(bigintval(REQUEST_GET('uid')), $t, bigintval(REQUEST_GET('d'))), __FILE__, __LINE__);
84
85                         // Entry found?
86                         if (SQL_NUMROWS($result) == 1) {
87                                 // Load data
88                                 $content = SQL_FETCHARRAY($result);
89
90                                 // Prepare constants for the pre-template
91                                 define('__GENDER'   , TRANSLATE_GENDER($content['gender']));
92                                 define('__SNAME'    , $content['surname']);
93                                 define('__FNAME'    , $content['family']);
94                                 define('__RANK'     , BIGINTVAL($content['level']));
95                                 define('__POINTS'   , TRANSLATE_COMMA($content['points']));
96                                 define('__MAILID'   , bigintval(REQUEST_GET('d')));
97                                 define('__RANK_ROWS', BONUS_MAKE_RANK_ROWS(bigintval(REQUEST_GET('d')), $t, bigintval(REQUEST_GET('uid'))));
98
99                                 // Constant created within previous function which contains informations for current user's ranking position:
100                                 //   __YOUR_RANKING_LINE
101
102                                 // Load pre-template
103                                 define('__BONUS_MSG', LOAD_TEMPLATE("show_bonus_msg", true));
104                         } else {
105                                 // No data found
106                                 define('__BONUS_MSG', "<span class=\"guest_failed\">{--BONUS_SHOW_NO_DATA--}</span>");
107                         }
108
109                         // Free memory
110                         SQL_FREERESULT($result);
111                 } else {
112                         // Wrong type entered
113                         define('__BONUS_MSG', "<span class=\"guest_failed\">{--BONUS_SHOW_WRONG_TYPE--}</span>");
114                 }
115         } else {
116                 // Wrong call!
117                 define('__BONUS_MSG', "<span class=\"guest_failed\">{--BONUS_SHOW_WRONG_CALL--}</span>");
118         }
119
120         // Load send_bonus header template (for your banners, e.g.?)
121         define('__BONUS_HEADER', LOAD_TEMPLATE("show_bonus_header", true));
122
123         // Load show_bonus footer template (for your banners, e.g.?)
124         define('__BONUS_FOOTER', LOAD_TEMPLATE("show_bonus_footer", true));
125
126         // Total ranks who can win
127         define('__BONUS_TOTAL_RANKS', getConfig('bonus_ranks'));
128
129         // Load final template
130         LOAD_TEMPLATE("show_bonus");
131
132         // Include footer
133         LOAD_INC("inc/footer.php");
134 } else {
135         // You have to install first!
136         LOAD_URL("install.php");
137 }
138
139 // Really all done here... ;-)
140 ?>