<?php 
error_reporting(0);
$SQLex=DB_query("select * from conf_interview_app_details where id='".$_REQUEST['id']."'",$db);
$record=DB_fetch_array($SQLex);

if(isset($_REQUEST['Save']) && $_REQUEST['Save']=='Save'){

//print_r($_REQUEST['question']);

 //$_REQUEST['question'];
 //print_r($_REQUEST['answer']);
// echo "<pre/>";
// print_r($_REQUEST);
// die('suspend');

     foreach($_REQUEST['question'] as $key=>$value)
  {
        date_default_timezone_set('Asia/Calcutta');
      $data['awd_question_dtls_id']=$key;
      //$data['awd_question_dtls_id']=$key;
      $data['awd_application_id']=$_REQUEST['applicantid'];
      $data['awd_answer_text']=$_REQUEST['answer'][$key];
      $data['conf_int_app_details_seq']=$_REQUEST['seq_no'];
      $data['conf_int_app_details_id']=$_REQUEST['config_int_detail_id'];
      $data['datetime']=date('Y-m-d H:i:s');
      $s->RecordInsert('awd_answer_txt',$data);


  }
    $dataArr['status']=$_REQUEST['status1'];
    $dataArr['conf_int_app_details_seq']=$_REQUEST['seq_no'];
    $condd="id='".$_REQUEST['applicantid']."'";
    $s->RecordEdit('hr_applcnt_rgstn',$dataArr,$condd);

    $dataArr1['status']=$_REQUEST['status1'];
    $dataArr1['conf_int_app_details_seq']=$_REQUEST['seq_no'];
    $dataArr1['conf_int_app_details_id']=$_REQUEST['config_int_detail_id'];
    $dataArr1['awd_application_id']=$_REQUEST['applicantid'];
    $dataArr1['created_by']=$_SESSION['UserID'];    
    $dataArr1['datetime']=date('Y-m-d H:i:s');
    $s->RecordInsert('hr_applcnt_rgstn_log_status',$dataArr1);
    $message="Accept answer successfull";
    $url='http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    echo "<script type='text/javascript'>alert('$message');</script>";
   // unset($_REQUEST);
  $s->pageLocation($url);
// die;

}
?>
<script type="text/javascript" src="js/css-pop.js"></script>
<script type="text/javascript" language="javascript">
function checkqty(i,str)
{
        var totlqty=parseFloat(document.getElementById("pending_qty_"+i).value);
	var Appqty=parseFloat(document.getElementById("app_qty_"+i).value);
        if(parseFloat(Appqty)>parseFloat(totlqty))
	{
            alert("Approval Qty is Not Greater Than Total Qty");
	document.getElementById("app_qty_"+i).focus();
	document.getElementById("app_qty_"+i).value=0;
        }
}
//	var courter=document.getElementById("count1").value;
//	var courter1=courter-1;
//	for(var i=1;i<=courter1;i++)
//	{
//	var totlqty=parseFloat(document.getElementById("pending_qty_"+i).value);
//	var Appqty=parseFloat(document.getElementById("app_qty_"+i).value);
//	if(Appqty>totlqty)
//	{
//	alert("Approval Qty is Not Greater Than Total Qty");
//	document.getElementById("app_qty_"+i).focus();
//	document.getElementById("app_qty_"+i).value=0;
//	}
//	}


function frmvalidate()
{
  //alert();
  //die;
	/*(document.getElementById("applicant").value=='0')
	{
		alert("Please Select Applicant Name !");
		document.getElementById("applicant").focus()
		return false;
	}
*/
}



function get_designation(str)
{
 //alert(str);
   $.ajax({
       url:"ajax_get_designation.php",
       type:"GET",
       //data:{aCatId:aCatId,compId:compId,areaId:areaId,topicId:topicId},
       data:{t:str},
       success:function(resultold_question){
            $("#design").html(resultold_question);
       }

   });
}
function get_applicant(str)
{
 //alert(str);
  var dept=document.getElementById("dept").value;
   $.ajax({
       url:"ajax_get_applicant.php",
       type:"GET",
       //data:{aCatId:aCatId,compId:compId,areaId:areaId,topicId:topicId},
       data:{design:str,depart:dept},
       success:function(resultold_question){
            $("#applicant").html(resultold_question);
       }

   });
}


</script>

   <?php //echo 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>

<h3><?php echo $record['approval_name']?> </h3>
<div class="centre" id="slidingDiv"> 
  <?php if(isset($message)){ echo $message; } ?>
