2 /************************************************************************
3 * M-XChange v0.2.1 Start: 04/25/2005 *
4 * ================ Last change: 05/19/2008 *
6 * -------------------------------------------------------------------- *
7 * File : what-list_sponsor.php *
8 * -------------------------------------------------------------------- *
9 * Short description : List all sponsors and their details *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Alle Sponsoren und deren Details auflisten *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 - 2008 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
37 ************************************************************************/
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
48 if (REQUEST_ISSET_GET('id')) {
49 // Show detailed informations to a sponsor
50 $result = SQL_QUERY_ESC("SELECT company, position, gender, surname, family, street_nr1, street_nr2, zip, city, country, phone, fax, cell, email, url, tax_ident, status, sponsor_created, last_online, last_change, receive_warnings, points_amount, points_used, remote_addr, warning_interval, refid, ref_count
51 FROM `{!_MYSQL_PREFIX!}_sponsor_data`
52 WHERE `id`='%s' LIMIT 1",
53 array(bigintval(REQUEST_GET('id'))), __FILE__, __LINE__);
55 if (SQL_NUMROWS($result) == 1) {
56 // Load sponsor details
57 $DATA = SQL_FETCHARRAY($result);
58 SQL_FREERESULT($result);
60 // Check if an entry is empty
61 foreach ($DATA as $k => $v) {
62 if (empty($v)) $DATA[$k] = '---';
65 // Check for sponsor's orders (only count)
66 $result_orders = SQL_QUERY_ESC("SELECT COUNT(id) FROM `{!_MYSQL_PREFIX!}_sponsor_orders` WHERE sponsorid='%s'",
67 array(bigintval(REQUEST_GET('id'))), __FILE__, __LINE__);
68 list($orders) = SQL_FETCHROW($result_orders);
69 SQL_FREERESULT($result_orders);
70 if (empty($orders)) $orders = 0;
72 // Prepare all data for the template
73 // @TODO Rewrite this huge amount of constants
75 define('__SPONSOR_ID' , REQUEST_GET('id'));
77 define('__SPONSOR_COMPANY' , $DATA['company']);
78 define('__SPONSOR_POSITION' , $DATA['position']);
79 define('__SPONSOR_TAX_IDENT' , $DATA['tax_ident']);
81 define('__SPONSOR_GENDER' , translateGender($DATA['gender']));
82 define('__SPONSOR_SURNAME' , $DATA['surname']);
83 define('__SPONSOR_FAMILY' , $DATA['family']);
84 define('__SPONSOR_STREET1' , $DATA['street_nr1']);
85 define('__SPONSOR_STREET2' , $DATA['street_nr2']);
86 define('__SPONSOR_ZIP' , $DATA['zip']);
87 define('__SPONSOR_CITY' , $DATA['city']);
88 define('__SPONSOR_COUNTRY' , $DATA['country']);
90 define('__SPONSOR_PHONE' , $DATA['phone']);
91 define('__SPONSOR_FAX' , $DATA['fax']);
92 define('__SPONSOR_CELL' , $DATA['cell']);
93 define('__SPONSOR_EMAIL' , "mailto:".$DATA['email']);
94 define('__SPONSOR_EMAIL_VALUE', $DATA['email']);
95 define('__SPONSOR_URL' , DEREFERER($DATA['url']));
97 define('__SPONSOR_CREATED' , generateDateTime($DATA['sponsor_created'], '2'));
98 define('__SPONSOR_LAST_ONLINE', generateDateTime($DATA['last_online'], '2'));
99 define('__SPONSOR_LAST_CHANGE', generateDateTime($DATA['last_change'], '2'));
101 define('__SPONSOR_AMOUNT' , translateComma($DATA['points_amount']));
102 define('__SPONSOR_USED' , translateComma($DATA['points_used']));
103 // Warning because low points
104 define('__SPONSOR_REC_WARNING', translateYesNo($DATA['receive_warnings']));
105 define('__SPONSOR_INTERVAL' , createFancyTime($DATA['warning_interval']));
107 define('__SPONSOR_ORDERS' , $orders);
109 define('__SPONSOR_STATUS' , sponsorTranslateUserStatus($DATA['status']));
110 define('__SPONSOR_REFID' , $DATA['refid']);
111 define('__SPONSOR_REMOTE_ADR' , $DATA['remote_addr']);
112 define('__SPONSOR_REFS' , $DATA['ref_count']);
115 LOAD_TEMPLATE("admin_list_sponsor_details");
118 LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_SPONSOR_404'), REQUEST_GET('id')));
120 } elseif (REQUEST_ISSET_GET(('rid'))) {
121 // Search for sponsor
122 $result = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_sponsor_data` WHERE `id`='%s' LIMIT 1",
123 array(bigintval(REQUEST_GET('rid'))), __FILE__, __LINE__);
124 if (SQL_NUMROWS($result) == 1) {
126 SQL_FREERESULT($result);
128 // Sponsor found so let's list all his referals
129 $result = SQL_QUERY_ESC("SELECT id, gender, surname, family, email, status, sponsor_created, last_online, points_amount, points_used, remote_addr, ref_count
130 FROM `{!_MYSQL_PREFIX!}_sponsor_data`
131 WHERE refid='%s' ORDER BY `id`",
132 array(bigintval(REQUEST_GET('rid'))), __FILE__, __LINE__);
134 if (SQL_NUMROWS($result) > 0) {
137 SQL_FREERESULT($result);
139 // No refs made so far
140 LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_SPONSOR_REFS_404'), "<a href=\"{!URL!}/modules.php?module=admin&what=list_sponsor&id=".bigintval(REQUEST_GET('rid'))."\">".bigintval(REQUEST_GET('rid'))."</a>"));
144 LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_SPONSOR_404'), bigintval(REQUEST_GET('rid'))));
148 $result_main = SQL_QUERY("SELECT id, gender, surname, family, email, status, sponsor_created, last_online, points_amount, points_used, remote_addr
149 FROM `{!_MYSQL_PREFIX!}_sponsor_data` ORDER BY `id`", __FILE__, __LINE__);
150 if (SQL_NUMROWS($result_main) > 0) {
151 // At least one sponsor found!
153 while ($content = SQL_FETCHARRAY($result_main)) {
154 // Transfer data to array
155 // @TODO Rewritings: sname->surname,fname->family,ip->remote_addr in template
157 'id' => $content['id'],
159 'gender' => translateGender($content['gender']),
160 'sname' => $content['surname'],
161 'fname' => $content['family'],
162 'email' => "mailto:".$content['email'],
163 'status' => sponsorTranslateUserStatus($content['status']),
164 'created' => generateDateTime($content['sponsor_created'], '2'),
165 'last' => generateDateTime($content['last_online'], '2'),
166 'points' => translateComma($content['points_amount'] - $content['points_used']),
167 'ip' => $content['remote_addr'],
171 $OUT .= LOAD_TEMPLATE("admin_list_sponsor_row", true, $content);
176 SQL_FREERESULT($result_main);
178 // @TODO Rewrite this constant
179 define('__SPONSOR_ROWS', $OUT);
181 // Load final template
182 LOAD_TEMPLATE("admin_list_sponsor");
184 // No sponsors registered so far
185 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_SPONSOR_NONE_REGISTERED'));