<?php
require("../connection.php");
include("../user.php");
$user_id = $_SESSION['user'];
$username = $_SESSION['user_name'];
$branch = $_SESSION['division_name'];
?>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title><?php echo TITLE; ?></title>
    <meta name="description" content="Ela Admin - HTML5 Admin Template">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="apple-touch-icon" href="../images/bluebase.png">
    <link rel="shortcut icon" href="../images/bluebase.png">

    <link rel="stylesheet" href="../css/normalize.min.css">
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/themify-icons.css">
    <link rel="stylesheet" href="../css/pe-icon-7-stroke.min.css">
    <link rel="stylesheet" href="../css/flag-icon.min.css">
    <link rel="stylesheet" href="../assets/css/cs-skin-elastic.css">
    <link rel="stylesheet" href="../assets/css/style.css">
    <link href="../css/chartist.min.css" rel="stylesheet">
    <link href="../css/jqvmap.min.css" rel="stylesheet">

    <link href="../css/weather-icons.css" rel="stylesheet" />
    <link href="../css/fullcalendar.min.css" rel="stylesheet" />

    <script src="../js/jquery-1.12.4.min.js"></script>
    <script src="../js/jquery-3.3.1.js"></script>
    <script src="../js/jquery.dataTables.min.js"></script>


    <script src="../js/popper.min.js"></script>
    <script src="../js/bootstrap.min.js"></script>
    <script src="../js/jquery.matchHeight.min.js"></script>
    <script src="../assets/js/main.js"></script>
    <script src="../js/jquery-3.3.1.min.js"></script>
    <style>
        #weatherWidget .currentDesc {
            color: #ffffff !important;
        }

        .traffic-chart {
            min-height: 335px;
        }

        #flotPie1 {
            height: 150px;
        }

        #flotPie1 td {
            padding: 3px;
        }

        #flotPie1 table {
            top: 20px !important;
            right: -10px !important;
        }

        .chart-container {
            display: table;
            min-width: 270px;
            text-align: left;
            padding-top: 10px;
            padding-bottom: 10px;
        }

        #flotLine5 {
            height: 105px;
        }

        #flotBarChart {
            height: 150px;
        }

        #cellPaiChart {
            height: 160px;
        }

        th {
            text-transform: uppercase;
        }

        td {
            text-transform: uppercase;
        }
    </style>

    <link rel="stylesheet" href="/asset_temp/datatable/css/jquery.dataTables.min.css">
    <script src="/asset_temp/datatable/js/jquery.dataTables.min.js"></script>
    <!-- button -->
    <link rel="stylesheet" type="text/css" href="/asset_temp/button/css/buttons.css" /><!-- button -->

    <script>
        $(document).ready(function() {
            $('#example').DataTable();
        });
    </script>
</head>

