<?php 
define('DOCUMENT_ROOT_CLASS','../');
define('DOCUMENT_ROOT_INC_FOLDER','');
$filepath = realpath(dirname(__FILE__));
if(!empty($_POST["action"]) and $_POST["action"] == "ajax_call"){
    require "../inc/ajax_header.php";
    $country_id = $_POST["country_id"];
    $getData = $commonFunctions->getData('sys_erp_adm_countries_states'," WHERE country_id = '".$country_id."' and active = 1 ");
    $html = "";
    foreach ($getData as $rw) {
        $html .= "<option value='".$rw['rowid']."'>".$rw['label']."</option>";
    }
    echo json_encode(array("option"=>$html));
    exit();
}
if(!empty($_GET["action"]) and $_GET["action"] == "ajax_call1"){
    require "../inc/ajax_header.php";
    $country_id = $_GET["country_id"];
    $state_id = $_GET["state_id"];
    $keyword = $_GET["keyword"]; 
    $getData = $commonFunctions->getData('sys_erp_adm_countries_states_cities'," WHERE country_id = '".$country_id."' and state_id = '".$state_id."' and name LIKE '%".$keyword."%' ");
    $html = "";
    $skillData = array(); 
    foreach ($getData as $rw) {
        $data['id'] = $rw['name']; 
        $data['value'] = $rw['name']; 
        array_push($skillData, $data); 
    } 
    echo json_encode($skillData);
    exit();
}
if(!empty($_POST["action"]) and $_POST["action"] == "ajax_call_1"){
    require "../inc/ajax_header.php";
    /*echo "<pre>";
    print_r($_POST);*/
    $commonFunctions->updateData('sys_erp_adm_user'," WHERE id = '".$_POST['user_id']."' ", ' erp_sys_user_name_first = "'.$_POST['erp_sys_user_name_first'].'",erp_sys_user_name_middle = "'.$_POST['erp_sys_user_name_middle'].'" ,erp_sys_user_name_last = "'.$_POST['erp_sys_user_name_last'].'",erp_sys_user_roleid = "'.$_POST['erp_sys_user_roleid'].'",erp_sys_user_mobile2 = "'.$_POST['erp_sys_user_mobile2'].'",erp_sys_user_id_msngr_whatsapp = "'.$_POST['erp_sys_user_id_msngr_whatsapp'].'",erp_sys_user_email_personal = "'.$_POST['erp_sys_user_email_personal'].'",erp_sys_user_id_sm_linkedin = "'.$_POST['erp_sys_user_id_sm_linkedin'].'",erp_sys_user_id_sm_twitter = "'.$_POST['erp_sys_user_id_sm_twitter'].'",erp_sys_user_id_sm_facebook = "'.$_POST['erp_sys_user_id_sm_facebook'].'",erp_sys_user_mobile_work = "'.$_POST['erp_sys_user_mobile_work'].'",erp_sys_org_phone_work = "'.$_POST['erp_sys_org_phone_work'].'",erp_sys_org_fax = "'.$_POST['erp_sys_org_fax'].'",erp_sys_user_email_work = "'.$_POST['erp_sys_user_email_work'].'",erp_sys_user_address = "'.$_POST['erp_sys_user_address'].'",erp_sys_user_city = "'.$_POST['erp_sys_user_city'].'",erp_sys_user_zipcode = "'.$_POST['erp_sys_user_zipcode'].'",erp_sys_user_state = "'.$_POST['erp_sys_user_state'].'",erp_sys_user_country = "'.$_POST['erp_sys_user_country'].'" ','');
    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["erp_sys_user_logo"]){
        $target_dir = "../uploads/admin-setting/users/";
        $target_file = $target_dir . basename($_FILES["erp_sys_user_logo"]["name"]);
        $uploadOk = 1;
        $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
        @getimagesize($_FILES["erp_sys_user_logo"]["tmp_name"]);
        if(move_uploaded_file($_FILES["erp_sys_user_logo"]["tmp_name"], $target_file)){
            $column = " erp_sys_user_logo";
            $fileName = " erp_sys_user_logo = '".$_FILES["erp_sys_user_logo"]["name"]."' ";
            $commonFunctions->updateData('sys_erp_adm_user'," 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_erp_adm_user'," WHERE id = '".$_POST['user_id']."' ", ' erp_sys_user_secutiry_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['erp_sys_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_erp_adm_user',' WHERE id NOT IN('.$id.') AND erp_sys_user_id = "'.$_POST['erp_sys_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['erp_sys_user_id']) and $error_ == 0){
        if($_POST['action'] == "add"){
            $column = $fileName = "";
            if($_FILES["erp_sys_user_logo"]){
                $target_dir = "../uploads/admin-setting/users/";
                $target_file = $target_dir . basename($_FILES["erp_sys_user_logo"]["name"]);
                $uploadOk = 1;
                $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
                @getimagesize($_FILES["erp_sys_user_logo"]["tmp_name"]);
                if(move_uploaded_file($_FILES["erp_sys_user_logo"]["tmp_name"], $target_file)){
                    $column = " ,erp_sys_user_logo";
                    $fileName = " , '".$_FILES["erp_sys_user_logo"]["name"]."'";
                }
            }
            $rand = rand(0,999999999999999);
            $commonFunctions->addData('global_contacts'," (cont_random_num,global_user_name_first,global_user_name_middle,global_user_name_last,global_user_email_personal,global_user_mobile1,global_user_mobile2,global_user_mobile_work,global_org_name,global_user_job_title,global_org_phone_work,global_user_org_phone_work_ext,global_org_fax,global_user_email_work,global_user_id_sm_linkedin,global_user_id_sm_twitter,global_user_id_sm_facebook,global_user_id_sm_instagram,global_user_id_msngr_skype,global_user_id_msngr_whatsapp,global_user_id_msngr_imo,global_user_id_msngr_telegram,global_user_id_msngr_signal,global_user_id_msngr_botim,global_user_id_messanger_viber) VALUES ('".$rand."','".$_POST['erp_sys_user_name_first']."','".$_POST['erp_sys_user_name_middle']."','".$_POST['erp_sys_user_name_last']."','".$_POST['erp_sys_user_email_personal']."','".$_POST['erp_sys_user_mobile1']."','".$_POST['erp_sys_user_mobile2']."','".$_POST['erp_sys_user_mobile_work']."','".$_POST['erp_sys_org_name']."','".$_POST['erp_sys_user_job_title']."','".$_POST['erp_sys_org_phone_work']."','".$_POST['erp_sys_user_org_phone_work_ext']."','".$_POST['erp_sys_org_fax']."','".$_POST['erp_sys_user_email_work']."','".$_POST['erp_sys_user_id_sm_linkedin']."','".$_POST['erp_sys_user_id_sm_twitter']."','".$_POST['erp_sys_user_id_sm_facebook']."','".$_POST['erp_sys_user_id_sm_instagram']."','".$_POST['erp_sys_user_id_msngr_skype']."','".$_POST['erp_sys_user_id_msngr_whatsapp']."','".$_POST['erp_sys_user_id_msngr_imo']."','".$_POST['erp_sys_user_id_msngr_telegram']."','".$_POST['erp_sys_user_id_msngr_signal']."','".$_POST['erp_sys_user_id_msngr_botim']."','".$_POST['erp_sys_user_id_messanger_viber']."' ) ",'');

            $commonFunctions->addData('sys_erp_adm_user'," (erp_sys_user_name_first,erp_sys_user_name_middle,erp_sys_user_name_last,erp_sys_user_id,erp_sys_user_email_personal,erp_sys_user_mobile1,erp_sys_user_mobile2,erp_sys_user_mobile_work,erp_sys_org_name,erp_sys_user_job_title,erp_sys_org_phone_work,erp_sys_user_org_phone_work_ext,erp_sys_org_fax,erp_sys_user_email_work,erp_sys_user_id_sm_linkedin,erp_sys_user_id_sm_twitter,erp_sys_user_id_sm_facebook,erp_sys_user_id_sm_instagram,erp_sys_user_id_msngr_skype,erp_sys_user_id_msngr_whatsapp,erp_sys_user_id_msngr_imo,erp_sys_user_id_msngr_telegram,erp_sys_user_id_msngr_signal,erp_sys_user_id_msngr_botim,erp_sys_user_id_messanger_viber,erp_sys_user_secutiry_permission,erp_sys_user_roleid,erp_sys_user_isActive".$column.",erp_sys_user_address,erp_sys_user_city,erp_sys_user_country,erp_sys_user_state,erp_sys_user_zipcode) VALUES ('".$_POST['erp_sys_user_name_first']."','".$_POST['erp_sys_user_name_middle']."','".$_POST['erp_sys_user_name_last']."','".$_POST['erp_sys_user_id']."','".$_POST['erp_sys_user_email_personal']."','".$_POST['erp_sys_user_mobile1']."','".$_POST['erp_sys_user_mobile2']."','".$_POST['erp_sys_user_mobile_work']."','".$_POST['erp_sys_org_name']."','".$_POST['erp_sys_user_job_title']."','".$_POST['erp_sys_org_phone_work']."','".$_POST['erp_sys_user_org_phone_work_ext']."','".$_POST['erp_sys_org_fax']."','".$_POST['erp_sys_user_email_work']."','".$_POST['erp_sys_user_id_sm_linkedin']."','".$_POST['erp_sys_user_id_sm_twitter']."','".$_POST['erp_sys_user_id_sm_facebook']."','".$_POST['erp_sys_user_id_sm_instagram']."','".$_POST['erp_sys_user_id_msngr_skype']."','".$_POST['erp_sys_user_id_msngr_whatsapp']."','".$_POST['erp_sys_user_id_msngr_imo']."','".$_POST['erp_sys_user_id_msngr_telegram']."','".$_POST['erp_sys_user_id_msngr_signal']."','".$_POST['erp_sys_user_id_msngr_botim']."','".$_POST['erp_sys_user_id_messanger_viber']."','".$_POST['erp_sys_user_secutiry_permission']."','".$_POST['erp_sys_user_roleid']."','".$_POST['erp_sys_user_isActive']."'".$fileName.",'".$_POST['erp_sys_user_address']."','".$_POST['erp_sys_user_city']."','".$_POST['erp_sys_user_country']."','".$_POST['erp_sys_user_state']."','".$_POST['erp_sys_user_zipcode']."' ) ",'users.php?state=form');
        }
        if($_POST['action'] == "edit"){
            $column = $fileName = "";
            if($_FILES["erp_sys_user_logo"]){
                $target_dir = "../uploads/admin-setting/users/";
                $target_file = $target_dir . basename($_FILES["erp_sys_user_logo"]["name"]);
                $uploadOk = 1;
                $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
                @getimagesize($_FILES["erp_sys_user_logo"]["tmp_name"]);
                if(move_uploaded_file($_FILES["erp_sys_user_logo"]["tmp_name"], $target_file)){
                    $column = " ,erp_sys_user_logo";
                    $fileName = " ,erp_sys_user_logo = '".$_FILES["erp_sys_user_logo"]["name"]."' ";
                }
            }
            //$commonFunctions->updateData('global_contacts'," WHERE id = '".$_POST['user_id']."' ", " global_user_name_first = '".$_POST['erp_sys_user_name_first']."', global_user_name_middle='".$_POST['erp_sys_user_name_middle']."', global_user_name_last='".$_POST['erp_sys_user_name_last']."' , global_user_email_personal='".$_POST['erp_sys_user_email_personal']."' , global_user_mobile1='".$_POST['erp_sys_user_mobile1']."', global_user_mobile2='".$_POST['erp_sys_user_mobile2']."', global_user_mobile_work='".$_POST['erp_sys_user_mobile_work']."' , global_org_name='".$_POST['erp_sys_org_name']."' , global_user_job_title='".$_POST['erp_sys_user_job_title']."', global_org_phone_work='".$_POST['erp_sys_org_phone_work']."', global_user_org_phone_work_ext='".$_POST['erp_sys_user_org_phone_work_ext']."', global_org_fax='".$_POST['erp_sys_org_fax']."', global_user_email_work='".$_POST['erp_sys_user_email_work']."', global_user_id_sm_linkedin='".$_POST['erp_sys_user_id_sm_linkedin']."', global_user_id_sm_twitter='".$_POST['erp_sys_user_id_sm_twitter']."', global_user_id_sm_facebook='".$_POST['erp_sys_user_id_sm_facebook']."', global_user_id_sm_instagram='".$_POST['erp_sys_user_id_sm_instagram']."', global_user_id_msngr_skype='".$_POST['erp_sys_user_id_msngr_skype']."', global_user_id_msngr_whatsapp='".$_POST['erp_sys_user_id_msngr_whatsapp']."', global_user_id_msngr_imo='".$_POST['erp_sys_user_id_msngr_imo']."', global_user_id_msngr_telegram='".$_POST['erp_sys_user_id_msngr_telegram']."', global_user_id_msngr_signal='".$_POST['erp_sys_user_id_msngr_signal']."', global_user_id_msngr_botim='".$_POST['erp_sys_user_id_msngr_botim']."', global_user_id_messanger_viber='".$_POST['erp_sys_user_id_messanger_viber']."'",'');

            $commonFunctions->updateData('sys_erp_adm_user'," WHERE id = '".$_POST['user_id']."' ", " erp_sys_user_name_first = '".$_POST['erp_sys_user_name_first']."', erp_sys_user_name_middle='".$_POST['erp_sys_user_name_middle']."', erp_sys_user_name_last='".$_POST['erp_sys_user_name_last']."' , erp_sys_user_id='".$_POST['erp_sys_user_id']."' , erp_sys_user_email_personal='".$_POST['erp_sys_user_email_personal']."' , erp_sys_user_mobile1='".$_POST['erp_sys_user_mobile1']."', erp_sys_user_mobile2='".$_POST['erp_sys_user_mobile2']."', erp_sys_user_mobile_work='".$_POST['erp_sys_user_mobile_work']."' , erp_sys_org_name='".$_POST['erp_sys_org_name']."' , erp_sys_user_job_title='".$_POST['erp_sys_user_job_title']."', erp_sys_org_phone_work='".$_POST['erp_sys_org_phone_work']."', erp_sys_user_org_phone_work_ext='".$_POST['erp_sys_user_org_phone_work_ext']."', erp_sys_org_fax='".$_POST['erp_sys_org_fax']."', erp_sys_user_email_work='".$_POST['erp_sys_user_email_work']."', erp_sys_user_id_sm_linkedin='".$_POST['erp_sys_user_id_sm_linkedin']."', erp_sys_user_id_sm_twitter='".$_POST['erp_sys_user_id_sm_twitter']."', erp_sys_user_id_sm_facebook='".$_POST['erp_sys_user_id_sm_facebook']."', erp_sys_user_id_sm_instagram='".$_POST['erp_sys_user_id_sm_instagram']."', erp_sys_user_id_msngr_skype='".$_POST['erp_sys_user_id_msngr_skype']."', erp_sys_user_id_msngr_whatsapp='".$_POST['erp_sys_user_id_msngr_whatsapp']."', erp_sys_user_id_msngr_imo='".$_POST['erp_sys_user_id_msngr_imo']."', erp_sys_user_id_msngr_telegram='".$_POST['erp_sys_user_id_msngr_telegram']."', erp_sys_user_id_msngr_signal='".$_POST['erp_sys_user_id_msngr_signal']."', erp_sys_user_id_msngr_botim='".$_POST['erp_sys_user_id_msngr_botim']."', erp_sys_user_id_messanger_viber='".$_POST['erp_sys_user_id_messanger_viber']."', erp_sys_user_secutiry_permission='".$_POST['erp_sys_user_secutiry_permission']."', erp_sys_user_roleid='".$_POST['erp_sys_user_roleid']."', erp_sys_user_isActive='".$_POST['erp_sys_user_isActive']."'".$fileName.",erp_sys_user_address='".$_POST['erp_sys_user_address']."',erp_sys_user_city='".$_POST['erp_sys_user_city']."',erp_sys_user_country='".$_POST['erp_sys_user_country']."',erp_sys_user_state='".$_POST['erp_sys_user_state']."',erp_sys_user_zipcode='".$_POST['erp_sys_user_zipcode']."' ",'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_erp_adm_user','WHERE erp_sys_user_roleid != 1'); ?></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_erp_adm_user',' WHERE erp_sys_user_roleid != 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 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_erp_adm_user',' WHERE erp_sys_user_isActive = 1 and erp_sys_user_roleid != 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 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">Branches</p>
                                        <h3 class="m-0">0</h3>
                                        <!--p class="mb-0 text-truncate text-muted">Products Below Desired Stock</p-->
                                    </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_erp_adm_user'," 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="erp_sys_user_isActive" value="1">
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_name_first" class="">First Name</label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_name_first" id="erp_sys_user_name_first" value="<?php echo @$editData['erp_sys_user_name_first'];?>" autofocus="autofocus" class="form-control" placeholder="First Name">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_name_middle" class="">Middle Name</label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_name_middle" id="erp_sys_user_name_middle" value="<?php echo @$editData['erp_sys_user_name_middle'];?>" autofocus="autofocus" class="form-control" placeholder="Middle Name">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_name_last" class="">Last Name</label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_name_last" id="erp_sys_user_name_last" value="<?php echo @$editData['erp_sys_user_name_last'];?>" autofocus="autofocus" class="form-control" placeholder="Last Name">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_org_name" class="">Company Name</label>
                                                        <select class="form-control" name="erp_sys_org_name">
                                                            <option value="0">Select</option>
                                                        </select>
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_job_title" class="">Job Title</label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_job_title" id="erp_sys_user_job_title" value="<?php echo @$editData['erp_sys_user_job_title'];?>" autofocus="autofocus" class="form-control" placeholder="Job Title">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_org_phone_work" class="">Work Phone</label>
                                                        <input type="text" maxlength="128" name="erp_sys_org_phone_work" id="erp_sys_org_phone_work" value="<?php echo @$editData['erp_sys_org_phone_work'];?>" autofocus="autofocus" class="form-control" placeholder="Work Phone">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_org_phone_work_ext" class="">Work Phone - Ext</label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_org_phone_work_ext" id="erp_sys_user_org_phone_work_ext" value="<?php echo @$editData['erp_sys_user_org_phone_work_ext'];?>" autofocus="autofocus" class="form-control" placeholder="Work Phone - Ext">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_org_fax" class="">Work Fax</label>
                                                        <input type="text" maxlength="128" name="erp_sys_org_fax" id="erp_sys_org_fax" value="<?php echo @$editData['erp_sys_org_fax'];?>" autofocus="autofocus" class="form-control" placeholder="Work Fax">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_mobile1" class="">Mobile 1</label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_mobile1" id="erp_sys_user_mobile1" value="<?php echo @$editData['erp_sys_user_mobile1'];?>" autofocus="autofocus" class="form-control" placeholder="Mobile">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_mobile2" class="">Mobile 2</label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_mobile2" id="erp_sys_user_mobile2" value="<?php echo @$editData['erp_sys_user_mobile2'];?>" autofocus="autofocus" class="form-control" placeholder="Mobile">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_email_work" class="">Work eMail</label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_email_work" id="erp_sys_user_email_work" value="<?php echo @$editData['erp_sys_user_email_work'];?>" autofocus="autofocus" class="form-control" placeholder="Work eMail">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_mobile_work" class="">Work Mobile</label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_mobile_work" id="erp_sys_user_mobile_work" value="<?php echo @$editData['erp_sys_user_mobile_work'];?>" autofocus="autofocus" class="form-control" placeholder="Work Mobile">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_email_personal" class="">Personal eMail</label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_email_personal" id="erp_sys_user_email_personal" value="<?php echo @$editData['erp_sys_user_email_personal'];?>" autofocus="autofocus" class="form-control" placeholder="Personal eMail">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_id_sm_linkedin" class="">LinkedIn</label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_id_sm_linkedin" id="erp_sys_user_id_sm_linkedin" value="<?php echo @$editData['erp_sys_user_id_sm_linkedin'];?>" autofocus="autofocus" class="form-control" placeholder="LinkedIn">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_id_sm_twitter" class="">Twitter</label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_id_sm_twitter" id="erp_sys_user_id_sm_twitter" value="<?php echo @$editData['erp_sys_user_id_sm_twitter'];?>" autofocus="autofocus" class="form-control" placeholder="Twitter">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_id_sm_facebook" class="">Facebook</label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_id_sm_facebook" id="erp_sys_user_id_sm_facebook" value="<?php echo @$editData['erp_sys_user_id_sm_facebook'];?>" autofocus="autofocus" class="form-control" placeholder="Facebook">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_id_sm_instagram" class="">Instagram</label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_id_sm_instagram" id="erp_sys_user_id_sm_instagram" value="<?php echo @$editData['erp_sys_user_id_sm_instagram'];?>" autofocus="autofocus" class="form-control" placeholder="Instagram">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_id_msngr_skype" class="">Skype</label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_id_msngr_skype" id="erp_sys_user_id_msngr_skype" value="<?php echo @$editData['erp_sys_user_id_msngr_skype'];?>" autofocus="autofocus" class="form-control" placeholder="Skype">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_id_msngr_whatsapp" class="">Whatsapp Number</label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_id_msngr_whatsapp" id="erp_sys_user_id_msngr_whatsapp" value="<?php echo @$editData['erp_sys_user_id_msngr_whatsapp'];?>" autofocus="autofocus" class="form-control" placeholder="Whatsapp Number">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_id_msngr_imo" class="">IMO Number </label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_id_msngr_imo" id="erp_sys_user_id_msngr_imo" value="<?php echo @$editData['erp_sys_user_id_msngr_imo'];?>" autofocus="autofocus" class="form-control" placeholder="IMO Number">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_id_msngr_telegram" class="">Telegram Number </label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_id_msngr_telegram" id="erp_sys_user_id_msngr_telegram" value="<?php echo @$editData['erp_sys_user_id_msngr_telegram'];?>" autofocus="autofocus" class="form-control" placeholder="Telegram Number">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_id_msngr_signal" class="">Signal Number </label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_id_msngr_signal" id="erp_sys_user_id_msngr_signal" value="<?php echo @$editData['erp_sys_user_id_msngr_signal'];?>" autofocus="autofocus" class="form-control" placeholder="Signal Number">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_id_msngr_botim" class="">Botim Number</label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_id_msngr_botim" id="erp_sys_user_id_msngr_botim" value="<?php echo @$editData['erp_sys_user_id_msngr_botim'];?>" autofocus="autofocus" class="form-control" placeholder="Botim Number">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_id_messanger_viber" class="">Viber Number</label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_id_messanger_viber" id="erp_sys_user_id_messanger_viber" value="<?php echo @$editData['erp_sys_user_id_messanger_viber'];?>" autofocus="autofocus" class="form-control" placeholder="Viber Number">
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_secutiry_permission" class="">Permission</label>
                                                        <select name="erp_sys_user_secutiry_permission" class="form-control">
                                                            <option value="">Select</option>
                                                        </select>
                                                    </div>

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

                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_address" class="">Address </label>
                                                        <textarea name="erp_sys_user_address" id="erp_sys_user_address" class="form-control"><?php echo @$editData['erp_sys_user_address'];?></textarea>
                                                    </div>
                                                    
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_country" class=""> Country </label>
                                                        <?php $countryData = $commonFunctions->getData('sys_erp_adm_countries',' WHERE active = 1 '); ?>
                                                        <select name="erp_sys_user_country" id="erp_sys_user_country" class="select2 form-control" >
                                                            <option value="0">Select Country</option>
                                                            <?php foreach ($countryData as $rw) { ?>
                                                                <option value="<?php echo $rw['rowid'];?>" ><?php echo $rw['label']."(".$rw['code'].")"; ?></option>     
                                                            <?php } ?>
                                                        </select>
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_state" class=""> State / Province </label>
                                                        <?php $stateData = $commonFunctions->getData('sys_erp_adm_countries_states',' WHERE active = 1 '); ?>
                                                        <select name="erp_sys_user_state" id="erp_sys_user_state" class="select2 form-control" >
                                                            <option value="0">Select State / Province</option>
                                                            <?php foreach ($stateData as $rw) { ?>
                                                                <option value="<?php echo $rw['rowid'];?>" ><?php echo $rw['label']."(".$rw['region_code'].")"; ?></option>     
                                                            <?php } ?>
                                                        </select>
                                                    </div>
                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_city" class="">City </label>
                                                        <input type="text" maxlength="128" name="erp_sys_user_city" id="erp_sys_user_city" value="<?php echo @$editData['erp_sys_user_city'];?>" autofocus="autofocus" class="form-control" placeholder="Enter City" >
                                                    </div>

                                                    <div class="position-relative form-group col-md-4">
                                                        <label for="erp_sys_user_zipcode" class="">Zipcode </label>
                                                        <input type="number" maxlength="128" name="erp_sys_user_zipcode" id="erp_sys_user_zipcode" value="<?php echo @$editData['erp_sys_user_zipcode'];?>" autofocus="autofocus" class="form-control" placeholder="Enter Zipcode" >
                                                    </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_erp_adm_user',' WHERE erp_sys_user_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'])){
                                                $countryArr = $commonFunctions->getIDs('sys_erp_adm_countries','rowid'," WHERE label LIKE '%".$_GET['search']."%' ");
                                                $sys_erp_adm_countries_statesArr = $commonFunctions->getIDs('sys_erp_adm_countries_states','rowid'," WHERE label LIKE '%".$_GET['search']."%' ");
                                                $country_ids = @$countryArr["ids"];
                                                $state_ids = @$sys_erp_adm_countries_statesArr["ids"];
                                                $search_con = " AND erp_sys_user_name_first LIKE '%".$_GET['search']."%' OR erp_sys_user_name_middle LIKE '%".$_GET['search']."%' OR erp_sys_user_name_last LIKE '%".$_GET['search']."%' OR erp_sys_user_email_personal LIKE '%".$_GET['search']."%' OR erp_sys_user_mobile1 LIKE '%".$_GET['search']."%' OR erp_sys_org_phone_work LIKE '%".$_GET['search']."%' OR erp_sys_user_email_work LIKE '%".$_GET['search']."%' OR erp_sys_org_name LIKE '%".$_GET['search']."%' ";
                                            }
                                            $where = " WHERE id ".$search_con." AND erp_sys_user_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_erp_adm_user',$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">User ID</th>
                                                                <th  class="text-center">Phone No</th>
                                                                <th  class="text-center">Mobile No</th>
                                                                <th  class="text-center">Email Address</th>
                                                                <th  class="text-center">Designation</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="redirect_('users-card.php?user_id=<?php echo $rw['id'];?>')"><?php echo $rw['erp_sys_user_name_first']." ".$rw['erp_sys_user_name_middle']." ".$rw['erp_sys_user_name_last'];?></td>
                                                                    <td class="text-primary" onclick="redirect_('users-card.php?user_id=<?php echo $rw['id'];?>')"><?php echo $rw['erp_sys_user_id'];?></td>
                                                                    <td><?php echo $rw['erp_sys_org_phone_work'];?></td>
                                                                    <td><?php echo $rw['erp_sys_user_mobile1'];?></td>
                                                                    <td class="text-primary" onclick="redirect_('users-card.php?user_id=<?php echo $rw['id'];?>')"><?php echo $rw['erp_sys_user_email_personal'];?></td>
                                                                    
                                                                    <!-- <td><span class="badge badge-lg badge-secondary text-white"><?php echo $users->formatDate($rw['last_logged_date']); ?></span></td> -->
                                                                    <td><?php echo $commonFunctions->getName($rw['erp_sys_user_roleid'],'sys_erp_adm_user_roles','role','id'); ?>
                                                                    </td>
                                                                    <td class="text-primary" onclick="redirect_('users-card.php?user_id=<?php echo $rw['id'];?>')"><?php echo $commonFunctions->getName($rw['erp_sys_user_roleid'],'sys_erp_adm_user_roles','role','id'); ?>
                                                                    </td>

                                                                    <td>
                                                                        <?php if ($rw['erp_sys_user_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_erp_adm_user'," 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['erp_sys_user_logo'])?$userData['erp_sys_user_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="erp_sys_user_logo" value="" style='display: none;' id="fileUpload">
                                                    </form>
                                                </div>
                                                <div class="dastone-profile_user-detail">
                                                    <h5 class="dastone-user-name"><?php echo @$userData['erp_sys_user_name_first']." ".$userData['erp_sys_user_name_middle']." ".$userData['erp_sys_user_name_last'];?></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['erp_sys_user_roleid'],'sys_erp_adm_user_roles','role','id'); ?></p>
                                                    <p class="mt-0 mb-0"><i class="text-secondary font-22 align-middle"></i> <b> Branch :</b>  <?php echo $commonFunctions->getName($_SESSION['warehouse_id'],'invty_wrhus','short_name_location','id');?> <?php echo $commonFunctions->getName($_SESSION['warehouse_id'],'invty_wrhus','address','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['erp_sys_org_phone_work'])?@$userData['erp_sys_org_phone_work']:"-";?></li>
                                                <li class="mt-2"><i class="las la-mobile mr-2 text-secondary font-22 align-middle"></i> <b> mobile </b> :  <?php echo (@$userData['erp_sys_user_mobile1'])?@$userData['erp_sys_user_mobile1']:"-";?></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['erp_sys_user_email_work'])?@$userData['erp_sys_user_email_work']:"-";?>"><?php echo (@$userData['erp_sys_user_email_work'])?@$userData['erp_sys_user_email_work']:"-";?></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_permission_tab" data-toggle="pill" href="#permission">Permission</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" id="user_security_tab" data-toggle="pill" href="#security">Security</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" id="user_settings_tab" data-toggle="pill" href="#user_settings">Settings</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="erp_sys_user_name_first" value="<?php echo @$userData['erp_sys_user_name_first'];?>" 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="erp_sys_user_name_middle" value="<?php echo @$userData['erp_sys_user_name_middle'];?>" 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="erp_sys_user_name_last" value="<?php echo @$userData['erp_sys_user_name_last'];?>" 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_erp_adm_user_roles',' WHERE isActive = 0 '); ?>
                                                                <select class="form-control" name="erp_sys_user_roleid" id="erp_sys_user_roleid" required="">
                                                                  <?php foreach ($optionData as $key) { ?>
                                                                    <option value="<?php echo $key['id'];?>" <?php echo (!empty(@$userData['erp_sys_user_roleid']) and $key['id'] == $userData['erp_sys_user_roleid'])?"selected":""; ?> ><?php echo $key['role'];?></option>
                                                                  <?php } ?>
                                                                </select>

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

                                                </div>                                        
                                            </div>
                                        </form>
                                        <!-- Personal Information Card - End --->
                                        <!-- 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">Mobile Number</label>
                                                        <div class="col-lg-9 col-xl-8">
                                                            <h5 class="card-title"> 
                                                                <input type="text" name="erp_sys_user_mobile2" value="<?php echo @$userData['erp_sys_user_mobile2'];?>" 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">Whatsapp Number</label>
                                                        <div class="col-lg-9 col-xl-8">
                                                            <h5 class="card-title"> 
                                                            <input type="text" name="erp_sys_user_id_msngr_whatsapp" value="<?php echo @$userData['erp_sys_user_id_msngr_whatsapp'];?>" 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="erp_sys_user_email_personal" value="<?php echo @$userData['erp_sys_user_email_personal'];?>" class="form-control">
                                                            </h5>
                                                        </div>
                                                    </div>                                                   
                                                </div><!--end card-body-->
                                            </div><!--end card-->
                                        </form>
                                        <form action="" class="socialInfoForm">  
                                            <div class="card">
                                                <div class="card-header">
                                                    <div class="row align-items-center">
                                                        <div class="col-11">                      
                                                            <h4 class="card-title text-left">Social Media </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">Linkedin</label>
                                                        <div class="col-lg-9 col-xl-8">
                                                            <h5 class="card-title"> 
                                                                <input type="text" name="erp_sys_user_id_sm_linkedin" value="<?php echo @$userData['erp_sys_user_id_sm_linkedin'];?>" 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">Twitter</label>
                                                        <div class="col-lg-9 col-xl-8">
                                                            <h5 class="card-title"> 
                                                                <input type="text" name="erp_sys_user_id_sm_twitter" value="<?php echo @$userData['erp_sys_user_id_sm_twitter'];?>" 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">Facebook</label>
                                                        <div class="col-lg-9 col-xl-8">
                                                            <h5 class="card-title"> 
                                                                <input type="text" name="erp_sys_user_id_sm_facebook" value="<?php echo @$userData['erp_sys_user_id_sm_facebook'];?>" class="form-control">
                                                            </h5>
                                                        </div>
                                                    </div>                                                    
                                                </div><!--end card-body-->
                                            </div><!--end card-->
                                        </form>
                                    </div>
                                    <div class="col-lg-6 col-xl-6">
                                        <form action="" class="contactOfiInfoForm">
                                            <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">( Official )</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">Mobile Number</label>
                                                        <div class="col-lg-9 col-xl-8">
                                                            <h5 class="card-title"> 
                                                                <input type="text" name="erp_sys_user_mobile_work" value="<?php echo @$userData['erp_sys_user_mobile_work'];?>" 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">Work Phone </label>
                                                        <div class="col-lg-9 col-xl-8">
                                                            <h5 class="card-title">
                                                                <input type="text" name="erp_sys_org_phone_work" value="<?php echo @$userData['erp_sys_org_phone_work'];?>" 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">Work Fax</label>
                                                        <div class="col-lg-9 col-xl-8">
                                                            <h5 class="card-title"> <input type="text" name="erp_sys_org_fax" value="<?php echo @$userData['erp_sys_org_fax'];?>" 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="erp_sys_user_email_work" value="<?php echo @$userData['erp_sys_user_email_work'];?>" class="form-control">

                                                            </h5>
                                                        </div>
                                                    </div>
                                                    
                                                </div><!--end card-body-->
                                            </div><!--end card-->
                                        </form>
                                        <form action="" class="officeInfoForm">    
                                            <div class="card">
                                                <div class="card-header">
                                                    <div class="row align-items-center">
                                                        <div class="col-11">                      
                                                            <h4 class="card-title text-left">Office Address </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">Address</label>
                                                        <div class="col-lg-9 col-xl-8">
                                                            <h5 class="card-title"> 
                                                                <input type="text" name="erp_sys_user_address" value="<?php echo @$userData['erp_sys_user_address'];?>" 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">Zip / Pin / PO Box</label>
                                                        <div class="col-lg-9 col-xl-8">
                                                            <h5 class="card-title"> 
                                                                <input type="text" name="erp_sys_user_zipcode" value="<?php echo @$userData['erp_sys_user_zipcode'];?>" 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">Country</label>
                                                        <div class="col-lg-9 col-xl-8">
                                                            <h5 class="card-title"> 
                                                                <?php $countryData = $commonFunctions->getData('sys_erp_adm_countries',' WHERE active = 1 '); ?>
                                                                <select name="erp_sys_user_country" id="erp_sys_user_country" class="select2 form-control" >
                                                                    <option value="0">Select Country</option>
                                                                    <?php foreach ($countryData as $rw) { ?>
                                                                        <option value="<?php echo $rw['rowid'];?>" <?php echo ($userData['erp_sys_user_country'] == $rw['rowid'])?"selected":'';?> ><?php echo $rw['label']."(".$rw['code'].")"; ?></option>     
                                                                    <?php } ?>
                                                                </select>
                                                             </h5>
                                                        </div>
                                                    </div>                                            
                                                    <div class="form-group row">                                         
                                                        <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">State / Province</label>
                                                        <div class="col-lg-9 col-xl-8">
                                                            <h5 class="card-title"> 
                                                                <?php $stateData = $commonFunctions->getData('sys_erp_adm_countries_states',' WHERE active = 1 '); ?>
                                                                <select name="erp_sys_user_state" id="erp_sys_user_state" class="select2 form-control" >
                                                                    <option value="0">Select State / Province</option>
                                                                    <?php foreach ($stateData as $rw) { ?>
                                                                        <option value="<?php echo $rw['rowid'];?>" <?php echo ($userData['erp_sys_user_state'] == $rw['rowid'])?"selected":'';?> ><?php echo $rw['label']."(".$rw['region_code'].")"; ?></option>     
                                                                    <?php } ?>
                                                                </select>
                                                            </h5>
                                                        </div>
                                                    </div>  

                                                    <div class="form-group row">    
                                                        <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">City</label>
                                                        <div class="col-lg-9 col-xl-8">
                                                            <h5 class="card-title"> 
                                                                <input type="text" name="erp_sys_user_city" id="erp_sys_user_city" value="<?php echo @$userData['erp_sys_user_city'];?>" class="form-control">
                                                            </h5>
                                                        </div>
                                                    </div>

                                                </div><!--end card-body-->
                                            </div><!--end card-->
                                        </form>
                                    </div>
                                </div>
                            </div>
                            <div class="tab-pane" id="user_settings" role="tabpanel" aria-labelledby="user_settings">
                                <div class="card">
                                    <div class="card-body">
                                        3
                                    </div><!--end row-->    
                                </div>
                            </div>
                            <div class="tab-pane" id="permission" role="tabpanel" aria-labelledby="permission">
                                <div class="card">
                                    <div class="card-body">
                                        <?php $moduleData = $commonFunctions->getData('sys_erp_module',''); ?>
                                        <table style="margin-top: 10px;width: 100% !important;text-align: center;" class="table datatable_t table-hover table-striped table-bordered">
                                            <thead>
                                                <tr>
                                                    <th class="text-center">SR No#</th>
                                                    <th class="text-center">Module Name</th>
                                                    <th class="text-center">Permission</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php $i = 1;
                                                $role = $commonFunctions->getName($userData['erp_sys_user_roleid'],'sys_erp_adm_user_roles','role','id');
                                                foreach ($moduleData as $row) { 
                                                    $modulePermissionData = $commonFunctions->getRowData('sys_erp_adm_user_access_permission',' WHERE module_id = "'.$row['id'].'" AND role_id = "'.@$userData['erp_sys_user_roleid'].'" ');
                                                    $display = (@$modulePermissionData["display"] == 1 OR $role == "Super-Admin")?'<span class="badge badge-soft-success"> <i class="fa fa-check"></i> </span>':'<span class="badge badge-soft-danger"> <i class="fa fa-times" style="margin-left: 2px;margin-right: 2px;"></i> </span>';
                                                    echo "<tr>";
                                                    echo "<td>".$i++."</td>";
                                                    echo "<td>".$row["name"]."</td>";
                                                    echo "<td>".$display."</td>";
                                                    echo "</tr>";
                                                }?>
                                            </tbody>
                                        </table>
                                    </div><!--end row-->    
                                </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" onsubmit="return confirm('Do you want changed your password?')" >
                                            <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 password" placeholder="Password" required="">
                                                        </div>
                                                        <div class="form-group searchForm col-md-6">
                                                            <label for="cnf_password" class="">Confirm Password</label>
                                                            <input type="password" maxlength="128" name="cnf_password" id="cnf_password" value="" autofocus="autofocus" class="form-control password" placeholder="Confirm Password" required="">
                                                            <br>
                                                            <input type="checkbox" id="checkview" onclick="myFunction()"> <label for="checkview">Show Password</label>
                                                        </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_(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()+"&"+$('.socialInfoForm').serialize()+"&"+$('.contactOfiInfoForm').serialize()+"&"+$('.officeInfoForm').serialize()+"&action=ajax_call_1",
        success: function(response) { 
          window.location.href = response;
        }
    });
});

