]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-unlock_sponsor.php
A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
42
43 // Check if admin has submitted form
44 if (IS_FORM_SENT()) {
45         // Does he have selected at least one sponsor?
46         if (SELECTION_COUNT(REQUEST_POST('id')) > 0) {
47                 // At least one entry selected
48                 foreach (REQUEST_POST('id') as $id => $selected) {
49                         // Secure ID number and init $content
50                         $content = array(
51                                 'id'    => bigintval($id),
52                                 'refid' => 0
53                         );
54
55                         // Load his personal data
56                         $result_main = SQL_QUERY_ESC("SELECT gender, surname, family, email, remote_addr, sponsor_created, points_amount, refid
57 FROM `{!_MYSQL_PREFIX!}_sponsor_data`
58 WHERE `status`='PENDING' AND id='%s' LIMIT 1",
59                                 array($content['id']), __FILE__, __LINE__);
60
61                         if (SQL_NUMROWS($result_main) == 1) {
62                                 // Load data
63                                 $content = SQL_FETCHROW($result_main);
64
65                                 // Check for open payments and close them
66                                 $result = SQL_QUERY_ESC("SELECT DISTINCT so.aid, so.pay_count, so.pay_ordered, so.pay_status,
67 sp.pay_name, sp.pay_rate, sp.pay_currency
68 FROM `{!_MYSQL_PREFIX!}_sponsor_orders` AS so
69 LEFT JOIN `{!_MYSQL_PREFIX!}_sponsor_paytypes` AS sp
70 ON sp.id=so.payid
71 WHERE so.sponsorid='%s'
72 ORDER BY sp.pay_name",
73                                         array($content['id']), __FILE__, __LINE__);
74                                 if (SQL_NUMROWS($result) > 0) {
75                                         // Payment does exist
76                                         while ($content2 = SQL_FETCHARRAY($result)) {
77                                                 // Merge both arrays
78                                                 $content = merge_array($content, $content2);
79
80                                                 // Set default email
81                                                 $content['email'] = getMessage('SPONSOR_NO_ADMIN');
82                                                 if ($content['aid'] > "0") {
83                                                         // Load admin's email address for contact
84                                                         $content['email'] = GET_ADMIN_EMAIL($content['aid']);
85                                                 } // END - if
86
87                                                 // Transfer data to array
88                                                 $data = array(
89                                                         'aid'   => $content['email'],
90                                                         'order' => ($content['pay_count'] * $content['pay_rate'])." ".$content['pay_currency'],
91                                                         'stamp' => MAKE_DATETIME($content['pay_ordered'], "2"),
92                                                         'pname' => $content['pay_name'],
93                                                 );
94         
95                                                 // Load email template
96                                                 $content['msg'] = LOAD_EMAIL_TEMPLATE("sponsor_unlock_sponsor_pay", $data, $content['id']);
97                                         }
98                                 } else {
99                                         // No payments found
100                                         $content['msg'] = getMessage('SPONSOR_NO_PAYMENTS_FOUND');
101                                 }
102
103                                 // Free memory
104                                 SQL_FREERESULT($result);
105                         }
106
107                         // Free memory
108                         SQL_FREERESULT($result_main);
109
110                         // Unlock sponsor account
111                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_sponsor_data` SET `status`='CONFIRMED'
112 WHERE id='%s' AND `status`='PENDING' LIMIT 1",
113                                 array($content['id']), __FILE__, __LINE__);
114
115                         // Update, if applyable, referal count and points
116                         if (($content['refid'] > 0) && ($content['refid'] != $content['id'])) {
117                                 // Update referal account
118                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_sponsor_data`
119 SET points_amount=points_amount+%s, ref_count=ref_count+1
120 WHERE id='%s' LIMIT 1",
121                                         array(getConfig('sponsor_ref_points'), bigintval($content['refid'])), __FILE__, __LINE__);
122
123                                 // Whas that update fine?
124                                 if (SQL_AFFECTEDROWS() == 1) {
125                                         // Load referal's data
126                                         $result = SQL_QUERY_ESC("SELECT id, gender, surname, family, email,
127 (points_amount - points_used) AS points, receive_warnings, ref_count AS refs
128 FROM `{!_MYSQL_PREFIX!}_sponsor_data`
129 WHERE id='%s' LIMIT 1",
130                                                 array(bigintval($content['refid'])), __FILE__, __LINE__);
131                                         $REFERRAL = SQL_FETCHARRAY($result);
132
133                                         // Send warnings out?
134                                         if ($REFERRAL['receive_warnings'] == "Y") {
135                                                 // Translate some data
136                                                 $REFERRAL['points']     = TRANSLATE_COMMA($REFERRAL['points']);
137                                                 $REFERRAL['ref_points'] = TRANSLATE_COMMA(getConfig('sponsor_ref_points'));
138                                                 $REFERRAL['gender']     = TRANSLATE_GENDER($REFERRAL['gender']);
139
140                                                 // Send notification to referal
141                                                 $REF_MSG = LOAD_EMAIL_TEMPLATE("sponsor_ref_notify", $REFERRAL);
142                                                 SEND_EMAIL($REFERRAL['email'], getMessage('SPONSOR_REF_NOTIFY_SUBJ'), $REF_MSG);
143                                         }
144
145                                         // Free memory
146                                         SQL_FREERESULT($result);
147                                 }
148                         }
149
150                         // Transfer data to array
151                         $content['gender']   = TRANSLATE_GENDER($content['gender']);
152                         $content['sponsor']  = $content['id'];
153                         $content['points']   = TRANSLATE_COMMA($content['points_amount']);
154
155                         // So let's send the email away
156                         $msg = LOAD_EMAIL_TEMPLATE("sponsor_unlocked", $content);
157                         SEND_EMAIL($content['email'], getMessage('SPONSOR_UNLOCKED_SUBJ'), $msg);
158                 }
159         } else {
160                 // Nothing selected
161                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_SPONSOR_NONE_SELECTED_UNLOCK'));
162         }
163
164         // Add seperator
165         OUTPUT_HTML("<br />");
166 }
167
168 // Begin listing of all pending sponsor accounts
169 $result = SQL_QUERY("SELECT
170         id, gender, surname, family, email, remote_addr, sponsor_created
171 FROM
172         `{!_MYSQL_PREFIX!}_sponsor_data`
173 WHERE
174         `status`='PENDING'
175 ORDER BY
176         `id`", __FILE__, __LINE__);
177
178 if (SQL_NUMROWS($result) > 0) {
179         // Entries found so let's list them!
180         $OUT = ""; $SW = 2;
181         while ($content = SQL_FETCHARRAY($result)) {
182                 // Transfer data to array
183                 // @TODO Rewritings: remote->remote_addr, created->sponsor_created in template
184                 $content = array(
185                         'sw'      => $SW,
186                         'id'      => $content['id'],
187                         'gender'   => TRANSLATE_GENDER($content['gender']),
188                         'surname' => $content['surname'],
189                         'family'  => $content['family'],
190                         'email'   => "mailto:".$content['email'],
191                         'remote'  => $content['remote_addr'],
192                         'created' => MAKE_DATETIME($content['sponsor_created'], "2"),
193                 );
194
195                 // Load row template and switch colors
196                 $OUT .= LOAD_TEMPLATE("admin_unlock_sponsor_row", true, $content);
197                 $SW = 3 - $SW;
198         }
199         define('__SPONSOR_ROWS', $OUT);
200
201         // Load template
202         LOAD_TEMPLATE("admin_unlock_sponsor");
203 } else {
204         // No pending accounts found
205         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_SPONSOR_NONE_PENDING'));
206 }
207
208 // Free memory
209 SQL_FREERESULT($result);
210
211 //
212 ?>