22f892f7c25f525504dadd5d71678ec6ae9d2cdc
[mailer.git] / inc / modules / admin / what-list_sponsor.php
1 <?php
2 /************************************************************************
3  * M-XChange v0.2.1                                   Start: 04/25/2005 *
4  * ================                             Last change: 05/19/2008 *
5  *                                                                      *
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  * -------------------------------------------------------------------- *
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  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
41         die();
42 }
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
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__);
53
54         if (SQL_NUMROWS($result) == 1) {
55                 // Load sponsor details
56                 $content = SQL_FETCHARRAY($result);
57                 SQL_FREERESULT($result);
58
59                 // Check if an entry is empty
60                 foreach ($content as $k => $v) {
61                         if (empty($v)) $content[$k] = '---';
62                 }
63
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;
70
71                 // Prepare all data for the template
72                 //  Sponsor's ID
73                 $content['id']                = getRequestElement('id');
74                 //  Personal data
75                 $content['gender']      = translateGender($content['gender']);
76                 //  Contact data
77                 $content['email_link']  = generateEmailLink($content['email'], 'sponsor_data');
78                 $content['url']         = generateDerefererUrl($content['url']);
79                 //  Timestamps
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');
83                 //  Sponsor points
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']);
89                 //  Orders total
90                 $content['orders']           = $orders;
91                 //  Other data
92                 $content['status']           = sponsorTranslateUserStatus($content['status']);
93
94                 // Load template
95                 loadTemplate('admin_list_sponsor_details', false, $content);
96         } else {
97                 // Sponsor not found
98                 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_SPONSOR_404'), getRequestElement('id')));
99         }
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) {
105                 // Free memory
106                 SQL_FREERESULT($result);
107
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`
113 FROM
114         `{?_MYSQL_PREFIX?}_sponsor_data`
115 WHERE
116         `refid`='%s'
117 ORDER BY
118         `id` ASC",
119                 array(bigintval(getRequestElement('rid'))), __FILE__, __LINE__);
120
121                 if (SQL_NUMROWS($result) > 0) {
122                         // List refs now
123                         // Free memory
124                         SQL_FREERESULT($result);
125                 } else {
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&amp;what=list_sponsor&amp;id=".bigintval(getRequestElement('rid'))."\">".bigintval(getRequestElement('rid'))."</a>"));
128                 }
129         } else {
130                 // Sponsor not found
131                 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_SPONSOR_404'), bigintval(getRequestElement('rid'))));
132         }
133 } else {
134         // List all sponsors
135         $result_main = SQL_QUERY("SELECT
136         `id`, `gender`, `surname`, `family`, `email`, `status`,
137         `sponsor_created`, `last_online`, `points_amount`, `points_used`, `remote_addr`
138 FROM
139         `{?_MYSQL_PREFIX?}_sponsor_data`
140 ORDER BY
141         `id` ASC", __FILE__, __LINE__);
142
143         if (SQL_NUMROWS($result_main) > 0) {
144                 // At least one sponsor found!
145                 $OUT = ''; $SW = 2;
146                 while ($content = SQL_FETCHARRAY($result_main)) {
147                         // Transfer data to array
148                         // @TODO Rewritings: surname->surname,family->family,ip->remote_addr in template
149                         $content = array(
150                                 'id'      => $content['id'],
151                                 'sw'      => $SW,
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'],
161                         );
162
163                         // Load row template
164                         $OUT .= loadTemplate('admin_list_sponsor_row', true, $content);
165                         $SW = 3 - $SW;
166                 }
167
168                 // Free memory
169                 SQL_FREERESULT($result_main);
170
171                 // Load final template
172                 loadTemplate('admin_list_sponsor', false, $OUT);
173         } else {
174                 // No sponsors registered so far
175                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_SPONSOR_NONE_REGISTERED'));
176         }
177 }
178
179 // [EOF]
180 ?>