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

    foreach($_REQUEST['lable_name'] as $key=>$val)
    {
       $label_arr='';
       $value_arr='';
      $label_str=  implode(',',$_REQUEST['lable_name'][$key]);
   //echo count($_REQUEST['lablevalue'][$key]);
      for($j=0;$j<count($_REQUEST['lablevalue'][$key]);$j++){
        //  echo count($_REQUEST['fieldvalue'][$key][$j]);
          for($k=0;$k<count($_REQUEST['fieldvalue'][$key][$j]);$k++)
          {
              if($_REQUEST['fieldvalue'][$key][$j][$k]=="")
              {
                  $_REQUEST['fieldvalue'][$key][$j][$k]=0;
              }
          }
      $value_arr[]= implode(',',$_REQUEST['fieldvalue'][$key][$j]);
      }
    $value_str=implode("__",$value_arr);      
    DB_query(" insert into hr_criteria_form_table(parameter_id,branch,label_value,field_value,created_by,created_date,companyid) value ('".$key."','".$_REQUEST['branch']."',   '".$label_str."','".$value_str."','".$_SESSION['UserID']."','".date('Y-m-d')."','".$_SESSION['ACGCompanyId']."') ",$db);
    }
    $s->pageLocation("index.php?route=HRModule/Master/job_criteria_detail_master_index".$rurl);  
}

?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div"> 
<h1>Job Criteria Detail 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 // echo "SELECT * FROM locations WHERE loccode in ('".$_SESSION['AssignedBranch']."')";  //print_r($_SESSION); ?>
    <td width="35%"><select name="branch" type="text" id="branch">
        <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)){
	?>
		<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="">Select</option>
          <option value="0">All</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="<?php echo $_POST['desigcode']?>" /></td>
  <td><strong>Job Type</strong></td>
  <td>Permanent <input name="job_type" type="radio" onclick="javasscript:getparameter(this);" id="job_type" value="p" /> &nbsp;Contract <input name="job_type" type="radio" id="job_type1" value="c" onclick="javasscript:getparameter(this);" /></td>
</tr>
</table>
<br>
<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 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 getparameter(str)
{
    if(document.getElementById("branch").value=="")
        {
         alert("Select the branch First ");  
         if(document.getElementById('job_type1').checked==true){
             document.getElementById('job_type1').checked=false
         }else if(document.getElementById('job_type').checked==true)
          {   
         document.getElementById('job_type').checked=false
        }
        }
    else if(document.getElementById("designation").value=="")
        {
             alert("Select the designation First ");
            if(document.getElementById('job_type1').checked==true){
             document.getElementById('job_type1').checked=false
         }else if(document.getElementById('job_type').checked==true)
          {   
         document.getElementById('job_type').checked=false
        }
        }
    else{
    var ajax;
    var branch=document.getElementById("branch").value;
    var desig=document.getElementById("designation").value.split("**");
    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;
            }
    }
  // alert("ajax_getjobpararmeter.php?branch="+branch+"&desig="+desig[0]+"&type="+str.value);
    ajax.open("POST","ajax_getjobpararmeter.php?branch="+branch+"&desig="+desig[0]+"&type="+str.value,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 getlablefields(str,j)
{
   var detid=document.getElementById("detid_"+j).value
   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("labcnt_"+j).innerHTML=ajax.responseText;
            }
    }
  
    ajax.open("POST","ajax_getjobpararmeter.php?lablecount="+str.value+"&detid="+detid,true);
    ajax.send();
}
      
 
function getfieldvalue(str)
{
 var splitid=str.id.split("_");
// alert(splitid[2]);
   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("fieldcnt_"+splitid[1]+"_"+splitid[2]).innerHTML=ajax.responseText;
            }
    }
   
    ajax.open("POST","ajax_getjobpararmeter.php?fieldcount="+str.value+"&detid="+splitid[1]+"&cntr="+splitid[2],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>

