<style type="text/css">

a{
color: #171717;
text-decoration: none;
}

a:hover{
color: #fff;
text-decoration: none;
}



#wrapper{
width:702px;
margin:auto;
}
.box{
background: #fff;

}
.boxholder{
clear: both;
padding: 5px;
border:#737373 5px solid;
padding-bottom:15px;

}
.tab{
float: left;
height: 32px;
width: 116px;
margin: 0 1px 0 0;
text-align: center;
background: #8DC70A url(images/greentab.jpg) no-repeat;
}
.tabtxt{
margin: 0;
color: #fff;
font-size: 12px;
font-weight: bold;
padding: 9px 0 0 0;

}


/****************** Start page styles ********************************************/



#wrap {
	max-width: 600px;
	margin: 30px auto;
	background: #fff;
	border: 4px solid #FFD16F;
	-moz-border-radius: 15px;
	-webkit-border-radius: 15px;
	border-radius: 15px;
	padding: 20px;
    }

.field { 
	padding: 0 0 1em;
	width:160px;
	}
.current{color:#FF0000;}

/****************** End page styles ********************************************/
</style>
<!--<script type="text/javascript" src="js/prototype.lite.js"></script>
<script type="text/javascript" src="js/moo.fx.js"></script>
<script type="text/javascript" src="js/moo.fx.pack.js"></script>-->
<!--<script type="text/javascript" src="js/min.js"></script>-->
<!--<script type="text/javascript" src="js/file-upload.js"></script>-->
<!--<script type="text/javascript">
function init(){
	var stretchers = document.getElementsByClassName('box');
	var toggles = document.getElementsByClassName('tab');
	var myAccordion = new fx.Accordion(
			toggles, stretchers, {opacity: false, height: true, duration: 600}
	);
	//hash functions
	var found = false;
	toggles.each(function(h4, i){
		var div = Element.find(h4, 'nextSibling');
			if (window.location.href.indexOf(h4.title) > 0) {
				myAccordion.showThisHideOpen(div);
				found = true;
			}
		});
		if (!found) myAccordion.showThisHideOpen(stretchers[0]);
}

</script>-->

<?php
$PageSecurity = 15;
if(isset($_REQUEST['save']))
{
 //echo "<pre>";
//print_r($_REQUEST);

///echo "insert into hr_interview_schedule (vacancy_id,branch,schedule_date,job_type,created_by,created_date,companyid) values('".$_REQUEST['vacid']."','".$_REQUEST['branch']."','".FormatDateForSQL($_REQUEST['idate'])."','".$_REQUEST['job_type']."','".$_SESSION['UserID']."','".date('Y-m-d')."','".$_SESSION['ACGCompanyId']."') ";
DB_query("insert into hr_interview_schedule (vacancy_id,branch,schedule_date,job_type,created_by,created_date,companyid) values('".$_REQUEST['vacid']."','".$_REQUEST['branch']."','".FormatDateForSQL($_REQUEST['idate'])."','".$_REQUEST['job_type']."','".$_SESSION['UserID']."','".date('Y-m-d')."','".$_SESSION['ACGCompanyId']."') " ,$db);
$last=DB_Last_Insert_ID($db,'hr_interview_schedule','id');

 foreach($_REQUEST['desig'] as $key =>$value)
    {
     for($i=0;$i<count($_REQUEST['from_date'][$key]);$i++){
         if($_REQUEST['from_date'][$key][$i]!="" && $_REQUEST['from_time'][$key][$i]!="" && $_REQUEST['to_date'][$key][$i]!="" && $_REQUEST['to_time'][$key][$i]!=""){
             
 DB_query("insert into hr_interview_schedule_details (parentid,vac_det_id,designation,from_date,from_time,to_date,to_time,app_from_date,app_from_time,app_to_date,app_to_time) value('".$last."','".$key."','".$_REQUEST['desig'][$key][0]."','".FormatDateForSQL($_REQUEST['from_date'][$key][$i])."','".$_REQUEST['from_time'][$key][$i]."','".FormatDateForSQL($_REQUEST['to_date'][$key][$i])."','".$_REQUEST['to_time'][$key][$i]."','".FormatDateForSQL($_REQUEST['from_app_date'][$key][$i])."','".$_REQUEST['from_app_time'][$key][$i]."','".FormatDateForSQL($_REQUEST['to_app_date'][$key][$i])."','".$_REQUEST['to_app_time'][$key][$i]."') ",$db); 
 
         }
         DB_query("update hr_job_created_details set schedule_status='1' where id='".$key."'",$db);
     }
    }
$sql1=DB_query("select * from hr_job_created_details where parentid='".$_REQUEST['vacid']."' ",$db);
$sql2=DB_query("select * from hr_job_created_details where parentid='".$_REQUEST['vacid']."' and schedule_status='1'",$db);
if(DB_num_rows($sql1)==DB_num_rows($sql2)){
    DB_query("update hr_job_created set schedule_status='1' where id='".$_REQUEST['vacid']."'",$db);
}   
   $s->pageLocation("index.php?route=HRModule/Master/intrvw_plan".$rurl);  
}
if(isset($_REQUEST['vacid']))
{
 $result=DB_fetch_assoc(DB_query("select * from hr_job_created a  where  a.id='".$_REQUEST['vacid']."'",$db));
}

?>
<link rel="stylesheet" type="text/css" href="css/jquery.datetimepicker.css"/>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div"> 
<h1>Interview Scheduling</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="javascipt:ajax_get_designation(this)" >
       
	<?php
		$loc_sql = "SELECT * FROM locations WHERE loccode ='".$result['branch']."' ";
		$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>Vacancy Code</strong></td>
        <td ><input type="text" readonly value="<?php echo $result['vacancy_code'] ?>" >  </td>
        
</tr>
<tr class="row1">
	<td><strong>Date</strong></td>
        <td><input name="idate" readonly type="text" id="idate" value="<?php echo date('d/m/Y') ?>"/></td>
        <td><strong>Job Type</strong></td>
        <td>Permanent <input name="" <?php if($result['job_type']=='p'){ echo "checked"; }?>  type="radio" id="job_type" disabled="" value="p"/> &nbsp;Contract <input name="" type="radio" id="job_type1" disabled value="c" <?php if($result['job_type']=='c'){ echo "checked"; }?>/></td>
        <input type="hidden" value="<?php echo $result['job_type'] ?>" name="job_type" >
</tr>
<?php $sql="select * from hr_job_created_details where parentid='".$_REQUEST['vacid']."' and schedule_status='0' "; 
$det_sql=DB_query($sql,$db); ?>

</table>
    <br/>
    <?php $i=0; while($det_res=DB_fetch_assoc($det_sql)){ ?>
    <fieldset style="border-color: slategray"><legend style="font-size: 14px;font-weight: bold"><?php echo $s->getField('desigmaster','id',$det_res['designation'],'designame'); ?>--<?php echo $s->getField('deptmaster','id',$s->getField('desigmaster','id',$det_res['designation'],'mst_departmentid'),'deptname'); ?></legend>
        <div style="float: left;width:100%">
            <table width="100%" border="0" cellspacing="0" cellpadding="3">
                <tr>
             <input type="hidden" id="ddd" value="<?php echo $det_res['id']; ?>" >       
            <input type="hidden" value="<?php echo $det_res['designation'] ?>" name="desig[<?php echo $det_res['id'] ?>][]" >
            <td width="3%"><strong>Required</strong></td>
            <td width="4%"><?php echo $det_res['required'] ?></td>
            <td width="10%"><strong>Number of schedule</strong></td>
            <td><input type="text" maxlength="2" onkeypress="return isNumberKey(event)" onkeyup="javascript:getlablefields(this,<?php echo $i ?>,<?php echo $det_res['id'] ?> )"  name="" id="count_<?php echo $i; ?>" value="<?php //echo  ?>" ></td>
        </tr></table>
    </div>
        <fieldset style="width: 45%;float:left; box-sizing:border-box; "><legend style="font-size: 12px">Interview Schedule</legend>
    <table width="100%" border="0" cellspacing="0" cellpadding="3">
        <tbody id="ajax_data_<?php echo $i; ?>">
        <tr>
            <td>From date</td>
            <td>From Time</td>
            <td>To date</td>
            <td>To Time</td>
        </tr>
        <tr><td><input type="text"  class="datepicker" name="from_date[<?php echo $det_res['id'] ?>][]"  id="from_date_<?php echo $det_res['id'].'_'.$i ?>" onclick="abc1(<?php echo $i; ?>)"></td> 
            <td><input type="text" class="timepicker" name="from_time[<?php echo $det_res['id'] ?>][]" id="from_time_<?php echo $det_res['id'].'_'.$i ?>"></td>
            <td><input  type="text"  class="datepicker" name="to_date[<?php echo $det_res['id'] ?>][]" id="to_date_<?php echo $det_res['id'].'_'.$i ?>" onchange="abc(this.id)"></td>
            <td><input type="text" name="to_time[<?php echo $det_res['id'] ?>][]" 
                                       class="timepicker"   id="to_time_<?php echo $det_res['id'].'_'.$i ?>"> </td></tr>
        </tbody>
    </table>
            </fieldset>
           <fieldset style="width: 45%;float:right; box-sizing:border-box; "><legend style="font-size: 12px">Applicant Registration Schedule</legend>
    <table width="100%" border="0" cellspacing="0" cellpadding="3">
        <tbody id="ajax_app_data_<?php echo $i; ?>">
        <tr><td>From date</td><td>From Time</td><td>To date</td><td>To Time</td><td></tr>
        <tr><td><input type="text"   class="datepicker" name="from_app_date[<?php echo $det_res['id'] ?>][]"  id="from_app_date_<?php echo $det_res['id'].'_'.$i ?>">  </td> 
            <td><input type="text" class="timepicker" name="from_app_time[<?php echo $det_res['id'] ?>][]" id="from_app_time_<?php echo $det_res['id'].'_'.$i ?>"> </td>
            <td><input  type="text" class="datepicker" onchange="abc1(this.id)" name="to_app_date[<?php echo $det_res['id'] ?>][]" id="to_app_date_<?php echo $det_res['id'].'_'.$i ?>"> </td>
            <td><input type="text" name="to_app_time[<?php echo $det_res['id'] ?>][]"  class="timepicker"   id="to_app_time_<?php echo $det_res['id'].'_'.$i ?>"> </td></tr>
        </tbody>
    </table>
            </fieldset>
        
    </fieldset>
    <br/>
    <?php $i++;} ?>
    <div>
        <button name="save" type="submit" value="save">Save</button>&nbsp;&nbsp;&nbsp;&nbsp;    <a href="index.php?route=HRModule/Master/intrvw_plan&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>"><button name="" type="button" value="">Cancel</button></a>
    </div>
</form>
<?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;
            }
    }
  
    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 datetime1()
{

    $('.timepicker').timepicker();
    $(".datepicker").datepicker({ dateFormat: 'dd/mm/yy' ,changeMonth: true,
        changeYear: true,
        yearRange: '-80:+20'});
/*$( document ).ready(function() {
$('.timepicker').datetimepicker({
	datepicker:false,
	format:'H:i',
	step:5
});

$('.datetimepicker2').datetimepicker({
	timepicker:false,
	format:'d/m/Y',
	formatDate:'Y/m/d',
	//minDate:'-1970/01/02', // yesterday is minimum date
	//maxDate:'+1970/01/02' // and tommorow is maximum date calendar
});
});*/

}


