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 - 2013 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 = sqlQueryEscaped("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) = sqlFetchRow($result);
51 sqlFreeResult($result);
54 if (!isGetRequestElementSet('task') && (!empty($userid)) && (isValidId($userid))) {
55 // Get task id from database
56 $result = sqlQueryEscaped("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) = sqlFetchRow($result);
59 sqlFreeResult($result);
60 if (empty($taskId)) $taskId = '0';
61 } elseif (!isValidId($userid)) {
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)) && (isValidId($userid))) {
71 if (!fetchUserData($userid)) {
72 // Abort here because it is not valid!
73 reportBug(__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 = sqlQueryEscaped("SELECT `payout_id` FROM `{?_MYSQL_PREFIX?}_user_payouts` WHERE `id`=%s LIMIT 1",
81 array(bigintval(getRequestElement('pid'))), __FILE__, __LINE__);
84 list($ptype) = sqlFetchRow($result);
87 sqlFreeResult($result);
90 // Obtain data from payout type
91 $result = sqlQueryEscaped("SELECT
100 `{?_MYSQL_PREFIX?}_payout_types`
104 array(bigintval($ptype)), __FILE__, __LINE__);
107 $data = sqlFetchArray($result);
110 sqlFreeResult($result);
112 if (!empty($data['engine_url'])) {
114 switch ($data['pass_enc']) {
116 $data['from_pass'] = md5($data['from_pass']);
117 $tpass = md5($tpass);
121 $data['from_pass'] = base64_encode($data['from_pass']);
122 $tpass = base64_encode($tpass);
126 // Transfer variables...
127 $reason = encodeString(getMessage('ADMIN_PAYOUT_REASON'), FALSE);
130 $ret = sendHttpGetRequest($data['engine_url']);
133 $ret[0] = $data['engine_ret_ok'];
136 if ($ret[0] == $data['engine_ret_ok']) {
138 if (isValidId($taskId)) {
139 runFilterChain('solve_task', $taskId);
142 // Clear payout request
143 sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_payouts` SET `status`='ACCEPTED' WHERE `id`=%s LIMIT 1",
144 array(bigintval(getRequestElement('pid'))), __FILE__, __LINE__);
147 $message = loadEmailTemplate('member_payout_accepted', postRequestElement('text'), $userid);
150 if ($data['allow_url'] == 'Y') {
151 // Banner / Textlink request
152 displayMessage('{--ADMIN_PAYOUT_BANNER_ACCEPTED_NOTIFIED--}');
155 displayMessage('{--ADMIN_PAYOUT_ACCEPTED_NOTIFIED--}');
159 sendEmail(getUserData('userid'), '{--MEMBER_PAYOUT_ACCEPTED_SUBJECT--}', $message);
161 // Something goes wrong... :-(
162 $content = implode('<br />', $ret);
163 loadTemplate('admin_payout_failed_transfer', FALSE, $content);
166 // Cannot load payout id
167 displayErrorMessage('{--ADMIN_PAYOUT_FAILED_OBTAIN_PAYOUT_ID--}');
173 'pid' => bigintval(getRequestElement('pid')),
174 'user' => '<a href="' . generateEmailLink(getUserData('email'), 'user_data') . '">{%pipe,translateGender=' . getUserData('gender') . '%} ' . getUserData('surname') . ' ' . getUserData('family') . '</a>',
178 loadTemplate('admin_payout_accept_form', FALSE, $content);
180 } elseif ((getRequestElement('do') == 'reject') && (getUserData('email') != '')) {
181 // Ok, now we can output the form or execute rejecting
183 if (isValidId($taskId)) {
185 runFilterChain('solve_task', $taskId);
188 // Clear payout request
189 sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_payouts` SET `status`='REJECTED' WHERE `id`=%s LIMIT 1",
190 array(bigintval(getRequestElement('pid'))), __FILE__, __LINE__);
193 $message = loadEmailTemplate('member_payout_rejected', postRequestElement('text'), $userid);
196 displayMessage('{--ADMIN_PAYOUT_REJECTED_NOTIFIED--}');
199 sendEmail(getUserData('userid'), '{--MEMBER_PAYOUT_REJECTED_SUBJECT--}', $message);
204 'pid' => bigintval(getRequestElement('pid')),
205 'user' => '<a href="' . generateEmailLink(getUserData('email'), 'user_data') . '">{%pipe,translateGender=' . getUserData('gender') . '%} ' . getUserData('surname') . ' ' . getUserData('family') . '</a>',
209 loadTemplate('admin_payout_reject_form', FALSE, $content);
212 // Cannot load user data
213 displayMessage('{--ADMIN_PAYOUT_FAILED_OBTAIN_USERDATA--}');
215 } elseif (!isValidId($taskId)) {
216 // Failed loading task id
217 displayMessage('{--ADMIN_PAYOUT_FAILED_OBTAIN_TASK_ID--}');
220 if (getRequestElement('do') == 'delete') {
221 // Delete all requests
222 $result = sqlQuery("TRUNCATE `{?_MYSQL_PREFIX?}_user_payouts`", __FILE__, __LINE__);
225 // Search for payouts
226 $result = sqlQuery('SELECT
230 `p`.`target_account`,
233 `p`.`payout_timestamp`,
240 `{?_MYSQL_PREFIX?}_user_payouts` AS `p`
242 `{?_MYSQL_PREFIX?}_payout_types` AS `t`
244 `p`.`payout_id`=`t`.`id`
246 `p`.`payout_timestamp` DESC', __FILE__, __LINE__);
248 if (!ifSqlHasZeroNums($result)) {
249 // List found payouts
251 while ($content = sqlFetchArray($result)) {
252 if ($content['status'] == 'NEW') {
253 // Generate links for direct accepting and rejecting
254 $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>';
257 $content['status'] = translatePayoutStatus($content['status']);
260 // Nothing entered must be secured in member/what-payputs.php !
261 if ($content['allow_url'] == 'Y') {
262 // Banner/Textlink views/clicks request
263 if (!empty($content['banner_url'])) {
264 // Load template for the banner
265 $content['target_account'] = loadTemplate('admin_list_payouts_banner', TRUE, $content);
268 $content['target_account'] = loadTemplate('admin_list_payouts_txt', TRUE, $content);
271 // Admins can addionally test the URL for framekillers
272 $content['target_bank'] = '<a href="' . generateFrametesterUrl($content['target_url']) . '" target="_blank">{--CLICK_HERE--}</a>';
275 // Add/Translate some data
276 $content['payout_timestamp'] = generateDateTime($content['payout_timestamp'], 2);
278 // Add row and switch color
279 $OUT .= loadTemplate('admin_list_payouts_row', TRUE, $content);
283 sqlFreeResult($result);
285 // Load final template
286 loadTemplate('admin_list_payouts', FALSE, $OUT);
288 // No payout requests are sent so far
289 displayMessage('{--ADMIN_PAYOUT_NO_REQUESTS_FOUND--}');