Sponsor stub extension added (not fully working\!)
[mailer.git] / inc / modules / admin / what-list_sponsor.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 04/25/2005 *
4  * ===============                              Last change: 05/18/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 {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", basename(__FILE__));
42
43 if (!empty($HTTP_GET_VARS['id']))
44 {
45         // Show detailed informations to a sponsor
46         $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
47 FROM "._MYSQL_PREFIX."_sponsor_data
48 WHERE id='%s' LIMIT 1",
49  array(bigintval($HTTP_GET_VARS['id'])), __FILE__, __LINE__);
50
51         if (SQL_NUMROWS($result) == 1)
52         {
53                 // Load sponsor details
54                 $DATA = SQL_FETCHARRAY($result);
55                 SQL_FREERESULT($result);
56
57                 // Check if an entry is empty
58                 foreach ($DATA as $k=>$v)
59                 {
60                         if (empty($v)) $DATA[$k] = "---";
61                 }
62
63                 // Check for sponsor's orders (only count)
64                 $result_orders = SQL_QUERY_ESC("SELECT COUNT(id) FROM "._MYSQL_PREFIX."_sponsor_orders WHERE sponsorid='%s'",
65                  array(bigintval($HTTP_GET_VARS['id'])), __FILE__, __LINE__);
66                 list($orders) = SQL_FETCHROW($result_orders);
67                 SQL_FREERESULT($result_orders);
68                 if (empty($orders)) $orders = "0";
69
70                 // Prepare all data for the template
71                 //  Sponsor's ID
72                 define('__SPONSOR_ID'         , $HTTP_GET_VARS['id']);
73                 //  Company's data
74                 define('__SPONSOR_COMPANY'    , $DATA['company']);
75                 define('__SPONSOR_POSITION'   , $DATA['position']);
76                 define('__SPONSOR_TAX_IDENT'  , $DATA['tax_ident']);
77                 //  Personal data
78                 define('__SPONSOR_SALUT'      , TRANSLATE_SEX($DATA['salut']));
79                 define('__SPONSOR_SURNAME'    , $DATA['surname']);
80                 define('__SPONSOR_FAMILY'     , $DATA['family']);
81                 define('__SPONSOR_STREET1'    , $DATA['street_nr1']);
82                 define('__SPONSOR_STREET2'    , $DATA['street_nr2']);
83                 define('__SPONSOR_ZIP'        , $DATA['zip']);
84                 define('__SPONSOR_CITY'       , $DATA['city']);
85                 define('__SPONSOR_COUNTRY'    , $DATA['country']);
86                 //  Contact data
87                 define('__SPONSOR_PHONE'      , $DATA['phone']);
88                 define('__SPONSOR_FAX'        , $DATA['fax']);
89                 define('__SPONSOR_CELL'       , $DATA['cell']);
90                 define('__SPONSOR_EMAIL'      , "mailto:".$DATA['email']);
91                 define('__SPONSOR_EMAIL_VALUE', $DATA['email']);
92                 define('__SPONSOR_URL'        , DEREFERER($DATA['url']));
93                 //  Timestamps
94                 define('__SPONSOR_CREATED'    , MAKE_DATETIME($DATA['sponsor_created'], "2"));
95                 define('__SPONSOR_LAST_ONLINE', MAKE_DATETIME($DATA['last_online'], "2"));
96                 define('__SPONSOR_LAST_CHANGE', MAKE_DATETIME($DATA['last_change'], "2"));
97                 //  Sponsor points
98                 define('__SPONSOR_AMOUNT'     , TRANSLATE_COMMA($DATA['points_amount']));
99                 define('__SPONSOR_USED'       , TRANSLATE_COMMA($DATA['points_used']));
100                 //  Warning because low points
101                 define('__SPONSOR_REC_WARNING', TRANSLATE_YESNO($DATA['receive_warnings']));
102                 define('__SPONSOR_INTERVAL'   , CREATE_FANCY_TIME($DATA['warning_interval']));
103                 //  Orders total
104                 define('__SPONSOR_ORDERS'     , $orders);
105                 //  Other data
106                 define('__SPONSOR_STATUS'     , SPONSOR_TRANSLATE_STATUS($DATA['status']));
107                 define('__SPONSOR_REFID'      , $DATA['refid']);
108                 define('__SPONSOR_REMOTE_ADR' , $DATA['remote_addr']);
109                 define('__SPONSOR_REFS'       , $DATA['ref_count']);
110
111                 // Load template
112                 LOAD_TEMPLATE("admin_list_sponsor_details");
113         }
114          else
115         {
116                 // Sponsor not found
117                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SPONSOR_404_1.$HTTP_GET_VARS['id'].ADMIN_SPONSOR_404_2);
118         }
119 }
120  elseif (!empty($HTTP_GET_VARS['rid']))
121 {
122         // Search for sponsor
123         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_sponsor_data WHERE id='%s' LIMIT 1",
124          array(bigintval($HTTP_GET_VARS['rid'])), __FILE__, __LINE__);
125         if (SQL_NUMROWS($result) == 1)
126         {
127                 // Free memory
128                 SQL_FREERESULT($result);
129
130                 // Sponsor found so let's list all his referrals
131                 $result = SQL_QUERY_ESC("SELECT id, salut, surname, family, email, status, sponsor_created, last_online, points_amount, points_used, remote_addr, ref_count
132 FROM "._MYSQL_PREFIX."_sponsor_data
133 WHERE refid='%s' ORDER BY id",
134  array(bigintval($HTTP_GET_VARS['rid'])), __FILE__, __LINE__);
135
136                 if (SQL_NUMROWS($result) > 0)
137                 {
138                         // List refs now
139                         // Free memory
140                         SQL_FREERESULT($result);
141                 }
142                  else
143                 {
144                         // No refs made so far
145                         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SPONSOR_REFS_404_1."<A href=\"".URL."/modules.php?module=admin&amp;what=list_sponsor&amp;id=".$HTTP_GET_VARS['rid']."\">".$HTTP_GET_VARS['rid']."</A>".ADMIN_SPONSOR_REFS_404_2);
146                 }
147         }
148          else
149         {
150                 // Sponsor not found
151                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SPONSOR_404_1.$HTTP_GET_VARS['rid'].ADMIN_SPONSOR_404_2);
152         }
153 }
154  else
155 {
156         // List all sponsors
157         $result_main = SQL_QUERY("SELECT id, salut, surname, family, email, status, sponsor_created, last_online, points_amount, points_used, remote_addr
158 FROM "._MYSQL_PREFIX."_sponsor_data ORDER BY id", __FILE__, __LINE__);
159         if (SQL_NUMROWS($result_main) > 0)
160         {
161                 // At least one sponsor found!
162                 $OUT = ""; $SW = 2;
163                 while(list($id, $salut, $sname, $fname, $email, $status, $created, $last, $amount, $used, $ip) = SQL_FETCHROW($result_main))
164                 {
165                         // Transfer data to array
166                         $content = array(
167                                 'id'      => $id,
168                                 'sw'      => $SW,
169                                 'salut'   => TRANSLATE_SEX($salut),
170                                 'sname'   => $sname,
171                                 'fname'   => $fname,
172                                 'email'   => "mailto:".$email,
173                                 'status'  => SPONSOR_TRANSLATE_STATUS($status),
174                                 'created' => MAKE_DATETIME($created, "2"),
175                                 'last'    => MAKE_DATETIME($last, "2"),
176                                 'points'  => TRANSLATE_COMMA($amount - $used),
177                                 'ip'      => $ip,
178                         );
179
180                         // Load row template
181                         $OUT .= LOAD_TEMPLATE("admin_list_sponsor_row", true, $content);
182                         $SW = 3 - $SW;
183                 }
184
185                 // Free memory
186                 SQL_FREERESULT($result_main);
187                 define('__SPONSOR_ROWS', $OUT);
188
189                 // Load final template
190                 LOAD_TEMPLATE("admin_list_sponsor");
191         }
192          else
193         {
194                 // No sponsors registered so far
195                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SPONSOR_NONE_REGISTERED);
196         }
197 }
198
199 //
200 ?>