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 * -------------------------------------------------------------------- *
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 *
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. *
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. *
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, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40 // Don't call this directly!
42 } elseif (!isMember()) {
44 redirectToIndexMemberOnlyModule();
47 // Add description as navigation point
48 addYouAreHereLink('member', __FILE__);
50 if ((!isExtensionActive('payout')) && (!isAdmin())) {
51 displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=payout%}');
55 // Translate point into comma
56 $payoutPoints = getPayoutPoints(getMemberId());
59 displayMessage('{%message,MEMBER_TOTAL_PAYOUT_POINTS=' . $payoutPoints . '%}');
62 if (!isGetRequestElementSet('payout')) {
64 $result = sqlQueryEscaped('SELECT
71 `{?_MYSQL_PREFIX?}_payout_types`
76 array($payoutPoints), __FILE__, __LINE__);
78 // Some entries found?
79 if (!ifSqlHasZeroNums($result)) {
80 // Check for his payouts
81 $result_payouts = sqlQueryEscaped('SELECT
87 `p`.`payout_timestamp`,
94 `{?_MYSQL_PREFIX?}_user_payouts` AS `p`
96 `{?_MYSQL_PREFIX?}_payout_types` AS `t`
98 `p`.`payout_id`=`t`.`id`
102 `p`.`payout_timestamp` DESC',
103 array(getMemberId()), __FILE__, __LINE__);
104 if (!ifSqlHasZeroNums($result_payouts)) {
105 // List all his requests
107 while ($content = sqlFetchArray($result_payouts)) {
108 // Nothing entered must be secured in member/what-payputs.php !
109 if ($content['allow_url'] == 'Y') {
110 // Banner/Textlink views/clicks request
111 if (!empty($content['banner'])) {
113 $content['target_account'] = '<img src="' . $content['banner'] . '" alt="' . $content['link_text'] . '" title="' . $content['link_text'] . '" border="0" />';
116 $content['target_account'] = $content['link_text'];
118 $content['target_bank'] = '<a href="{%pipe,generateDereferrerUrl=' . $content['target_url'] . '%}" target="_blank">{--CLICK_HERE--}</a>';
121 // Prepare data for the template
122 $content['payout_timestamp'] = generateDateTime($content['payout_timestamp'], 2);
124 // Load row template and switch colors
125 $OUT .= loadTemplate('member_payout_row', TRUE, $content);
129 loadTemplate('member_payout', FALSE, $OUT);
133 sqlFreeResult($result_payouts);
135 // Output payout list
136 outputPayoutList($payoutPoints);
138 // No payout types setup
139 displayMessage('{--MEMBER_PAYOUT_SETUP_INCOMPLETE_LOW_POINTS--}');
143 sqlFreeResult($result);
145 // Chedk if he can get paid by selected type
146 $result = sqlQueryEscaped('SELECT
152 `{?_MYSQL_PREFIX?}_payout_types`
156 array(bigintval(getRequestElement('payout'))), __FILE__, __LINE__);
158 if (sqlNumRows($result) == 1) {
159 // id is valid so load the data
160 $content = sqlFetchArray($result);
162 // Calculate maximum value
163 $max = round($payoutPoints * $content['rate'] - 0.5);
166 // Calulcate points from submitted amount
168 if (isPostRequestElementSet('payout')) {
169 $points = bigintval(postRequestElement('payout')) / $content['rate'];
170 $PAY_MAX = $max / $content['rate'];
173 // Has enougth points to payout?
174 if ($payoutPoints >= $content['min_points']) {
175 // Ok, he can get be paid
176 if ((isFormSent()) && ($points <= $PAY_MAX) && ($points >= $content['min_points'])) {
177 // Remember points in array
178 setPostRequestElement('payout_points', $points);
179 setPostRequestElement('type' , $content['type']);
181 // Subtract points from member's account and ignore return status
182 subtractPoints('payout', getMemberId(), $points);
184 // Add entry to his tranfer history
185 if ($content['allow_url'] == 'Y') {
186 // Banner/textlink ordered
187 sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_user_payouts` (`userid`, `payout_total`, `payout_id`, `payout_timestamp`, `status`, `target_url`, `link_text`, `banner_url`)
188 VALUES (%s,%s,%s, UNIX_TIMESTAMP(), 'NEW','%s','%s','%s')",
191 bigintval(postRequestElement('payout')),
192 bigintval(getRequestElement('payout')),
193 postRequestElement('turl'),
194 postRequestElement('link_text'),
195 postRequestElement('banner')
196 ), __FILE__, __LINE__);
199 $message_mem = loadEmailTemplate('member_payout_request_banner', postRequestArray(), getMemberId());
200 if (isExtensionInstalledAndNewer('admins', '0.4.1')) {
201 $adm_tpl = 'admin_payout_request_banner';
203 $message_adm = loadEmailTemplate('admin_payout_request_banner', postRequestArray(), getMemberId());
206 // e-currency payout requested
207 sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_user_payouts` (`userid`, `payout_total`, `target_account`, `target_bank`, `payout_id`, `payout_timestamp`, `status`, `password`)
208 VALUES (%s,%s,%s,'%s',%s, UNIX_TIMESTAMP(), 'NEW','%s')",
211 bigintval(postRequestElement('payout')),
212 bigintval(postRequestElement('account')),
213 postRequestElement('bank'),
214 bigintval(getRequestElement('payout')),
215 postRequestElement('password')
216 ), __FILE__, __LINE__);
219 $message_mem = loadEmailTemplate('member_payout_request', postRequestArray(), getMemberId());
220 $message_adm = loadEmailTemplate('admin_payout_request', postRequestArray(), getMemberId());
223 // @TODO Rewrite this to a filter
224 if (isExtensionInstalledAndNewer('admins', '0.4.1')) {
225 $admin_tpl = 'admin_payout_request';
229 // Generate task (we ignore the task id here)
230 createNewTask('[payout:] {--ADMIN_PAYOUY_REQUEST_SUBJECT--}', $message_adm, 'PAYOUT_REQUEST', getMemberId());
233 sendEmail(getMemberId(), '{--MEMBER_PAYOUT_REQUEST_SUBJECT--}', $message_mem);
236 sendAdminNotification('{--ADMIN_PAYOUY_REQUEST_SUBJECT--}', $admin_tpl, postRequestArray(), getMemberId());
238 // Load template and output it
239 displayMessage('{--MEMBER_PAYOUT_REQUEST_SENT--}');
240 } elseif ($content['allow_url'] == 'Y') {
244 'type' => $content['type'],
245 'payout' => bigintval(getRequestElement('payout'))
248 // Generate banner order form
249 loadTemplate('member_payout_form_banner', FALSE, $content);
254 'type' => $content['type'],
255 'payout' => bigintval(getRequestElement('payout'))
258 // Generate normal form
259 loadTemplate('member_payout_form', FALSE, $content);
262 // Not enougth points
263 displayMessage('{--MEMBER_PAYOUT_POINTS_NOT_ENOUGTH--}');
267 displayMessage('{--MEMBER_PAYOUT_ID_INVALID--}');
271 sqlFreeResult($result);