<?php 
    include'include/session.php';
    
    $tableName="view_assignment";
    
    $sql = "SELECT * FROM $tableName WHERE staffID ='$staffID' ORDER BY assignmentID DESC";
    $query = mysql_query($sql);
    $rowcount=  mysql_num_rows($query);
    
?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>View Assignments | Lecturer | WAKA CMEC</title>
    <link rel="shortcut icon" href="../../../assets/img/logo.png" />
    <link rel="stylesheet" href="../../../assets/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Slab:300,400|Roboto:300,400,700">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto">
    <link rel="stylesheet" href="../../../assets/fonts/font-awesome.min.css">
    <link rel="stylesheet" href="../../../assets/css/ebs-simple-login-form1.css">
    <link rel="stylesheet" href="../../../assets/css/ebs-simple-login-form2.css">
    <link rel="stylesheet" href="../../../assets/css/ebs-simple-login-form.css">
    <link rel="stylesheet" href="../../../assets/css/FPE-Gentella-form-elements.css">
    <link rel="stylesheet" href="../../../assets/css/FPE-Gentella-form-elements1.css">
    <link rel="stylesheet" href="../../../assets/css/MUSA_no-more-tables.css">
    <link rel="stylesheet" href="../../../assets/css/MUSA_no-more-tables1.css">
    <link rel="stylesheet" href="../../../assets/css/MUSA_panel-table.css">
    <link rel="stylesheet" href="../../../assets/css/MUSA_panel-table1.css">
    <link rel="stylesheet" href="../../../assets/css/nav.css">
    <link rel="stylesheet" href="../../../assets/css/Navbar-Fixed-Side1.css">
    <link rel="stylesheet" href="../../../assets/css/Profile-Edit.css">
    <link rel="stylesheet" href="../../../assets/css/Profile-Edit1.css">
    <link rel="stylesheet" href="../../../assets/css/Responsive-Form.css">
    <link rel="stylesheet" href="../../../assets/css/Responsive-Form1.css">
    <link rel="stylesheet" href="../../../assets/css/Sidebar-Menu.css">
    <link rel="stylesheet" href="../../../assets/css/Sidebar-Menu1.css">
    <link rel="stylesheet" href="../../../assets/css/styles.css">
    <link rel="stylesheet" href="../../../assets/css/Data-Table.css">
    <link rel="stylesheet" href="../../../assets/css/Data-Table1.css">
</head>

<body style="background-color:rgb(252,252,252);">
    <div></div>
    <div id="wrapper">
        <div id="sidebar-wrapper" style="background-color:rgb(62,140,228);">
            <ul class="sidebar-nav">
                <li class="sidebar-brand" style="color:rgb(255,255,255);"> 
                    <a href="#" style="font-weight:bold;color:rgb(254,254,254);">Lecturer | WAKA CMEC</a>
                </li>
                <li style="color:rgb(252,253,254);"> 
                    <a href="index.php" style="color:rgb(255,255,255);">Home</a>
                    <a href="course-work.php" style="color:rgb(255,255,255);">Course Work</a>
                    <!--<a href="timetable.php" style="color:rgb(255,255,255);">Time Table</a>-->
                    <a class="bg-info">View Assignments</a>
                    <a href="exam.php" style="color:rgb(255,255,255);">View Exam</a>
                    <a href="assigned-units.php" style="color:rgb(255,255,255);">View Units</a>
                </li>
            </ul>
        </div>
        <div class="page-content-wrapper">
            <div class="container-fluid"><a class="btn btn-link" role="button" href="#menu-toggle" id="menu-toggle"><i class="fa fa-bars"></i></a>
                <div class="dropdown" style="width:150px;float:right;margin-top:5px;">
                    <button class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false" type="button" style="width:150px;background-color:rgb(252,252,252);color:rgb(20,19,19);border:1px solid rgb(252,252,252);text-align:right;"><i class="fa fa-user"></i> &nbsp; <?php echo $lec;?> <span class="caret"></span></button>
                    <ul role="menu" class="dropdown-menu dropdown-menu-right">
                        <li role="presentation"><a href="settings.php"><i class="fa fa-wrench"></i> &nbsp;Settings</a></li>
                        <li role="presentation"><a href="../validate/logout.php"><i class="fa fa-power-off"></i> &nbsp; Logout</a></li>
                    </ul>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css" rel='stylesheet' type='text/css'>

