<?php 
    session_start();

    if (!isset($_SESSION['username'])){
        echo ("<script>location.href = 'login.php';</script>");
    }


    include "../connection.php";
    include "../function.php";



    if (isset($_GET["deleteID"])){
        $deleteID = $_GET["deleteID"];
        $email = "";

        $sql = "SELECT *  FROM $rezervaceTable WHERE id=$deleteID";
        $result = mysqli_query($conn, $sql);
        if (mysqli_num_rows($result)>0) {
            while ($row = mysqli_fetch_assoc($result)) {
                    $email=$row['email']; 
            }
        }
        if ($email!="") {
            sendMail("","","","","",$email,"delete");
        }
        

        $delete=mysqli_query($conn, "DELETE FROM $rezervaceTable WHERE id=$deleteID");

        
    }

        $todayDate = (date("Y-m-d"));

        $sql = "SELECT *  FROM $rezervaceTable INNER JOIN $sluzbyTable ON $rezervaceTable.id_sluzby=$sluzbyTable.id_sluzby WHERE DATE(`datum`) = DATE(NOW()) AND $sluzbyTable.id_typSluzby = 1 ORDER BY datum";
        $result_kadernictvi = mysqli_query($conn, $sql);


        $sql = "SELECT *  FROM $rezervaceTable INNER JOIN $sluzbyTable ON $rezervaceTable.id_sluzby=$sluzbyTable.id_sluzby WHERE DATE(`datum`) = DATE(NOW()) AND $sluzbyTable.id_typSluzby = 2 ORDER BY datum";
        $result_kosmetika = mysqli_query($conn, $sql);


        $sql = "SELECT *  FROM $rezervaceTable INNER JOIN $sluzbyTable ON $rezervaceTable.id_sluzby=$sluzbyTable.id_sluzby WHERE DATE(`datum`) = DATE(NOW()) AND $sluzbyTable.id_typSluzby = 3 ORDER BY datum";
        $result_manikura = mysqli_query($conn, $sql);


        $sql = "SELECT *  FROM $rezervaceTable INNER JOIN $sluzbyTable ON $rezervaceTable.id_sluzby=$sluzbyTable.id_sluzby WHERE DATE(`datum`) = DATE(NOW()) AND $sluzbyTable.id_typSluzby = 4 ORDER BY datum";
        $result_pedikura = mysqli_query($conn, $sql);




    $conn->close();
?>















<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Kadeřnictví Hrdlořezy - Admin</title>
    <link rel="stylesheet" href="../styleKadernictvi.css">
    <link rel="stylesheet" href="styleAdmin.css">
