Fix for missing array elements
[mailer.git] / inc / modules / admin / what-list_payouts.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 05/08/2004 *
4  * ===================                          Last change: 08/12/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-list_payouts.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : List member's payout requests                    *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Auflistung der Auszahlungsanfragen               *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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                  *
23  *                                                                      *
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.                                  *
28  *                                                                      *
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.                         *
33  *                                                                      *
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,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 } // END - if
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
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);
54
55         // Obtain some data
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='".$tstamp."' LIMIT 1",
59                 array(bigintval($userid)), __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'));
66         } else {
67                 // Get task id from URL
68                 $task = getRequestParameter('task');
69         }
70
71         if ((!empty($task)) && (!empty($userid)) && ($userid > 0)) {
72                 // Load user's data
73                 if (!fetchUserData($userid)) {
74                         // Abort here because it is not valid!
75                         debug_report_bug('No user account ' . $userid . ' found.');
76                 } // END - if
77
78                 if ((getRequestParameter('do') == 'accept') && (!empty(getUserData('email')))) {
79                         // Ok, now we can output the form or execute accepting
80                         if (isFormSent()) {
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);
86
87                                 if (!empty($ptype)) {
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`
90 FROM
91         `{?_MYSQL_PREFIX?}_payout_types`
92 WHERE
93         `id`=%s
94 LIMIT 1",
95                                                 array(bigintval($ptype)), __FILE__, __LINE__);
96                                         list($fuserid, $fpass, $eurl, $eok, $failed, $eenc, $allow) = SQL_FETCHROW($result);
97                                         SQL_FREERESULT($result);
98
99                                         if (!empty($eurl)) {
100                                                 // Ok, run URL...
101                                                 switch ($eenc) {
102                                                         case 'md5':
103                                                                 $fpass = md5($fpass);
104                                                                 $tpass = md5($tpass);
105                                                                 break;
106
107                                                         case 'base64':
108                                                                 $fpass = base64_encode($fpass);
109                                                                 $tpass = base64_encode($tpass);
110                                                                 break;
111                                                 }
112
113                                                 // Transfer variables...
114                                                 $eval = '$URL = "' . $eurl . '";';
115                                                 $reason = encodeString(getMessage('PAYOUT_REASON_PAYOUT'), false);
116
117                                                 // Run code...
118                                                 // @TODO Do we need this time-consuming eval() here?
119                                                 eval($eval);
120
121                                                 // Execute transfer
122                                                 $ret = sendGetRequest($URL);
123                                         } else {
124                                                 // No URL to run
125                                                 $ret[0] = $eok;
126                                         }
127
128                                         if ($ret[0] == $eok) {
129                                                 // Clear task
130                                                 if ($task > 0) {
131                                                         runFilterChain('solve_task', $task);
132                                                 }
133
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__);
137
138                                                 // Send out mail
139                                                 $message = loadEmailTemplate('member_payout_accepted', postRequestParameter('text'), $userid);
140
141                                                 // Output message
142                                                 if ($allow == 'Y') {
143                                                         // Banner / Textlink request
144                                                         loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_BANNER_ACCEPTED_NOTIFIED'));
145                                                 } else {
146                                                         // Normal request
147                                                         loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_ACCEPTED_NOTIFIED'));
148                                                 }
149
150                                                 // Finally send mail
151                                                 sendEmail(getUserData('email'), getMessage('PAYOUT_ACCEPTED_SUBJECT'), $message);
152                                         } else {
153                                                 // Something goes wrong... :-(
154                                                 $content = implode("<br />", $ret);
155                                                 loadTemplate('admin_payout_failed_transfer', false, $content);
156                                         }
157                                 } else {
158                                         // Cannot load payout id
159                                         loadTemplate('admin_settings_saved', false, '<div class="admin_failed">{--PAYOUT_FAILED_OBTAIN_PAYOUT_ID--}</div>');
160                                 }
161                         } else {
162                                 // Prepare content
163                                 $content = array(
164                                         'task' => $task,
165                                         'pid'  => bigintval(getRequestParameter('pid')),
166                                         'user' => '<a href="' . generateEmailLink(getUserData('email'), 'user_data') . '">' . translateGender(getUserData('gender')) . ' ' . getUserData('surname') . ' ' . getUserData('family') . '</a>',
167                                 );
168
169                                 // Load template
170                                 loadTemplate('admin_payout_accept_form', false, $content);
171                         }
172                 } elseif ((getRequestParameter('do') == 'reject') && (!empty(getUserData('email')))) {
173                         // Ok, now we can output the form or execute rejecting
174                         if (isFormSent()) {
175                                 if ($task > 0) {
176                                         // Clear task
177                                         runFilterChain('solve_task', $task);
178                                 } // END - if
179
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__);
183
184                                 // Send out mail
185                                 $message = loadEmailTemplate('member_payout_rejected', postRequestParameter('text'), $userid);
186
187                                 // Output message
188                                 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_REJECTED_NOTIFIED'));
189
190                                 // Finally send mail
191                                 sendEmail(getUserData('email'), getMessage('PAYOUT_REJECTED_SUBJECT'), $message);
192                         } else {
193                                 // Prepare content
194                                 $content = array(
195                                         'task' => $task,
196                                         'pid'  => bigintval(getRequestParameter('pid')),
197                                         'user' => '<a href="' . generateEmailLink(getUserData('email'), 'user_data') . '">' . translateGender(getUserData('gender')) . ' ' . getUserData('surname') . ' ' . getUserData('family') . '</a>',
198                                 );
199
200                                 // Load template
201                                 loadTemplate('admin_payout_reject_form', false, $content);
202                         }
203                 } else {
204                         // Cannot load user data
205                         loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_FAILED_OBTAIN_USERDATA'));
206                 }
207         } elseif ((empty($task)) || ($task == '0')) {
208                 // Failed loading task id
209                 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_FAILED_OBTAIN_TASK_ID'));
210         }
211 } else {
212         if (getRequestParameter('do') == 'delete') {
213                 // Delete all requests
214                 $result = SQL_QUERY("TRUNCATE `{?_MYSQL_PREFIX?}_user_payouts`", __FILE__, __LINE__);
215         } // END - if
216
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
223 FROM
224         `{?_MYSQL_PREFIX?}_user_payouts` AS p
225 LEFT JOIN
226         `{?_MYSQL_PREFIX?}_payout_types` AS t
227 ON
228         p.payout_id=t.id
229 ORDER BY
230         p.payout_timestamp DESC", __FILE__, __LINE__);
231
232         if (SQL_NUMROWS($result) > 0) {
233                 // List found payouts
234                 $OUT = ''; $SW = 2;
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&amp;what=list_payouts&amp;do=accept&amp;pid=' . $content['id'] . '%}">{--PAYOUT_ACCEPT_PAYOUT--}</a>&nbsp;|&nbsp;<a href="{%url=modules.php?module=admin&amp;what=list_payouts&amp;do=reject&amp;pid=' . $content['id'] . '%}">{--PAYOUT_REJECT_PAYOUT--}</a>';
239                         } else {
240                                 // Translate status
241                                 $content['status'] = getMessage('PAYOUT_STATUS_'.strtoupper($content['status']).'');
242                                 $content['status'] = '<div class="admin_failed">' . $content['status'] . '</div>';
243                         }
244
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);
251                                 } else {
252                                         // Textlink
253                                         $content['target_account'] = loadTemplate('admin_list_payouts_txt', true, $content);
254                                 }
255
256                                 // Admins can addionally test the URL for framekillers
257                                 $content['target_bank'] = '<a href="' . generateFrametesterUrl($content['url']) . '" target="_blank">{--CLICK_HERE--}</a>';
258                         } else {
259                                 // e-currency payout request
260                                 if (empty($content['target_account'])) $content['target_account'] = '---';
261                                 if (empty($content['target_bank']))    $content['target_bank']    = '---';
262                         }
263
264                         // Remember data in array for the template
265                         $content = array(
266                                 'sw'      => $SW,
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'],
273                         );
274
275                         // Add row and switch color
276                         $OUT .= loadTemplate('admin_list_payouts_row', true, $content);
277                         $SW = 3 - $SW;
278                 } // END - while
279
280                 // Free memory
281                 SQL_FREERESULT($result);
282
283                 // Load final template
284                 loadTemplate('admin_list_payouts', false, $OUT);
285         } else {
286                 // No payout requests are sent so far
287                 loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_ADMIN_NO_REQUESTS_FOUND'));
288         }
289 }
290
291 // [EOF]
292 ?>