<?php 
$staff_id=$this->uri->segment("3");
$staff_table="school_staff";
$get_staff_information=$this->SchoolModel->get_item_data($staff_id,$staff_table);
if($get_staff_information){
    foreach($get_staff_information as $staff_data){
        $staff_permission_table="staff_permissions";
        $get_staff_permissions=$this->SchoolModel->get_staff_permissons($staff_id,$staff_permission_table);
        
        // $emp_id=0;
        $accounts=0;
        $student_attendance=0;
        $staff_attendance=0;
        $courses=0;
        $enquiry=0;
        $admission=0;
        $fee_structure=0;
        $exam=0;
        $fee=0;
        $documents=0;
        $staff=0;
        $transport=0;
        $students=0;
        $fee_defaulter=0;
        $delete_fee_invoice=0;
        $delete_student=0;
        $acedemic_session_permission=0;
        $circular=0;
        $admin=0;
        $time_table=0;
        
        $edit_fee=0;
        $back_date_fee=0;
        if($get_staff_permissions){
            foreach($get_staff_permissions as $per_data){
                $accounts= $per_data['accounts'];
                $student_attendance	=$per_data['student_attendance'];
                $staff_attendance	=$per_data['staff_attendance'];
                $courses	=$per_data['courses'];
                $enquiry	=$per_data['enquiry'];
                $admission	=$per_data['admission'];
                $fee_structure	=$per_data['fee_structure'];
                $exam	=$per_data['exam'];
                $fee=$per_data['fee'];
                $documents=$per_data['documents'];
                $staff	=$per_data['staff'];
                $transport	=$per_data['transport'];
                $students	=$per_data['students'];
                $fee_defaulter	=$per_data['fee_defaulter'];
                $delete_fee_invoice	=$per_data['delete_fee_invoice'];
                $delete_student=$per_data['delete_student'];
                $acedemic_session_permission=$per_data['acedemic_session'];
                $circular=$per_data['circular'];
                $admin=$per_data['admin'];
                $time_table=$per_data['time_table'];
                $edit_fee=$per_data['edit_fee'];
                $back_date_fee=$per_data['back_date_fee'];
            }
        }
?>
<div class="container-fluid mt-3 mb-3 bg-white">
    <div class="row">
        <div class="col-sm-12  pt-3 pb-3">
            <ul class="breadcrumb">
                <li class="breadcrumb-item"><a href="<?php echo base_url(); ?>Welcome">Home</a></li>
                <li class="breadcrumb-item">
                    <a href="<?php echo base_url(); ?>Management/view_staff">All Staff</a>
                </li>
                <li class="breadcrumb-item">
                    Update Staff
                </li>
                <li class="breadcrumb-item"><?php echo $staff_id; ?></li>
            </ul>
    
            
            <form  method="post" enctype="multipart/form-data" class="form-outer">
                <div class="add-teacher">
                    <h1 class="main-heading">Update Staff</h1><hr>
                    <?php if($success){ ?>
                    <p class="alert alert-success"> <?php echo $success; ?></p>
                    <?php } ?>
                    <?php if($error){ ?>
                    <p class="alert alert-danger"> <?php echo $error; ?></p>
                    <?php } ?>
                    <div class="fgw-25">
                        <input type="hidden" name="staff_id" value="<?php echo $staff_id; ?>">
                        <label>Salutation</label>
                        <!--<input type="text" name="salutation" class="input-field-1">-->
                        <select class="input-field-1" name="salutation" required>
                            <option value="">-- Select Salutation --</option>
                            <option value="Mr" <?php if($staff_data['salutation'] == "Mr"){ echo "selected"; } ?>>Mr</option>
                            <option value="Miss" <?php if($staff_data['salutation'] == "Miss"){ echo "selected"; } ?>>Miss</option>
                            <option value="Mrs" <?php if($staff_data['salutation'] == "Mrs"){ echo "selected"; } ?>>Mrs</option>
                        </select>
                    </div>
                    
                    <div class="fgw-25">
                        <label>Name</label>    
                        <input type="text" class="input-field-1" name="teacher_name" placeholder="Teacher Name" value="<?php echo $staff_data['name']; ?>" required>
                    </div>
                    <div class="fgw-25">
                        <label>Designation</label>
                        <input type="text" name="designation" class="input-field-1" placeholder="Designation" value="<?php echo $staff_data['designation']; ?>" required>
                    </div>
                    <div class="fgw-25">
                        <label>Gender</label>
                        <select class="input-field-1" name="gender">
                            <option value="">-- Select Gender --</option>
                            <option value="Male" <?php if($staff_data['gender'] == "Male" ){ echo "selected"; } ?>>Male</option>
                            <option value="Female" <?php if($staff_data['gender'] == "Female" ){ echo "selected"; } ?>>Female</option>
                        </select>
                    </div>
                    
                    <div class="fgw-25">
                        <label>D.O.B.</label>
                        <input type="date" name="dob" class="input-field-1" value="<?php echo $staff_data['dob']; ?>">
                     </div>
                    
                    <div class="fgw-25">
                        <label>Mobile Number:</label>    
                        <input type="number" class="input-field-1" name="mobile_number" placeholder="Mobile Number" required min="1000000000" value="<?php echo $staff_data['mobile_number']; ?>">
                    </div>
                    
                    <div class="fgw-25">
                        <label>Alt Mobile Number</label>
                        <input type="number" name="alt_mobile_number" class="input-field-1" placeholder="Alternate Mobile No" value="<?php echo $staff_data['alt_mobile_number']; ?>">
                    </div>
                    
                    <div class="fgw-25">
                        <label>Email</label>
                        <input type="email" name="email" class="input-field-1" placeholder="Email" value="<?php echo $staff_data['email']; ?>">
                    </div>
                    
                    
                    <div class="fgw-50">
                        <label>Address</label>
                        <input type="text" name="address" class="input-field-1" placeholder="Current Address" value="<?php echo $staff_data['address']; ?>">
                    </div>
                    <div class="fgw-50">
                        <label>Permanent Address</label>
                        <input type="text" name="permanent_address" class="input-field-1" placeholder="Permanent Address" value="<?php echo $staff_data['permanent_address']; ?>">
                    </div>
                    
                    <div class="fgw-50">
                        <label>Profile Picture</label>
                        <input type="file" name="user_profile_picture" class="input-field-1">
                        <?php if($staff_data['profile_pic'] !="" ){ ?><p><img src="<?php echo base_url()."assets/profile_picture/".$staff_data['profile_pic']; ?>"></p><?php } ?>
                    </div>
                    <div class="fgw-50">
                        <label>Signature</label>
                        <input type="file" name="signature" class="input-field-1">
                        <?php if($staff_data['signature'] !="" ){ ?><p><img src="<?php echo base_url()."assets/signature/".$staff_data['profile_pic']; ?>"></p><?php } ?>
                    </div>
                    
                    <div class="fgw-50">
                        <label>Staff Category</label>
                        <select class="input-field-1" name="staff_category" required>
                            <option value="">-- Staff Category --</option>
                            <option value="teaching-staff" <?php if($staff_data['staff_category'] == "teaching-staff"){ echo "selected"; }?>>Teaching Staff</option>
                            <option value="non-teaching-staff" <?php if($staff_data['staff_category'] == "non-teaching-staff"){ echo "selected"; }?>>Non Teaching Staff</option>
                        </select>
                    </div>
                    
                    <div class="fgw-50">
                        <label>Status</label>
                        <select class="input-field-1" name="status" required>
                            <option value="">-- Select Status --</option>
                            <option value="1" <?php if($staff_data['user_status'] == 1){ echo "selected"; }?>>Active</option>
                            <option value="0" <?php if($staff_data['user_status'] == 0){ echo "selected"; }?>>Inactive</option>
                        </select>
                    </div>
                    
                    <div class="fgw-100">
                        <hr>
                        <h3 class="main-heading">Permissions</h3>
                    </div>
                    
                   
                    
                    <div class="fgw-25">
                        <label>Accounts </label>
                        <input type="checkbox" class="checkbox" name="accounts" value="1" <?php if($accounts == 1){ echo "checked"; } ?>>
                    </div>
                     <div class="fgw-25">
                        <label>Attendance(Student)</label>
                        <input type="checkbox" class="checkbox" name="student_attendance" value="1" <?php if($student_attendance == 1){ echo "checked"; } ?>>
                    </div>
                    
                     <div class="fgw-25">
                        <label>Attendance(Staff) </label>
                        <input type="checkbox" class="checkbox" name="staff_attendance" value="1" <?php if($staff_attendance == 1){ echo "checked"; } ?>>
                    </div>
                    
                     <div class="fgw-25">
                        <label>Add Edit Courses </label>
                        <input type="checkbox" class="checkbox" name="courses" value="1" <?php if($courses == 1){ echo "checked"; } ?>>
                    </div>
                    
                    <div class="fgw-25">
                        <label>Enquiry</label>
                        <input type="checkbox" class="checkbox" name="enquiry" value="1" <?php if($enquiry == 1){ echo "checked"; } ?>>
                    </div>
                    
                    <div class="fgw-25">
                        <label>Admission </label>
                        <input type="checkbox" class="checkbox" name="admission" value="1" <?php if($admission == 1){ echo "checked"; } ?>>
                    </div>
                    
                    <div class="fgw-25">
                        <label>Add/Edit Fee Structure </label>
                        <input type="checkbox" class="checkbox" name="fee_structure" value="1" <?php if($fee_structure == 1){ echo "checked"; } ?>>
                    </div>
                    
                    <div class="fgw-25">
                        <label>Exam </label>
                        <input type="checkbox" class="checkbox" name="exam" value="1" <?php if($exam == 1){ echo "checked"; } ?>>
                    </div>
                    
                    <div class="fgw-25">
                        <label>Fee </label>
                        <input type="checkbox" class="checkbox" name="fee" value="1" <?php if($fee == 1){ echo "checked"; } ?>>
                    </div>
                    
                    <div class="fgw-25">
                        <label>Documents </label>
                        <input type="checkbox" class="checkbox" name="documents" value="1" <?php if($documents == 1){ echo "checked"; } ?>>
                    </div>
                    
                    <div class="fgw-25">
                        <label>Add/Edit Staff </label>
                        <input type="checkbox" class="checkbox" name="staff" value="1" <?php if($staff == 1){ echo "checked"; } ?>>
                    </div>
                    
                    <div class="fgw-25">
                        <label>Transport </label>
                        <input type="checkbox" class="checkbox" name="transport" value="1" <?php if($transport == 1){ echo "checked"; } ?>>
                    </div>
                    
                    <div class="fgw-25">
                        <label>Edit / View Students</label>
                        <input type="checkbox" class="checkbox" name="students" value="1" <?php if($students == 1){ echo "checked"; } ?>>
                    </div>
                    
                    <div class="fgw-25">
                        <label>Fee Defaulter</label>
                        <input type="checkbox" class="checkbox" name="fee_defaulter" value="1" <?php if($fee_defaulter == 1){ echo "checked"; } ?>>
                    </div>
                    
                    <div class="fgw-25">
                        <label>Delete Fee Invoice</label>
                        <input type="checkbox" class="checkbox" name="delete_fee_invoice" value="1" <?php if($delete_fee_invoice == 1){ echo "checked"; } ?>>
                    </div>
                    
                    <div class="fgw-25">
                        <label>Delete Student</label>
                        <input type="checkbox" class="checkbox" name="delete_student" value="1" <?php if($delete_student == 1){ echo "checked"; } ?>>
                    </div>
                    
                    <div class="fgw-25">
                        <label>Acedemic Session</label>
                        <input type="checkbox" class="checkbox" name="acedemic_session_permission" value="1" <?php if($acedemic_session_permission == 1){ echo "checked"; } ?>>
                    </div>
                    
                    <div class="fgw-25">
                        <label>Circular</label>
                        <input type="checkbox" class="checkbox" name="circular" value="1" <?php if($circular == 1){ echo "checked"; } ?>>
                    </div>
                    
                    <div class="fgw-25">
                        <label>Admin</label>
                        <input type="checkbox" class="checkbox" name="admin" value="1" <?php if($admin == 1){ echo "checked"; } ?>>
                    </div>
                    
                    <div class="fgw-25">
                        <label>Time Table</label>
                        <input type="checkbox" class="checkbox" name="time_table" value="1" <?php if($time_table == 1){ echo "checked"; } ?>>
                    </div>
                    
                    
                    <div class="fgw-25">
                        <label>Edit Fee</label>
                        <input type="checkbox" class="checkbox" name="edit_fee" value="1" <?php if($edit_fee == 1){ echo "checked"; } ?>>
                    </div>
                    
                    <div class="fgw-25">
                        <label>Back Date Fee</label>
                        <input type="checkbox" class="checkbox" name="back_date_fee" value="1" <?php if($back_date_fee == 1){ echo "checked"; } ?>>
                    </div>
                    
                    <div class="fgw-25">
                        <label>Check All</label>
                        <input type="checkbox" name="check_all" id="select_all">
                    </div>
                    
                    
                    <div class="form-group fgw-100">
                        <!--<input type="submit" class="btn btn-sm btn-success" name="add_teacher" placeholder="" value="Submit">-->
                        <button class="btn btn-sm btn-success" name="update_teacher">Submit</button>
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>
<?php
    }
}
?>

<script>
    $(document).ready(function(){
        // alert();        
        $('#select_all').on('click',function(){
            if(this.checked){
                $('.checkbox').each(function(){
                    this.checked = true;
                });
            }else{
                $('.checkbox').each(function(){
                    this.checked = false;
                });
            }
        });
    });
</script>