<!DOCTYPE html>
<!--
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.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        
                    <link rel='stylesheet' href='style/manager.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>
        
        <?php
require '/sda1/www/idp.runpolito.ml/vendor/autoload.php';
require_once '/sda1/www/idp.runpolito.ml/lib/_autoload.php';
require 'lib/r4fb.php';  
//require 'lib/sns.php';
//session_start();
$auth = new \SimpleSAML\Auth\Simple('runpolito-sp');

/*if (!$auth->isAuthenticated()) {
    SimpleSAML_Session::getSessionFromRequest()->cleanup();
    // Show login link.
    print('<a href="/login">Login</a>');
}*/

//Auth livello 1:
$auth->requireAuth();
SimpleSAML_Session::getSessionFromRequest()->cleanup();

//print_r($auth->getAttributes());

$guid = $auth->getAttributes()['guid'][0];
//print_r(r4fb::fetchUsers($guid));
$nome = r4fb::fetchUsers($guid)[0]['nome'];
$cognome = r4fb::fetchUsers($guid)[0]['cognome'];
$matr = r4fb::fetchUsers($guid)[0]['matr'];
//Auth livello 2:
$tipo = trim(r4fb::fetchUsers($guid)[0]['tipo']);
//print $tipo;
if($tipo != 1 && $tipo != 2)
{
    $auth->logout();
  header("Location: index.php?error=Privilegi insufficienti.");
   die("su cunnu e tzia rua bagassa");
}


?>
        <?php

/*

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/>.

*/        
/**
 * Description of manager
 *
 * @author corradomulas for Run PoliTo - Corso Duca degli Abruzzi 24, 10129 Torino (TO)
 */
