<?php 
include('session.php');
$title = "";
$instructions = "";
$due_date = "";
$due_time = "";
$attached_file = "";
$date_posted = "";
$time_posted = "";

if($_SERVER["REQUEST_METHOD"] == "GET")
{   
    $ID = $_GET["ID"];
    $sql_assignment = mysqli_query($db, "SELECT * FROM requirements WHERE ID='$ID'");
    while($DB_ROW = mysqli_fetch_array($sql_assignment)) {

        $title = $DB_ROW["Title"];
        $instructions = $DB_ROW["Instructions"];
        $due_date = $DB_ROW['Due_Date'];
        $due_time = $DB_ROW['Due_Time'];
        $attached_file = $DB_ROW["Attached_File"];
        if($attached_file == "None"){
            $attached_file = "";
        }
        $date_posted = $DB_ROW['Date_Posted'];
        $time_posted = $DB_ROW['Time_Posted'];
    }
}
?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
      <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>PME-ADMIN</title>
	<link rel="icon" type="image/png" href="images/icons/minsu-icon.ico"/>
	<!-- BOOTSTRAP STYLES-->
    <link href="assets/css/bootstrap.css" rel="stylesheet" />
     <!-- FONTAWESOME STYLES-->
    <link href="assets/css/font-awesome.css" rel="stylesheet" />
     <!-- MORRIS CHART STYLES-->
    <link href="assets/js/morris/morris-0.4.3.min.css" rel="stylesheet" />
        <!-- CUSTOM STYLES-->
    <link href="assets/css/custom.css" rel="stylesheet" />
     <!-- GOOGLE FONTS-->
   <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />


