<?php
$pgMod = "one_day_salary";

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

        $days = "";
        if($_POST['days_type'] == "2"){
            $days = $_POST['days'];
        }

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

        $flg  = $db->insertAry("salary_days",   $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">
		<!--<center><input class="form-control" id="myInput" type="text" placeholder="Search.."></center>-->
		<?php
		$data = $db->getRow("select * from salary_days 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>Calendar Month</td>
    			        <td><input type="radio" name="days_type" value="1" <?php if($data['days_type']=="1")echo "checked"; ?> /></td>
    			    </tr>
    			    <tr>
    			        <td>Every Month 30 days</td>
    			        <td><input type="radio" name="days_type" value="2" <?php if($data['days_type']=="2")echo "checked"; ?> />
    			            <input type="text" name="days" placeholder="Enter Days" value="<?php echo $data['days']; ?>" style="width:100px;">
    			        </td>
    			    </tr>
    			    <tr>
    			        <td>Exclude Weekly Offs</td>
    			        <td><input type="radio" name="days_type" value="3" <?php if($data['days_type']=="3")echo "checked"; ?> /></td>
    			    </tr>
    			</tbody>
			</table>
        </div></div></div></div></form>

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



