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, 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)) {
93 // Nothing entered must be secured in member/what-payputs.php !
94 if ($content['allow'] == 'Y') {
95 // Banner/Textlink views/clicks request
96 if (!empty($content['banner'])) {
98 $content['target_account'] = '<img src="' . $content['banner'] . '" alt="' . $content['link_text'] . '" title="' . $content['link_text'] . '" border="0" />';
101 $content['target_account'] = $content['link_text'];
103 $content['target_bank'] = '<a href="' . generateDerefererUrl($content['url']) . '" target="_blank">{--CLICK_HERE--}</a>';
106 // Prepare data for the template
107 $content['payout_timestamp'] = generateDateTime($content['payout_timestamp'], 2);
109 // Load row template and switch colors
110 $OUT .= loadTemplate('member_payout_row', true, $content);
114 loadTemplate('member_payout', false, $OUT);
118 SQL_FREERESULT($result_payouts);
120 // Output payout list
121 outputPayoutList($totalPoints);
123 // No payout types setup
124 loadTemplate('admin_settings_saved', false, '{--MEMBER_PAYOUT_SETUP_INCOMPLETE--}');
127 // Chedk if he can get paid by selected type
128 $result = SQL_QUERY_ESC("SELECT `type`, `rate`, `min_points`, `allow_url` AS allow FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE `id`=%s LIMIT 1",
129 array(bigintval(getRequestParameter('payout'))), __FILE__, __LINE__);
131 if (SQL_NUMROWS($result) == 1) {
132 // id is valid so load the data
133 $content = SQL_FETCHARRAY($result);
135 // Calculate maximum value
136 $max = round($totalPoints * $content['rate'] - 0.5);
139 // Calulcate points from submitted amount
141 if (isPostRequestParameterSet('payout')) {
142 $points = bigintval(postRequestParameter('payout')) / $content['rate'];
143 $PAY_MAX = $max / $content['rate'];
146 // Has enougth points to payout?
147 if ($totalPoints >= $content['min_points']) {
148 // Ok, he can get be paid
149 if ((isFormSent()) && ($points <= $PAY_MAX) && ($points >= $content['min_points'])) {
150 // Remember points in array
151 setPostRequestParameter('payout_points', translateComma($points));
152 setPostRequestParameter('type' , $content['type']);
154 // Subtract points from member's account
155 subtractPoints('payout', getMemberId(), $points);
157 // Add entry to his tranfer history
158 if ($content['allow'] == 'Y') {
159 // Banner/textlink ordered
160 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_payouts` (`userid`, `payout_total`, `payout_id`, `payout_timestamp`, `status`, `target_url`, `link_text`, `banner_url`)
161 VALUES (%s,%s,%s, UNIX_TIMESTAMP(), 'NEW','%s','%s','%s')",
164 bigintval(postRequestParameter('payout')),
165 bigintval(getRequestParameter('payout')),
166 postRequestParameter('turl'),
167 postRequestParameter('link_text'),
168 postRequestParameter('banner')
169 ), __FILE__, __LINE__);
172 $message_mem = loadEmailTemplate('member_payout_request_banner', postRequestArray(), getMemberId());
173 if (isExtensionInstalledAndNewer('admins', '0.4.1')) {
174 $adm_tpl = 'admin_payout_request_banner';
176 $message_adm = loadEmailTemplate('admin_payout_request_banner', postRequestArray(), getMemberId());
179 // e-currency payout requested
180 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_payouts` (`userid`, `payout_total`, `target_account`, `target_bank`, `payout_id`, `payout_timestamp`, `status`, `password`)
181 VALUES (%s,%s,%s,'%s',%s, UNIX_TIMESTAMP(), 'NEW','%s')",
184 bigintval(postRequestParameter('payout')),
185 bigintval(postRequestParameter('account')),
186 postRequestParameter('bank'),
187 bigintval(getRequestParameter('payout')),
188 postRequestParameter('password')
189 ), __FILE__, __LINE__);
192 $message_mem = loadEmailTemplate('member_payout_request', postRequestArray(), getMemberId());
193 $message_adm = loadEmailTemplate('admin_payout_request', postRequestArray(), getMemberId());
196 // @TODO Rewrite this to a filter
197 if (isExtensionInstalledAndNewer('admins', '0.4.1')) {
198 $admin_tpl = 'admin_payout_request';
202 // Generate task (we ignore the task id here)
203 createNewTask('[payout:] {--ADMIN_PAYOUY_REQUEST_SUBJECT--}', $message_adm, 'PAYOUT_REQUEST', getMemberId());
206 sendEmail(getMemberId(), '{--MEMBER_PAYOUT_REQUEST_SUBJECT--}', $message_mem);
209 sendAdminNotification('{--ADMIN_PAYOUY_REQUEST_SUBJECT--}', $admin_tpl, postRequestArray(), getMemberId());
211 // Load template and output it
212 loadTemplate('admin_settings_saved', false, '{--MEMBER_PAYOUT_REQUEST_SENT--}');
213 } elseif ($content['allow'] == 'Y') {
217 'type' => $content['type'],
218 'payout' => bigintval(getRequestParameter('payout'))
221 // Generate banner order form
222 loadTemplate('member_payout_form_banner', false, $content);
227 'type' => $content['type'],
228 'payout' => bigintval(getRequestParameter('payout'))
231 // Generate normal form
232 loadTemplate('member_payout_form', false, $content);
235 // Not enougth points
236 loadTemplate('admin_settings_saved', false, '{--MEMBER_PAYOUT_POINTS_NOT_ENOUGTH--}');
240 loadTemplate('admin_settings_saved', false, '{--MEMBER_PAYOUT_ID_INVALID--}');
244 SQL_FREERESULT($result);