Fixed logfile writing in installation phase, .revision is now ignored
[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:: 856                                                    $ *
14  * $Date:: 2009-03-06 20:24:32 +0100 (Fr, 06. Mär 2009)              $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author:: stelzi                                                   $ *
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'] = ADMIN_USER_PROFILE_LINK($content['userid']); } else { $content['userid'] = "---"; }
87                                 if ($content['refid'] > 0)  { $content['refid']  = ADMIN_USER_PROFILE_LINK($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' => TRANSLATE_COMMA($content['points']),
95                                 'stamp'  => MAKE_DATETIME($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         }
128
129         if (getConfig('doubler_jackpot') == "Y") {
130                 // Load jackpot
131                 $result = SQL_QUERY("SELECT points FROM `{!_MYSQL_PREFIX!}_jackpot` WHERE ok='ok' LIMIT 1", __FUNCTION__, __LINE__);
132                 list($jackpot) = SQL_FETCHROW($result);
133                 SQL_FREERESULT($result);
134
135                 if (!empty($jackpot)) $points += $jackpot;
136         }
137
138         if (getConfig('doubler_uid') > 0) {
139                 // Get user's points
140                 $user = GET_TOTAL_DATA(getConfig('doubler_uid'), "user_points", "points");
141                 $points += $user;
142         }
143
144         // Return value
145         return $points;
146 }
147 //
148 ?>