PDA

View Full Version : condition for checkbox



newphpbees
11 Apr 2012, 10:32 PM
Hi..

I have form for leave and now I need to add checkbox for halfday.

if checkbox is checked the HOURS_LEAVE = HOURS_LEAVE * 4 because his leave is halfday only.
then if checkbox is not check the HOURS_LEAVE = HOURS_LEAVE * 8 .
and also if checkbox is check the value is H else W then it also save to database
here is my code for LeaveEmp.php



<?php
include 'config.php';
session_start();
$currentEmpID = $_SESSION['empID'];

$EMP_NO = $_GET['EMP_NO'];
$NAME = $_GET['NAME'];
$DATE_LEAVE_FROM = $_GET['DATE_LEAVE_FROM'];
$DATE_LEAVE_TO = $_GET['DATE_LEAVE_TO'];
$HOURS_LEAVE = $_GET['HOURS_LEAVE'];
$Approve = $_GET['Approve'];
$TYPE =$_GET['TYPE'];
$dateprocess = $_GET['dateprocess'];
$DATE_LEAVE = $_GET['DATE_LEAVE'];
$EMPNO = $_GET['EMPNO'];

function GetDays($StartDate, $EndDate){
$StartDate = date("Y-m-d", strtotime($StartDate));
$EndDate = date("Y-m-d", strtotime($EndDate));
$Days[] = $StartDate;
$CurrentDate = $StartDate;
while($CurrentDate < $EndDate){
$CurrentDate = date("Y-m-d", strtotime("+1 day", strtotime($CurrentDate)));

if(date("w",strtotime($CurrentDate))>0){
$Days[] = $CurrentDate;

}

}
return count($Days);
}

$HOURS_LEAVE = GetDays($DATE_LEAVE_FROM, $DATE_LEAVE_TO);

$smarty->assign('LeaveStatus', array(SickLeave=>'Sick Leave',VacationLeave=>'Vacation Leave',BirthdayLeave=>'Birthday Leave',MaternityLeave=>'Maternity Leave', PaternityLeave=>'Paternity Leave', UnionLeave=>'Union Leave', Holiday=>'Holiday'));
$smarty->assign('TYPE', $TYPE);

$sql = "SELECT l.EMP_NO, l.DATE_LEAVE_FROM,
l.DATE_LEAVE_TO, l.HOURS_LEAVE, l.TYPE_LEAVE, l.STATUS_LEAVE
FROM $ADODB_DB.employment em, $PAYROLL.leave_data l
WHERE em.EMP_NO = l.EMP_NO AND em.EMP_ID = '$currentEmpID' AND l.DATE_LEAVE_FROM = '$DATE_LEAVE_FROM'";
$result_edit = $conn2->Execute($sql);

$DATE_LEAVE_FROM = $result_edit->fields['DATE_LEAVE_FROM'];
$DATE_LEAVE_TO = $result_edit->fields['DATE_LEAVE_TO'];

$smarty->assign('DATE_LEAVE_FROM', $DATE_LEAVE_FROM);
$smarty->assign('DATE_LEAVE_TO', $DATE_LEAVE_TO);

$sql = "SELECT l.EMP_NO, p.EMP_ID, CONCAT(LNAME, ', ', FNAME, ' ', MI, '.') AS FULLNAME, l.DATE_LEAVE_FROM, l.DATE_LEAVE_TO, l.HOURS_LEAVE, l.TYPE_LEAVE, l.STATUS_LEAVE FROM $ADODB_DB.PERSONAL p, $ADODB_DB.employment em, $PAYROLL.leave_data l WHERE em.EMP_NO = l.EMP_NO AND p.EMP_ID = em.EMP_ID ORDER BY FULLNAME";
$rs = $conn2->GetAll($sql);

$smarty->assign('getleave', $rs);

$smarty->display('header_att.tpl');
$smarty->display('LeaveForm.tpl');
$smarty->display('footer.tpl');
?>


here is my code for saving leave:



<?php
include 'config.php';
$currentEmpID = $_SESSION["empID"];

$EMP_NO = $_GET['EMP_NO'];
$NAME = $_GET['NAME'];
$DATE_LEAVE_FROM = $_GET['DATE_LEAVE_FROM'];
$DATE_LEAVE_TO = $_GET['DATE_LEAVE_TO'];
$HOURS_LEAVE = $_GET['HOURS_LEAVE'];
$TYPE =$_GET['TYPE'];
$Approve = $_GET['Approve'];
$dateprocess = $_GET['dateprocess'];

