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 * 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 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
48 // Check if admin has submitted form
50 // Does he have selected at least one sponsor?
51 if (ifPostContainsSelections('id')) {
52 // At least one entry selected
53 foreach (postRequestParameter('id') as $id => $selected) {
54 // Secure id number and init $content
56 'id' => bigintval($id),
60 // Load his personal data
61 $result_main = SQL_QUERY_ESC("SELECT
62 `id`, `gender`, `surname`, `family`, `email`, `remote_addr`, `sponsor_created`, `points_amount`, `points_used`, `refid`
64 `{?_MYSQL_PREFIX?}_sponsor_data`
66 `status` IN('PENDING','UNCONFIRMED') AND
69 array($content['id']), __FILE__, __LINE__);
71 /// Is there an entry?
72 if (SQL_NUMROWS($result_main) == 1) {
74 $content = SQL_FETCHARRAY($result_main);
77 $content['points'] = ($content['points_amount'] - $content['points_used']);
79 // Check for open payments and close them
80 $result = SQL_QUERY_ESC("SELECT
81 so.admin_id, so.pay_count, so.pay_ordered, so.pay_status,
82 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 ($content['admin_id'] > 0) {
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 loadTemplate('admin_settings_saved', false, getMaskedMessage('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, referal count and points
146 if ((isValidUserId($content['refid'])) && ($content['refid'] != $content['id'])) {
147 // Update referal account
148 SQL_QUERY_ESC("UPDATE
149 `{?_MYSQL_PREFIX?}_sponsor_data`
151 `points_amount`=`points_amount`+{?sponsor_ref_points?}, `ref_count`=`ref_count`+1
155 array(bigintval($content['refid'])), __FILE__, __LINE__);
157 // Whas that update fine?
158 if (SQL_AFFECTEDROWS() == 1) {
159 // Load referal's data
160 $result = SQL_QUERY_ESC("SELECT
161 `id`, `gender`, `surname`, `family`, `email`,
162 (`points_amount` - `points_used`) AS points,
163 `receive_warnings`, `ref_count` AS refs
165 `{?_MYSQL_PREFIX?}_sponsor_data`
169 array(bigintval($content['refid'])), __FILE__, __LINE__);
170 $REFERAL = SQL_FETCHARRAY($result);
172 // Send warnings out?
173 if ($REFERAL['receive_warnings'] == 'Y') {
174 // Send notification to referal
175 $REFERAL_MSG = loadEmailTemplate('sponsor_ref_notify', $REFERAL);
176 sendEmail($REFERAL['email'], '{--SPONSOR_REFERAL_NOTIFY_SUBJECT--}', $REFERAL_MSG);
180 SQL_FREERESULT($result);
184 // So let's send the email away
185 $message = loadEmailTemplate('sponsor_unlocked', $content);
186 sendEmail($content['email'], '{--SPONSOR_UNLOCKED_SUBJECT--}', $message);
190 loadTemplate('admin_settings_saved', false, '{--ADMIN_SPONSOR_NONE_SELECTED_UNLOCK--}');
194 // Begin listing of all pending sponsor accounts
195 $result = SQL_QUERY("SELECT
196 `id`, `gender`, `surname`, `family`, `email`, `remote_addr`, `sponsor_created`
198 `{?_MYSQL_PREFIX?}_sponsor_data`
200 `status` IN('PENDING','UNCONFIRMED')
202 `id`", __FILE__, __LINE__);
204 if (!SQL_HASZERONUMS($result)) {
205 // Entries found so let's list them!
207 while ($content = SQL_FETCHARRAY($result)) {
208 // Translate some data
209 $content['sponsor_created'] = generateDateTime($content['sponsor_created'], 2);
211 // Load row template and switch colors
212 $OUT .= loadTemplate('admin_unlock_sponsor_row', true, $content);
216 loadTemplate('admin_unlock_sponsor', false, $OUT);
218 // No pending accounts found
219 loadTemplate('admin_settings_saved', false, '{--ADMIN_SPONSOR_NONE_PENDING--}');
223 SQL_FREERESULT($result);