<?php require_once 'header.php'; ?>


<?php 
if($session_id ==1 || $allPermissions['auth_users']['read']=="1"){ ?>

<?php
if(isset($_POST['submit'])) {
	$valid = 1;

	if(empty($_POST['role_name'])) {
		$valid = 0;
		$error_message .= 'Role Name can not be empty<br>';
	}

    $permission = '{"client":{"create":0,"read":0,"update":0,"delete":0},"pincode":{"create":0,"read":0,"update":0,"delete":0},"pod_entry":{"create":0,"read":0,"update":0,"delete":0,"upload":0},"delivery_status":{"create":0,"read":0,"update":0,"delete":0},"drs":{"create":0,"read":0,"update":0,"delete":0},"tracking":{"read":false},"incoming_manifest":{"create":0,"read":0,"update":0,"delete":0},"outgoing_manifest":{"create":0,"read":0,"update":0,"delete":0},"manifest":{"create":0,"read":0,"update":0,"delete":0},"userManagement":{"create":0,"read":0,"update":0,"delete":0},"reports":{"read_total":0,"read_client":0,"read_delivered":0,"read_day":0},"backup":{"read":0},"roles":{"create":0,"read":0,"update":0,"delete":0},"transaction_booking":{"create":0,"read":0,"update":0,"delete":0},"ftl_booking":{"create":0,"read":0,"update":0,"delete":0},"booking_bulk_upload":{"read":0,"delete":0},"generate_zone":{"create":0,"read":0,"update":0,"delete":0},"material_type":{"create":0,"read":0,"update":0,"delete":0},"zone_master":{"create":0,"read":0,"update":0,"delete":0},"rate_entry":{"create":0,"read":0,"update":0,"delete":0},"status":{"create":0,"read":0,"update":0,"delete":0},"reason":{"create":0,"read":0,"update":0,"delete":0},"mode":{"create":0,"read":0,"update":0,"delete":0},"transporter_details":{"create":0,"read":0,"update":0,"delete":0},"driver":{"create":0,"read":0,"update":0,"delete":0},"pickup_points":{"create":0,"read":0,"update":0,"delete":0},"consignor":{"create":0,"read":0,"update":0,"delete":0},"consignee":{"create":0,"read":0,"update":0,"delete":0},"coloader":{"create":0,"read":0,"update":0,"delete":0},"delivery_boy":{"create":0,"read":0,"update":0,"delete":0},"branch":{"create":0,"read":0,"update":0,"delete":0},"company":{"create":0,"read":0,"update":0,"delete":0}}';
    $role_name = $_POST['role_name'];

    if($valid==1){
    
		$statement = $pdo->prepare("INSERT INTO tbl_role (role_name, permission) VALUES (?,?)");
		$result = $statement->execute(array($role_name, $permission));
			
		$success_message = 'Role is Added Successfully!';
		if($result){
		    
		    $ids = $pdo->lastInsertId();
		    header("location: auth-role-edit.php?id=".$ids);
		}
    }
	
}
?>

<section class="content-header" style="background-color: white;">
	<!--<div class="content-header-left">
		<h1>Add Clients</h1>
	</div>
	<div class="content-header-right">
		<a href="user.php" class="btn btn-primary btn-sm">View All</a>
	</div>
</section>


<section class="content">-->

 <div class="row">
		<div class="col-md-4" style="text-align: left;">
			<h4><i class="fa fa-map-marker"></i> Add Consignor Details</h4>
		</div>
		<div class="col-md-8" style="text-align: right;"> 
		    <a href="auth-role-list.php" class="btn btn-warning btn-sm"><i class="fa fa-arrow-left"></i> Back to Role List</a>
		</div>
	</div> 
	
	

	<div class="row">
		<div class="col-md-12">

			<?php if($error_message): ?>
			<div class="callout callout-danger">
				<p>
					<?php echo $error_message; ?>
				</p>
			</div>
			<?php endif; ?>

			<?php if($success_message): ?>
			<div class="callout callout-success">
				<p><?php echo $success_message; ?></p>
			</div>
			<?php endif; ?>
			
			
			
			<form class="form-horizontal" action="" method="post" enctype="multipart/form-data">
				<div class="box box-info" <?=$border_style?>>
					<div class="box-body">
					   
					    
						<div class="form-group">
							<label for="" class="col-sm-2 control-label required">Role Name </label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" placeholder="Enter Role Name" class="form-control" name="role_name" value="<?php if(isset($_POST['role_name'])){echo $_POST['full_name'];} ?>">
							</div>
						</div>
						
						<div class="form-group">
							<label for="" class="col-sm-2 control-label"></label>
							<div class="col-sm-6">
								<button type="submit" class="btn btn-success pull-left" name="submit">Submit</button>
							</div>
						</div>
						
						
					</div>
				</div>
			</form>
		</div>
	</div>

</section>
<?php }else{ ?>
    <?=$page_not_access?>
<?php } ?>




<?php require_once('footer.php'); ?>



<script>
    $(document).ready(function(){
       
  get_client_details();
     
    $("#branch_id").change(function () {
        get_client_details();
    });
    
    function get_client_details(){
         $('#client_id').empty();
        var branch_id=$('#branch_id').val();
       
                                $.ajax({
                            url: 'api/get-clients-api.php',
                            type: 'post',
                            dataType: 'json',
                            data: {type:'get_client_details',branch_id:branch_id},
                            success: function (response) {
                                 console.log(response);
                                if(response['error']==false){
                                    var m='';
                                    m+='<option value="">Select Client Name<span style="text-fill-color: red;">*</span></option>';
                                    for(var n=0;n<response['data'].length;n++){
                                        m+='<option value='+response['data'][n]['id']+'>'+response['data'][n]['name']+'</option>';
                                    }
                                 $('#client_id').append(m);  
                                }
                                
                               
                            }
                        });
    }
}); 
</script>