<?php
include'../database.php';
$obj = new Database();
$cid=$_POST['cid'];

if($_POST['submit']=='allpresent'){
$obj->sql("SELECT * FROM employee WHERE cid='$cid'");
$result = $obj->getResult();
	foreach ($result as list("id"=>$id)) {
$staffid=$id;
$getdate=$_POST['date'];
$date= date("j-n-Y", strtotime($getdate));
$detail="";
$attendance="Present";
	$obj->insert('attendances',['cid'=>$cid,'staffid'=>$staffid,'attendance'=>$attendance,'detail'=>$detail,'date'=>$date]);
    }}
if($_POST['submit']=='allabsent'){
$obj->sql("SELECT * FROM employee WHERE cid='$cid' ORDER BY id DESC");
$result = $obj->getResult();
	foreach ($result as list("id"=>$id)) {
$staffid=$id;
$getdate=$_POST['date'];
$date= date("j-n-Y", strtotime($getdate));
$detail="";
$attendance="Absent";
	$obj->insert('attendances',['cid'=>$cid,'staffid'=>$staffid,'attendance'=>$attendance,'detail'=>$detail,'date'=>$date]);
    }}
if($_POST['submit']=='allholiday'){
$obj->sql("SELECT * FROM employee WHERE cid='$cid' ORDER BY id DESC");
$result = $obj->getResult();
	foreach ($result as list("id"=>$id)) {
$staffid=$id;
$getdate=$_POST['date'];
$date= date("j-n-Y", strtotime($getdate));
$detail="";
$attendance="Holiday";
	$obj->insert('attendances',['cid'=>$cid,'staffid'=>$staffid,'attendance'=>$attendance,'detail'=>$detail,'date'=>$date]);
    }}
?>




<?php
if($_POST['submit']=='present'){
$staffid=$_POST['staffid'];
$getdate=$_POST['date'];
$date= date("j-n-Y", strtotime($getdate));
$detail=$_POST['detail'];
$attendance="Present";
	$obj->insert('attendances',['cid'=>$cid,'staffid'=>$staffid,'attendance'=>$attendance,'detail'=>$detail,'date'=>$date]);
}
if($_POST['submit']=='absent'){
    $staffid=$_POST['staffid'];
$getdate=$_POST['date'];
$date= date("j-n-Y", strtotime($getdate));
    $detail=$_POST['detail'];
    $attendance="Absent";
	$obj->insert('attendances',['cid'=>$cid,'staffid'=>$staffid,'attendance'=>$attendance,'detail'=>$detail,'date'=>$date]);
}
if($_POST['submit']=='short_leave'){
    $staffid=$_POST['staffid'];
$getdate=$_POST['date'];
$date= date("j-n-Y", strtotime($getdate));
    $detail=$_POST['detail'];
    $attendance="Short_Leave";
	$obj->insert('attendances',['cid'=>$cid,'staffid'=>$staffid,'attendance'=>$attendance,'detail'=>$detail,'date'=>$date]);
}
if($_POST['submit']=='halfday'){
    $staffid=$_POST['staffid'];
$getdate=$_POST['date'];
$date= date("j-n-Y", strtotime($getdate));
    $detail=$_POST['detail'];
    $attendance="Half_Day";
	$obj->insert('attendances',['cid'=>$cid,'staffid'=>$staffid,'attendance'=>$attendance,'detail'=>$detail,'date'=>$date]);
}
if($_POST['submit']=='onleave'){
    $staffid=$_POST['staffid'];
$getdate=$_POST['date'];
$date= date("j-n-Y", strtotime($getdate));
    $detail=$_POST['detail'];
    $attendance="On_Leave";
	$obj->insert('attendances',['cid'=>$cid,'staffid'=>$staffid,'attendance'=>$attendance,'detail'=>$detail,'date'=>$date]);
}
?>

<?php
if($_POST['submit']=='editpresent'){
$id=$_POST['id'];
$obj->update('attendances',['attendance'=>"Present"],"id=$id");
}
if($_POST['submit']=='editabsent'){
$id=$_POST['id'];
$obj->update('attendances',['attendance'=>"Absent"],"id=$id");
}
if($_POST['submit']=='editshortleave'){
$id=$_POST['id'];
$obj->update('attendances',['attendance'=>"Short_Leave"],"id=$id");
}
if($_POST['submit']=='editonleave'){
$id=$_POST['id'];
$obj->update('attendances',['attendance'=>"On_Leave"],"id=$id");
}
if($_POST['submit']=='edithalfday'){
$id=$_POST['id'];
$obj->update('attendances',['attendance'=>"Half_day"],"id=$id");
}
?>