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 - 2009 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')) || (!isAdmin())) {
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
47 if (isGetRequestElementSet('id')) {
48 // Show detailed informations to a sponsor
49 $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
50 FROM `{?_MYSQL_PREFIX?}_sponsor_data`
51 WHERE `id`='%s' LIMIT 1",
52 array(bigintval(getRequestElement('id'))), __FILE__, __LINE__);
54 if (SQL_NUMROWS($result) == 1) {
55 // Load sponsor details
56 $content = SQL_FETCHARRAY($result);
57 SQL_FREERESULT($result);
59 // Check if an entry is empty
60 foreach ($content as $k => $v) {
61 if (empty($v)) $content[$k] = '---';
64 // Check for sponsor's orders (only count)
65 $result_orders = SQL_QUERY_ESC("SELECT COUNT(id) FROM `{?_MYSQL_PREFIX?}_sponsor_orders` WHERE sponsorid='%s'",
66 array(bigintval(getRequestElement('id'))), __FILE__, __LINE__);
67 list($orders) = SQL_FETCHROW($result_orders);
68 SQL_FREERESULT($result_orders);
69 if (empty($orders)) $orders = 0;
71 // Prepare all data for the template
73 $content['id'] = getRequestElement('id');
75 $content['gender'] = translateGender($content['gender']);
77 $content['email_link'] = generateEmailLink($content['email'], 'sponsor_data');
78 $content['url'] = generateDerefererUrl($content['url']);
80 $content['created'] = generateDateTime($content['sponsor_created'], 2);
81 $content['last_online'] = generateDateTime($content['last_online'], 2);
82 $content['last_change'] = generateDateTime($content['last_change'], 2);
84 $content['points_amount'] = translateComma($content['points_amount']);
85 $content['points_used'] = translateComma($content['points_used']);
86 // Warning because low points
87 $content['receive_warnings'] = translateYesNo($content['receive_warnings']);
88 $content['warning_interval'] = createFancyTime($content['warning_interval']);
90 $content['orders'] = $orders;
92 $content['status'] = sponsorTranslateUserStatus($content['status']);
95 loadTemplate('admin_list_sponsor_details', false, $content);
98 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_SPONSOR_404'), getRequestElement('id')));
100 } elseif (isGetRequestElementSet('rid')) {
101 // Search for sponsor
102 $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `id`='%s' LIMIT 1",
103 array(bigintval(getRequestElement('rid'))), __FILE__, __LINE__);
104 if (SQL_NUMROWS($result) == 1) {
106 SQL_FREERESULT($result);
108 // Sponsor found so let's list all his referals
109 $result = SQL_QUERY_ESC("SELECT
110 `id`, `gender`, `surname`, `family`, `email`, `status`,
111 `sponsor_created`, `last_online`, `points_amount`, `points_used`,
112 `remote_addr`, `ref_count`
114 `{?_MYSQL_PREFIX?}_sponsor_data`
119 array(bigintval(getRequestElement('rid'))), __FILE__, __LINE__);
121 if (SQL_NUMROWS($result) > 0) {
124 SQL_FREERESULT($result);
126 // No refs made so far
127 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_SPONSOR_REFS_404'), "<a href=\"{?URL?}/modules.php?module=admin&what=list_sponsor&id=".bigintval(getRequestElement('rid'))."\">".bigintval(getRequestElement('rid'))."</a>"));
131 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_SPONSOR_404'), bigintval(getRequestElement('rid'))));
135 $result_main = SQL_QUERY("SELECT
136 `id`, `gender`, `surname`, `family`, `email`, `status`,
137 `sponsor_created`, `last_online`, `points_amount`, `points_used`, `remote_addr`
139 `{?_MYSQL_PREFIX?}_sponsor_data`
141 `id` ASC", __FILE__, __LINE__);
143 if (SQL_NUMROWS($result_main) > 0) {
144 // At least one sponsor found!
146 while ($content = SQL_FETCHARRAY($result_main)) {
147 // Transfer data to array
148 // @TODO Rewritings: surname->surname,family->family,ip->remote_addr in template
150 'id' => $content['id'],
152 'gender' => translateGender($content['gender']),
153 'surname' => $content['surname'],
154 'family' => $content['family'],
155 'email' => generateEmailLink($content['email'], 'sponsor_data'),
156 'status' => sponsorTranslateUserStatus($content['status']),
157 'created' => generateDateTime($content['sponsor_created'], 2),
158 'last_online' => generateDateTime($content['last_online'], 2),
159 'points' => translateComma($content['points_amount'] - $content['points_used']),
160 'ip' => $content['remote_addr'],
164 $OUT .= loadTemplate('admin_list_sponsor_row', true, $content);
169 SQL_FREERESULT($result_main);
171 // Load final template
172 loadTemplate('admin_list_sponsor', false, $OUT);
174 // No sponsors registered so far
175 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_SPONSOR_NONE_REGISTERED'));