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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
47 // Check if admin has submitted form
49 // Does he have selected at least one sponsor?
50 if (countSelection(postRequestElement('id')) > 0) {
51 // At least one entry selected
52 foreach (postRequestElement('id') as $id => $selected) {
53 // Secure id number and init $content
55 'id' => bigintval($id),
59 // Load his personal data
60 $result_main = SQL_QUERY_ESC("SELECT gender, surname, family, email, remote_addr, sponsor_created, points_amount, refid
61 FROM `{?_MYSQL_PREFIX?}_sponsor_data`
62 WHERE `status`='PENDING' AND id='%s' LIMIT 1",
63 array($content['id']), __FILE__, __LINE__);
65 if (SQL_NUMROWS($result_main) == 1) {
67 $content = SQL_FETCHARRAY($result_main);
69 // Check for open payments and close them
70 $result = SQL_QUERY_ESC("SELECT so.admin_id, so.pay_count, so.pay_ordered, so.pay_status,
71 sp.pay_name, sp.pay_rate, sp.pay_currency
72 FROM `{?_MYSQL_PREFIX?}_sponsor_orders` AS so
73 LEFT JOIN `{?_MYSQL_PREFIX?}_sponsor_paytypes` AS sp
75 WHERE so.sponsorid='%s'
76 ORDER BY sp.pay_name",
77 array($content['id']), __FILE__, __LINE__);
78 if (SQL_NUMROWS($result) > 0) {
80 while ($content2 = SQL_FETCHARRAY($result)) {
82 $content = merge_array($content, $content2);
85 $content['email'] = getMessage('SPONSOR_NO_ADMIN');
86 if ($content['admin_id'] > 0) {
87 // Load admin's email address for contact
88 $content['email'] = getAdminEmail($content['admin_id']);
91 // Transfer data to array
93 'admin_id' => $content['email'],
94 'order' => ($content['pay_count'] * $content['pay_rate'])." ".$content['pay_currency'],
95 'stamp' => generateDateTime($content['pay_ordered'], 2),
96 'pname' => $content['pay_name'],
99 // Load email template
100 $content['message'] = loadEmailTemplate('sponsor_unlock_sponsor_pay', $data, $content['id']);
104 $content['message'] = getMessage('SPONSOR_NO_PAYMENTS_FOUND');
108 SQL_FREERESULT($result);
112 SQL_FREERESULT($result_main);
114 // Unlock sponsor account
115 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_sponsor_data` SET `status`='CONFIRMED'
116 WHERE `id`='%s' AND `status`='PENDING' LIMIT 1",
117 array($content['id']), __FILE__, __LINE__);
119 // Update, if applyable, referal count and points
120 if (($content['refid'] > 0) && ($content['refid'] != $content['id'])) {
121 // Update referal account
122 SQL_QUERY_ESC("UPDATE
123 `{?_MYSQL_PREFIX?}_sponsor_data`
125 `points_amount`=`points_amount`+{?sponsor_ref_points?}, `ref_count`=`ref_count`+1
129 array(bigintval($content['refid'])), __FILE__, __LINE__);
131 // Whas that update fine?
132 if (SQL_AFFECTEDROWS() == 1) {
133 // Load referal's data
134 $result = SQL_QUERY_ESC("SELECT id, gender, surname, family, email,
135 (points_amount - points_used) AS points, receive_warnings, ref_count AS refs
136 FROM `{?_MYSQL_PREFIX?}_sponsor_data`
137 WHERE `id`='%s' LIMIT 1",
138 array(bigintval($content['refid'])), __FILE__, __LINE__);
139 $REFERAL = SQL_FETCHARRAY($result);
141 // Send warnings out?
142 if ($REFERAL['receive_warnings'] == 'Y') {
143 // Translate some data
144 $REFERAL['points'] = translateComma($REFERAL['points']);
145 $REFERAL['ref_points'] = translateComma(getConfig('sponsor_ref_points'));
146 $REFERAL['gender'] = translateGender($REFERAL['gender']);
148 // Send notification to referal
149 $REF_MSG = loadEmailTemplate('sponsor_ref_notify', $REFERAL);
150 sendEmail($REFERAL['email'], getMessage('SPONSOR_REF_NOTIFY_SUBJ'), $REF_MSG);
154 SQL_FREERESULT($result);
158 // Transfer data to array
159 $content['gender'] = translateGender($content['gender']);
160 $content['sponsor'] = $content['id'];
161 $content['points'] = translateComma($content['points_amount']);
163 // So let's send the email away
164 $message = loadEmailTemplate('sponsor_unlocked', $content);
165 sendEmail($content['email'], getMessage('SPONSOR_UNLOCKED_SUBJ'), $message);
169 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_SPONSOR_NONE_SELECTED_UNLOCK'));
173 outputHtml('<br />');
176 // Begin listing of all pending sponsor accounts
177 $result = SQL_QUERY("SELECT
178 `id`, `gender`, `surname`, `family`, `email`, `remote_addr`, `sponsor_created`
180 `{?_MYSQL_PREFIX?}_sponsor_data`
184 `id`", __FILE__, __LINE__);
186 if (SQL_NUMROWS($result) > 0) {
187 // Entries found so let's list them!
189 while ($content = SQL_FETCHARRAY($result)) {
190 // Transfer data to array
191 // @TODO Rewritings: remote->remote_addr, created->sponsor_created in template
194 'id' => $content['id'],
195 'gender' => translateGender($content['gender']),
196 'surname' => $content['surname'],
197 'family' => $content['family'],
198 'email' => generateEmailLink($content['email'], 'sponsor_data'),
199 'remote' => $content['remote_addr'],
200 'created' => generateDateTime($content['sponsor_created'], 2),
203 // Load row template and switch colors
204 $OUT .= loadTemplate('admin_unlock_sponsor_row', true, $content);
209 loadTemplate('admin_unlock_sponsor', false, $OUT);
211 // No pending accounts found
212 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_SPONSOR_NONE_PENDING'));
216 SQL_FREERESULT($result);