</head>
<body style="font-family: Arial;">
    <div id="wrapper">
        <!-- /. NAV SIDE  -->
            <div id="page-inner" style="padding-left: 30px; padding-right: 30px;">
                <div class="row">
                    <div class="col-md-12">
                    <a href="assignments.php"><button style="float: left; margin-top: 20px; cursor: pointer; background-color: #313131; border-radius: 5px; margin-left: 10px; border-color: gray;" title="Click to go back"><img src="images/back_btn.png" width="25px" height= "25px" style="border: none; border: border-color: white; background-color: #313131; border-radius: 5px; padding: 3px;"></button></a><p style="color: white; background-color: #3c5755; padding: 18px; margin-top: -0.1px; font-family: Arial; font-weight: bold; font-size: 27px;">&nbsp<img src="images/requirement_white.png" style="width: 40px; height: 40px; margin-top: -5px;">&nbsp<?php echo $title;?></p>   
                    <br>
                </div>
                <?php
                    if($due_date == "None" || $due_time == "None"){
                      $due = "No due date";
                      $due_date = "";
                      $due_time = "";
                    }
                    else{
                      $due = "Due";
                    }
                    if($attached_file != ""){
                        //Check the file extension and display icon based on the file format
                        $ext1 = pathinfo($attached_file, PATHINFO_EXTENSION);
                        if($ext1 == "jpg" || $ext1 == "jpeg" || $ext1 == "JPG" || $ext1 == "png" || $ext1 == "PNG" || $ext1 == "bmp"){
                            $icon1 = "image_icon.png";
                        }
                        else if($ext1 == "docx" || $ext1 == "doc"){
                            $icon1 = "word_icon.png";
                        }
                        else if($ext1 == "xlsx" || $ext1 == "xlsm" || $ext1 == "xlsb" || $ext1 == "xltx" || $ext1 == "xltm" || $ext1 == "xls" || $ext1 == "xlt" || $ext1 == "xltm" || $ext1 == "xml" || $ext1 == "xlam" || $ext1 == "xla" || $ext1 == "xlw" || $ext1 == "xlr"){
                            $icon1 = "excel_icon.png";
                        }
                        else if($ext1 == "txt"){
                            $icon1 = "docu_icon.png";
                        }
                        else if($ext1 == "pdf"){
                            $icon1 = "pdf_icon.png";
                        }
                        else if($ext1 == "pptx" || $ext1 == "ppt"){
                            $icon1 = "powerpoint_icon.png";
                        }
                        else{
                            $icon1 = "unknown_icon.png";
                        }
                    }
                    echo '<div style="background-color: #f9f9f9; padding-bottom: 30px;">';
                    echo '<p style="margin-left: 40px; font-size: 14px; color: #696969;">Posted '.$date_posted. ' <span style="float: right; padding-right: 80px; font-weight: bold;">'.$due. ' ' . $due_date . ' ' . $due_time .'</span></p>';
                    echo '<hr><p style="margin-left: 40px; margin-top: -20px; font-size: 14px; padding-right: 30px; ">'.$instructions.'</p>';
                    
                    if($attached_file != ""){
                    echo '<div style="width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; float: left; border-radius: 10px; margin-top: 10px; margin-left: 35px; border: none; padding-left: 10px; padding-right: 30px; padding-bottom: 20px; font-weight: bold; font-family: Arial; width: 300px; border-style:solid; border-width: thin; border-color: #d6d6d6; background-color: #fafafa;">';
                    echo '<br><img src="images/'.$icon1.'" alt="Icon" style="width:50px;height:45px;"><a href="attached_files/'.$attached_file.'" style="margin-left: 20px; margin-top: -15px;" download>'.$attached_file.'</a></div>';
                    echo '</div><br><br><br><br><hr>';
                    }
                ?>        
                </div>
                <?php
                $sql_tasks = mysqli_query($db, "SELECT * FROM tasks WHERE Assignment_Code='$ID'");
                while($DB_ROW = mysqli_fetch_array($sql_tasks)) {
                    if($DB_ROW["File_Link"] != ""){
                        //Check the file extension and display icon based on the file format
                        $fl = $DB_ROW['File_Link'];
                        $ext = pathinfo($fl, PATHINFO_EXTENSION);
                        if($ext == "jpg" || $ext == "jpeg" || $ext == "JPG" || $ext == "png" || $ext == "PNG" || $ext == "bmp"){
                            $icon = "image_icon.png";
                        }
                        else if($ext == "docx" || $ext == "doc"){
                            $icon = "word_icon.png";
                        }
                        else if($ext == "xlsx" || $ext == "xlsm" || $ext == "xlsb" || $ext == "xltx" || $ext == "xltm" || $ext == "xls" || $ext == "xlt" || $ext == "xltm" || $ext == "xml" || $ext == "xlam" || $ext == "xla" || $ext == "xlw" || $ext == "xlr"){
                            $icon = "excel_icon.png";
                        }
                        else if($ext == "txt"){
                            $icon = "docu_icon.png";
                        }
                        else if($ext == "pdf"){
                            $icon = "pdf_icon.png";
                        }
                        else if($ext == "pptx" || $ext == "ppt"){
                            $icon = "powerpoint_icon.png";
                        }
                        else{
                            $icon = "unknown_icon.png";
                        }

                        // If user has no uploaded profile picture
                        if($DB_ROW['Profile_Picture'] == ""){
                            $DB_ROW['Profile_Picture'] = "unnamed.png";
                        }
                        ?>
                            <h3 style="margin-left: 20px; color: gray;">SUBMITTED FILES</h3><br>
                            <a target="_parent" href="tasks.php?ID=<?php echo $DB_ROW['ID'];?>">  
                                <div class="col-md-2 col-sm-6 col-xs-6" title="<?php echo $DB_ROW['File_Link']?>">         
                            <div class="panel panel-back noti-box" style="background-color: #f1f1f1;">
                            <center><img src="images/<?php echo $icon ?>" alt="Message" style="width:50px;height:45px;"></center>
                                
                            <center><div class="text-box">
                                    <p title="<?php echo $DB_ROW['File_Link']?>" style="font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><?php echo $DB_ROW['File_Link']?></p>
                                    <p class="text-muted" style="font-size: 14px; margin-top: -25px;"><?php echo $DB_ROW['File_Status'] ?></p>
                                    <p title="<?php echo $DB_ROW['Username']?>" style="color: black; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: -10px;"><img title="<?php echo $DB_ROW['Username']?>" src="profile_pic/<?php echo $DB_ROW['Profile_Picture'] ?>" style="border:3px; height:25px; width:25px; border-radius: 25px;"> <?php echo $DB_ROW['Username']?></p>
                                    </div></center>
                            </div>
                            </div>
                            </a>  
                    <?php 
                        }
                    }
                ?> 
            </div>
    </div>
     <!-- /. WRAPPER  -->
    <!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME-->
    <!-- JQUERY SCRIPTS -->
    <script src="assets/js/jquery-1.10.2.js"></script>
      <!-- BOOTSTRAP SCRIPTS -->
    <script src="assets/js/bootstrap.min.js"></script>
    <!-- METISMENU SCRIPTS -->
    <script src="assets/js/jquery.metisMenu.js"></script>
      <!-- CUSTOM SCRIPTS -->
    <script src="assets/js/custom.js"></script>

    <script>
    // Get the modal
    var modal = document.getElementById("myModal");

    // Get the button that opens the modal
    var btn = document.getElementById("myBtn");

    // Get the <span> element that closes the modal
    var span = document.getElementsByClassName("close")[0];

    // When the user clicks the button, open the modal 
    btn.onclick = function() {
    modal.style.display = "block";
    }

    // When the user clicks on <span> (x), close the modal
    span.onclick = function() {
    modal.style.display = "none";
    }

    // When the user clicks anywhere outside of the modal, close it
    window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
    }
    </script>

    <script>
       document.getElementById('select-all').onclick = function() {
        var checkboxes = document.querySelectorAll('input[type="checkbox"]');
        for (var checkbox of checkboxes) {
            checkbox.checked = this.checked;
        }
       } 
    </script>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script>
    $("#checkboxes input").click(function () {
    $("#output").text($("#checkboxes input:checked").map(function () {
        return $(this).val();
    }).get().join());
    }).click().click();
    </script>

    <!-- <script>
        document.getElementById('submitID').disabled = true; //Disable at first
        //Listen for keyup event (after we hit a key)
        //-----------------------------------------------------------
        //NOTE: We can also use the change event, but the submit button
        //      won't update until we finish typing the whole thing
        //-----------------------------------------------------------
        document.getElementById('myInputFieldID').addEventListener('keyup', e => {
        //Check for the input's value
        if (e.target.value == "") {
            document.getElementById('submitID').disabled = true;
        }
        else {
            document.getElementById('submitID').disabled = false;
        }
        });
        </script> -->
        
   
</body>
</html>
