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 - 2011 by Mailer Developer Team *
20 * For more information visit: http://www.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 (!isGetRequestParameterSet('payout')) {
60 $result = SQL_QUERY_ESC("SELECT
61 `id`, `type`, `rate`, `min_points`, `allow_url`
63 `{?_MYSQL_PREFIX?}_payout_types`
68 array($payoutPoints), __FILE__, __LINE__);
69 if (!SQL_HASZERONUMS($result)) {
71 SQL_FREERESULT($result);
73 // Check for his payouts
74 $result_payouts = SQL_QUERY_ESC("SELECT
75 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, p.banner_url AS banner
77 `{?_MYSQL_PREFIX?}_user_payouts` AS p
79 `{?_MYSQL_PREFIX?}_payout_types` AS t
85 p.payout_timestamp DESC",
86 array(getMemberId()), __FILE__, __LINE__);
87 if (!SQL_HASZERONUMS($result_payouts)) {
88 // List all his requests
90 while ($content = SQL_FETCHARRAY($result_payouts)) {
91 // Nothing entered must be secured in member/what-payputs.php !
92 if ($content['allow'] == 'Y') {
93 // Banner/Textlink views/clicks request
94 if (!empty($content['banner'])) {
96 $content['target_account'] = '<img src="' . $content['banner'] . '" alt="' . $content['link_text'] . '" title="' . $content['link_text'] . '" border="0" />';
99 $content['target_account'] = $content['link_text'];
101 $content['target_bank'] = '<a href="' . generateDerefererUrl($content['url']) . '" target="_blank">{--CLICK_HERE--}</a>';
104 // Prepare data for the template
105 $content['payout_timestamp'] = generateDateTime($content['payout_timestamp'], 2);
107 // Load row template and switch colors
108 $OUT .= loadTemplate('member_payout_row', true, $content);
112 loadTemplate('member_payout', false, $OUT);
116 SQL_FREERESULT($result_payouts);
118 // Output payout list
119 outputPayoutList($payoutPoints);
121 // No payout types setup
122 displayMessage('{--MEMBER_PAYOUT_SETUP_INCOMPLETE--}');
125 // Chedk if he can get paid by selected type
126 $result = SQL_QUERY_ESC("SELECT `type`, `rate`, `min_points`, `allow_url` AS allow FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE `id`=%s LIMIT 1",
127 array(bigintval(getRequestParameter('payout'))), __FILE__, __LINE__);
129 if (SQL_NUMROWS($result) == 1) {
130 // id is valid so load the data
131 $content = SQL_FETCHARRAY($result);
133 // Calculate maximum value
134 $max = round($payoutPoints * $content['rate'] - 0.5);
137 // Calulcate points from submitted amount
139 if (isPostRequestParameterSet('payout')) {
140 $points = bigintval(postRequestParameter('payout')) / $content['rate'];
141 $PAY_MAX = $max / $content['rate'];
144 // Has enougth points to payout?
145 if ($payoutPoints >= $content['min_points']) {
146 // Ok, he can get be paid
147 if ((isFormSent()) && ($points <= $PAY_MAX) && ($points >= $content['min_points'])) {
148 // Remember points in array
149 setPostRequestParameter('payout_points', $points);
150 setPostRequestParameter('type' , $content['type']);
152 // Subtract points from member's account
153 subtractPoints('payout', getMemberId(), $points);
155 // Add entry to his tranfer history
156 if ($content['allow'] == 'Y') {
157 // Banner/textlink ordered
158 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_payouts` (`userid`, `payout_total`, `payout_id`, `payout_timestamp`, `status`, `target_url`, `link_text`, `banner_url`)
159 VALUES (%s,%s,%s, UNIX_TIMESTAMP(), 'NEW','%s','%s','%s')",
162 bigintval(postRequestParameter('payout')),
163 bigintval(getRequestParameter('payout')),
164 postRequestParameter('turl'),
165 postRequestParameter('link_text'),
166 postRequestParameter('banner')
167 ), __FILE__, __LINE__);
170 $message_mem = loadEmailTemplate('member_payout_request_banner', postRequestArray(), getMemberId());
171 if (isExtensionInstalledAndNewer('admins', '0.4.1')) {
172 $adm_tpl = 'admin_payout_request_banner';
174 $message_adm = loadEmailTemplate('admin_payout_request_banner', postRequestArray(), getMemberId());
177 // e-currency payout requested
178 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_payouts` (`userid`, `payout_total`, `target_account`, `target_bank`, `payout_id`, `payout_timestamp`, `status`, `password`)
179 VALUES (%s,%s,%s,'%s',%s, UNIX_TIMESTAMP(), 'NEW','%s')",
182 bigintval(postRequestParameter('payout')),
183 bigintval(postRequestParameter('account')),
184 postRequestParameter('bank'),
185 bigintval(getRequestParameter('payout')),
186 postRequestParameter('password')
187 ), __FILE__, __LINE__);
190 $message_mem = loadEmailTemplate('member_payout_request', postRequestArray(), getMemberId());
191 $message_adm = loadEmailTemplate('admin_payout_request', postRequestArray(), getMemberId());
194 // @TODO Rewrite this to a filter
195 if (isExtensionInstalledAndNewer('admins', '0.4.1')) {
196 $admin_tpl = 'admin_payout_request';
200 // Generate task (we ignore the task id here)
201 createNewTask('[payout:] {--ADMIN_PAYOUY_REQUEST_SUBJECT--}', $message_adm, 'PAYOUT_REQUEST', getMemberId());
204 sendEmail(getMemberId(), '{--MEMBER_PAYOUT_REQUEST_SUBJECT--}', $message_mem);
207 sendAdminNotification('{--ADMIN_PAYOUY_REQUEST_SUBJECT--}', $admin_tpl, postRequestArray(), getMemberId());
209 // Load template and output it
210 displayMessage('{--MEMBER_PAYOUT_REQUEST_SENT--}');
211 } elseif ($content['allow'] == 'Y') {
215 'type' => $content['type'],
216 'payout' => bigintval(getRequestParameter('payout'))
219 // Generate banner order form
220 loadTemplate('member_payout_form_banner', false, $content);
225 'type' => $content['type'],
226 'payout' => bigintval(getRequestParameter('payout'))
229 // Generate normal form
230 loadTemplate('member_payout_form', false, $content);
233 // Not enougth points
234 displayMessage('{--MEMBER_PAYOUT_POINTS_NOT_ENOUGTH--}');
238 displayMessage('{--MEMBER_PAYOUT_ID_INVALID--}');
242 SQL_FREERESULT($result);