<link rel="stylesheet" href="css/new_mxerp.css">

<div class="body_contain">
<div class="tab_div"> 

<h1>Reference Acknowledgement</h1>

<form name="search" action="" method="post">
<?php 
$qu=DB_fetch_array(DB_query("SELECT no_of_assignee FROM conf_interview_approval",$db));
$no_assign=$qu['no_of_assignee'];
?>

<p align="left">
<?php  $url='&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'];?>
<a href='index.php?route=HRModule/Master/reference_aknow<?php echo$url; ?>'>
  <input class="search" type="button" value="Pending"></a>
  <a href='index.php?route=HRModule/Master/reference_hold<?php echo$url; ?>'>
  <input class="search" type="button" value="Hold"></a>
  <!--
  <a href='index.php?route=HRModule/Master/Reference_rejected<?php echo$url; ?>'>
  <input class="search" type="button" value="Rejected"></a>
  
  <a href='index.php?route=HRModule/Master/reference_ackowledge<?php echo$url; ?>'>
  <input class="search" type="button" value="Acknowledged"></a>-->
</p>
<table width="100%" cellspacing="0" cellpadding="3" border="0" align="center">
  <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="">Select Applicant </option>
         <?php $SQL12=DB_query("SELECT id,first_name,middle_name,last_name FROM hr_applcnt_rgstn where status='mail'",$db);
                         while($GetRec12=DB_fetch_array($SQL12)) {

        ?>
        <option value="<?php echo $GetRec12['first_name'];?>"><?php echo $GetRec12['first_name']." ".$GetRec12['middle_name']." ".$GetRec12['last_name']; ?></option>
          <?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>
</table>
<br>
<?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($_REQUEST['applicant']!='')
  {
  $filter[]="first_name='".$_REQUEST['applicant']."'";
  }
}
if($filter!='')
  {
  
    $filter1 = implode(" and ",$filter);
    
   $SQL=DB_query("SELECT * FROM hr_applcnt_rgstn WHERE $filter1 and STATUS='mail'",$db);
    }
else
{
  $SQL=DB_query("SELECT * FROM hr_applcnt_rgstn WHERE STATUS='mail'",$db);
}


?>
<h3>PENDING</h3>
<div style="width:100%; overflow:auto; margin:0 auto;">
<table width="120%" cellpadding="3" cellspacing="0" border="1" style="border:#808080 1px solid; border-collapse:collapse;">
  <tr>
    <th width="3%">S. No.</th>
    <th>Applicant Name</th>
    <th width="6%">Contact No.</th>
    <th width="12%">Email</th>
    <th width="8%">Department</th>
    <th width="10%">Designation</th>
    <th width="7%">Job Type</th>
    <th width="120">Reference Name</th>
    <th width="160">Reference Mail</th>
    <th width="440" style="text-align:center;">Action</th>
    <!--<td class="tabledata"><strong>Action</strong></td>-->
  </tr>
  <?php 
  $i=1;
  //$SQL=DB_query("SELECT * FROM hr_applcnt_rgstn where $filter1 and status='accept' and conf_int_app_details_seq ='".$oldseq."'"
  while($GetRec=DB_fetch_array($SQL)) {
    $applicantid=$GetRec['id'];
    $qt=DB_num_rows(DB_query("SELECT * FROM hr_applcnt_rgstn_ref where hr_applcnt_rgstn_id='".$GetRec['id']."' and akk_status='pending' and email!=''",$db));
  if($qt>0){
    ?>
  <tr>
    <td valign="top"><?php echo $i; ?></td>
    <td valign="top"><?php echo $GetRec['first_name']." ".$GetRec['middle_name']." ".$GetRec['last_name']; ?></td>
    <td valign="top"><?php echo $GetRec['mobile1']; ?></td>
    <td valign="top"><?php echo $GetRec['email1']; ?></td>       
    <td valign="top"><?php echo $s->GetFieldValue("deptmaster","id='".$GetRec['department']."'","deptname") ;?></td>
    <td valign="top"><?php echo $s->GetFieldValue("desigmaster","id='".$GetRec['designation']."'","designame") ;?></td>
    <td valign="top"><?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 colspan="3" valign="top" style="padding:0;">
    <div id="amc-tab">
      <table width="100%" border="0" cellpadding="3" cellspacing="0">
      <?php
          $t=1;
          
        $SQL1=DB_query("SELECT * FROM hr_applcnt_rgstn_ref where hr_applcnt_rgstn_id='".$GetRec['id']."' and akk_status='pending' and email!=''",$db);
          while($GetRec1=DB_fetch_array($SQL1)) {
          
          ?>         
      <tr>
        <td width="160" valign="top"><?php echo $GetRec1['name']; ?></td>
        <td width="160" valign="top">
        <?php echo $GetRec1['email']; ?></td>
        <td width="240" valign="top"><a href='index.php?route=HRModule/Master/reference_aknow<?php echo$url.'&id='.$GetRec1['id'].'&action='.'hold'; ?>'><input class="search" type="button" value="Hold" name="hold"></a> <a href='index.php?route=HRModule/Master/reference_aknow<?php echo$url.'&id='.$GetRec1['id'].'&action='.'reject'; ?>'><input class="search" type="button" value="Reject" name="reject"></a> <input class="search" type="submit" value="ACK" name="ack" onclick="return validate(<?php echo $t; ?>,<?php echo $GetRec1['id']; ?>)">          
        </td>
        <td width="200" valign="top"><textarea placeholder="Ackowledgement" rows="2" cols="10" name="ackdetails[]" id="ack_<?php echo $t; ?>_<?php echo $GetRec1['id']; ?>"></textarea></td>
      </tr>
      <input type="hidden" name="detailsid[]" value="<?php echo $GetRec1['id']; ?>">         
    <?php $t++; } ?>
    </table></div></td>         
  </tr>
  <?php $i++; } } ?>
