89db1c6400e981f4625d30f1147e5e2fb66f6763
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
20  * For more information visit: http://www.mxchange.org                  *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addMenuDescription('admin', __FILE__);
45
46 if (isGetRequestParameterSet('id')) {
47         // Show detailed informations to a sponsor
48         $result = SQL_QUERY_ESC("SELECT
49         `company`, `position`, `gender`, `surname`, `family`, `street_nr1`, `street_nr2`, `zip`, `city`, `country`,
50         `phone`, `fax`, `cell`, `email`, `url`, `tax_ident`,
51         `status`,
52         UNIX_TIMESTAMP(`sponsor_created`) AS `sponsor_created`,
53         UNIX_TIMESTAMP(`last_online`) AS `last_online`,
54         UNIX_TIMESTAMP(`last_change`) AS `last_change`,
55         `receive_warnings`,
56         `points_amount`, `points_used`, `remote_addr`, `warning_interval`, `refid`, `ref_count`
57 FROM
58         `{?_MYSQL_PREFIX?}_sponsor_data`
59 WHERE
60         `id`=%s LIMIT 1",
61         array(bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
62
63         if (SQL_NUMROWS($result) == 1) {
64                 // Load sponsor details
65                 $content = SQL_FETCHARRAY($result);
66
67                 // Check if an entry is empty
68                 foreach ($content as $k => $v) {
69                         if ((empty($v)) && ($v != 0)) $content[$k] = '---';
70                 } // END - foreach
71
72                 // Prepare all data for the template
73                 //  Sponsor's id
74                 $content['id']              = getRequestParameter('id');
75                 //  Contact data
76                 $content['email_link']      = generateEmailLink($content['email'], 'sponsor_data');
77                 //  Timestamps
78                 $content['sponsor_created'] = generateDateTime($content['sponsor_created'], 2);
79                 $content['last_online']     = generateDateTime($content['last_online'], 2);
80                 $content['last_change']     = generateDateTime($content['last_change'], 2);
81                 //  Orders total
82                 $content['orders']          = countSumTotalData(bigintval(getRequestParameter('id')), 'sponsor_orders', 'id', 'sponsor_id', true);
83
84                 // Load template
85                 loadTemplate('admin_list_sponsor_details', false, $content);
86         } else {
87                 // Sponsor not found
88                 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_SPONSOR_404', bigintval(getRequestParameter('id'))));
89         }
90
91         // Free result
92         SQL_FREERESULT($result);
93 } elseif (isGetRequestParameterSet('refid')) {
94         // Search for sponsor
95         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `id`=%s LIMIT 1",
96                 array(bigintval(getRequestParameter('refid'))), __FILE__, __LINE__);
97         if (SQL_NUMROWS($result) == 1) {
98                 // Free memory
99                 SQL_FREERESULT($result);
100
101                 // Sponsor found so let's list all his referals
102                 $result = SQL_QUERY_ESC("SELECT
103         `id`, `gender`, `surname`, `family`, `email`, `status`,
104         UNIX_TIMESTAMP(`sponsor_created`) AS `sponsor_created`,
105         UNIX_TIMESTAMP(`last_online`) AS `last_online`,
106         `points_amount`, `points_used`,
107         `remote_addr`, `ref_count`
108 FROM
109         `{?_MYSQL_PREFIX?}_sponsor_data`
110 WHERE
111         `refid`='%s'
112 ORDER BY
113         `id` ASC",
114                 array(bigintval(getRequestParameter('refid'))), __FILE__, __LINE__);
115
116                 if (!SQL_HASZERONUMS($result)) {
117                         // List refs now
118                         // Free memory
119                         SQL_FREERESULT($result);
120                 } else {
121                         // No refs made so far
122                         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('refid')) . '%}">' . bigintval(getRequestParameter('refid')) . '</a>'));
123                 }
124         } else {
125                 // Sponsor not found
126                 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_SPONSOR_404', bigintval(getRequestParameter('refid'))));
127         }
128 } else {
129         // List all sponsors
130         $result_main = SQL_QUERY("SELECT
131         `id`, `gender`, `surname`, `family`, `email`, `status`,
132         UNIX_TIMESTAMP(`sponsor_created`) AS `sponsor_created`,
133         UNIX_TIMESTAMP(`last_online`) AS `last_online`,
134         `points_amount`, `points_used`, `remote_addr`
135 FROM
136         `{?_MYSQL_PREFIX?}_sponsor_data`
137 ORDER BY
138         `id` ASC", __FILE__, __LINE__);
139
140         if (!SQL_HASZERONUMS($result_main)) {
141                 // At least one sponsor found!
142                 $OUT = '';
143                 while ($content = SQL_FETCHARRAY($result_main)) {
144                         // Transfer data to array
145                         $content['email']           = generateEmailLink($content['email'], 'sponsor_data');
146                         $content['sponsor_created'] = generateDateTime($content['sponsor_created'], 2);
147                         $content['last_online']     = generateDateTime($content['last_online'], 2);
148                         $content['points']          = ($content['points_amount'] - $content['points_used']);
149
150                         // Load row template
151                         $OUT .= loadTemplate('admin_list_sponsor_row', true, $content);
152                 } // END - while
153
154                 // Free memory
155                 SQL_FREERESULT($result_main);
156
157                 // Load final template
158                 loadTemplate('admin_list_sponsor', false, $OUT);
159         } else {
160                 // No sponsors registered so far
161                 loadTemplate('admin_settings_saved', false, '{--ADMIN_SPONSOR_NONE_REGISTERED--}');
162         }
163 }
164
165 // [EOF]
166 ?>