Removed comment introduced by Profi-Concept, this comment should fine (in a much...
[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, 2010 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 }
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         if (empty($cnt)) $cnt = '0';
47         $add = ''; $DT_MODE = '0';
48         if (isValidUserId($userid)) {
49                 // Load entries only from a single user
50                 $add = sprintf(" AND `userid`=%s", bigintval($userid));
51                 $mode = 'member'; $COLS = 4; $DT_MODE = 2;
52                 $message = '{--MEMBER_DOUBLER_NO_ENTRIES_FOUND--}';
53         } else {
54                 // Guest mode!
55                 $mode = 'guest'; $COLS = 3; $DT_MODE = 3;
56                 $message = '{--GUEST_DOUBLER_NO_ENTRIES_FOUND--}';
57         }
58
59         if (($done == 'Y') && ($sort == 'ASC')) {
60                 // Already payed out points (latest payouts first)
61                 $limit = getConfig('doubler_display_old');
62         } elseif ($sort == 'ASC') {
63                 // List entries which will receive their payout soon
64                 $limit = getConfig('doubler_display_pay');
65         } elseif ($sort == 'DESC') {
66                 // Newest entries
67                 $limit = getConfig('doubler_display_new');
68         }
69
70         // List entries
71         $result = SQL_QUERY_ESC("SELECT
72         `userid`, `refid`, `points`, `timemark`
73 FROM
74         `{?_MYSQL_PREFIX?}_doubler`
75 WHERE
76         `completed`='%s' AND `is_ref`='%s'" . $add . "
77 ORDER BY
78         `timemark` %s
79 LIMIT %s",
80                 array(
81                         $done,
82                         $ref,
83                         $sort,
84                         $limit
85                 ), __FUNCTION__, __LINE__);
86
87         if (!SQL_HASZERONUMS($result)) {
88                 // List entries
89                 $OUT = '';
90                 while ($content = SQL_FETCHARRAY($result)) {
91                         // Rewrite userid/refid only if admin is in
92                         // @TODO Can't this be moved into EL?
93                         if (isAdmin()) {
94                                 // Set empty userid/refid
95                                 $content['userid'] = '---';
96                                 $content['refid']  = '---';
97
98                                 // Set links to admin area
99                                 if (isValidUserId($content['userid'])) $content['userid'] = generateUserProfileLink($content['userid']);
100                                 if (isValidUserId($content['refid']))  $content['refid']  = generateUserProfileLink($content['refid']);
101                         } // END - if
102
103                         // Prepare data for the row template
104                         $content['timemark'] = generateDateTime($content['timemark'], $DT_MODE);
105
106                         // Load template and switch color
107                         $OUT .= loadTemplate($mode . '_doubler_list_rows', true, $content);
108                 } // END - while
109
110                 // Free memory
111                 SQL_FREERESULT($result);
112         } else {
113                 // List no entries
114                 $OUT = '<tr>
115   <td colspan="' . $COLS . '" align="center" class="bottom">
116     ' . loadTemplate('admin_settings_saved', true, $message) . '
117   </td>
118 </tr>';
119         }
120
121         // Return template
122         return loadTemplate($mode . '_doubler_list', true, $OUT);
123 }
124
125 // Get total points left in doubler pot
126 function getDoublerTotalPointsLeft() {
127         // Initialize variables
128         $points = '0';
129
130         if (getConfig('doubler_own') == 'Y') {
131                 // Take points from doubler's own account
132                 $points += getConfig('doubler_points') - getConfig('doubler_used');
133         } // END - if
134
135         if ((getConfig('doubler_jackpot') == 'Y') && (isExtensionActive('jackpot'))) {
136                 // Load jackpot
137                 $jackpot = getJackpotPoints();
138
139                 if (!empty($jackpot)) $points += $jackpot;
140         } // END - if
141
142         if (isValidUserId(getConfig('doubler_userid'))) {
143                 // Get user's points
144                 $user = getTotalPoints(getConfig('doubler_userid'));
145                 $points += $user;
146         } // END - if
147
148         // Return value
149         return $points;
150 }
151
152 // "Getter" for doubler_userid
153 function getDoublerUserid () {
154         // Is it cached?
155         if (!isset($GLOBALS['doubler_userid'])) {
156                 // Get it
157                 $GLOBALS['doubler_userid'] = getConfig('doubler_userid');
158         } // END - if
159
160         // Return cache
161         return $GLOBALS['doubler_userid'];
162 }
163
164 // [EOF]
165 ?>