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 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41 // Don't call this directly!
43 } elseif (!isMember()) {
45 redirectToIndexMemberOnlyModule();
48 // Add description as navigation point
49 addMenuDescription('member', __FILE__);
51 if ((!isExtensionActive('payout')) && (!isAdmin())) {
52 loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('payout'));
56 $result_depths = SQL_QUERY("SELECT `level`, `percents` FROM `{?_MYSQL_PREFIX?}_refdepths` ORDER BY level", __FILE__, __LINE__);
58 while ($content = SQL_FETCHARRAY($result_depths)) {
59 // Load referal points
60 $result_points = SQL_QUERY_ESC("SELECT `points` FROM `{?_MYSQL_PREFIX?}_user_points` WHERE `userid`=%s AND `ref_depth`='%s' LIMIT 1",
61 array(getMemberId(), bigintval($content['level'])), __FILE__, __LINE__);
64 if (SQL_NUMROWS($result_points) == 1) {
66 list($points) = SQL_FETCHROW($result_points);
69 $totalPoints += $points;
73 SQL_FREERESULT($result_points);
77 SQL_FREERESULT($result_depths);
80 $usedPoints = countSumTotalData(getMemberId(), 'user_data', 'used_points');
82 // Translate point into comma
83 $totalPoints = ($totalPoints - $usedPoints);
86 if (empty($totalPoints)) $totalPoints = '0.00000';
88 if (!isGetRequestElementSet('payout')) {
90 $result = SQL_QUERY_ESC("SELECT
91 `id`, `type`, `rate`, `min_points`, `allow_url`
93 `{?_MYSQL_PREFIX?}_payout_types`
98 array($totalPoints), __FILE__, __LINE__);
99 if (SQL_NUMROWS($result) > 0) {
101 SQL_FREERESULT($result);
103 // Check for his payouts
104 $result_payouts = SQL_QUERY_ESC("SELECT
105 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
107 `{?_MYSQL_PREFIX?}_user_payouts` AS p
109 `{?_MYSQL_PREFIX?}_payout_types` AS t
115 p.payout_timestamp DESC",
116 array(getMemberId()), __FILE__, __LINE__);
117 if (SQL_NUMROWS($result_payouts) > 0) {
118 // List all his requests
120 while ($content = SQL_FETCHARRAY($result_payouts)) {
122 $content['status'] = getMessage('PAYOUT_MEMBER_STATUS_'.strtoupper($content['status']).'');
123 $content['status'] = "<div class=\"member_failed\">".$content['status']."</div>";
125 // Nothing entered must be secured in member/what-payputs.php !
126 if ($content['allow'] == 'Y') {
127 // Banner/Textlink views/clicks request
128 if (!empty($content['banner'])) {
130 $content['target_account'] = "<img src=\"".$content['banner']."\" alt=\"".$content['alt']."\" title=\"".$content['alt']."\" border=\"0\" />";
133 $content['target_account'] = $content['alt'];
135 $content['target_bank'] = "<a href=\"".generateDerefererUrl($content['url'])."\" target=\"_blank\">{--CLICK_HERE--}</a>";
137 // e-currency payout request
138 if (empty($content['target_account'])) $content['target_account'] = '---';
139 if (empty($content['target_bank'])) $content['target_bank'] = '---';
142 // Prepare data for the template
145 'target_account' => $content['target_account'],
146 'points' => translateComma($content['payout_total']) . ' ' . $content['type'],
147 'target_bank' => $content['target_bank'],
148 'payout_timestamp' => generateDateTime($content['payout_timestamp'], 2),
149 'status' => $content['status']
152 // Load row template and switch colors
153 $OUT .= loadTemplate('member_payout_row', true, $content);
158 loadTemplate('member_payout', false, $OUT);
162 SQL_FREERESULT($result_payouts);
164 // Output payout list
165 outputPayoutList($totalPoints);
167 // No payout types setup
168 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_NO_PAYOUT_TYPES'));
171 // Chedk if he can get paid by selected type
172 $result = SQL_QUERY_ESC("SELECT type, rate, min_points, allow_url AS allow FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE `id`=%s LIMIT 1",
173 array(bigintval(getRequestElement('payout'))), __FILE__, __LINE__);
175 if (SQL_NUMROWS($result) == 1) {
176 // id is valid so load the data
177 $content = SQL_FETCHARRAY($result);
179 // Calculate maximum value
180 $max = round($totalPoints * $content['rate'] - 0.5);
183 // Calulcate points from submitted amount
185 if (isPostRequestElementSet('payout')) {
186 $points = bigintval(postRequestElement('payout')) / $content['rate'];
187 $PAY_MAX = $max / $content['rate'];
190 // Has enougth points to payout?
191 if ($totalPoints >= $content['min_points']) {
192 // Ok, he can get be paid
193 if ((isFormSent()) && ($points <= $PAY_MAX) && ($points >= $content['min_points'])) {
194 // Remember points in array
195 setRequestPostElement('payout_points', translateComma($points));
196 setRequestPostElement('type' , $content['type']);
198 // Subtract points from member's account
199 subtractPoints('payout', getMemberId(), $points);
201 // Add entry to his tranfer history
202 if ($content['allow'] == 'Y') {
203 // Banner/textlink ordered
204 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_payouts` (`userid`, `payout_total`, `payout_id`, `payout_timestamp`, `status`, `target_url`, `link_text`, `banner_url`)
205 VALUES (%s,%s,%s, UNIX_TIMESTAMP(), 'NEW','%s','%s','%s')",
208 bigintval(postRequestElement('payout')),
209 bigintval(getRequestElement('payout')),
210 postRequestElement('turl'),
211 postRequestElement('alt'),
212 postRequestElement('banner')
213 ), __FILE__, __LINE__);
216 $message_mem = loadEmailTemplate('member_payout_request_banner', postRequestArray(), getMemberId());
217 if (getExtensionVersion('admins') >= '0.4.1') {
218 $adm_tpl = 'admin_payout_request_banner';
220 $message_adm = loadEmailTemplate('admin_payout_request_banner', postRequestArray(), getMemberId());
223 // e-currency payout requested
224 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_payouts` (`userid`, `payout_total`, `target_account`, `target_bank`, `payout_id`, `payout_timestamp`, `status`, `password`)
225 VALUES (%s,%s,%s,'%s',%s, UNIX_TIMESTAMP(), 'NEW','%s')",
228 bigintval(postRequestElement('payout')),
229 bigintval(postRequestElement('account')),
230 postRequestElement('bank'),
231 bigintval(getRequestElement('payout')),
232 postRequestElement('pass')
233 ), __FILE__, __LINE__);
236 $message_mem = loadEmailTemplate('member_payout_request', postRequestArray(), getMemberId());
237 $message_adm = loadEmailTemplate('admin_payout_request', postRequestArray(), getMemberId());
240 // @TODO Rewrite this to a filter
241 if (getExtensionVersion('admins') >= '0.4.1') {
242 $admin_tpl = 'admin_payout_request';
247 createNewTask('[payout:] {--PAYOUT_REQUEST_ADMIN--}', $message_adm, 'PAYOUT_REQUEST', getMemberId());
250 sendEmail(getMemberId(), getMessage('PAYOUT_REQUEST_MEMBER'), $message_mem);
253 sendAdminNotification(getMessage('PAYOUT_REQUEST_ADMIN'), $admin_tpl, postRequestArray(), getMemberId());
255 // Load template and output it
256 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_REQUEST_SENT'));
257 } elseif ($content['allow'] == 'Y') {
261 'type' => $content['type'],
262 'payout' => bigintval(getRequestElement('payout'))
265 // Generate banner order form
266 loadTemplate('member_payout_form_banner', false, $content);
271 'type' => $content['type'],
272 'payout' => bigintval(getRequestElement('payout'))
275 // Generate normal form
276 loadTemplate('member_payout_form', false, $content);
279 // Not enougth points
280 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_POINTS_NOT_ENOUGTH'));
284 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_ID_INVALID'));
288 SQL_FREERESULT($result);