<?php 
    include("../connection.php");
    include("../user.php");
    $cur_date=date('Y-m-d H:i:s');
    $user=$_SESSION['user'];
    $ho_access=$_SESSION['ha'];
    $u_id=$_REQUEST['id'];
    $rolemap=mysqli_fetch_array(mysqli_query($con,"select  * from user_master where user_id='$u_id'"));	
?>
<!doctype html>
<html class="no-js" lang=""> 
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title><?php echo TITLE;?></title>
    <meta name="description" content="Ela Admin - HTML5 Admin Template">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="apple-touch-icon" href="../images/bluebase.png">
    <link rel="shortcut icon" href="../images/bluebase.png">
    <!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/html5shiv/3.7.3/html5shiv.min.js"></script> -->
	<style>
        input[type=text] 
        {
        	text-transform:uppercase;
        }
        .select2-results__option {
            text-transform: uppercase;
        }
    </style>
    <script>
        $(document).ready(function() {
            $('.select-search').select2({
                placeholder: "-- SELECT --",
                allowClear: true,
                templateResult: function (data) {
                    if (!data.id) return data.text;
                    return data.text.toUpperCase();
                },
                templateSelection: function (data) {
                    if (!data.id) return data.text;
                    return data.text.toUpperCase();
                }
            });
        });
    </script>

</head>
<body>
	<div class="col-lg-8">
    	<div class="card">
	    	<div class="card-header">
		        <strong style="float:left;">Role Mapping</strong>
			    <a href="user_master.php"><button class="btn btn-primary" style="width:50px;float:right;"onclick=""><i class="fa fa-backward"></i></button></a>			
		    </div>
    	    <div class="card-body card-block">
    	        <form  method="post" enctype="multipart/form-data" class="form-horizontal" action="rolemap_submit.php">
            		<div class="row form-group">
                		<div class="col col-md-3"><label for="text-input" class=" form-control-label">User Name</label></div>
                		<input type="hidden" name="user" id="user" value="<?php echo $rolemap['user_id']; ?>">
                		<div class="col-12 col-md-9"><input type="text" id="username" name="username" value="<?php echo $rolemap['user_name'];?>" placeholder="Enter your user name" class="form-control" autocomplete="off" readOnly></div>
            		</div>
    		        <div class="row form-group">
            			<div class="col col-md-3"><label for="select" class="form-control-label">Role</label></div>
            			<div class="col-12 col-md-9">
    			            <select  style="text-transform:uppercase;"  id="role" name="role" class="form-control select-search" onchange="branchmap(this.value)" required>				
            				<?php 
            				 $que=mysqli_fetch_array(mysqli_query($con,"select m.code,r.ho_admin_access ,r.role_name as role_name from role_mapping m join role_master r on r.code=m.code where m.user_id='$u_id' and m.status='0'"));				
            				if($que)
            				{	
            				    $role_fix_condition=$que['role_name']; ?> 
    				            <option value="<?php echo $que['code'];?>"><?php echo $que['role_name'];?></option>
    				        <?php
    				        $sql=mysqli_query($con,"select * from role_master where status='0' and role_name<>'$role_fix_condition'");
        					while($query=mysqli_fetch_array($sql))
        					{
        					?>
        					    <option style="text-transform:uppercase;" value="<?php echo $query['code'];?>"><?php echo $query['role_name'];?></option>
    					    <?php
        					}	
        					?>	
    				        <?php } else {?>
    				            <option selected disabled>SELECT ROLE</option>
    				        <?php
            				$sql=mysqli_query($con,"select * from role_master where status='0'");
        					while($query=mysqli_fetch_array($sql))
        					{
        					?>
        					    <option  style="text-transform:uppercase;" value="<?php echo $query['code'];?>"><?php echo $query['role_name'];?></option>
        					<?php
        					} 
        				    } ?>
    	                    </select>							
            			</div>
            		</div>
            		<?php
            	    $check_que=mysqli_fetch_array(mysqli_query($con,"select m.code,r.ho_admin_access ,r.role_name as role_name from role_mapping m join role_master r on r.code=m.code where m.user_id='$u_id' and m.status='0'"));
            		$access_check=$check_que['ho_admin_access'];
            		if($access_check=='yes')
            		{
            	    ?>
                	<div class="row form-group" id="branch_form">
                		<div class="col col-md-3"><label for="select" class="form-control-label">LOCATION</label></div>
            			<div class="col-12 col-md-9">
            				<select name="branch_name" id="branch_name" class="form-control select-search" style="padding:5px;text-transform:uppercase;"  required>
    					        <option value="">SELECT LOCATION</option>
                				<?php  $sql=mysqli_query($con,"select * from location_master where status='0'");
                				while($query=mysqli_fetch_array($sql))	{
                				?>
    				            <option value="<?php echo $query['id'];?>"><?php echo $query['location'];?></option>
                				<?php } ?>	
            				</select>
    			        </div>
                	</div>
                	<div class="row form-group" id="branch_form">
                	    <div class="col col-md-3"><label for="select" class="form-control-label">DIVISION</label></div>
                		<div class="col-12 col-md-9">
                			<select name="divison_name" id="divison_name" class="form-control select-search" style="padding:5px;text-transform:uppercase;"  required>
                			    <option value="">SELECT DIVISION</option>
                				<?php  $sql12=mysqli_query($con,"select * from branch_master where status='0'");
                				while($query12=mysqli_fetch_array($sql12))	{	?>
            					<option value="<?php echo $query12['id'];?>"><?php echo $query12['branch_name'];?></option>
                				<?php } ?>	
                			</select>
                		</div>
    	            </div>
            		<?php } else { ?>
            		<div class="row form-group" id="branch_form">
            		</div>
    	            <?php } ?>
    				<div style="">
                		<button type="submit" name="submit" id="submit"  class="btn btn-success" ><i class="fa fa-dot-circle-o"></i> Submit</button>
            		</div>
    	        </form>
            </div>
    	</div>
    </div>
	
    <div class="clearfix"></div>
    <footer class="site-footer">
    </footer>
</body>
</html>