// put your code here
        
        //MAIN: 
  //      echo $_SESSION['tourn'];
        ?>
        
    <div class="sidenav">
        <form name="seltour2" method="post" action="">
                    <select name="curtour2">
                        <?php                
                            $tornei = r4fb::fetchTourneys();
                            $max = sizeof($tornei); //limitare res a prime 5 non disputate
                            for($i = 0; $i < $max;$i++)
                            {
                                $tarray = $tornei[$i];      
                                $id = $tarray['id'];
                                $nomet = $tarray['nome'];
                                echo '<option value="'.$id.'">'.$nomet.'</option>';
                            }
                        ?>
                    </select>
                    <input type="submit" name="selct2" id="selct" value="Seleziona torneo"/>
        </form>
        <?php if(isset($_POST['selct2'])) $_SESSION['tourn'] = $_POST['curtour2']; ?>
        <a href="#" onclick="usercatShow()">Utente</a>
        <a href="#" onclick="trcatShow()">Torneo</a>
        <a href="#" onclick="refcatShow()">Arbitri</a>
        <a href="#" onclick="teamcatShow()">Squadre</a>
        <a href="#" onclick="plcatShow()">Giocatori</a>
        <a href="#" onclick="calcatShow()">Calendario</a>
        <a href="#" onclick="matcatShow()">Partite</a>
        <a href="#" onclick="msgcatShow()">Messaggi</a>
    </div>
        
        <div class="main">
        <!--div gestione utente-->
        <div id="usertab">
            <div style="float: left">merda
                <ul>
                    <li><a href="#" onclick="chpassShow()">Cambia password</a></li>
                    <li><a href="#" onclick="usermodShow()">Modifica dati utente</a></li>
                    <li><a href="#" onclick="logout()">Logout</a></li>
                </ul>
            </div>
        </div>
        
        <!--div gestione/creazione partite-->
        <div id="matchestab">
            <div style="float: left">merda
                <ul>
                    <li><a href="#" onclick="insmaShow()">Inserisci partite</a></li>
                    <li><a href="#" onclick="modmaShow()">Modifica partite</a></li>
                    <li><a href="#" onclick="delmaShow()">Elimina partite</a></li>
                    <li><a href="#" onclick="showmaShow()">Visualizza partite</a></li>
                    <li><a href="#" onclick="statsmaShow()">Visualizza statistiche</a></li>
                </ul>
            </div>
        </div>
        
        <!--div gestione arbitri-->
        <div id="refereestab">
            <div style="float: left" id="remenu">merda
                <ul>
                    <li><a href="#" onclick="insreShow()">Crea arbitro</a></li>
                    <li><a href="#" onclick="modreShow()">Modifica arbitro</a></li>
                    <li><a href="#" onclick="showreShow()">Visualizza arbitri</a></li>
                    <li><a href="#" onclick="asgnreShow()">Assegna partita</a></li>
                    <li><a href="#" onclick="substreShow()">Sostituisci arbitro</a></li>
                    <li><a href="#" onclick="statsreShow()">Visualizza statistiche</a></li>
                    <li><a href="#" onclick="showcmreShow()">Visualizza partite correnti</a></li>
                </ul>
            </div>
           
                <div class="refuncs" id="insre">
                    porco dio
                    
                    <form action="" method="post" name="insre">
                        <ul>
                            <li>
                                <label for="nome">Nome</label>
                                <input type="text" name="nome" id="nome" />
                            </li>
                            <li>
                                <label for="email">E-mail</label>
                                <input type="text" name="email" id="email" />
                            </li>
                            <li>
                                <label for="telefono">Telefono</label>
                                <input type="text" name="telefono" id="telefono" /> (necessario solo per invio credenziali)
                            </li>
                            <li>
                                <label for="torneo">Torneo corrente</label>
                                <select name="curtourn">
                                  <!--  <option value="id_torneo">Nome_torneo</option> -->
                                    <?php
                                        $tornei = r4fb::fetchTourneys();
                                        $max = sizeof($tornei); //limitare res a prime 5 non disputate
                                        for($i = 0; $i < $max;$i++)
                                        {
                                            $tarray = $tornei[$i];      
                                            $id = $tarray['id'];
                                            $nomet = $tarray['nome'];
            
                                            echo '<option value="'.$id.'">'.$nomet.'</option>';
                                        }
                                    ?>
                                </select>
                            </li>
                        </ul>
                        <input type="submit" name="submit_arb" id="submit" value="Registra arbitro"/>
                    </form>
                    <?php
                        if(isset($_POST['submit_arb']))
                        {
                            $thumb = "notdef";
                           echo r4fb::insArb($_POST['nome'], $_POST['curtourn'], $thumb, $_POST['email'], $_POST['telefono']);
                        }
                    ?>
                </div>
                <div class="refuncs" id="modre">
                    porca madonna
                    <?php
                    
                    ?>
                </div>
                <div class="refuncs" id="showre">
                    porco gesoo
                    <?php
                    
                    ?>
                </div>
                <div class="refuncs" id="asgnre">
                    porco giuseppe
                    <?php
                    
                    ?>
                </div>
                <div class="refuncs" id="substre">
                    porci re magi
                    <?php
                    
                    ?>
                </div>
                <div class="refuncs" id="statsre">
                    porco abramo
                    <?php
                    
                    ?>
                </div>
                <div class="refuncs" id="showcmre">
                    porco caino
                    <?php
                    
                    ?>
                </div>
            
        </div>
        
        <!--div gestione/creazione calendario-->
        <div id="calendartab">
            <div style="float: left" id="calfuncs">merda
                <ul>
                    <li><a href="#" onclick="inscalShow()">Crea calendario</a></li>
                    <li><a href="#" onclick="modcalShow()">Modifica calendario</a></li>
                    <li><a href="#" onclick="showcalShow()">Mostra calendario</a></li>
                </ul>
            </div>
            <div id="inscal">
                        <form action="" method="post" name="calins">
                            <select name="tipocal">
                                <option value="1">Gironi</option>
                                <option value="2">Ottavi</option>
                                <option value="3">Quarti</option>
                                <option value="4">Semifinali</option>
                                <option value="5">Finale</option>
                            </select>
                            <select name="catcal">
                                <option value="1">--</option>
                                <option value="2">PlayOff</option>
                                <option value="3">PlayOut</option>
                            </select>
                            <div class="container1">
                                <button class="add_form_field">Aggiungi campi &nbsp; <span style="font-size:16px; font-weight:bold;">+ </span></button>
                            </div>
                            <input type="submit" name="calsub" value="Inserisci calendario" />
                        </form>
            <?php
                if(isset($_POST['calsub']))
                {
                    $max = count($_POST['orario']);
                    $tourn = $_SESSION['tourn'];
                   // echo $tourn;
                   // print_r($_POST['orario']);
                    for($i=0; $i < $max; $i++)
                    {
                        $s1 = $_POST['s1'][$i];
                        $s2 = $_POST['s2'][$i];
                        $refe = $_POST['arbitro'][$i];
                        $giornata = $_POST['giornata'][$i];
                        $orario = strtotime($_POST['orario'][$i]);
                        $campo = $_POST['campo'][$i];
                        $tipo = $_POST['tipocal'];
                        $categoria = $_POST['catcal'];
                        
                        r4fb::insMatch($orario, $s1, $s2, $refe, $tourn, $giornata, $campo, $tipo, $categoria);
                    }
                }
            ?>
            </div>
        </div>
        
        <!--div messaggistica-->
        <div id="msgtab">
            <div style="float: left">merda
                <ul>
                    <li><a href="#" onclick="sendmsgShow()">Invia messaggio</a></li>
                    <li><a href="#" onclick="showmsgShow()">Mostra messaggi</a></li>
                    <li><a href="#"></a></li>
                </ul>
            </div>
        </div>
        
        <!--div gestione/creazione squadre-->
        <div id="teamstab">
            <div style="float: left" id="teamsmenu">merda
                <ul>
                    <li><a href="#" onclick="instmShow()">Crea squadre</a></li>
                    <li><a href="#" onclick="modtmShow()">Modifica squadre</a></li>
                    <li><a href="#" onclick="showtmShow()">Mostra squadre</a></li>
                    <li><a href="#" onclick="statstmShow()">Visualizza statistiche</a></li>
                </ul>
            </div>
            <div class="teamfuncs" id="insteam">          
            </div>
        <div id="instm">
         <?php
                $tourn = $_SESSION['tourn'];
                echo $tourn;
                $nsq = r4fb::nSquadre($tourn);
                $gironi = r4fb::fetchGironi($tourn);
                $maxg = sizeof($gironi);
              //  echo $maxg;print_r($gironi);
                echo 'Inserimento Squadre:<form action="" method="post" class="pure-form">';
                
                for($i=0; $i < $nsq; $i++)
                {
                    echo '
                    <fieldset>
                        <legend>Squadra '.($i+1).'</legend>

                        <input name="nome[]" type="text" placeholder="Nome">
                        <label for="colore">Colore:</label>
                        <input name="colore[]" class="jscolor" value="ab2567" placeholder="colore">
                        <label for="npls">N° Giocatori:</label>
                        <select name="npls[]">';
                            for($j=1; $j < 31; $j++)
                            {
                                echo '<option value="'.$j.'">'.$j.'</option>';
                            }
                        echo '</select>
                        <label for="girone">Girone:</label>
                        <select name="girone[]">';
                            for($k=0; $k < $maxg; $k++)
                            {
                                
                                echo '<option value="'.$gironi[$k]['id'].'">'.$gironi[$k]['lettera'].'</option>';
                            }
                        echo '</select>
                    </fieldset>';
                }
                
                echo    '<input name="insq" type="submit" class="pure-button pure-button-primary" value="Inserisci squadre" />';
                echo '</form>';
                                
                if(isset($_POST['insq']))
                {
                    $max = sizeof($_POST['nome']);
                    $tourn = $_SESSION['tourn'];
                    echo $tourn;
                    for($i=0; $i < $max; $i++)
                    {
                        $nome = $_POST['nome'][$i];
                        $colore = $_POST['colore'][$i];
                        $npls = $_POST['npls'][$i];
                        $girone = $_POST['girone'][$i];
                        
                        r4fb::insSq($tourn, ($i+1), $nome, $colore, $npls, $girone);
                    }
                }
                ?>
        </div>
        </div>
        <!--div gestione/creazione torneo-->
        <div id="tourntab">
            <div style="float: left" id="tournmenu">merda
                <ul>
                    <li><a href="#" onclick="instrShow()">Crea torneo</a></li>
                    <li><a href="#" onclick="modtrShow()">Modifica torneo</a></li>
                    <li><a href="#" onclick="showtrShow()">Mostra torneo</a></li>
                    <li><a href="#" onclick="statstrShow()">Visualizza statistiche</a></li>
                    <li><a href="#" onclick="toggleVoteShow()">Apri/Chiudi voti</a></li>
                </ul>
            </div>
            <div class="tournfuncs" id="instourn">
                <form action="" method="post" name="instourn">
                    <ul>
                        <li>
                            <label for="nome">Nome</label>
                            <input type="text" name="nome" id="nome" />
                        </li>
                        <li>
                            <label for="tourntime">Inizio torneo</label>
                            <input type="datetime-local" name="tourntime" />
                        </li>
                        <li>
                            <label for="location">Location</label>
                            <input type="text" name="location" id="location" />
                        </li>
                        <li>
                            <label for="org">Organizzazione</label>
                            <input type="text" name="org" id="org" />
                        </li>
                        <li>
                            <label for="nsquadre">N° squadre</label>
                            <select name="nsquadre">
                                <?php                        
                                    for($i=1; $i < 25; $i++)
                                    {
                                        echo "<option value='".$i."'>".$i."</option>";
                                    }
                                ?>
                            </select>
                        </li>
                        <li>
                        <label for="ngironi">N° gironi</label>
                            <select name="ngironi">
                                <?php     
                                    for($i=1; $i < 25; $i++)
                                    {
                                        echo "<option value='".$i."'>".$i."</option>";
                                    }
                                ?>
                            </select>
                        </li>
                        <input type="submit" name="submit_tourn" id="submit" value="Inserisci torneo"/>         
                </form>
                
                <?php
                
                if(isset($_POST['submit_tourn']))
                {
                    //  $dateTimeObject = \DateTime::createFromFormat('Y-M-dTH:i', $_POST['tourntime']);
                    //$dateTimeObject->format('H:i');
                    $tsinizio = strtotime($_POST['tourntime']);
                    $org = $_POST['org'];
                    $loc = $_POST['location'];
                    $nome = $_POST['nome'];
                    $nsquadre = $_POST['nsquadre'];
                    $ngironi = $_POST['ngironi'];
                    
                    r4fb::insTorneo($tsinizio,$nome,$org,$loc,$guid,$nsquadre,$ngironi);
                }
                
                ?>
            </div>
            
        </div>
        <div class="tournfuncs" id="modtourn">
            
        </div>
        <div class="tournfuncs" id="showtourn">
            
        </div>
        <div class="tournfuncs" id="statstourn">
            
        </div>
        
        <div class="tournfuncs" id="togglevote">
            <button class="votebt" onclick="openVote('<?php echo $_SESSION['tourn'] ?>')" id="openvote" name="openvote">Apri votazione</button>
            <button class="votebt" onclick="closeVote('<?php echo $_SESSION['tourn'] ?>')" id="closevote" name="closevote">Chiudi votazione</button>
        </div>
       <!-- <div class="tournfuncs" id="instourn">
            
        </div>
        <div class="tournfuncs" id="instourn">
            
        </div> -->
        
        <div id="playerstab">
            <div style="float: left" id="plsmenu">merda
                <ul>
                    <li><a href="#" onclick="insplShow()">Inserisci giocatori</a></li>
                    <li><a href="#" onclick="modplShow()">Modifica giocatori</a></li>
                    <li><a href="#" onclick="showplShow()">Mostra giocatori</a></li>
                    <li><a href="#" onclick="statsplShow()">Visualizza statistiche</a></li>
                </ul>
            </div>
            <div class="plfuncs" id="inspls">
                <form name="selteam" method="post" action="">
                    <select name="curteam">
                        <?php                
                            $teams = r4fb::fetchSquadreTourn($_SESSION['tourn']);
                            
                            $max = sizeof($teams); //limitare res a prime 5 non disputate
                            for($i = 0; $i < $max;$i++)
                            {
                               
                                echo '<option value="'.$teams[$i]['id'].'">'.$teams[$i]['nome'].'</option>';
                            }
                        ?>
                    </select>
                    <input type="submit" name="selcteam" id="selct" value="Seleziona squadra"/>
                </form>
               
            </div>
        
         <?php
                if(isset($_POST['selcteam']))
                {
                    
                $team = $_POST['curteam'];
                $_SESSION['team'] = $team;
                echo $team;
                $npl = r4fb::nPlayers($team);
                echo 'Inserimento Giocatori:<form action="" method="post" class="pure-form">';
                
                for($i=0; $i < $npl; $i++)
                {
                    echo '
                    <fieldset>
                        <legend>Giocatore '.($i+1).'</legend>
                        <input name="nome[]" type="text" placeholder="Nome">
                        <input name="email[]" type="email" placeholder="Email">
                    </fieldset>';
                }
                
                echo    '<input name="insp" type="submit" class="pure-button pure-button-primary" value="Inserisci Giocatori" />';
                echo '</form>';
                }
                
                if(isset($_POST['insp']))
                {
                    $max = sizeof($_POST['nome']);
                    $team = $_SESSION['team'];
                    echo $team;
                    for($i=0; $i < $max; $i++)
                    {
                        $nome = $_POST['nome'][$i];
                        $email = $_POST['email'][$i];
                        $n = $i+1;                      
                        if(!r4fb::insPlayer($n, "1", $nome, "notdef", $team, $email)) die("merdacciasecca");
                    }
                }
                ?>
        </div>
        </div>
    </div>
        
        <!--JS mostra/nascondi categorie principali-->
        <script type="text/javascript">
        function usercatShow()
        {
            jQuery("#usertab").css('display','block');
            jQuery("#matchestab").css('display','none');
            jQuery("#refereestab").css('display','none');
            jQuery("#calendartab").css('display','none');
            jQuery("#msgtab").css('display','none');
            jQuery("#teamstab").css('display','none');
            jQuery("#tourntab").css('display','none');
            jQuery("#playerstab").css('display','none');
            jQuery(".votebt").css('display','none');
                        
//#fallo #ammonizione #goal #pli #partite
        }
        
        function trcatShow()
        {
            jQuery("#usertab").css('display','none');
            jQuery("#matchestab").css('display','none');
            jQuery("#refereestab").css('display','none');
            jQuery("#calendartab").css('display','none');
            jQuery("#msgtab").css('display','none');
            jQuery("#teamstab").css('display','none');
            jQuery("#tourntab").css('display','block');
            jQuery("#playerstab").css('display','none');
            jQuery(".votebt").css('display','none');
                        
//#fallo #ammonizione #goal #pli #partite
        }
        
        function toggleVoteShow()
        {
            jQuery("#usertab").css('display','none');
            jQuery("#matchestab").css('display','none');
            jQuery("#refereestab").css('display','none');
            jQuery("#calendartab").css('display','none');
            jQuery("#msgtab").css('display','none');
            jQuery("#teamstab").css('display','none');
            jQuery("#tourntab").css('display','none');
            jQuery("#playerstab").css('display','none');
            jQuery(".votebt").css('display','block');
    
                        
//#fallo #ammonizione #goal #pli #partite
        }        
        
        function refcatShow()
        {
            jQuery("#usertab").css('display','none');
            jQuery("#matchestab").css('display','none');
            jQuery("#refereestab").css('display','block');
            jQuery("#calendartab").css('display','none');
            jQuery("#msgtab").css('display','none');
            jQuery("#teamstab").css('display','none');
            jQuery("#tourntab").css('display','none');
            jQuery("#playerstab").css('display','none');
            jQuery("#remenu").css('display','block');
            jQuery(".refuncs").css('display','none');
            jQuery(".votebt").css('display','none');
                        
//#fallo #ammonizione #goal #pli #partite
        }
        
        function teamcatShow()
        {
            jQuery("#usertab").css('display','none');
            jQuery("#matchestab").css('display','none');
            jQuery("#refereestab").css('display','none');
            jQuery("#calendartab").css('display','none');
            jQuery("#msgtab").css('display','none');
            jQuery("#teamstab").css('display','block');
            jQuery("#tourntab").css('display','none');
            jQuery("#playerstab").css('display','none');
            jQuery(".votebt").css('display','none');
                        
//#fallo #ammonizione #goal #pli #partite
        }
        
        function plcatShow()
        {
            jQuery("#usertab").css('display','none');
            jQuery("#matchestab").css('display','none');
            jQuery("#refereestab").css('display','none');
            jQuery("#calendartab").css('display','none');
            jQuery("#msgtab").css('display','none');
            jQuery("#teamstab").css('display','none');
            jQuery("#tourntab").css('display','none');
            jQuery("#playerstab").css('display','block');
            jQuery(".votebt").css('display','none');
                        
//#fallo #ammonizione #goal #pli #partite
        }
        
        function calcatShow()
        {
            jQuery("#usertab").css('display','none');
            jQuery("#matchestab").css('display','none');
            jQuery("#refereestab").css('display','none');
            jQuery("#calendartab").css('display','block');
            jQuery("#msgtab").css('display','none');
            jQuery("#teamstab").css('display','none');
            jQuery("#tourntab").css('display','none');
            jQuery("#playerstab").css('display','none');
            jQuery(".votebt").css('display','none');
                        
//#fallo #ammonizione #goal #pli #partite
        }
        
        function matcatShow()
        {
            jQuery("#usertab").css('display','none');
            jQuery("#matchestab").css('display','block');
            jQuery("#refereestab").css('display','none');
            jQuery("#calendartab").css('display','none');
            jQuery("#msgtab").css('display','none');
            jQuery("#teamstab").css('display','none');
            jQuery("#tourntab").css('display','none');
            jQuery("#playerstab").css('display','none');
            jQuery(".votebt").css('display','none');
                        
//#fallo #ammonizione #goal #pli #partite
        }
        
        function msgcatShow()
        {
            jQuery("#usertab").css('display','none');
            jQuery("#matchestab").css('display','none');
            jQuery("#refereestab").css('display','none');
            jQuery("#calendartab").css('display','none');
            jQuery("#msgtab").css('display','block');
            jQuery("#teamstab").css('display','none');
            jQuery("#tourntab").css('display','none');
            jQuery("#playerstab").css('display','none');
            jQuery(".votebt").css('display','none');
                        
//#fallo #ammonizione #goal #pli #partite
        }
    </script>
   
    <!--JS sottocategoria arbitri-->
    <script type="text/javascript">
        //Mostra crea arb
        function insreShow()
        {
            jQuery("#insre").css('display','block');
            jQuery("#modre").css('display','none');
            jQuery("#showre").css('display','none');
            jQuery("#asgnre").css('display','none');
            jQuery("#substre").css('display','none');
            jQuery("#statsre").css('display','none');
            jQuery("#showcmre").css('display','none');
            jQuery("#remenu").css('display','none');
            
/*            <div id="insre">porco dio</div>
            <div id="modre">porca madonna</div>
            <div id="showre">porco gesoo</div>
            <div id="asgnre">porco giuseppe</div>
            <div id="substre">porci re magi</div>
            <div id="statsre">porco abramo</div>
            <div id="showcmre">porco caino</div> */

        }
        
        //Mostra modifica arb
        function modreShow()
        {
            jQuery("#insre").css('display','none');
            jQuery("#modre").css('display','block');
            jQuery("#showre").css('display','none');
            jQuery("#asgnre").css('display','none');
            jQuery("#substre").css('display','none');
            jQuery("#statsre").css('display','none');
            jQuery("#showcmre").css('display','none');
            jQuery("#remenu").css('display','none');
            
/*            <div id="insre">porco dio</div>
            <div id="modre">porca madonna</div>
            <div id="showre">porco gesoo</div>
            <div id="asgnre">porco giuseppe</div>
            <div id="substre">porci re magi</div>
            <div id="statsre">porco abramo</div>
            <div id="showcmre">porco caino</div> */

        }
        
                //Mostra visualizza arb
        function showreShow()
        {
            jQuery("#insre").css('display','none');
            jQuery("#modre").css('display','none');
            jQuery("#showre").css('display','block');
            jQuery("#asgnre").css('display','none');
            jQuery("#substre").css('display','none');
            jQuery("#statsre").css('display','none');
            jQuery("#showcmre").css('display','none');
            jQuery("#remenu").css('display','none');
            
/*            <div id="insre">porco dio</div>
            <div id="modre">porca madonna</div>
            <div id="showre">porco gesoo</div>
            <div id="asgnre">porco giuseppe</div>
            <div id="substre">porci re magi</div>
            <div id="statsre">porco abramo</div>
            <div id="showcmre">porco caino</div> */

        }
        
                //Mostra assegna arb
        function asgnreShow()
        {
            jQuery("#insre").css('display','none');
            jQuery("#modre").css('display','none');
            jQuery("#showre").css('display','none');
            jQuery("#asgnre").css('display','block');
            jQuery("#substre").css('display','none');
            jQuery("#statsre").css('display','none');
            jQuery("#showcmre").css('display','none');
            jQuery("#remenu").css('display','none');
            
/*            <div id="insre">porco dio</div>
            <div id="modre">porca madonna</div>
            <div id="showre">porco gesoo</div>
            <div id="asgnre">porco giuseppe</div>
            <div id="substre">porci re magi</div>
            <div id="statsre">porco abramo</div>
            <div id="showcmre">porco caino</div> */

        }
        
                //Mostra sostituisci arb
        function substreShow()
        {
            jQuery("#insre").css('display','none');
            jQuery("#modre").css('display','none');
            jQuery("#showre").css('display','none');
            jQuery("#asgnre").css('display','none');
            jQuery("#substre").css('display','block');
            jQuery("#statsre").css('display','none');
            jQuery("#showcmre").css('display','none');
            jQuery("#remenu").css('display','none');
            
/*            <div id="insre">porco dio</div>
            <div id="modre">porca madonna</div>
            <div id="showre">porco gesoo</div>
            <div id="asgnre">porco giuseppe</div>
            <div id="substre">porci re magi</div>
            <div id="statsre">porco abramo</div>
            <div id="showcmre">porco caino</div> */

        }
        
                //Mostra crea arb
        function statsreShow()
        {
            jQuery("#insre").css('display','none');
            jQuery("#modre").css('display','none');
            jQuery("#showre").css('display','none');
            jQuery("#asgnre").css('display','none');
            jQuery("#substre").css('display','none');
            jQuery("#statsre").css('display','block');
            jQuery("#showcmre").css('display','none');
            jQuery("#remenu").css('display','none');
            
/*            <div id="insre">porco dio</div>
            <div id="modre">porca madonna</div>
            <div id="showre">porco gesoo</div>
            <div id="asgnre">porco giuseppe</div>
            <div id="substre">porci re magi</div>
            <div id="statsre">porco abramo</div>
            <div id="showcmre">porco caino</div> */

        }
        
                //Mostra crea arb
        function showcmreShow()
        {
            jQuery("#insre").css('display','none');
            jQuery("#modre").css('display','none');
            jQuery("#showre").css('display','none');
            jQuery("#asgnre").css('display','none');
            jQuery("#substre").css('display','none');
            jQuery("#statsre").css('display','none');
            jQuery("#showcmre").css('display','block');
            jQuery("#remenu").css('display','none');
            
/*            <div id="insre">porco dio</div>
            <div id="modre">porca madonna</div>
            <div id="showre">porco gesoo</div>
            <div id="asgnre">porco giuseppe</div>
            <div id="substre">porci re magi</div>
            <div id="statsre">porco abramo</div>
            <div id="showcmre">porco caino</div> */

        }
        
        //Sezione AJAX
    </script>
    
        <script type="text/javascript">
        //Mostra crea arb
        function instmShow()
        {
            jQuery("#instm").css('display','block');
            jQuery("#modtm").css('display','none');
            jQuery("#showtm").css('display','none');
            jQuery("#asgntm").css('display','none');
            jQuery("#substtm").css('display','none');
            jQuery("#statstm").css('display','none');
            jQuery("#showcmtm").css('display','none');
            jQuery("#teamsmenu").css('display','none');
            
/*            <div id="insre">porco dio</div>
            <div id="modre">porca madonna</div>
            <div id="showre">porco gesoo</div>
            <div id="asgnre">porco giuseppe</div>
            <div id="substre">porci re magi</div>
            <div id="statsre">porco abramo</div>
            <div id="showcmre">porco caino</div> */

        }
        
        function instrShow()
        {
            jQuery("#instourn").css('display','block');
            jQuery("#modtourn").css('display','none');
            jQuery("#showtourn").css('display','none');
            jQuery("#asgntm").css('display','none');
            jQuery("#substtm").css('display','none');
            jQuery("#statstm").css('display','none');
            jQuery("#showcmtm").css('display','none');
            jQuery("#tournmenu").css('display','none');
            
/*            <div id="insre">porco dio</div>
            <div id="modre">porca madonna</div>
            <div id="showre">porco gesoo</div>
            <div id="asgnre">porco giuseppe</div>
            <div id="substre">porci re magi</div>
            <div id="statsre">porco abramo</div>
            <div id="showcmre">porco caino</div> */

        }
        
        function inscalShow()
        {
            jQuery("#inscal").css('display','block');
            jQuery("#modcal").css('display','none');
            jQuery("#showcal").css('display','none');
            jQuery("#asgntm").css('display','none');
            jQuery("#substtm").css('display','none');
            jQuery("#statstm").css('display','none');
            jQuery("#showcmtm").css('display','none');
            jQuery("#calfuncs").css('display','none');
            
/*            <div id="insre">porco dio</div>
            <div id="modre">porca madonna</div>
            <div id="showre">porco gesoo</div>
            <div id="asgnre">porco giuseppe</div>
            <div id="substre">porci re magi</div>
            <div id="statsre">porco abramo</div>
            <div id="showcmre">porco caino</div> */

        }
        
        function insplShow()
        {
            jQuery("#inspls").css('display','block');
            jQuery("#modpls").css('display','none');
            jQuery("#showpls").css('display','none');
            jQuery("#asgnpls").css('display','none');
            jQuery("#substtm").css('display','none');
            jQuery("#statstm").css('display','none');
            jQuery("#showcmtm").css('display','none');
            jQuery("#plsmenu").css('display','none');
            
/*            <div id="insre">porco dio</div>
            <div id="modre">porca madonna</div>
            <div id="showre">porco gesoo</div>
            <div id="asgnre">porco giuseppe</div>
            <div id="substre">porci re magi</div>
            <div id="statsre">porco abramo</div>
            <div id="showcmre">porco caino</div> */

        }
        </script>
        
        <script>
            $(document).ready(function() {
            var max_fields      = 500;
            var wrapper         = $(".container1");
            var add_button      = $(".add_form_field");
  
           var x = 1;
            $(add_button).click(function(e){
            e.preventDefault();
            if(x < max_fields){
                x++;
                $(wrapper).append('<?php echo '<fieldset><!--<input type="text" name="mytext[]">-->'
                                .'<label for="s1">Squadra 1</label>'
                                .'<select name="s1[]">';
                            $teams = r4fb::fetchSquadreTourn($_SESSION['tourn']);
                            
                            $max = sizeof($teams); //limitare res a prime 5 non disputate
                            for($i = 0; $i < $max;$i++)
                            {
                               
                                echo '<option value="'.$teams[$i]['id'].'">'.$teams[$i]['nome'].'</option>';
                            }                
                                echo '</select>'
                                .'<label for="s2">Squadra 2</label>'
                                .'<select name="s2[]">';
                            $teams = r4fb::fetchSquadreTourn($_SESSION['tourn']);
                            
                            $max = sizeof($teams); //limitare res a prime 5 non disputate
                            for($i = 0; $i < $max;$i++)
                            {
                               
                                echo '<option value="'.$teams[$i]['id'].'">'.$teams[$i]['nome'].'</option>';
                            }                
                                echo '</select>'
                                .'<label for="arbitro">Arbitro</label>'
                                .'<select name="arbitro[]">';
                            
                            $arbs = r4fb::fetchArbsTourn($_SESSION['tourn']);
                            $max = sizeof($arbs); //limitare res a prime 5 non disputate
                            for($i = 0; $i < $max;$i++)
                            {
                               echo '<option value="'.$arbs[$i]['id'].'">'.$arbs[$i]['nome'].'</option>';
                            }                
                                echo '</select>'
                                .'<label for="giornata">Giornata</label>'
                                .'<select name="giornata[]">';
                            for($i = 1; $i < 51;$i++)
                            {
                               
                                echo '<option value="'.$i.'">'.$i.'</option>';
                            }                
                                echo '</select>'
                                .'<label for="orario">Orario</label>'
                                    .'<input type="datetime-local" name="orario[]" />'
                                .'<label for="campo">Campo</label>'
                                        .'<select name="campo[]">'
                                        . '<option value="A">A</option>'
                                        . '<option value="B">B</option>'
                                        . '<option value="C">C</option>';
                        //    for($i = 1; $i < 11;$i++)
                        //    {
                               
                         //       echo '<option value="'.$i.'">'.$i.'</option>';
                        //    }                
                                echo '</select></fieldset>'?>'); //add input box
            }
            else
            {
                alert('You Reached the limits')
            }
            });
  
                $(wrapper).on("click",".delete", function(e){
                e.preventDefault(); $(this).parent('div').remove(); x--;
                })
            });
</script>
<script type="text/javascript">
    
           function openVote(tournid)
            {
                $.ajax(
                {
                    url:"ajax/v1/ajax.php",
                    type:"GET",
                    data:{op: "opvt", trn: tournid},
                    success:function(result)
                            {
                                $("div#stato").html("Partita terminata");
                            },
                    error:function(stato,errori)
                            {
                                $("div#stato").html("Errore"+stato+" "+errori);
                            }
                });
            }
            
            function closeVote(tournid)
            {
                $.ajax(
                {
                    url:"ajax/v1/ajax.php",
                    type:"GET",
                    data:{op: "clvt", trn: tournid},
                    success:function(result)
                            {
                                $("div#stato").html("Partita terminata");
                            },
                    error:function(stato,errori)
                            {
                                $("div#stato").html("Errore"+stato+" "+errori);
                            }
                });
            }
</script>
    </body>
</html>