<form name="search" action="" method="post">
<table width="100%" cellspacing="0" cellpadding="3" border="0" align="center">
  <tbody><tr class="row1">
    <td width="13%"><strong>Department</strong></td>
    <td width="20%"><select style="width:98%;" id="dept" name="dept" onchange="get_designation(this.value)">
    <option value="0">Select Department</option>
       <?php  $dept1=DB_query("SELECT * FROM `deptmaster` order by deptname",$db);?>

                 <?php   while($DeptRec1=DB_fetch_array($dept1)) { ?>
          <option value="<?php echo $DeptRec1['id']; ?>" <?php if($DeptRec1['id']==$_REQUEST['dept']){ echo "selected" ;}  ?>><?php echo $DeptRec1['deptname']; ?></option>
          <?php } ?>
      </select></td>
    <td width="13%"><strong>Designation</strong></td>
    <td width="20%"> 
      <select style="width:98%;" id="design" name="design" onchange="get_applicant(this.value)">              
      <option value="0">Select Designation</option>
      <?php  $design1=DB_query("SELECT * FROM `desigmaster` order by designame",$db);?>
              <?php   while($designRec1=DB_fetch_array($design1)) { ?>
          <option value="<?php echo $designRec1['id']; ?>" <?php if($designRec1['id']==$_REQUEST['design']){ echo "selected" ;}  ?>><?php echo $designRec1['designame']; ?></option>
          <?php } ?>        
         </select>
         <td width="13%"><strong>Applicant </strong></td>
    <td> 
      <select style="width:98%;" id="applicant" name="applicant">              
      <option value="0">Select Applicant </option>
       <?php if($record['seq_no']==1){

  $applicant=DB_query("SELECT id,first_name,middle_name,last_name FROM `hr_applcnt_rgstn` where status='shortlisted' order by first_name",$db);?>
	   <?php while($applresult=DB_fetch_array($applicant)) { ?>
	          <option value="<?php echo $applresult['id']; ?>" <?php if($applresult['id']==$_REQUEST['applicant']){ echo "selected" ;}  ?>><?php echo $applresult['first_name']." ".$applresult['middle_name']." ".$applresult['last_name']; ?></option>
	          <?php } 
          }else{
              $oldseq=$record['seq_no']-1;
            $applicant=DB_query("SELECT id,first_name,middle_name,last_name FROM `hr_applcnt_rgstn` where status='accept' and conf_int_app_details_seq ='".$oldseq."' order by first_name",$db);?>
     <?php while($applresult=DB_fetch_array($applicant)) { ?>
            <option value="<?php echo $applresult['id']; ?>" <?php if($applresult['id']==$_REQUEST['applicant']){ echo "selected" ;}  ?>><?php echo $applresult['first_name']." ".$applresult['middle_name']." ".$applresult['last_name']; ?>
          <?php } }?>        
         </select>
      </td>
    </tr>

<tr class="row1">
  <td style="text-align:center;" colspan="6"><input type="submit" onclick="return frmvalidate();" value="Search" class="search" name="Search">
  </td>
</tr>
</tbody></table>
</form>
</div>
<br />

<form method="post" action="">
<?php
//if(in_array($_SESSION['UserID'],$Explode))
//{

