]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-unlock_sponsor.php
Duplicate message id GUEST_GENDER removed, column type TIMESTAMP in ext-sponsor,
[mailer.git] / inc / modules / admin / what-unlock_sponsor.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 04/23/2005 *
4  * ===================                          Last change: 05/19/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-unlock_sponsor.php                          *
8  * -------------------------------------------------------------------- *
9  * Short description : Unlock sponsor accounts                          *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Sponsorenaccounts freigeben                      *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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                  *
23  *                                                                      *
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.                                  *
28  *                                                                      *
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.                         *
33  *                                                                      *
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,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 } // END - if
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
48 // Check if admin has submitted form
49 if (isFormSent()) {
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
55                         $content = array(
56                                 'id'    => bigintval($id),
57                                 'refid' => 0
58                         );
59
60                         // Load his personal data
61                         $result_main = SQL_QUERY_ESC("SELECT
62         `id`, `gender`, `surname`, `family`, `email`, `remote_addr`,
63         UNIX_TIMESTAMP(`sponsor_created`) AS `sponsor_created`,
64         `points_amount`, `points_used`, `refid`
65 FROM
66         `{?_MYSQL_PREFIX?}_sponsor_data`
67 WHERE
68         `status` IN('PENDING','UNCONFIRMED') AND
69         `id`=%s
70 LIMIT 1",
71                         array($content['id']), __FILE__, __LINE__);
72
73                         /// Is there an entry?
74                         if (SQL_NUMROWS($result_main) == 1) {
75                                 // Load data
76                                 $content = SQL_FETCHARRAY($result_main);
77
78                                 // Add total amount
79                                 $content['points'] = ($content['points_amount'] - $content['points_used']);
80
81                                 // Check for open payments and close them
82                                 $result = SQL_QUERY_ESC("SELECT
83         so.admin_id, so.pay_count,
84         UNIX_TIMESTAMP(so.pay_ordered) AS `pay_ordered`,
85         so.pay_status, sp.pay_name, sp.pay_rate, sp.pay_currency
86 FROM
87         `{?_MYSQL_PREFIX?}_sponsor_orders` AS so
88 LEFT JOIN
89         `{?_MYSQL_PREFIX?}_sponsor_paytypes` AS sp
90 ON
91         sp.id=so.payment_id
92 WHERE
93         so.sponsor_id=%s
94 ORDER BY
95         sp.pay_name ASC",
96                                         array($content['id']), __FILE__, __LINE__);
97                                 if (!SQL_HASZERONUMS($result)) {
98                                         // Payment does exist
99                                         while ($content2 = SQL_FETCHARRAY($result)) {
100                                                 // Merge both arrays
101                                                 $content = merge_array($content, $content2);
102
103                                                 // Set default email
104                                                 $content['email'] = '{--SPONSOR_NO_ADMIN--}';
105                                                 if ($content['admin_id'] > 0) {
106                                                         // Load admin's email address for contact
107                                                         $content['email'] = getAdminEmail($content['admin_id']);
108                                                 } // END - if
109
110                                                 // Transfer data to array
111                                                 $data = array(
112                                                         'admin_id' => $content['email'],
113                                                         'order'    => ($content['pay_count'] * $content['pay_rate']) . ' ' . $content['pay_currency'],
114                                                         'stamp'    => generateDateTime($content['pay_ordered'], 2),
115                                                         'pname'    => $content['pay_name'],
116                                                 );
117
118                                                 // Load email template
119                                                 $content['message'] = loadEmailTemplate('sponsor_unlock_sponsor_pay', $data, $content['id']);
120                                         }
121                                 } else {
122                                         // No payments found
123                                         $content['message'] = '{--SPONSOR_NO_PAYMENTS_FOUND--}';
124                                 }
125
126                                 // Free memory
127                                 SQL_FREERESULT($result);
128                         } else {
129                                 // Not found
130                                 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_SPONSOR_ACCOUNT_404_ALREADY_CONFIRMED', $content['id']));
131                                 return;
132                         }
133
134                         // Free memory
135                         SQL_FREERESULT($result_main);
136
137                         // Unlock sponsor account
138                         SQL_QUERY_ESC("UPDATE
139         `{?_MYSQL_PREFIX?}_sponsor_data`
140 SET
141         `status`='CONFIRMED'
142 WHERE
143         `id`=%s AND
144         `status` IN('PENDING','UNCONFIRMED')
145 LIMIT 1",
146                         array($content['id']), __FILE__, __LINE__);
147
148                         // Update, if applyable, referal count and points
149                         if ((isValidUserId($content['refid'])) && ($content['refid'] != $content['id'])) {
150                                 // Update referal account
151                                 SQL_QUERY_ESC("UPDATE
152         `{?_MYSQL_PREFIX?}_sponsor_data`
153 SET
154         `points_amount`=`points_amount`+{?sponsor_ref_points?}, `ref_count`=`ref_count`+1
155 WHERE
156         `id`=%s
157 LIMIT 1",
158                                         array(bigintval($content['refid'])), __FILE__, __LINE__);
159
160                                 // Whas that update fine?
161                                 if (SQL_AFFECTEDROWS() == 1) {
162                                         // Load referal's data
163                                         $result = SQL_QUERY_ESC("SELECT
164         `id`, `gender`, `surname`, `family`, `email`,
165         (`points_amount` - `points_used`) AS points,
166         `receive_warnings`, `ref_count` AS refs
167 FROM
168         `{?_MYSQL_PREFIX?}_sponsor_data`
169 WHERE
170         `id`=%s
171 LIMIT 1",
172                                         array(bigintval($content['refid'])), __FILE__, __LINE__);
173                                         $REFERAL = SQL_FETCHARRAY($result);
174
175                                         // Send warnings out?
176                                         if ($REFERAL['receive_warnings'] == 'Y') {
177                                                 // Send notification to referal
178                                                 $REFERAL_MSG = loadEmailTemplate('sponsor_ref_notify', $REFERAL);
179                                                 sendEmail($REFERAL['email'], '{--SPONSOR_REFERAL_NOTIFY_SUBJECT--}', $REFERAL_MSG);
180                                         } // END - if
181
182                                         // Free memory
183                                         SQL_FREERESULT($result);
184                                 } // END - if
185                         } // END - if
186
187                         // So let's send the email away
188                         $message = loadEmailTemplate('sponsor_unlocked', $content);
189                         sendEmail($content['email'], '{--SPONSOR_UNLOCKED_SUBJECT--}', $message);
190                 } // END - foreach
191         } else {
192                 // Nothing selected
193                 loadTemplate('admin_settings_saved', false, '{--ADMIN_SPONSOR_NONE_SELECTED_UNLOCK--}');
194         }
195 } // END - if
196
197 // Begin listing of all pending sponsor accounts
198 $result = SQL_QUERY("SELECT
199         `id`, `gender`, `surname`, `family`, `email`, `remote_addr`,
200         UNIX_TIMESTAMP(`sponsor_created`) AS `sponsor_created`
201 FROM
202         `{?_MYSQL_PREFIX?}_sponsor_data`
203 WHERE
204         `status` IN('PENDING','UNCONFIRMED')
205 ORDER BY
206         `id`", __FILE__, __LINE__);
207
208 if (!SQL_HASZERONUMS($result)) {
209         // Entries found so let's list them!
210         $OUT = '';
211         while ($content = SQL_FETCHARRAY($result)) {
212                 // Translate some data
213                 $content['sponsor_created'] = generateDateTime($content['sponsor_created'], 2);
214
215                 // Load row template and switch colors
216                 $OUT .= loadTemplate('admin_unlock_sponsor_row', true, $content);
217         } // END - while
218
219         // Load template
220         loadTemplate('admin_unlock_sponsor', false, $OUT);
221 } else {
222         // No pending accounts found
223         loadTemplate('admin_settings_saved', false, '{--ADMIN_SPONSOR_NONE_PENDING--}');
224 }
225
226 // Free memory
227 SQL_FREERESULT($result);
228
229 // [EOF]
230 ?>