$("#erp_sys_user_country").change(function(){
    var country = $("#erp_sys_user_country option:selected").val();
    $.ajax({
        type: 'POST',
        url: "",
        data: {"country_id":country,"action":"ajax_call"},
        success: function(response) { 
            obj = JSON.parse(response);
            $("#erp_sys_user_state").html("<option value=''>Select State / Province</option>"+obj.option);
        }
    });
})
$(function() {
    $("#erp_sys_user_city").autocomplete({
        source: function(request, response) {
            $.getJSON("", { country_id: $('#erp_sys_user_country option:selected').val(),state_id: $('#erp_sys_user_state option:selected').val(),keyword: request.term,action:"ajax_call1" }, response);
        },
        minLength: 2,
    });
});
function myFunction() {
  var x = document.getElementById("password");
  if (x.type === "password") {
    x.type = "text";
  } else {
    x.type = "password";
  }

  var x = document.getElementById("cnf_password");
  if (x.type === "password") {
    x.type = "text";
  } else {
    x.type = "password";
  }
}
</script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.15.1/jquery.validate.min.js"></script>
<script type="text/javascript">
var value = $("#password_reg").val();

$.validator.addMethod("checklower", function(value) {
  return /[a-z]/.test(value);
});
$.validator.addMethod("checkupper", function(value) {
  return /[A-Z]/.test(value);
});
$.validator.addMethod("checkdigit", function(value) {
  return /[0-9]/.test(value);
});
$.validator.addMethod("pwcheck", function(value) {
  return /^[A-Za-z0-9\d=!\-@._*]*$/.test(value) && /[a-z]/.test(value) && /\d/.test(value) && /[A-Z]/.test(value);
});
$('#reset-password-form').validate({
  rules: {
    password: {
      minlength: 6,
      maxlength: 30,
      required: true,
      //pwcheck: true,
      checklower: true,
      checkupper: true,
      checkdigit: true
    },
    cnf_password: {
      equalTo: "#password",
    },
  },
  messages: {
    password: {
      pwcheck: "Password is not strong enough",
      checklower: "Need atleast 1 lowercase alphabet",
      checkupper: "Need atleast 1 uppercase alphabet",
      checkdigit: "Need atleast 1 digit"
    }
  },
  highlight: function(element) {
    var id_attr = "#" + $(element).attr("id") + "1";
    $(element).closest('.form-group').removeClass('has-success').addClass('has-error');
    $(id_attr).removeClass('glyphicon-ok').addClass('glyphicon-remove');
    $('.form-group').css('margin-bottom', '5px');
    $('.form').css('padding', '30px 40px');
    $('.tab-group').css('margin', '0 0 25px 0');
    $('.help-block').css('display', '');
  },
  unhighlight: function(element) {
    var id_attr = "#" + $(element).attr("id") + "1";
    $(element).closest('.form-group').removeClass('has-error').addClass('has-success');
    $(id_attr).removeClass('glyphicon-remove').addClass('glyphicon-ok');
    $('#cnf_password').attr('disabled', false);
  },
  errorElement: 'span',
  errorClass: 'validate_cus error',
  errorPlacement: function(error, element) {
    x = element.length;
    if (element.length) {
      error.insertAfter(element);
    } else {
      error.insertAfter(element);
    }
  },
});
</script>