</head>
<body>

    <button><img class="menuIcon lg:hidden" src="../img/menu_icon.png" alt=""></button>

    <nav class="mainMenu">           
        <a class="block text-2xl mx-auto navBtnPhone phoneNavLine nav-sluzby-phone font-bold active" href="index.php">DNEŠNÍ TERMÍNY</a>
        <a class="block text-2xl mx-auto navBtnPhone phoneNavLine nav-sluzby-phone font-bold" href="kadernictvi.php">KADEŘNICTVÍ</a>
        <a class="block text-2xl mx-auto navBtnPhone phoneNavLine nav-foto-phone font-bold " href="kosmetika.php">KOSMETIKA</a>
        <a class="block text-2xl mx-auto navBtnPhone phoneNavLine nav-onas-phone font-bold" href="manikura.php">MANIKÚRA</a>             
        <a class="block text-2xl mx-auto navBtnPhone phoneNavLine nav-kontakt-phone border-gray-300 font-bold" href="pedikura.php">PEDIKÚRA</a>
        <?php
            if ($_SESSION["admin"]==1) {
                ?>
                    <a id="uzivateleBtn" class="block text-2xl mx-auto navBtnPhone phoneNavLine nav-kontakt-phone border-b border-gray-300 font-bold"  href="users.php">UŽIVATELÉ</a>
                <?php
            }
        ?>
        
        
    </nav>
        <div class="logoutDiv hidden lg:visible">
            <p>uživatel: <b><?php echo $_SESSION['username']; ?></b></p>
            <span>|</span>
            <a class="logoutBtn" href="logout.php">ODHLÁSIT</a>
        </div>
    <nav>
        <div class="mainMenuPhone justify-center justify-items-center text-center z-50  p-0 mt-0 lg:hidden">
            <a class="block text-2xl mx-auto navBtnPhone phoneNavLine nav-sluzby-phone font-bold active" href="index.php">DNEŠNÍ TERMÍNY</a>
            <a class="block text-2xl mx-auto navBtnPhone phoneNavLine nav-sluzby-phone font-bold" href="kadernictvi.php">KADEŘNICTVÍ</a>
            <a class="block text-2xl mx-auto navBtnPhone phoneNavLine nav-foto-phone font-bold " href="kosmetika.php">KOSMETIKA</a>
            <a class="block text-2xl mx-auto navBtnPhone phoneNavLine nav-onas-phone font-bold" href="manikura.php">MANIKÚRA</a>             
            <a class="block text-2xl mx-auto navBtnPhone phoneNavLine nav-kontakt-phone border-gray-300 font-bold" href="pedikura.php">PEDIKÚRA</a>
            <?php
                if ($_SESSION["admin"]==1) {
                    ?>
                        <a class="block text-2xl mx-auto navBtnPhone phoneNavLine nav-kontakt-phone border-gray-300 font-bold" href="users.php">UŽIVATELÉ</a>
                    <?php
                }
            ?>  
            <a class="block text-2xl mx-auto navBtnPhone phoneNavLine nav-kontakt-phone border-b border-gray-300 font-bold logoutBtn" href="logout.php">ODHLÁSIT</a>
        </div>
    </nav>

    <header class="updateHeader lg:hidden">
        Dnešní termíny
    </header>
        

        <section class="mt-20 lg:mt-40">
            <h2 class="mb-4" >KADEŘNICTVÍ</h2>
            <table class="rezervaceTable">
                <tr>
                    <th>Jmeno</th>
                    <th>Služba</td>
                    <th>Čas</td>
                    <th>Akce</th>               
                </tr>

                <?php
                    if (mysqli_num_rows($result_kadernictvi) > 0) {
                        while($row = mysqli_fetch_array($result_kadernictvi)) 
                        {
                            echo "
                                <tr>
                                    <td class='w-1/4'>".$row["jmeno"] ."</td>
                                    <td class='w-1/4'>".$row["nazev"] ."</td>
                                    <td class='w-1/4'>".$row["cas_zacatek"] ."</td>
                                    <td class='buttons w-1/4'>"?>

                                    <?php if ($_SESSION['typSluzby']==1 || $_SESSION['admin']==1) {      
                                        ?>
                                            <a onclick="return confirm('Opravdu smazat?')" class='delete' href='index.php?deleteID=<?php echo $row['id'];?>'>X</a>
                                            <a class='update' target="_blank" href='update.php?updateID=<?php echo $row['id'];?>&sluzbaTyp=kadeřnictví'>></a>
                                        <?php
                                    } ?>

                                    <?php "
                                    </td>                                
                                    
                                </tr>
                            ";
                        }
                    }
                    else{
                        echo "<tr class='w-full' ><td colspan='4' class='text-center my-16  text-lg py-10 w-full'>- žádné rezervace -<td><tr>";
                    }
                ?>
            </table>
        </section>

        <section>
            <h2 class="mb-4">KOSMETIKA</h2>
            <table class="rezervaceTable">
                <tr>
                    <th>Jmeno</th>
                    <th>Služba</td>
                    <th>Čas</td>
                    <th>Akce</th>               
                </tr>

                <?php
                    if (mysqli_num_rows($result_kosmetika) > 0) {
                        while($row = mysqli_fetch_array($result_kosmetika)) 
                        {
                            echo "
                                <tr>
                                    <td class='w-1/4'>".$row["jmeno"] ."</td>
                                    <td class='w-1/4'>".$row["nazev"] ."</td>
                                    <td class='w-1/4'>".$row["cas_zacatek"] ."</td>
                                    <td class='buttons w-1/4'>"?>
                                    
                                    <?php if ($_SESSION['typSluzby']==2 || $_SESSION['admin']==1) {      
                                        ?>
                                            <a onclick="return confirm('Opravdu smazat?')" class='delete' href='index.php?deleteID=<?php echo $row['id'];?>'>X</a>
                                            <a class='update' target="_blank" href='update.php?updateID=<?php echo $row['id'];?>&sluzbaTyp=kosmetika'>></a>  
                                        <?php
                                    } ?>
                                        
                                        <?php "
                                    </td> 
                                    
                                </tr>
                            ";
                        }
                    }
                    else{
                        echo "<tr class='w-full' ><td colspan='4' class='text-center my-16  text-lg py-10 w-full'>- žádné rezervace -<td><tr>";
                    }

                ?>
            </table>
        </section>

        <section>
            <h2 class="mb-4" >MANIKÚRA</h2>
            <table class="rezervaceTable">
                <tr>
                    <th>Jmeno</th>
                    <th>Služba</td>
                    <th>Čas</td>
                    <th>Akce</th>               
                </tr>

                <?php
                    if (mysqli_num_rows($result_manikura) > 0) {
                        while($row = mysqli_fetch_array($result_manikura)) 
                        {
                            echo "
                                <tr>
                                    <td class='w-1/4'>".$row["jmeno"] ."</td>
                                    <td class='w-1/4'>".$row["nazev"] ."</td>
                                    <td class='w-1/4'>".$row["cas_zacatek"] ."</td>
                                    <td class='buttons w-1/4'>"?>
                                    <?php if ($_SESSION['typSluzby']==3 || $_SESSION['admin']==1) {      
                                        ?>
                                            <a onclick="return confirm('Opravdu smazat?')" class='delete' href='index.php?deleteID=<?php echo $row['id'];?>'>X</a>
                                            <a class='update' target="_blank" href='update.php?updateID=<?php echo $row['id'];?>&sluzbaTyp=manikúra'>></a>  
                                        <?php
                                    } ?>
                                        
                                        <?php "
                                    </td> 
                                    
                                </tr>
                            ";
                        }
                    }
                    else{
                        echo "<tr class='w-full' ><td colspan='4' class='text-center my-16  text-lg py-10 w-full'>- žádné rezervace -<td><tr>";
                    }

                ?>
            </table>
        </section>

        <section>
            <h2 class="mb-4" >PEDIKÚRA</h2>
            <table class="rezervaceTable">
                <tr>
                    <th>Jmeno</th>
                    <th>Služba</td>
                    <th>Čas</td>
                    <th>Akce</th>               
                </tr>

                <?php
                    if (mysqli_num_rows($result_pedikura) > 0) {
                        while($row = mysqli_fetch_array($result_pedikura)) 
                        {
                            echo "
                                <tr>
                                    <td class='w-1/4'>".$row["jmeno"] ."</td>
                                    <td class='w-1/4'>".$row["nazev"] ."</td>
                                    <td class='w-1/4'>".$row["cas_zacatek"] ."</td>
                                    <td class='buttons w-1/4'>"?>
                                    <?php if ($_SESSION['typSluzby']==4 || $_SESSION['admin']==1) {      
                                        ?>
                                            <a onclick="return confirm('Opravdu smazat?')" class='delete' href='index.php?deleteID=<?php echo $row['id'];?>'>X</a>
                                            <a class='update' target="_blank" href='update.php?updateID=<?php echo $row['id'];?>&sluzbaTyp=pedikúra'>></a>  
                                        <?php
                                    } ?>
                                        
                                        <?php "
                                    </td> 
                                    
                                </tr>
                            ";
                        }
                    }
                    else{
                        echo "<tr class='w-full' ><td colspan='4' class='text-center my-16  text-lg py-10 w-full'>- žádné rezervace -<td><tr>";
                    }
                ?>
            </table>
        </section>





    <script src="../scriptKadernictvi.js"></script>
    <script src="scriptAdmin.js"></script>
</body>
</html>