<div class="container">
    <div class="row">
    
        <div class="col-md-12 ">
        <form method="POST">
            <div class="panel panel-default panel-table">
              <div class="panel-heading">
                <div class="row">
                  <div class="col col-xs-6">
                    <h3 class="panel-title">
                        <em class="fa fa-book"></em> 
                        <b>Assignments</b>
                        
                     </h3>
                  </div>
                  <div class="col col-xs-6 text-right">
                      
                      <a href="upload-assignment.php">
                                <i class="fa fa-upload"></i>&nbsp; Upload
                      </a>
                      
                  </div>
                </div>
              </div> 
                <?php
                    include 'validate/delete-assignment.php';
                    if(isset($_SESSION['delete'])=="true"){
                        echo'<div class="alert alert-success absolue center text-center" role="alert">
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                    <span aria-hidden="true">×</span>
                                </button>
                                <span class="text-success">Delete Successful</span>
                            </div>';
                        unset($_SESSION['delete']); 
                    }
                    if(isset($_SESSION['success'])=="true"){
                        echo'<div class="alert alert-success absolue center text-center" role="alert">
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                    <span aria-hidden="true">×</span>
                                </button>
                                <span class="text-success">Assignment marked successful</span>
                            </div>';
                        unset($_SESSION['success']); 
                    }
                    
                    if(isset($_SESSION['update'])=="true"){
                        echo'<div class="alert alert-success absolue center text-center" role="alert">
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                    <span aria-hidden="true">×</span>
                                </button>
                                <span class="text-success">Update Successful</span>
                            </div>';
                        unset($_SESSION['update']); 
                    }
                    
                    if(empty($query)){
                        echo'<div class="alert alert-danger absolue center text-center">
                                <strong class="text-danger">Error occured while trying to retrieve assignments</strong>
                            </div>';
                     }else{
                ?>
              
              <div class="panel-body">
                  
                <table class="table table-striped" id="myTable">
                  <thead style="background-color:rgb(62,140,228);color:rgb(252,254,255);">
                    <tr>
                        <th>#</th>
                        <th>Code</th>
                        <th>Title</th>
                        <th>Unit</th>
                        <th>YoS/Block</th>
                        <th>Course</th>
                        <th>Uploaded</th>
                        <th>Status</th>
                        <th align="center"><em class="fa fa-cog"></em></th>
                    </tr> 
                  </thead>
                  <tbody>
                        <?php 
                                $r=1;
                                while ($row = mysql_fetch_array($query)) {
                                    
                            ?>
                        <tr>  
                            <td align="center"><?php echo $r++; ?></td>
                            <td><a href="#"><?php echo $row['code']; ?></a></td>
                            <td><?php echo $row['title']; ?></td>
                            <td><?php echo $row['unit']; ?></td>
                            <td><?php echo "Year ".$row['YOS'].", Block".$row['semister']; ?></td>
                            <td><?php echo $row['abbreviation']; ?></td>
                            <td><?php echo date_format(date_create($row['uploaded']),"d M-Y"); ?></td>
                            <td style="font-size:12px;font-weight:normal;
                                                    color:
                                                        <?php 
                                                        if(date('Y-m-d') < date_format(date_create($row['startDate']),"Y-m-d")){
                                                            echo '#B8860B';
                                                        }else
                                                        if(date('Y-m-d') >= date_format(date_create($row['startDate']),"Y-m-d") && date('Y-m-d') <= date_format(date_create($row['deadline']),"Y-m-d")){
                                                            echo '#00BFFF';
                                                        }else
                                                        if( date('Y-m-d') > date_format(date_create($row['deadline']),"Y-m-d")){
                                                            echo '#228B22';
                                                        }

                                                    ?>;"> 
                                            <?php 
                                                if(date('Y-m-d') < date_format(date_create($row['startDate']),"Y-m-d") ){
                                                echo 'Pending';
                                                }else
                                                if(date('Y-m-d') >= date_format(date_create($row['startDate']),"Y-m-d") && date('Y-m-d') <= date_format(date_create($row['deadline']),"Y-m-d")){
                                                    echo 'Ongoing';
                                                }else
                                                if(date('Y-m-d') > date_format(date_create($row['deadline']),"Y-m-d")){
                                                    echo 'Done';
                                                }                                         
                                            ?>
                            </td>
                            <td align="center" style="padding-left:2px;padding-right:2px;">
                                <a href="mark.php?id=<?php echo $row['assignmentID']?>" class="text-info"  title="Mark Assignment" role="button"><em class="fa fa-check"></em></a> &nbsp;
                              <a href="submitted-assignment.php?id=<?php echo $row['assignmentID']?>" class="text-info" title="View Submitted Assignment" role="button"><em class="fa fa-eye"></em></a> &nbsp;
                              <a href="../../uploads/assignment/<?php echo $row['document']; ?>" class="text-info" title="Download Assignment"  role="button"><em class="fa fa-download"></em></a>  &nbsp;
                              <?php
                                if(date('Y-m-d') > date_format(date_create($row['deadline']),"Y-m-d")){
                              ?>
                                <a title="Edit/Update Assignment" onClick="return alert('Cannot update Assignment past deadline');" role="button"><em class="fa fa-pencil"></em></a>&nbsp; 
                                <button title="Delete Assignment" onClick="return alert('Cannot delete Assignment past deadline');" style="background-color:transparent;border:none;">
                                      <i class="fa fa-trash" style="font-size:14px;"></i>
                                 </button>
                              <?php }else{ ?>
                                <a href="update-assignment.php?id=<?php echo $row['assignmentID']?>" class="text-primary" title="Edit/Update Assignment"  role="button"><em class="fa fa-pencil"></em></a>&nbsp; 
                                <button name="delete" value="<?php echo $row['assignmentID']?>" title="Delete Assignment" onClick="return confirm('Deleting this assignment might alter other CRITICAL records.\nSure you want to delete??');" style="background-color:transparent;border:none;">
                                      <i class="fa fa-trash" style="font-size:14px;color:rgb(254,17,2);"></i>
                                 </button>
                              <?php } ?>
                            </td>
                        </tr>
                        <?php }?>
                        </tbody>
                </table>
            
              </div>
            </div>
            <?php } ?>
        </div>
        </form>
    </div>
</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="../../../assets/js/jquery.min.js"></script>
    <script src="../../../assets/bootstrap/js/bootstrap.min.js"></script>
    <script src="../../../assets/js/ebs-simple-login-form.js"></script>
    <script src="../../../assets/js/Profile-Edit.js"></script>
    <script src="../../../assets/js/Sidebar-Menu.js"></script>
    <script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.15/js/dataTables.bootstrap.min.js"></script>
</body>
    <script>
        $(document).ready(function(){
            $('#myTable').dataTable();
        });
    </script>
</html>