$today = date("Y-m-d");

function GetDays($StartDate, $EndDate){
$StartDate = date("Y-m-d", strtotime($StartDate));
$EndDate = date("Y-m-d", strtotime($EndDate));
$Days[] = $StartDate;
$CurrentDate = $StartDate;
while($CurrentDate < $EndDate){
$CurrentDate = date("Y-m-d", strtotime("+1 day", strtotime($CurrentDate)));

if(date("w",strtotime($CurrentDate))>0){
$Days[] = $CurrentDate;

}

}
return count($Days);
}

$HOURS_LEAVE = GetDays($DATE_LEAVE_FROM, $DATE_LEAVE_TO);
$HOURS_LEAVE = $HOURS_LEAVE * 8;
$smarty->assign('LeaveStatus', array(SickLeave=>'Sick Leave',VacationLeave=>'Vacation Leave',BirthdayLeave=>'Birthday Leave',MaternityLeave=>'Maternity Leave', PaternityLeave=>'Paternity Leave', UnionLeave=>'Union Leave', Holiday=>'Holiday'));
$smarty->assign('TYPE', $TYPE);

$smarty->assign('DATE_LEAVE_FROM', $DATE_LEAVE_FROM);
$smarty->assign('DATE_LEAVE_TO', $DATE_LEAVE_TO);
$smarty->assign('EMP_NO', $EMP_NO);
$smarty->assign('NAME', $NAME);
$smarty->assign('HOURS_LEAVE', $HOURS_LEAVE);
$smarty->assign('TYPE', $TYPE);
$smarty->assign('dateprocess', $today);
$sql = "SELECT EMP_NO, DATE_LEAVE_FROM, DATE_LEAVE_TO, HOURS_LEAVE, TYPE_LEAVE, STATUS_LEAVE, DATE_PROCESS FROM leave_data WHERE EMP_NO = '$EMP_NO' AND DATE_LEAVE_FROM = '$DATE_LEAVE_FROM' AND DATE_LEAVE_TO = '$DATE_LEAVE_TO'";
$RsLeave = $conn2->Execute($sql);

$numrowsRsLeave = $RsLeave->RecordCount();

if($numrowsRsLeave > 0){
echo "<script>alert('Transaction has already been process')</script>";
echo "<script>navigate('LeaveEmp.php')</script>";
}

else {
$sql = "SELECT EMP_NO, DATE_LEAVE_FROM, DATE_LEAVE_TO, HOURS_LEAVE, TYPE_LEAVE, STATUS_LEAVE, DATE_PROCESS FROM leave_data WHERE EMP_NO = '$EMP_NO' AND DATE_LEAVE_FROM = '$DATE_LEAVE_FROM' AND DATE_LEAVE_TO = '$DATE_LEAVE_TO'";
$RsLeave = $conn2->Execute($sql);

$saverec['EMP_NO'] = $EMP_NO;
$saverec['DATE_LEAVE_FROM'] = $DATE_LEAVE_FROM;
$saverec['DATE_LEAVE_TO'] = $DATE_LEAVE_TO;
$saverec['HOURS_LEAVE'] = $HOURS_LEAVE;
$saverec['TYPE_LEAVE'] = $TYPE;
$saverec['STATUS_LEAVE'] = $Approve;
$saverec['DATE_PROCESS'] = $today;

$insertSQL = $conn2->GetInsertSQL($RsLeave, $saverec);
$conn2->Execute($insertSQL);
}


$sql = "SELECT EMP_NO, DATE_LEAVE_FROM, DATE_LEAVE_TO, HOURS_LEAVE, TYPE_LEAVE, STATUS_LEAVE, DATE_PROCESS FROM leave_log WHERE EMP_NO = '$EMP_NO' AND DATE_LEAVE_FROM = '$DATE_LEAVE_FROM' AND DATE_LEAVE_TO = '$DATE_LEAVE_TO'";
$RsLeaveLog = $conn2->Execute($sql);

$numrowsRsLeave = $RsLeaveLog->RecordCount();

if($numrowsRsLeave > 0){
echo "<script>alert('Transaction has already been process')</script>";
echo "<script>navigate('LeaveEmp.php')</script>";
}

