Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[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 - 2015 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 = sqlQueryEscaped("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 (!ifSqlHasZeroNumRows($result)) {
92                 // List entries
93                 $OUT = '';
94                 while ($content = sqlFetchArray($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                 sqlFreeResult($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 // @TODO This could be rewritten to a filter
131 function getDoublerTotalPointsLeft() {
132         // Initialize variables
133         $points = '0';
134
135         if (getConfig('doubler_own') == 'Y') {
136                 // Take points from doubler's own account
137                 $points += getDoublerPoints() - getConfig('doubler_used');
138         } // END - if
139
140         if ((getConfig('doubler_jackpot') == 'Y') && (isExtensionActive('jackpot'))) {
141                 // Get+add jackpot points
142                 $points += getJackpotPoints();
143         } // END - if
144
145         if (isValidId(getDoublerUserid())) {
146                 // Get user's points
147                 $points += getTotalPoints(getDoublerUserid());
148         } // END - if
149
150         // Return value
151         return $points;
152 }
153
154 //-----------------------------------------------------------------------------
155 //                      Wrapper functions for ext-doubler
156 //-----------------------------------------------------------------------------
157
158 // "Getter" for doubler_userid
159 function getDoublerUserid () {
160         // Is it cached?
161         if (!isset($GLOBALS['doubler_userid'])) {
162                 // Get it
163                 $GLOBALS['doubler_userid'] = getConfig('doubler_userid');
164         } // END - if
165
166         // Return cache
167         return $GLOBALS['doubler_userid'];
168 }
169
170 // "Getter" for doubler_timeout
171 function getDoublerTimeout () {
172         // Is there cache?
173         if (!isset($GLOBALS[__FUNCTION__])) {
174                 // Determine it
175                 $GLOBALS[__FUNCTION__] = getConfig('doubler_timeout');
176         } // END - if
177
178         // Return cache
179         return $GLOBALS[__FUNCTION__];
180 }
181
182 // "Getter" for doubler_send_mode
183 function getDoublerSendMode () {
184         // Is there cache?
185         if (!isset($GLOBALS[__FUNCTION__])) {
186                 // Determine it
187                 $GLOBALS[__FUNCTION__] = getConfig('doubler_send_mode');
188         } // END - if
189
190         // Return cache
191         return $GLOBALS[__FUNCTION__];
192 }
193
194 // "Getter" for doubler_ref
195 function getDoublerRef () {
196         // Is there cache?
197         if (!isset($GLOBALS[__FUNCTION__])) {
198                 // Determine it
199                 $GLOBALS[__FUNCTION__] = getConfig('doubler_ref');
200         } // END - if
201
202         // Return cache
203         return $GLOBALS[__FUNCTION__];
204 }
205
206 // "Getter" for doubler_points
207 function getDoublerPoints () {
208         // Is there cache?
209         if (!isset($GLOBALS[__FUNCTION__])) {
210                 // Determine it
211                 $GLOBALS[__FUNCTION__] = getConfig('doubler_points');
212         } // END - if
213
214         // Return cache
215         return $GLOBALS[__FUNCTION__];
216 }
217
218 // "Getter" for doubler_min
219 function getDoublerMin () {
220         // Is there cache?
221         if (!isset($GLOBALS[__FUNCTION__])) {
222                 // Determine it
223                 $GLOBALS[__FUNCTION__] = getConfig('doubler_min');
224         } // END - if
225
226         // Return cache
227         return $GLOBALS[__FUNCTION__];
228 }
229
230 // "Getter" for doubler_max
231 function getDoublerMax () {
232         // Is there cache?
233         if (!isset($GLOBALS[__FUNCTION__])) {
234                 // Determine it
235                 $GLOBALS[__FUNCTION__] = getConfig('doubler_max');
236         } // END - if
237
238         // Return cache
239         return $GLOBALS[__FUNCTION__];
240 }
241
242 // "Getter" for doubler_counter
243 function getDoublerCounter () {
244         // Is there cache?
245         if (!isset($GLOBALS[__FUNCTION__])) {
246                 // Determine it
247                 $GLOBALS[__FUNCTION__] = getConfig('doubler_counter');
248         } // END - if
249
250         // Return cache
251         return $GLOBALS[__FUNCTION__];
252 }
253
254 // "Getter" for doubler_charge
255 function getDoublerCharge () {
256         // Is there cache?
257         if (!isset($GLOBALS[__FUNCTION__])) {
258                 // Determine it
259                 $GLOBALS[__FUNCTION__] = getConfig('doubler_charge');
260         } // END - if
261
262         // Return cache
263         return $GLOBALS[__FUNCTION__];
264 }
265
266 // "Getter" for doubler_max_sent
267 function getDoublerMaxSent () {
268         // Is there cache?
269         if (!isset($GLOBALS[__FUNCTION__])) {
270                 // Determine it
271                 $GLOBALS[__FUNCTION__] = getConfig('doubler_max_sent');
272         } // END - if
273
274         // Return cache
275         return $GLOBALS[__FUNCTION__];
276 }
277
278 // [EOF]
279 ?>