]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-unlock_sponsor.php
0aaba4551f2699f43b469ed3efe16bacfb73b9a8
[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 (isset($_POST['ok'])) {
45         // Does he have selected at least one sponsor?
46         if (SELECTION_COUNT($_POST['id']) > 0) {
47                 // At least one entry selected
48                 foreach ($_POST['id'] as $id => $sel) {
49                         // Secure ID number
50                         $id = bigintval($id);
51
52                         // Load his personal data
53                         $result_main = SQL_QUERY_ESC("SELECT gender, surname, family, email, remote_addr, sponsor_created, points_amount, refid
54 FROM "._MYSQL_PREFIX."_sponsor_data
55 WHERE status='PENDING' AND id='%s' LIMIT 1",
56  array($id), __FILE__, __LINE__);
57                         $refid = 0;
58                         if (SQL_NUMROWS($result_main) == 1) {
59                                 // Load data and free memory
60                                 list($gender, $sname, $fname, $email, $ip, $created, $points, $refid) = SQL_FETCHROW($result_main);
61
62                                 // Check for open payments and close them
63                                 $result = SQL_QUERY_ESC("SELECT DISTINCT so.aid, so.pay_count, so.pay_ordered, so.pay_status,
64 sp.pay_name, sp.pay_rate, sp.pay_currency
65 FROM "._MYSQL_PREFIX."_sponsor_orders AS so
66 LEFT JOIN "._MYSQL_PREFIX."_sponsor_paytypes AS sp
67 ON sp.id=so.payid
68 WHERE so.sponsorid='%s'
69 ORDER BY sp.pay_name",
70  array($id), __FILE__, __LINE__);
71                                 if (SQL_NUMROWS($result) > 0) {
72                                         // Payment does exist
73                                         while(list($aid, $count, $ordered, $status, $pname, $prate, $pcurr) = SQL_FETCHROW($result))
74                                         {
75                                                 if ($aid == "0") {
76                                                         // No admin assigned!
77                                                         $aid = SPONSOR_NO_ADMIN;
78                                                 } else {
79                                                         // Load admin's email address for contact
80                                                         $aid = GET_ADMIN_EMAIL(GET_ADMIN_LOGIN(($aid));
81                                                 }
82
83                                                 // Transfer data to array
84                                                 $content = array(
85                                                         'aid'   => $aid,
86                                                         'order' => ($count * $prate)." ".$pcurr,
87                                                         'stamp' => MAKE_DATETIME($ordered, "2"),
88                                                         'pname' => $pname,
89                                                 );
90         
91                                                 // Load email template
92                                                 $content['msg'] = LOAD_EMAIL_TEMPLATE("sponsor_unlock_sponsor_pay", $content, $id);
93                                         }
94                                 } else {
95                                         // No payments found
96                                         $content['msg'] = SPONSOR_NO_PAYMENTS_FOUND;
97                                 }
98
99                                 // Free memory
100                                 SQL_FREERESULT($result);
101                         }
102
103                         // Free memory
104                         SQL_FREERESULT($result_main);
105
106                         // Unlock sponsor account
107                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_sponsor_data SET status='CONFIRMED'
108 WHERE id='%s' AND status='PENDING' LIMIT 1",
109  array($id), __FILE__, __LINE__);
110
111                         // Update, if applyable, referal count and points
112                         if (($refid > 0) && ($refid != $id)) {
113                                 // Update referal account
114                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_sponsor_data
115 SET points_amount=points_amount+%s, ref_count=ref_count+1
116 WHERE id='%s' LIMIT 1",
117  array($_CONFIG['sponsor_ref_points'], bigintval($refid)), __FILE__, __LINE__);
118
119                                 // Whas that update fine?
120                                 if (SQL_AFFECTEDROWS() == 1) {
121                                         // Load referal's data
122                                         $result = SQL_QUERY_ESC("SELECT id, gender, surname, family, email,
123 (points_amount - points_used) AS points, receive_warnings, ref_count AS refs
124 FROM "._MYSQL_PREFIX."_sponsor_data
125 WHERE id='%s' LIMIT 1",
126  array(bigintval($refid)), __FILE__, __LINE__);
127                                         $REFERRAL = SQL_FETCHARRAY($result);
128
129                                         // Send warnings out?
130                                         if ($REFERRAL['receive_warnings'] == "Y") {
131                                                 // Translate some data
132                                                 $REFERRAL['points']     = TRANSLATE_COMMA($REFERRAL['points']);
133                                                 $REFERRAL['ref_points'] = TRANSLATE_COMMA($_CONFIG['sponsor_ref_points']);
134                                                 $REFERRAL['gender']      = TRANSLATE_GENDER($REFERRAL['gender']);
135
136                                                 // Send notification to referal
137                                                 $REF_MSG = LOAD_EMAIL_TEMPLATE("sponsor_ref_notify", $REFERRAL);
138                                                 SEND_EMAIL($REFERRAL['email'], SPONSOR_REF_NOTIFY_SUBJ, $REF_MSG);
139                                         }
140
141                                         // Free memory
142                                         SQL_FREERESULT($result);
143                                 }
144                         }
145
146                         // Transfer data to array
147                         $content['gender']   = TRANSLATE_GENDER($gender);
148                         $content['surname'] = $sname;
149                         $content['family']  = $fname;
150                         $content['sponsor'] = $id;
151                         $content['points']  = TRANSLATE_COMMA($points);
152
153                         // So let's send the email away
154                         $msg = LOAD_EMAIL_TEMPLATE("sponsor_unlocked", $content);
155                         SEND_EMAIL($email, SPONSOR_UNLOCKED_SUBJ, $msg);
156                 }
157         } else {
158                 // Nothing selected
159                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SPONSOR_NONE_SELECTED_UNLOCK);
160         }
161
162         // Add seperator
163         OUTPUT_HTML("<br />");
164 }
165
166 // Begin listing of all pending sponsor accounts
167 $result = SQL_QUERY("SELECT id, gender, surname, family, email, remote_addr, sponsor_created
168 FROM "._MYSQL_PREFIX."_sponsor_data
169 WHERE status='PENDING' ORDER BY id", __FILE__, __LINE__);
170
171 if (SQL_NUMROWS($result) > 0) {
172         // Entries found so let's list them!
173         $OUT = ""; $SW = 2;
174         while(list($id, $gender, $sname, $fname, $email, $ip, $created) = SQL_FETCHROW($result)) {
175                 // Transfer data to array
176                 $content = array(
177                         'sw'      => $SW,
178                         'id'      => $id,
179                         'gender'   => TRANSLATE_GENDER($gender),
180                         'surname' => $sname,
181                         'family'  => $fname,
182                         'email'   => "mailto:".$email,
183                         'remote'  => $ip,
184                         'created' => MAKE_DATETIME($created, "2"),
185                 );
186
187                 // Load row template and switch colors
188                 $OUT .= LOAD_TEMPLATE("admin_unlock_sponsor_row", true, $content);
189                 $SW = 3 - $SW;
190         }
191         define('__SPONSOR_ROWS', $OUT);
192
193         // Load template
194         LOAD_TEMPLATE("admin_unlock_sponsor");
195 } else {
196         // No pending accounts found
197         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SPONSOR_NONE_PENDING);
198 }
199
200 // Free memory
201 SQL_FREERESULT($result);
202
203 //
204 ?>