else{
$sql = "SELECT EMP_NO, DATE_LEAVE_FROM, DATE_LEAVE_TO, HOURS_LEAVE, TYPE_LEAVE, STATUS_LEAVE, DATE_PROCESS FROM leave_log WHERE EMP_NO = '$EMP_NO' AND DATE_LEAVE_FROM = '$DATE_LEAVE_FROM' AND DATE_LEAVE_TO = '$DATE_LEAVE_TO'";
$RsLeaveLog = $conn2->Execute($sql);

$saverec['EMP_NO'] = $EMP_NO;
$saverec['DATE_LEAVE_FROM'] = $DATE_LEAVE_FROM;
$saverec['DATE_LEAVE_TO'] = $DATE_LEAVE_TO;
$saverec['HOURS_LEAVE'] = $HOURS_LEAVE;
$saverec['TYPE_LEAVE'] = $TYPE;
$saverec['STATUS_LEAVE'] = $Approve;
$saverec['DATE_PROCESS'] = $today;

$insertSQL = $conn2->GetInsertSQL($RsLeaveLog, $saverec);
$conn2->Execute($insertSQL);
}

header("Location:LeaveEmp.php");
?>


And here is the LeaveForm.tpl



<script>
function ApproveLeaveOP(){
var EMP_NO = document.getElementById('EMP_NO').value;
var DATE_LEAVE_FROM = document.getElementById('DATE_LEAVE_FROM').value;
var DATE_LEAVE_TO = document.getElementById('DATE_LEAVE_TO').value;
var NAME = document.getElementById('NAME').value;
var HOURS_LEAVE = document.getElementById('HOURS_LEAVE').value;
var Approve = document.getElementById('Approve').value;
var TYPE = document.getElementById('TYPE').value;
var dateprocess = document.getElementById('dateprocess').value;
var H = document.getElementById('H').value;
document.sampleform.action="AddLeave.php?EMP_NO="+EMP_NO+"&DATE_LEAVE_FROM="+DATE_LEAVE_FROM+"&DATE_LEAVE_TO="+DATE_LEAVE_TO+"&NAME="+NAME+"&HOURS_LEAVE="+HOURS_LEAVE+"&Approve="+Approve+"&TYPE="+TYPE+"&dateprocess="+dateprocess+"&H="+H;
document.sampleform.submit();
}
</script>

<div id="Search">
<form>
<div id="EmpOTForm">
<fieldset>
<legend>Overtime and Leave Form</legend>
<p class="serif">
<label>EMP ID</label><label>NAME</label><label>FROM DATE</label><label>TO DATE</label><label>LEAVE TYPE</label><label>H</label>
<input type="text" name="EMP_NO" id="EMP_NO" value="{$empno}" size="8" >
<input type="text" name="NAME" id="NAME" value="{$fullname}" size="35" >
<input type="text" name="DATE_LEAVE_FROM" id="DATE_LEAVE_FROM" value="{$DATE_LEAVE_FROM}" size="9">
<input type="text" name="DATE_LEAVE_TO" id="DATE_LEAVE_TO" value="{$DATE_LEAVE_TO}" size="9">

{html_options id=TYPE name=TYPE options=$LeaveStatus selected=$TYPE}
<input type="checkbox" name="H" id="H" value="">
<input type="button" name="Approve" value="Approve" id="Approve" onclick="ApproveLeaveOP()">
<input type="button" name="Edit" value="Edit" id="Edit" onclick="EditLeaveOP()">
<input type="hidden" name="dateprocess" id="dateprocess" value="{$dateprocess}">
</p>
<input type="hidden" id="HOURS_LEAVE">
</fieldset>
<div>
<p>
<table border="1" class="stat" width="auto">
<tr>
<th>EMP ID</th>
<th>NAME</th>
<th>FROM DATE</th>
<th>TO DATE</th>
<th># of HOURS</th>
<th>TYPE</th>
<th>STATUS</th>
</tr>
{section name=att loop=$getleave}
<tr>
<td id = "EMPNO">{$getleave[att].EMP_NO}</td>
<td >{$getleave[att].FULLNAME}</td>
<td id = "DATE_LEAVE" onclick="opleave_edit('{$getleave[att].DATE_LEAVE_FROM}')">{$getleave[att].DATE_LEAVE_FROM}</td>
<td >{$getleave[att].DATE_LEAVE_TO}</td>
<td >{$getleave[att].HOURS_LEAVE}</td>
<td >{$getleave[att].TYPE_LEAVE}</td>
<td >{$getleave[att].STATUS_LEAVE}</td>
</tr>
{/section}

</table>
</p>

</form>
</div>
</div>
</div>


I attach the sample form.

Thank you