<?php include('include/auth.php'); 
if (isset($_GET['type'])  && $_GET['type']!=0) {
    $type=$_GET['type'];}
    else {$type=0;}
  
        if (isset($_GET['status'])  && $_GET['status']!=3) {
            $status=$_GET['status'];}
            else {$status=3;}
?>
<!doctype html>
<html class="fixed dark">
<?php 
	$pagerole="lists";
	include('include/head.php');?>
<style>
    .green {
        color: green !important;
    }

    .red {
        color: red !important;
    }
</style>

<body>
    <section class="body">

        <!-- start: header -->
        <header class="header">
            <div class="logo-container">
                <a href="index.php" class="logo">
                    <img src="img/logo-light.png" width="75" height="35" alt="Web Voyage" />
                </a>
                <div class="d-md-none toggle-sidebar-left" data-toggle-class="sidebar-left-opened" data-target="html"
                    data-fire-event="sidebar-left-opened">
                    <i class="fas fa-bars" aria-label="Toggle sidebar"></i>
                </div>
            </div>

            <!-- start: search & user box -->
            <div class="header-right">
                <?php include('include/search.php');?>


                <span class="separator"></span>
                <?php include('include/notifications.php');?>


                <span class="separator"></span>
                <?php include('include/userbox.php');?>

            </div>
            <!-- end: search & user box -->
        </header>
        <!-- end: header -->

        <div class="inner-wrapper">
            <!-- start: sidebar -->
            <?php include('include/nav.php');?>
            <!-- end: sidebar -->

            <section role="main" class="content-body">
                <header class="page-header">
                    <h2>Tasks Overview</h2>

                    <div class="right-wrapper text-right">
                        <ol class="breadcrumbs">
                            <li>
                                <a href="index.php">
                                    <i class="fas fa-home"></i>
                                </a>
                            </li>
                            <li><span>WV Admin</span></li>
                            <li><span>Tasks Overview</span></li>
                        </ol>

                        <a class="sidebar-right-toggle" data-open="sidebar-right"><i
                                class="fas fa-chevron-left"></i></a>
                    </div>
                </header>
               
                  <h3>Filters</h3>
                <div class="row mb-0">

                    <div class="col-md-4"> <label>Task Status</label>
                        <select class="form-control populate" onChange="window.location.href=this.value">
                        <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("status"=>3)))?>"
                                <?php if($status==3) { echo "selected";} ?>>
                                All</option>
                        <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("status"=>0)))?>"
                                <?php if($status==0) { echo "selected";} ?>>
                                In Progress</option>
                                <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("status"=>1)))?>"
                                <?php if($status==1) { echo "selected";} ?>>
                                Completed</option>
                                
                            </select>
                    </div>
                    <div class="col-md-4"> <label>Task Type</label>
                        <select class="form-control populate" onChange="window.location.href=this.value">
                        <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("type"=>0)))?>"
                                <?php if($type==0) { echo "selected";} ?>>
                                All</option>
                                <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("type"=>1)))?>"
                                <?php if($type==1) { echo "selected";} ?>>
                                Sent</option>
                                <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("type"=>2)))?>"
                                <?php if($type==2) { echo "selected";} ?>>
                                Received</option>
                            </select>
                    </div>
                
                     </div>        
                <div class="row">
                    <div class="col">
                        <section class="card">
                            <header class="card-header">
                                <div class="card-actions">
                                    <a href="#" class="card-action card-action-toggle" data-card-toggle></a>
                                    <a href="#" class="card-action card-action-dismiss" data-card-dismiss></a>
                                </div>

                                <h2 class="card-title">Tasks Overview</h2>
                            </header>

                            <div class="card-body">

                                <table class="table table-bordered table-striped mb-0" id="datatable-tabletools">
                                    <thead>
                                        <tr>
                                            <th>ID</th>
                                            <th>From</th>
                                            <th>To</th>
                                            <th>Title</th>
                                            <th>Start</th>
                                            <th>End</th>
                                            <th>Show</th>
                                            <th>Status</th>
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>

                                        <?php 
                                                    $sql = "SELECT * FROM tasks ";
                                                    if ($status=='2' || $status=='1'){
                                                        $sql .=" WHERE tasks.task_status='$status' ";
                                                        }
                                                    if ($type=='0'){
                                                        $sql .=" WHERE tasks.task_to='$userid' OR tasks.task_from='$userid' ";
                                                        
                                                    }
                                                    
                                                     elseif($type=='1'){
                                                            $sql .=" WHERE tasks.task_from='$userid' ";
                                                            }
    
                                                    elseif($type=='2'){
                                                            $sql .=" WHERE tasks.task_to='$userid' ";
                                                            } 
                                                    
                                                       
                                                        
                                        $result = mysqli_query($db2,$sql);

                                        if ($result->num_rows > 0) {
                                            // output data of each row
                                        while($row = mysqli_fetch_array($result)) {
                                            $fromuser=$row['task_from'];
                                            $sqlu2 = $db->query("SELECT * FROM users WHERE users.id='$fromuser' ") or die(mysql_error());    
                                            $rowu2 = mysqli_fetch_array( $sqlu2 );
                                            $touser=$row['task_to'];
                                            $sqlu3 = $db->query("SELECT * FROM users WHERE users.id='$touser' ") or die(mysql_error());    
                                            $rowu3 = mysqli_fetch_array( $sqlu3 );
                                            $sst2=date("d/m/y", strtotime($row['task_start_date']));
					$eet2=date("d/m/y", strtotime($row['task_end_date']));
                    $startdatetime=$sst2." @ ".$row['task_start_time'];
                    $enddatetime=$eet2." @ ".$row['task_end_time'];
									 ?>

                                        <tr>
                                            <td><?php echo $row["task_id"]; ?></td>
                                            <td class="text-center"><?php echo $rowu2["username"]; ?></td>
                                            <td class="text-center"><?php echo $rowu3["username"]; ?></td>

                                            <td class="text-center "><?php echo $row["task_name"];?></td>
                                           
                                                <td class="text-center" ><?php echo $startdatetime;?></td>
                                                <td class="text-center" ><?php echo $enddatetime;?></td>
                                                <td class="text-center "><?php  if ($row['task_seen']=="1") { echo "Yes";} else {echo "No";}?></td>
                                                <td class="text-center "><?php  if ($row["task_status"]=="1") {echo "Completed";} else {echo "In Progress";}?></td>
                                            <td class="actions">
                                                <?php if($userid==$row['task_from']){?>
                                                <a href="taskedit.php?id=<?php echo $row["task_id"];?>"
                                                    class="on-default edit-row"><i class="fas fa-edit"></i></a><?php } ?>
                                                 
                                                    <a href="taskstatus.php?id=<?php echo $row["task_id"];?>"
                                                    class="on-default edit-row"><i class="fas fa-pencil-alt"></i></a>
                                                    <a href="task.php?id=<?php echo $row["task_id"];?>"
                                                    class="on-default edit-row"><i class="fa fa-eye"></i></a>

                                            </td>
                                        </tr>
                                        <?php } ?>
                                    </tbody>
                                </table>
                            </div>

                        </section>

                    </div>
                </div>
                <?php } ?>
                <!-- end: page -->
            </section>
        </div>

        <?php include('include/aside.php');?>

    </section>


    <!-- Vendor -->
    <script src="vendor/jquery/jquery.js"></script>
    <script src="vendor/jquery-browser-mobile/jquery.browser.mobile.js"></script>
    <script src="vendor/popper/umd/popper.min.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.js"></script>
    <script src="vendor/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
    <script src="vendor/common/common.js"></script>
    <script src="vendor/nanoscroller/nanoscroller.js"></script>
    <script src="vendor/magnific-popup/jquery.magnific-popup.js"></script>
    <script src="vendor/jquery-placeholder/jquery.placeholder.js"></script>

    <!-- Specific Page Vendor -->
    <script src="vendor/select2/js/select2.js"></script>
    <script src="vendor/datatables/media/js/jquery.dataTables.min.js"></script>
    <script src="vendor/datatables/media/js/dataTables.bootstrap4.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/Buttons-1.4.2/js/dataTables.buttons.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/Buttons-1.4.2/js/buttons.bootstrap4.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/Buttons-1.4.2/js/buttons.html5.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/Buttons-1.4.2/js/buttons.print.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/JSZip-2.5.0/jszip.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/pdfmake-0.1.32/pdfmake.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/pdfmake-0.1.32/vfs_fonts.js"></script>


    <!--(remove-empty-lines-end)-->

    <!-- Theme Base, Components and Settings -->
    <script src="js/theme.js"></script>

    <!-- Theme Custom -->
    <script src="js/custom.js"></script>

    <!-- Theme Initialization Files -->
    <script src="js/theme.init.js"></script>

    <!-- Examples -->
    <script src="js/examples/examples.datatables.default.js"></script>

    <script>
        (function ($) {

            'use strict';

            var datatableInit = function () {
                var $table = $('#datatable-tabletools');


                var table = $table.dataTable({
                    "order": [
                        [3, "desc"]
                    ],
                    sDom: '<"text-right mb-md"T><"row"<"col-lg-6"l><"col-lg-6"f>><"table-responsive"t>p',
                    buttons: [{
                            extend: 'print',
                            text: 'Print'
                        },
                        {
                            extend: 'excel',
                            text: 'Excel'
                        },
                        {
                            extend: 'pdf',
                            text: 'PDF',
                            customize: function (doc) {
                                var colCount = new Array();
                                $('#datatable-tabletools').find('tbody tr:first-child td').each(
                                    function () {
                                        if ($(this).attr('colspan')) {
                                            for (var i = 1; i <= $(this).attr(
                                                    'colspan'); $i++) {
                                                colCount.push('*');
                                            }
                                        } else {
                                            colCount.push('*');
                                        }
                                    });
                                doc.content[1].table.widths = colCount;
                            }
                        }
                    ]
                });

                $('<div />').addClass('dt-buttons mb-2 pb-1 text-right').prependTo(
                    '#datatable-tabletools_wrapper');

                $table.DataTable().buttons().container().prependTo('#datatable-tabletools_wrapper .dt-buttons');

                $('#datatable-tabletools_wrapper').find('.btn-secondary').removeClass('btn-secondary').addClass(
                    'btn-default');
            };

            $(function () {
                datatableInit();
            });

        }).apply(this, [jQuery]);
    </script>
</body>

</html>
<?php include('include/footer.php');?>