<?php
$pgMod = "late_deduction";

    if(isset($_POST['save_details'])){

        $db->delete("late_deduction", "where school_id='".$_SESSION["admin"]["school_id"]."'  ");
        $saveAry = array(
                "deduction_enable"  =>  $_POST['deduction_enable'],
                "late_days"         =>  $_POST['late_days'],
                "school_id"         =>  $_SESSION["admin"]["school_id"],
                "added_by"          =>  $_SESSION["admin"]["uid"],
			);

        $flg  = $db->insertAry("late_deduction",   $saveAry);

        if(!is_null($flg))
 		{
 			$_SESSION['msg']='update Successfully';
 			redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Payroll", "page_id"=>$pgMod)));
 		}

    }
?>

	<form method="post" action="" name="myForm" onsubmit="return validateForm()">
		<div class="row-fluid">
            <div class="span12">
            	<div class="top-bar">
					<h3><i class="icon-cog"></i>Staff List</h3>
                    <div>
						<button type="submit" name="save_details" class="btn btn-primary"> Save Details</button>
					</div>
				</div>
		<div class="well no-padding">
        	<div class="controls controls-row">

		<?php
		$data = $db->getRow("select * from late_deduction where school_id='".$_SESSION["admin"]["school_id"]."' ");
			?>
			<table class="table">
    		    <thead>
    		        <tr>
    		            <td>Choose Type</td>
    		            <td>Action</td>
    		        </tr>
                </thead>
                <tbody id="myTable">
    			    <tr>
    			        <td>Late Deduction</td>
    			        <td>
    			            <input type="radio" name="deduction_enable" value="1" <?php if($data['deduction_enable']=="1")echo "checked"; ?> required /> Enabled
    			            <input type="radio" name="deduction_enable" value="0" <?php if($data['deduction_enable']=="0")echo "checked"; ?> required /> Disabled
    			        </td>
    			    </tr>
    			    <tr>
    			        <td>No. of late days ( = 1 Day Leave)</td>
    			        <td><input type="text" name="late_days" placeholder="Enter Days" value="<?php echo $data['late_days']; ?>" style="width:100px;"></td>
    			    </tr>
    			</tbody>
			</table>
        </div></div></div></div></form>

		<script>
            function validateForm() {
                let x = document.forms["myForm"]["deduction_enable"].value;
                if(x == "1"){
                    let days = document.forms["myForm"]["late_days"].value;
                    if(days == ""){
                        alert("Please Enter late days.");
                        document.forms["myForm"]["late_days"].focus();
                        return false;
                    }
                } else {
                    return true;
                }
            }
		</script>



