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 ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!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 salut, 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($salut, $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 $result_aid = SQL_QUERY_ESC("SELECT email FROM "._MYSQL_PREFIX."_admins WHERE id='%s' LIMIT 1",
70 array(bigintval($aid)), __FILE__, __LINE__);
71 list($aid) = SQL_FETCHROW($result_aid);
72 SQL_FREERESULT($result_aid);
74 // Check if admin login is still in db
75 if (empty($aid)) $aid = ADMIN_NOT_FOUND;
78 // Transfer data to array
81 'order' => ($count * $prate)." ".$pcurr,
82 'stamp' => MAKE_DATETIME($ordered, "2"),
86 // Load email template
87 $content['msg'] = LOAD_EMAIL_TEMPLATE("sponsor_unlock_sponsor_pay", $content, $id);
91 $content['msg'] = SPONSOR_NO_PAYMENTS_FOUND;
95 SQL_FREERESULT($result);
99 SQL_FREERESULT($result_main);
101 // Unlock sponsor account
102 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_sponsor_data SET status='CONFIRMED'
103 WHERE id='%s' AND status='PENDING' LIMIT 1",
104 array($id), __FILE__, __LINE__);
106 // Update, if applyable, referral count and points
107 if (($refid > 0) && ($refid != $id)) {
108 // Update referral account
109 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_sponsor_data
110 SET points_amount=points_amount+%s, ref_count=ref_count+1
111 WHERE id='%s' LIMIT 1",
112 array($CONFIG['sponsor_ref_points'], bigintval($refid)), __FILE__, __LINE__);
114 // Whas that update fine?
115 if (SQL_AFFECTED_ROWS($link) == 1) {
116 // Load referral's data
117 $result = SQL_QUERY_ESC("SELECT id, salut, surname, family, email,
118 (points_amount - points_used) AS points, receive_warnings, ref_count AS refs
119 FROM "._MYSQL_PREFIX."_sponsor_data
120 WHERE id='%s' LIMIT 1",
121 array(bigintval($refid)), __FILE__, __LINE__);
122 $REFERRAL = SQL_FETCHARRAY($result);
124 // Send warnings out?
125 if ($REFERRAL['receive_warnings'] == "Y") {
126 // Translate some data
127 $REFERRAL['points'] = TRANSLATE_COMMA($REFERRAL['points']);
128 $REFERRAL['ref_points'] = TRANSLATE_COMMA($CONFIG['sponsor_ref_points']);
129 $REFERRAL['salut'] = TRANSLATE_SEX($REFERRAL['salut']);
131 // Send notification to referral
132 $REF_MSG = LOAD_EMAIL_TEMPLATE("sponsor_ref_notify", $REFERRAL);
133 SEND_EMAIL($REFERRAL['email'], SPONSOR_REF_NOTIFY_SUBJ, $REF_MSG);
137 SQL_FREERESULT($result);
141 // Transfer data to array
142 $content['salut'] = TRANSLATE_SEX($salut);
143 $content['surname'] = $sname;
144 $content['family'] = $fname;
145 $content['sponsor'] = $id;
146 $content['points'] = TRANSLATE_COMMA($points);
148 // So let's send the email away
149 $msg = LOAD_EMAIL_TEMPLATE("sponsor_unlocked", $content);
150 SEND_EMAIL($email, SPONSOR_UNLOCKED_SUBJ, $msg);
154 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SPONSOR_NONE_SELECTED_UNLOCK);
161 // Begin listing of all pending sponsor accounts
162 $result = SQL_QUERY("SELECT id, salut, surname, family, email, remote_addr, sponsor_created
163 FROM "._MYSQL_PREFIX."_sponsor_data
164 WHERE status='PENDING' ORDER BY id", __FILE__, __LINE__);
166 if (SQL_NUMROWS($result) > 0) {
167 // Entries found so let's list them!
169 while(list($id, $salut, $sname, $fname, $email, $ip, $created) = SQL_FETCHROW($result)) {
170 // Transfer data to array
174 'salut' => TRANSLATE_SEX($salut),
177 'email' => "mailto:".$email,
179 'created' => MAKE_DATETIME($created, "2"),
182 // Load row template and switch colors
183 $OUT .= LOAD_TEMPLATE("admin_unlock_sponsor_row", true, $content);
186 define('__SPONSOR_ROWS', $OUT);
189 LOAD_TEMPLATE("admin_unlock_sponsor");
191 // No pending accounts found
192 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SPONSOR_NONE_PENDING);
196 SQL_FREERESULT($result);