2 /************************************************************************
3 * MXChange v0.2.1 Start: 04/12/2004 *
4 * ================ Last change: 12/01/2008 *
6 * -------------------------------------------------------------------- *
7 * File : what-payout.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Payout requests *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Auszahlungsanfragen *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36 // Don't call this directly!
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
39 } elseif (!IS_MEMBER()) {
41 LOAD_URL("modules.php?module=index");
42 } elseif ((!EXT_IS_ACTIVE("payout")) && (!IS_ADMIN())) {
43 addFatalMessage(__FILE__, __LINE__, getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), "payout");
47 // Add description as navigation point
48 ADD_DESCR("member", __FILE__);
50 $result_depths = SQL_QUERY("SELECT level, percents FROM `{!_MYSQL_PREFIX!}_refdepths` ORDER BY level", __FILE__, __LINE__);
52 while (list($lvl, $per) = SQL_FETCHROW($result_depths)) {
53 // Load referal points
54 $result_points = SQL_QUERY_ESC("SELECT points FROM `{!_MYSQL_PREFIX_user_points!}` WHERE userid=%s AND ref_depth=%d LIMIT 1",
55 array($GLOBALS['userid'], bigintval($lvl)), __FILE__, __LINE__);
58 if (SQL_NUMROWS($result_points) == 1) {
60 list($points) = SQL_FETCHROW($result_points);
67 SQL_FREERESULT($result_points);
71 SQL_FREERESULT($result_depths);
74 $USED = GET_TOTAL_DATA($GLOBALS['userid'], "user_data", "used_points");
76 // Translate point into comma
77 $TPTS = TRANSLATE_COMMA($TPTS - $USED);
80 if (empty($TPTS)) $TPTS = "0.00000";
82 if (!REQUEST_ISSET_GET(('payout'))) {
84 $result = SQL_QUERY_ESC("SELECT id, type, rate, min_points, allow_url
85 FROM `{!_MYSQL_PREFIX!}_payout_types`
86 WHERE %s >= min_points
87 ORDER BY type", array(REVERT_COMMA($TPTS)), __FILE__, __LINE__);
88 if (SQL_NUMROWS($result) > 0) {
90 SQL_FREERESULT($result);
92 // Check for his payouts
93 $result_payouts = SQL_QUERY_ESC("SELECT DISTINCT p.id, p.payout_total, p.target_account, p.target_bank, t.type, p.payout_timestamp, p.status, t.allow_url AS allow, p.target_url AS url, p.link_text AS alt, p.banner_url AS bannerm
94 FROM `{!_MYSQL_PREFIX!}_user_payouts` AS p
95 LEFT JOIN `{!_MYSQL_PREFIX!}_payout_types` AS t
98 ORDER BY p.payout_timestamp DESC",
99 array($GLOBALS['userid']), __FILE__, __LINE__);
100 if (SQL_NUMROWS($result_payouts) > 0) {
101 // List all his requests
103 while (list($pid, $total, $account, $bank, $type, $tstamp, $status, $allow, $url, $alt, $banner) = SQL_FETCHROW($result_payouts)) {
105 $status = constant('PAYOUT_MEMBER_STATUS_'.strtoupper($status).'');
106 $status = "<div class=\"member_failed\">".$status."</div>";
108 // Nothing entered must be secured in member/what-payputs.php !
110 // Banner/Textlink views/clicks request
111 if (!empty($banner)) {
113 $account = "<img src=\"".$banner."\" alt=\"".$alt."\" title=\"".$alt."\" border=\"0\" />";
118 $bank = "<a href=\"".DEREFERER($url)."\" target=\"_blank\">{--CLICK_HERE--}</a>";
120 // e-currency payout request
121 if (empty($account)) $account = "---";
122 if (empty($bank)) $bank = "---";
125 // Prepare data for the template
129 'points' => TRANSLATE_COMMA($total)." ".COMPILE_CODE($type),
131 'stamp' => MAKE_DATETIME($tstamp, "2"),
134 // Load row template and switch colors
135 $OUT .= LOAD_TEMPLATE("member_payout_row", true, $content);
139 // Remember rows in constant
140 define('__PAYOUT_ROWS', $OUT);
143 LOAD_TEMPLATE("member_payout");
147 SQL_FREERESULT($result_payouts);
149 // Output payout list
150 PAYOUT_OUTPUT_PAYOUT_LIST($TPTS);
153 // Chedk if he can get paid by selected type
154 $result = SQL_QUERY_ESC("SELECT type, rate, min_points, allow_url FROM `{!_MYSQL_PREFIX!}_payout_types` WHERE id=%s LIMIT 1",
155 array(bigintval(REQUEST_GET('payout'))), __FILE__, __LINE__);
157 if (SQL_NUMROWS($result) == 1) {
159 list($type, $rate, $min, $allow) = SQL_FETCHROW($result);
160 SQL_FREERESULT($result);
162 // Calculate maximum value
163 $max = round($TPTS * $rate - 0.5);
165 // Calulcate points from submitted amount
167 if (REQUEST_ISSET_POST(('payout'))) {
168 $PAYOUT = bigintval(REQUEST_POST('payout')) / $rate;
169 $PAY_MAX = $max / $rate;
172 // Move variables into constants for templates
173 define('PAYOUT_MAX_VALUE' , $max);
174 define('PAYOUT_TYPE_VALUE', COMPILE_CODE($type));
176 if (REVERT_COMMA($TPTS) >= $min) {
177 // Ok, he can get be paid
178 if ((IS_FORM_SENT()) && ($PAYOUT <= $PAY_MAX) && ($PAYOUT >= $min)) {
179 // Calculate exact value
180 define('PAYOUT_POINTS_VALUE', $PAYOUT);
182 // Subtract points from member's account
183 SUB_POINTS("payout", $GLOBALS['userid'], $PAYOUT);
185 // Add entry to his tranfer history
187 // Banner/textlink ordered
188 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_user_payouts` (userid, payout_total, payout_id, payout_timestamp, status, target_url, link_text, banner_url)
189 VALUES (%s,%s,%s, UNIX_TIMESTAMP(), 'NEW','%s','%s','%s')",
192 bigintval(REQUEST_POST('payout')),
193 bigintval(REQUEST_GET('payout')),
194 REQUEST_POST('turl'),
196 REQUEST_POST('banner')
197 ), __FILE__, __LINE__);
200 $msg_mem = LOAD_EMAIL_TEMPLATE("member_payout_request_banner", array(), $GLOBALS['userid']);
201 if (GET_EXT_VERSION("admins") >= "0.4.1") {
202 $adm_tpl = "admin_payout_request_banner";
204 $msg_adm = LOAD_EMAIL_TEMPLATE("admin_payout_request_banner", array(), $GLOBALS['userid']);
207 // e-currency payout requested
208 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_user_payouts` (userid, payout_total, target_account, target_bank, payout_id, payout_timestamp, status, password)
209 VALUES (%s,%s,%s,'%s',%s, UNIX_TIMESTAMP(), 'NEW','%s')",
212 bigintval(REQUEST_POST('payout')),
213 bigintval(REQUEST_POST('account')),
214 REQUEST_POST('bank'),
215 bigintval(REQUEST_GET('payout')),
217 ), __FILE__, __LINE__);
220 $msg_mem = LOAD_EMAIL_TEMPLATE("member_payout_request", array(), $GLOBALS['userid']);
221 $msg_adm = LOAD_EMAIL_TEMPLATE("admin_payout_request", array(), $GLOBALS['userid']);
223 if (GET_EXT_VERSION("admins") >= "0.4.1")
225 $admin_tpl = "admin_payout_request";
230 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_task_system` (assigned_admin, status, task_type, subject, text, task_created, userid)
231 VALUES (0, 'NEW','PAYOUT_REQUEST','[payout:] {--PAYOUT_REQUEST_ADMIN--}','%s', UNIX_TIMESTAMP(), %s)",
235 ), __FILE__, __LINE__);
238 SEND_EMAIL($GLOBALS['userid'], getMessage('PAYOUT_REQUEST_MEMBER'), $msg_mem);
241 SEND_ADMIN_NOTIFICATION(getMessage('PAYOUT_REQUEST_ADMIN'), $admin_tpl, array(), $GLOBALS['userid']);
243 // Load template and output it
244 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('PAYOUT_REQUEST_SENT'));
245 } elseif ($allow == "Y") {
246 // Generate banner order form
247 LOAD_TEMPLATE("member_payout_form_banner");
249 // Generate normal form
250 LOAD_TEMPLATE("member_payout_form");
253 // Not enougth points
254 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('PAYOUT_POINTS_NOT_ENOUGTH'));
258 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('PAYOUT_ID_INVALID'));