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. *
21 ************************************************************************/
23 // Some security stuff...
24 if ((!defined('__SECURITY')) || (!is_admin())) {
25 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
29 // Add description as navigation point
30 ADD_DESCR("admin", basename(__FILE__));
32 // Check if admin has submitted form
33 if (isset($_POST['ok'])) {
34 // Does he have selected at least one sponsor?
35 if (SELECTION_COUNT($_POST['id']) > 0) {
36 // At least one entry selected
37 foreach ($_POST['id'] as $id => $sel) {
41 // Load his personal data
42 $result_main = SQL_QUERY_ESC("SELECT gender, surname, family, email, remote_addr, sponsor_created, points_amount, refid
43 FROM "._MYSQL_PREFIX."_sponsor_data
44 WHERE status='PENDING' AND id='%s' LIMIT 1",
45 array($id), __FILE__, __LINE__);
47 if (SQL_NUMROWS($result_main) == 1) {
48 // Load data and free memory
49 list($gender, $sname, $fname, $email, $ip, $created, $points, $refid) = SQL_FETCHROW($result_main);
51 // Check for open payments and close them
52 $result = SQL_QUERY_ESC("SELECT DISTINCT so.aid, so.pay_count, so.pay_ordered, so.pay_status,
53 sp.pay_name, sp.pay_rate, sp.pay_currency
54 FROM "._MYSQL_PREFIX."_sponsor_orders AS so
55 LEFT JOIN "._MYSQL_PREFIX."_sponsor_paytypes AS sp
57 WHERE so.sponsorid='%s'
58 ORDER BY sp.pay_name",
59 array($id), __FILE__, __LINE__);
60 if (SQL_NUMROWS($result) > 0) {
62 while(list($aid, $count, $ordered, $status, $pname, $prate, $pcurr) = SQL_FETCHROW($result))
66 $aid = SPONSOR_NO_ADMIN;
68 // Load admin's email address for contact
69 $aid = GET_ADMIN_EMAIL(GET_ADMIN_LOGIN(($aid));
72 // Transfer data to array
75 'order' => ($count * $prate)." ".$pcurr,
76 'stamp' => MAKE_DATETIME($ordered, "2"),
80 // Load email template
81 $content['msg'] = LOAD_EMAIL_TEMPLATE("sponsor_unlock_sponsor_pay", $content, $id);
85 $content['msg'] = SPONSOR_NO_PAYMENTS_FOUND;
89 SQL_FREERESULT($result);
93 SQL_FREERESULT($result_main);
95 // Unlock sponsor account
96 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_sponsor_data SET status='CONFIRMED'
97 WHERE id='%s' AND status='PENDING' LIMIT 1",
98 array($id), __FILE__, __LINE__);
100 // Update, if applyable, referral count and points
101 if (($refid > 0) && ($refid != $id)) {
102 // Update referral account
103 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_sponsor_data
104 SET points_amount=points_amount+%s, ref_count=ref_count+1
105 WHERE id='%s' LIMIT 1",
106 array($_CONFIG['sponsor_ref_points'], bigintval($refid)), __FILE__, __LINE__);
108 // Whas that update fine?
109 if (SQL_AFFECTEDROWS() == 1) {
110 // Load referral's data
111 $result = SQL_QUERY_ESC("SELECT id, gender, surname, family, email,
112 (points_amount - points_used) AS points, receive_warnings, ref_count AS refs
113 FROM "._MYSQL_PREFIX."_sponsor_data
114 WHERE id='%s' LIMIT 1",
115 array(bigintval($refid)), __FILE__, __LINE__);
116 $REFERRAL = SQL_FETCHARRAY($result);
118 // Send warnings out?
119 if ($REFERRAL['receive_warnings'] == "Y") {
120 // Translate some data
121 $REFERRAL['points'] = TRANSLATE_COMMA($REFERRAL['points']);
122 $REFERRAL['ref_points'] = TRANSLATE_COMMA($_CONFIG['sponsor_ref_points']);
123 $REFERRAL['gender'] = TRANSLATE_GENDER($REFERRAL['gender']);
125 // Send notification to referral
126 $REF_MSG = LOAD_EMAIL_TEMPLATE("sponsor_ref_notify", $REFERRAL);
127 SEND_EMAIL($REFERRAL['email'], SPONSOR_REF_NOTIFY_SUBJ, $REF_MSG);
131 SQL_FREERESULT($result);
135 // Transfer data to array
136 $content['gender'] = TRANSLATE_GENDER($gender);
137 $content['surname'] = $sname;
138 $content['family'] = $fname;
139 $content['sponsor'] = $id;
140 $content['points'] = TRANSLATE_COMMA($points);
142 // So let's send the email away
143 $msg = LOAD_EMAIL_TEMPLATE("sponsor_unlocked", $content);
144 SEND_EMAIL($email, SPONSOR_UNLOCKED_SUBJ, $msg);
148 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SPONSOR_NONE_SELECTED_UNLOCK);
152 OUTPUT_HTML("<br />");
155 // Begin listing of all pending sponsor accounts
156 $result = SQL_QUERY("SELECT id, gender, surname, family, email, remote_addr, sponsor_created
157 FROM "._MYSQL_PREFIX."_sponsor_data
158 WHERE status='PENDING' ORDER BY id", __FILE__, __LINE__);
160 if (SQL_NUMROWS($result) > 0) {
161 // Entries found so let's list them!
163 while(list($id, $gender, $sname, $fname, $email, $ip, $created) = SQL_FETCHROW($result)) {
164 // Transfer data to array
168 'gender' => TRANSLATE_GENDER($gender),
171 'email' => "mailto:".$email,
173 'created' => MAKE_DATETIME($created, "2"),
176 // Load row template and switch colors
177 $OUT .= LOAD_TEMPLATE("admin_unlock_sponsor_row", true, $content);
180 define('__SPONSOR_ROWS', $OUT);
183 LOAD_TEMPLATE("admin_unlock_sponsor");
185 // No pending accounts found
186 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SPONSOR_NONE_PENDING);
190 SQL_FREERESULT($result);