2 /************************************************************************
3 * M-XChange v0.2.1 Start: 04/23/2005 *
4 * ================ Last change: 05/19/2008 *
6 * -------------------------------------------------------------------- *
7 * File : what-unlock_sponsor.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Unlock sponsor accounts *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Sponsorenaccounts freigeben *
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')) || (!IS_ADMIN())) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
43 // Check if admin has submitted form
44 if (isset($_POST['ok'])) {
45 // Does he have selected at least one sponsor?
46 if (SELECTION_COUNT($_POST['id']) > 0) {
47 // At least one entry selected
48 foreach ($_POST['id'] as $id => $sel) {
52 // Load his personal data
53 $result_main = SQL_QUERY_ESC("SELECT gender, surname, family, email, remote_addr, sponsor_created, points_amount, refid
54 FROM `{!_MYSQL_PREFIX!}_sponsor_data`
55 WHERE `status`='PENDING' AND id='%s' LIMIT 1",
56 array($id), __FILE__, __LINE__);
58 if (SQL_NUMROWS($result_main) == 1) {
59 // Load data and free memory
60 list($gender, $sname, $fname, $email, $ip, $created, $points, $refid) = SQL_FETCHROW($result_main);
62 // Check for open payments and close them
63 $result = SQL_QUERY_ESC("SELECT DISTINCT so.aid, so.pay_count, so.pay_ordered, so.pay_status,
64 sp.pay_name, sp.pay_rate, sp.pay_currency
65 FROM `{!_MYSQL_PREFIX!}_sponsor_orders` AS so
66 LEFT JOIN `{!_MYSQL_PREFIX!}_sponsor_paytypes` AS sp
68 WHERE so.sponsorid='%s'
69 ORDER BY sp.pay_name",
70 array($id), __FILE__, __LINE__);
71 if (SQL_NUMROWS($result) > 0) {
73 while (list($aid, $count, $ordered, $status, $pname, $prate, $pcurr) = SQL_FETCHROW($result))
76 $email = SPONSOR_NO_ADMIN;
78 // Load admin's email address for contact
79 $email = GET_ADMIN_EMAIL($aid);
82 // Transfer data to array
85 'order' => ($count * $prate)." ".$pcurr,
86 'stamp' => MAKE_DATETIME($ordered, "2"),
90 // Load email template
91 $content['msg'] = LOAD_EMAIL_TEMPLATE("sponsor_unlock_sponsor_pay", $content, $id);
95 $content['msg'] = SPONSOR_NO_PAYMENTS_FOUND;
99 SQL_FREERESULT($result);
103 SQL_FREERESULT($result_main);
105 // Unlock sponsor account
106 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_sponsor_data` SET `status`='CONFIRMED'
107 WHERE id='%s' AND `status`='PENDING' LIMIT 1",
108 array($id), __FILE__, __LINE__);
110 // Update, if applyable, referal count and points
111 if (($refid > 0) && ($refid != $id)) {
112 // Update referal account
113 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_sponsor_data`
114 SET points_amount=points_amount+%s, ref_count=ref_count+1
115 WHERE id='%s' LIMIT 1",
116 array(getConfig('sponsor_ref_points'), bigintval($refid)), __FILE__, __LINE__);
118 // Whas that update fine?
119 if (SQL_AFFECTEDROWS() == 1) {
120 // Load referal's data
121 $result = SQL_QUERY_ESC("SELECT id, gender, surname, family, email,
122 (points_amount - points_used) AS points, receive_warnings, ref_count AS refs
123 FROM `{!_MYSQL_PREFIX!}_sponsor_data`
124 WHERE id='%s' LIMIT 1",
125 array(bigintval($refid)), __FILE__, __LINE__);
126 $REFERRAL = SQL_FETCHARRAY($result);
128 // Send warnings out?
129 if ($REFERRAL['receive_warnings'] == "Y") {
130 // Translate some data
131 $REFERRAL['points'] = TRANSLATE_COMMA($REFERRAL['points']);
132 $REFERRAL['ref_points'] = TRANSLATE_COMMA(getConfig('sponsor_ref_points'));
133 $REFERRAL['gender'] = TRANSLATE_GENDER($REFERRAL['gender']);
135 // Send notification to referal
136 $REF_MSG = LOAD_EMAIL_TEMPLATE("sponsor_ref_notify", $REFERRAL);
137 SEND_EMAIL($REFERRAL['email'], getMessage('SPONSOR_REF_NOTIFY_SUBJ'), $REF_MSG);
141 SQL_FREERESULT($result);
145 // Transfer data to array
146 $content['gender'] = TRANSLATE_GENDER($gender);
147 $content['surname'] = $sname;
148 $content['family'] = $fname;
149 $content['sponsor'] = $id;
150 $content['points'] = TRANSLATE_COMMA($points);
152 // So let's send the email away
153 $msg = LOAD_EMAIL_TEMPLATE("sponsor_unlocked", $content);
154 SEND_EMAIL($email, getMessage('SPONSOR_UNLOCKED_SUBJ'), $msg);
158 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_SPONSOR_NONE_SELECTED_UNLOCK'));
162 OUTPUT_HTML("<br />");
165 // Begin listing of all pending sponsor accounts
166 $result = SQL_QUERY("SELECT
167 id, gender, surname, family, email, remote_addr, sponsor_created
169 `{!_MYSQL_PREFIX!}_sponsor_data`
173 `id`", __FILE__, __LINE__);
175 if (SQL_NUMROWS($result) > 0) {
176 // Entries found so let's list them!
178 while (list($id, $gender, $sname, $fname, $email, $ip, $created) = SQL_FETCHROW($result)) {
179 // Transfer data to array
183 'gender' => TRANSLATE_GENDER($gender),
186 'email' => "mailto:".$email,
188 'created' => MAKE_DATETIME($created, "2"),
191 // Load row template and switch colors
192 $OUT .= LOAD_TEMPLATE("admin_unlock_sponsor_row", true, $content);
195 define('__SPONSOR_ROWS', $OUT);
198 LOAD_TEMPLATE("admin_unlock_sponsor");
200 // No pending accounts found
201 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_SPONSOR_NONE_PENDING'));
205 SQL_FREERESULT($result);