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