<body>
    <?php require('../sidemenu.php'); ?>
    <!-- /#left-panel -->
    <!-- Right Panel -->
    <div id="right-panel" class="right-panel">
        <!-- Header-->
        <?php require('../header.php'); ?>
        <div class="content">
            <!-- Animated -->
            <div class="animated fadeIn">
                <div style="background-color:white;margin-bottom:10px;">
                    <strong style="color:blue">
                        <center>USER LIST</center>
                    </strong>
                </div>
                <button class="button button--moema button--text-thick button--text-upper button--size-s" style="padding:1.5px;" onclick="newuser()"><i class="fa fa-user-plus">CREATE</i></button>
                <table id="example" class="table table-striped table-bordered">
                    <?php
                    //$row=mysqli_query($con,"select u.user_id,u.full_name,u.user_name,u.password,u.email_id,rm.code,bm.location,bmm.branch_name as branch_names,case when u.status='0' then 'ACTIVE' else 'INACTIVE' end as Status,case when rr.role_name is null then 'MAPPING PENDING' else  rr.role_name end as role from user_master u left join branch_mapping b on u.user_id=b.user_id left join location_master bm on bm.id=b.branch_id left join role_mapping rm on rm.user_id=u.user_id left join role_master rr on rr.code=rm.code join branch_master bmm on b.division_id=bmm.id where b.to_date is null and rm.to_date is null order by u.user_id desc");	

                    $row = mysqli_query($con, "select  u.user_id,u.full_name,u.user_name,u.password,u.email_id,rm.code,bm.location,
case when u.status='0' then 'ACTIVE' else 'INACTIVE' end as Status,case when rr.role_name is null then 'MAPPING PENDING' else  rr.role_name end as role,case when b.division_id is null then 'MAPPING PENDING' else  b.division_id end as branch_names from user_master u left join branch_mapping b on u.user_id=b.user_id left join location_master bm on bm.id=b.branch_id left join role_mapping rm on rm.user_id=u.user_id left join role_master rr on rr.code=rm.code where b.to_date is null and rm.to_date is null order by u.user_id desc");    ?>
                    <thead>
                        <tr>
                            <th>S.No</th>
                            <th>Full Name</th>
                            <th>User Name</th>
                            <th>Email</th>
                            <th>Branch</th>
                            <th>Division</th>
                            <th>Role</th>
                            <th>Status</th>
                            <th>Action</th>
                        </tr>
                    </thead>

                    <tbody>
                        <?php
                        $s = 1;
                        while ($type = mysqli_fetch_array($row)) { ?>
                            <tr>
                                <td><?php echo $s++; ?></td>
                                <td><?php echo $type['full_name']; ?></td>
                                <td><?php echo $type['user_name']; ?></td>
                                <td><?php echo $type['email_id']; ?></td>
                                <?php $branch_name = $type['location'];
                                if ($branch_name == "") {     ?>
                                    <td style="color:red;"><?php echo "MAPPING PENDING"; ?></td>
                                <?php } else {    ?>
                                    <td><?php echo $type['location']; ?></td>
                                <?php    }
                                $division_name = $type['branch_names'];
                                if ($division_name == "MAPPING PENDING") {
                                    $branch_name = "MAPPING PENDING";
                                } else {
                                    $branch_detail = mysqli_fetch_array(mysqli_query($con, "SELECT * FROM branch_master where id='$division_name'"));
                                    $branch_name = $branch_detail['branch_name'];
                                }

                                if ($division_name == "MAPPING PENDING") {     ?>
                                    <td style="color:red;"><?php echo $branch_name; ?></td>
                                <?php } else {    ?>
                                    <td><?php echo $branch_name; ?></td>
                                <?php    }
                                $branch = $type['role'];
                                if ($branch == "MAPPING PENDING") {    ?>
                                    <td style="color:red;"><?php echo $type['role']; ?></td>
                                <?php } else {    ?>
                                    <td><?php echo strtoupper($type['role']); ?></td>
                                <?php    } ?>
                                <td><?php echo $type['Status']; ?></td>

                                <?php
                                $stat = $type['Status'];
                                if ($stat == "ACTIVE") {
                                ?>
                                    <td class="text-left">
                                        <button type="button" class="btn btn-link btn-round" id="<?php echo $type['user_id']; ?>" title="Edit User" onclick="edituser(this.id)"><i class="fa fa-edit"></i></button>
                                        <button type="button" onclick="deactivate_user(this.id)" id="<?php echo $type['user_id']; ?>" class="btn btn-link btn-round" title="Inactive"><i class="fa fa-eye-slash"></i></button>
                                        <button type="button" onclick="reset_password(this.id)" id="<?php echo $type['user_id']; ?>" class="btn btn-link btn-round" title="Reset Password"><i class="fa fa-undo"></i></button>
                                        <button type="button" onclick="delete_user(this.id)" id="<?php echo $type['user_id']; ?>" class="btn btn-link btn-round" title="Delete"><i class="fa fa-trash"></i></button>
                                    </td>
                                    <!--button type="button" onclick="delete_detail(this.id)" id="<!?php echo $type['user_id'];?>"class="btn btn-link btn-round" title="Inactive item"><i class="md md-delete"></i></button-->
                                <?php
                                } else {
                                ?>

                                    <td>&emsp;&emsp;<button type="button" onclick="activate_user(this.id)" id="<?php echo $type['user_id']; ?>" class="btn btn-link btn-round" title="Active"><i class="fa fa-eye"></i></button></td>
                                <?php
                                }
                                ?>


                            </tr>
                        <?php
                        }
                        ?>
                    </tbody>
                </table>

            </div>
        </div>
        <div class="clearfix"></div>
    </div>
</body>

</html>

<?php require("../mainjavascript.js"); ?>