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 - 2012 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());
58 if (!isGetRequestElementSet('payout')) {
60 $result = SQL_QUERY_ESC("SELECT
67 `{?_MYSQL_PREFIX?}_payout_types`
72 array($payoutPoints), __FILE__, __LINE__);
73 if (!SQL_HASZERONUMS($result)) {
75 SQL_FREERESULT($result);
77 // Check for his payouts
78 $result_payouts = SQL_QUERY_ESC("SELECT
86 t.`allow_url` AS `allow`,
87 p.`target_url` AS `url`,
89 p.`banner_url` AS `banner`
91 `{?_MYSQL_PREFIX?}_user_payouts` AS `p`
93 `{?_MYSQL_PREFIX?}_payout_types` AS `t`
95 p.`payout_id` = t.`id`
99 p.`payout_timestamp` DESC",
100 array(getMemberId()), __FILE__, __LINE__);
101 if (!SQL_HASZERONUMS($result_payouts)) {
102 // List all his requests
104 while ($content = SQL_FETCHARRAY($result_payouts)) {
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['link_text'] . '" title="' . $content['link_text'] . '" border="0" />';
113 $content['target_account'] = $content['link_text'];
115 $content['target_bank'] = '<a href="{%pipe,generateDereferrerUrl=' . $content['url'] . '%}" target="_blank">{--CLICK_HERE--}</a>';
118 // Prepare data for the template
119 $content['payout_timestamp'] = generateDateTime($content['payout_timestamp'], 2);
121 // Load row template and switch colors
122 $OUT .= loadTemplate('member_payout_row', TRUE, $content);
126 loadTemplate('member_payout', FALSE, $OUT);
130 SQL_FREERESULT($result_payouts);
132 // Output payout list
133 outputPayoutList($payoutPoints);
135 // No payout types setup
136 displayMessage('{--MEMBER_PAYOUT_SETUP_INCOMPLETE--}');
139 // Chedk if he can get paid by selected type
140 $result = SQL_QUERY_ESC("SELECT `type`, `rate`, `min_points`, `allow_url` AS allow FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE `id`=%s LIMIT 1",
141 array(bigintval(getRequestElement('payout'))), __FILE__, __LINE__);
143 if (SQL_NUMROWS($result) == 1) {
144 // id is valid so load the data
145 $content = SQL_FETCHARRAY($result);
147 // Calculate maximum value
148 $max = round($payoutPoints * $content['rate'] - 0.5);
151 // Calulcate points from submitted amount
153 if (isPostRequestElementSet('payout')) {
154 $points = bigintval(postRequestElement('payout')) / $content['rate'];
155 $PAY_MAX = $max / $content['rate'];
158 // Has enougth points to payout?
159 if ($payoutPoints >= $content['min_points']) {
160 // Ok, he can get be paid
161 if ((isFormSent()) && ($points <= $PAY_MAX) && ($points >= $content['min_points'])) {
162 // Remember points in array
163 setPostRequestElement('payout_points', $points);
164 setPostRequestElement('type' , $content['type']);
166 // Subtract points from member's account and ignore return status
167 subtractPoints('payout', getMemberId(), $points);
169 // Add entry to his tranfer history
170 if ($content['allow'] == 'Y') {
171 // Banner/textlink ordered
172 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_payouts` (`userid`, `payout_total`, `payout_id`, `payout_timestamp`, `status`, `target_url`, `link_text`, `banner_url`)
173 VALUES (%s,%s,%s, UNIX_TIMESTAMP(), 'NEW','%s','%s','%s')",
176 bigintval(postRequestElement('payout')),
177 bigintval(getRequestElement('payout')),
178 postRequestElement('turl'),
179 postRequestElement('link_text'),
180 postRequestElement('banner')
181 ), __FILE__, __LINE__);
184 $message_mem = loadEmailTemplate('member_payout_request_banner', postRequestArray(), getMemberId());
185 if (isExtensionInstalledAndNewer('admins', '0.4.1')) {
186 $adm_tpl = 'admin_payout_request_banner';
188 $message_adm = loadEmailTemplate('admin_payout_request_banner', postRequestArray(), getMemberId());
191 // e-currency payout requested
192 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_payouts` (`userid`, `payout_total`, `target_account`, `target_bank`, `payout_id`, `payout_timestamp`, `status`, `password`)
193 VALUES (%s,%s,%s,'%s',%s, UNIX_TIMESTAMP(), 'NEW','%s')",
196 bigintval(postRequestElement('payout')),
197 bigintval(postRequestElement('account')),
198 postRequestElement('bank'),
199 bigintval(getRequestElement('payout')),
200 postRequestElement('password')
201 ), __FILE__, __LINE__);
204 $message_mem = loadEmailTemplate('member_payout_request', postRequestArray(), getMemberId());
205 $message_adm = loadEmailTemplate('admin_payout_request', postRequestArray(), getMemberId());
208 // @TODO Rewrite this to a filter
209 if (isExtensionInstalledAndNewer('admins', '0.4.1')) {
210 $admin_tpl = 'admin_payout_request';
214 // Generate task (we ignore the task id here)
215 createNewTask('[payout:] {--ADMIN_PAYOUY_REQUEST_SUBJECT--}', $message_adm, 'PAYOUT_REQUEST', getMemberId());
218 sendEmail(getMemberId(), '{--MEMBER_PAYOUT_REQUEST_SUBJECT--}', $message_mem);
221 sendAdminNotification('{--ADMIN_PAYOUY_REQUEST_SUBJECT--}', $admin_tpl, postRequestArray(), getMemberId());
223 // Load template and output it
224 displayMessage('{--MEMBER_PAYOUT_REQUEST_SENT--}');
225 } elseif ($content['allow'] == 'Y') {
229 'type' => $content['type'],
230 'payout' => bigintval(getRequestElement('payout'))
233 // Generate banner order form
234 loadTemplate('member_payout_form_banner', FALSE, $content);
239 'type' => $content['type'],
240 'payout' => bigintval(getRequestElement('payout'))
243 // Generate normal form
244 loadTemplate('member_payout_form', FALSE, $content);
247 // Not enougth points
248 displayMessage('{--MEMBER_PAYOUT_POINTS_NOT_ENOUGTH--}');
252 displayMessage('{--MEMBER_PAYOUT_ID_INVALID--}');
256 SQL_FREERESULT($result);