Initial checkin
[ndccode.git] / stats / playerstats.pl
1 #!/usr/bin/perl 
2
3 # playerstats.pl
4 # NDC Code Release 1
5 # CGI-Parameters:
6 #       nick:   Player name
7 #
8 # Displays a web page showing the stats for one player, displaying
9 # a picture, mail address and web page.
10 #
11 #   Copyright (C) 2001 Andreas Ulbrich, Ralf Ertzinger (ndccode@ndc.sh)
12 #
13 #   This program is free software; you can redistribute it and/or modify
14 #   it under the terms of the GNU General Public License as published by
15 #   the Free Software Foundation; either version 2 of the License, or
16 #   (at your option) any later version.
17 #
18 #   This program is distributed in the hope that it will be useful,
19 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
20 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 #   GNU General Public License for more details.
22 #
23 #   You should have received a copy of the GNU General Public License
24 #   along with this program; if not, write to the Free Software
25 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
27 #use strict;
28 require 5.002;
29 use DBI;
30 use CGI;
31
32 my $CGIquery;
33
34 ### Var def ###
35 $CGIquery = new CGI;
36 $picturepath = 'http://www.ndc.sh/graphics/playerdb/';
37 $nick = $CGIquery->param("nick");
38
39 # Define SQL-Variables
40
41 $sql_database = "stats";
42 $sql_datasource = "DBI:mysql:$sql_database";
43 $sql_username = "";
44 $sql_password = "";
45 $sql_db_handle = DBI->connect($sql_datasource, $sql_username, $sql_password) or die "Could not connect to database.\n";
46
47
48 print "Content-Type: text/html\n\n\n";
49
50 # Retrieve player data from SQL
51
52 $sql_query_string = "SELECT nick, email, picture, homepage, kills, victims, suicides, mapsplayed, mapswon, FPH, skill, time, skill_top, fe_skill, fe_kills, fe_victims, fe_suicides, fe_mapsplayed, fe_mapswon, fe_fph, fe_time, fe_rank, date_format(LastSeen, '%d.%m.%Y') as date_europe FROM PlayerStats WHERE nick=?";
53 $sql_query = $sql_db_handle->prepare($sql_query_string);
54 $sql_query->execute($nick);
55
56 $sql_row = $sql_query->fetchrow_hashref;
57
58 $pl_name = $sql_row->{nick};
59 $pl_email = $sql_row->{email};
60 $pl_picture = $picturepath . $sql_row->{picture};
61 $pl_homepage = $sql_row->{homepage};
62 $pl_kills = $sql_row->{kills};
63 $pl_victims = $sql_row->{victims};
64 $pl_suicides = $sql_row->{suicides};
65 $pl_fph = $sql_row->{FPH};
66 $pl_skill = $sql_row->{skill};
67 $pl_time = $sql_row->{time};
68 $pl_maps_played = $sql_row->{mapsplayed};
69 $pl_maps_won = $sql_row->{mapswon};
70 $pl_fe_kills = $sql_row->{fe_kills};
71 $pl_fe_victims = $sql_row->{fe_victims};
72 $pl_fe_suicides = $sql_row->{fe_suicides};
73 $pl_fe_maps_played= $sql_row->{fe_mapsplayed};
74 $pl_fe_maps_won = $sql_row->{fe_mapswon};
75 $pl_fe_skill = $sql_row->{fe_skill};
76 $pl_fe_fph = $sql_row->{fe_fph};
77 $pl_fe_time = $sql_row->{fe_time};
78 $pl_skill_top = $sql_row->{skill_top};
79 $pl_fe_rank = $sql_row->{fe_rank};
80 $pl_lastseen = $sql_row->{date_europe};
81
82 $sql_query->finish;
83
84 $sql_db_handle->disconnect;
85
86 ## Ausgabe ##
87 ### Header ###
88 print '<HTML><HEAD><TITLE>NDC Spielerdaten</TITLE>';
89 print '<META NAME="Andreas Ulbrich">';
90 print '</HEAD><BODY BGCOLOR="#FFFFFF">';
91 print "\n<CENTER><img SRC=\"http:\/\/www.ndc.sh\/graphics\/aktuell_logo.jpg\" WIDTH=\"300\" HEIGHT=\"90\" BORDER=\"0\"ALT=\"\[SERVER Status\]\"><\/CENTER>\n";
92 print "\&nbsp\;<P>\n";
93 if (defined($eingabe{showquery})) {
94   print "<pre>\n";
95   print "SQL-Query:\n";
96   print "$sql_query_string\n";
97   print "</pre>";
98 }
99 print "<UL><table BORDER=\"0\">\n";
100 print "<tr>\n";
101 print "<td WIDTH=\"270\" ALIGN=\"CENTER\" BGCOLOR=\"\#FFFFCC\"><b>Spielerdaten<\/b><\/td>\n";
102 print "<\/TABLE><\/UL>\n";
103
104 if (defined($pl_name)) {
105   print "<UL><table BORDER=\"0\">\n";
106   print "<tr>\n";
107   print "<td ROWSPAN=\"10\" VALIGN=\"TOP\"><img src \=\"$pl_picture\" WIDTH=\"186\" HEIGHT=\"300\" BORDER=\"0\"><\/td>";
108   print "<td WIDTH=\"120\" BGCOLOR=\"\#CCCCCC\">Nickname:<\/td>";
109   print "<td WIDTH=\"200\" BGCOLOR=\"\#EEEEEE\"><b>" . make_html($pl_name) . "<\/b><\/td>\n";
110   print "<\/tr>\n";
111
112   print "<tr>\n";
113   print "<td BGCOLOR=\"#CCCCCC\">email:<\/td>";
114   if ($pl_email ne "") {
115     print "<td BGCOLOR=\"#EEEEEE\"><b><a href=\"mailto:$pl_email\">$pl_email<\/a><\/b><\/td>\n";
116   } else {
117     print "<td BGCOLOR=\"#EEEEEE\"><b>-<\/b><\/td>\n";
118   }
119   print "<\/tr>\n";
120
121   print "<tr>\n";
122   print "<td BGCOLOR=\"#CCCCCC\">Homepage:<\/td>";
123   if ($pl_homepage ne "") {
124     print "<td BGCOLOR=\"#EEEEEE\"><b><a href=\"$pl_homepage\" TARGET=\"xxyyzz\">$pl_homepage<\/a><\/b><\/td>\n";
125   } else {
126     print "<td BGCOLOR=\"#EEEEEE\"><b>-<\/b><\/td>\n";
127   }
128   print "<\/tr>\n";
129
130   print "<tr>\n";
131   print "<td BGCOLOR=\"#CCCCCC\">Kills:<\/td>";
132   print "<td BGCOLOR=\"#EEEEEE\"><b>$pl_fe_kills<\/b><\/td>\n";
133   print "<\/tr>\n";
134
135   print "<tr>\n";
136   print "<td BGCOLOR=\"#CCCCCC\">Victims:<\/td>";
137   print "<td BGCOLOR=\"#EEEEEE\"><b>$pl_fe_victims<\/b><\/td>\n";
138   print "<\/tr>\n";
139
140   print "<tr>\n";
141   print "<td BGCOLOR=\"#CCCCCC\">Suicides:<\/td>";
142   print "<td BGCOLOR=\"#EEEEEE\"><b>$pl_fe_suicides<\/b><\/td>\n";
143   print "<\/tr>\n";
144
145   print "<tr>\n";
146   print "<td BGCOLOR=\"#CCCCCC\">Skill:<\/td>";
147   print "<td BGCOLOR=\"#EEEEEE\"><b>$pl_fe_skill<\/b><\/td>\n";
148   print "<\/tr>\n";
149
150   print "<tr>\n";
151   print "<td BGCOLOR=\"#CCCCCC\">H&ouml;chster Skill:<\/td>";
152   print "<td BGCOLOR=\"#EEEEEE\"><b>$pl_skill_top<\/b><\/td>\n";
153   print "<\/tr>\n";
154
155   print "<tr>\n";
156   print "<td BGCOLOR=\"#CCCCCC\">Rang:<\/td>";
157   if ($pl_fe_rank != 0) {
158     print "<td BGCOLOR=\"#EEEEEE\"><b>$pl_fe_rank<\/b><\/td>\n";
159   } else {
160     print "<td BGCOLOR=\"#EEEEEE\"><b>-<\/b><\/td>\n";
161   }
162   print "<\/tr>\n";
163
164   print "<tr>\n";
165   print "<td BGCOLOR=\"#CCCCCC\">Zuletzt gespielt:<\/td>";
166   print "<td BGCOLOR=\"#EEEEEE\"><b>$pl_lastseen<\/b><\/td>\n";
167   print "<\/tr>\n";
168
169   print "<\/TABLE><\/UL>\n";
170
171   print "<P>&nbsp;<P>\n";
172   print "<UL><b>Gestern<\/b><br>\n";
173   print "<TABLE border=\"0\">\n";
174   print "<tr>\n";
175   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#FFFFCC\" WIDTH=\"100\">Map<\/td>\n";
176   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#FFFFCC\" WIDTH=\"50\">Skill<\/td>\n";
177   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#FFFFCC\" WIDTH=\"50\">FPH<\/td>\n";
178   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#FFFFCC\" WIDTH=\"50\">Maps gespielt<\/td>\n";
179   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#FFFFCC\" WIDTH=\"50\">Maps gewonnen<\/td>\n";
180   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#FFFFCC\" WIDTH=\"50\">Kills<\/td>\n";
181   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#FFFFCC\" WIDTH=\"50\">Victims<\/td>\n";
182   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#FFFFCC\" WIDTH=\"50\">Suicides<\/td>\n";
183   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#FFFFCC\" WIDTH=\"50\">Zeit (Min)<\/td>\n";
184   print "<\/tr>\n";
185
186   if ($pl_maps_played > 0) {
187
188     print "<tr>\n";
189     print "<td ALIGN=\"CENTER\" BGCOLOR=\"#CCCCCC\">Total<\/td>\n";
190     print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">$pl_skill<\/td>\n";
191     print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">$pl_fph<\/td>\n";
192     print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">$pl_maps_played<\/td>\n";
193     print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">$pl_maps_won<\/td>\n";
194     print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">$pl_kills<\/td>\n";
195     print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">$pl_victims<\/td>\n";
196     print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">$pl_suicides<\/td>\n";
197     print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">$pl_time<\/td>\n";
198     print "<\/tr>\n";
199
200   } else {
201
202     print "<tr>\n";
203     print "<td ALIGN=\"CENTER\" BGCOLOR=\"#CCCCCC\">Total<\/td>\n";
204     print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">-<\/td>\n";
205     print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">-<\/td>\n";
206     print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">-<\/td>\n";
207     print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">-<\/td>\n";
208     print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">-<\/td>\n";
209     print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">-<\/td>\n";
210     print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">-<\/td>\n";
211     print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">-<\/td>\n";
212     print "<\/tr>\n";
213
214   }
215
216   print "<\/TABLE><\/UL>\n";
217
218
219   print "<P>&nbsp;<P>\n";
220   print "<UL><b>Gesamt<\/b><br>\n";
221   print "<TABLE border=\"0\">\n";
222   print "<tr>\n";
223   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#FFFFCC\" WIDTH=\"100\">Map<\/td>\n";
224   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#FFFFCC\" WIDTH=\"50\">Skill<\/td>\n";
225   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#FFFFCC\" WIDTH=\"50\">FPH<\/td>\n";
226   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#FFFFCC\" WIDTH=\"50\">Maps gespielt<\/td>\n";
227   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#FFFFCC\" WIDTH=\"50\">Maps gewonnen<\/td>\n";
228   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#FFFFCC\" WIDTH=\"50\">Kills<\/td>\n";
229   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#FFFFCC\" WIDTH=\"50\">Victims<\/td>\n";
230   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#FFFFCC\" WIDTH=\"50\">Suicides<\/td>\n";
231   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#FFFFCC\" WIDTH=\"50\">Zeit (Min)<\/td>\n";
232   print "<\/tr>\n";
233
234
235   print "<tr>\n";
236   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#CCCCCC\">Total<\/td>\n";
237   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">$pl_fe_skill<\/td>\n";
238   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">$pl_fe_fph<\/td>\n";
239   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">$pl_fe_maps_played<\/td>\n";
240   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">$pl_fe_maps_won<\/td>\n";
241   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">$pl_fe_kills<\/td>\n";
242   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">$pl_fe_victims<\/td>\n";
243   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">$pl_fe_suicides<\/td>\n";
244   print "<td ALIGN=\"CENTER\" BGCOLOR=\"#EEEEEE\">$pl_fe_time<\/td>\n";
245   print "<\/tr>\n";
246
247   print "<\/TABLE><\/UL>\n";
248
249   print "<P>&nbsp;<P>\n";
250   print "<UL>Suche bei <a href=\"http\:\/\/www.theclq.com\/asp\/find.asp\?name=";
251   print make_compatible($pl_name);
252   print "\" TARGET=\"_blank\">The CLQ<\/a><\/ul>\n";
253   
254
255 } else {
256
257   print "<ul>Es wurde kein Spieler dieses Namens in der Datenbank gefunden.</ul>\n";
258
259 }
260   
261 print "<P><FONT SIZE=\"-2\"><DIV ALIGN=right>Skripting by NDC Code<BR><A href=\"http://www.ndc.sh\" target=\"_top\">www.ndc.sh</A></DIV></FONT><BR>\n";
262
263 print '</BODY></HTML>';
264
265
266 ####### Subroutines #####
267
268 sub make_html {
269
270   $input = shift;
271 #  $input =~ s/&/und/g;
272   $input =~ s/</&lt\;/g;
273   $input =~ s/>/&gt\;/g;
274   $input =~ s/"/&quot\;/g;
275   $input =~ s/\x1c/&middot;/g;
276 #  $input =~ s/\|/pipe/g;
277   return $input;
278 }
279
280 sub make_compatible {
281
282   $input = shift;
283   $input =~ s/%/%25/g;
284   $input =~ s/\+/%2B/g;
285   $input =~ s/ /+/g;
286   $input =~ s/,/%2C/g;
287   $input =~ s/</%3C/g;
288   $input =~ s/>/%3E/g;
289   $input =~ s/#/%23/g;
290   $input =~ s/\[/%5B/g;
291   $input =~ s/\]/%5D/g;
292   $input =~ s/\//%2F/g;
293   $input =~ s/\|/%7C/g;
294   $input =~ s/\?/%3F/g;
295   $input =~ s/\x1c/%1C/g;
296
297   return $input;
298 }
299