]> git.sesse.net Git - wloh/commitdiff
Factor out the division selector into its own function.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 25 Mar 2012 15:21:41 +0000 (17:21 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 25 Mar 2012 15:21:41 +0000 (17:21 +0200)
www/index.pl

index ef2e15eeacad5f042a1c3ba6515c302f4ba9ecb4..b754d4cffc98f44c72cbc91e9f1de1a3d5f5bf1a 100755 (executable)
@@ -77,6 +77,50 @@ sub get_subdivisions {
        return @subdivisions;
 }
 
+sub print_division_selector {
+       my ($dbh, $divisions, $subdivisions, $division, $subdivision) = @_;
+
+       print <<"EOF";
+    <form method="get" action="/">
+EOF
+
+       my $max_division = $divisions->[(scalar @$divisions) - 1];
+
+       print <<"EOF";
+     <p>Divisjon:
+        <select name="divisjon" onchange="form.submit();">
+EOF
+
+       for my $d (@$divisions) {
+               if ($d == $division) {
+                       print "        <option value=\"$d\" selected=\"selected\">$d</option>\n";
+               } else {
+                       print "        <option value=\"$d\">$d</option>\n";
+               }
+       }
+
+       print <<"EOF";
+        </select>
+        Avdeling:
+        <select name="avdeling" onchange="form.submit();">
+EOF
+
+       for my $sd (@$subdivisions) {
+               if ($sd == $subdivision) {
+                       print "        <option value=\"$sd\" selected=\"selected\">$sd</option>\n";
+               } else {
+                       print "        <option value=\"$sd\">$sd</option>\n";
+               }
+       }
+
+       print <<"EOF";
+        </select>
+        <input type="submit" value="Vis" />
+      </p>
+    </form>
+EOF
+}
+
 sub make_table {
        my ($lowest_division, $used_ratings, $used_cov) = @_;
 
@@ -216,51 +260,15 @@ printf <<"EOF", $match_stddev;
       Tallene vil variere litt fra gang til gang fordi utregningen skjer ved randomisering.</p>
 
     <p>Spillerne er sortert etter nick.</p>
-
-    <form method="get" action="/">
 EOF
 
 my $season = get_max_season($dbh);
 my @divisions = get_divisions($dbh, $season);
 $division = 1 if (!grep { $_ == $division } @divisions);
-my $max_division = $divisions[$#divisions];
-
-print <<"EOF";
-     <p>Divisjon:
-        <select name="divisjon" onchange="form.submit();">
-EOF
-
-for my $d (@divisions) {
-       if ($d == $division) {
-               print "        <option value=\"$d\" selected=\"selected\">$d</option>\n";
-       } else {
-               print "        <option value=\"$d\">$d</option>\n";
-       }
-}
-
-print <<"EOF";
-        </select>
-        Avdeling:
-        <select name="avdeling" onchange="form.submit();">
-EOF
-
 my @subdivisions = get_subdivisions($dbh, $season, $division);
 $subdivision = 1 if (!grep { $_ == $subdivision } @subdivisions);
 
-for my $sd (@subdivisions) {
-       if ($sd == $subdivision) {
-               print "        <option value=\"$sd\" selected=\"selected\">$sd</option>\n";
-       } else {
-               print "        <option value=\"$sd\">$sd</option>\n";
-       }
-}
-
-print <<"EOF";
-        </select>
-        <input type="submit" value="Vis" />
-      </p>
-    </form>
-EOF
+print_division_selector($dbh, \@divisions, \@subdivisions, $division, $subdivision);
 
 # Get players and ratings
 my $sum_rating = 0.0;
@@ -305,6 +313,7 @@ while (my $ref = $q->fetchrow_hashref) {
        $cov->{$ref->{'player1'}}{$ref->{'player2'}} = $ref->{'cov'};
 }
 
+my $max_division = $divisions[$#divisions];
 my $lowest_division = ($division == $max_division);
 make_table($lowest_division, {}, {});