2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 04/12/2004 *
4 * =================== Last change: 12/01/2008 *
6 * -------------------------------------------------------------------- *
7 * File : what-payout.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Payout requests *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Auszahlungsanfragen *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 *
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. *
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. *
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, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41 // Don't call this directly!
43 } elseif (!isMember()) {
45 redirectToIndexMemberOnlyModule();
48 // Add description as navigation point
49 addMenuDescription('member', __FILE__);
51 if ((!isExtensionActive('payout')) && (!isAdmin())) {
52 loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('payout'));
57 $totalPoints = countSumTotalData(getMemberId(), 'user_points', 'points');
60 $usedPoints = countSumTotalData(getMemberId(), 'user_data', 'used_points');
62 // Translate point into comma
63 $totalPoints = ($totalPoints - $usedPoints);
66 if (empty($totalPoints)) $totalPoints = '0.00000';
68 if (!isGetRequestParameterSet('payout')) {
70 $result = SQL_QUERY_ESC("SELECT
71 `id`, `type`, `rate`, `min_points`, `allow_url`
73 `{?_MYSQL_PREFIX?}_payout_types`
78 array($totalPoints), __FILE__, __LINE__);
79 if (SQL_NUMROWS($result) > 0) {
81 SQL_FREERESULT($result);
83 // Check for his payouts
84 $result_payouts = SQL_QUERY_ESC("SELECT
85 p.id, p.payout_total, p.target_account, p.target_bank, t.type, p.payout_timestamp, p.status, t.allow_url AS allow, p.target_url AS url, p.link_text AS alt, p.banner_url AS banner
87 `{?_MYSQL_PREFIX?}_user_payouts` AS p
89 `{?_MYSQL_PREFIX?}_payout_types` AS t
95 p.payout_timestamp DESC",
96 array(getMemberId()), __FILE__, __LINE__);
97 if (SQL_NUMROWS($result_payouts) > 0) {
98 // List all his requests
100 while ($content = SQL_FETCHARRAY($result_payouts)) {
102 $content['status'] = getMessage('PAYOUT_MEMBER_STATUS_'.strtoupper($content['status']).'');
103 $content['status'] = '<div class="member_failed">' . $content['status'] . '</div>';
105 // Nothing entered must be secured in member/what-payputs.php !
106 if ($content['allow'] == 'Y') {
107 // Banner/Textlink views/clicks request
108 if (!empty($content['banner'])) {
110 $content['target_account'] = "<img src=\"".$content['banner']."\" alt=\"".$content['alt']."\" title=\"".$content['alt']."\" border=\"0\" />";
113 $content['target_account'] = $content['alt'];
115 $content['target_bank'] = '<a href="' . generateDerefererUrl($content['url']) . '" target="_blank">{--CLICK_HERE--}</a>';
117 // e-currency payout request
118 if (empty($content['target_account'])) $content['target_account'] = '---';
119 if (empty($content['target_bank'])) $content['target_bank'] = '---';
122 // Prepare data for the template
125 'target_account' => $content['target_account'],
126 'points' => translateComma($content['payout_total']) . ' ' . $content['type'],
127 'target_bank' => $content['target_bank'],
128 'payout_timestamp' => generateDateTime($content['payout_timestamp'], 2),
129 'status' => $content['status']
132 // Load row template and switch colors
133 $OUT .= loadTemplate('member_payout_row', true, $content);
138 loadTemplate('member_payout', false, $OUT);
142 SQL_FREERESULT($result_payouts);
144 // Output payout list
145 outputPayoutList($totalPoints);
147 // No payout types setup
148 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_NO_PAYOUT_TYPES'));
151 // Chedk if he can get paid by selected type
152 $result = SQL_QUERY_ESC("SELECT type, rate, min_points, allow_url AS allow FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE `id`=%s LIMIT 1",
153 array(bigintval(getRequestParameter('payout'))), __FILE__, __LINE__);
155 if (SQL_NUMROWS($result) == 1) {
156 // id is valid so load the data
157 $content = SQL_FETCHARRAY($result);
159 // Calculate maximum value
160 $max = round($totalPoints * $content['rate'] - 0.5);
163 // Calulcate points from submitted amount
165 if (isPostRequestParameterSet('payout')) {
166 $points = bigintval(postRequestParameter('payout')) / $content['rate'];
167 $PAY_MAX = $max / $content['rate'];
170 // Has enougth points to payout?
171 if ($totalPoints >= $content['min_points']) {
172 // Ok, he can get be paid
173 if ((isFormSent()) && ($points <= $PAY_MAX) && ($points >= $content['min_points'])) {
174 // Remember points in array
175 setPostRequestParameter('payout_points', translateComma($points));
176 setPostRequestParameter('type' , $content['type']);
178 // Subtract points from member's account
179 subtractPoints('payout', getMemberId(), $points);
181 // Add entry to his tranfer history
182 if ($content['allow'] == 'Y') {
183 // Banner/textlink ordered
184 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_payouts` (`userid`, `payout_total`, `payout_id`, `payout_timestamp`, `status`, `target_url`, `link_text`, `banner_url`)
185 VALUES (%s,%s,%s, UNIX_TIMESTAMP(), 'NEW','%s','%s','%s')",
188 bigintval(postRequestParameter('payout')),
189 bigintval(getRequestParameter('payout')),
190 postRequestParameter('turl'),
191 postRequestParameter('alt'),
192 postRequestParameter('banner')
193 ), __FILE__, __LINE__);
196 $message_mem = loadEmailTemplate('member_payout_request_banner', postRequestArray(), getMemberId());
197 if (getExtensionVersion('admins') >= '0.4.1') {
198 $adm_tpl = 'admin_payout_request_banner';
200 $message_adm = loadEmailTemplate('admin_payout_request_banner', postRequestArray(), getMemberId());
203 // e-currency payout requested
204 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_payouts` (`userid`, `payout_total`, `target_account`, `target_bank`, `payout_id`, `payout_timestamp`, `status`, `password`)
205 VALUES (%s,%s,%s,'%s',%s, UNIX_TIMESTAMP(), 'NEW','%s')",
208 bigintval(postRequestParameter('payout')),
209 bigintval(postRequestParameter('account')),
210 postRequestParameter('bank'),
211 bigintval(getRequestParameter('payout')),
212 postRequestParameter('pass')
213 ), __FILE__, __LINE__);
216 $message_mem = loadEmailTemplate('member_payout_request', postRequestArray(), getMemberId());
217 $message_adm = loadEmailTemplate('admin_payout_request', postRequestArray(), getMemberId());
220 // @TODO Rewrite this to a filter
221 if (getExtensionVersion('admins') >= '0.4.1') {
222 $admin_tpl = 'admin_payout_request';
227 createNewTask('[payout:] {--PAYOUT_REQUEST_ADMIN--}', $message_adm, 'PAYOUT_REQUEST', getMemberId());
230 sendEmail(getMemberId(), getMessage('PAYOUT_REQUEST_MEMBER'), $message_mem);
233 sendAdminNotification(getMessage('PAYOUT_REQUEST_ADMIN'), $admin_tpl, postRequestArray(), getMemberId());
235 // Load template and output it
236 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_REQUEST_SENT'));
237 } elseif ($content['allow'] == 'Y') {
241 'type' => $content['type'],
242 'payout' => bigintval(getRequestParameter('payout'))
245 // Generate banner order form
246 loadTemplate('member_payout_form_banner', false, $content);
251 'type' => $content['type'],
252 'payout' => bigintval(getRequestParameter('payout'))
255 // Generate normal form
256 loadTemplate('member_payout_form', false, $content);
259 // Not enougth points
260 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_POINTS_NOT_ENOUGTH'));
264 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_ID_INVALID'));
268 SQL_FREERESULT($result);