<?php
$PageSecurity = 15;
if(isset($_REQUEST['save']))
{

    $str=explode('**',$_REQUEST['designation']);
DB_query("insert into hr_job_criteria (branch,designation,job_type,created_by,created_date,companyid) values('".$_REQUEST['branch']."','".$str[0]."','".$_REQUEST['job_type']."','".$_SESSION['UserID']."','".date('Y-m-d')."','".$_SESSION['ACGCompanyId']."') " ,$db);
$last=DB_Last_Insert_ID($db, hr_job_criteria, id);
    for($i=0;$i<count($_REQUEST['pararmeter']);$i++)
    {
        if($_REQUEST['pararmeter'][$i]!=""){
        DB_query("insert into hr_job_criteria_details (masterid,seq_no,parameter) value('".$last."','".$_REQUEST['sequence'][$i]."','".$_REQUEST['pararmeter'][$i]."') ",$db);
        }   
    }
    
  $s->pageLocation("index.php?route=HRModule/Master/job_criteria_index".$rurl);  
}

?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div"> 
<h1>Job Criteria Master</h1>
<form method="post" action="" onsubmit="javascript:return validate()">
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="0">
<tr class="row1">
    <td width="13%"><strong>Branch</strong></td>
    <?php $branchsql=DB_query("SELECT branch FROM hr_job_criteria WHERE designation='0'",$db);
    if(DB_num_rows($branchsql)>0){
    while($branchres1=DB_fetch_assoc($branchsql)){$branchres[]=$branchres1['branch'];} 
    $str=implode(',',$branchres);
    }
    ?>
    <td width="35%"><select name="branch" id="branch" onchange="javascript:ajax_get_designation(this)">
        <option value="">Select</option>
	<?php
		$loc_sql = "SELECT * FROM locations WHERE loccode in ('".$_SESSION['AssignedBranch']."') ";
		$loc_result = DB_query($loc_sql,$db);
		while($locRow = DB_fetch_array($loc_result)){
                  $branchsql=DB_query("SELECT * FROM hr_job_criteria WHERE designation='0' and branch='".$locRow['loccode']."'",$db);
                    if(DB_num_rows($branchsql)==0){
	?>
		<option value="<?php echo $locRow['loccode']?>" <?php echo ($locRow['loccode']==$_POST['branch']) ?"selected" :"" ;?>><?php echo $locRow['locationname']?></option>
                    <?php } }  ?>
        </select>
	</td>        
	<td width="13%"><strong>Designation</strong></td>
	<td><select name="designation" type="text" id="designation" onchange="javascript:getdepartment(this)">
          <option value="0">--Select--</option>
	<?php
		$dept_sql = "SELECT id,designame,mst_departmentid FROM desigmaster WHERE CompanyId='".$_SESSION['ACGCompanyId']."' ORDER BY designame ASC ";
		$dept_result = DB_query($dept_sql,$db);
		while($deptRow = DB_fetch_array($dept_result)){
	?>
		<option value="<?php echo $deptRow['id']."**".$deptRow['mst_departmentid'] ; ?>" <?php echo ($deptRow['id']==$_POST['designation']) ?"selected" :"" ;?>><?php echo $deptRow['designame']?></option>
	<?php } ?>
	</select> 
        </td>        
</tr>
<tr class="row1">
	<td><strong>Department</strong></td>
	<td><input name="dept" readonly type="text" id="dept" value="All"/></td>
    <td><strong>Job Type</strong></td>
    <td>Permanent <input name="job_type" type="radio" id="job_type" value="p" /> &nbsp;Contract <input name="job_type" type="radio" id="job_type1" value="c" /></td>
</tr>
<tr class="row1">
	<td><strong>Number of Criteria</strong></td>
    <td><input name="criteria" type="text"  id="criteria" maxlength="3" onkeypress="return isNumberKey(event)" onkeyup="javascript:getparameter_row(this);" value="<?php echo $_POST['designame']?>"/></td>
    <td colspan="2"></td>
</tr>
</table>
    <div id="all_data">
   </div> 
    <p align="center">
        <button name="save" value="save">Save</button>
    </p>
</form>
</div>
</div>
<?php
include('includes/footer.inc');
?>
<style type="text/css" >
.button{ background-color:#4D767D;
color: #FFFFFF;
height:25px;
margin:0px 5px 0px 5px;
border:1px solid #000000;
}
.link{ color:#9900CC; font-family:"Comic Sans MS";
}
</style>

<script>
function ajax_get_designation(str)
{
    var ajax;
    if(window.XMLHttpRequest)
    {
        ajax=new XMLHttpRequest();
    }
   else
    {
        ajax=new ActiveXObject("Microsoft.XMLHTTP");
    }
    ajax.onreadystatechange=function(){
        if(ajax.readyState==4 && ajax.status==200)
            {
                //alert(ajax.responseText);
               document.getElementById("designation").innerHTML=ajax.responseText;
            }
    }
   
  // alert("get_designation_ajax.php?branch="+str.value);
    ajax.open("POST","get_designation_ajax.php?branch="+str.value,true);
    ajax.send();
        }
    
function getdepartment(str)
{
    if(str.value=="0")
        {
             document.getElementById("dept").value="All";
        }
        else{
    var ajax;
    if(window.XMLHttpRequest)
    {
        ajax=new XMLHttpRequest();
    }
   else
    {
        ajax=new ActiveXObject("Microsoft.XMLHTTP");
    }
    ajax.onreadystatechange=function(){
        if(ajax.readyState==4 && ajax.status==200)
            {
                document.getElementById("dept").value=ajax.responseText;
            }
    }
   var dept=str.value.split("**");
    ajax.open("POST","ajax_getdepartment.php?did="+dept[1],true);
    ajax.send();
        }
}

function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57) )
            return false;
         else   
          return true;
      
      }

function getparameter_row(str)
{
 
    var ajax;
    if(window.XMLHttpRequest)
    {
        ajax=new XMLHttpRequest();
    }
   else
    {
        ajax=new ActiveXObject("Microsoft.XMLHTTP");
    }
        ajax.onreadystatechange=function(){
            if(ajax.readyState==4 && ajax.status==200)
                { 
                  // alert(ajax.responseText);
                  document.getElementById("all_data").innerHTML=ajax.responseText;
                }
    }
    
    ajax.open("POST","ajax_getdepartment.php?val="+str.value,true);
    ajax.send();
        
}


function validate()
{
  
   var  flag=0;
    var branch=document.getElementById("branch").value;
    if(branch=="")
    { alert("Please select the Branch");     return false;}
    if(document.getElementById("job_type").checked==false && document.getElementById("job_type1").checked==false) { alert("Please checked the job type");     return false; }
}

</script>



