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 * 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')) || (!isAdmin())) {
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
48 if (isGetRequestParameterSet(('pid'))) {
49 // First let's get the member's id
50 $result = SQL_QUERY_ESC("SELECT userid, target_account, payout_total, payout_timestamp, password FROM `{?_MYSQL_PREFIX?}_user_payouts` WHERE `id`=%s LIMIT 1",
51 array(getRequestParameter('pid')), __FILE__, __LINE__);
52 list($userid, $tuserid, $points, $tstamp, $tpass) = SQL_FETCHROW($result);
53 SQL_FREERESULT($result);
56 if (!isGetRequestParameterSet(('task')) && (!empty($userid)) && ($userid > 0)) {
57 // Get task id from database
58 $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",
59 array(bigintval($userid), bigintval($tstamp)), __FILE__, __LINE__);
60 list($task) = SQL_FETCHROW($result);
61 SQL_FREERESULT($result);
62 if (empty($task)) $task = '0';
63 } elseif ((empty($userid)) || ($userid == '0')) {
64 // Cannot obtain member id!
65 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_FAILED_OBTAIN_USERID'));
67 // Get task id from URL
68 $task = getRequestParameter('task');
71 if ((!empty($task)) && (!empty($userid)) && ($userid > 0)) {
73 if (!fetchUserData($userid)) {
74 // Abort here because it is not valid!
75 debug_report_bug('No user account ' . $userid . ' found.');
78 if ((getRequestParameter('do') == 'accept') && (!empty(getUserData('email')))) {
79 // Ok, now we can output the form or execute accepting
81 // Obtain payout type and other data
82 $result = SQL_QUERY_ESC("SELECT `payout_id` FROM `{?_MYSQL_PREFIX?}_user_payouts` WHERE `id`=%s LIMIT 1",
83 array(bigintval(getRequestParameter('pid'))), __FILE__, __LINE__);
84 list($ptype) = SQL_FETCHROW($result);
85 SQL_FREERESULT($result);
88 // Obtain data from payout type
89 $result = SQL_QUERY_ESC("SELECT `from_account`, `from_pass`, `engine_url`, `engine_ret_ok`, `engine_ret_failed`, `pass_enc`, `allow_url`
91 `{?_MYSQL_PREFIX?}_payout_types`
95 array(bigintval($ptype)), __FILE__, __LINE__);
96 list($fuserid, $fpass, $eurl, $eok, $failed, $eenc, $allow) = SQL_FETCHROW($result);
97 SQL_FREERESULT($result);
103 $fpass = md5($fpass);
104 $tpass = md5($tpass);
108 $fpass = base64_encode($fpass);
109 $tpass = base64_encode($tpass);
113 // Transfer variables...
114 $eval = '$url = "' . $eurl . '";';
115 $reason = encodeString(getMessage('PAYOUT_REASON_PAYOUT'), false);
118 // @TODO Do we need this time-consuming eval() here?
122 $ret = sendGetRequest($url);
128 if ($ret[0] == $eok) {
131 runFilterChain('solve_task', $task);
134 // Clear payout request
135 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_payouts` SET `status`='ACCEPTED' WHERE `id`=%s LIMIT 1",
136 array(bigintval(getRequestParameter('pid'))), __FILE__, __LINE__);
139 $message = loadEmailTemplate('member_payout_accepted', postRequestParameter('text'), $userid);
143 // Banner / Textlink request
144 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_BANNER_ACCEPTED_NOTIFIED'));
147 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_ACCEPTED_NOTIFIED'));
151 sendEmail(getUserData('email'), getMessage('PAYOUT_ACCEPTED_SUBJECT'), $message);
153 // Something goes wrong... :-(
154 $content = implode("<br />", $ret);
155 loadTemplate('admin_payout_failed_transfer', false, $content);
158 // Cannot load payout id
159 loadTemplate('admin_settings_saved', false, '<div class="admin_failed">{--PAYOUT_FAILED_OBTAIN_PAYOUT_ID--}</div>');
165 'pid' => bigintval(getRequestParameter('pid')),
166 'user' => '<a href="' . generateEmailLink(getUserData('email'), 'user_data') . '">' . translateGender(getUserData('gender')) . ' ' . getUserData('surname') . ' ' . getUserData('family') . '</a>',
170 loadTemplate('admin_payout_accept_form', false, $content);
172 } elseif ((getRequestParameter('do') == 'reject') && (!empty(getUserData('email')))) {
173 // Ok, now we can output the form or execute rejecting
177 runFilterChain('solve_task', $task);
180 // Clear payout request
181 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_payouts` SET `status`='REJECTED' WHERE `id`=%s LIMIT 1",
182 array(bigintval(getRequestParameter('pid'))), __FILE__, __LINE__);
185 $message = loadEmailTemplate('member_payout_rejected', postRequestParameter('text'), $userid);
188 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_REJECTED_NOTIFIED'));
191 sendEmail(getUserData('email'), getMessage('PAYOUT_REJECTED_SUBJECT'), $message);
196 'pid' => bigintval(getRequestParameter('pid')),
197 'user' => '<a href="' . generateEmailLink(getUserData('email'), 'user_data') . '">' . translateGender(getUserData('gender')) . ' ' . getUserData('surname') . ' ' . getUserData('family') . '</a>',
201 loadTemplate('admin_payout_reject_form', false, $content);
204 // Cannot load user data
205 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_FAILED_OBTAIN_USERDATA'));
207 } elseif ((empty($task)) || ($task == '0')) {
208 // Failed loading task id
209 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_FAILED_OBTAIN_TASK_ID'));
212 if (getRequestParameter('do') == 'delete') {
213 // Delete all requests
214 $result = SQL_QUERY("TRUNCATE `{?_MYSQL_PREFIX?}_user_payouts`", __FILE__, __LINE__);
217 // Search for payouts
218 $result = SQL_QUERY("SELECT
219 p.id, p.userid, p.payout_total, p.target_account,
220 p.target_bank, t.type, p.payout_timestamp, p.status,
221 t.allow_url AS allow, p.target_url AS url, p.link_text AS alt,
222 p.banner_url AS banner
224 `{?_MYSQL_PREFIX?}_user_payouts` AS p
226 `{?_MYSQL_PREFIX?}_payout_types` AS t
230 p.payout_timestamp DESC", __FILE__, __LINE__);
232 if (SQL_NUMROWS($result) > 0) {
233 // List found payouts
235 while ($content = SQL_FETCHARRAY($result)) {
236 if ($content['status'] == 'NEW') {
237 // Generate links for direct accepting and rejecting
238 $content['status'] = '<a href="{%url=modules.php?module=admin&what=list_payouts&do=accept&pid=' . $content['id'] . '%}">{--PAYOUT_ACCEPT_PAYOUT--}</a> | <a href="{%url=modules.php?module=admin&what=list_payouts&do=reject&pid=' . $content['id'] . '%}">{--PAYOUT_REJECT_PAYOUT--}</a>';
241 $content['status'] = getMessage('PAYOUT_STATUS_'.strtoupper($content['status']).'');
242 $content['status'] = '<div class="admin_failed">' . $content['status'] . '</div>';
245 // Nothing entered must be secured in member/what-payputs.php !
246 if ($content['allow'] == 'Y') {
247 // Banner/Textlink views/clicks request
248 if (!empty($content['banner'])) {
249 // Load template for the banner
250 $content['target_account'] = loadTemplate('admin_list_payouts_banner', true, $content);
253 $content['target_account'] = loadTemplate('admin_list_payouts_txt', true, $content);
256 // Admins can addionally test the URL for framekillers
257 $content['target_bank'] = '<a href="' . generateFrametesterUrl($content['url']) . '" target="_blank">{--CLICK_HERE--}</a>';
259 // e-currency payout request
260 if (empty($content['target_account'])) $content['target_account'] = '---';
261 if (empty($content['target_bank'])) $content['target_bank'] = '---';
264 // Remember data in array for the template
267 'ulink' => generateUserProfileLink($content['userid']),
268 'ptype' => translateComma($content['payout_total']) . ' ' . $content['type'],
269 'account' => $content['target_account'],
270 'bank' => $content['target_bank'],
271 'tstamp' => generateDateTime($content['payout_timestamp'], 2),
272 'status' => $content['status'],
275 // Add row and switch color
276 $OUT .= loadTemplate('admin_list_payouts_row', true, $content);
281 SQL_FREERESULT($result);
283 // Load final template
284 loadTemplate('admin_list_payouts', false, $OUT);
286 // No payout requests are sent so far
287 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_ADMIN_NO_REQUESTS_FOUND'));