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 * 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 if (!fetchUserData($userid)) {
73 // Abort here because it is not valid!
74 debug_report_bug('No user account ' . $userid . ' found.');
77 if ((getRequestElement('do') == 'accept') && (!empty(getUserData('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);
102 $fpass = md5($fpass);
103 $tpass = md5($tpass);
107 $fpass = base64_encode($fpass);
108 $tpass = base64_encode($tpass);
112 // Transfer variables...
113 $eval = "\$URL = \"".$eurl."\";";
114 $reason = encodeString(getMessage('PAYOUT_REASON_PAYOUT'), false);
117 // @TODO Do we need this time-consuming eval() here?
121 $ret = sendGetRequest($URL);
127 if ($ret[0] == $eok) {
130 runFilterChain('solve_task', $task);
133 // Clear payout request
134 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_payouts` SET `status`='ACCEPTED' WHERE `id`=%s LIMIT 1",
135 array(bigintval(getRequestElement('pid'))), __FILE__, __LINE__);
138 $message = loadEmailTemplate('member_payout_accepted', postRequestElement('text'), $userid);
142 // Banner / Textlink request
143 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_BANNER_ACCEPTED_NOTIFIED'));
146 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_ACCEPTED_NOTIFIED'));
150 sendEmail(getUserData('email'), getMessage('PAYOUT_ACCEPTED_SUBJECT'), $message);
152 // Something goes wrong... :-(
153 $content = implode("<br />", $ret);
154 loadTemplate('admin_payout_failed_transfer', false, $content);
157 // Cannot load payout id
158 loadTemplate('admin_settings_saved', false, "<div class=\"admin_failed\">{--PAYOUT_FAILED_OBTAIN_PAYOUT_ID--}</div>");
164 'pid' => bigintval(getRequestElement('pid')),
165 'user' => "<a href=\"".generateEmailLink(getUserData('email'), 'user_data')."\">".translateGender(getUserData('gender'))." ".getUserData('surname')." ".getUserData('family')."</a>",
169 loadTemplate('admin_payout_accept_form', false, $content);
171 } elseif ((getRequestElement('do') == 'reject') && (!empty(getUserData('email')))) {
172 // Ok, now we can output the form or execute rejecting
176 runFilterChain('solve_task', $task);
179 // Clear payout request
180 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_payouts` SET `status`='REJECTED' WHERE `id`=%s LIMIT 1",
181 array(bigintval(getRequestElement('pid'))), __FILE__, __LINE__);
184 $message = loadEmailTemplate('member_payout_rejected', postRequestElement('text'), $userid);
187 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_REJECTED_NOTIFIED'));
190 sendEmail(getUserData('email'), getMessage('PAYOUT_REJECTED_SUBJECT'), $message);
195 'pid' => bigintval(getRequestElement('pid')),
196 'user' => "<a href=\"".generateEmailLink(getUserData('email'), 'user_data')."\">".translateGender(getUserData('gender'))." ".getUserData('surname')." ".getUserData('family')."</a>",
200 loadTemplate('admin_payout_reject_form', false, $content);
203 // Cannot load user data
204 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_FAILED_OBTAIN_USERDATA'));
206 } elseif ((empty($task)) || ($task == '0')) {
207 // Failed loading task id
208 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_FAILED_OBTAIN_TASK_ID'));
211 if (!isGetRequestElementSet('do')) setRequestGetElement('do', '');
213 if (getRequestElement('do') == 'delete') {
214 // Delete all requests
215 $result = SQL_QUERY("TRUNCATE `{?_MYSQL_PREFIX?}_user_payouts`", __FILE__, __LINE__);
218 // Search for payouts
219 $result = SQL_QUERY("SELECT
220 p.id, p.userid, p.payout_total, p.target_account,
221 p.target_bank, t.type, p.payout_timestamp, p.status,
222 t.allow_url AS allow, p.target_url AS url, p.link_text AS alt,
223 p.banner_url AS banner
225 `{?_MYSQL_PREFIX?}_user_payouts` AS p
227 `{?_MYSQL_PREFIX?}_payout_types` AS t
231 p.payout_timestamp DESC", __FILE__, __LINE__);
233 if (SQL_NUMROWS($result) > 0) {
234 // List found payouts
236 while ($content = SQL_FETCHARRAY($result)) {
237 if ($content['status'] == 'NEW') {
238 // Generate links for direct accepting and rejecting
239 $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>";
242 $content['status'] = getMessage('PAYOUT_STATUS_'.strtoupper($content['status']).'');
243 $content['status'] = "<div class=\"admin_failed\">".$content['status']."</div>";
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>";
260 // e-currency payout request
261 if (empty($content['target_account'])) $content['target_account'] = '---';
262 if (empty($content['target_bank'])) $content['target_bank'] = '---';
265 // Remember data in array for the template
268 'ulink' => generateUserProfileLink($content['userid']),
269 'ptype' => translateComma($content['payout_total']) . ' ' . $content['type'],
270 'account' => $content['target_account'],
271 'bank' => $content['target_bank'],
272 'tstamp' => generateDateTime($content['payout_timestamp'], 2),
273 'status' => $content['status'],
276 // Add row and switch color
277 $OUT .= loadTemplate('admin_list_payouts_row', true, $content);
282 SQL_FREERESULT($result);
284 // Load final template
285 loadTemplate('admin_list_payouts', false, $OUT);
287 // No payout requests are sent so far
288 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_ADMIN_NO_REQUESTS_FOUND'));