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
45 // Does he have selected at least one sponsor?
46 if (SELECTION_COUNT(REQUEST_POST('id')) > 0) {
47 // At least one entry selected
48 foreach (REQUEST_POST('id') as $id => $selected) {
49 // Secure ID number and init $content
51 'id' => bigintval($id),
55 // Load his personal data
56 $result_main = SQL_QUERY_ESC("SELECT gender, surname, family, email, remote_addr, sponsor_created, points_amount, refid
57 FROM `{!_MYSQL_PREFIX!}_sponsor_data`
58 WHERE `status`='PENDING' AND id='%s' LIMIT 1",
59 array($content['id']), __FILE__, __LINE__);
61 if (SQL_NUMROWS($result_main) == 1) {
63 $content = SQL_FETCHROW($result_main);
65 // Check for open payments and close them
66 $result = SQL_QUERY_ESC("SELECT DISTINCT so.aid, so.pay_count, so.pay_ordered, so.pay_status,
67 sp.pay_name, sp.pay_rate, sp.pay_currency
68 FROM `{!_MYSQL_PREFIX!}_sponsor_orders` AS so
69 LEFT JOIN `{!_MYSQL_PREFIX!}_sponsor_paytypes` AS sp
71 WHERE so.sponsorid='%s'
72 ORDER BY sp.pay_name",
73 array($content['id']), __FILE__, __LINE__);
74 if (SQL_NUMROWS($result) > 0) {
76 while ($content2 = SQL_FETCHARRAY($result)) {
78 $content = merge_array($content, $content2);
81 $content['email'] = getMessage('SPONSOR_NO_ADMIN');
82 if ($content['aid'] > "0") {
83 // Load admin's email address for contact
84 $content['email'] = GET_ADMIN_EMAIL($content['aid']);
87 // Transfer data to array
89 'aid' => $content['email'],
90 'order' => ($content['pay_count'] * $content['pay_rate'])." ".$content['pay_currency'],
91 'stamp' => MAKE_DATETIME($content['pay_ordered'], "2"),
92 'pname' => $content['pay_name'],
95 // Load email template
96 $content['msg'] = LOAD_EMAIL_TEMPLATE("sponsor_unlock_sponsor_pay", $data, $content['id']);
100 $content['msg'] = getMessage('SPONSOR_NO_PAYMENTS_FOUND');
104 SQL_FREERESULT($result);
108 SQL_FREERESULT($result_main);
110 // Unlock sponsor account
111 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_sponsor_data` SET `status`='CONFIRMED'
112 WHERE id='%s' AND `status`='PENDING' LIMIT 1",
113 array($content['id']), __FILE__, __LINE__);
115 // Update, if applyable, referal count and points
116 if (($content['refid'] > 0) && ($content['refid'] != $content['id'])) {
117 // Update referal account
118 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_sponsor_data`
119 SET points_amount=points_amount+%s, ref_count=ref_count+1
120 WHERE id='%s' LIMIT 1",
121 array(getConfig('sponsor_ref_points'), bigintval($content['refid'])), __FILE__, __LINE__);
123 // Whas that update fine?
124 if (SQL_AFFECTEDROWS() == 1) {
125 // Load referal's data
126 $result = SQL_QUERY_ESC("SELECT id, gender, surname, family, email,
127 (points_amount - points_used) AS points, receive_warnings, ref_count AS refs
128 FROM `{!_MYSQL_PREFIX!}_sponsor_data`
129 WHERE id='%s' LIMIT 1",
130 array(bigintval($content['refid'])), __FILE__, __LINE__);
131 $REFERRAL = SQL_FETCHARRAY($result);
133 // Send warnings out?
134 if ($REFERRAL['receive_warnings'] == "Y") {
135 // Translate some data
136 $REFERRAL['points'] = TRANSLATE_COMMA($REFERRAL['points']);
137 $REFERRAL['ref_points'] = TRANSLATE_COMMA(getConfig('sponsor_ref_points'));
138 $REFERRAL['gender'] = TRANSLATE_GENDER($REFERRAL['gender']);
140 // Send notification to referal
141 $REF_MSG = LOAD_EMAIL_TEMPLATE("sponsor_ref_notify", $REFERRAL);
142 SEND_EMAIL($REFERRAL['email'], getMessage('SPONSOR_REF_NOTIFY_SUBJ'), $REF_MSG);
146 SQL_FREERESULT($result);
150 // Transfer data to array
151 $content['gender'] = TRANSLATE_GENDER($content['gender']);
152 $content['sponsor'] = $content['id'];
153 $content['points'] = TRANSLATE_COMMA($content['points_amount']);
155 // So let's send the email away
156 $msg = LOAD_EMAIL_TEMPLATE("sponsor_unlocked", $content);
157 SEND_EMAIL($content['email'], getMessage('SPONSOR_UNLOCKED_SUBJ'), $msg);
161 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_SPONSOR_NONE_SELECTED_UNLOCK'));
165 OUTPUT_HTML("<br />");
168 // Begin listing of all pending sponsor accounts
169 $result = SQL_QUERY("SELECT
170 id, gender, surname, family, email, remote_addr, sponsor_created
172 `{!_MYSQL_PREFIX!}_sponsor_data`
176 `id`", __FILE__, __LINE__);
178 if (SQL_NUMROWS($result) > 0) {
179 // Entries found so let's list them!
181 while ($content = SQL_FETCHARRAY($result)) {
182 // Transfer data to array
183 // @TODO Rewritings: remote->remote_addr, created->sponsor_created in template
186 'id' => $content['id'],
187 'gender' => TRANSLATE_GENDER($content['gender']),
188 'surname' => $content['surname'],
189 'family' => $content['family'],
190 'email' => "mailto:".$content['email'],
191 'remote' => $content['remote_addr'],
192 'created' => MAKE_DATETIME($content['sponsor_created'], "2"),
195 // Load row template and switch colors
196 $OUT .= LOAD_TEMPLATE("admin_unlock_sponsor_row", true, $content);
199 define('__SPONSOR_ROWS', $OUT);
202 LOAD_TEMPLATE("admin_unlock_sponsor");
204 // No pending accounts found
205 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_SPONSOR_NONE_PENDING'));
209 SQL_FREERESULT($result);