<?php 
    include('session.php');
    if (session_status() == PHP_SESSION_NONE) {
        session_start();
    }
    $my_campus = $_SESSION['campus'];
    $campus = "";
    if(isset($_GET['campus'])){ 
        $campus = mysqli_real_escape_string($db,$_GET['campus']);
        if($campus == "MCC"){
            $selected1 = "selected";
            $selected2 = "";
            $selected3 = "";
        }
        else if($campus == "MBC"){
            $selected1 = "";
            $selected2 = "selected";
            $selected3 = "";
        }
        else if($campus == "MMC"){
            $selected1 = "";
            $selected2 = "";
            $selected3 = "selected";
        }
    }
    else{
        $selected1 = "";
        $selected2 = "";
        $selected3 = "";
    }
    
    $already_uploaded = false;
    $tense = "";
    $ID = "";
    if(isset($_GET["ID"])){
        $selected_btn = "Update";
        $selected_action = '<form action="update_assignment.php" method="post" enctype= multipart/form-data>';
        $ID = $_GET["ID"];
        $sql_assign2 = mysqli_query($db, "SELECT * FROM requirements WHERE ID='$ID'");
        while($DB_ROW2 = mysqli_fetch_array($sql_assign2)) {
            $title = $DB_ROW2["Title"];
            $instructions = $DB_ROW2["Instructions"];
            $due_date = $DB_ROW2['Due_Date'];
            $due_time = $DB_ROW2["Due_Time"];
            $my_uploaded_file = $DB_ROW2['Attached_File'];

            if($due_date == "None"){
                $date_type = "text";
                $date_value = "No due date";
                $time_type = "text";
                $time_value = "Time";
            }
            else{
                $date_type = "date";
                $time_type = "time";
                $d = date('Y-m-d', strtotime(str_replace('-', '/', $due_date)));
                $date_value = date('Y-m-d', strtotime($d));

                $time_value = date('H:i:s', strtotime($due_time));
            }

            if($my_uploaded_file == "None"){
                $already_uploaded = false;
            }
            else{
                $already_uploaded = true;
                $tense = "ed";
            }
        }   
    }
    else{
        $already_uploaded = false;
        $tense = "";
        $selected_btn = "Assign";
        $selected_action = '<form action="create_assignment.php" method="post" enctype= multipart/form-data>';
        $title = "";
        $instructions = "";
        $date_type = "text";
        $date_value = "No due date";
        $time_type = "text";
        $time_value = "Time";
    }

    if($already_uploaded == true){
        $input_attr = "";
        $remove_file = '<a href="attached_files/'.$my_uploaded_file.'" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap; float: left; border-radius: 10px; padding:10px; margin-top: -70px; border: none; padding-left: 10px; padding-right: 30px; padding-bottom: 10px; font-weight: bold; font-family: Arial; width: 300px; border-style:solid; border-width: thin; border-color: #d6d6d6; background-color: #fafafa;">'.$my_uploaded_file.'</a>
                       <form method="post" action="remove_attached_file.php">
                       <input type="hidden" name="ID" value="'.$ID.'">
                       <input type="hidden" name="att_file" value="'.$my_uploaded_file.'">
                       <button type="submit" name="remove" style="cursor: pointer; float: left; margin-left:; border-radius: 5px; padding:5px; margin-top: -20px; border: none; padding-left: 30px; padding-right: 30px; padding-top: 10px; padding-bottom: 10px; font-weight: bold; font-family: Arial; width: 150px; border-style:solid; border-width: thin; border-color: #d6d6d6; background-color: gray; color: white; text-align: center;" >Remove</button><br><br><br>
                       </form>';
                    }
    else{
        $input_attr = '<input type="file" name="file[]" id="file" style="margin-top: 10px; background-color: gray; border: none; color: white; border-radius: 5px; padding:8px; cursor: pointer; width: 240px;" />';
        $remove_file = "";
    }
?>

<!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' />


   <style>
/* The Modal (background) */
.modal {
  display: none; /* Hidden by default */
  position: fixed; /* Stay in place */
  z-index: 10000000; /* Sit on top */
  padding-top: 100px; /* Location of the box */
  left: 0;
  top: 0;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  overflow: auto; /* Enable scroll if needed */
  background-color: rgb(0,0,0); /* Fallback color */
  background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content */
.modal-content {
  background-color: #fefefe;
  margin: auto;
  padding: 20px;
  border: 1px solid #888;
  width: 80%;
}

/* The Close Button */
.close {
  color: #aaaaaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
}

.close:hover,
.close:focus {
  color: #000;
  text-decoration: none;
  cursor: pointer;
  
}

.dropbtn {
  background-color: #8b8b8b;
  color: white;
  padding: 8px;
  font-size: 16px;
  border: none;
  cursor: pointer;
  border-radius: 5px;
}

.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f3f3f3;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
  width: 300px;;
  padding: 10px;
}