function getlablefields(str,j,id)
{
 //alert(j); 
   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); 
                var data=ajax.responseText.split("***");
                document.getElementById("ajax_data_"+j).innerHTML=data[0];
                 document.getElementById("ajax_app_data_"+j).innerHTML=data[1];
                 $('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});
                 $('.timepicker').timepicker();

                //datetime1();
               //y alert(str);
               // for(var m=0;m<str.value;m++)
              //  {
                 //   abc(m);
              //  }    
            }
    }
    
// alert("ajax_getjobpararmeter1.php?cntr="+str.value+"&id="+id);
    ajax.open("POST","ajax_getjobpararmeter1.php?cntr="+str.value+"&id="+id,true);
    ajax.send();
    
}

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>   
<script src="js/jquery111.js"></script>
<script src="js/jquery.datetimepicker.js"></script>
<script src="ui/jquery.ui.timepicker.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script>

function abc(t1)
{
   // alert(t1);
    arr = t1.split('_');
   // alert(arr[3]);
  var from_date=document.getElementById("from_date_"+arr[2]+"_"+arr[3]).value;
  var to_date=document.getElementById("to_date_"+arr[2]+"_"+arr[3]).value;
   
    f1=from_date.split('/');
    t2=to_date.split('/');
    f11=f1[1]+"/"+f1[0]+"/"+f1[2];
    t12=t2[1]+"/"+t2[0]+"/"+t2[2];
var date1 = new Date(f11);
var date2 = new Date(t12);

if(date2 < date1){
    alert("Please select grater than from or equal date");
    document.getElementById("to_date_"+arr[2]+"_"+arr[3]).value='';
    return false;
}


}
function abc1(t1)
{
   // alert(t1);
    arr = t1.split('_');
   // alert(arr[3]);
  var from_date=document.getElementById("from_app_date_"+arr[3]+"_"+arr[4]).value;
  var to_date=document.getElementById("to_app_date_"+arr[3]+"_"+arr[4]).value;
   
    f1=from_date.split('/');
    t2=to_date.split('/');
    f11=f1[1]+"/"+f1[0]+"/"+f1[2];
    t12=t2[1]+"/"+t2[0]+"/"+t2[2];
var date1 = new Date(f11);
var date2 = new Date(t12);

if(date2 < date1){
    alert("Please select grater than from or equal date");
    document.getElementById("to_app_date_"+arr[3]+"_"+arr[4]).value='';
    return false;
}


}



