
<?php include('session.php');
      session_start();
      $my_campus = $_SESSION['campus'];

    $dept_off = "";
    $v_disabled = "disabled";
    $m_disabled = "disabled";
    $selected = "";
    
    if(isset($_POST['dept_off'])){ 
        $dept_off = mysqli_real_escape_string($db,$_POST['dept_off']);
    }

    if(isset($_POST['dept_off'])){ 
        if($_POST['dept_off'] != ""){ 
            $v_disabled = "";
            $m_disabled = "";
        }
}

    $assign_hidden = "";
    $update_hidden = "hidden";

    $add_corev_hidden = "";
    $update_corev_hidden = "hidden";

    // ========================= VISION MISSION =========================
    if(isset($_POST['assign_vm_btn'])){ 
        $dept_off = mysqli_real_escape_string($db,$_POST['dept_off']);
        $vision = mysqli_real_escape_string($db,$_POST['vision']);
        $mission = mysqli_real_escape_string($db,$_POST['mission']); 

        $sql = "INSERT INTO vm (`Departments/Offices`, `Vision`, `Mission`, `Campus`)
        VALUES ('$dept_off', '$vision', '$mission', '$my_campus')";
        if (mysqli_query($db, $sql)) {
            echo '<script>alert("Vision and Mision assigned successfully!");</script>';
        } else {
            $error = "Invalid";
            echo "Error: " . $sql . "<br>" . mysqli_error($db);
        }
    }

    if(isset($_POST['update_vm_btn'])){ 
        $dept_off = mysqli_real_escape_string($db,$_POST['dept_off']);
        $vision = mysqli_real_escape_string($db,$_POST['vision']);
        $mission = mysqli_real_escape_string($db,$_POST['mission']); 

        $sql = "UPDATE vm SET Vision='$vision', Mission='$mission' WHERE `Departments/Offices`='$dept_off' ";
        if (mysqli_query($db, $sql)) {
            echo '<script>alert("Vision and Mision updated successfully!");</script>';
        } else {
            $error = "Invalid";
            echo "Error: " . $sql . "<br>" . mysqli_error($db);
        }
    }

    // ========================= CORE VALUES =========================
    if(isset($_POST['add_corev_btn'])){ 
        $resilience = mysqli_real_escape_string($db,$_POST['resilience']);
        $integrity = mysqli_real_escape_string($db,$_POST['integrity']);
        $commitment = mysqli_real_escape_string($db,$_POST['commitment']);  
        $excellence = mysqli_real_escape_string($db,$_POST['excellence']); 

        $sql = "INSERT INTO core_values (`Resilience`, `Integrity`, `Commitment`, `Excellence`)
        VALUES ('$resilience', '$integrity', '$commitment', '$excellence' )";
        if (mysqli_query($db, $sql)) {
            echo '<script>alert("Core Values added successfully!");</script>';
        } else {
            $error = "Invalid";
            echo "Error: " . $sql . "<br>" . mysqli_error($db);
        }
    }

    if(isset($_POST['update_corev_btn'])){ 
        $resilience = mysqli_real_escape_string($db,$_POST['resilience']);
        $integrity = mysqli_real_escape_string($db,$_POST['integrity']);
        $commitment = mysqli_real_escape_string($db,$_POST['commitment']);  
        $excellence = mysqli_real_escape_string($db,$_POST['excellence']); 

        $sql = "UPDATE core_values SET Resilience='$resilience', Integrity='$integrity', Commitment='$commitment', Excellence='$excellence' WHERE ID='1' ";
        if (mysqli_query($db, $sql)) {
            echo '<script>alert("Core Values updated successfully!");</script>';
        } else {
            $error = "Invalid";
            echo "Error: " . $sql . "<br>" . mysqli_error($db);
        }
    }

?>

<!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;
}
</style>

</head>
<body>
    <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="super_user.php" style="background-color: green;">ADMIN-PME</a> 
            </div>
  <div style="color: white;
