]> git.sesse.net Git - wloh/blobdiff - www/index.pl
Fix a reference to the variable in wrong scope.
[wloh] / www / index.pl
index 697470cdd75a6002c92ed6b2919bef3b15258007..c26f12892168ef5702e47404d1e0dde34df32667 100755 (executable)
@@ -39,12 +39,6 @@ sub color {
        return int(255.0 * ($x ** (1.80)));
 }
 
-sub get_max_season {
-       my $dbh = shift;
-       my $ref = $dbh->selectrow_hashref('SELECT MAX(sesong) AS max_sesong FROM fotballserier');
-       return $ref->{'max_sesong'};
-}
-
 sub get_divisions {
        my ($dbh, $season) = @_;
 
@@ -230,7 +224,7 @@ function showScenario(element_id, url) {
     var obj = document.getElementById(element_id);
     var parent = obj.parentElement;
     parent.removeChild(obj);
-    obj = obj.cloneNode();
+    obj = obj.cloneNode(false);
     obj.data = url;
     parent.appendChild(obj);
 }
@@ -254,7 +248,7 @@ EOF
                $prob{$player} = [ @x[1..$#x] ];
        }
        close MCCALC;
-       #unlink $tmpnam;
+       unlink $tmpnam;
 
        my $num_games = scalar keys %prob;
        for my $i (1..$num_games) {
@@ -313,9 +307,9 @@ sub find_avg_rating {
 
        my $sum_rating = 0.0;
        for my $r (values %$ratings) {
-               $sum_rating += $r;
+               $sum_rating += ($r // 500.0);
        }
-       return $sum_rating / scalar keys %ratings;
+       return $sum_rating / scalar keys %$ratings;
 }
 
 sub get_auxillary_parameters {
@@ -340,12 +334,19 @@ sub print_header {
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="no">
   <head>
     <title>$title</title>
-    <link rel="stylesheet" href="/style" type="text/css" />
+    <link rel="stylesheet" href="style" type="text/css" />
   </head>
   <body>
 EOF
 }
 
+sub get_locale {
+       my $cgi = shift;
+       my $url = $cgi->url(-absolute => 1);
+       $url =~ m#^/([a-z][a-z]-[A-Z][A-Z])/# or die "Invalid locale!";
+       return $1;
+}
+
 sub print_footer {
        print <<"EOF";
   </body>
@@ -361,7 +362,7 @@ my $subdivision = $cgi->param('avdeling') // -1;
 my $match_player = $cgi->param('spiller');
 my $match_position = $cgi->param('posisjon');
 
-my $season = get_max_season($dbh);
+my $season = wloh_common::get_max_season($dbh);
 my @divisions = get_divisions($dbh, $season);
 $division = 1 if (!grep { $_ == $division } @divisions);
 my @subdivisions = get_subdivisions($dbh, $season, $division);
@@ -388,7 +389,7 @@ if (defined($match_player) && defined($match_position)) {
                push @scenario, [ $1, $2, $3 ];
        }
        close MCCALC;
-       #unlink $tmpnam;
+       unlink $tmpnam;
 
        my @sorted_players = sort { $players{$a} cmp $players{$b} } keys %players;
        my $player_name = $players{$sorted_players[$match_player]};
@@ -430,7 +431,7 @@ EOF
 
        print <<"EOF";
     <p style="clear: both; padding-top: 1em;">Under er en variant som tar relativ spillestyrke med i beregningen;
-      se <a href="/rating">ratingsiden</a>.</p>
+      se <a href="rating">ratingsiden</a>.</p>
 EOF
 
        make_table($aux_parms, $match_stddev, $lowest_division, \%ratings, $cov, $division, $subdivision);