2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 05/08/2004 *
4 * =================== Last change: 08/12/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-list_payouts.php *
8 * -------------------------------------------------------------------- *
9 * Short description : List member's payout requests *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Auflistung der 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://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')) || (!isAdmin())) {
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
46 if (isGetRequestElementSet('pid')) {
47 // First let's get the member's id
48 $result = SQL_QUERY_ESC("SELECT `userid`,`target_account`,`payout_total`,`payout_timestamp`,`password` FROM `{?_MYSQL_PREFIX?}_user_payouts` WHERE `id`=%s LIMIT 1",
49 array(getRequestElement('pid')), __FILE__, __LINE__);
50 list($userid, $tuserid, $points, $tstamp, $tpass) = SQL_FETCHROW($result);
51 SQL_FREERESULT($result);
54 if (!isGetRequestElementSet('task') && (!empty($userid)) && (isValidUserId($userid))) {
55 // Get task id from database
56 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `userid`=%s AND `task_type`='PAYOUT_REQUEST' AND `task_created`=%s LIMIT 1",
57 array(bigintval($userid), bigintval($tstamp)), __FILE__, __LINE__);
58 list($taskId) = SQL_FETCHROW($result);
59 SQL_FREERESULT($result);
60 if (empty($taskId)) $taskId = '0';
61 } elseif ((empty($userid)) || ($userid == '0')) {
62 // Cannot obtain member id!
63 displayMessage('{--ADMIN_PAYOUT_FAILED_OBTAIN_USERID--}');
65 // Get task id from URL
66 $taskId = getRequestElement('task');
69 if ((!empty($taskId)) && (!empty($userid)) && (isValidUserId($userid))) {
71 if (!fetchUserData($userid)) {
72 // Abort here because it is not valid!
73 debug_report_bug(__FILE__, __LINE__, 'No user account ' . $userid . ' found.');
76 if ((getRequestElement('do') == 'accept') && (getUserData('email') != '')) {
77 // Ok, now we can output the form or execute accepting
79 // Obtain payout type and other data
80 $result = SQL_QUERY_ESC("SELECT `payout_id` FROM `{?_MYSQL_PREFIX?}_user_payouts` WHERE `id`=%s LIMIT 1",
81 array(bigintval(getRequestElement('pid'))), __FILE__, __LINE__);
84 list($ptype) = SQL_FETCHROW($result);
87 SQL_FREERESULT($result);
90 // Obtain data from payout type
91 $result = SQL_QUERY_ESC("SELECT
92 `from_account`,`from_pass`,`engine_url`,`engine_ret_ok`,`engine_ret_failed`,`pass_enc`,`allow_url`
94 `{?_MYSQL_PREFIX?}_payout_types`
98 array(bigintval($ptype)), __FILE__, __LINE__);
101 $data = SQL_FETCHARRAY($result);
104 SQL_FREERESULT($result);
106 if (!empty($data['engine_url'])) {
108 switch ($data['pass_enc']) {
110 $data['from_pass'] = md5($data['from_pass']);
111 $tpass = md5($tpass);
115 $data['from_pass'] = base64_encode($data['from_pass']);
116 $tpass = base64_encode($tpass);
120 // Transfer variables...
121 $reason = encodeString(getMessage('ADMIN_PAYOUT_REASON'), false);
124 $ret = sendGetRequest($data['engine_url']);
127 $ret[0] = $data['engine_ret_ok'];
130 if ($ret[0] == $data['engine_ret_ok']) {
133 runFilterChain('solve_task', $taskId);
136 // Clear payout request
137 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_payouts` SET `status`='ACCEPTED' WHERE `id`=%s LIMIT 1",
138 array(bigintval(getRequestElement('pid'))), __FILE__, __LINE__);
141 $message = loadEmailTemplate('member_payout_accepted', postRequestElement('text'), $userid);
144 if ($data['allow_url'] == 'Y') {
145 // Banner / Textlink request
146 displayMessage('{--ADMIN_PAYOUT_BANNER_ACCEPTED_NOTIFIED--}');
149 displayMessage('{--ADMIN_PAYOUT_ACCEPTED_NOTIFIED--}');
153 sendEmail(getUserData('userid'), '{--MEMBER_PAYOUT_ACCEPTED_SUBJECT--}', $message);
155 // Something goes wrong... :-(
156 $content = implode('<br />', $ret);
157 loadTemplate('admin_payout_failed_transfer', false, $content);
160 // Cannot load payout id
161 loadTemplate('admin_settings_unsaved', false, '{--ADMIN_PAYOUT_FAILED_OBTAIN_PAYOUT_ID--}');
167 'pid' => bigintval(getRequestElement('pid')),
168 'user' => '<a href="' . generateEmailLink(getUserData('email'), 'user_data') . '">{%pipe,translateGender=' . getUserData('gender') . '%} ' . getUserData('surname') . ' ' . getUserData('family') . '</a>',
172 loadTemplate('admin_payout_accept_form', false, $content);
174 } elseif ((getRequestElement('do') == 'reject') && (getUserData('email') != '')) {
175 // Ok, now we can output the form or execute rejecting
179 runFilterChain('solve_task', $taskId);
182 // Clear payout request
183 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_payouts` SET `status`='REJECTED' WHERE `id`=%s LIMIT 1",
184 array(bigintval(getRequestElement('pid'))), __FILE__, __LINE__);
187 $message = loadEmailTemplate('member_payout_rejected', postRequestElement('text'), $userid);
190 displayMessage('{--ADMIN_PAYOUT_REJECTED_NOTIFIED--}');
193 sendEmail(getUserData('userid'), '{--MEMBER_PAYOUT_REJECTED_SUBJECT--}', $message);
198 'pid' => bigintval(getRequestElement('pid')),
199 'user' => '<a href="' . generateEmailLink(getUserData('email'), 'user_data') . '">{%pipe,translateGender=' . getUserData('gender') . '%} ' . getUserData('surname') . ' ' . getUserData('family') . '</a>',
203 loadTemplate('admin_payout_reject_form', false, $content);
206 // Cannot load user data
207 displayMessage('{--ADMIN_PAYOUT_FAILED_OBTAIN_USERDATA--}');
209 } elseif ((empty($taskId)) || ($taskId == '0')) {
210 // Failed loading task id
211 displayMessage('{--ADMIN_PAYOUT_FAILED_OBTAIN_TASK_ID--}');
214 if (getRequestElement('do') == 'delete') {
215 // Delete all requests
216 $result = SQL_QUERY("TRUNCATE `{?_MYSQL_PREFIX?}_user_payouts`", __FILE__, __LINE__);
219 // Search for payouts
220 $result = SQL_QUERY("SELECT
221 p.id, p.userid, p.payout_total, p.target_account,
222 p.target_bank, t.type, p.payout_timestamp, p.status,
223 t.allow_url AS allow, p.target_url AS url, p.link_text AS alt,
224 p.banner_url AS banner
226 `{?_MYSQL_PREFIX?}_user_payouts` AS p
228 `{?_MYSQL_PREFIX?}_payout_types` AS t
232 p.payout_timestamp DESC", __FILE__, __LINE__);
234 if (!SQL_HASZERONUMS($result)) {
235 // List found payouts
237 while ($content = SQL_FETCHARRAY($result)) {
238 if ($content['status'] == 'NEW') {
239 // Generate links for direct accepting and rejecting
240 $content['status'] = '<a href="{%url=modules.php?module=admin&what=list_payouts&do=accept&pid=' . $content['id'] . '%}">{--ADMIN_PAYOUT_ACCEPT_PAYOUT--}</a>|<a href="{%url=modules.php?module=admin&what=list_payouts&do=reject&pid=' . $content['id'] . '%}">{--ADMIN_PAYOUT_REJECT_PAYOUT--}</a>';
243 $content['status'] = translatePayoutStatus($content['status']);
246 // Nothing entered must be secured in member/what-payputs.php !
247 if ($content['allow'] == 'Y') {
248 // Banner/Textlink views/clicks request
249 if (!empty($content['banner'])) {
250 // Load template for the banner
251 $content['target_account'] = loadTemplate('admin_list_payouts_banner', true, $content);
254 $content['target_account'] = loadTemplate('admin_list_payouts_txt', true, $content);
257 // Admins can addionally test the URL for framekillers
258 $content['target_bank'] = '<a href="' . generateFrametesterUrl($content['url']) . '" target="_blank">{--CLICK_HERE--}</a>';
261 // Add/Translate some data
262 $content['payout_timestamp'] = generateDateTime($content['payout_timestamp'], 2);
264 // Add row and switch color
265 $OUT .= loadTemplate('admin_list_payouts_row', true, $content);
269 SQL_FREERESULT($result);
271 // Load final template
272 loadTemplate('admin_list_payouts', false, $OUT);
274 // No payout requests are sent so far
275 displayMessage('{--ADMIN_PAYOUT_NO_REQUESTS_FOUND--}');