2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2012 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
46 // Check if admin has submitted form
48 // Does he have selected at least one sponsor?
49 if (ifPostContainsSelections('id')) {
50 // At least one entry selected
51 foreach (postRequestElement('id') as $id => $selected) {
52 // Secure id number and init $content
54 'id' => bigintval($id),
58 // Load his personal data
59 $result_main = SQL_QUERY_ESC("SELECT
60 `id`, `gender`, `surname`, `family`, `email`, `remote_addr`,
61 UNIX_TIMESTAMP(`sponsor_created`) AS `sponsor_created`,
62 `points_amount`, `points_used`,
63 (`points_amount` + `points_used`) AS `points`,
66 `{?_MYSQL_PREFIX?}_sponsor_data`
68 `status` IN('PENDING','UNCONFIRMED') AND
71 array($content['id']), __FILE__, __LINE__);
74 if (SQL_NUMROWS($result_main) == 1) {
76 $content = SQL_FETCHARRAY($result_main);
78 // Check for open payments and close them
79 $result = SQL_QUERY_ESC("SELECT
80 so.admin_id, so.pay_count,
81 UNIX_TIMESTAMP(so.pay_ordered) AS `pay_ordered`,
82 so.pay_status, sp.pay_name, sp.pay_rate, sp.pay_currency
84 `{?_MYSQL_PREFIX?}_sponsor_orders` AS so
86 `{?_MYSQL_PREFIX?}_sponsor_paytypes` AS sp
93 array($content['id']), __FILE__, __LINE__);
94 if (!SQL_HASZERONUMS($result)) {
96 while ($content2 = SQL_FETCHARRAY($result)) {
98 $content = merge_array($content, $content2);
101 $content['email'] = '{--SPONSOR_NO_ADMIN--}';
102 if (isValidUserId($content['admin_id'])) {
103 // Load admin's email address for contact
104 $content['email'] = getAdminEmail($content['admin_id']);
107 // Transfer data to array
109 'admin_id' => $content['email'],
110 'order' => ($content['pay_count'] * $content['pay_rate']) . ' ' . $content['pay_currency'],
111 'stamp' => generateDateTime($content['pay_ordered'], 2),
112 'pname' => $content['pay_name'],
115 // Load email template
116 $content['message'] = loadEmailTemplate('sponsor_unlock_sponsor_pay', $data, $content['id']);
120 $content['message'] = '{--SPONSOR_NO_PAYMENTS_FOUND--}';
124 SQL_FREERESULT($result);
127 displayMessage('{%message,ADMIN_SPONSOR_ACCOUNT_404_ALREADY_CONFIRMED=' . $content['id'] . '%}');
132 SQL_FREERESULT($result_main);
134 // Unlock sponsor account
135 SQL_QUERY_ESC("UPDATE
136 `{?_MYSQL_PREFIX?}_sponsor_data`
141 `status` IN('PENDING','UNCONFIRMED')
143 array($content['id']), __FILE__, __LINE__);
145 // Update, if applyable, referral count and points
146 if ((isValidUserId($content['refid'])) && ($content['refid'] != $content['id'])) {
147 // Update referral account
148 SQL_QUERY_ESC("UPDATE
149 `{?_MYSQL_PREFIX?}_sponsor_data`
151 `points_amount`=`points_amount`+{?sponsor_ref_points?},
152 `ref_count`=`ref_count`+1
156 array(bigintval($content['refid'])), __FILE__, __LINE__);
158 // Whas that update fine?
159 if (!SQL_HASZEROAFFECTED()) {
160 // Load referral's data
161 $result = SQL_QUERY_ESC("SELECT
167 (`points_amount` - `points_used`) AS `points`,
169 `ref_count` AS `refs`
171 `{?_MYSQL_PREFIX?}_sponsor_data`
175 array(bigintval($content['refid'])), __FILE__, __LINE__);
176 $REFERRAL = SQL_FETCHARRAY($result);
178 // Send warnings out?
179 if ($REFERRAL['receive_warnings'] == 'Y') {
180 // Send notification to referral
181 $REFERRAL_MSG = loadEmailTemplate('sponsor_ref_notify', $REFERRAL);
182 sendEmail($REFERRAL['email'], '{--SPONSOR_REFERRAL_NOTIFY_SUBJECT--}', $REFERRAL_MSG);
186 SQL_FREERESULT($result);
190 // So let's send the email away
191 $message = loadEmailTemplate('sponsor_unlocked', $content);
192 sendEmail($content['email'], '{--SPONSOR_UNLOCKED_SUBJECT--}', $message);
196 displayMessage('{--ADMIN_SPONSOR_NONE_SELECTED_UNLOCK--}');
200 // Begin listing of all pending sponsor accounts
201 $result = SQL_QUERY("SELECT
202 `id`, `gender`, `surname`, `family`, `email`, `remote_addr`,
203 UNIX_TIMESTAMP(`sponsor_created`) AS `sponsor_created`
205 `{?_MYSQL_PREFIX?}_sponsor_data`
207 `status` IN('PENDING','UNCONFIRMED')
209 `id`", __FILE__, __LINE__);
211 if (!SQL_HASZERONUMS($result)) {
212 // Entries found so let's list them!
214 while ($content = SQL_FETCHARRAY($result)) {
215 // Translate some data
216 $content['sponsor_created'] = generateDateTime($content['sponsor_created'], 2);
218 // Load row template and switch colors
219 $OUT .= loadTemplate('admin_unlock_sponsor_row', TRUE, $content);
223 loadTemplate('admin_unlock_sponsor', FALSE, $OUT);
225 // No pending accounts found
226 displayMessage('{--ADMIN_SPONSOR_NONE_PENDING--}');
230 SQL_FREERESULT($result);