<?php 
define('DOCUMENT_ROOT_CLASS','../');
define('DOCUMENT_ROOT_INC_FOLDER','');
$filepath = realpath(dirname(__FILE__));
if(!empty($_POST["action"]) and $_POST["action"] == "ajax_call_1"){
    require "../inc/ajax_header.php";
    $commonFunctions->updateData('sys_users'," WHERE id = '".$_POST['user_id']."' ", ' first_name = "'.$_POST['first_name'].'",father_name = "'.$_POST['father_name'].'" ,last_name = "'.$_POST['last_name'].'",roleid = "'.$_POST['roleid'].'",username = "'.$_POST['username'].'",contact = "'.$_POST['contact'].'"','');
    echo 'users-card.php?user_id='.$_POST['user_id'];
    exit();
}
require "../inc/header.php";
Session::CheckSession(); 
$msg = Session::get('msg');
Session::set("msg", NULL); 
if(!empty($_POST['action']) and @$_POST['action'] == "profile"){
    $column = $fileName = "";
    if($_FILES["logo"]){
        $target_dir = "../uploads/admin-setting/users/";
        $target_file = $target_dir . basename($_FILES["logo"]["name"]);
        $uploadOk = 1;
        $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
        @getimagesize($_FILES["logo"]["tmp_name"]);
        if(move_uploaded_file($_FILES["logo"]["tmp_name"], $target_file)){
            $column = " logo";
            $fileName = " logo = '".$_FILES["logo"]["name"]."' ";
            $commonFunctions->updateData('sys_users'," WHERE id = '".$_POST['user_id']."' ", $fileName ,'users-card.php?user_id='.$_POST['user_id']);
        }
    }else{
        Session::set('msg', '<div class="alert alert-danger alert-dismissible mt-3" id="flash-msg"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Error !</strong> User profile picture not saved!</div>');
        echo "<script>location.href='users-card.php?user_id=".$_POST['user_id']."';</script>";
    }
    exit();
}
if(!empty($_POST['action']) and @$_POST['action'] == "reset_password"){
    if(!empty($_POST["password"])){
        $commonFunctions->updateData('sys_users'," WHERE id = '".$_POST['user_id']."' ", ' password = "'.SHA1($_POST['password']).'" ','users-card.php?user_id='.$_POST['user_id']);
    }else{
        Session::set('msg', '<div class="alert alert-danger alert-dismissible mt-3" id="flash-msg"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Error !</strong> Please enter password and confirm password!</div>');
        echo "<script>location.href='users-card.php?user_id=".$_POST['user_id']."';</script>";
    }
    exit();
}
if(!empty($_POST)){
    $error_ = 0;
    if(empty($_POST['user_id'])){
        Session::set('msg', '<div class="alert alert-danger alert-dismissible mt-3" id="flash-msg"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Error !</strong> Please enter code !</div>');
    }else{
        $id = $_POST['user_id'];
        $cntA = $commonFunctions->getRowData('sys_users',' WHERE id NOT IN('.$id.') AND user_id = "'.$_POST['user_id'].'" ');
        if(@count($cntA) > 1){
           $error_ = 1;
           Session::set('msg', '<div class="alert alert-danger alert-dismissible mt-3" id="flash-msg"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Error !</strong> Customer code already exists !</div>');
        }
    }

    if(!empty($_POST['user_id']) and $error_ == 0){
        if($_POST['action'] == "add"){
            $column = $fileName = "";
            if($_FILES["logo"]){
                $target_dir = "../uploads/admin-setting/users/";
                $target_file = $target_dir . basename($_FILES["logo"]["name"]);
                $uploadOk = 1;
                $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
                @getimagesize($_FILES["logo"]["tmp_name"]);
                if(move_uploaded_file($_FILES["logo"]["tmp_name"], $target_file)){
                    $column = " ,logo";
                    $fileName = " , '".$_FILES["logo"]["name"]."'";
                }
            }
            $rand = rand(0,999999999999999);
            
            $commonFunctions->addData('sys_users'," (first_name,father_name,last_name,email,contact,roleid,isActive,username".$column.") VALUES ('".$_POST['first_name']."','".$_POST['father_name']."','".$_POST['last_name']."','".$_POST['user_id']."','".$_POST['email']."','".$_POST['contact']."','".$_POST['roleid']."','".$_POST['isActive']."','".$_POST['username']."'".$fileName." ) ",'users.php?state=form');
        }
        if($_POST['action'] == "edit"){
            $column = $fileName = "";
            if($_FILES["logo"]){
                $target_dir = "../uploads/admin-setting/users/";
                $target_file = $target_dir . basename($_FILES["logo"]["name"]);
                $uploadOk = 1;
                $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
                @getimagesize($_FILES["logo"]["tmp_name"]);
                if(move_uploaded_file($_FILES["logo"]["tmp_name"], $target_file)){
                    $column = " ,logo";
                    $fileName = " ,logo = '".$_FILES["logo"]["name"]."' ";
                }
            }
            $commonFunctions->updateData('sys_users'," WHERE id = '".$_POST['user_id']."' ", " first_name = '".$_POST['first_name']."', father_name='".$_POST['father_name']."', last_name='".$_POST['last_name']."' , email='".$_POST['email']."' ,contact='".$_POST['contact']."', roleid='".$_POST['roleid']."', username='".$_POST['username']."', isActive='".$_POST['isActive']."'".$fileName ,'users.php?state=list');
        }
    }else{
        echo "<script>location.href='users.php?state=form';</script>";
    }
}
?>    
<style type="text/css"> td.text-primary { cursor: pointer; } </style>
        
    <!-- Page-Title -->
    <div class="row">
        <div class="col-sm-12">
            <div class="page-title-box">
                <div class="row">
                    <div class="col">
                        <h4 class="page-title">Users</h4>
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="javascript:void(0);">Settings</a></li>
                            <li class="breadcrumb-item"><a href="javascript:void(0);">User Management</a></li>
                            <li class="breadcrumb-item"><a href="javascript:void(0);">Users<?php echo (!empty($_GET['state']) and $_GET['state'] == "form")?" Form ":" List "; ?></a></li>
                        </ol>
                    </div><!--end col-->
                    <?php if($_GET['state'] != "list"){ ?>
                        <a href="users.php?state=list"><button type="button" class="btn btn-sm btn-outline-secondary clear_form">Back to Users List</button></a> 
                    <?php } ?>
                </div><!--end row-->                                                              
            </div><!--end page-title-box-->
        </div><!--end col-->
    </div><!--end row-->
    <!-- end page title end breadcrumb -->
    <div class="row">
        <div class="col-md-12">
            <?php if(empty($_GET['state']) OR (!empty($_GET['state']) and $_GET['state'] == "list")): ?>
                <div class="row justify-content-center">
                    <div class="col-md-6 col-lg-3">
                        <div class="card report-card">
                            <div class="card-body">
                                <div class="row d-flex justify-content-center">
                                    <div class="col">
                                        <p class="text-dark mb-0 font-weight-semibold">Total Users</p>
                                        <h3 class="m-0"><?php echo $commonFunctions->getRowDataCount('sys_users',''); ?></h3>
                                    </div>
                                    <div class="col-auto align-self-center">
                                        <div class="report-main-icon bg-light-alt">
                                            <i data-feather="users" class="align-self-center text-muted icon-sm"></i>  
                                        </div>
                                    </div>
                                </div>
                            </div><!--end card-body--> 
                        </div><!--end card--> 
                    </div> <!--end col--> 
                    <div class="col-md-6 col-lg-3">
                        <div class="card report-card">
                            <div class="card-body">
                                <div class="row d-flex justify-content-center">                                                
                                    <div class="col">
                                        <p class="text-dark mb-0 font-weight-semibold">Active Users</p>                
                                        <h3 class="m-0"><?php echo $commonFunctions->getRowDataCount('sys_users',' WHERE isActive = 0 '); ?></h3>
                                    </div>
                                    <div class="col-auto align-self-center">
                                        <div class="report-main-icon bg-light-alt">
                                            <i data-feather="clock" class="align-self-center text-muted icon-sm"></i>  
                                        </div>
                                    </div> 
                                </div>
                            </div><!--end card-body--> 
                        </div><!--end card--> 
                    </div> <!--end col--> 
                    <div class="col-md-6 col-lg-3">
                        <div class="card report-card">
                            <div class="card-body">
                                <div class="row d-flex justify-content-center">                                                
                                    <div class="col">
                                        <p class="text-dark mb-0 font-weight-semibold">In-Active Users</p>
                                        <h3 class="m-0"><?php echo $commonFunctions->getRowDataCount('sys_users',' WHERE isActive = 1 '); ?></h3>
                                    </div>
                                    <div class="col-auto align-self-center">
                                        <div class="report-main-icon bg-light-alt">
                                            <i data-feather="clock" class="align-self-center text-muted icon-sm"></i>  
                                        </div>
                                    </div> 
                                </div>
                            </div><!--end card-body--> 
                        </div><!--end card--> 
                    </div> <!--end col--> 
                                           
                </div><!--end row-->
            <?php endif; ?>
            <?php if(!empty($_GET['state']) and $_GET['state'] != "edit" ){ ?>
                <div class="card">
                    <div class="card-header">
                        <h4 class="card-title">
                            <div class="form-row">
                                <div class="form-group searchForm col-md-6">
                                    <a href="users-form.php?state=form" style="float: left;"><button type="button" class="btn btn-outline-primary">Add User</button></a>
                                </div>    
                                <div class="form-group searchForm col-md-6">
                                <?php if(empty($_GET['state']) OR (!empty($_GET['state']) and $_GET['state'] == "list")): ?>    
                                    <form action="" id="searchForm" method="GET">
                                        <div class="form-row">
                                            <div class="form-group searchForm col-md-8">
                                                <input type="text" name="search" id="search" placeholder="Search" class="form-control" value="<?php echo @$_GET['search']; ?>">
                                                <input type="hidden" name="state" value="<?php echo @$_GET['state']; ?>">
                                                <input type="hidden" name="page" value="<?php echo @$_GET['page']; ?>">
                                            </div>
                                            <div class="form-group searchForm col-md-4">
                                                <button type="submit" id="searchbtn" class="btn btn-primary"> <i class="fa fa-search"></i> Search</button>
                                                <button type="button" id="clearbtn" class="btn btn-danger"> <i class="fa fa-trash"></i> Clear</button>
                                            </div>
                                        </div>
                                    </form>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </h4>
                        <?php echo !empty($msg)?$msg:''; ?>        
                        <?php echo !empty($msg1)?$msg1:''; ?>        
                    </div>
            
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="main-card mb-3 ">
                                    <!-- <div class="card-body"> -->
                                        <?php if(!empty($_GET['state']) and $_GET['state'] != "list" ):
                                            if(!empty($_GET['user_id'])){
                                                $editData = $commonFunctions->getRowData('sys_users'," WHERE id = '".$_GET['user_id']."' ");
                                            }
                                            ?>
                                            <form enctype="multipart/form-data" action="users.php?state=form&action=add" method="post" name="formsoc" autocomplete="off">      
                                                <div class="form-row">
                                                    <input type="hidden" name="action" value="<?php echo !empty($_GET['user_id'])?'edit':'add';?>">
                                                    <input type="hidden" name="user_id" value="<?php echo @$_GET['user_id'];?>">
                                                    <input type="hidden" name="isActive" value="1">
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="first_name" class="">First Name</label>
                                                        <input type="text" maxlength="128" name="first_name" id="first_name" value="<?php echo @$editData['first_name'];?>" autofocus="autofocus" class="form-control" placeholder="First Name">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="father_name" class="">Middle Name</label>
                                                        <input type="text" maxlength="128" name="father_name" id="father_name" value="<?php echo @$editData['father_name'];?>" autofocus="autofocus" class="form-control" placeholder="Middle Name">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="last_name" class="">Last Name</label>
                                                        <input type="text" maxlength="128" name="last_name" id="last_name" value="<?php echo @$editData['last_name'];?>" autofocus="autofocus" class="form-control" placeholder="Last Name">
                                                    </div>
                                                    
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="contact" class="">Phone</label>
                                                        <input type="text" maxlength="128" name="contact" id="contact" value="<?php echo @$editData['contact'];?>" autofocus="autofocus" class="form-control" placeholder="Phone">
                                                    </div>
                                                    
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="email" class="">Personal eMail</label>
                                                        <input type="text" maxlength="128" name="email" id="email" value="<?php echo @$editData['email'];?>" autofocus="autofocus" class="form-control" placeholder="Personal eMail">
                                                    </div>

                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="username" class="">UserName <span class="error">*</span></label>
                                                        <input type="text" maxlength="128" name="username" id="username" value="<?php echo @$editData['username'];?>" autofocus="autofocus" class="form-control" placeholder="UserName" required="">
                                                    </div>
                                                    
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="roleid">Select User Type <span class="error">*</span></label>
                                                        <?php $optionData = $commonFunctions->getData('sys_roles',' WHERE isActive = 0 '); ?>
                                                        <select class="form-control" name="roleid" id="roleid">
                                                          <?php foreach ($optionData as $key) { ?>
                                                            <option value="<?php echo $key['id'];?>" <?php echo (!empty(@$editData['roleid']) and $key['id'] == $editData['roleid'])?"selected":""; ?> ><?php echo $key['role'];?></option>
                                                          <?php } ?>
                                                        </select>
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="logo" class=""> User Photo (Avatar) </label>
                                                        <input type="file" name="logo" >
                                                    </div>

                                                    <div class="position-relative form-group col-md-12">
                                                        <button type="submit" class="btn btn-success">Create</button>
                                                        <a href="users.php?state=list"><button type="button" class="btn btn-danger">Back to Users List</button></a>
                                                    </div>
                                                </div>
                                            </form>
                                        <?php endif; ?>
                                        <?php if(empty($_GET['state']) OR (!empty($_GET['state']) and $_GET['state'] == "list")): 

                                            $targetpage = "users.php?state=list";

                                            $limit = 50;
                                            $total_pages = $commonFunctions->getData('sys_users',' WHERE roleid != 1 ');
                                            $total_pages = count($total_pages);
                                            $stages = 3;
                                            $page = @$_GET['page'];
                                            if($page){
                                                $start = ($page - 1) * $limit; 
                                            }else{
                                                $start = 0; 
                                            } 
                                            
                                            $search_con = "";
                                            if(!empty($_GET['search'])){
                                                
                                                $search_con = " AND first_name LIKE '%".$_GET['search']."%' OR father_name LIKE '%".$_GET['search']."%' OR last_name LIKE '%".$_GET['search']."%' OR email LIKE '%".$_GET['search']."%' OR contact LIKE '%".$_GET['search']."%'";
                                            }
                                            $where = " WHERE id ".$search_con." AND roleid != 1 ORDER BY id DESC LIMIT $start, $limit ";
                                           
                                            // Initial page num setup
                                            if ($page == 0){ $page = 1; }
                                            $prev = $page - 1;  
                                            $next = $page + 1;  
                                            $lastpage = ceil($total_pages/$limit);  
                                            $LastPagem1 = $lastpage - 1;    
                                            $paginate = '';
                                            if($lastpage > 1)
                                            {       
                                                $paginate .= "<div class='paginate'>";
                                                // Previous

                                                if ($page > 1){
                                                    $paginate.= "<a href='$targetpage&page=$prev'>Previous</a>";
                                                }else{
                                                    $paginate.= "<span class='disabled'>Previous</span>";   }
                                                // Pages    
                                                if ($lastpage < 7 + ($stages * 2))  // Not enough pages to breaking it up
                                                {   
                                                    for ($counter = 1; $counter <= $lastpage; $counter++)
                                                    {
                                                        if ($counter == $page){
                                                            $paginate.= "<span class='current'>$counter</span>";
                                                        }else{
                                                            $paginate.= "<a href='$targetpage&page=$counter'>$counter</a>";}    
                                                    }
                                                }
                                                elseif($lastpage > 5 + ($stages * 2))   // Enough pages to hide a few?
                                                {
                                                    // Beginning only hide later pages
                                                    if($page < 1 + ($stages * 2))   
                                                    {
                                                        for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
                                                        {
                                                            if ($counter == $page){
                                                                $paginate.= "<span class='current'>$counter</span>";
                                                            }else{
                                                                $paginate.= "<a href='$targetpage&page=$counter'>$counter</a>";}    
                                                        }
                                                        $paginate.= "...";
                                                        $paginate.= "<a href='$targetpage&page=$LastPagem1'>$LastPagem1</a>";
                                                        $paginate.= "<a href='$targetpage&page=$lastpage'>$lastpage</a>";
                                                    }
                                                    // Middle hide some front and some back
                                                    elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
                                                    {
                                                        $paginate.= "<a href='$targetpage&page=1'>1</a>";
                                                        $paginate.= "<a href='$targetpage&page=2'>2</a>";
                                                        $paginate.= "...";
                                                        for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
                                                        {
                                                            if ($counter == $page){
                                                                $paginate.= "<span class='current'>$counter</span>";
                                                            }else{
                                                                $paginate.= "<a href='$targetpage&page=$counter'>$counter</a>";}    
                                                        }
                                                        $paginate.= "...";
                                                        $paginate.= "<a href='$targetpage&page=$LastPagem1'>$LastPagem1</a>";
                                                        $paginate.= "<a href='$targetpage&page=$lastpage'>$lastpage</a>";
                                                    }
                                                    // End only hide early pages
                                                    else
                                                    {
                                                        $paginate.= "<a href='$targetpage&page=1'>1</a>";
                                                        $paginate.= "<a href='$targetpage&page=2'>2</a>";
                                                        $paginate.= "...";
                                                        for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
                                                        {
                                                            if ($counter == $page){
                                                                $paginate.= "<span class='current'>$counter</span>";
                                                            }else{
                                                                $paginate.= "<a href='$targetpage&page=$counter'>$counter</a>";}
                                                        }
                                                    }       
                                                }       
                                                        // Next
                                                if ($page < $counter - 1){ 
                                                    $paginate.= "<a href='$targetpage&page=$next'>Next</a>";
                                                }else{
                                                    $paginate.= "<span class='disabled'>Next</span>";
                                                    }
                                                $paginate.= "</div>";   
                                            }
                                            $resultData = $commonFunctions->getData('sys_users',$where);
                                            ?>
                                            <div class="form-row1 table-rep-plugin">
                                                <div class="table-responsive1 mb-0" data-pattern="priority-columns">
                                                    <table style="width: 100% !important;" class="table datatable_t table-hover table-striped table-bordered">
                                                        <thead>
                                                            <tr>
                                                                <th  class="text-center">Name</th>
                                                                <th  class="text-center">UserName</th>
                                                                <th  class="text-center">Phone No</th>
                                                                <th  class="text-center">Email Address</th>
                                                                <th  class="text-center">User User Role</th>
                                                                <th  class="text-center">User Status</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                            <?php $i = 1; foreach ($resultData as $rw) { ?>
                                                                <tr>
                                                                    <td class="text-primary" onclick=" return window.location.href='users-card.php?user_id=<?php echo $rw['id'];?>';"><?php echo $rw['first_name']." ".$rw['father_name']." ".$rw['last_name'];?></td>
                                                                    <td class="text-primary" onclick=" return window.location.href='users-card.php?user_id=<?php echo $rw['id'];?>';" ><?php echo $rw['username'];?></td>
                                                                    <td><?php echo $rw['contact'];?></td>
                                                                    <td class="text-primary" onclick=" return window.location.href='users-card.php?user_id=<?php echo $rw['id'];?>';" ><?php echo $rw['email'];?></td>
                                                                    
                                                                    <td class="text-primary" onclick=" return window.location.href='users-card.php?user_id=<?php echo $rw['id'];?>';" > <?php echo $commonFunctions->getName($rw['roleid'],'sys_roles','role','id'); ?>
                                                                    </td>

                                                                    <td>
                                                                        <?php if ($rw['isActive'] == '0') { ?>
                                                                            <span class="badge badge-lg badge-info text-white">Active</span>
                                                                        <?php }else{ ?>
                                                                            <span class="badge badge-lg badge-danger text-white">Deactive</span>
                                                                        <?php } ?>
                                                                    </td>
                                                                </tr>
                                                            <?php } ?>
                                                        </tbody>
                                                    </table>
                                                </div>
                                            </div>
                                            <?php echo "<center>".$paginate."</center>";?>
                                        <?php endif; ?>
                                    <!-- </div> -->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            <?php }else{ 
                $userData = $commonFunctions->getRowData('sys_users'," WHERE id = '".@$_GET['user_id']."' ");
                ?>
                <div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-body">
                                <div class="dastone-profile">
                                    <div class="row">
                                        <div class="col-lg-4 align-self-center mb-3 mb-lg-0">
                                            <div class="dastone-profile-main">
                                                <div class="dastone-profile-main-pic">
                                                    <img src="../uploads/admin-setting/users/<?php echo (@$userData['logo'])?$userData['logo']:'default-img.jpg';?>" alt="" height="110" class="thumb-lx rounded" style='max-width:140px;'>
                                                    <span class="dastone-profile_main-pic-change">
                                                        <i class="fas fa-camera"></i>
                                                    </span>
                                                    <form enctype="multipart/form-data" method="post" id="fileUploadForm">
                                                        <input type="hidden" name="action" value="profile">
                                                        <input type="hidden" name="user_id" value="<?php echo $userData['id'];?>">
                                                        <input type="file" name="logo" value="" style='display: none;' id="fileUpload">
                                                    </form>
                                                </div>
                                                <div class="dastone-profile_user-detail">
                                                    <h5 class="dastone-user-name"><?php echo @$userData['first_name']." ".$userData['father_name']." ".$userData['last_name'];?></h5>
                                                    <p class="mt-0 mb-0"><i class="text-secondary font-22 align-middle"></i> <b> Designation / Job Title :</b> <?php echo $commonFunctions->getName($userData['roleid'],'sys_roles','role','id'); ?></p>
                                                </div>
                                            </div>                                                
                                        </div><!--end col-->
                                        
                                        <div class="col-lg-4 ml-auto align-self-center">
                                            <ul class="list-unstyled personal-detail mb-0">
                                                <li class="mt-2"><i class="las la-phone mr-2 text-secondary font-22 align-middle"></i> <b> phone </b> :  <?php echo (@$userData['contact'])?@$userData['contact']:"-";?></li>
                                                
                                                <li class="mt-2"><i class="las la-envelope text-secondary font-22 align-middle mr-2"></i> <b> Email </b> :   <a href="mailto:<?php echo (@$userData['email'])?@$userData['email']:"-";?>"><?php echo (@$userData['email'])?@$userData['email']:"-";?></a></li>                                                  
                                            </ul>                                               
                                        </div><!--end col-->
                                        
                                        <div class="col-lg-4 align-self-center">
                                            <div class="row">
                                                <div class="col-auto text-right border-right">
                                                    <button type="button" class="btn btn-soft-primary btn-icon-circle-sm mb-2">
                                                        <i class="fab fa-facebook-f"></i>
                                                    </button>
                                                    <p class="mb-0 font-weight-semibold">Facebook</p>
                                                    <h4 class="m-0 font-weight-bold">0k <span class="text-muted font-12 font-weight-normal">Followers</span></h4>
                                                </div><!--end col-->
                                                <div class="col-auto">
                                                    <button type="button" class="btn btn-soft-info btn-icon-circle-sm mb-2">
                                                        <i class="fab fa-twitter"></i>
                                                    </button>
                                                    <p class="mb-0 font-weight-semibold">Twitter</p>
                                                    <h4 class="m-0 font-weight-bold">0k <span class="text-muted font-12 font-weight-normal">Followers</span></h4>
                                                </div><!--end col-->
                                            </div><!--end row-->                                               
                                        </div><!--end col-->
                                    </div><!--end row-->
                                </div><!--end f_profile-->                                                                                
                            </div>
                        </div> 
                    </div><!--end col-->
                </div><!--end row-->
                <div class="pb-4">
                    <ul class="nav-border nav nav-pills mb-0" id="pills-tab" role="tablist">
                        <li class="nav-item">
                            <a class="nav-link active" id="user_details_tab" data-toggle="pill" href="#user_details">User Details</a>
                        </li>
                        
                        <li class="nav-item">
                            <a class="nav-link" id="user_security_tab" data-toggle="pill" href="#security">Security</a>
                        </li>

                    </ul>        
                </div><!--end card-body-->
                <style type="text/css">
                    label.form-control1 {display: block;}
                    label.label-title {font-weight: 600;}
                </style>
                <div class="row">
                    <div class="col-12">
                        <?php echo !empty($msg)?$msg:''; ?>        
                        <?php echo !empty($msg1)?$msg1:''; ?>      
                        <div class="tab-content" id="pills-tabContent">
                            <div class="tab-pane fade show active" id="user_details" role="tabpanel" aria-labelledby="user_details_tab">
                                <div class="row" >
                                    <div class="col-lg-6 col-xl-6">
                                        <form action="" class="personalInfoForm">
                                            <div class="card">
                                                <div class="card-header">
                                                    <div class="row align-items-center">
                                                        <div class="col-11">                      
                                                            <h4 class="card-title text-left">Personal Information</h4>                      
                                                        </div><!--end col-->
                                                        <div class="col-1">                      
                                                            <a class="FormBtn" href="javascript:void(0);"><button type="button" class="text-right btn btn-sm btn-success waves-effect waves-light">Save</button></a>              
                                                        </div><!--end col-->                                                       
                                                    </div>  <!--end row-->                                  
                                                </div><!--end card-header-->
                                                <div class="card-body">
                                                    <input type="hidden" name="user_id" value="<?php echo @$_GET['user_id'];?>">
                                                    <div class="form-group row">                                         
                                                        <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">First Name</label>
                                                        <div class="col-lg-9 col-xl-8">
                                                            <h5 class="card-title">
                                                                <input type="text" name="first_name" value="<?php echo @$userData['first_name'];?>" class="form-control">
                                                            </h5>
                                                        </div>
                                                    </div>
                                                    <div class="form-group row">                                         
                                                        <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Middle Name</label>
                                                        <div class="col-lg-9 col-xl-8">
                                                            <h5 class="card-title"> 
                                                                <input type="text" name="father_name" value="<?php echo @$userData['father_name'];?>" class="form-control">
                                                            </h5>
                                                        </div>
                                                    </div>
                                                    <div class="form-group row">                                         
                                                        <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Last Name</label>
                                                        <div class="col-lg-9 col-xl-8">
                                                            <h5 class="card-title">
                                                                <input type="text" name="last_name" value="<?php echo @$userData['last_name'];?>" class="form-control"> </h5>
                                                        </div>
                                                    </div>
                                                    <div class="form-group row">                                         
                                                        <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Designation / Job Title</label>
                                                        <div class="col-lg-9 col-xl-8">
                                                            <h5 class="card-title"> 
                                                                <?php $optionData = $commonFunctions->getData('sys_roles',' WHERE isActive = 0 '); ?>
                                                                <select class="form-control" name="roleid" id="roleid" required="">
                                                                  <?php foreach ($optionData as $key) { ?>
                                                                    <option value="<?php echo $key['id'];?>" <?php echo (!empty(@$userData['roleid']) and $key['id'] == $userData['roleid'])?"selected":""; ?> ><?php echo $key['role'];?></option>
                                                                  <?php } ?>
                                                                </select>

                                                             </h5>
                                                        </div>
                                                    </div>

                                                </div>                                        
                                            </div>
                                        </form>
                                        <!-- Personal Information Card - End --->
                                    </div>

                                    <div class="col-lg-6 col-xl-6">
                                        <!-- Contact Information Personal Card - End --->
                                        <form action="" class="contactInfoForm">    
                                            <div class="card">
                                                <div class="card-header">
                                                    <div class="row align-items-center">
                                                        <div class="col-11">                      
                                                            <h4 class="card-title text-left">Contact Information <label class="col-xl-3 col-lg-3 mb-lg-0 align-self-center">( Personal )</label></h4>                      
                                                        </div><!--end col-->
                                                        <div class="col-1">                      
                                                            <a class="FormBtn" href="javascript:void(0);"><button type="button" class="text-right btn btn-sm btn-success waves-effect waves-light">Save</button></a>
                                                        </div><!--end col-->                                                       
                                                    </div>  <!--end row-->                                  
                                                </div><!--end card-header-->
                                                <div class="card-body">                                                                          
                                                    <div class="form-group row">                                         
                                                        <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Phone</label>
                                                        <div class="col-lg-9 col-xl-8">
                                                            <h5 class="card-title"> 
                                                                <input type="text" name="contact" value="<?php echo @$userData['contact'];?>" class="form-control"> </h5>
                                                        </div>
                                                    </div>
                                                    
                                                    <div class="form-group row">                                         
                                                        <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Email Address</label>
                                                        <div class="col-lg-9 col-xl-8">
                                                            <h5 class="card-title"> 
                                                                <input type="text" name="email" value="<?php echo @$userData['email'];?>" class="form-control">
                                                            </h5>
                                                        </div>
                                                    </div>                                                   
                                                </div><!--end card-body-->
                                            </div><!--end card-->
                                        </form>
                                        
                                    </div>
                                    
                                </div>
                            </div>
                             
                            <div class="tab-pane" id="security" role="tabpanel" aria-labelledby="user_security_tab">
                                <div class="card">
                                    <div class="card-body">
                                        <form id="reset-password-form" action="" method="post">
                                            <input type="hidden" name="user_id" id="user_id" value="<?php echo $userData['id'];?>" >
                                            <input type="hidden" name="action" value="reset_password">
                                            <div class="form-row">
                                                <div class="col-lg-2"></div>
                                                <div class="col-lg-8">
                                                    <div class="form-row">
                                                        <div class="form-group searchForm col-md-6">
                                                            <label for="password" class="">Password</label>
                                                            <input type="password" maxlength="128" name="password" id="password" value="" autofocus="autofocus" class="form-control" placeholder="Password" required="">
                                                        </div>
                                                        <div class="form-group searchForm col-md-6">
                                                            <label for="cnf_password" class="">Confirm Password</label>
                                                            <input type="text" maxlength="128" name="cnf_password" id="cnf_password" value="" autofocus="autofocus" class="form-control" placeholder="Confirm Password" required="">
                                                        </div>
                                                        <div class="form-group searchForm col-md-12" style="text-align: center;">
                                                            <br>
                                                            <button type="submit" class="btn btn-primary"> Save </button>
                                                            <br>
                                                            <br>
                                                            <br>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-lg-2"></div>
                                            </div>
                                        </form>
                                    </div><!--end row-->    
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            <?php } ?>
        </div> <!-- end col -->
    </div> <!-- end row -->
    
<?php require "../inc/footer.php"; ?>
<script type="text/javascript">
$("#clearbtn").click(function(){
    $("#search").val('');
    $("#searchForm").submit();
});
function redirect_1(uri){
    window.location.href = uri;
}
$(".dastone-profile_main-pic-change").click(function(){
    $("#fileUpload").click();
});
$("#fileUpload").change(function(){
    if(confirm("Please make sure do you want to change your profile picture?")){
        $("#fileUploadForm").submit();
    }else{
        return false;
    }
});
$(".FormBtn").click(function(){
    $.ajax({
        type: 'POST',
        url: "",
        data: $('.personalInfoForm').serialize()+"&"+$('.contactInfoForm').serialize()+"&action=ajax_call_1",
        success: function(response) { 
          window.location.href = response;
        }
    });
});
</script>