Reset rewritten, SQL fixed, zeros are now numeric
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software. You can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License.       *
21  *                                                                      *
22  * This program is distributed in the hope that it will be useful,      *
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
25  * GNU General Public License for more details.                         *
26  *                                                                      *
27  * You should have received a copy of the GNU General Public License    *
28  * along with this program; if not, write to the Free Software          *
29  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
30  * MA  02110-1301  USA                                                  *
31  ************************************************************************/
32
33 // Some security stuff...
34 if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!is_admin())) {
35         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
36         require($INC);
37 }
38
39 // Add description as navigation point
40 ADD_DESCR("admin", basename(__FILE__));
41
42 if (!empty($_GET['id'])) {
43         // Show detailed informations to a sponsor
44         $result = SQL_QUERY_ESC("SELECT company, position, salut, 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
45 FROM "._MYSQL_PREFIX."_sponsor_data
46 WHERE id='%s' LIMIT 1",
47  array(bigintval($_GET['id'])), __FILE__, __LINE__);
48
49         if (SQL_NUMROWS($result) == 1) {
50                 // Load sponsor details
51                 $DATA = SQL_FETCHARRAY($result);
52                 SQL_FREERESULT($result);
53
54                 // Check if an entry is empty
55                 foreach ($DATA as $k => $v) {
56                         if (empty($v)) $DATA[$k] = "---";
57                 }
58
59                 // Check for sponsor's orders (only count)
60                 $result_orders = SQL_QUERY_ESC("SELECT COUNT(id) FROM "._MYSQL_PREFIX."_sponsor_orders WHERE sponsorid='%s'",
61                  array(bigintval($_GET['id'])), __FILE__, __LINE__);
62                 list($orders) = SQL_FETCHROW($result_orders);
63                 SQL_FREERESULT($result_orders);
64                 if (empty($orders)) $orders = 0;
65
66                 // Prepare all data for the template
67                 //  Sponsor's ID
68                 define('__SPONSOR_ID'         , $_GET['id']);
69                 //  Company's data
70                 define('__SPONSOR_COMPANY'    , $DATA['company']);
71                 define('__SPONSOR_POSITION'   , $DATA['position']);
72                 define('__SPONSOR_TAX_IDENT'  , $DATA['tax_ident']);
73                 //  Personal data
74                 define('__SPONSOR_SALUT'      , TRANSLATE_SEX($DATA['salut']));
75                 define('__SPONSOR_SURNAME'    , $DATA['surname']);
76                 define('__SPONSOR_FAMILY'     , $DATA['family']);
77                 define('__SPONSOR_STREET1'    , $DATA['street_nr1']);
78                 define('__SPONSOR_STREET2'    , $DATA['street_nr2']);
79                 define('__SPONSOR_ZIP'        , $DATA['zip']);
80                 define('__SPONSOR_CITY'       , $DATA['city']);
81                 define('__SPONSOR_COUNTRY'    , $DATA['country']);
82                 //  Contact data
83                 define('__SPONSOR_PHONE'      , $DATA['phone']);
84                 define('__SPONSOR_FAX'        , $DATA['fax']);
85                 define('__SPONSOR_CELL'       , $DATA['cell']);
86                 define('__SPONSOR_EMAIL'      , "mailto:".$DATA['email']);
87                 define('__SPONSOR_EMAIL_VALUE', $DATA['email']);
88                 define('__SPONSOR_URL'        , DEREFERER($DATA['url']));
89                 //  Timestamps
90                 define('__SPONSOR_CREATED'    , MAKE_DATETIME($DATA['sponsor_created'], "2"));
91                 define('__SPONSOR_LAST_ONLINE', MAKE_DATETIME($DATA['last_online'], "2"));
92                 define('__SPONSOR_LAST_CHANGE', MAKE_DATETIME($DATA['last_change'], "2"));
93                 //  Sponsor points
94                 define('__SPONSOR_AMOUNT'     , TRANSLATE_COMMA($DATA['points_amount']));
95                 define('__SPONSOR_USED'       , TRANSLATE_COMMA($DATA['points_used']));
96                 //  Warning because low points
97                 define('__SPONSOR_REC_WARNING', TRANSLATE_YESNO($DATA['receive_warnings']));
98                 define('__SPONSOR_INTERVAL'   , CREATE_FANCY_TIME($DATA['warning_interval']));
99                 //  Orders total
100                 define('__SPONSOR_ORDERS'     , $orders);
101                 //  Other data
102                 define('__SPONSOR_STATUS'     , SPONSOR_TRANSLATE_STATUS($DATA['status']));
103                 define('__SPONSOR_REFID'      , $DATA['refid']);
104                 define('__SPONSOR_REMOTE_ADR' , $DATA['remote_addr']);
105                 define('__SPONSOR_REFS'       , $DATA['ref_count']);
106
107                 // Load template
108                 LOAD_TEMPLATE("admin_list_sponsor_details");
109         } else {
110                 // Sponsor not found
111                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SPONSOR_404_1.$_GET['id'].ADMIN_SPONSOR_404_2);
112         }
113 } elseif (!empty($_GET['rid'])) {
114         // Search for sponsor
115         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_sponsor_data WHERE id='%s' LIMIT 1",
116          array(bigintval($_GET['rid'])), __FILE__, __LINE__);
117         if (SQL_NUMROWS($result) == 1) {
118                 // Free memory
119                 SQL_FREERESULT($result);
120
121                 // Sponsor found so let's list all his referrals
122                 $result = SQL_QUERY_ESC("SELECT id, salut, surname, family, email, status, sponsor_created, last_online, points_amount, points_used, remote_addr, ref_count
123 FROM "._MYSQL_PREFIX."_sponsor_data
124 WHERE refid='%s' ORDER BY id",
125  array(bigintval($_GET['rid'])), __FILE__, __LINE__);
126
127                 if (SQL_NUMROWS($result) > 0) {
128                         // List refs now
129                         // Free memory
130                         SQL_FREERESULT($result);
131                 } else {
132                         // No refs made so far
133                         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SPONSOR_REFS_404_1."<A href=\"".URL."/modules.php?module=admin&amp;what=list_sponsor&amp;id=".bigintval($_GET['rid'])."\">".bigintval($_GET['rid'])."</A>".ADMIN_SPONSOR_REFS_404_2);
134                 }
135         } else {
136                 // Sponsor not found
137                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SPONSOR_404_1.bigintval($_GET['rid']).ADMIN_SPONSOR_404_2);
138         }
139 } else {
140         // List all sponsors
141         $result_main = SQL_QUERY("SELECT id, salut, surname, family, email, status, sponsor_created, last_online, points_amount, points_used, remote_addr
142 FROM "._MYSQL_PREFIX."_sponsor_data ORDER BY id", __FILE__, __LINE__);
143         if (SQL_NUMROWS($result_main) > 0) {
144                 // At least one sponsor found!
145                 $OUT = ""; $SW = 2;
146                 while(list($id, $salut, $sname, $fname, $email, $status, $created, $last, $amount, $used, $ip) = SQL_FETCHROW($result_main)) {
147                         // Transfer data to array
148                         $content = array(
149                                 'id'      => $id,
150                                 'sw'      => $SW,
151                                 'salut'   => TRANSLATE_SEX($salut),
152                                 'sname'   => $sname,
153                                 'fname'   => $fname,
154                                 'email'   => "mailto:".$email,
155                                 'status'  => SPONSOR_TRANSLATE_STATUS($status),
156                                 'created' => MAKE_DATETIME($created, "2"),
157                                 'last'    => MAKE_DATETIME($last, "2"),
158                                 'points'  => TRANSLATE_COMMA($amount - $used),
159                                 'ip'      => $ip,
160                         );
161
162                         // Load row template
163                         $OUT .= LOAD_TEMPLATE("admin_list_sponsor_row", true, $content);
164                         $SW = 3 - $SW;
165                 }
166
167                 // Free memory
168                 SQL_FREERESULT($result_main);
169                 define('__SPONSOR_ROWS', $OUT);
170
171                 // Load final template
172                 LOAD_TEMPLATE("admin_list_sponsor");
173         } else {
174                 // No sponsors registered so far
175                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SPONSOR_NONE_REGISTERED);
176         }
177 }
178
179 //
180 ?>