]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-unlock_sponsor.php
bd1f77f5060c45d90c026fa18ea49201a11fbeb9
[mailer.git] / inc / modules / admin / what-unlock_sponsor.php
1 <?php
2 /************************************************************************
3  * M-XChange v0.2.1                                   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  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
41         die();
42 }
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
47 // Check if admin has submitted form
48 if (isFormSent()) {
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
54                         $content = array(
55                                 'id'    => bigintval($id),
56                                 'refid' => 0
57                         );
58
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__);
64
65                         if (SQL_NUMROWS($result_main) == 1) {
66                                 // Load data
67                                 $content = SQL_FETCHARRAY($result_main);
68
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
74 ON sp.id=so.payid
75 WHERE so.sponsorid='%s'
76 ORDER BY sp.pay_name",
77                                 array($content['id']), __FILE__, __LINE__);
78                                 if (SQL_NUMROWS($result) > 0) {
79                                         // Payment does exist
80                                         while ($content2 = SQL_FETCHARRAY($result)) {
81                                                 // Merge both arrays
82                                                 $content = merge_array($content, $content2);
83
84                                                 // Set default email
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']);
89                                                 } // END - if
90
91                                                 // Transfer data to array
92                                                 $data = 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'],
97                                                 );
98
99                                                 // Load email template
100                                                 $content['message'] = loadEmailTemplate('sponsor_unlock_sponsor_pay', $data, $content['id']);
101                                         }
102                                 } else {
103                                         // No payments found
104                                         $content['message'] = getMessage('SPONSOR_NO_PAYMENTS_FOUND');
105                                 }
106
107                                 // Free memory
108                                 SQL_FREERESULT($result);
109                         }
110
111                         // Free memory
112                         SQL_FREERESULT($result_main);
113
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__);
118
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`
124 SET
125         `points_amount`=`points_amount`+{?sponsor_ref_points?}, `ref_count`=`ref_count`+1
126 WHERE
127         `id`='%s'
128 LIMIT 1",
129                                         array(bigintval($content['refid'])), __FILE__, __LINE__);
130
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);
140
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']);
147
148                                                 // Send notification to referal
149                                                 $REF_MSG = loadEmailTemplate('sponsor_ref_notify', $REFERAL);
150                                                 sendEmail($REFERAL['email'], getMessage('SPONSOR_REF_NOTIFY_SUBJ'), $REF_MSG);
151                                         }
152
153                                         // Free memory
154                                         SQL_FREERESULT($result);
155                                 }
156                         }
157
158                         // Transfer data to array
159                         $content['gender']   = translateGender($content['gender']);
160                         $content['sponsor']  = $content['id'];
161                         $content['points']   = translateComma($content['points_amount']);
162
163                         // So let's send the email away
164                         $message = loadEmailTemplate('sponsor_unlocked', $content);
165                         sendEmail($content['email'], getMessage('SPONSOR_UNLOCKED_SUBJ'), $message);
166                 }
167         } else {
168                 // Nothing selected
169                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_SPONSOR_NONE_SELECTED_UNLOCK'));
170         }
171
172         // Add seperator
173         outputHtml('<br />');
174 }
175
176 // Begin listing of all pending sponsor accounts
177 $result = SQL_QUERY("SELECT
178         `id`, `gender`, `surname`, `family`, `email`, `remote_addr`, `sponsor_created`
179 FROM
180         `{?_MYSQL_PREFIX?}_sponsor_data`
181 WHERE
182         `status`='PENDING'
183 ORDER BY
184         `id`", __FILE__, __LINE__);
185
186 if (SQL_NUMROWS($result) > 0) {
187         // Entries found so let's list them!
188         $OUT = ''; $SW = 2;
189         while ($content = SQL_FETCHARRAY($result)) {
190                 // Transfer data to array
191                 // @TODO Rewritings: remote->remote_addr, created->sponsor_created in template
192                 $content = array(
193                         'sw'      => $SW,
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),
201                 );
202
203                 // Load row template and switch colors
204                 $OUT .= loadTemplate('admin_unlock_sponsor_row', true, $content);
205                 $SW = 3 - $SW;
206         }
207
208         // Load template
209         loadTemplate('admin_unlock_sponsor', false, $OUT);
210 } else {
211         // No pending accounts found
212         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_SPONSOR_NONE_PENDING'));
213 }
214
215 // Free memory
216 SQL_FREERESULT($result);
217
218 // [EOF]
219 ?>