Bad things are now 'classified' as bad (CSS class 'bad' is being used instead of...
[mailer.git] / inc / libs / doubler_functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
43 // Generates a HTML table based on given data
44 // @TODO Lame description
45 function generateDoublerTable ($userid = NULL, $done = 'N', $ref = 'N', $sort = 'ASC') {
46         $add = ''; $DT_MODE = '0';
47         if (isValidUserId($userid)) {
48                 // Load entries only from a single user
49                 $add = sprintf(" AND `userid`=%s", bigintval($userid));
50                 $mode = 'member'; $COLS = 4; $DT_MODE = 2;
51                 $message = '{--MEMBER_DOUBLER_NO_ENTRIES_FOUND--}';
52         } else {
53                 // Guest mode!
54                 $mode = 'guest'; $COLS = 3; $DT_MODE = 3;
55                 $message = '{--GUEST_DOUBLER_NO_ENTRIES_FOUND--}';
56         }
57
58         if (($done == 'Y') && ($sort == 'ASC')) {
59                 // Already payed out points (latest payouts first)
60                 $limit = getConfig('doubler_display_old');
61         } elseif ($sort == 'ASC') {
62                 // List entries which will receive their payout soon
63                 $limit = getConfig('doubler_display_pay');
64         } elseif ($sort == 'DESC') {
65                 // Newest entries
66                 $limit = getConfig('doubler_display_new');
67         }
68
69         // List entries
70         $result = SQL_QUERY_ESC("SELECT
71         `userid`,`refid`,`points`,`timemark`
72 FROM
73         `{?_MYSQL_PREFIX?}_doubler`
74 WHERE
75         `completed`='%s' AND
76         `is_ref`='%s'
77         " . $add . "
78 ORDER BY
79         `timemark` %s
80 LIMIT %s",
81                 array(
82                         $done,
83                         $ref,
84                         $sort,
85                         $limit
86                 ), __FUNCTION__, __LINE__);
87
88         if (!SQL_HASZERONUMS($result)) {
89                 // List entries
90                 $OUT = '';
91                 while ($content = SQL_FETCHARRAY($result)) {
92                         // Rewrite userid/refid only if admin is in
93                         // @TODO Can't this be moved into EL?
94                         if (isAdmin()) {
95                                 // Set empty userid/refid
96                                 $content['userid'] = '---';
97                                 $content['refid']  = '---';
98
99                                 // Set links to admin area
100                                 if (isValidUserId($content['userid'])) $content['userid'] = generateUserProfileLink($content['userid']);
101                                 if (isValidUserId($content['refid']))  $content['refid']  = generateUserProfileLink($content['refid']);
102                         } // END - if
103
104                         // Prepare data for the row template
105                         $content['timemark'] = generateDateTime($content['timemark'], $DT_MODE);
106
107                         // Load template and switch color
108                         $OUT .= loadTemplate($mode . '_doubler_list_rows', true, $content);
109                 } // END - while
110
111                 // Free memory
112                 SQL_FREERESULT($result);
113         } else {
114                 // List no entries
115                 $OUT = '<tr>
116   <td colspan="' . $COLS . '" align="center" class="bottom">
117     ' . displayMessage($message, true) . '
118   </td>
119 </tr>';
120         }
121
122         // Return template
123         return loadTemplate($mode . '_doubler_list', true, $OUT);
124 }
125
126 // Get total points left in doubler pot
127 function getDoublerTotalPointsLeft() {
128         // Initialize variables
129         $points = '0';
130
131         if (getConfig('doubler_own') == 'Y') {
132                 // Take points from doubler's own account
133                 $points += getConfig('doubler_points') - getConfig('doubler_used');
134         } // END - if
135
136         if ((getConfig('doubler_jackpot') == 'Y') && (isExtensionActive('jackpot'))) {
137                 // Load jackpot
138                 $jackpot = getJackpotPoints();
139
140                 if (!empty($jackpot)) $points += $jackpot;
141         } // END - if
142
143         if (isValidUserId(getConfig('doubler_userid'))) {
144                 // Get user's points
145                 $user = getTotalPoints(getConfig('doubler_userid'));
146                 $points += $user;
147         } // END - if
148
149         // Return value
150         return $points;
151 }
152
153 //-----------------------------------------------------------------------------
154 //                      Wrapper functions for ext-doubler
155 //-----------------------------------------------------------------------------
156
157 // "Getter" for doubler_userid
158 function getDoublerUserid () {
159         // Is it cached?
160         if (!isset($GLOBALS['doubler_userid'])) {
161                 // Get it
162                 $GLOBALS['doubler_userid'] = getConfig('doubler_userid');
163         } // END - if
164
165         // Return cache
166         return $GLOBALS['doubler_userid'];
167 }
168
169 // "Getter" for doubler_timeout
170 function getDoublerTimeout () {
171         // Do we have cache?
172         if (!isset($GLOBALS[__FUNCTION__])) {
173                 // Determine it
174                 $GLOBALS[__FUNCTION__] = getConfig('doubler_timeout');
175         } // END - if
176
177         // Return cache
178         return $GLOBALS[__FUNCTION__];
179 }
180
181 // "Getter" for doubler_send_mode
182 function getDoublerSendMode () {
183         // Do we have cache?
184         if (!isset($GLOBALS[__FUNCTION__])) {
185                 // Determine it
186                 $GLOBALS[__FUNCTION__] = getConfig('doubler_send_mode');
187         } // END - if
188
189         // Return cache
190         return $GLOBALS[__FUNCTION__];
191 }
192
193 // "Getter" for doubler_ref
194 function getDoublerRef () {
195         // Do we have cache?
196         if (!isset($GLOBALS[__FUNCTION__])) {
197                 // Determine it
198                 $GLOBALS[__FUNCTION__] = getConfig('doubler_ref');
199         } // END - if
200
201         // Return cache
202         return $GLOBALS[__FUNCTION__];
203 }
204
205 // "Getter" for doubler_points
206 function getDoublerPoints () {
207         // Do we have cache?
208         if (!isset($GLOBALS[__FUNCTION__])) {
209                 // Determine it
210                 $GLOBALS[__FUNCTION__] = getConfig('doubler_points');
211         } // END - if
212
213         // Return cache
214         return $GLOBALS[__FUNCTION__];
215 }
216
217 // "Getter" for doubler_min
218 function getDoublerMin () {
219         // Do we have cache?
220         if (!isset($GLOBALS[__FUNCTION__])) {
221                 // Determine it
222                 $GLOBALS[__FUNCTION__] = getConfig('doubler_min');
223         } // END - if
224
225         // Return cache
226         return $GLOBALS[__FUNCTION__];
227 }
228
229 // "Getter" for doubler_max
230 function getDoublerMax () {
231         // Do we have cache?
232         if (!isset($GLOBALS[__FUNCTION__])) {
233                 // Determine it
234                 $GLOBALS[__FUNCTION__] = getConfig('doubler_max');
235         } // END - if
236
237         // Return cache
238         return $GLOBALS[__FUNCTION__];
239 }
240
241 // "Getter" for doubler_counter
242 function getDoublerCounter () {
243         // Do we have cache?
244         if (!isset($GLOBALS[__FUNCTION__])) {
245                 // Determine it
246                 $GLOBALS[__FUNCTION__] = getConfig('doubler_counter');
247         } // END - if
248
249         // Return cache
250         return $GLOBALS[__FUNCTION__];
251 }
252
253 // "Getter" for doubler_charge
254 function getDoublerCharge () {
255         // Do we have cache?
256         if (!isset($GLOBALS[__FUNCTION__])) {
257                 // Determine it
258                 $GLOBALS[__FUNCTION__] = getConfig('doubler_charge');
259         } // END - if
260
261         // Return cache
262         return $GLOBALS[__FUNCTION__];
263 }
264
265 // [EOF]
266 ?>