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))
77 $aid = SPONSOR_NO_ADMIN;
79 // Load admin's email address for contact
80 $aid = GET_ADMIN_EMAIL(GET_ADMIN_LOGIN(($aid));
83 // Transfer data to array
86 'order' => ($count * $prate)." ".$pcurr,
87 'stamp' => MAKE_DATETIME($ordered, "2"),
91 // Load email template
92 $content['msg'] = LOAD_EMAIL_TEMPLATE("sponsor_unlock_sponsor_pay", $content, $id);
96 $content['msg'] = SPONSOR_NO_PAYMENTS_FOUND;
100 SQL_FREERESULT($result);
104 SQL_FREERESULT($result_main);
106 // Unlock sponsor account
107 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_sponsor_data SET status='CONFIRMED'
108 WHERE id='%s' AND status='PENDING' LIMIT 1",
109 array($id), __FILE__, __LINE__);
111 // Update, if applyable, referal count and points
112 if (($refid > 0) && ($refid != $id)) {
113 // Update referal account
114 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_sponsor_data
115 SET points_amount=points_amount+%s, ref_count=ref_count+1
116 WHERE id='%s' LIMIT 1",
117 array($_CONFIG['sponsor_ref_points'], bigintval($refid)), __FILE__, __LINE__);
119 // Whas that update fine?
120 if (SQL_AFFECTEDROWS() == 1) {
121 // Load referal's data
122 $result = SQL_QUERY_ESC("SELECT id, gender, surname, family, email,
123 (points_amount - points_used) AS points, receive_warnings, ref_count AS refs
124 FROM "._MYSQL_PREFIX."_sponsor_data
125 WHERE id='%s' LIMIT 1",
126 array(bigintval($refid)), __FILE__, __LINE__);
127 $REFERRAL = SQL_FETCHARRAY($result);
129 // Send warnings out?
130 if ($REFERRAL['receive_warnings'] == "Y") {
131 // Translate some data
132 $REFERRAL['points'] = TRANSLATE_COMMA($REFERRAL['points']);
133 $REFERRAL['ref_points'] = TRANSLATE_COMMA($_CONFIG['sponsor_ref_points']);
134 $REFERRAL['gender'] = TRANSLATE_GENDER($REFERRAL['gender']);
136 // Send notification to referal
137 $REF_MSG = LOAD_EMAIL_TEMPLATE("sponsor_ref_notify", $REFERRAL);
138 SEND_EMAIL($REFERRAL['email'], SPONSOR_REF_NOTIFY_SUBJ, $REF_MSG);
142 SQL_FREERESULT($result);
146 // Transfer data to array
147 $content['gender'] = TRANSLATE_GENDER($gender);
148 $content['surname'] = $sname;
149 $content['family'] = $fname;
150 $content['sponsor'] = $id;
151 $content['points'] = TRANSLATE_COMMA($points);
153 // So let's send the email away
154 $msg = LOAD_EMAIL_TEMPLATE("sponsor_unlocked", $content);
155 SEND_EMAIL($email, SPONSOR_UNLOCKED_SUBJ, $msg);
159 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SPONSOR_NONE_SELECTED_UNLOCK);
163 OUTPUT_HTML("<br />");
166 // Begin listing of all pending sponsor accounts
167 $result = SQL_QUERY("SELECT id, gender, surname, family, email, remote_addr, sponsor_created
168 FROM "._MYSQL_PREFIX."_sponsor_data
169 WHERE status='PENDING' ORDER BY id", __FILE__, __LINE__);
171 if (SQL_NUMROWS($result) > 0) {
172 // Entries found so let's list them!
174 while(list($id, $gender, $sname, $fname, $email, $ip, $created) = SQL_FETCHROW($result)) {
175 // Transfer data to array
179 'gender' => TRANSLATE_GENDER($gender),
182 'email' => "mailto:".$email,
184 'created' => MAKE_DATETIME($created, "2"),
187 // Load row template and switch colors
188 $OUT .= LOAD_TEMPLATE("admin_unlock_sponsor_row", true, $content);
191 define('__SPONSOR_ROWS', $OUT);
194 LOAD_TEMPLATE("admin_unlock_sponsor");
196 // No pending accounts found
197 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SPONSOR_NONE_PENDING);
201 SQL_FREERESULT($result);