<?php
include_once '../session/admin-session.php';
include_once '../classes/class_admin.php';
include_once '../classes/validation.php';
include_once '../classes/common.php';
ob_start();

$log = new common();
$objadm = new class_admin();
$val = new validation();

$success_msg = "";
if(!empty($_POST['chair_add_btn'])) {
    $remove = array("'", '"');
	$cpos = $val->ValidateString($_POST['chair_pos']);
	$cdis = $val->ValidateString($_POST['chair_dis']);
	$crol = $val->ValidateString($_POST['chair_roll']);
        
        $objadm->cpos= $cpos;
        $objadm->cdis = $cdis;
        $objadm->crol = $crol;
        $objadm->admin_roll = $_SESSION['user_sesroll'];
        
        $objadm->InsertHead();
        
        $success_msg = "Detail is saved successfully!";
    
}

if(!empty($_REQUEST['Delheadid']) && !empty($_REQUEST['Delfacroll'])){
    
    $Delheadid = $val->ValidateString($_REQUEST['Delheadid']);
    $Delfacroll = $val->ValidateString($_REQUEST['Delfacroll']);
    
    $objadm->Delheadid = $Delheadid;
    $objadm->Delfacroll = $Delfacroll;
    $objadm->admin_roll = $_SESSION['user_sesroll'];
    
    $objadm->DeleteHead();
    
    header("Location: people-chair.php");
    
}


/*Getting the List Of Chair*/
$result_facultyChair = $objadm->GetFacultyChair();
/* Getting the List of Teachers */
$objadm->fac_status = 'Full';
$result_faculty = $objadm->GetFacultyList();
?>
<div class="container-fluid">
    <div class="row">
        <div class="col-xl-12 col-xxl-12 col-sm-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title">Chair</h5>
                </div>
                <div class="text-success"><?php echo $success_msg; ?></div>
                <div class="card-body">
                    <form style="border: 1px solid #ccc;  padding: 20px;
                          width: 100%;
                          max-width: 700px;
                          margin: 0 auto 30px auto;" method="POST" action="">
                        <label for="chair_pos">Position</label>
                        <select id="chair_pos" name="chair_pos" required="">
                            <option value="">-- - - Select - - - --</option>
                            <option value="5YPC">5YPC</option>
                            <option value="Chair">Chair</option>
                            <option value="DCCR">DCCR</option>
                            <option value="DyChair">DyChair</option>
                            <option value="MScPC">MScPC</option>
                        </select>

                        <label for="chair_dis">Discipline</label>
                        <select name="chair_dis" id="chair_dis" required="">
                            <option value="">-- - - Select Discipline - - - --</option>
                            <option value="BIO">BIO</option>
                            <option value="CHM">CHM</option>
                            <option value="DS">DS</option>
                            <option value="ECS">ECS</option>
                            <option value="HSS">HSS</option>
                            <option value="IDC">IDC</option>
                            <option value="MTH">MTH</option>
                            <option value="PHY">PHY</option>
                            <option value="SE">SE</option>
                        </select>

                        <label for="chair_roll">Faculty</label>
                        <select name="chair_roll" id="chair_roll" required="">
                            <option value="">-- - - Select Faculty - - - --</option>
                            <?php while ($rowCh = mysqli_fetch_array($result_faculty)) { ?>
                                <option value="<?php echo $rowCh['roll'] ?>"><?php echo $rowCh['name'] ?></option>
                            <?php } ?>
                        </select>

                        <input type="submit" class="btn btn-danger" style="background: #a9181b;
                               border: #a9181b;width: 15%;
                               margin-top: 12px;" value="SAVE" name="chair_add_btn"/>
                    </form>

                    <table>
                        <thead>
                            <tr>
                                <th>Name</th>
                                <th>Stream</th>
                                <th>Position</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php while($row = mysqli_fetch_array($result_facultyChair)){ 
                                
                                $head_id = $row['head_id'];
                                $fac_roll = $row['fac_roll'];
                                
                                ?>
                            <tr>
                                <td>
                                    <?php echo $row['name']; ?>
                                </td>
                                  <td>
                                    <?php echo $row['dept']; ?>
                                </td>
                                 <td>
                                    <?php echo $row['position']; ?>
                                </td>
                                <td>
                                    <a href="javascript:void(0);" class="btn btn-danger shadow btn-xs sharp" onclick="FunDelPplChair('<?php echo $head_id; ?>','<?php echo $fac_roll; ?>');"><i class="fa fa-trash"></i></a>
                                </td>
                            </tr>
                            <?php  } ?>
                           
                        </tbody>
                    </table>
                </div>

            </div>

        </div>
    </div>
</div>
<?php
$pagemaincontent = ob_get_contents();
ob_clean();
$PAGENAME = 'people-chair';
$HTMLTITLE = '';
$HTMLDESCRIPTION = '';
$HTMLKEYWORDS = '';
include("admin-master.php");
?>
<script type="text/javascript">
    function FunDelPplChair(headid, facroll){
        if(confirm("Are You sure to delete?")){
            window.location.href="people-chair.php?Delheadid="+headid+"&Delfacroll="+facroll;
        }
    }
</script>