padding: 15px 50px 5px 50px;
float: right;
font-size: 16px;"> 

<!--This code can be use to get the current date-->
<!--<script>    
    var d = new Date();
     
    var date = d.getDate();
    var month = d.getMonth() + 1; // Since getMonth() returns month from 0-11 not 1-12
    var month_let;
    if(month == 1)
    {
        month_let = "January";
    }
    else if(month == 2)
    {
        month_let = "February";
    }
    else if(month == 3)
    {
        month_let = "March";
    }
    else if(month == 4)
    {
        month_let = "April";
    }
    else if(month == 5)
    {
        month_let = "May";
    }
    else if(month == 6)
    {
        month_let = "June";
    }
    else if(month == 7)
    {
        month_let = "July";
    }
    else if(month == 8)
    {
        month_let = "August";
    }
    else if(month == 9)
    {
        month_let = "September";
    }
    else if(month == 10)
    {
        month_let = "October";
    }
    else if(month == 11)
    {
        month_let = "November";
    }
    else if(month == 12)
    {
        month_let = "December";
    }
    var year = d.getFullYear();
     
    var dateStr = month_let + " " + date + " " + year;
    document.write(dateStr);
    </script> -->

        <!-- 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: 220px; width: 500px;">
        <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: 200%;">
            <div class="sidebar-collapse">
                <ul class="nav" id="main-menu">
				<li class="text-center">
                    <img src="images/minsu_logo.png" class="user-image img-responsive"/>
					</li>
				
				
                    <!-- <li>-->
                    <!--    <a  href="messages.php" style="height: 80px; padding-top:35px;"><img src="images/message_white.jpg" width="50px" height="50px" style="margin-left: -5px; margin-top: -17px; float: left;"><i class="fa fa-3x"></i> Messages</a>-->
                    <!--</li>-->
                      
                    <li>
                        <a 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 class="active-menu" 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>
                        <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> 
        
        <?php 
            //fetch usertype from database
            $sql_usertype = mysqli_query($db, "SELECT * FROM usertype WHERE Campus='$my_campus' || Campus='All'");
        ?>
        <!-- /. NAV SIDE  -->
        <div id="page-wrapper" style="min-height: 30px;">
            <div id="page-inner" style="min-height: 30px; padding: 30px;">
                    <div class="col-md-12">
                    </div>
                    <p style="color: white; background-color: #3c5755; padding: 23px; margin-top: -0.1px; font-family: Arial; font-weight: bold; font-size: 27px;"><img src="images/vmc.png" style="width: 60px; height: 60px; margin-top: -18px; float: left; margin-left: -5px;"> VMC</p>
                 <!-- /. ROW  -->
                  <hr />
            <form id="my-form" method="post">
            <?php // Attempt select query execution
                $gen_vision = "";
                $gen_mission = "";
                $sql = "SELECT * FROM vm WHERE `Departments/Offices`='MINSU'";
                if($result = $db->query($sql)){
                    if($result->num_rows > 0){
                        while($row = $result->fetch_array()){
                            $gen_vision = $row['Vision'];
                            $gen_mission = $row['Mission'];
                        }
                        $assign_hidden = "hidden";
                        $update_hidden = "";
                    }
                    else{
                        $assign_hidden = "";
                        $update_hidden = "hidden";
                    }
                }
                ?>
                <div class="row" style="margin-left: 16px; width: 100%;">
                  <select onchange="sort_file_status()" name="dept_off" 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="MINSU" selected>MINSU</option>
								<!-- Fetch the list of usertype in usertype table from database -->
						</select>
                        <b><button type="submit" name="assign_vm_btn" class="login100-form-btn" style="background-color: #36892f; color: white; float: right; margin-right: 30px; padding-right:20px; padding-left: 20px; padding-top:10px; padding-bottom: 10px; border: none; border-radius: 25px; font-family: Arial;" <?php echo $assign_hidden?>>Assign <img src="images/add_icon.png" style="width: 22px; height: 17px; margin-top: -5px;"></button></b>
                <b><button type="submit" name="update_vm_btn" class="login100-form-btn" style="background-color: #1597cd; color: white; float: right; margin-right: 30px; padding-right:20px; padding-left: 20px; padding-top:10px; padding-bottom: 10px; border: none; border-radius: 25px; font-family: Arial;" <?php echo $update_hidden?>>Update <img src="images/update.png" style="width: 23px; height: 21px; margin-top: -5px;"></button></b>
                    </div><br>
                <div class="row" style="margin-left: 1px; width: 100%;">
                <div class="col-md-6 col-sm-9 col-xs-12">         
			<div class="panel panel-back noti-box" style="background-color: #f1f1f1; border-radius: 10px;">   
            <center><div class="text-box">
                <h3 style="margin-top: -5px; font-weight: bold;">Vision</h3>
                <b><textarea name="vision" placeholder="Input some text here..." style="text-align: center; color: black; width: 100%; height: 250px; padding: 15px; border-radius: 10px; resize: none;"required><?php echo $gen_vision; ?></textarea></b>
                </div></center>
             </div>
		     </div>

             <div class="col-md-6 col-sm-9 col-xs-12">             
			<div class="panel panel-back noti-box" style="background-color: #f1f1f1; border-radius: 10px;">   
            <center><div class="text-box">
                <h3 style="margin-top: -5px; font-weight: bold;">Mission</h3>
                <b><textarea name="mission" placeholder="Input some text here..." style="text-align: center; color: black; width: 100%; height: 250px; padding: 15px; border-radius: 10px; resize: none;" required><?php echo $gen_mission; ?></textarea></b>
                </div></center>
             </div>
		     </div>
            </div>
            </form>
            <hr>

            <!------------------------------ CORE VALUES ------------------------------>
            <form method="post">
            <?php // Attempt select query execution
                $gen_resilience = "";
                $gen_integrity = "";
                $gen_commitment = "";
                $gen_excellence = "";
                $sql = "SELECT * FROM core_values WHERE `ID`='1'";
                if($result = $db->query($sql)){
                    if($result->num_rows > 0){
                        while($row = $result->fetch_array()){
                            $gen_resilience = $row['Resilience'];
                            $gen_integrity = $row['Integrity'];
                            $gen_commitment = $row['Commitment'];
                            $gen_excellence = $row['Excellence'];
                        }
                        $add_corev_hidden = "hidden";
                        $update_corev_hidden = "";
                    }
                    else{
                        $add_corev_hidden = "";
                        $update_corev_hidden = "hidden";
                    }
                }
                ?>

            <b><button type="submit" name="add_corev_btn" class="login100-form-btn" style="background-color: #36892f; color: white; float: right; margin-right: 20px; margin-top: -8px; padding-right:20px; padding-left: 20px; padding-top:10px; padding-bottom: 10px; border: none; border-radius: 25px; font-family: Arial;" <?php echo $add_corev_hidden?>>Add <img src="images/add_icon.png" style="width: 22px; height: 17px; margin-top: -5px;"></button></b>
                <b><button type="submit" name="update_corev_btn" class="login100-form-btn" style="background-color: #1597cd; color: white; float: right; margin-top: -8px; margin-right: 20px; padding-right:20px; padding-left: 20px; padding-top:10px; padding-bottom: 10px; border: none; border-radius: 25px; font-family: Arial;" <?php echo $update_corev_hidden?>>Update <img src="images/update.png" style="width: 23px; height: 21px; margin-top: -5px;"></button></b>
            <center><h3 style="color: #003e07; font-weight: bold;">CORE VALUES</h3></center>
            <hr>
            
             <div class="row" style="margin-left: 1px; width: 100%;">
            
             <div class="col-md-6 col-sm-9 col-xs-12">            
			<div class="panel panel-back noti-box" style="background-color: #f1f1f1; border-radius: 10px;">   
            <center><div class="text-box">
                <h3 style="margin-top: -5px; font-weight: bold;">Resilience</h3>
                <b><textarea name="resilience" placeholder="Input some text here..." style="text-align: center; color: black; width: 100%; height: 150px; padding: 25px; border-radius: 10px; resize: none;" required><?php echo $gen_resilience?></textarea></b>
                </div></center>
             </div>
		     </div>

             <div class="col-md-6 col-sm-9 col-xs-12">            
			<div class="panel panel-back noti-box" style="background-color: #f1f1f1; border-radius: 10px;">   
            <center><div class="text-box">
                <h3 style="margin-top: -5px; font-weight: bold;">Integrity</h3>
                <b><textarea name="integrity" placeholder="Input some text here..." style="text-align: center; color: black; width: 100%; height: 150px; padding: 25px; border-radius: 10px; resize: none;" required><?php echo $gen_integrity?></textarea></b>
                </div></center>
             </div>
		     </div>

             <div class="col-md-6 col-sm-9 col-xs-12">            
			<div class="panel panel-back noti-box" style="background-color: #f1f1f1; border-radius: 10px;">   
            <center><div class="text-box">
                <h3 style="margin-top: -5px; font-weight: bold;">Commitment</h3>
                <b><textarea name="commitment" placeholder="Input some text here..." style="text-align: center; color: black; width: 100%; height: 150px; padding: 25px; border-radius: 10px; resize: none;" required><?php echo $gen_commitment?></textarea></b>
                </div></center>
             </div>
		     </div>

             <div class="col-md-6 col-sm-9 col-xs-12">            
			<div class="panel panel-back noti-box" style="background-color: #f1f1f1; border-radius: 10px;">   
            <center><div class="text-box">
                <h3 style="margin-top: -5px; font-weight: bold;">Excellence</h3>
                <b><textarea name="excellence" placeholder="Input some text here..." style="text-align: center; color: black; width: 100%; height: 150px; padding: 25px; border-radius: 10px; resize: none;" required><?php echo $gen_excellence?></textarea></b>
                </div></center>
             </div>
		     </div>
            </form>
            
                 <!-- /. ROW  -->                                               
                        
        </div>
                 <!-- /. ROW  -->
                <div class="row">
                    
                <!--<div class="col-md-9 col-sm-12 col-xs-12">                     
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Analytics Reports
                        </div>
                        <div class="panel-body">
                            <div>Area </div>
                            <canvas  id="chartjs_bar"></canvas>
                        </div>
                    </div>             
                    </div>-->

                 <!-- /. ROW  -->           
    </div>
             <!-- /. PAGE INNER  -->
            </div>
         <!-- /. PAGE WRAPPER  -->
        </div>
     <!-- /. WRAPPER  -->

     
    <!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME-->
    <script src="//code.jquery.com/jquery-1.9.1.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>
<script type="text/javascript">
      var ctx = document.getElementById("chartjs_bar").getContext('2d');
                var myChart = new Chart(ctx, {
                    type: 'bar',
                    data: {
                        labels:<?php echo json_encode($dept_off); ?>,
                        datasets: [{
                            backgroundColor: [
                               "#5969ff",
                                "#ff407b",
                                "#25d5f2",
                                "#ffc750",
                                "#2ec551",
                                "#7040fa",
                                "#ff004e"
                            ],
                            data:<?php echo json_encode($area); ?>,
                        }]
                    },
                    options: {
                           legend: {
                        display: false,
                        position: 'bottom',
 
                        labels: {
                            fontColor: '#71748d',
                            fontFamily: 'Circular Std Book',
                            fontSize: 14,
                        }
                    },
 
 
                }
                });
    </script>
    <!-- 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>
     <!-- MORRIS CHART SCRIPTS -->
     <script src="assets/js/morris/raphael-2.1.0.min.js"></script>
    <script src="assets/js/morris/morris.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>
        function sort_file_status(){
            document.getElementById("my-form").submit();
        }
    </script>
   
</body>
</html>
