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'));
58 $totalPoints = countSumTotalData(getMemberId(), 'user_points', 'points');
61 $usedPoints = countSumTotalData(getMemberId(), 'user_data', 'used_points');
63 // Translate point into comma
64 $totalPoints = ($totalPoints - $usedPoints);
67 if (empty($totalPoints)) $totalPoints = '0.00000';
69 if (!isGetRequestParameterSet('payout')) {
71 $result = SQL_QUERY_ESC("SELECT
72 `id`, `type`, `rate`, `min_points`, `allow_url`
74 `{?_MYSQL_PREFIX?}_payout_types`
79 array($totalPoints), __FILE__, __LINE__);
80 if (SQL_NUMROWS($result) > 0) {
82 SQL_FREERESULT($result);
84 // Check for his payouts
85 $result_payouts = SQL_QUERY_ESC("SELECT
86 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
88 `{?_MYSQL_PREFIX?}_user_payouts` AS p
90 `{?_MYSQL_PREFIX?}_payout_types` AS t
96 p.payout_timestamp DESC",
97 array(getMemberId()), __FILE__, __LINE__);
98 if (SQL_NUMROWS($result_payouts) > 0) {
99 // List all his requests
101 while ($content = SQL_FETCHARRAY($result_payouts)) {
103 $content['status'] = getMessage('PAYOUT_MEMBER_STATUS_'.strtoupper($content['status']).'');
104 $content['status'] = '<div class="member_failed">' . $content['status'] . '</div>';
106 // Nothing entered must be secured in member/what-payputs.php !
107 if ($content['allow'] == 'Y') {
108 // Banner/Textlink views/clicks request
109 if (!empty($content['banner'])) {
111 $content['target_account'] = "<img src=\"".$content['banner']."\" alt=\"".$content['alt']."\" title=\"".$content['alt']."\" border=\"0\" />";
114 $content['target_account'] = $content['alt'];
116 $content['target_bank'] = '<a href="' . generateDerefererUrl($content['url']) . '" target="_blank">{--CLICK_HERE--}</a>';
118 // e-currency payout request
119 if (empty($content['target_account'])) $content['target_account'] = '---';
120 if (empty($content['target_bank'])) $content['target_bank'] = '---';
123 // Prepare data for the template
126 'target_account' => $content['target_account'],
127 'points' => translateComma($content['payout_total']) . ' ' . $content['type'],
128 'target_bank' => $content['target_bank'],
129 'payout_timestamp' => generateDateTime($content['payout_timestamp'], 2),
130 'status' => $content['status']
133 // Load row template and switch colors
134 $OUT .= loadTemplate('member_payout_row', true, $content);
139 loadTemplate('member_payout', false, $OUT);
143 SQL_FREERESULT($result_payouts);
145 // Output payout list
146 outputPayoutList($totalPoints);
148 // No payout types setup
149 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_NO_PAYOUT_TYPES'));
152 // Chedk if he can get paid by selected type
153 $result = SQL_QUERY_ESC("SELECT type, rate, min_points, allow_url AS allow FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE `id`=%s LIMIT 1",
154 array(bigintval(getRequestParameter('payout'))), __FILE__, __LINE__);
156 if (SQL_NUMROWS($result) == 1) {
157 // id is valid so load the data
158 $content = SQL_FETCHARRAY($result);
160 // Calculate maximum value
161 $max = round($totalPoints * $content['rate'] - 0.5);
164 // Calulcate points from submitted amount
166 if (isPostRequestParameterSet('payout')) {
167 $points = bigintval(postRequestParameter('payout')) / $content['rate'];
168 $PAY_MAX = $max / $content['rate'];
171 // Has enougth points to payout?
172 if ($totalPoints >= $content['min_points']) {
173 // Ok, he can get be paid
174 if ((isFormSent()) && ($points <= $PAY_MAX) && ($points >= $content['min_points'])) {
175 // Remember points in array
176 setPostRequestParameter('payout_points', translateComma($points));
177 setPostRequestParameter('type' , $content['type']);
179 // Subtract points from member's account
180 subtractPoints('payout', getMemberId(), $points);
182 // Add entry to his tranfer history
183 if ($content['allow'] == 'Y') {
184 // Banner/textlink ordered
185 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_payouts` (`userid`, `payout_total`, `payout_id`, `payout_timestamp`, `status`, `target_url`, `link_text`, `banner_url`)
186 VALUES (%s,%s,%s, UNIX_TIMESTAMP(), 'NEW','%s','%s','%s')",
189 bigintval(postRequestParameter('payout')),
190 bigintval(getRequestParameter('payout')),
191 postRequestParameter('turl'),
192 postRequestParameter('alt'),
193 postRequestParameter('banner')
194 ), __FILE__, __LINE__);
197 $message_mem = loadEmailTemplate('member_payout_request_banner', postRequestArray(), getMemberId());
198 if (isExtensionInstalledAndNewer('admins', '0.4.1')) {
199 $adm_tpl = 'admin_payout_request_banner';
201 $message_adm = loadEmailTemplate('admin_payout_request_banner', postRequestArray(), getMemberId());
204 // e-currency payout requested
205 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_payouts` (`userid`, `payout_total`, `target_account`, `target_bank`, `payout_id`, `payout_timestamp`, `status`, `password`)
206 VALUES (%s,%s,%s,'%s',%s, UNIX_TIMESTAMP(), 'NEW','%s')",
209 bigintval(postRequestParameter('payout')),
210 bigintval(postRequestParameter('account')),
211 postRequestParameter('bank'),
212 bigintval(getRequestParameter('payout')),
213 postRequestParameter('pass')
214 ), __FILE__, __LINE__);
217 $message_mem = loadEmailTemplate('member_payout_request', postRequestArray(), getMemberId());
218 $message_adm = loadEmailTemplate('admin_payout_request', postRequestArray(), getMemberId());
221 // @TODO Rewrite this to a filter
222 if (isExtensionInstalledAndNewer('admins', '0.4.1')) {
223 $admin_tpl = 'admin_payout_request';
228 createNewTask('[payout:] {--PAYOUT_REQUEST_ADMIN--}', $message_adm, 'PAYOUT_REQUEST', getMemberId());
231 sendEmail(getMemberId(), getMessage('PAYOUT_REQUEST_MEMBER'), $message_mem);
234 sendAdminNotification(getMessage('PAYOUT_REQUEST_ADMIN'), $admin_tpl, postRequestArray(), getMemberId());
236 // Load template and output it
237 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_REQUEST_SENT'));
238 } elseif ($content['allow'] == 'Y') {
242 'type' => $content['type'],
243 'payout' => bigintval(getRequestParameter('payout'))
246 // Generate banner order form
247 loadTemplate('member_payout_form_banner', false, $content);
252 'type' => $content['type'],
253 'payout' => bigintval(getRequestParameter('payout'))
256 // Generate normal form
257 loadTemplate('member_payout_form', false, $content);
260 // Not enougth points
261 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_POINTS_NOT_ENOUGTH'));
265 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_ID_INVALID'));
269 SQL_FREERESULT($result);