<?php
	session_start();
	include 'prijava/connect.php';
    setlocale(LC_TIME,"hr_HR");
?>
<!DOCTYPE html>
<head>
    <?php
        define('meta', TRUE);
        include 'inc/head.php';
    ?>
    <script src="js/mark-order.js"></script>
    <title>Narudžbe - KrikStudio</title>
</head>
<body>
    <?php
        if(!isset($_SESSION['username']) || $_SESSION['admin'] == 0) {
            echo '<script>';
            echo 'window.location.href="./"';
            echo '</script>';
        }
        define('nav', TRUE);
        include 'inc/nav.php';
        include 'inc/five-days.php';
    ?>

    <section class="orders">
        <div class="wrapper">
            <h2>NARUDŽBE<a class="all-history-btn" href="./sva-povijest"><i data-feather="archive"></i>Sve narudžbe</a></h2>
            <p class="today__date"><b>
                <?php
                    if ($day1->format('D')=="Mon") {
                        echo "Ponedjeljak, "; 
                    } else if ($day1->format("D") == "Tue") {
                        echo "Utorak, "; 
                    } else if ($day1->format("D") == "Wed") {
                        echo "Srijeda, "; 
                    } else if ($day1->format("D") == "Thu") {
                        echo "Četvrtak, "; 
                    } else if ($day1->format("D") == "Fri") {
                        echo "Petak, "; 
                    }
                    echo $day1->format('d.m.Y.'); 
                ?>
            </b></p>

            <div class="today__list">
                <table>
                    <thead>
                        <tr>
                            <th>MENU A</th>
                            <th>MENU B</th>
                            <th>MENU C</th>
                            <th>MENU D</th>
                            <th>MENU E</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next' AND menu = 'A'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countA = $data['total'];
                                echo $countA;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next' AND menu = 'B'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countB = $data['total'];
                                echo $countB;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next' AND menu = 'C'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countC = $data['total'];
                                echo $countC;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next' AND menu = 'D'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countD = $data['total'];
                                echo $countD;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next' AND menu = 'E'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countE = $data['total'];
                                echo $countE;
                            ?></td>
                        </tr>
                    </tbody>
                </table>
                <p class="orders-sum">UKUPNO NARUDŽBI: 
                    <?php
                        $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next'";
                        $result = mysqli_query($dbc, $query);
                        $data = mysqli_fetch_array($result);
                        echo $data['total'];
                    ?>
                </p>

                <?php 
                    if($_SESSION['dir'] == 1 AND ($countA != 0 OR $countB != 0 OR $countC != 0 OR $countD != 0 OR $countE != 0)) {
                        if($dbc) {
                            $query = "SELECT finish FROM complete WHERE date = '$next'";
                            $result = mysqli_query($dbc,$query) or die('Error querying database.');
                            if (mysqli_num_rows($result) == 0) { ?>
                                <button class="mark-done-btn" onclick="markOrder('<?php echo $next ?>')">NARUČENO</button>
                            <?php } else {
                                echo "<button class='order-complete'>NARUČENO</button>";
                            }   
                        }
                    } 
                ?>
            </div>
            <div class="accordion">
                <input type="checkbox" id="day-1">
                <h1><label for="day-1">DETALJI NARUDŽBE<i data-feather="chevron-down"></i></label></h1>
                <div class="p">
                    <p><b>MENU A</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next' AND menu = 'A'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU B</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next' AND menu = 'B'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU C</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next' AND menu = 'C'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU D</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next' AND menu = 'D'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU E</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next' AND menu = 'E'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                </div>
            </div>

            <!-- DAY #2 -->
            <p class="today__date"><b>
                <?php 
                    if ($day2->format('D')=="Mon") {
                        echo "Ponedjeljak, "; 
                    } else if ($day2->format("D") == "Tue") {
                        echo "Utorak, "; 
                    } else if ($day2->format("D") == "Wed") {
                        echo "Srijeda, "; 
                    } else if ($day2->format("D") == "Thu") {
                        echo "Četvrtak, "; 
                    } else if ($day2->format("D") == "Fri") {
                        echo "Petak, "; 
                    }
                    echo $day2->format('d.m.Y.'); 
                ?>
            </b></p>

            <div class="today__list">
                <table>
                    <thead>
                        <tr>
                            <th>MENU A</th>
                            <th>MENU B</th>
                            <th>MENU C</th>
                            <th>MENU D</th>
                            <th>MENU E</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next2' AND menu = 'A'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countA = $data['total'];
                                echo $countA;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next2' AND menu = 'B'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countB = $data['total'];
                                echo $countB;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next2' AND menu = 'C'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countC = $data['total'];
                                echo $countC;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next2' AND menu = 'D'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countD = $data['total'];
                                echo $countD;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next2' AND menu = 'E'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countE = $data['total'];
                                echo $countE;
                            ?></td>
                        </tr>
                    </tbody>
                </table>
                <p class="orders-sum">UKUPNO NARUDŽBI: 
                    <?php
                        $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next2'";
                        $result = mysqli_query($dbc, $query);
                        $data = mysqli_fetch_array($result);
                        echo $data['total'];
                    ?>
                </p>

                <?php 
                    if($_SESSION['dir'] == 1 AND ($countA != 0 OR $countB != 0 OR $countC != 0 OR $countD != 0 OR $countE != 0)) {
                        if($dbc) {
                            $query = "SELECT finish FROM complete WHERE date = '$next2'";
                            $result = mysqli_query($dbc,$query) or die('Error querying database.');
                            if (mysqli_num_rows($result) == 0) { ?>
                                <button class="mark-done-btn" onclick="markOrder('<?php echo $next2 ?>')">NARUČENO</button>
                            <?php } else {
                                echo "<button class='order-complete'>NARUČENO</button>";
                            }   
                        }
                    } 
                ?>
            </div>
            <div class="accordion">
                <input type="checkbox" id="day-2">
                <h1><label for="day-2">DETALJI NARUDŽBE<i data-feather="chevron-down"></i></label></h1>
                <div class="p">
                    <p><b>MENU A</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next2' AND menu = 'A'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU B</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next2' AND menu = 'B'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU C</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next2' AND menu = 'C'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU D</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next2' AND menu = 'D'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU E</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next2' AND menu = 'E'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                </div>
            </div>

            <!-- DAY #3 -->
            <p class="today__date"><b>
                <?php 
                    if ($day3->format('D')=="Mon") {
                        echo "Ponedjeljak, "; 
                    } else if ($day3->format("D") == "Tue") {
                        echo "Utorak, "; 
                    } else if ($day3->format("D") == "Wed") {
                        echo "Srijeda, "; 
                    } else if ($day3->format("D") == "Thu") {
                        echo "Četvrtak, "; 
                    } else if ($day3->format("D") == "Fri") {
                        echo "Petak, "; 
                    }
                    echo $day3->format('d.m.Y.'); 
                ?>
            </b></p>

            <div class="today__list">
                <table>
                    <thead>
                        <tr>
                            <th>MENU A</th>
                            <th>MENU B</th>
                            <th>MENU C</th>
                            <th>MENU D</th>
                            <th>MENU E</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next3' AND menu = 'A'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countA = $data['total'];
                                echo $countA;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next3' AND menu = 'B'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countB = $data['total'];
                                echo $countB;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next3' AND menu = 'C'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countC = $data['total'];
                                echo $countC;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next3' AND menu = 'D'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countD = $data['total'];
                                echo $countD;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next3' AND menu = 'E'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countE = $data['total'];
                                echo $countE;
                            ?></td>
                            <!-- <td><b><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next3'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                echo $data['total'];
                            ?></b></td> -->
                        </tr>
                    </tbody>
                </table>
                <p class="orders-sum">UKUPNO NARUDŽBI: 
                    <?php
                        $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next3'";
                        $result = mysqli_query($dbc, $query);
                        $data = mysqli_fetch_array($result);
                        echo $data['total'];
                    ?>
                </p>

                <?php 
                    if($_SESSION['dir'] == 1 AND ($countA != 0 OR $countB != 0 OR $countC != 0 OR $countD != 0 OR $countE != 0)) {
                        if($dbc) {
                            $query = "SELECT finish FROM complete WHERE date = '$next3'";
                            $result = mysqli_query($dbc,$query) or die('Error querying database.');
                            if (mysqli_num_rows($result) == 0) { ?>
                                <button class="mark-done-btn" onclick="markOrder('<?php echo $next3 ?>')">NARUČENO</button>
                            <?php } else {
                                echo "<button class='order-complete'>NARUČENO</button>";
                            }   
                        }
                    } 
                ?>
            </div>
            <div class="accordion">
                <input type="checkbox" id="day-3">
                <h1><label for="day-3">DETALJI NARUDŽBE<i data-feather="chevron-down"></i></label></h1>
                <div class="p">
                    <p><b>MENU A</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next3' AND menu = 'A'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU B</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next3' AND menu = 'B'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU C</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next3' AND menu = 'C'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU D</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next3' AND menu = 'D'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU E</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next3' AND menu = 'E'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                </div>
            </div>

            <!-- DAY #4 -->
            <p class="today__date"><b>
                <?php 
                    if ($day4->format('D')=="Mon") {
                        echo "Ponedjeljak, "; 
                    } else if ($day4->format("D") == "Tue") {
                        echo "Utorak, "; 
                    } else if ($day4->format("D") == "Wed") {
                        echo "Srijeda, "; 
                    } else if ($day4->format("D") == "Thu") {
                        echo "Četvrtak, "; 
                    } else if ($day4->format("D") == "Fri") {
                        echo "Petak, "; 
                    }
                    echo $day4->format('d.m.Y.'); 
                ?>
            </b></p>

            <div class="today__list">
                <table>
                    <thead>
                        <tr>
                            <th>MENU A</th>
                            <th>MENU B</th>
                            <th>MENU C</th>
                            <th>MENU D</th>
                            <th>MENU E</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next4' AND menu = 'A'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countA = $data['total'];
                                echo $countA;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next4' AND menu = 'B'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countB = $data['total'];
                                echo $countB;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next4' AND menu = 'C'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countC = $data['total'];
                                echo $countC;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next4' AND menu = 'D'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countD = $data['total'];
                                echo $countD;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next4' AND menu = 'E'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countE = $data['total'];
                                echo $countE;
                            ?></td>
                            <!-- <td><b><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next4'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                echo $data['total'];
                            ?></b></td> -->
                        </tr>
                    </tbody>
                </table>
                <p class="orders-sum">UKUPNO NARUDŽBI: 
                    <?php
                        $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next4'";
                        $result = mysqli_query($dbc, $query);
                        $data = mysqli_fetch_array($result);
                        echo $data['total'];
                    ?>
                </p>

                <?php 
                    if($_SESSION['dir'] == 1 AND ($countA != 0 OR $countB != 0 OR $countC != 0 OR $countD != 0 OR $countE != 0)) {
                        if($dbc) {
                            $query = "SELECT finish FROM complete WHERE date = '$next4'";
                            $result = mysqli_query($dbc,$query) or die('Error querying database.');
                            if (mysqli_num_rows($result) == 0) { ?>
                                <button class="mark-done-btn" onclick="markOrder('<?php echo $next4 ?>')">NARUČENO</button>
                            <?php } else {
                                echo "<button class='order-complete'>NARUČENO</button>";
                            }   
                        }
                    } 
                ?>
            </div>
            <div class="accordion">
                <input type="checkbox" id="day-4">
                <h1><label for="day-4">DETALJI NARUDŽBE<i data-feather="chevron-down"></i></label></h1>
                <div class="p">
                    <p><b>MENU A</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next4' AND menu = 'A'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU B</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next4' AND menu = 'B'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU C</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next4' AND menu = 'C'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU D</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next4' AND menu = 'D'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU E</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next4' AND menu = 'E'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                </div>
            </div>

            <!-- DAY #5 -->
            <p class="today__date"><b>
                <?php 
                    if ($day5->format('D')=="Mon") {
                        echo "Ponedjeljak, "; 
                    } else if ($day5->format("D") == "Tue") {
                        echo "Utorak, "; 
                    } else if ($day5->format("D") == "Wed") {
                        echo "Srijeda, "; 
                    } else if ($day5->format("D") == "Thu") {
                        echo "Četvrtak, "; 
                    } else if ($day5->format("D") == "Fri") {
                        echo "Petak, "; 
                    }
                    echo $day5->format('d.m.Y.'); 
                ?>
            </b></p>

            <div class="today__list">
                <table>
                    <thead>
                        <tr>
                            <th>MENU A</th>
                            <th>MENU B</th>
                            <th>MENU C</th>
                            <th>MENU D</th>
                            <th>MENU E</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next5' AND menu = 'A'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countA = $data['total'];
                                echo $countA;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next5' AND menu = 'B'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countB = $data['total'];
                                echo $countB;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next5' AND menu = 'C'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countC = $data['total'];
                                echo $countC;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next5' AND menu = 'D'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countD = $data['total'];
                                echo $countD;
                            ?></td>
                            <td><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next5' AND menu = 'E'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                $countE = $data['total'];
                                echo $countE;
                            ?></td>
                            <!-- <td><b><?php
                                $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next5'";
                                $result = mysqli_query($dbc, $query);
                                $data = mysqli_fetch_array($result);
                                echo $data['total'];
                            ?></b></td> -->
                        </tr>
                    </tbody>
                </table>
                <p class="orders-sum">UKUPNO NARUDŽBI: 
                    <?php
                        $query="SELECT COUNT(*) AS total FROM orders WHERE date = '$next5'";
                        $result = mysqli_query($dbc, $query);
                        $data = mysqli_fetch_array($result);
                        echo $data['total'];
                    ?>
                </p>

                <?php 
                    if($_SESSION['dir'] == 1 AND ($countA != 0 OR $countB != 0 OR $countC != 0 OR $countD != 0 OR $countE != 0)) {
                        if($dbc) {
                            $query = "SELECT finish FROM complete WHERE date = '$next5'";
                            $result = mysqli_query($dbc,$query) or die('Error querying database.');
                            if (mysqli_num_rows($result) == 0) { ?>
                                <button class="mark-done-btn" onclick="markOrder('<?php echo $next5 ?>')">NARUČENO</button>
                            <?php } else {
                                echo "<button class='order-complete'>NARUČENO</button>";
                            }   
                        }
                    } 
                ?>
            </div>
            <div class="accordion">
                <input type="checkbox" id="day-5">
                <h1><label for="day-5">DETALJI NARUDŽBE<i data-feather="chevron-down"></i></label></h1>
                <div class="p">
                    <p><b>MENU A</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next5' AND menu = 'A'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU B</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next5' AND menu = 'B'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU C</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next5' AND menu = 'C'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU D</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next5' AND menu = 'D'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                    <p><b>MENU E</b> <?php
                        $query="SELECT * FROM orders WHERE date = '$next5' AND menu = 'E'";
                        $result = mysqli_query($dbc, $query);
                        if($result) {
                            while($row = mysqli_fetch_array($result)) {
                                echo "| ".$row['user']." ";
                            }
                        }
                    ?></p>
                </div>
            </div>
        </div>
    </section>

    <?php define('footer', TRUE);include 'inc/footer.php'; ?>

    <script>
        feather.replace();
    </script>
</body>