b840333adb98a48635f4cefd3587523ecd5cd4c0
[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
51         `company`, `position`, `gender`, `surname`, `family`, `street_nr1`, `street_nr2`, `zip`, `city`, `country`,
52         `phone`, `fax`, `cell`, `email`, `url`, `tax_ident`,
53         `status`, `sponsor_created`, `last_online`, `last_change`, `receive_warnings`,
54         `points_amount`, `points_used`, `remote_addr`, `warning_interval`, `refid`, `ref_count`
55 FROM
56         `{?_MYSQL_PREFIX?}_sponsor_data`
57 WHERE
58         `id`=%s LIMIT 1",
59         array(bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
60
61         if (SQL_NUMROWS($result) == 1) {
62                 // Load sponsor details
63                 $content = SQL_FETCHARRAY($result);
64                 SQL_FREERESULT($result);
65
66                 // Check if an entry is empty
67                 foreach ($content as $k => $v) {
68                         if (empty($v)) $content[$k] = '---';
69                 } // END - foreach
70
71                 // Prepare all data for the template
72                 //  Sponsor's id
73                 $content['id']              = getRequestParameter('id');
74                 //  Contact data
75                 $content['email_link']      = generateEmailLink($content['email'], 'sponsor_data');
76                 //  Timestamps
77                 $content['sponsor_created'] = generateDateTime($content['sponsor_created'], 2);
78                 $content['last_online']     = generateDateTime($content['last_online'], 2);
79                 $content['last_change']     = generateDateTime($content['last_change'], 2);
80                 //  Orders total
81                 $content['orders']          = countSumTotalData(bigintval(getRequestParameter('id')), 'sponsor_orders', 'id', 'sponsor_id', true);
82
83                 // Load template
84                 loadTemplate('admin_list_sponsor_details', false, $content);
85         } else {
86                 // Sponsor not found
87                 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_SPONSOR_404', bigintval(getRequestParameter('id'))));
88         }
89 } elseif (isGetRequestParameterSet('refid')) {
90         // Search for sponsor
91         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_sponsor_data` WHERE `id`='%s' LIMIT 1",
92                 array(bigintval(getRequestParameter('refid'))), __FILE__, __LINE__);
93         if (SQL_NUMROWS($result) == 1) {
94                 // Free memory
95                 SQL_FREERESULT($result);
96
97                 // Sponsor found so let's list all his referals
98                 $result = SQL_QUERY_ESC("SELECT
99         `id`, `gender`, `surname`, `family`, `email`, `status`,
100         `sponsor_created`, `last_online`, `points_amount`, `points_used`,
101         `remote_addr`, `ref_count`
102 FROM
103         `{?_MYSQL_PREFIX?}_sponsor_data`
104 WHERE
105         `refid`='%s'
106 ORDER BY
107         `id` ASC",
108                 array(bigintval(getRequestParameter('refid'))), __FILE__, __LINE__);
109
110                 if (!SQL_HASZERONUMS($result)) {
111                         // List refs now
112                         // Free memory
113                         SQL_FREERESULT($result);
114                 } else {
115                         // No refs made so far
116                         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>'));
117                 }
118         } else {
119                 // Sponsor not found
120                 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_SPONSOR_404', bigintval(getRequestParameter('refid'))));
121         }
122 } else {
123         // List all sponsors
124         $result_main = SQL_QUERY("SELECT
125         `id`, `gender`, `surname`, `family`, `email`, `status`,
126         `sponsor_created`, `last_online`, `points_amount`, `points_used`, `remote_addr`
127 FROM
128         `{?_MYSQL_PREFIX?}_sponsor_data`
129 ORDER BY
130         `id` ASC", __FILE__, __LINE__);
131
132         if (!SQL_HASZERONUMS($result_main)) {
133                 // At least one sponsor found!
134                 $OUT = '';
135                 while ($content = SQL_FETCHARRAY($result_main)) {
136                         // Transfer data to array
137                         $content = array(
138                                 'id'              => $content['id'],
139                                 'gender'          => $content['gender'],
140                                 'surname'         => $content['surname'],
141                                 'family'          => $content['family'],
142                                 'email'           => generateEmailLink($content['email'], 'sponsor_data'),
143                                 'status'          => $content['status'],
144                                 'sponsor_created' => generateDateTime($content['sponsor_created'], 2),
145                                 'last_online'     => generateDateTime($content['last_online'], 2),
146                                 'points'          => ($content['points_amount'] - $content['points_used']),
147                                 'remote_addr'     => $content['remote_addr'],
148                         );
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 ?>