<?php include ("kfunctions.php");
role("overadmin");
?>
<html>
<head>
<?php kheader(); ?>
<?php 
require_once("connect.php");

?>
<link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
<script src="js/sorttable.js"></script>
</head>
<body>


    <div id="wrapper">

        <!-- Navigation -->
        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <!-- Brand and toggle get grouped for better mobile display -->
            <?php ktopbar(); ?>
            <!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
            <?php kleftbar(); ?>
            <!-- /.navbar-collapse -->
        </nav>

        <div id="page-wrapper">

            <div class="container-fluid">

 <!-- Page Heading -->
                

                <div class="row">
                    <div class="col-lg-12">
                        <div class="panel panel-default">
                            <div class="panel-body">
                            
                           

<div class='panel panel-yellow'><!--Initiative-->
<div class='panel-heading'><h3 class='panel-title'>Active users</h3></div>
<div class='panel-body'>
<?php

if(isset($_POST["submit4"])){
$rolenumberz =$_POST["rolenumberz"];
$status = $_POST["status"];
include ("connect.php");

$updateusers = $dbh->query("update users set status='$status' where rolenumber='$rolenumberz'");

$result7 = $dbh->query("select * from users where rolenumber='$rolenumberz'");
$row7 = $result7->fetchObject();

if($status=="0"){
    $status2 = "deactivated";
}elseif($status=="1"){
    $status2 = "activated";
}
useractivity("($row7->firstname $row7->lastname) has been ".$status2."", "56");

echo "<div class='alert alert-success'>Success: Status has been updated. </div>";
}

?>

<table class='table table-bordered table-hover table-striped sortable'>
 <thead>
<tr>
<th>Role</th>
<th>Names</th>
<th>Phonenumber</th>
<th>Email</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
include ("connect.php");
$result = $dbh->query("select * from users where role not like '%overadmin%' and role not like '%tech%' ");
$row = $result->fetchObject();
$count = $result->rowCount();

if($count>0){
do{

    if($row->role=="priadmin"){
        $role3 = "Admin - primary";
    
    }elseif($row->role=="secadmin"){
        $role3 = "Admin - Secondary";
    
    }elseif($row->role=="priaccount"){
        $role3 = "Accountant - Primary";
    
    }elseif($row->role=="secaccount"){
        $role3 = "Accountant - Secondary";
    
    }

echo "
<tr>
<td>".$role3."</td>
<td>".$row->firstname." ".$row->lastname."</td>
<td>".$row->phonenumber."</td>
<td>".$row->email."</td>
<td>
<form method='post'>
<input type='hidden' name='rolenumberz' value='".$row->rolenumber."'>
<select name='status' class='form-control'>";

$result7 = $dbh->query("select * from users where rolenumber='$row->rolenumber'");
$row7 = $result7->fetchObject();

if($row7->status=='1'){
    $status2 = "Active";

}elseif($row7->status=='0'){
    $status2 = "Inactive";
}

echo "
<option value='".$row7->status."'>".$status2."</option>
<option value='1'>Active</option>
<option value='0'>Inactive</option>
<input type='submit' class='btn btn-sm btn-success' name='submit4' value='Submit'>
</select>
</form>
</td>
</tr>
";
}while($row = $result->fetchObject());
}else{
    echo "So far, there is NO user.";
}

?>
</tbody>
</table>
</div></div>

</div>
                            </div> </div>
                    </div>
                </div>
                <!-- /.row -->

               

            </div>
            <!-- /.container-fluid -->
<?php useractivity("on page", "56"); ?>
        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

    <!-- jQuery -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/jquery-1.8.3.min.js" charset="UTF-8"></script>
</body>

</html>