if($_REQUEST['Search']!=''){

  //$filter[]="1=1";
if($_REQUEST['dept']!='0')
  {
  $filter[]="department='".$_REQUEST['dept']."'";
  }
  if($_REQUEST['design']!='0' && $_REQUEST['design']!='')
  {
  $filter[]="designation='".$_REQUEST['design']."'";
  }
  if(isset($_REQUEST['applicant']))
  {
  $filter[]="id='".$_REQUEST['applicant']."'";
  }


?>
   
 <table width="100%" cellpadding="3" cellspacing="0" border="1" style="border:#808080 1px solid; border-collapse:collapse;">
<tr>
  <th width="4%" rowspan="2"><strong>S. No.</strong></th>
  <th rowspan="2"><strong>Applicant Name</strong></th>
  <th width="10%" rowspan="2"><strong>Contact No.</strong></th>
  <th width="12%" rowspan="2"><strong>Email</strong></th>
  <th width="8%" rowspan="2"><strong>Total Experience</strong></th>
  <th width="12%" rowspan="2"><strong>Department</strong></th>
  <th width="12%" rowspan="2"><strong>Designation</strong></th>
  <th width="10%" rowspan="2"><strong>Job Type</strong></th>
  <th colspan="2" style="text-align:center;"><strong>Resume</strong></th>
  <!--<td class="tabledata"><strong>Action</strong></td>-->
</tr>
<tr>
  <th width="5%" style="text-align:center;">Download</th>
  <th width="5%" style="text-align:center;">View</th>
</tr>

<?php $i=0; 
 
if(!empty($filter))
  {
  
    $filter1 = implode(" and ",$filter);
 if($record['seq_no']=="1"){
    $SQL=DB_query("SELECT * FROM hr_applcnt_rgstn where $filter1 and status='shortlisted'",$db);

  
//$SQL=DB_query("SELECT * FROM hr_applcnt_rgstn where  $filter1 and status='".$_REQUEST[status]."'",$db);
}else{
 
  $SQL=DB_query("SELECT * FROM hr_applcnt_rgstn where $filter1 and status='accept' and conf_int_app_details_seq ='".$oldseq."'",$db);
}

if(DB_num_rows($SQL)>0){ 
while($GetRec=DB_fetch_array($SQL)) {
  $applicantid=$GetRec['id'];
  ?>
<tr bgcolor="#fff">
  <td><?php echo $i+1; ?></td>
  <td><a onclick="show_div();" style="cursor: pointer; cursor: hand; color:#0169df; font-weight:bold;"><span ><?php echo $GetRec['first_name']." ".$GetRec['middle_name']." ".$GetRec['last_name']; ?></span></a></td>
        <td><?php echo $GetRec['mobile1']; ?></td>
        <td><?php echo $GetRec['email1']; ?></td>
        <td><?php echo $GetRec['total_experience'];  ?></td>
        <td><?php echo $s->GetFieldValue("deptmaster","id='".$GetRec['department']."'","deptname") ;?></td>
        <td><?php echo $s->GetFieldValue("desigmaster","id='".$GetRec['designation']."'","designame") ;?></td>
        <td><?php $jobtype= $s->GetFieldValue("hr_job_created","id='".$GetRec['hr_job_created_id']."'","job_type") ;
        		if($jobtype=='p'){
        			echo "Permanent";
        			$emp_type='Permanent';
        		}
        		if($jobtype=='c'){
        			echo "Contract ";
        			$emp_type='Contract';
        		}
        ?></td>
        <td style="text-align:center;">
          <?php //$filewidth="uploaded_docs/".$GetRec['attach_file']; ?>
          <a href="uploaded_docs/<?php echo $GetRec['attach_file']; ?>"target="_blank" title="Vacancy Profile"><img src="images/download1.png" height="15" width="15" title="Download Resume" ></a>
        </td>
        <td style="text-align:center;">
          <a href="#"  onclick="popup('popUpDiv')"><img src="images/search.png" height="15" width="15" title="View Resume" ></a>
        </td>
        <!--<td width="25%"><a href="index.php?route=HRModule/Master/applicant_shortlisting&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>&vacid=<?php echo $GetRec['id'] ?>&status=rejected"><input type="button" value="Reject" ></a>
          <a href="index.php?route=HRModule/Master/applicant_shortlisting&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>&vacid=<?php echo $GetRec['id'] ?>&status=hold"><input type="button" value="Hold" ></a>
          <a href="index.php?route=HRModule/Master/applicant_shortlisting&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>&vacid=<?php echo $GetRec['id'] ?>&status=shortlist"><input type="button" value="Shortlist" ></a>
         <a href="index.php?route=HRModule/Master/applicant_shortlisting&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>&vacid=<?php echo $GetRec['id'] ?>&status=pending"><input type="button" value="pending" ></a>
        </td>-->
  
</tr>


<?php $i++;}} else{?>
<tr>
    <td colspan="9">No Result Found.</td>
</tr>
<?php }
}
 ?>
 </table>
</form>

<br>
<!--<p align="left" id ="q"><span class="search">add</span></p>-->
<div id ="a" style="display:none;">

  <form name ="answe" method="post" action="">
 <table width="100%" cellpadding="3" cellspacing="0" border="1" style="border:#808080 1px solid; border-collapse:collapse;">
 	<?php 
 			$question_area=DB_query("select A.*, B.*,B.id as questionid from awd_question as A INNER JOIN awd_question_dtls as B ON A.id=B.question_id where A.emp_typ='".$emp_type."'",$db);
$area = array();
	while($recordques=DB_fetch_array($question_area)){
		$question[$recordques['assmnt_area_dtls_id']][$recordques['assmnt_topic_dtls_id']][]=$recordques;
		$area[]=$recordques['assmnt_area_dtls_id'];
		$topic[$recordques['assmnt_area_dtls_id']][$recordques['assmnt_topic_dtls_id']]=$recordques['assmnt_topic_dtls_id'];
	}
	//echo "<pre>";
	//print_r($topic);
	//$topic=array_unique($topic);
		$area=array_unique($area);
		foreach($area as $key=>$value ){

 	?>
	<tr>
	  <th ><strong><?php //echo $value;?> <?php echo $s->GetFieldValue("awd_member_assmnt_area_dtls","id='".$value."'","area_name") ;?></strong>

      <input type="hidden" name="seq_no" id="seq_no" value="<?php echo $record['seq_no'];?>">
       <input type="hidden" name="config_int_detail_id" id="config_int_detail_id" value="<?php echo $record['id'];?>">
       <input type="hidden" name="applicantid" id="applicantid" value="<?php echo $applicantid;?>">

    </th>
    <th colspan="<?php echo $record['seq_no']+1;?>">
        <strong><?php //echo $value;?> <?php echo $s->GetFieldValue("awd_member_assmnt_area_dtls","id='".$value."'","total_marks") ;?></strong>
    </th>
	</tr>
	<?php foreach($topic[$value] as $key1=>$value1) {
		?>
	<tr>
		<th><strong><?php echo $s->GetFieldValue("awd_member_assmnt_topic_dtls","id='".$value1."'","topic_name") ;?></strong></th>

    <th><strong><?php echo $s->GetFieldValue("awd_member_assmnt_topic_dtls","id='".$value1."'","total_marks") ;?></strong></th>

		<?php		
		for($i=1;$i<=$record['seq_no'];$i++){
				$SQLexasd=DB_query("select * from conf_interview_app_details where seq_no='".$i."' and interview_approval_id='".$record['interview_approval_id']."'",$db);
					$recordasd=DB_fetch_array($SQLexasd);
			?>			
		<th><strong><?php echo $recordasd['approval_name'];?></strong></th>
		<?php }
		?>		
	</tr>
	<?php
     foreach($question[$value][$value1] as $key1=>$value2)
     {
	 ?>
	<tr>
		<td><strong><?php echo $s->GetFieldValue("awd_question_dtls","id='".$value2['questionid']."'","ques_name"); ?></strong>
      <input type="hidden" id="question_<?php echo $value2['questionid']; ?>" name="question[<?php echo $value2['questionid']; ?>]" value="<?php echo $value2['questionid']; ?>" >

    </td>
      <td>
     <?php echo $s->GetFieldValue("awd_question_dtls","id='".$value2['questionid']."'","ques_marks"); ?></strong>
    </td>
		<?php for($k=1;$k<=$record['seq_no'];$k++){
				$SQLexchk=DB_query("select * from conf_interview_app_details where seq_no='".$k."' and interview_approval_id='".$record['interview_approval_id']."'",$db);
					$recordchk=DB_fetch_array($SQLexchk);
			?>
    </td>   
    <td>

       <!-- <input type ="text" name="answer" id="answer" <?php if($recordchk['seq_no']!=$record['seq_no']) { ?> readonly="readonly" <?php } ?>>-->
        <?php if($recordchk['seq_no']!=$record['seq_no']) {?>
    <textarea id="answer" name="answer1[<?php echo $value2['questionid'];?>]" readonly="readonly" ><?php echo $s->GetFieldValue("awd_answer_txt","awd_question_dtls_id='".$value2['questionid']."' and conf_int_app_details_seq='".$k."' and awd_application_id='".$applicantid."'","awd_answer_text"); ?></textarea>
<?php } else{ ?>
<textarea id="answer" name="answer[<?php echo $value2['questionid'];?>]"></textarea>
<?php } ?>
    </td>
		<?php }	?>
	</tr>
	
<?php } } } ?>
		<tr>
		<td colspan="5" style="text-align:center;">
      <input type="radio" name="status1" value="accept"  checked="checked" > Accept
      <input type="radio" name="status1" value="Reject"> Reject
</td>
	</tr>
  <tr>
    <td colspan="5" style="text-align:center;">
      <input type="submit" name="Save" class="search" id="save" value="Save">
</td>
  </tr>
</table>
</form>

</div></div>
<?php 
} ?>