</table>
</div>
</form>

</div>
</div>
<?php
if($_REQUEST['action']=='hold' && $_REQUEST['id']!='')
{
$qu=DB_query("UPDATE hr_applcnt_rgstn_ref SET akk_status='hold' WHERE id='".$_REQUEST['id']."'",$db);
echo "<script>alert('Hold');</script>";
$s->pageLocation("index.php?route=HRModule/Master/reference_aknow"."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']);

}
if($_REQUEST['action']=='reject' && $_REQUEST['id']!='')
{
$qu=DB_query("UPDATE hr_applcnt_rgstn_ref SET akk_status='reject' WHERE id='".$_REQUEST['id']."'",$db);
echo "<script>alert('Rejected');</script>";
$s->pageLocation("index.php?route=HRModule/Master/reference_aknow"."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']);
}

  if($_REQUEST['ack'])
  {
    for($it=0;$it<count($_REQUEST['detailsid']);$it++)
      {
        if($_REQUEST['ackdetails'][$it]!='')
        {
           $details=$_REQUEST['ackdetails'][$it];
           $mid=$_REQUEST['detailsid'][$it];
      $qu=DB_query("UPDATE hr_applcnt_rgstn_ref SET akk_status='ok',aknowlede='".$details."' WHERE id='".$mid."'",$db);
       } 
       }
    echo "<script>alert('Acknowledged');</script>";
  $s->pageLocation("index.php?route=HRModule/Master/reference_aknow"."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']);        
  }
  //echo "<pre>";
 // print_r($_REQUEST['ackdetails']);

?>
<?php /*
function dateDiff1($d1, $d2)
  {
        return round(abs(strtotime($d1)-strtotime($d2))/86400)+1;
  } 
  
  function sendMail($to_mail,$maildata,$email_id)
  {
    
    //$to='rajeev@acgil.com';
      $to  =  $to_mail;
        $email=$email_id;
        $subject="confirmation mail";
         require_once('mailerfunction/phpmailer/class.phpmailer.php');
        //include("../class.smtp.php");
      // optional, gets called from within class.phpmailer.php if not already loaded

        $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

        $mail->IsSMTP(); // telling the class to use SMTP

        try {
        
            $mail->Host       = "mail.marketing.i2k2.com"; // SMTP server
            $mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
            $mail->SMTPAuth   = true;                  // enable SMTP authentication
            //$mail->Host       = "host2.777networks.com"; // sets the SMTP server
            $mail->Host       = "mail.marketing.i2k2.com"; // sets the SMTP server
            $mail->Port       = 25;
            $mail->Username   = "authsasl@marketing.i2k2.com"; // SMTP account username
            $mail->Password   = "MtaMyNetwork?1024?";        // SMTP account password
            //$mail->Password   = "123456";        // SMTP account password
            $mail->AddReplyTo($email);
            $mail->AddAddress($to);
            //$mail->SetFrom($email);
            $mail->SetFrom($email);
            $mail->Subject = $subject;
            $mail->AltBody = $maildata; // optional - MsgHTML will create an alternate automatically
            //$mail->MsgHTML(file_get_contents('contents.html'));
            $mail->MsgHTML($maildata);
            //$mail->AddAttachment('images/phpmailer.gif');      // attachment
            //$mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
             if($mail->Send())
              $errorMsg="Sucessfully send";
       else
              $errorMsg="Not Sucessfully send";
            
          } catch (phpmailerException $e) {
          
          } catch (Exception $e) {
          }
  }

if(isset($_REQUEST['action'])=='mail' && $_REQUEST['id']!='' )
{ 
 
 $fromemail=$s->getField('www_users','id',$_SESSION['UserID'],'email');
  $subject="confirmation mail";
  
  $from='From'. ':- '. ' '.$fromemail ;
      $SQL13=DB_query("SELECT * FROM hr_applcnt_rgstn_ref where hr_applcnt_rgstn_id='".$_REQUEST['id']."'",$db);
      while($GetRec13=DB_fetch_array($SQL13))
       {
         $to=$GetRec13['email'];
           $name=$GetRec13['name'];
            $message="Mr / Ms". ":- ". $name. " " ."<br>". "this is confirmation mail ";
              //$m=mail($to,$subject,$message,$from);
            //$m=sendMail($to,$message,$fromemail);
            $m=sendMail($to,$message,$from);
  
      }

$dataArr1['status']='mail';
    $dataArr1['conf_int_app_details_seq']=0;
    //$dataArr1['conf_int_app_details_id']=$_REQUEST['id'];
    $dataArr1['awd_application_id']=$_REQUEST['id'];
    $dataArr1['created_by']=$_SESSION['UserID'];    
    $dataArr1['datetime']=date('Y-m-d H:i:s');
    $s->RecordInsert('hr_applcnt_rgstn_log_status',$dataArr1);
    echo "<script> alert('Email is sent '); </script>";
$s->pageLocation("index.php?route=HRModule/Master/refference_mail"."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']);
}*/
?>
<script type="text/javascript">
  function validate(str,nt)
  {
   //alert(str);
    var x=document.getElementById('ack_'+str+'_'+nt).value;
    //alert(x);
    if(x=='')
    {
    alert('please Enter ackowledgement');
    return false;
  }
  }
</script>