Mailer project rwritten:
[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 - 2012 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 (isValidId($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`,
72         `refid`,
73         `points`,
74         `timemark`
75 FROM
76         `{?_MYSQL_PREFIX?}_doubler`
77 WHERE
78         `completed`='%s' AND
79         `is_ref`='%s'
80         " . $add . "
81 ORDER BY
82         `timemark` %s
83 LIMIT %s",
84                 array(
85                         $done,
86                         $ref,
87                         $sort,
88                         $limit
89                 ), __FUNCTION__, __LINE__);
90
91         if (!SQL_HASZERONUMS($result)) {
92                 // List entries
93                 $OUT = '';
94                 while ($content = SQL_FETCHARRAY($result)) {
95                         // Rewrite userid/refid only if admin is in
96                         // @TODO Can't this be moved into EL?
97                         if (isAdmin()) {
98                                 // Set empty userid/refid
99                                 $content['userid'] = '---';
100                                 $content['refid']  = '---';
101
102                                 // Set links to admin area
103                                 if (isValidId($content['userid'])) $content['userid'] = generateUserProfileLink($content['userid']);
104                                 if (isValidId($content['refid']))  $content['refid']  = generateUserProfileLink($content['refid']);
105                         } // END - if
106
107                         // Prepare data for the row template
108                         $content['timemark'] = generateDateTime($content['timemark'], $DT_MODE);
109
110                         // Load template and switch color
111                         $OUT .= loadTemplate($mode . '_doubler_list_rows', TRUE, $content);
112                 } // END - while
113
114                 // Free memory
115                 SQL_FREERESULT($result);
116         } else {
117                 // List no entries
118                 $OUT = '<tr>
119   <td colspan="' . $COLS . '" align="center" class="bottom">
120     ' . displayMessage($message, TRUE) . '
121   </td>
122 </tr>';
123         }
124
125         // Return template
126         return loadTemplate($mode . '_doubler_list', TRUE, $OUT);
127 }
128
129 // Get total points left in doubler pot
130 function getDoublerTotalPointsLeft() {
131         // Initialize variables
132         $points = '0';
133
134         if (getConfig('doubler_own') == 'Y') {
135                 // Take points from doubler's own account
136                 $points += getDoublerPoints() - getConfig('doubler_used');
137         } // END - if
138
139         if ((getConfig('doubler_jackpot') == 'Y') && (isExtensionActive('jackpot'))) {
140                 // Load jackpot
141                 $jackpot = getJackpotPoints();
142
143                 if (!empty($jackpot)) $points += $jackpot;
144         } // END - if
145
146         if (isValidId(getDoublerUserid())) {
147                 // Get user's points
148                 $user = getTotalPoints(getDoublerUserid());
149                 $points += $user;
150         } // END - if
151
152         // Return value
153         return $points;
154 }
155
156 //-----------------------------------------------------------------------------
157 //                      Wrapper functions for ext-doubler
158 //-----------------------------------------------------------------------------
159
160 // "Getter" for doubler_userid
161 function getDoublerUserid () {
162         // Is it cached?
163         if (!isset($GLOBALS['doubler_userid'])) {
164                 // Get it
165                 $GLOBALS['doubler_userid'] = getConfig('doubler_userid');
166         } // END - if
167
168         // Return cache
169         return $GLOBALS['doubler_userid'];
170 }
171
172 // "Getter" for doubler_timeout
173 function getDoublerTimeout () {
174         // Is there cache?
175         if (!isset($GLOBALS[__FUNCTION__])) {
176                 // Determine it
177                 $GLOBALS[__FUNCTION__] = getConfig('doubler_timeout');
178         } // END - if
179
180         // Return cache
181         return $GLOBALS[__FUNCTION__];
182 }
183
184 // "Getter" for doubler_send_mode
185 function getDoublerSendMode () {
186         // Is there cache?
187         if (!isset($GLOBALS[__FUNCTION__])) {
188                 // Determine it
189                 $GLOBALS[__FUNCTION__] = getConfig('doubler_send_mode');
190         } // END - if
191
192         // Return cache
193         return $GLOBALS[__FUNCTION__];
194 }
195
196 // "Getter" for doubler_ref
197 function getDoublerRef () {
198         // Is there cache?
199         if (!isset($GLOBALS[__FUNCTION__])) {
200                 // Determine it
201                 $GLOBALS[__FUNCTION__] = getConfig('doubler_ref');
202         } // END - if
203
204         // Return cache
205         return $GLOBALS[__FUNCTION__];
206 }
207
208 // "Getter" for doubler_points
209 function getDoublerPoints () {
210         // Is there cache?
211         if (!isset($GLOBALS[__FUNCTION__])) {
212                 // Determine it
213                 $GLOBALS[__FUNCTION__] = getConfig('doubler_points');
214         } // END - if
215
216         // Return cache
217         return $GLOBALS[__FUNCTION__];
218 }
219
220 // "Getter" for doubler_min
221 function getDoublerMin () {
222         // Is there cache?
223         if (!isset($GLOBALS[__FUNCTION__])) {
224                 // Determine it
225                 $GLOBALS[__FUNCTION__] = getConfig('doubler_min');
226         } // END - if
227
228         // Return cache
229         return $GLOBALS[__FUNCTION__];
230 }
231
232 // "Getter" for doubler_max
233 function getDoublerMax () {
234         // Is there cache?
235         if (!isset($GLOBALS[__FUNCTION__])) {
236                 // Determine it
237                 $GLOBALS[__FUNCTION__] = getConfig('doubler_max');
238         } // END - if
239
240         // Return cache
241         return $GLOBALS[__FUNCTION__];
242 }
243
244 // "Getter" for doubler_counter
245 function getDoublerCounter () {
246         // Is there cache?
247         if (!isset($GLOBALS[__FUNCTION__])) {
248                 // Determine it
249                 $GLOBALS[__FUNCTION__] = getConfig('doubler_counter');
250         } // END - if
251
252         // Return cache
253         return $GLOBALS[__FUNCTION__];
254 }
255
256 // "Getter" for doubler_charge
257 function getDoublerCharge () {
258         // Is there cache?
259         if (!isset($GLOBALS[__FUNCTION__])) {
260                 // Determine it
261                 $GLOBALS[__FUNCTION__] = getConfig('doubler_charge');
262         } // END - if
263
264         // Return cache
265         return $GLOBALS[__FUNCTION__];
266 }
267
268 // "Getter" for doubler_max_sent
269 function getDoublerMaxSent () {
270         // Is there cache?
271         if (!isset($GLOBALS[__FUNCTION__])) {
272                 // Determine it
273                 $GLOBALS[__FUNCTION__] = getConfig('doubler_max_sent');
274         } // END - if
275
276         // Return cache
277         return $GLOBALS[__FUNCTION__];
278 }
279
280 // [EOF]
281 ?>