<?php

include "../../classes/app.class.php";
$app = new app();
$db = new DBMain();
$date_1 = date('Y-m-d');
$date_2 = date('Y-m-d', strtotime("+1 Days"));
$date_3 = date('Y-m-d', strtotime("+2 Days"));
$date_4 = date('Y-m-d', strtotime("+3 Days"));
$date_5 = date('Y-m-d', strtotime("+4 Days"));
$date_6 = date('Y-m-d', strtotime("+5 Days"));
$date_7 = date('Y-m-d', strtotime("+6 Days"));
$date_8 = date('Y-m-d', strtotime("+7 Days"));
if (isset($_GET['artisan_id'])) {
    $artisan_id = $_GET['artisan_id'];
} else {
    $artisan_id = 0;
}
?>


<div class='container flex_row'>
    <div class='container flex_column'>
    <h3>7 DAYS PLANNING</h3>
        <select onchange="change()" id='artisan_id'>
            <?php if ($artisan_id == 0) { ?>
                <option value=0>SELECT ARTISAN</option>
            <?php } else { ?>
                <option value='<?php echo $_GET['artisan_id']; ?>'><?php echo $db->get_user_name($_GET['artisan_id']); ?></option>
            <?php } ?>
            <?php echo $db->get_artisans_in_dropdown(); ?>
        </select>

        <script>
            function change() {
                window.location.href = 'jobcard_planning.php?artisan_id=' + document.getElementById('artisan_id').value;
            }
        </script>
        <input type="text" value='PENDING' readonly style='background-color: grey; color:white; margin-left:1%;' />
        <input type="text" value='OPEN' readonly style='background-color: green; color:white;  margin-left:1%;' />
        <input type="text" value='HOLD' readonly style='background-color: orange; color:white;  margin-left:1%;' />
        <input type="text" value='CLOSED' readonly style='background-color: black; color:white;  margin-left:1%;' />
    </div>
    <div class='flex_column flex_col_gap_1' style='width:98.5%; height:100%; border: 0px solid black; margin-top: 1%;'>
        <div class='flex_row' style='padding: 0.5%; min-height:10vw; height:100%; border: 1px solid black;'>
            <input type='text' value='OVERDUE' style='background-color: #145593; color:white;' readonly />

            <?php echo $db->sort_page_overdue($artisan_id); ?>
        </div>
        <div class='flex_row' style='padding: 0.5%; min-height:10vw; height:100%; border: 1px solid black;'>
            <input type='text' value='<?php echo date('l', strtotime($date_1)); ?> <?php echo $date_1; ?>' style='background-color: #145593; color:white;' readonly />

            <?php echo $db->sort_page($date_1, $artisan_id); ?>
        </div>
        <div class='flex_row' style='padding: 0.5%; min-height:10vw; height:100%; border: 1px solid black;'>
            <input type='text' value='<?php echo date('l', strtotime($date_2)); ?> <?php echo $date_2; ?>' style='background-color: #145593; color:white;' readonly />

            <?php echo $db->sort_page($date_2, $artisan_id); ?>

        </div>
        <div class='flex_row' style='padding: 0.5%; min-height:10vw; height:100%; border: 1px solid black;'>
            <input type='text' value='<?php echo date('l', strtotime($date_3)); ?> <?php echo $date_3; ?>' style='background-color: #145593; color:white;' readonly />

            <?php echo $db->sort_page($date_3, $artisan_id); ?>

        </div>
        <div class='flex_row' style='padding: 0.5%; min-height:10vw; height:100%; border: 1px solid black;'>
            <input type='text' value='<?php echo date('l', strtotime($date_4)); ?> <?php echo $date_4; ?>' style='background-color: #145593; color:white;' readonly />

            <?php echo $db->sort_page($date_4, $artisan_id); ?>

        </div>
        <div class='flex_row' style='padding: 0.5%; min-height:10vw; height:100%; border: 1px solid black;'>
            <input type='text' value='<?php echo date('l', strtotime($date_5)); ?> <?php echo $date_5; ?>' style='background-color: #145593; color:white;' readonly />


            <?php echo $db->sort_page($date_5, $artisan_id); ?>
        </div>
        <div class='flex_row' style='padding: 0.5%; min-height:10vw; height:100%; border: 1px solid black;'>
            <input type='text' value='<?php echo date('l', strtotime($date_6)); ?> <?php echo $date_6; ?>' style='background-color: #145593; color:white;' readonly />


            <?php echo $db->sort_page($date_6, $artisan_id); ?>
        </div>
        <div class='flex_row' style='padding: 0.5%; min-height:10vw; height:100%; border: 1px solid black;'>
            <input type='text' value='<?php echo date('l', strtotime($date_7)); ?> <?php echo $date_7; ?>' style='background-color: #145593; color:white;' readonly />

            <?php echo $db->sort_page($date_7, $artisan_id); ?>

        </div>

    </div>

    <script>
        function move_up(id) {
            var xhttp = new XMLHttpRequest();
            xhttp.onload = function() {
                // alert(this.responseText);
                if (this.responseText == 1) {
                    // alert('User added successfully');
                    window.location.href = 'jobcard_planning.php?artisan_id=' + <?php echo $artisan_id; ?>;
                }

            }
            xhttp.open('GET', '../../ajax/jobcards/move_jobcard.php?record_id=' + id + '&direction=up', true);
            xhttp.send();
        }

        function move_back(id) {
            var xhttp = new XMLHttpRequest();
            xhttp.onload = function() {
                // alert(this.responseText);
                if (this.responseText == 1) {
                    // alert('User added successfully');
                    window.location.href = 'jobcard_planning.php?artisan_id=' + <?php echo $artisan_id; ?>;
                }

            }
            xhttp.open('GET', '../../ajax/jobcards/move_jobcard.php?record_id=' + id + '&direction=down', true);
            xhttp.send();
        }

        function show_settings(id) {
            document.getElementById('jobcard-' + id).style.display = 'block';
            documnet.getElementById('container_of_jc-' + id).style.border = '2px solid black';
            documnet.getElementById('container_of_jc-' + id).style.padding = '5px';


        }

        function hide_settings(id) {
            document.getElementById('jobcard-' + id).style.display = 'none';
            documnet.getElementById('container_of_jc-' + id).style.border = '0px solid black';
            documnet.getElementById('container_of_jc-' + id).style.padding = '0px';
        }

        function hold_jobcard(id) {

            var xhttp = new XMLHttpRequest();
            xhttp.onload = function() {
                // alert(this.responseText);
                if (this.responseText == 1) {
                    // alert('User added successfully');
                    window.location.href = 'jobcard_planning.php?artisan_id=' + <?php echo $artisan_id; ?>;
                }
            }
            xhttp.open('GET', '../../ajax/jobcards/hold_jobcard.php?record_id=' + id, true);
            xhttp.send();
        }

        function re_open_jobcard(id) {

            var xhttp = new XMLHttpRequest();
            xhttp.onload = function() {
                // alert(this.responseText);
                if (this.responseText == 1) {
                    // alert('User added successfully');
                    window.location.href = 'jobcard_planning.php?artisan_id=' + <?php echo $artisan_id; ?>;
                }
            }
            xhttp.open('GET', '../../ajax/jobcards/re_open_jobcard.php?record_id=' + id, true);
            xhttp.send();
        }
    </script>