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 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42 // Don't call this directly!
44 } elseif (!isMember()) {
46 redirectToIndexMemberOnlyModule();
49 // Add description as navigation point
50 addMenuDescription('member', __FILE__);
52 if ((!isExtensionActive('payout')) && (!isAdmin())) {
53 loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('payout'));
57 // Translate point into comma
58 $totalPoints = getTotalPoints(getMemberId());
60 if (!isGetRequestParameterSet('payout')) {
62 $result = SQL_QUERY_ESC("SELECT
63 `id`, `type`, `rate`, `min_points`, `allow_url`
65 `{?_MYSQL_PREFIX?}_payout_types`
70 array($totalPoints), __FILE__, __LINE__);
71 if (!SQL_HASZERONUMS($result)) {
73 SQL_FREERESULT($result);
75 // Check for his payouts
76 $result_payouts = SQL_QUERY_ESC("SELECT
77 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
79 `{?_MYSQL_PREFIX?}_user_payouts` AS p
81 `{?_MYSQL_PREFIX?}_payout_types` AS t
87 p.payout_timestamp DESC",
88 array(getMemberId()), __FILE__, __LINE__);
89 if (!SQL_HASZERONUMS($result_payouts)) {
90 // List all his requests
92 while ($content = SQL_FETCHARRAY($result_payouts)) {
94 $content['status'] = translatePayoutStatus();
95 $content['status'] = '<div class="member_failed">' . $content['status'] . '</div>';
97 // Nothing entered must be secured in member/what-payputs.php !
98 if ($content['allow'] == 'Y') {
99 // Banner/Textlink views/clicks request
100 if (!empty($content['banner'])) {
102 $content['target_account'] = '<img src="' . $content['banner'] . '" alt="' . $content['alt'] . '" title="' . $content['alt'] . '" border="0" />';
105 $content['target_account'] = $content['alt'];
107 $content['target_bank'] = '<a href="' . generateDerefererUrl($content['url']) . '" target="_blank">{--CLICK_HERE--}</a>';
110 // Prepare data for the template
112 'target_account' => $content['target_account'],
113 'payout_total' => $content['payout_total'],
114 'target_bank' => $content['target_bank'],
115 'payout_timestamp' => generateDateTime($content['payout_timestamp'], 2),
116 'status' => $content['status'],
117 'type' => $content['type'],
120 // Load row template and switch colors
121 $OUT .= loadTemplate('member_payout_row', true, $content);
125 loadTemplate('member_payout', false, $OUT);
129 SQL_FREERESULT($result_payouts);
131 // Output payout list
132 outputPayoutList($totalPoints);
134 // No payout types setup
135 loadTemplate('admin_settings_saved', false, '{--MEMBER_PAYOUT_SETUP_INCOMPLETE--}');
138 // Chedk if he can get paid by selected type
139 $result = SQL_QUERY_ESC("SELECT `type`, `rate`, `min_points`, `allow_url` AS allow FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE `id`=%s LIMIT 1",
140 array(bigintval(getRequestParameter('payout'))), __FILE__, __LINE__);
142 if (SQL_NUMROWS($result) == 1) {
143 // id is valid so load the data
144 $content = SQL_FETCHARRAY($result);
146 // Calculate maximum value
147 $max = round($totalPoints * $content['rate'] - 0.5);
150 // Calulcate points from submitted amount
152 if (isPostRequestParameterSet('payout')) {
153 $points = bigintval(postRequestParameter('payout')) / $content['rate'];
154 $PAY_MAX = $max / $content['rate'];
157 // Has enougth points to payout?
158 if ($totalPoints >= $content['min_points']) {
159 // Ok, he can get be paid
160 if ((isFormSent()) && ($points <= $PAY_MAX) && ($points >= $content['min_points'])) {
161 // Remember points in array
162 setPostRequestParameter('payout_points', translateComma($points));
163 setPostRequestParameter('type' , $content['type']);
165 // Subtract points from member's account
166 subtractPoints('payout', getMemberId(), $points);
168 // Add entry to his tranfer history
169 if ($content['allow'] == 'Y') {
170 // Banner/textlink ordered
171 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_payouts` (`userid`, `payout_total`, `payout_id`, `payout_timestamp`, `status`, `target_url`, `link_text`, `banner_url`)
172 VALUES (%s,%s,%s, UNIX_TIMESTAMP(), 'NEW','%s','%s','%s')",
175 bigintval(postRequestParameter('payout')),
176 bigintval(getRequestParameter('payout')),
177 postRequestParameter('turl'),
178 postRequestParameter('alt'),
179 postRequestParameter('banner')
180 ), __FILE__, __LINE__);
183 $message_mem = loadEmailTemplate('member_payout_request_banner', postRequestArray(), getMemberId());
184 if (isExtensionInstalledAndNewer('admins', '0.4.1')) {
185 $adm_tpl = 'admin_payout_request_banner';
187 $message_adm = loadEmailTemplate('admin_payout_request_banner', postRequestArray(), getMemberId());
190 // e-currency payout requested
191 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_payouts` (`userid`, `payout_total`, `target_account`, `target_bank`, `payout_id`, `payout_timestamp`, `status`, `password`)
192 VALUES (%s,%s,%s,'%s',%s, UNIX_TIMESTAMP(), 'NEW','%s')",
195 bigintval(postRequestParameter('payout')),
196 bigintval(postRequestParameter('account')),
197 postRequestParameter('bank'),
198 bigintval(getRequestParameter('payout')),
199 postRequestParameter('pass')
200 ), __FILE__, __LINE__);
203 $message_mem = loadEmailTemplate('member_payout_request', postRequestArray(), getMemberId());
204 $message_adm = loadEmailTemplate('admin_payout_request', postRequestArray(), getMemberId());
207 // @TODO Rewrite this to a filter
208 if (isExtensionInstalledAndNewer('admins', '0.4.1')) {
209 $admin_tpl = 'admin_payout_request';
213 // Generate task (we ignore the task id here)
214 createNewTask('[payout:] {--ADMIN_PAYOUY_REQUEST_SUBJECT--}', $message_adm, 'PAYOUT_REQUEST', getMemberId());
217 sendEmail(getMemberId(), '{--MEMBER_PAYOUT_REQUEST_SUBJECT--}', $message_mem);
220 sendAdminNotification('{--ADMIN_PAYOUY_REQUEST_SUBJECT--}', $admin_tpl, postRequestArray(), getMemberId());
222 // Load template and output it
223 loadTemplate('admin_settings_saved', false, '{--MEMBER_PAYOUT_REQUEST_SENT--}');
224 } elseif ($content['allow'] == 'Y') {
228 'type' => $content['type'],
229 'payout' => bigintval(getRequestParameter('payout'))
232 // Generate banner order form
233 loadTemplate('member_payout_form_banner', false, $content);
238 'type' => $content['type'],
239 'payout' => bigintval(getRequestParameter('payout'))
242 // Generate normal form
243 loadTemplate('member_payout_form', false, $content);
246 // Not enougth points
247 loadTemplate('admin_settings_saved', false, '{--MEMBER_PAYOUT_POINTS_NOT_ENOUGTH--}');
251 loadTemplate('admin_settings_saved', false, '{--MEMBER_PAYOUT_ID_INVALID--}');
255 SQL_FREERESULT($result);