#!/usr/bin/perl
print "Content-type: text/html\n\n";

print "<html>\n";
print "<head>\n";
print "<meta http-equiv='Content-Type' content='text/html; charset=windows-1250'>";
print "<title>a</title>";
print "</head>\n";

print "<body>\n";

$kol = '55';  # pocet kol 1. ligy
$ko = '0';    # 0 vsechny kola   1 - 52 jen vybrane
$typ = '0';   # styl
$kdo = '0';   # 0 vsechny teamy    jinak vyber
#$kdo = 'BER';   # 0 vsechny teamy    jinak vyber

use Env;

@tempo = split /&/, $QUERY_STRING;
#print "<BR> Pocet polozek: ",$#tempo,"<BR>";

for $i ( 0 .. $#tempo ){
   @temp = split /=/, $tempo[$i];
   
        if     ($temp[0] eq "kol")   { $kol = $temp[1]; }
        if     ($temp[0] eq "ko")    { $ko = $temp[1];  }	
        if     ($temp[0] eq "typ")   { $typ = $temp[1]; }		
        if     ($temp[0] eq "kdo")   { $kdo = $temp[1]; }	
	if     ($temp[0] eq "icq")   { $icq = $temp[1]; }
    };
  @team = '';
  @kolo = '';

  open (SBR, 'data.team.csv');
	while ( <SBR> ) {
	chomp;
        push(@team, $_)
        };
  close (SBR);
  
  open (SBR, 'data.zapas.csv');
	while ( <SBR> ) {
	chomp;
        push(@kolo, $_)
        };
  close (SBR);



for $j(1 .. 52) {
#print " ",$j,"kolo\n";
   print "<table border='0' width='620' cellspacing='0' cellpadding='0'>\n";
   print "<tr>\n";
   print "<td width='10' bgcolor='#000000'><strong><small><font color='#FFFFFF' face='Arial'></font></small></strong></td>\n";
   print "          <td width='60' bgcolor='#000000' align='center'><strong><small><font color='#FFFFFF' face='Arial'>";
   print " ",$j,". kolo</font></small></strong></td>\n";
   
   if ($kdo eq '0') {
       print "<td width='275' bgcolor='#000000'><strong><small><font color='#FFFFFF' face='Arial'>\n";
       print "středa","</font></small></strong></td>\n";}
   if ($kdo ne '0') {
       print "<td width='400' bgcolor='#000000'><strong><small><font color='#FFFFFF' face='Arial'>\n";
       print "středa","</font></small></strong></td>\n";}       
   if ($kdo eq '0') {   
       print "<td width='275' bgcolor='#000000'><p align='right'><strong><small><font color='#FFFFFF' face='Arial'>\n";
       print ".","</font></small></strong></td>\n";}
   if ($kdo ne '0') {   
       print "<td width='150' bgcolor='#000000'><p align='right'><strong><small><font color='#FFFFFF' face='Arial'>\n";
       print ".","</font></small></strong></td>\n";}       

print "</tr>\n";
			    
   print "<td width='10'></td>\n";
   print "<td width='60'></td>\n";
	    

  $cnt = '0';
  for $i(1 .. $#kolo) {

  $q = '0';
  @tmp = split ";",$kolo[$i];
  
  if ($tmp[1] eq $j) {
      $cnt = $cnt + 1;
      if ($kdo eq '0') { print "<td width='275'>";}

      for $j(1 ..$#team) {
             @tmp2 = split ";",$team[$j];
                 if ($tmp[2] eq $tmp2[1]) 
		    { $dom = $tmp2[0]; 
                      $q = $q + 1;
                      $aa = $tmp2[2];   
                     }
       }

      for $j(1 ..$#team) {
           @tmp2 = split ";",$team[$j];      
                 if ($tmp[3] eq $tmp2[1])
                    { $hos = $tmp2[0];
                      $q = $q + 1;
                      $bb = $tmp2[2];   
                    }
        }
      
      

     
     
   if ($kdo eq '0' && $q eq '2') {   print $aa," - ",$bb," ",$tmp[4],":",$tmp[5];}
   if ($kdo ne '0') { 
          if ($tmp[3] eq $kdo || $tmp[2] eq $kdo) {print "<td width='400'>",$aa," - ",$bb," </td><td width='150'>",$tmp[4],":",$tmp[5];}	  
                    }
   
     }  # next i
#  print "</td>\n";
  if ($cnt eq '2' || $cnt eq '4' || $cnt eq '6') {
           print "</tr>\n";
           print "<tr>\n";
           print "<td width='10'></td>\n";
           print "<td width='60'></td>\n";
	   }
  
   }
 
  print "</table>\n";
}
