A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[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  *                                                                      *
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')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Generates a HTML table based on given data
41 // @TODO Lame description
42 function DOUBLER_GENERATE_TABLE ($uid="0", $done='N', $ref='N', $sort="ASC") {
43         if (empty($cnt)) $cnt = 0;
44         $ADD = ""; $DT_MODE = 0;
45         if ($uid > 0) {
46                 // Load entries only from a single user
47                 $ADD = " AND userid='".bigintval($uid)."'";
48                 $MODE = "member"; $COLS = "4"; $DT_MODE = "2";
49                 $NOT_FOUND = getMessage('DOUBLER_MEMBER_NO_ENTRIES_FOUND');
50         } else {
51                 // Guest mode!
52                 $MODE = "guest"; $COLS = "3"; $DT_MODE = "3";
53                 $NOT_FOUND = getMessage('DOUBLER_GUEST_NO_ENTRIES_FOUND');
54         }
55
56         if (($done == "Y") && ($sort == "ASC")) {
57                 // Already payed out points (latest payouts first)
58                 $limit = getConfig('doubler_display_old');
59         } elseif ($sort == "ASC") {
60                 // List entries which will receive their payout soon
61                 $limit = getConfig('doubler_display_pay');
62         } elseif ($sort == "DESC") {
63                 // Newest entries
64                 $limit = getConfig('doubler_display_new');
65         }
66
67         // List entries
68         $result = SQL_QUERY("SELECT userid, refid, points, timemark
69 FROM `{!_MYSQL_PREFIX!}_doubler`
70 WHERE completed='".$done."' AND is_ref='".$ref."'".$ADD."
71 ORDER BY timemark ".$sort."
72 LIMIT ".$limit, __FUNCTION__, __LINE__);
73
74         if (SQL_NUMROWS($result) > 0) {
75                 // List entries
76                 $OUT = ""; $SW = 2;
77                 while ($content = SQL_FETCHARRAY($result)) {
78                         // Rewrite userid/refid only if admin is in
79                         if (IS_ADMIN()) {
80                                 // Set links to admin area
81                                 if ($content['userid'] > 0) { $content['userid'] = ADMIN_USER_PROFILE_LINK($content['userid']); } else { $content['userid'] = "---"; }
82                                 if ($content['refid'] > 0)  { $content['refid']  = ADMIN_USER_PROFILE_LINK($content['refid']);  } else { $content['refid']  = "---"; }
83                         } // END - if
84
85                         // Prepare data for the row template
86                         $content = array(
87                                 'uid'    => $content['userid'],
88                                 'rid'    => $content['refid'],
89                                 'points' => TRANSLATE_COMMA($content['points']),
90                                 'stamp'  => MAKE_DATETIME($content['timemark'], $DT_MODE),
91                                 'sw'     => $SW,
92                         );
93
94                         // Load template and switch color
95                         $OUT .= LOAD_TEMPLATE($MODE."_doubler_list_rows", true, $content);
96                         $SW = 3 - $SW;
97                 }
98
99                 // Free memory
100                 SQL_FREERESULT($result);
101         } else {
102                 // List no entries
103                 $OUT = "<tr>
104   <td colspan=\"".$COLS."\" align=\"center\" class=\"doubler_big_row bottom2\">
105     ".LOAD_TEMPLATE("admin_settings_saved", true, $NOT_FOUND)."
106   </td>
107 </tr>\n";
108         }
109
110         // Return template
111         return LOAD_TEMPLATE($MODE."_doubler_list", true, $OUT);
112 }
113
114 //
115 function DOUBLER_GET_TOTAL_POINTS_LEFT() {
116         // Initialize variables
117         $points = 0;
118
119         if (getConfig('doubler_own') == "Y") {
120                 // Take points from doubler's own account
121                 $points += getConfig('doubler_points') - getConfig('doubler_used');
122         }
123
124         if (getConfig('doubler_jackpot') == "Y") {
125                 // Load jackpot
126                 $result = SQL_QUERY("SELECT points FROM `{!_MYSQL_PREFIX!}_jackpot` WHERE ok='ok' LIMIT 1", __FUNCTION__, __LINE__);
127                 list($jackpot) = SQL_FETCHROW($result);
128                 SQL_FREERESULT($result);
129
130                 if (!empty($jackpot)) $points += $jackpot;
131         }
132
133         if (getConfig('doubler_uid') > 0) {
134                 // Get user's points
135                 $user = GET_TOTAL_DATA(getConfig('doubler_uid'), "user_points", "points");
136                 $points += $user;
137         }
138
139         // Return value
140         return $points;
141 }
142 //
143 ?>