.dropdown-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}

.dropdown-content a:hover {background-color: #f1f1f1}

.dropdown:hover .dropdown-content {
  display: block;
}

.dropdown:hover .dropbtn {
  background-color: #6a6969;
}

.double {
  zoom: 0.7;
  transform: scale(2);
  -ms-transform: scale(2);
  -webkit-transform: scale(2);
  -o-transform: scale(2);
  -moz-transform: scale(2);
  transform-origin: 0 0;
  -ms-transform-origin: 0 0;
  -webkit-transform-origin: 0 0;
  -o-transform-origin: 0 0;
  -moz-transform-origin: 0 0;
  font-size: 11px;
}

</style>

</head>
<body style="font-family: Arial;">
    <div id="wrapper">
        <nav class="navbar navbar-default navbar-cls-top " role="navigation" style="margin-bottom: 0">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-collapse" >
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="admin.php" style="background-color: orange;">CCS - ADMIN</a> 
            </div>
  <div style="color: white;
padding: 15px 50px 5px 50px;
float: right;
font-size: 16px;"> 

        <!-- LOGOUT -->
        <?php echo $_SESSION['login_user']; ?> &nbsp; <a id="myBtn" class="btn btn-danger square-btn-adjust">Logout</a> </div>
        
        <!-- The Modal -->
        <div id="myModal" class="modal">

        <!-- Modal content -->
        <div class="modal-content" style="border-radius: 20px; height: 235px; width: 300px;">
        <span class="close">&times;</span>
        <h3>Logout</h3>
        <h4>Are you sure you want to logout?</h4>
        <br><br><br>
        <a onclick="document.getElementById('myModal').style.display='none'" class="logout" style="cursor: pointer; width: 100px; float:right; width: 70px; padding: 10px; color:white; margin-top:-20px; text-align: center; background-color: gray; border-radius: 5px; width: 100px;">No</a>
        <a href="logout.php" id="myBtn" class="logout"  style="cursor: pointer; width: 70px; padding: 10px; color:white; text-align: center; float:right; margin-top:-20px; margin-right: 5px; background-color: #4c9be1; border-radius: 5px; width: 100px;">Yes</a>

        </div>
        </div>
        </nav>   
           <!-- /. NAV TOP  -->
                <nav class="navbar-default navbar-side" role="navigation" style="height: 180%;">
            <div class="sidebar-collapse">
                <ul class="nav" id="main-menu">
				<li class="text-center">
                    <img src="images/CCS_logo.png" class="user-image img-responsive"/>
					</li>
			
                    <li>
                        <a class="active-menu" href="super_user.php" style="height: 80px; padding-top:35px;"><img src="images/requirement_white.png" width="50px" height="50px" style="margin-left: -9px; margin-top: -15px; float: left;"/><i class="fa fa-3x"></i> Assignments</a>
                    </li>  
                    <li>
                        <a href="accounts-su.php" style="height: 80px; padding-top:35px;"><img src="images/accounts_white1.png" width="60px" height="63px" style="margin-left: -10px; margin-top: -20px; float: left;"/><i class="fa fa-3x"></i> Accounts</a>
                    </li>         
                    <li>
                        <a href="vmc-su.php"><i class="fa fa-sitemap fa-3x"></i> &nbsp VMC</a>
                      </li> 
                      <!-- <li>
                        <a  href="evaluations-su.php" style="height: 80px; padding-top:35px;"><img src="images/comments_white.png" width="50px" height="56px" style="margin-left: -5px; margin-top: -18px; float: left;"/><i class="fa fa-3x"></i> Evaluations</a>
                    </li>   -->
                      <li>
                        <a  href="register-su.php" style="height: 80px; padding-top:35px;"><img src="images/register_user.png" width="50px" height="56px" style="margin-left: -5px; margin-top: -18px; float: left;"/><i class="fa fa-3x"></i> Register Admin</a>
                    </li> 
                </ul>
               
            </div>
            
        </nav>  
        <!-- /. NAV SIDE  -->
        <div id="page-wrapper" >
            <div id="page-inner" style="padding: 30px;">
                <div class="row">
                    <div class="col-md-12">

                    <p style="color: white; background-color: gray; padding: 18px; margin-top: -0.1px; font-family: Arial; font-weight: bold; font-size: 27px;"><img src="images/requirement_white.png" style="width: 40px; height: 40px; margin-top: -5px;">&nbsp Requirements</p>
                    <form id="my-form" method="get" action="">
                    <select onchange="sort_file_status()" name="campus" class="field input" style="width: 250px; border-color: white; border-radius: 5px; background-color: white; border: 2px solid #e8e8e8; height: 40px; font-size: 17px; margin-top: 5px; padding:5px;" required>
							<option value="">Select Campus :</option>
							<option value="MCC" <?php echo $selected1 ?>>MCC</option>
							<option value="MBC" <?php echo $selected2 ?>>MBC</option>
							<option value="MMC" <?php echo $selected3 ?>>MMC</option>
						</select>
                    </form>
                    <hr>
                    <!--<h2 style="color: #36892f;">Assignments</h2><hr style="border-color: #8dc388; margin-bottom: 0px;">-->
                    <!-- DROP DOWN LIST FOR POSTED ASSIGNMENT -->
                    <?php
                    
                    $sql_assign = mysqli_query($db, "SELECT * FROM requirements WHERE Campus='$campus' ORDER BY ID DESC");
                    if($sql_assign->num_rows > 0){
                                            $i = 1;
                        while($DB_ROW = mysqli_fetch_array($sql_assign)) {
                            if($DB_ROW['Due_Date'] == "None" || $DB_ROW['Due_Time'] == "None"){
                                $DB_ROW['Due_Date'] = "";
                                $DB_ROW['Due_Time'] = "";
                                $due = "";
                            }
                            else{
                                $due = "Due";
    
                            }
                            if($DB_ROW['Attached_File'] == "None"){
                                $DB_ROW['Attached_File'] = "";
                            }
    
                            echo '<button onclick="myFunction' . $i . '()" style="text-align: left; background-color: #fffbed; width: 100%; padding: 20px; border: none; border-bottom: solid; border-radius: 5px; border-bottom-width: thin; border-bottom-color: #ebc75a; color: #55565d; font-weight: bold;"><img src="images/assignments.png" style="width: 30px; height: 30px;">&nbsp &nbsp ' . $DB_ROW['Title'] . '<span style="float: right; font-weight: normal;">'. $due . ' ' . $DB_ROW['Due_Date'] . ' ' . $DB_ROW['Due_Time'] . '</span></button>';
                            echo '<div id="' . $i . '"   style="display: none;   width: 100%; padding: 5px 0; pading-top: 0px; text-align: left; background-color: #f7f7f7; border-bottom: solid; border-width: thin; border-color: #dcab17; border-radius: 10px;">';
                            echo '<p style="margin-left: 20px; font-size: 14px; color: #696969;">Posted ' . $DB_ROW["Date_Posted"] . '</p>';
                            echo '<p style="margin-left: 20px; font-size: 14px; ">' . $DB_ROW["Instructions"] . '</p>';
                            echo '<div style="width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">';
                            echo '<br><a href="attached_files/' . $DB_ROW["Attached_File"] . '" title="' . $DB_ROW["Attached_File"] . '" style="margin-left: 20px;" download>' . $DB_ROW["Attached_File"] . '</a>';
                            echo '</div>';
                            echo '<hr style="border-color: #cacaca;"><a href="view_assignment-su.php?ID='. $DB_ROW['ID'] .'&campus='.$campus.'" style="padding-left: 20px; border:none; background-color: #f7f7f7; color: #36892f; font-weight: bold;">View assignment</a>';
                            echo '<br><br>';
                            echo '</div><br>';
                            echo '<script>';
                            echo 'function myFunction' . $i . '() {
                            var x = document.getElementById("' . $i . '");
                            if (x.style.display === "none") {
                                x.style.display = "block";
                            } else {
                                x.style.display = "none";
                            }
                            }
                            </script>';
                            $i++;
                        }
                        
                    }
                    else{
                        echo '<div class="alert alert-danger"><em>No records were found.</em></div>';
                    }
                    ?>

                </div>
                </div>
                 <!-- /. ROW  -->
               
    </div>
             <!-- /. PAGE INNER  -->
            </div>
         <!-- /. PAGE WRAPPER  -->
        </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> -->
        
            <script>
        function sort_file_status(){
            document.getElementById("my-form").submit();
        }
    </script>
        
   
</body>
</html>
