All CSS classes top2,bottom2,right2,left2 are now deprecated, user details now have...
[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  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 }
43
44 // Generates a HTML table based on given data
45 // @TODO Lame description
46 function generateDoublerTable ($userid = '0', $done = 'N', $ref = 'N', $sort = 'ASC') {
47         if (empty($cnt)) $cnt = '0';
48         $add = ''; $DT_MODE = '0';
49         if ($userid > 0) {
50                 // Load entries only from a single user
51                 $add = sprintf(" AND `userid`=%s", bigintval($userid));
52                 $mode = 'member'; $COLS = 4; $DT_MODE = 2;
53                 $message = getMessage('DOUBLER_MEMBER_NO_ENTRIES_FOUND');
54         } else {
55                 // Guest mode!
56                 $mode = 'guest'; $COLS = 3; $DT_MODE = 3;
57                 $message = getMessage('DOUBLER_GUEST_NO_ENTRIES_FOUND');
58         }
59
60         if (($done == 'Y') && ($sort == 'ASC')) {
61                 // Already payed out points (latest payouts first)
62                 $limit = getConfig('doubler_display_old');
63         } elseif ($sort == 'ASC') {
64                 // List entries which will receive their payout soon
65                 $limit = getConfig('doubler_display_pay');
66         } elseif ($sort == 'DESC') {
67                 // Newest entries
68                 $limit = getConfig('doubler_display_new');
69         }
70
71         // List entries
72         $result = SQL_QUERY("SELECT
73         `userid`, `refid`, `points`, `timemark`
74 FROM
75         `{?_MYSQL_PREFIX?}_doubler`
76 WHERE
77         `completed`='".$done."' AND `is_ref`='".$ref."'".$add."
78 ORDER BY
79         `timemark` ".$sort."
80 LIMIT ".$limit, __FUNCTION__, __LINE__);
81
82         if (SQL_NUMROWS($result) > 0) {
83                 // List entries
84                 $OUT = ''; $SW = 2;
85                 while ($content = SQL_FETCHARRAY($result)) {
86                         // Rewrite userid/refid only if admin is in
87                         if (isAdmin()) {
88                                 // Set links to admin area
89                                 if ($content['userid'] > 0) { $content['userid'] = generateUserProfileLink($content['userid']); } else { $content['userid'] = '---'; }
90                                 if ($content['refid'] > 0)  { $content['refid']  = generateUserProfileLink($content['refid']);  } else { $content['refid']  = '---'; }
91                         } // END - if
92
93                         // Prepare data for the row template
94                         $content = array(
95                                 'userid'   => $content['userid'],
96                                 'rid'      => $content['refid'],
97                                 'points'   => translateComma($content['points']),
98                                 'timemark' => generateDateTime($content['timemark'], $DT_MODE),
99                                 'sw'       => $SW,
100                         );
101
102                         // Load template and switch color
103                         $OUT .= loadTemplate($mode . '_doubler_list_rows', true, $content);
104                         $SW = 3 - $SW;
105                 }
106
107                 // Free memory
108                 SQL_FREERESULT($result);
109         } else {
110                 // List no entries
111                 $OUT = "<tr>
112   <td colspan=\"".$COLS."\" align=\"center\" class=\"doubler_big_row bottom\">
113     ".loadTemplate('admin_settings_saved', true, $message)."
114   </td>
115 </tr>\n";
116         }
117
118         // Return template
119         return loadTemplate($mode . '_doubler_list', true, $OUT);
120 }
121
122 //
123 function DOUBLER_GET_TOTAL_POINTS_LEFT() {
124         // Initialize variables
125         $points = '0';
126
127         if (getConfig('doubler_own') == 'Y') {
128                 // Take points from doubler's own account
129                 $points += getConfig('doubler_points') - getConfig('doubler_used');
130         } // END - if
131
132         if ((getConfig('doubler_jackpot') == 'Y') && (isExtensionActive('jackpot'))) {
133                 // Load jackpot
134                 $jackpot = getJackpotPoints();
135
136                 if (!empty($jackpot)) $points += $jackpot;
137         } // END - if
138
139         if (getConfig('doubler_userid') > 0) {
140                 // Get user's points
141                 $user = countSumTotalData(getConfig('doubler_userid'), 'user_points', 'points');
142                 $points += $user;
143         } // END - if
144
145         // Return value
146         return $points;
147 }
148 //
149 ?>