<script>

 function show_div(){
  //alert();
//$("#q").click(function(){
//alert();   
   $("#a").show();
 // })
}

</script>
<!--main div Close -->
<div id="blanket" style="display:none;"></div>
<div id="popUpDiv" style="display:none; " >
    
      <a href="#" onclick="popup('popUpDiv')" >X</a>
        <?php 
 /* header("Content-Type: application/msword");
  function read_file_docx($filename){
      
      //  echo $filename;
        $striped_content = '';
        $content = '';

        if(!$filename || !file_exists($filename)) return false;

        $zip = zip_open($filename);

        if (!$zip || is_numeric($zip)) return false;


        while ($zip_entry = zip_read($zip)) {

            if (zip_entry_open($zip, $zip_entry) == FALSE) continue;

            if (zip_entry_name($zip_entry) != "word/document.xml") continue;

            $content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));

            zip_entry_close($zip_entry);
        }// end while

        zip_close($zip);

        //echo $content;
      // echo "<hr>";
       // file_put_contents('1.xml', $content);     

        $content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content);
        $content = str_replace('</w:r></w:p>', "\r\n", $content);
       // $striped_content = strip_tags($content);
        $striped_content = $content;

        return $striped_content;
    }



    $filename = $pr[1];

    $content = read_file_docx($filewidth);
    if($content !== false) {


        echo "<pre>".$content."</pre>";   
    }
    else {
        echo 'Couldn\'t find the file. Please check that file.';
    }
*/
        ?>
  </div>
