2 /************************************************************************
3 * MXChange v0.2.1 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 * 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')) || (!isAdmin())) {
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
47 if (isGetRequestElementSet(('pid'))) {
48 // First let's get the member's ID
49 $result = SQL_QUERY_ESC("SELECT userid, target_account, payout_total, payout_timestamp, password FROM `{?_MYSQL_PREFIX?}_user_payouts` WHERE `id`=%s LIMIT 1",
50 array(getRequestElement('pid')), __FILE__, __LINE__);
51 list($userid, $tuserid, $points, $tstamp, $tpass) = SQL_FETCHROW($result);
52 SQL_FREERESULT($result);
55 if (!isGetRequestElementSet(('task')) && (!empty($userid)) && ($userid > 0)) {
56 // Get task ID from database
57 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `userid`=%s AND `task_type`='PAYOUT_REQUEST' AND task_created='".$tstamp."' LIMIT 1",
58 array(bigintval($userid)), __FILE__, __LINE__);
59 list($task) = SQL_FETCHROW($result);
60 SQL_FREERESULT($result);
61 if (empty($task)) $task = 0;
62 } elseif ((empty($userid)) || ($userid == 0)) {
63 // Cannot obtain member ID!
64 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_FAILED_OBTAIN_USERID'));
66 // Get task ID from URL
67 $task = getRequestElement('task');
70 if ((!empty($task)) && (!empty($userid)) && ($userid > 0)) {
72 $result = SQL_QUERY_ESC("SELECT `email`, `gender`, `surname`, `family` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
73 array(bigintval($userid)), __FILE__, __LINE__);
74 list($email, $gender, $surname, $family) = SQL_FETCHROW($result);
75 SQL_FREERESULT($result);
77 if ((getRequestElement('do') == 'accept') && (!empty($email))) {
78 // Ok, now we can output the form or execute accepting
80 // Obtain payout type and other data
81 $result = SQL_QUERY_ESC("SELECT `payout_id` FROM `{?_MYSQL_PREFIX?}_user_payouts` WHERE `id`=%s LIMIT 1",
82 array(bigintval(getRequestElement('pid'))), __FILE__, __LINE__);
83 list($ptype) = SQL_FETCHROW($result);
84 SQL_FREERESULT($result);
87 // Obtain data from payout type
88 $result = SQL_QUERY_ESC("SELECT `from_account`, `from_pass`, `engine_url`, `engine_ret_ok`, `engine_ret_failed`, `pass_enc`, `allow_url`
90 `{?_MYSQL_PREFIX?}_payout_types`
94 array(bigintval($ptype)), __FILE__, __LINE__);
95 list($fuserid, $fpass, $eurl, $eok, $failed, $eenc, $allow) = SQL_FETCHROW($result);
96 SQL_FREERESULT($result);
100 $eurl = compileCode($eurl);
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(getRequestElement('pid'))), __FILE__, __LINE__);
139 $message = loadEmailTemplate('member_payout_accepted', postRequestElement('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($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(getRequestElement('pid')),
166 'user' => "<a href=\"".generateEmailLink($email, 'user_data')."\">".translateGender($gender)." ".$surname." ".$family."</a>",
170 loadTemplate('admin_payout_accept_form', false, $content);
172 } elseif ((getRequestElement('do') == 'reject') && (!empty($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(getRequestElement('pid'))), __FILE__, __LINE__);
185 $message = loadEmailTemplate('member_payout_rejected', postRequestElement('text'), $userid);
188 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_REJECTED_NOTIFIED'));
191 sendEmail($email, getMessage('PAYOUT_REJECTED_SUBJECT'), $message);
196 'pid' => bigintval(getRequestElement('pid')),
197 'user' => "<a href=\"".generateEmailLink($email, 'user_data')."\">".translateGender($gender)." ".$surname." ".$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 (!isGetRequestElementSet('do')) setRequestGetElement('do', '');
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_NUMROWS($result) > 0) {
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']."\">".PAYOUT_ACCEPT_PAYOUT."</a> | <a href=\"{?URL?}/modules.php?module=admin&what=list_payouts&do=reject&pid=".$content['id']."\">".PAYOUT_REJECT_PAYOUT."</a>";
243 $content['status'] = getMessage('PAYOUT_STATUS_'.strtoupper($content['status']).'');
244 $content['status'] = "<div class=\"admin_failed\">".$content['status']."</div>";
247 // Nothing entered must be secured in member/what-payputs.php !
248 if ($content['allow'] == 'Y') {
249 // Banner/Textlink views/clicks request
250 if (!empty($content['banner'])) {
251 // Load template for the banner
252 $content['target_account'] = loadTemplate('admin_list_payouts_banner', true, $content);
255 $content['target_account'] = loadTemplate('admin_list_payouts_txt', true, $content);
258 // Admins can addionally test the URL for framekillers
259 $content['target_bank'] = "<a href=\"".generateFrametesterUrl($content['url'])."\" target=\"_blank\">{--CLICK_HERE--}</a>";
261 // e-currency payout request
262 if (empty($content['target_account'])) $content['target_account'] = '---';
263 if (empty($content['target_bank'])) $content['target_bank'] = '---';
266 // Remember data in array for the template
269 'ulink' => generateUserProfileLink($content['userid']),
270 'ptype' => translateComma($content['payout_total']) . ' ' . $content['type'],
271 'account' => $content['target_account'],
272 'bank' => $content['target_bank'],
273 'tstamp' => generateDateTime($content['payout_timestamp'], 2),
274 'status' => $content['status'],
277 // Add row and switch color
278 $OUT .= loadTemplate('admin_list_payouts_row', true, $content);
283 SQL_FREERESULT($result);
285 // Load final template
286 loadTemplate('admin_list_payouts', false, $OUT);
288 // No payout requests are sent so far
289 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_ADMIN_NO_REQUESTS_FOUND'));