<?php
include("../db.php");
$ch=$_REQUEST["type"];

if($ch==="delete_fee"){

	$id = $_POST['id'];

    $res=$db->delete("salary_components","where id='$id' ");
    if($res){
        echo "Deleted Successfully.";
    } else {
        echo "Something went wrong. Please try again.";
    }
}

if($ch==="departmentfaculty"){
    $dept = "";
	if($_POST['department']!=""){
    	$dept = " and department='$_POST[department]' ";
	}
	
	
	$staff = $db->getRows("select * from staff where session='".$_SESSION["admin"]["session"]."' and status=1 $dept order by name");
	?>
      <select class="" name="teacher_id">
      <option value="">--Select Teacher--</option>
      <?php 
            foreach($staff as $teacher){
                echo "<option value='$teacher[idno]'>$teacher[name]</option>";
                }
            ?>
        </select>
    <?php }


if($ch === "delete_all_salary"){
    $month = $_POST['month'];
    
    $delete = $db->delete("salery", " where month='$month' and session='".$_SESSION["admin"]["session"]."' ");
    
}

if($ch === "delete_salary"){
    $month = $_POST['month'];
    $idno = $_POST['idno'];
    
    $delete = $db->delete("salery", " where month='$month' and idno='$idno' and session='".$_SESSION["admin"]["session"]."' ");
    
}
 
if($ch === "get_leaves_used"){ 
    
    $total_leave = $_POST['total_leave'];
    $idno = $_POST['idno']; 
    $leaves = $db->getRows("select * from teacher_leave where teacher_id='$idno' and leave_status=1 and session='".$_SESSION["admin"]["session"]."' ");
    foreach($leaves as $l){
        if($l['is_half_day']!=2){$i++;
            ?>
                <tr <?php if($i>$total_leave){echo "style='border-top:solid 2px red;' ";} ?> >
                    <td><?php echo $i; ?></td>
                    <td><?php echo $l['date']; ?></td>
                    <td>
                        <?php if($l['is_half_day']==1){
                                echo "Half Day"; 
                            } else {
                                echo "Full Day";
                            }
                        ?>
                    </td>
                    <td>
                        <?php if($l['is_half_day']==1){
                                echo "0.5";
                            } else {
                                echo "1";
                            }
                        ?>
                    </td>
                </tr>
            <?php
        }
    }
}
    
?>



