2 /************************************************************************
3 * MXChange v0.2.1 Start: 04/23/2005 *
4 * =============== Last change: 05/18/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. *
22 * This program is distributed in the hope that it will be useful, *
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
25 * GNU General Public License for more details. *
27 * You should have received a copy of the GNU General Public License *
28 * along with this program; if not, write to the Free Software *
29 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
31 ************************************************************************/
33 // Some security stuff...
34 if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!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", basename(__FILE__));
43 // Check if admin has submitted form
44 if (isset($HTTP_POST_VARS['ok']))
46 // Does he have selected at least one sponsor?
47 if (SELECTION_COUNT($HTTP_POST_VARS['id']) > 0)
49 // At least one entry selected
50 foreach ($HTTP_POST_VARS['id'] as $id=>$sel)
52 // Load his personal data
53 $result_main = SQL_QUERY_ESC("SELECT salut, 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(bigintval($id)), __FILE__, __LINE__);
58 if (SQL_NUMROWS($result_main) == 1)
60 // Load data and free memory
61 list($salut, $sname, $fname, $email, $ip, $created, $points, $refid) = SQL_FETCHROW($result_main);
63 // Check for open payments and close them
64 $result = SQL_QUERY_ESC("SELECT DISTINCT so.aid, so.pay_count, so.pay_ordered, so.pay_status,
65 sp.pay_name, sp.pay_rate, sp.pay_currency
66 FROM "._MYSQL_PREFIX."_sponsor_orders AS so
67 LEFT JOIN "._MYSQL_PREFIX."_sponsor_paytypes AS sp
69 WHERE so.sponsorid='%s'
70 ORDER BY sp.pay_name",
71 array(bigintval($id)), __FILE__, __LINE__);
72 if (SQL_NUMROWS($result) > 0)
75 while(list($aid, $count, $ordered, $status, $pname, $prate, $pcurr) = SQL_FETCHROW($result))
80 $aid = SPONSOR_NO_ADMIN;
84 // Load admin's email address for contact
85 $result_aid = SQL_QUERY_ESC("SELECT email FROM "._MYSQL_PREFIX."_admins WHERE id='%s' LIMIT 1",
86 array(bigintval($aid)), __FILE__, __LINE__);
87 list($aid) = SQL_FETCHROW($result_aid);
88 SQL_FREERESULT($result_aid);
90 // Check if admin login is still in db
91 if (empty($aid)) $aid = ADMIN_NOT_FOUND;
94 // Transfer data to array
97 'order' => ($count * $prate)." ".$pcurr,
98 'stamp' => MAKE_DATETIME($ordered, "2"),
102 // Load email template
103 $content['msg'] = LOAD_EMAIL_TEMPLATE("sponsor_unlock_sponsor_pay", $content, $id);
109 $content['msg'] = SPONSOR_NO_PAYMENTS_FOUND;
113 SQL_FREERESULT($result);
117 SQL_FREERESULT($result_main);
119 // Unlock sponsor account
120 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_sponsor_data SET status='CONFIRMED'
121 WHERE id='%s' AND status='PENDING' LIMIT 1",
122 array(bigintval($id)), __FILE__, __LINE__);
124 // Update, if applyable, referral count and points
125 if (($refid > 0) && ($refid != $id))
127 // Update referral account
128 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_sponsor_data
129 SET points_amount=points_amount+%s, ref_count=ref_count+1
130 WHERE id='%s' LIMIT 1",
131 array($CONFIG['sponsor_ref_points'], bigintval($refid)), __FILE__, __LINE__);
133 // Load referral's data
134 if (SQL_AFFECTED_ROWS($link) == 1)
136 $result = SQL_QUERY_ESC("SELECT id, salut, surname, family, email,
137 (points_amount - points_used) AS points, receive_warnings, ref_count AS refs
138 FROM "._MYSQL_PREFIX."_sponsor_data
139 WHERE id='%s' LIMIT 1",
140 array(bigintval($refid)), __FILE__, __LINE__);
141 $REFERRAL = SQL_FETCHARRAY($result);
142 if ($REFERRAL['receive_warnings'] == "Y")
144 // Translate some data
145 $REFERRAL['points'] = TRANSLATE_COMMA($REFERRAL['points']);
146 $REFERRAL['ref_points'] = TRANSLATE_COMMA($CONFIG['sponsor_ref_points']);
147 $REFERRAL['salut'] = TRANSLATE_SEX($REFERRAL['salut']);
149 // Send notification to referral
150 $REF_MSG = LOAD_EMAIL_TEMPLATE("sponsor_ref_notify", $REFERRAL);
151 SEND_EMAIL($REFERRAL['email'], SPONSOR_REF_NOTIFY_SUBJ, $REF_MSG);
155 SQL_FREERESULT($result);
159 // Transfer data to array
160 $content['salut'] = TRANSLATE_SEX($salut);
161 $content['surname'] = $sname;
162 $content['family'] = $fname;
163 $content['sponsor'] = $id;
164 $content['points'] = TRANSLATE_COMMA($points);
166 // So let's send the email away
167 $msg = LOAD_EMAIL_TEMPLATE("sponsor_unlocked", $content);
168 SEND_EMAIL($email, SPONSOR_UNLOCKED_SUBJ, $msg);
174 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SPONSOR_NONE_SELECTED_UNLOCK);
181 // Begin listing of all pending sponsor accounts
182 $result = SQL_QUERY("SELECT id, salut, surname, family, email, remote_addr, sponsor_created
183 FROM "._MYSQL_PREFIX."_sponsor_data
184 WHERE status='PENDING' ORDER BY id", __FILE__, __LINE__);
186 if (SQL_NUMROWS($result) > 0)
188 // Entries found so let's list them!
190 while(list($id, $salut, $sname, $fname, $email, $ip, $created) = SQL_FETCHROW($result))
192 // Transfer data to array
196 'salut' => TRANSLATE_SEX($salut),
199 'email' => "mailto:".$email,
201 'created' => MAKE_DATETIME($created, "2"),
204 // Load row template and switch colors
205 $OUT .= LOAD_TEMPLATE("admin_unlock_sponsor_row", true, $content);
208 define('__SPONSOR_ROWS', $OUT);
211 LOAD_TEMPLATE("admin_unlock_sponsor");
215 // No pending accounts found
216 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SPONSOR_NONE_PENDING);
220 SQL_FREERESULT($result);