]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-unlock_sponsor.php
The yearly copyright-update commit. 2009, 2010 are now copyrighted on the developer...
[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 }
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 (countSelection(postRequestParameter('id')) > 0) {
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 gender, surname, family, email, remote_addr, sponsor_created, points_amount, refid
62 FROM `{?_MYSQL_PREFIX?}_sponsor_data`
63 WHERE `status`='PENDING' AND id='%s' LIMIT 1",
64                         array($content['id']), __FILE__, __LINE__);
65
66                         if (SQL_NUMROWS($result_main) == 1) {
67                                 // Load data
68                                 $content = SQL_FETCHARRAY($result_main);
69
70                                 // Check for open payments and close them
71                                 $result = SQL_QUERY_ESC("SELECT so.admin_id, so.pay_count, so.pay_ordered, so.pay_status,
72 sp.pay_name, sp.pay_rate, sp.pay_currency
73 FROM `{?_MYSQL_PREFIX?}_sponsor_orders` AS so
74 LEFT JOIN `{?_MYSQL_PREFIX?}_sponsor_paytypes` AS sp
75 ON sp.id=so.payid
76 WHERE so.sponsorid='%s'
77 ORDER BY sp.pay_name",
78                                 array($content['id']), __FILE__, __LINE__);
79                                 if (SQL_NUMROWS($result) > 0) {
80                                         // Payment does exist
81                                         while ($content2 = SQL_FETCHARRAY($result)) {
82                                                 // Merge both arrays
83                                                 $content = merge_array($content, $content2);
84
85                                                 // Set default email
86                                                 $content['email'] = getMessage('SPONSOR_NO_ADMIN');
87                                                 if ($content['admin_id'] > 0) {
88                                                         // Load admin's email address for contact
89                                                         $content['email'] = getAdminEmail($content['admin_id']);
90                                                 } // END - if
91
92                                                 // Transfer data to array
93                                                 $data = array(
94                                                         'admin_id'   => $content['email'],
95                                                         'order' => ($content['pay_count'] * $content['pay_rate']) . ' ' . $content['pay_currency'],
96                                                         'stamp' => generateDateTime($content['pay_ordered'], 2),
97                                                         'pname' => $content['pay_name'],
98                                                 );
99
100                                                 // Load email template
101                                                 $content['message'] = loadEmailTemplate('sponsor_unlock_sponsor_pay', $data, $content['id']);
102                                         }
103                                 } else {
104                                         // No payments found
105                                         $content['message'] = getMessage('SPONSOR_NO_PAYMENTS_FOUND');
106                                 }
107
108                                 // Free memory
109                                 SQL_FREERESULT($result);
110                         }
111
112                         // Free memory
113                         SQL_FREERESULT($result_main);
114
115                         // Unlock sponsor account
116                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_sponsor_data` SET `status`='CONFIRMED'
117 WHERE `id`='%s' AND `status`='PENDING' LIMIT 1",
118                         array($content['id']), __FILE__, __LINE__);
119
120                         // Update, if applyable, referal count and points
121                         if (($content['refid'] > 0) && ($content['refid'] != $content['id'])) {
122                                 // Update referal account
123                                 SQL_QUERY_ESC("UPDATE
124         `{?_MYSQL_PREFIX?}_sponsor_data`
125 SET
126         `points_amount`=`points_amount`+{?sponsor_ref_points?}, `ref_count`=`ref_count`+1
127 WHERE
128         `id`='%s'
129 LIMIT 1",
130                                         array(bigintval($content['refid'])), __FILE__, __LINE__);
131
132                                 // Whas that update fine?
133                                 if (SQL_AFFECTEDROWS() == 1) {
134                                         // Load referal's data
135                                         $result = SQL_QUERY_ESC("SELECT id, gender, surname, family, email,
136 (points_amount - points_used) AS points, receive_warnings, ref_count AS refs
137 FROM `{?_MYSQL_PREFIX?}_sponsor_data`
138 WHERE `id`='%s' LIMIT 1",
139                                         array(bigintval($content['refid'])), __FILE__, __LINE__);
140                                         $REFERAL = SQL_FETCHARRAY($result);
141
142                                         // Send warnings out?
143                                         if ($REFERAL['receive_warnings'] == 'Y') {
144                                                 // Translate some data
145                                                 $REFERAL['points']     = translateComma($REFERAL['points']);
146                                                 $REFERAL['ref_points'] = translateComma(getConfig('sponsor_ref_points'));
147                                                 $REFERAL['gender']     = translateGender($REFERAL['gender']);
148
149                                                 // Send notification to referal
150                                                 $REF_MSG = loadEmailTemplate('sponsor_ref_notify', $REFERAL);
151                                                 sendEmail($REFERAL['email'], getMessage('SPONSOR_REF_NOTIFY_SUBJ'), $REF_MSG);
152                                         }
153
154                                         // Free memory
155                                         SQL_FREERESULT($result);
156                                 }
157                         }
158
159                         // Transfer data to array
160                         $content['gender']   = translateGender($content['gender']);
161                         $content['sponsor']  = $content['id'];
162                         $content['points']   = translateComma($content['points_amount']);
163
164                         // So let's send the email away
165                         $message = loadEmailTemplate('sponsor_unlocked', $content);
166                         sendEmail($content['email'], getMessage('SPONSOR_UNLOCKED_SUBJ'), $message);
167                 }
168         } else {
169                 // Nothing selected
170                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_SPONSOR_NONE_SELECTED_UNLOCK'));
171         }
172
173         // Add seperator
174         outputHtml('<br />');
175 }
176
177 // Begin listing of all pending sponsor accounts
178 $result = SQL_QUERY("SELECT
179         `id`, `gender`, `surname`, `family`, `email`, `remote_addr`, `sponsor_created`
180 FROM
181         `{?_MYSQL_PREFIX?}_sponsor_data`
182 WHERE
183         `status`='PENDING'
184 ORDER BY
185         `id`", __FILE__, __LINE__);
186
187 if (SQL_NUMROWS($result) > 0) {
188         // Entries found so let's list them!
189         $OUT = ''; $SW = 2;
190         while ($content = SQL_FETCHARRAY($result)) {
191                 // Transfer data to array
192                 // @TODO Rewritings: remote->remote_addr, created->sponsor_created in template
193                 $content = array(
194                         'sw'      => $SW,
195                         'id'      => $content['id'],
196                         'gender'   => translateGender($content['gender']),
197                         'surname' => $content['surname'],
198                         'family'  => $content['family'],
199                         'email'   => generateEmailLink($content['email'], 'sponsor_data'),
200                         'remote'  => $content['remote_addr'],
201                         'created' => generateDateTime($content['sponsor_created'], 2),
202                 );
203
204                 // Load row template and switch colors
205                 $OUT .= loadTemplate('admin_unlock_sponsor_row', true, $content);
206                 $SW = 3 - $SW;
207         }
208
209         // Load template
210         loadTemplate('admin_unlock_sponsor', false, $OUT);
211 } else {
212         // No pending accounts found
213         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_SPONSOR_NONE_PENDING'));
214 }
215
216 // Free memory
217 SQL_FREERESULT($result);
218
219 // [EOF]
220 ?>