$( document ).ready(function() {
var t=document.getElementById("count_0").value; 
var ddd=document.getElementById("ddd").value; 

if(t=='') t1=0;




 $("#from_date_"+ddd+"_"+t1).datepicker({ 
                 //showButtonPanel: true,
                dateFormat: 'dd/mm/yy', 
                // altFormat: "yy-mm-dd",               
                numberOfMonths: 2,
                onSelect: function (selected) {
                    var dt = new Date(selected);                   
                    dt.setDate(dt.getDate() + 1);  
                    alert(dt);                 
                    $("#to_date_"+ddd+"_"+t1).datepicker("option", "minDate", dt);
                    
                }
            });
            $("#to_date_"+ddd+"_"+t1).datepicker({
                   // showButtonPanel: true,
                dateFormat: 'dd/mm/yy', 
               // altFormat: "yy-mm-dd", 
                numberOfMonths: 2,
                onSelect: function (selected) {
                    var dt = new Date(selected);
                    dt.setDate(dt.getDate() - 1);
                     $("#from_date_"+ddd+"_"+t1).datepicker("option", "maxDate", dt);
                },
                          
            });

 $("#from_app_date_"+ddd+"_"+t1).datepicker({               
                numberOfMonths: 2,
                onSelect: function (selected) {
                    var dt = new Date(selected);
                    dt.setDate(dt.getDate() + 1);
                     
                    $("#to_app_date_"+ddd+"_"+t1).datepicker("option", "minDate", dt);
                },
                 
            });
            $("#to_app_date_"+ddd+"_"+t1).datepicker({
               
                numberOfMonths: 2,
                onSelect: function (selected) {
                    var dt = new Date(selected);
                    dt.setDate(dt.getDate() - 1);
                    
                    $("#from_app_date_"+ddd+"_"+t1).datepicker("option", "maxDate", dt);
                },
               
            });


 });

$( document ).ready(function() {
$('.datetimepicker1').datetimepicker({
	datepicker:false,
	format:'H:i',
	step:5
});
$('.datetimepicker2').datetimepicker({
	timepicker:false,
	format:'d/m/Y',
	formatDate:'Y/m/d',
	//minDate:'-1970/01/02', // yesterday is minimum date
	//maxDate:'+1970/01/02' // and tommorow is maximum date calendar
});
});
</script>

<script language="JavaScript"> 
$('.timepicker').timepicker();
</script>