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