Even more rewrites/fixes from EL branch (please report any broken part after you...
[mailer.git] / inc / modules / admin / what-list_sponsor.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 }
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
48 if (isGetRequestParameterSet('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(getRequestParameter('id'))), __FILE__, __LINE__);
54
55         if (SQL_NUMROWS($result) == 1) {
56                 // Load sponsor details
57                 $content = SQL_FETCHARRAY($result);
58                 SQL_FREERESULT($result);
59
60                 // Check if an entry is empty
61                 foreach ($content as $k => $v) {
62                         if (empty($v)) $content[$k] = '---';
63                 }
64
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(getRequestParameter('id'))), __FILE__, __LINE__);
68                 list($orders) = SQL_FETCHROW($result_orders);
69                 SQL_FREERESULT($result_orders);
70                 if (empty($orders)) $orders = '0';
71
72                 // Prepare all data for the template
73                 //  Sponsor's id
74                 $content['id']                = getRequestParameter('id');
75                 //  Personal data
76                 $content['gender']      = translateGender($content['gender']);
77                 //  Contact data
78                 $content['email_link']  = generateEmailLink($content['email'], 'sponsor_data');
79                 $content['url']         = generateDerefererUrl($content['url']);
80                 //  Timestamps
81                 $content['created']     = generateDateTime($content['sponsor_created'], 2);
82                 $content['last_online'] = generateDateTime($content['last_online'], 2);
83                 $content['last_change'] = generateDateTime($content['last_change'], 2);
84                 //  Sponsor points
85                 $content['points_amount'] = translateComma($content['points_amount']);
86                 $content['points_used']   = translateComma($content['points_used']);
87                 //  Warning because low points
88                 $content['receive_warnings'] = translateYesNo($content['receive_warnings']);
89                 $content['warning_interval'] = createFancyTime($content['warning_interval']);
90                 //  Orders total
91                 $content['orders']           = $orders;
92                 //  Other data
93                 $content['status']           = sponsorTranslateUserStatus($content['status']);
94
95                 // Load template
96                 loadTemplate('admin_list_sponsor_details', false, $content);
97         } else {
98                 // Sponsor not found
99                 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_SPONSOR_404', bigintval(getRequestParameter('id'))));
100         }
101 } elseif (isGetRequestParameterSet('rid')) {
102         // Search for sponsor
103         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `id`='%s' LIMIT 1",
104                 array(bigintval(getRequestParameter('rid'))), __FILE__, __LINE__);
105         if (SQL_NUMROWS($result) == 1) {
106                 // Free memory
107                 SQL_FREERESULT($result);
108
109                 // Sponsor found so let's list all his referals
110                 $result = SQL_QUERY_ESC("SELECT
111         `id`, `gender`, `surname`, `family`, `email`, `status`,
112         `sponsor_created`, `last_online`, `points_amount`, `points_used`,
113         `remote_addr`, `ref_count`
114 FROM
115         `{?_MYSQL_PREFIX?}_sponsor_data`
116 WHERE
117         `refid`='%s'
118 ORDER BY
119         `id` ASC",
120                 array(bigintval(getRequestParameter('rid'))), __FILE__, __LINE__);
121
122                 if (SQL_NUMROWS($result) > 0) {
123                         // List refs now
124                         // Free memory
125                         SQL_FREERESULT($result);
126                 } else {
127                         // No refs made so far
128                         loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_SPONSOR_REFS_404', '<a href="{%url=modules.php?module=admin&amp;what=list_sponsor&amp;id=' . bigintval(getRequestParameter('rid')) . '%}">' . bigintval(getRequestParameter('rid')) . '</a>'));
129                 }
130         } else {
131                 // Sponsor not found
132                 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_SPONSOR_404', bigintval(getRequestParameter('rid'))));
133         }
134 } else {
135         // List all sponsors
136         $result_main = SQL_QUERY("SELECT
137         `id`, `gender`, `surname`, `family`, `email`, `status`,
138         `sponsor_created`, `last_online`, `points_amount`, `points_used`, `remote_addr`
139 FROM
140         `{?_MYSQL_PREFIX?}_sponsor_data`
141 ORDER BY
142         `id` ASC", __FILE__, __LINE__);
143
144         if (SQL_NUMROWS($result_main) > 0) {
145                 // At least one sponsor found!
146                 $OUT = ''; $SW = 2;
147                 while ($content = SQL_FETCHARRAY($result_main)) {
148                         // Transfer data to array
149                         // @TODO Rewritings: surname->surname,family->family,ip->remote_addr in template
150                         $content = array(
151                                 'id'      => $content['id'],
152                                 'sw'      => $SW,
153                                 'gender'  => translateGender($content['gender']),
154                                 'surname'   => $content['surname'],
155                                 'family'   => $content['family'],
156                                 'email'   => generateEmailLink($content['email'], 'sponsor_data'),
157                                 'status'  => sponsorTranslateUserStatus($content['status']),
158                                 'created' => generateDateTime($content['sponsor_created'], 2),
159                                 'last_online'    => generateDateTime($content['last_online'], 2),
160                                 'points'  => translateComma($content['points_amount'] - $content['points_used']),
161                                 'ip'      => $content['remote_addr'],
162                         );
163
164                         // Load row template
165                         $OUT .= loadTemplate('admin_list_sponsor_row', true, $content);
166                         $SW = 3 - $SW;
167                 }
168
169                 // Free memory
170                 SQL_FREERESULT($result_main);
171
172                 // Load final template
173                 loadTemplate('admin_list_sponsor', false, $OUT);
174         } else {
175                 // No sponsors registered so far
176                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_SPONSOR_NONE_REGISTERED'));
177         }
178 }
179
180 // [EOF]
181 ?>