Several minor rewrites, getter GET_JACKPOT_POINTS() added
[mailer.git] / inc / libs / doubler_functions.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 02/17/2005 *
4  * ===============                              Last change: 02/17/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : doubler_functions.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : Functions for the guest's newsletter             *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Funktionen fuer den Newsletter an die Gaeste     *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 }
44
45 // Generates a HTML table based on given data
46 // @TODO Lame description
47 function DOUBLER_GENERATE_TABLE ($uid = '0', $done = 'N', $ref = 'N', $sort = 'ASC') {
48         if (empty($cnt)) $cnt = 0;
49         $add = ''; $DT_MODE = 0;
50         if ($uid > 0) {
51                 // Load entries only from a single user
52                 $add = " AND `userid`='".bigintval($uid)."'";
53                 $mode = 'member'; $COLS = '4'; $DT_MODE = '2';
54                 $NOT_FOUND = getMessage('DOUBLER_MEMBER_NO_ENTRIES_FOUND');
55         } else {
56                 // Guest mode!
57                 $mode = 'guest'; $COLS = '3'; $DT_MODE = '3';
58                 $NOT_FOUND = getMessage('DOUBLER_GUEST_NO_ENTRIES_FOUND');
59         }
60
61         if (($done == 'Y') && ($sort == 'ASC')) {
62                 // Already payed out points (latest payouts first)
63                 $limit = getConfig('doubler_display_old');
64         } elseif ($sort == 'ASC') {
65                 // List entries which will receive their payout soon
66                 $limit = getConfig('doubler_display_pay');
67         } elseif ($sort == 'DESC') {
68                 // Newest entries
69                 $limit = getConfig('doubler_display_new');
70         }
71
72         // List entries
73         $result = SQL_QUERY("SELECT userid, refid, points, timemark
74 FROM `{!_MYSQL_PREFIX!}_doubler`
75 WHERE completed='".$done."' AND is_ref='".$ref."'".$add."
76 ORDER BY timemark ".$sort."
77 LIMIT ".$limit, __FUNCTION__, __LINE__);
78
79         if (SQL_NUMROWS($result) > 0) {
80                 // List entries
81                 $OUT = ''; $SW = 2;
82                 while ($content = SQL_FETCHARRAY($result)) {
83                         // Rewrite userid/refid only if admin is in
84                         if (IS_ADMIN()) {
85                                 // Set links to admin area
86                                 if ($content['userid'] > 0) { $content['userid'] = generateUserProfileLink($content['userid']); } else { $content['userid'] = '---'; }
87                                 if ($content['refid'] > 0)  { $content['refid']  = generateUserProfileLink($content['refid']);  } else { $content['refid']  = '---'; }
88                         } // END - if
89
90                         // Prepare data for the row template
91                         $content = array(
92                                 'uid'    => $content['userid'],
93                                 'rid'    => $content['refid'],
94                                 'points' => translateComma($content['points']),
95                                 'stamp'  => generateDateTime($content['timemark'], $DT_MODE),
96                                 'sw'     => $SW,
97                         );
98
99                         // Load template and switch color
100                         $OUT .= LOAD_TEMPLATE($mode . '_doubler_list_rows', true, $content);
101                         $SW = 3 - $SW;
102                 }
103
104                 // Free memory
105                 SQL_FREERESULT($result);
106         } else {
107                 // List no entries
108                 $OUT = "<tr>
109   <td colspan=\"".$COLS."\" align=\"center\" class=\"doubler_big_row bottom2\">
110     ".LOAD_TEMPLATE('admin_settings_saved', true, $NOT_FOUND)."
111   </td>
112 </tr>\n";
113         }
114
115         // Return template
116         return LOAD_TEMPLATE($mode . '_doubler_list', true, $OUT);
117 }
118
119 //
120 function DOUBLER_GET_TOTAL_POINTS_LEFT() {
121         // Initialize variables
122         $points = 0;
123
124         if (getConfig('doubler_own') == 'Y') {
125                 // Take points from doubler's own account
126                 $points += getConfig('doubler_points') - getConfig('doubler_used');
127         } // END - if
128
129         if (getConfig('doubler_jackpot') == 'Y') {
130                 // Load jackpot
131                 $jackpot = GET_JACKPOT_POINTS();
132
133                 if (!empty($jackpot)) $points += $jackpot;
134         }
135
136         if (getConfig('doubler_uid') > 0) {
137                 // Get user's points
138                 $user = GET_TOTAL_DATA(getConfig('doubler_uid'), 'user_points', 'points');
139                 $points += $user;
140         }
141
142         // Return value
143         return $points;
144 }
145 //
146 ?>