<?php  include "header.php";



if(isset($_POST['create_role'])){
    try{
        
      
      
        
        
        $permissions = "";      
        $role_name = $_POST['role_name'];
        
        
                
        $statement = $pdo->prepare("INSERT INTO tbl_role (`role_name`, `permission`, `created_by`) VALUES (?,?,?)");
        $result = $statement->execute(array($role_name, $permissions, $session_id));


    
                
                if($result){
                    
                    $role_id = $pdo->lastInsertId(); 
                    
                    header("location: role-edit.php?id=".$role_id);
                    
                    
                    $_SESSION['message'] = "Role is Added Successfully... Please Update <a class='btn btn-info btn-xs' href='role-edit.php?id=".$role_id."' style='text-decoration: none;'>Click Here</a>";
                    
                    $message = 'Role Created Successfully!';
                    unset($_POST);      
                }else{
                    $warning="Something Went Wrong Try Again...";
                }  
    }catch(Exception $e){
        $error=$e;
    }   
}
    
?>
<div class="content-wrapper" style="background:white;">
        <section class="content-header">
            <a href="role.php" class="btn btn-danger btn-sm pull-left"><i class="fa fa-arrow-left"></i> Back to Role List</a>
        </section>


        <div class="col-lg-12 alerts">
            <div id="custom-alerts" style="display:none;">
                <div class="alert alert-dismissable">
                    <div class="custom-msg"></div>
                </div>
            </div>
            <?php if ($error)  { ?>
            <div class="alert alert-danger alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4><i class="icon fa fa-ban"></i> Error</h4>
                <?= $error; ?>
            </div>
            <?php $error=0;} if ($warning) { ?>
            <div class="alert alert-warning alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4><i class="icon fa fa-warning"></i> Warning</h4>
                <?= $warning; ?>
            </div>
            <?php  $warning=0;} if ($message) { ?>
           <br> <div class="alert alert-success alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4>    <i class="icon fa fa-check"></i> Success</h4>
                <?= $message; ?>
            </div>
            <?php $message=0; } ?>
        </div>
        <div class="clearfix"></div>





<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div >
                <div class="box-header">
                    <h3 class="box-title"><b>Create Role Details</b></h3>
                </div>
                <div class="box-body">
                    <div class="col-lg-12">
                <form action="" method="post">
                    
                    
                    <div class="row">
                        
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label class="required" for="name">Role Name</label>                                    
                                    <input type="text" name="role_name" value="" placeholder="Enter Role Name" class="form-control tip" id="name"  required="required" />
                                </div>
                            </div>
                            
                             <div class="col-md-4">
                                <div class="form-group">
                                    <label class="required" for="employee_ids">Employee Name</label>                                    
                                    <select name="employee_ids[]" id="employee_ids" class="form-control select2" multiple>
    							        <option value='0' <?php if(in_array(0, $branch_ids)){ echo "selected";} ?>>All Branch's</option> 
    							        <?php 
    							        	$statement = $pdo->prepare("SELECT * FROM tbl_business_branch where 1=1 and status=1");
                							$statement->execute();
                							$result = $statement->fetchAll(PDO::FETCH_ASSOC);
                						 foreach($result as $rows){ ?>
                						     <option value="<?=$rows['id']?>" <?php if(in_array($rows['id'], $branch_ids)){ echo "selected";} ?>><?=$rows['location_name']?></option>
                						<?php } ?>
    							    </select>
                                </div>
                            </div>
                            
                            
                    </div>
                    
                    
                    
                    
                    
                    
                   
                    
                    
                    <div class="form-group" style="text-align:center;margin-top: 10px;">
                            <br><input type="submit" name="create_role" value="Create Role"  class="btn btn-success" />
                    </div>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                 </form>       
                       

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

<?php include "footer.php"; ?>