<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        
                    <link rel='stylesheet' href='style/tables.css'/>
            <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Archivo" rel="stylesheet">
            <script src="js/jscolor.js"></script>

            <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    </head>
    <body style="display:  inline-table">
        <div style="overflow-x:auto;">
<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 *

Run4Football v0.1
This file is part of Run4Football. (C)2019 Corrado Mulas - CM TLC - R&D Dept. - Ardara (SS) 

    Run4Football is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Run4Football is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Run4Football.  If not, see <http://www.gnu.org/licenses/>.

*/        
require 'lib/r4fb.php';


session_start();
switch ($_GET['print'])
{
    case "gironi":
        
        $gironi = r4fb::fetchGironi($_GET['trn']);
        //print_r($gironi);
        $max = count($gironi);
        
        for($i=0; $i<$max; $i++)
        {
            $lettera = $gironi[$i]['lettera'];
            $idgrn = $gironi[$i]['id'];
            $classf = r4fb::fetchClassGrn($_GET['trn'], $idgrn);
        $max2 = count($classf);
       // $max2 = 10;
        echo "
            <table border='1' style='display:  inline-table'>
          <!--  <caption>Classifica Punti</caption> -->
	
		<thead>
		
			<tr>
				<th scope='col' colspan='2'>Girone ".$lettera."</th>
			</tr>

		</thead>
		
		
		<tbody align='center'>
		        <tr>
				<td>Squadra</td>
                                <td>Pt</td>
			</tr>";
                    
                    for($j=0; $j<$max2; $j++)
//                       if($classf[$j]['pt_gir'] != 0)
  //                     {
                        echo "<tr>
                            <td>".$classf[$j]['nome']."</td>
				<td>".$classf[$j]['pt_gir']."</td>
			</tr>";
    //                   }
		echo "
		</tbody>
		
		<tfoot align='center'>
		
			<tr>
				<td colspan='2'></td>		
			</tr>
		
		</tfoot>

            </table>";
        }
    break;
    case "poff":
        $classf = r4fb::fetchClassPoff($_GET['trn'],0);
        $classfo = r4fb::fetchClassPoff($_GET['trn'],2);
        $classfq = r4fb::fetchClassPoff($_GET['trn'],3);
        $classfs = r4fb::fetchClassPoff($_GET['trn'],4);
        $classff = r4fb::fetchClassPoff($_GET['trn'],5);
        //$max = count($classf);
        $max = 10;

//ottavi        
                echo "
            <table border='1' style='display:  inline-table'>
            <caption>Classifica Punti</caption>
	
		<thead>
		
			<tr>
				<th scope='col' colspan='2'>Ottavi PlayOff</th>
			</tr>

		</thead>
		
		
		<tbody align='center'>
		        <tr>
				<td>Squadra</td>
                                <td>Pt</td>
			</tr>";
        
        for($i=0;$i<$max;$i++)
        {
            if($classfo[$i]['pt_poff'] != 0)
            {
                        echo "<tr>
                            <td>".$classfo[$i]['nome']."</td>
				<td>".$classfo[$i]['pt_poff']."</td>
			</tr>";            
            }           
        }
        		echo "
		</tbody>
		
		<tfoot align='center'>
		
			<tr>
				<td colspan='2'></td>		
			</tr>
		
		</tfoot>

            </table>";
                        
//quarti
                echo "
            <table border='1' style='display:  inline-table'>
            <caption></caption>
	
		<thead>
		
			<tr>
				<th scope='col' colspan='2'>Ottavi PlayOff</th>
			</tr>

		</thead>
		
		
		<tbody align='center'>
		        <tr>
				<td>Squadra</td>
                                <td>Pt</td>
			</tr>";
        
        for($i=0;$i<$max;$i++)
        {
            if($classfq[$i]['pt_poff'] != 0)
            {
                        echo "<tr>
                            <td>".$classfq[$i]['nome']."</td>
				<td>".$classfq[$i]['pt_poff']."</td>
			</tr>";            
            }           
        }
        		echo "
		</tbody>
		
		<tfoot align='center'>
		
			<tr>
				<td colspan='2'></td>		
			</tr>
		
		</tfoot>

            </table>";

//semifinali
                echo "
            <table border='1' style='display:  inline-table'>
            <caption></caption>
	
		<thead>
		
			<tr>
				<th scope='col' colspan='2'>Semifinali PlayOff</th>
			</tr>

		</thead>
		
		
		<tbody align='center'>
		        <tr>
				<td>Squadra</td>
                                <td>Pt</td>
			</tr>";
        
        for($i=0;$i<$max;$i++)
        {
            if($classfs[$i]['pt_poff'] != 0)
            {
                        echo "<tr>
                            <td>".$classfs[$i]['nome']."</td>
				<td>".$classfs[$i]['pt_poff']."</td>
			</tr>";            
            }           
        }
        		echo "
		</tbody>
		
		<tfoot align='center'>
		
			<tr>
				<td colspan='2'></td>		
			</tr>
		
		</tfoot>

            </table>";

//finali
                echo "
            <table border='1' style='display:  inline-table'>
            <caption></caption>
	
		<thead>
		
			<tr>
				<th scope='col' colspan='2'>Finali PlayOff</th>
			</tr>

		</thead>
		
		
		<tbody align='center'>
		        <tr>
				<td>Squadra</td>
                                <td>Pt</td>
			</tr>";
        
        for($i=0;$i<$max;$i++)
        {
            if($classff[$i]['pt_poff'] != 0)
            {
                        echo "<tr>
                            <td>".$classff[$i]['nome']."</td>
				<td>".$classff[$i]['pt_poff']."</td>
			</tr>";            
            }           
        }
        		echo "
		</tbody>
		
		<tfoot align='center'>
		
			<tr>
				<td colspan='2'></td>		
			</tr>
		
		</tfoot>

            </table>";                        
    break;
    case "pout":
        $classfo = r4fb::fetchClassPout($_GET['trn'],2);
        $classfq = r4fb::fetchClassPout($_GET['trn'],3);
        $classfs = r4fb::fetchClassPout($_GET['trn'],4);
        $classff = r4fb::fetchClassPout($_GET['trn'],5);
        $classf = r4fb::fetchClassPout($_GET['trn'],0);
        //$max = count($classf);
        $max = 10;
        
        //ottavi
                echo "
            <table border='1' style='display:  inline-table'>
            <caption>Classifica Punti</caption>
	
		<thead>
		
			<tr>
				<th scope='col' colspan='2'>Ottavi PlayOut</th>
			</tr>

		</thead>
		
		
		<tbody align='center'>
		        <tr>
				<td>Squadra</td>
                                <td>Pt</td>
			</tr>";
        
        for($i=0;$i<$max;$i++)
        {
            if($classfo[$i]['pt_pout'] != 0)
            {
                        echo "<tr>
                            <td>".$classfo[$i]['nome']."</td>
				<td>".$classfo[$i]['pt_pout']."</td>
			</tr>";            
            }
        }
        		echo "
		</tbody>
		
		<tfoot align='center'>
		
			<tr>
				<td colspan='2'></td>		
			</tr>
		
		</tfoot>

            </table>";        
                        
        //quarti
                echo "
            <table border='1' style='display:  inline-table'>
            <caption>Classifica Punti</caption>
	
		<thead>
		
			<tr>
				<th scope='col' colspan='2'>Quarti PlayOut</th>
			</tr>

		</thead>
		
		
		<tbody align='center'>
		        <tr>
				<td>Squadra</td>
                                <td>Pt</td>
			</tr>";
        
        for($i=0;$i<$max;$i++)
        {
            if($classfq[$i]['pt_pout'] != 0)
            {
                        echo "<tr>
                            <td>".$classfq[$i]['nome']."</td>
				<td>".$classfq[$i]['pt_pout']."</td>
			</tr>";            
            }           
        }
        		echo "
		</tbody>
		
		<tfoot align='center'>
		
			<tr>
				<td colspan='2'></td>		
			</tr>
		
		</tfoot>

            </table>";                                
                        
//semifinali
                echo "
            <table border='1' style='display:  inline-table'>
            <caption></caption>
	
		<thead>
		
			<tr>
				<th scope='col' colspan='2'>Semifinali PlayOut</th>
			</tr>

		</thead>
		
		
		<tbody align='center'>
		        <tr>
				<td>Squadra</td>
                                <td>Pt</td>
			</tr>";
        
        for($i=0;$i<$max;$i++)
        {
            if($classfs[$i]['pt_pout'] != 0)
            {
                        echo "<tr>
                            <td>".$classfs[$i]['nome']."</td>
				<td>".$classfs[$i]['pt_pout']."</td>
			</tr>";            
            }       
        }
        		echo "
		</tbody>
		
		<tfoot align='center'>
		
			<tr>
				<td colspan='2'></td>		
			</tr>
		
		</tfoot>

            </table>";                        
                        
//finali
                echo "
            <table border='1' style='display:  inline-table'>
            <caption></caption>
	
		<thead>
		
			<tr>
				<th scope='col' colspan='2'>Finali PlayOut</th>
			</tr>

		</thead>
		
		
		<tbody align='center'>
		        <tr>
				<td>Squadra</td>
                                <td>Pt</td>
			</tr>";
        
        for($i=0;$i<$max;$i++)
        {
            if($classff[$i]['pt_pout'] != 0)
            {
                        echo "<tr>
                            <td>".$classff[$i]['nome']."</td>
				<td>".$classff[$i]['pt_pout']."</td>
			</tr>";            
            }           
        }
        		echo "
		</tbody>
		
		<tfoot align='center'>
		
			<tr>
				<td colspan='2'></td>		
			</tr>
		
		</tfoot>

            </table>";                                
    break;
    case "class":
        $classf = r4fb::fetchClass($_GET['trn']);
        //$max = count($classf);
        $max = 10;
        
                echo "
            <table border='1' style='display:  inline-table'>
            <caption>Classifica Punti</caption>
	
		<thead>
		
			<tr>
				<th scope='col' colspan='2'>Classifica Generale</th>
			</tr>

		</thead>
		
		
		<tbody align='center'>
		        <tr>
				<td>Squadra</td>
                                <td>Pt</td>
			</tr>";
        
        for($i=0;$i<$max;$i++)
        {
                        echo "<tr>
                            <td>".$classf[$i]['nome']."</td>
				<td>".$classf[$i]['pt']."</td>
			</tr>";            
        }
        		echo "
		</tbody>
		
		<tfoot align='center'>
		
			<tr>
				<td colspan='2'></td>		
			</tr>
		
		</tfoot>

            </table>";           
        
        break;
    case "cc":
        $classf = r4fb::fetchClassCC($_GET['trn']);
        
                $max = 10;
        
                echo "
            <table border='1' style='display:  inline-table'>
            <caption>Classifica Marcatori</caption>
	
		<thead>
		
			<tr>
				<th scope='col' colspan='3'>Capocannonieri</th>
			</tr>

		</thead>
		
		
		<tbody align='center'>
		        <tr>
                                <td>Nome</td>
				<td>Squadra</td>
                                <td>Goal</td>
			</tr>";
        
        for($i=0;$i<$max;$i++)
        {
            $id = $classf[$i]['squadra'];
            $sqd = r4fb::fetchSquadraData($id);
           // print_r($sqd);
            if($classf[$i]['goal'] != 0)
            {
                        echo "<tr>
                            <td>".$classf[$i]['nome']."</td>
				<td>".$sqd[0]['nome']."</td>
                                <td>".$classf[$i]['goal']."</td>
			</tr>";            
            }
        }
        		echo "
		</tbody>
		
		<tfoot align='center'>
		
			<tr>
				<td colspan='3'></td>		
			</tr>
		
		</tfoot>

            </table>";        
        break;
    case "votesfrm":
       // echo $_GET['trn'];
        $squadre = r4fb::fetchSquadreTourn($_GET['trn']);
        $status = r4fb::tournData($_GET['trn'])['voteStatus'];
        
    if($status == 1)
    {
        $max = count($squadre);
        echo '
            

        <form action="" method="post" name="votesfrmsls">
        <p><fieldset style="border:none; width:100%">
                <label for="bestpl" id="bestpl"><strong>Miglior Giocatore:</strong></label>
                <label for="selsq">(seleziona squadra)</label>
                <select name="selsq" id="selsq">';
                
                for($i=0;$i<$max;$i++)
                {
                    echo   '<option value="'.$squadre[$i]['id'].'">'.$squadre[$i]['nome'].'</option>';
                }
                
                if(isset($_POST['selsqd'])) $_SESSION['sqdvote'] = $_POST['selsq'];
                
                echo '</select><input type="submit" name="selsqd" value="Seleziona"/></form>
                <form action="" method="post" name="votesfrm">
                <select id="bestpl" name="bestpl">';
                
                $players = r4fb::fetchPlayers($_SESSION['sqdvote']);
                
                $max = count($players);
                for($i=0;$i<$max;$i++)
                {
                    echo   '<option value="'.$players[$i]['id'].'">'.$players[$i]['nome'].'</option>';
                }
                
                echo '
                </select>
            </fieldset></p>
            <p><fieldset style="border:none; width:100%">
                <label for="bestsq"><strong>Miglior Squadra:</strong></label>
                <select name="bestsq">';
                
                for($i=0;$i<$max;$i++)
                {
                    echo   '<option value="'.$squadre[$i]['id'].'">'.$squadre[$i]['nome'].'</option>';
                }
                
                echo '</select>
            </fieldset></p>
            
           <p><fieldset style="border:none; width:100%">
                <label for="bestrf"><strong>Miglior Arbitro:</strong></label>
                <select name="bestrf">';
                
                $arbs = r4fb::fetchArbs($_GET['trn']);
                
                $max = count($arbs);
                for($i=0;$i<$max;$i++)
                {
                    echo   '<option value="'.$arbs[$i]['id'].'">'.$arbs[$i]['nome'].'</option>';
                }
                
                echo '
                </select>
            </fieldset></p>
            <p><fieldset style="border:none; width:100%">
                <label for="commenti"><strong>Commenti:</strong></label>
                <textarea name="commenti"></textarea>
            </fieldset></p>
            <p><fieldset style="border:none; margin-top:30px; width:100%">            
                <input type="submit" name="subvotes" value="Vota"/>
            </fieldset></p>
        </form>
        ';
                
            if(isset($_POST['subvotes']))
            {
                if(r4fb::insVote($_POST['bestpl'],$_POST['bestsq'],$_POST['bestrf'],$_POST['commenti'], session_id(),$_SERVER['REMOTE_ADDR'])) echo "Grazie per aver votato!";
            }
    }
    else if($status == 2)
    {
        //visualizza risultati
        echo "Le votazioni per questo torneo si sono concluse!";
    }
    else if($status == 0)
    {
        echo "Le votazioni non sono ancora disponibili per questo torneo, torna più tardi!";
    }
    break;   
    case "proxma":
        $proxma = r4fb::proxMatches($_GET['trn']);
        //print_r($proxma);
            $max = 10;
      //  $max = count($proxma);
                echo "
            <table border='1' style='display:  inline-table'>
            <caption></caption>
	
		<thead>
		
			<tr>
				<th scope='col' colspan='3'>Prossime partite</th>
			</tr>

		</thead>
		
		
		<tbody align='center'>
		        <tr>
                                <td>Squadre</td>
				<td>Orario</td>
                                <td>Campo</td>
			</tr>";
        
        for($i=0;$i<$max;$i++)
        {
            $s1 = $proxma[$i]['s1'];
            $s2 = $proxma[$i]['s2'];
            
            $sqd1 = r4fb::fetchSquadraData($s1);
            $sqd2 = r4fb::fetchSquadraData($s2);
           // print_r($sqd);
            if($s1 != NULL)
            {
                        echo "<tr>
                            <td>".$sqd1[0]['nome']." VS ".$sqd2[0]['nome']."</td>
				<td>".date('H:i',$proxma[$i]['t_prog'])."</td>
                                <td>".$proxma[$i]['campo']."</td>
			</tr>";            
            }
        }
        		echo "
		</tbody>
		
		<tfoot align='center'>
		
			<tr>
				<td colspan='3'></td>		
			</tr>
		
		</tfoot>

            </table>";                
    break;
    case "curma":
                $curma = r4fb::curMatches($_GET['trn']);
        //print_r($proxma);
               $max = count($curma);
        
                echo "
                    <script type='text/javascript'>
                        setTimeout(function(){
                        window.location.reload(1);
                        }, 10000);
                    </script>
            <table border='1' style='display:  inline-table'>
            <caption></caption>
	
		<thead>
		
			<tr>
				<th scope='col' colspan='5'>Partite correnti</th>
			</tr>

		</thead>
		
		
		<tbody align='center'>
		        <tr>
                                <td>Squadre</td>
				<td>Ora inizio</td>
                                <td>Campo</td>
                                <td>Punteggio</td>
                                <td>Falli</td>
			</tr>";
        
        for($i=0;$i<$max;$i++)
        {
            $s1 = $curma[$i]['s1'];
            $s2 = $curma[$i]['s2'];
            
            $sqd1 = r4fb::fetchSquadraData($s1);
            $sqd2 = r4fb::fetchSquadraData($s2);
           // print_r($sqd);
            if($s1 != NULL)
            {
                        echo "<tr>
                            <td>".$sqd1[0]['nome']." VS ".$sqd2[0]['nome']."</td>
				<td>".date('H:i',$curma[0]['t_start'])."</td>
                                <td>".$curma[0]['campo']."</td>
                                <td>".$curma[0]['pt_s1']." - ".$curma[0]['pt_s2']."</td>
                                <td>".$curma[0]['falli_s1']." - ".$curma[0]['falli_s2']."</td>
			</tr>";            
            }
        }
        		echo "
		</tbody>
		
		<tfoot align='center'>
		
			<tr>
				<td colspan='5'></td>		
			</tr>
		
		</tfoot>

            </table>";                
    break;
}


?>
        </div>
    </body>
</html>
