9a82dde5dba0672583e7b039e88428512c6011d3
[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 } // END - if
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                 } // END - foreach
64
65                 // Prepare all data for the template
66                 //  Sponsor's id
67                 $content['id']          = getRequestParameter('id');
68                 //  Contact data
69                 $content['email_link']  = generateEmailLink($content['email'], 'sponsor_data');
70                 //  Timestamps
71                 $content['created']     = generateDateTime($content['sponsor_created'], 2);
72                 $content['last_online'] = generateDateTime($content['last_online'], 2);
73                 $content['last_change'] = generateDateTime($content['last_change'], 2);
74                 //  Orders total
75                 $content['orders']      = countSumTotalData(bigintval(getRequestParameter('id')), 'sponsor_orders', 'id', 'sponsorid', true);
76
77                 // Load template
78                 loadTemplate('admin_list_sponsor_details', false, $content);
79         } else {
80                 // Sponsor not found
81                 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_SPONSOR_404', bigintval(getRequestParameter('id'))));
82         }
83 } elseif (isGetRequestParameterSet('rid')) {
84         // Search for sponsor
85         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `id`='%s' LIMIT 1",
86                 array(bigintval(getRequestParameter('rid'))), __FILE__, __LINE__);
87         if (SQL_NUMROWS($result) == 1) {
88                 // Free memory
89                 SQL_FREERESULT($result);
90
91                 // Sponsor found so let's list all his referals
92                 $result = SQL_QUERY_ESC("SELECT
93         `id`, `gender`, `surname`, `family`, `email`, `status`,
94         `sponsor_created`, `last_online`, `points_amount`, `points_used`,
95         `remote_addr`, `ref_count`
96 FROM
97         `{?_MYSQL_PREFIX?}_sponsor_data`
98 WHERE
99         `refid`='%s'
100 ORDER BY
101         `id` ASC",
102                 array(bigintval(getRequestParameter('rid'))), __FILE__, __LINE__);
103
104                 if (SQL_NUMROWS($result) > 0) {
105                         // List refs now
106                         // Free memory
107                         SQL_FREERESULT($result);
108                 } else {
109                         // No refs made so far
110                         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>'));
111                 }
112         } else {
113                 // Sponsor not found
114                 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_SPONSOR_404', bigintval(getRequestParameter('rid'))));
115         }
116 } else {
117         // List all sponsors
118         $result_main = SQL_QUERY("SELECT
119         `id`, `gender`, `surname`, `family`, `email`, `status`,
120         `sponsor_created`, `last_online`, `points_amount`, `points_used`, `remote_addr`
121 FROM
122         `{?_MYSQL_PREFIX?}_sponsor_data`
123 ORDER BY
124         `id` ASC", __FILE__, __LINE__);
125
126         if (SQL_NUMROWS($result_main) > 0) {
127                 // At least one sponsor found!
128                 $OUT = ''; $SW = 2;
129                 while ($content = SQL_FETCHARRAY($result_main)) {
130                         // Transfer data to array
131                         $content = array(
132                                 'id'          => $content['id'],
133                                 'sw'          => $SW,
134                                 'gender'      => $content['gender'],
135                                 'surname'     => $content['surname'],
136                                 'family'      => $content['family'],
137                                 'email'       => generateEmailLink($content['email'], 'sponsor_data'),
138                                 'status'      => $content['status'],
139                                 'created'     => generateDateTime($content['sponsor_created'], 2),
140                                 'last_online' => generateDateTime($content['last_online'], 2),
141                                 'points'      => translateComma($content['points_amount'] - $content['points_used']),
142                                 'remote_addr' => $content['remote_addr'],
143                         );
144
145                         // Load row template
146                         $OUT .= loadTemplate('admin_list_sponsor_row', true, $content);
147                         $SW = 3 - $SW;
148                 }
149
150                 // Free memory
151                 SQL_FREERESULT($result_main);
152
153                 // Load final template
154                 loadTemplate('admin_list_sponsor', false, $OUT);
155         } else {
156                 // No sponsors registered so far
157                 loadTemplate('admin_settings_saved', false, '{--ADMIN_SPONSOR_NONE_REGISTERED--}');
158         }
159 }
160
161 // [EOF]
162 ?>