<?php
ob_start();
session_start();
date_default_timezone_set('asia/Kuala_Lumpur');
include "../db/connection.php";
include "send-email.php";
include "constant.php";
ini_set('display_errors',0);
if(isset($_SESSION) && $_SESSION['logged']!=1){
  header("Location:http://ytyportal.ytygroup.my/Dashboard/Authenticate/login.php");
  die;
}
//*********************************SUPPORT EMAIL START BY DEEP RANA*****************/
$querySE= "SELECT YTY_FN_EMPGRV_REPLY AS SUPPORT_EMAIL FROM DUAL"; 
$supportEmailDetails = oci_parse($dbcon,$querySE);
oci_execute($supportEmailDetails);
$rowSupt=oci_fetch_array($supportEmailDetails);
//echo"<pre>";print_r($rowSupt);die;
//*********************************SUPPORT EMAIL END BY DEEP RANA*****************/
$employeeId=$_SESSION['EMP_ID'];
$emp_name=$_SESSION['EMP_NAME'];

if(isset($_POST['employee_id']) && isset($_POST['application_id']))
{
  //echo"<pre>";print_r($_POST);die;
  $insertFlag=0;
  $emp_id = $_POST['emp_id'];
  $emp_name = $_POST['emp_name'];
  $date_form_submitted = date('d-M-Y',strtotime($_POST['date_form_submitted']));
  $postion = $_POST['postion'];
  $employee_sign = $_POST['employee_sign'];
  $date = date('d-M-Y',strtotime($_POST['date']));
  $event_location = $_POST['event_location'];
  $event_location_Date = $_POST['event_location_Date'];
  $witness = $_POST['witness'];
  $event_account = $_POST['event_account'];
  $violation = $_POST['violation'];
  $team_handled = $_POST['team_handled'];
  $emp_sign_1 = $_POST['emp_sign_1'];
  $date_1 = date('d-M-Y',strtotime($_POST['date_1']));
  $received_sign = $_POST['received_sign'];
  $date_2 = date('d-M-Y',strtotime($_POST['date_2']));
  $grievance_status ='0';
  $from_language =$_POST['convert_lang'];
  $to_language ='en';

  if($_POST['assign_emp_id']){
  //*****************************Language code****************************/
  $assignEmpId=$_POST['emp_id'];
  $hrComment=addslashes($_POST['comment']);
  list($hrCat,$catId)=explode("_",$_POST['priority']);
  $returnLangEm=$assignEmpId;
  $returnLangCmt=$hrComment;
  $returnLangCat=$hrCat; 
  if($to_language!=$from_language)
  { 
    $assignEmpId=$_POST['emp_id'];
    $hrComment=addslashes($_POST['comment']);
    list($hrCat,$catId)=explode("_",$_POST['priority']);
    $returnLangEm=googleTranslatorCoverter($assignEmpId,$to_language,$from_language);
    $returnLangCmt=googleTranslatorCoverter($hrComment,$to_language,$from_language);
    $returnLangCat=googleTranslatorCoverter($hrCat,$to_language,$from_language); 
  }

  //echo"<pre>";print_r($returnLangEm);die;

    $email_id=$_POST['to_email_id'];
    $update_query = "UPDATE EMPLOYEE_GRIEVANCE SET ASSIGN_TO_EMPLOYEE='".$returnLangEm."',STATUS_OF_GRIEVANCE='2',ADMIN_COMMENT='".addslashes($returnLangCmt)."',CATEGORY='".$returnLangCat."',ASSIGN_TO_EMPLOYEE_GRV='".$_POST['assign_emp_id']."',ADMIN_COMMENT_GRV='".addslashes($_POST['comment'])."',CATEGORY_GRV='".$hrCat."',ASSIGN_EMP_DATE=sysdate WHERE EMP_ID='".$_POST['employee_id']."' AND APPLICATION_ID='".$_POST['application_id']."'";
    $executeQuery1= oci_parse($dbcon,$update_query);
    $html_to='<!doctype html>
    <html>
    <head>
      <title></title>
      <style type="text/css">
        table {border-collapse:separate;}
        .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td {line-height: 100%}
        .ExternalClass {width: 100%;}
    
        .wrapper {
          width:100%;
          background-color: #fff;
        }
    
        .container {
          width:800px !important;
        }
    
        .content {
          background-color: #fff;
          border: 1px solid #D6D6D6;
          -webkit-box-shadow: 0px 0px 7px 1px rgba(0,0,0,0.75);
          -moz-box-shadow: 0px 0px 7px 1px rgba(0,0,0,0.75);
          box-shadow: 0px 0px 7px 1px rgba(0,0,0,0.55);
        }
    
        .mbody {
          color: #000;
          font-family: Verdana;
          font-style: normal;
          font-size: 10.5pt;
        }
    
        .note {
          font-size: 7.5pt;
          font-family: Verdana;
          color: #000;
          text-align: justify;
        }
      </style>
    </head>
    <body>
    <table cellpadding="0" cellspacing="0" align="center" border="0" width="100%" style="height:100%!important; margin:0; padding:0; width:100%!important; text-align:center">
    <tr>
      <td style="height:20px; display:block;"></td>
    </tr>
    <tr>
      <td style="width:20px; display:block;"></td>
      <td align="center">
        <table class="content" border="0" cellspacing="0" cellpadding="0" width="800" style="border-collapse: collapse; border:1px solid #7f7f7f;">
        <tr>
          <td>
            <img src="http://dl.ytygroup.com.my/CommonLogo/MailHeader.jpg" width="952" height="106" style="display:block;"/>
          </td>
        </tr>
        <tr>
          <td style="height:10px; display:block;"></td>
        </tr>
        <tr>
          <td>
            <table class="mbody" style="width:100%;">
            <tr>
              <td style="width:20px; display:block;"></td>
              <td style="line-height: 1.3em;">
                <p>Dear PIC,</p>
                <p><b>Application no.:</b>'.$_POST['application_id'].'</p>
                <p><b>Employee ID :</b>'.substr($_POST['employee_id'],3).'</p>
                <p><b>Employee Name :</b>'.$emp_name.'</p>
                <p>Kindly respond to this within the stipulated time frame.</p>
                <br/><p>Sincerely,<br /><b>YTY Workflow</b></p> 
                <p style="font-size:11px;">Note: This message is auto-generated so please do not respond to this email.</p></td>
              <td style="width:20px; display:block;"></td>
            </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td style="height:10px; display:block;"></td>
        </tr>
        <tr>
          <td>
            <img src="http://dl.ytygroup.com.my/CommonLogo/MailFooter.jpg" style="display:block;"/>
          </td>
        </tr>
        </table>
      </td>
      <td style="width:20px; display:block;"></td>
    </tr>
    <tr>
      <td style="height:20px; display:block;"></td>
    </tr>
    </table>
    </body>
    </html>';
    //echo"<pre>";print_r($email_id);die;
    if($email_id){ 
      $mailSubject="GRIEVANCE SYSTEM-GRIEVANCE CASE ASSIGNED/APPLICATION NO :".$_POST['application_id'];
      sendEmail($email_id,$mailSubject,$html_to,'');
      //sendEmail('oraclesupport@ytygroup.com.my',$mailSubjectHr,$htmlHr);
    }
  }
  else{
    //echo"<dfsdf>";print_r($_POST);die;
    if($_POST['cnd_handled_by']=="" && $_POST['cnd_addtional']!="")
    {
      $assignEmpId=$_POST['emp_id'];
      $hrComment=addslashes($_POST['comment']);
      list($hrCat,$catId)=explode("_",$_POST['priority']);
      $returnLangEm=$assignEmpId;
      $returnLangCmt=$hrComment;
      $returnLangCat=$hrCat;
      if($to_language!=$from_language)
      { 
        $assignEmpId=$_POST['emp_id'];
        $hrComment=addslashes($_POST['comment']);
        list($hrCat,$catId)=explode("_",$_POST['priority']);
        $returnLangEm=googleTranslatorCoverter($assignEmpId,$to_language,$from_language);
        $returnLangCmt=googleTranslatorCoverter($hrComment,$to_language,$from_language);
        $returnLangCat=googleTranslatorCoverter($hrCat,$to_language,$from_language); 
      }      
      //echo"<pre>";print_r($returnLangCat);die;
    
        $email_id=$_POST['to_email_id'];
        $update_query = "UPDATE EMPLOYEE_GRIEVANCE SET ASSIGN_TO_EMPLOYEE='".$returnLangEm."',STATUS_OF_GRIEVANCE='2',ADMIN_COMMENT='".addslashes($returnLangCmt)."',CATEGORY='".$returnLangCat."',ASSIGN_TO_EMPLOYEE_GRV='".$_POST['update_assign_emp_id']."',ADMIN_COMMENT_GRV='".addslashes($_POST['comment'])."',CATEGORY_GRV='".$hrCat."',ASSIGN_EMP_DATE=sysdate WHERE EMP_ID='".$_POST['employee_id']."' AND APPLICATION_ID='".$_POST['application_id']."'";
        $executeQuery1= oci_parse($dbcon,$update_query);
        $html_to='<!doctype html>
        <html>
        <head>
          <title></title>
          <style type="text/css">
            table {border-collapse:separate;}
            .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td {line-height: 100%}
            .ExternalClass {width: 100%;}
        
            .wrapper {
              width:100%;
              background-color: #fff;
            }
        
            .container {
              width:800px !important;
            }
        
            .content {
              background-color: #fff;
              border: 1px solid #D6D6D6;
              -webkit-box-shadow: 0px 0px 7px 1px rgba(0,0,0,0.75);
              -moz-box-shadow: 0px 0px 7px 1px rgba(0,0,0,0.75);
              box-shadow: 0px 0px 7px 1px rgba(0,0,0,0.55);
            }
        
            .mbody {
              color: #000;
              font-family: Verdana;
              font-style: normal;
              font-size: 10.5pt;
            }
        
            .note {
              font-size: 7.5pt;
              font-family: Verdana;
              color: #000;
              text-align: justify;
            }
          </style>
        </head>
        <body>
        <table cellpadding="0" cellspacing="0" align="center" border="0" width="100%" style="height:100%!important; margin:0; padding:0; width:100%!important; text-align:center">
        <tr>
          <td style="height:20px; display:block;"></td>
        </tr>
        <tr>
          <td style="width:20px; display:block;"></td>
          <td align="center">
            <table class="content" border="0" cellspacing="0" cellpadding="0" width="800" style="border-collapse: collapse; border:1px solid #7f7f7f;">
            <tr>
              <td>
                <img src="http://dl.ytygroup.com.my/CommonLogo/MailHeader.jpg" width="952" height="106" style="display:block;"/>
              </td>
            </tr>
            <tr>
              <td style="height:10px; display:block;"></td>
            </tr>
            <tr>
              <td>
                <table class="mbody" style="width:100%;">
                <tr>
                  <td style="width:20px; display:block;"></td>
                  <td style="line-height: 1.3em;">
                    <p>Dear PIC,</p>
                    <p><b>Application no.:</b>'.$_POST['application_id'].'</p>
                    <p><b>Employee ID :</b>'.substr($_POST['employee_id'],3).'</p>
                    <p><b>Employee Name :</b>'.$emp_name.'</p>
                    <p>Kindly respond to this within the stipulated time frame.</p>
                    <br/><p>Sincerely,<br /><b>YTY Workflow</b></p> 
                    <p style="font-size:11px;">Note: This message is auto-generated so please do not respond to this email.</p></td>
                  <td style="width:20px; display:block;"></td>
                </tr>
                </table>
              </td>
            </tr>
            <tr>
              <td style="height:10px; display:block;"></td>
            </tr>
            <tr>
              <td>
                <img src="http://dl.ytygroup.com.my/CommonLogo/MailFooter.jpg" style="display:block;"/>
              </td>
            </tr>
            </table>
          </td>
          <td style="width:20px; display:block;"></td>
        </tr>
        <tr>
          <td style="height:20px; display:block;"></td>
        </tr>
        </table>
        </body>
        </html>';
        //echo"<pre>";print_r($email_id);die;
        if($email_id){ 
          $mailSubject="GRIEVANCE SYSTEM-GRIEVANCE CASE ASSIGNED/APPLICATION NO :".$_POST['application_id'];
          sendEmail($email_id,$mailSubject,$html_to,'');
          //sendEmail('oraclesupport@ytygroup.com.my',$mailSubjectHr,$htmlHr);
        }
    }
    else if($_POST['received_sign']=="")
    {
      $assignEmpId=$_POST['emp_id'];
      $hrComment=addslashes($_POST['comment']);
      list($hrCat,$catId)=explode("_",$_POST['priority']);
      $returnLangEm=$assignEmpId;
      $returnLangCmt=$hrComment;
      $returnLangCat=$hrCat;
      if($to_language!=$from_language)
      { 
        $assignEmpId=$_POST['emp_id'];
        $hrComment=addslashes($_POST['comment']);
        list($hrCat,$catId)=explode("_",$_POST['priority']);
        $returnLangEm=googleTranslatorCoverter($assignEmpId,$to_language,$from_language);
        $returnLangCmt=googleTranslatorCoverter($hrComment,$to_language,$from_language);
        $returnLangCat=googleTranslatorCoverter($hrCat,$to_language,$from_language); 
      }      
      //echo"<pre>";print_r($returnLangCat);die;
    
        $email_id=$_POST['to_email_id'];
        $update_query = "UPDATE EMPLOYEE_GRIEVANCE SET ASSIGN_TO_EMPLOYEE='".$returnLangEm."',STATUS_OF_GRIEVANCE='2',ADMIN_COMMENT='".addslashes($returnLangCmt)."',CATEGORY='".$returnLangCat."',ASSIGN_TO_EMPLOYEE_GRV='".$_POST['update_assign_emp_id']."',ADMIN_COMMENT_GRV='".addslashes($_POST['comment'])."',CATEGORY_GRV='".$hrCat."',ASSIGN_EMP_DATE=sysdate WHERE EMP_ID='".$_POST['employee_id']."' AND APPLICATION_ID='".$_POST['application_id']."'";
        $executeQuery1= oci_parse($dbcon,$update_query);
        $html_to='<!doctype html>
        <html>
        <head>
          <title></title>
          <style type="text/css">
            table {border-collapse:separate;}
            .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td {line-height: 100%}
            .ExternalClass {width: 100%;}
        
            .wrapper {
              width:100%;
              background-color: #fff;
            }
        
            .container {
              width:800px !important;
            }
        
            .content {
              background-color: #fff;
              border: 1px solid #D6D6D6;
              -webkit-box-shadow: 0px 0px 7px 1px rgba(0,0,0,0.75);
              -moz-box-shadow: 0px 0px 7px 1px rgba(0,0,0,0.75);
              box-shadow: 0px 0px 7px 1px rgba(0,0,0,0.55);
            }
        
            .mbody {
              color: #000;
              font-family: Verdana;
              font-style: normal;
              font-size: 10.5pt;
            }
        
            .note {
              font-size: 7.5pt;
              font-family: Verdana;
              color: #000;
              text-align: justify;
            }
          </style>
        </head>
        <body>
        <table cellpadding="0" cellspacing="0" align="center" border="0" width="100%" style="height:100%!important; margin:0; padding:0; width:100%!important; text-align:center">
        <tr>
          <td style="height:20px; display:block;"></td>
        </tr>
        <tr>
          <td style="width:20px; display:block;"></td>
          <td align="center">
            <table class="content" border="0" cellspacing="0" cellpadding="0" width="800" style="border-collapse: collapse; border:1px solid #7f7f7f;">
            <tr>
              <td>
                <img src="http://dl.ytygroup.com.my/CommonLogo/MailHeader.jpg" width="952" height="106" style="display:block;"/>
              </td>
            </tr>
            <tr>
              <td style="height:10px; display:block;"></td>
            </tr>
            <tr>
              <td>
                <table class="mbody" style="width:100%;">
                <tr>
                  <td style="width:20px; display:block;"></td>
                  <td style="line-height: 1.3em;">
                    <p>Dear PIC,</p>
                    <p><b>Application no.:</b>'.$_POST['application_id'].'</p>
                    <p><b>Employee ID :</b>'.substr($_POST['employee_id'],3).'</p>
                    <p><b>Employee Name :</b>'.$emp_name.'</p>
                    <p>Kindly respond to this within the stipulated time frame.</p>
                    <br/><p>Sincerely,<br /><b>YTY Workflow</b></p> 
                    <p style="font-size:11px;">Note: This message is auto-generated so please do not respond to this email.</p></td>
                  <td style="width:20px; display:block;"></td>
                </tr>
                </table>
              </td>
            </tr>
            <tr>
              <td style="height:10px; display:block;"></td>
            </tr>
            <tr>
              <td>
                <img src="http://dl.ytygroup.com.my/CommonLogo/MailFooter.jpg" style="display:block;"/>
              </td>
            </tr>
            </table>
          </td>
          <td style="width:20px; display:block;"></td>
        </tr>
        <tr>
          <td style="height:20px; display:block;"></td>
        </tr>
        </table>
        </body>
        </html>';
        //echo"<pre>";print_r($email_id);die;
        if($email_id){ 
          $mailSubject="GRIEVANCE SYSTEM-GRIEVANCE CASE ASSIGNED/APPLICATION NO :".$_POST['application_id'];
          sendEmail($email_id,$mailSubject,$html_to,'');
          //sendEmail('oraclesupport@ytygroup.com.my',$mailSubjectHr,$htmlHr);
        }
    }
    else{ 
          $hrRmk=$_POST['remark'];
          $returnLangRmk=googleTranslatorCoverter($hrRmk,$to_language,$from_language);  
          $grievance_status ='1';
          $email_id=$_POST['emp_email_id'];
          $update_query = "UPDATE EMPLOYEE_GRIEVANCE SET STATUS_OF_GRIEVANCE='". $grievance_status."',CLOSURE_ACTIONS_REMARK='".addslashes($_POST['remark'])."',CLOSE_DATE=sysdate,CLOSE_BY='".$employeeId."',CLOSURE_ACTIONS_REMARK_GRV='".addslashes($returnLangRmk)."',CLOSE_DATE_GRV=sysdate WHERE EMP_ID='".$_POST['employee_id']."' AND APPLICATION_ID='".$_POST['application_id']."'";
          $executeQuery1= oci_parse($dbcon,$update_query);
          $query= "SELECT EG.*,ei.employee_name AS ASSIGN_TO FROM EMPLOYEE_GRIEVANCE EG
          LEFT JOIN YTY_VW_EMP_INFO EI ON EG.ASSIGN_TO_EMPLOYEE=EI.EMP_MAIN_ID WHERE EG.APPLICATION_ID='".$_POST['application_id']."'"; 
          $tableDetails = oci_parse($dbcon, $query);
          oci_execute($tableDetails);
          $rowDetailsArr=oci_fetch_array($tableDetails);
          $from_language =$rowDetailsArr['EMP_GRV_LANGUAGE'];
          $to_language =$rowDetailsArr['HR_LANGUAGE'];
          $searchArr=array("APPLICATION_ID","EMPLOYEE_NAME","EMPLOYEE_ID");
          $replaceArr=array($_POST['application_id'],$emp_name,substr($_POST['employee_id'],3));
          $convertedLanguage=MsgTextFormat($searchArr,$replaceArr,$emailConstant[$from_language]);
          $engLanguage=MsgTextFormat($searchArr,$replaceArr,$emailConstant[$to_language]);
          $encode=base64_encode($_POST['application_id']."_".$from_language);
          //echo"<pre>";print_r(base64_encode$encode);die;
          //$jsMsg=str_replace('APPLICATION_ID',$_POST['application_id'],$emailConstant[$from_language]);
          //$returnLangEl=googleTranslatorCoverter($jsMsg,$to_language,$from_language);
          //echo"<pre>";print_r($_POST);die;
          if($_POST['mobile_no']!="")
          { 
            $mobile=$_POST['mobile_no'];
            $query1= "SELECT  YTY_FN_EMP_GRV_PASS_VERIF('".$_POST['application_id']."') PASSCODE FROM DUAL"; 
            $tableDetails1= oci_parse($dbcon, $query1);
            oci_execute($tableDetails1);
            $row1=oci_fetch_array($tableDetails1);
            $passCode=$row1['PASSCODE'];
            $encode=base64_encode($_POST['application_id']."_".$from_language);
            $replaceLink='https://ytyhub.com/formsyty/yty-grievance-serarch-form.php?empDet='.$encode;
            $querySmsTemplate= "SELECT SMS_TEMPLATE FROM XXYTY_SMS_TEMPLATE T WHERE T.PORTAL_TYPE = '1005' AND T.FROM_TYPE = 'CLOSEFORM'"; 
            $tableDetailsSMS= oci_parse($dbcon, $querySmsTemplate);
            oci_execute($tableDetailsSMS);
            $row2=oci_fetch_array($tableDetailsSMS);
            $sms_template=$row2['SMS_TEMPLATE'];
            $searchArr=array('APPLICATION_ID','PASSCODE','LINK');
            $replaceArr=array($_POST['application_id'],$passCode,$replaceLink);
            $mergeSMS=MsgTextFormat($searchArr,$replaceArr,$sms_template);
            //echo"<pre>";print_r($mergeSMS);die;
            $returnSms=gw_send_sms($mobile,$mergeSMS);
          }
          $html_emp='<!doctype html>
          <html>
          <head>
            <title></title>
            <style type="text/css">
              table {border-collapse:separate;}
              .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td {line-height: 100%}
              .ExternalClass {width: 100%;}
          
              .wrapper {
                width:100%;
                background-color: #fff;
              }
          
              .container {
                width:800px !important;
              }
          
              .content {
                background-color: #fff;
                border: 1px solid #D6D6D6;
                -webkit-box-shadow: 0px 0px 7px 1px rgba(0,0,0,0.75);
                -moz-box-shadow: 0px 0px 7px 1px rgba(0,0,0,0.75);
                box-shadow: 0px 0px 7px 1px rgba(0,0,0,0.55);
              }
          
              .mbody {
                color: #000;
                font-family: Verdana;
                font-style: normal;
                font-size: 10.5pt;
              }
          
              .note {
                font-size: 7.5pt;
                font-family: Verdana;
                color: #000;
                text-align: justify;
              }
            </style>
          </head>
          <body>
          <table cellpadding="0" cellspacing="0" align="center" border="0" width="100%" style="height:100%!important; margin:0; padding:0; width:100%!important; text-align:center">
          <tr>
            <td style="height:20px; display:block;"></td>
          </tr>
          <tr>
            <td style="width:20px; display:block;"></td>
            <td align="center">
              <table class="content" border="0" cellspacing="0" cellpadding="0" width="800" style="border-collapse: collapse; border:1px solid #7f7f7f;">
              <tr>
                <td>
                  <img src="http://dl.ytygroup.com.my/CommonLogo/MailHeader.jpg" width="952" height="106" style="display:block;"/>
                </td>
              </tr>
              <tr>
                <td style="height:10px; display:block;"></td>
              </tr>
              <tr>
                <td>
                  <table class="mbody" style="width:100%;">
                  <tr>
                    <td style="width:20px; display:block;"></td>
                    <td style="line-height: 1.3em;">
                    '.$convertedLanguage.'<br><br>English Version-:<br><br>'.$engLanguage.'  
                    <br/><p><a href="https://ytyhub.com/formsyty/yty-grievance-serarch-form.php?empDet='.$encode.'">See More Detail</a></p>           
                      <br/><p>Sincerely,<br /><b>YTY Workflow</b></p> 
                      <p style="font-size:11px;">Note: This message is auto-generated so please do not respond to this email.</p></td>
                    <td style="width:20px; display:block;"></td>
                  </tr>
                  </table>
                </td>
              </tr>
              <tr>
                <td style="height:10px; display:block;"></td>
              </tr>
              <tr>
                <td>
                  <img src="http://dl.ytygroup.com.my/CommonLogo/MailFooter.jpg" style="display:block;"/>
                </td>
              </tr>
              </table>
            </td>
            <td style="width:20px; display:block;"></td>
          </tr>
          <tr>
            <td style="height:20px; display:block;"></td>
          </tr>
          </table>
          </body>
          </html>';
          //echo"<pre>";print_r($html_emp);die;
          if($email_id){ 
            $filePath=$_POST['application_id'].".png";
            $mailSubject="GRIEVANCE SYSTEM-GRIEVANCE CASE CLOSURE/APPLICATION ID:".$_POST['application_id'];
            //$mailFunction="select ytycustom.SEND_MAIL_ATTACH_FINAL(p_to => ytycustom.mail_address('".$email_id."'), 
                                //  p_cc => ytycustom.mail_address('oraclesupport@ytygroup.com.my'),
                                //  p_bcc => ytycustom.mail_address('rana.deepkamal@gmail.com'),
                                //  p_subject => '".$mailSubject."',
                                //  p_attach_name =>'".$filePath."',
                                //  p_msg => '".$html_emp."',
                                //  p_msg_type => 'HTML',
                                // p_directory => 'GRIUPLOAD'
                                // ) FROM DUAL";
                  // $insertEmailQuery = oci_parse($dbcon, $mailFunction);
                  // $r = oci_execute($insertEmailQuery);
                    //if (!$r) {
                    // $e = oci_error($insertEmailQuery); 
                    // echo htmlentities($e['message']);
                    // echo "<pre>";
                    // echo htmlentities($e['sqltext']);
                      //printf("\n%".($e['offset']+1)."s", "^");
                      //echo "</pre>";
                    //}
                    //else{
                    // echo "Yes mail send..";
                    
                    //}
                    
            sendEmail($email_id,$mailSubject,$html_emp,'');
          }
    }
  }
  if(oci_execute($executeQuery1))
    {
        $insertFlag=1;
    }           
    if($insertFlag==1)
    {
      header("location:yty-grievance-moderator.php?msg=Data has been updated successfuly.");  
      die;    
   }
   else
   {
      header("location:yty-grievance-moderator.php?msg=Data Not Inserted.");
      die;      
   }
}
if(isset($_POST['emp_id']) && isset($_POST['app_id']))
{
  $query= "SELECT EG.*,ei.employee_name AS ASSIGN_TO FROM EMPLOYEE_GRIEVANCE EG
              LEFT JOIN YTY_VW_EMP_INFO EI ON EG.ASSIGN_TO_EMPLOYEE_GRV=EI.EMP_MAIN_ID WHERE EG.EMP_ID='".$_POST['emp_id']."' AND EG.APPLICATION_ID='".$_POST['app_id']."'"; 
  $tableDetails = oci_parse($dbcon, $query);
  oci_execute($tableDetails);
  $rowDetailsArr=oci_fetch_array($tableDetails);
  //echo "<pre>";print_r($rowDetailsArr);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <title>EMPLOYEE GRIEVANCE AND REDRESSAL</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="css/mystyle.css">
  <link rel="shortcut icon" href="favicon.png" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>

</head>
<body>
<header id="myHeader">
  <div class="container-fluid">
   <div class="col-md-8 col-sm-7 col-xs-12 pull-left">
   <img src="medi-logo1.png" alt="YTY"><span>EMPLOYEE GRIEVANCE AND REDRESSAL</span>
   </div>

    <div class="col-md-4 col-sm-5 col-xs-12 pull-right">
    <div class="row">
        <div class="col-md-6 col-sm-6 col-xs-6" style="padding:0"> 
         <div class="modal-content">    
         <div id="google_translate_element">
           <button><i class="fa fa-language"></i></button> 
          </div>
        </div>
       </div>        
    </div>        
   </div>
  </div>
</header>
 <div class="containerfluid mydesignform">
 
   <div class="row">
     <div class="divtitle">
       <h1>EMPLOYEE GRIEVANCE FORM<span>(Employees are strongly encouraged to have informal discussions before filling the  grievance form)</span></h1>
     </div>  
     <div class="col-sm-12 col-xs-4">
                    <?php
          if($_REQUEST['msg'])
          {
            ?>
                        <div class="alert alert-success" id="success-alert">
                          <button type="button" class="close" data-dismiss="alert">x</button>
                          <strong><?php echo $_REQUEST['msg'];?></strong></a>
                        </div>  
          <?php
          }
          ?>
          </div>
   </div>
   
   <div class="row">
      <form action="" method="post" id="formSubmit">
      <input type="hidden" name="employee_id" value="<?php echo $_POST['emp_id'];?>" />
      <input type="hidden" name="application_id" value="<?php echo $_POST['app_id'];?>" />
      <input type="hidden" name="emp_email_id" value="<?php echo $rowDetailsArr['EMPLOYEE_EMAIL'];?>" />
      <input type="hidden" name="convert_lang" value="<?php echo $rowDetailsArr['EMP_GRV_LANGUAGE'];?>" />
      <input type="hidden" name="mobile_no" value="<?php echo $rowDetailsArr['EMPLOYEE_MOB'];?>" />
      <div class="section1bg">
      <!--heading Start-->  
      <div class="col-lg-12 col-12 formheading">EMPLOYEE'S INFORMATION</div>
      <!--heading End-->     
       <!--Form Column Start-->
      <div class="col-lg-6 col-md-6 col-sm-6 col-6 autodropdownlist">
        <div class="form-group">
         <label for="email">EMPLOYEE ID<span>*</span></label>
         <input type="text" class="form-control" disabled name="emp_id_1" required id="emp_id_1" value="<?php echo substr($rowDetailsArr['EMP_ID'],3);?>"    onkeyup="return wating(this.value)" onchange="return getEmployeeDetails(document.getElementById('txtUserid').value)">
        </div>
      </div>
      <!--Form Column End-->
   
      <!--Form Column Start-->
      <div class="col-lg-6 col-md-6 col-sm-6 col-6">
        <div class="form-group">
         <label for="email">EMPLOYEE NAME<span>*</span></label>
         <input type="text" class="form-control" name="emp_name" value="<?php echo $rowDetailsArr['EMPLOYEE_NAME'];?>" id="emp_name" readonly placeholder="" required>
        </div>
      </div>      
      <!--Form Column End-->
      <!--Form Column Start-->
      <div class="col-lg-6 col-md-6 col-sm-6 col-6">
        <div class="form-group">
         <label for="email">DATE FORM SUBMITTED<span>*</span></label>
         <input class="form-control" name="date_form_submitted" placeholder="MM/DD/YYY" value="<?php echo date('d-M-Y',strtotime($rowDetailsArr['SUBMISSION_DATE']));?>" readonly required type="text"  autocomplete="off"/>
        </div>
      </div>
      <!--Form Column End--> 
      <!--Form Column Start-->
      <!--<div class="col-lg-6 col-md-6 col-sm-6 col-6">
        <div class="form-group">
         <label for="email">POSITION</label>
         <input type="text" class="form-control" value="<?php echo $rowDetailsArr['POSITION'];?>" readonly name="postion" required>
        </div>
      </div>-->
      <!--Form Column End--> 
      <!--Form Column Start-->
      <!--<div class="col-lg-6 col-md-6 col-sm-6 col-6">
        <div class="form-group">
         <label for="email">SIGNATURE OF EMPLOYEE</label>
         <input type="text" class="form-control" value="<?php echo $rowDetailsArr['EMP_SIGNATURE_1'];?>" readonly name="employee_sign">
        </div>
      </div>-->
      <!--Form Column End-->
      <!--Form Column Start-->
      <!--<div class="col-lg-6 col-md-6 col-sm-6 col-6">
        <div class="form-group">
         <label for="email">DATE</label>
          <input class="form-control" name="date" type="text"  value="<?php echo date('d-M-Y',strtotime($rowDetailsArr['SIGN_DATE_1']));?>" readonly autocomplete="off"/>
        </div>
      </div>-->
       <!--Form Column Start-->
       <div class="col-lg-6 col-md-6 col-sm-6 col-6">
        <div class="form-group">
         <label for="email">Email</label>
         <input type="email" class="form-control"  name="email_id" disabled value="<?php echo $rowDetailsArr['EMPLOYEE_EMAIL'];?>" id="email_id" required>
        </div>
      </div>
      <!--Form Column End-->
      <!--Form Column Start-->
      <div class="col-lg-6 col-md-6 col-sm-6 col-6">
        <div class="form-group">
         <label for="email">Mobile</label>
          <input class="form-control" name="mobile" id="mobile" type="number" disabled value="<?php echo $rowDetailsArr['EMPLOYEE_MOB'];?>" required  autocomplete="off"/>
        </div>
      </div>
      <div class="col-lg-6 col-md-12">
        <div class="form-group" style="margin-top: 14px;">
            <span><input type="checkbox" style="width: 20px;margin: 0;height: 20px;margin-top: 13px;position: relative;top: 4px;" name="sought_check" <?php if($rowDetailsArr['OPEN_FOR_OTHERS']=='Y') echo 'checked';?> disabled></span>
         <label for="email">Open to be contacted if further information is sought.</label>
     
        </div>
      </div>
      <!--Form Column End-->  
      <!--Form Column End-->  
     </div>
     <div class="section1bg">
      <!--heading Start-->  
      <div class="col-lg-12 col-12 formheading">DETAILS OF EVENT LEADING TO GRIEVANCE</div>
      <!--heading End-->      
      <!--Form Column Start-->
      <div class="col-lg-6 col-md-4 col-sm-4 col-6">
        <div class="form-group">
         <label for="email">DATE, TIME, AND LOCATION OF EVENT</label>
         <textarea type="text" class="form-control" readonly name="event_location" placeholder="Location of event. If you cannot remember the exact date, please enter the approximate date."><?php echo $rowDetailsArr['GRIEVANCE_DETAILS_HR'];?></textarea>
        </div>
      </div>
      <!--Form Column End--> 
      <!--Form Column Start-->
      <div class="col-lg-6 col-md-4 col-sm-4 col-6">
        <div class="form-group">
        <label for="email">WITNESSES if applicable</label>
        <textarea type="text" class="form-control" readonly name="event_location_Date" placeholder="Date & time location of event"><?php echo $rowDetailsArr['WITNESS_NAME_HR'];?></textarea>
        </div>
      </div>
      <!--Form Column End--> 
      <!--Form Column Start-->
      <div class="col-lg-6 col-md-6 col-sm-6 col-6">
        <div class="form-group">
         <label for="email">ACCOUNT OF EVENT</label>
         <textarea type="text" class="form-control" readonly name="event_account" placeholder="Provide a detailed account of the occurrence. 
Include the names of any additional persons involved."><?php echo $rowDetailsArr['ACCOUNT_OF_EVENT_HR'];?></textarea>
        </div>
      </div>
      <!--Form Column End--> 
      <!--Form Column Start-->
      <div class="col-lg-6 col-md-6 col-sm-6 col-6">
        <div class="form-group">
         <label for="email">VIOLATIONS</label>
         <textarea type="text" class="form-control" readonly name="violation" placeholder="Provide a list of any policies, procedures, or guidelines you believe have been violated in the event described."><?php echo $rowDetailsArr['VIOLATIONS_HR'];?></textarea>
        </div>
      </div>
      <!--Form Column End-->  
      <!--Form Column Start-->
      <div class="col-lg-6 col-md-6 col-sm-6 col-6">
        <div class="form-group">
         <label for="email">Attachment</label>
         <?php
         $fileArr=explode(",",$rowDetailsArr['GRIEVANCE_ATTACHMENT']);
         $sno=1;
         foreach($fileArr as $files)
         {
           $filePath="https://ytyhub.com/formsyty/upload/".$files;
           if($files!="")
           {
             ?>
              <a href="<?php echo $filePath;?>" class="indicatorbg" target="_blank">File <?php echo $sno++;?></a>
             <?php
           }
           else{
            echo "<span style='color:red'>&nbsp;-&nbsp;No file attached.</span>";
          }
        }
         ?>
        </div>
      </div>
      <!--Form Column End-->        
     </div>
     <div class="section1bg">
      <!--heading Start-->  
      <div class="col-lg-12 col-12 formheading">ADMINISTRATIVE SECTION</div>
      <!--heading End-->     
      <!--Form Column Start-->
      <div class="col-lg-12 col-md-4 col-sm-4 col-6">
        <div class="form-group">
         <label for="email">COMMENT</label>
         <textarea type="text" class="form-control" <?php if($rowDetailsArr['HANDLED_BY']!='' && $rowDetailsArr['ADDITIONAL_INFO']!='') echo "readonly"; else if($rowDetailsArr['HANDLED_BY']=='' && $rowDetailsArr['ADDITIONAL_INFO']!='') echo ""; else if($rowDetailsArr['RECEIVED_BY']!='') echo "readonly";?>  name="comment"  id="comment" placeholder=""><?php if(isset($_SESSION['global_comment']) && $_SESSION['global_comment']!='') echo $_SESSION['global_comment']; else echo $rowDetailsArr['ADMIN_COMMENT_GRV'];?></textarea>
        </div>
      </div> 
      <!--heading End-->   
      <!--Form Column Start-->
      <div class="col-lg-6 col-md-12 col-sm-12 col-6">
      <div class="form-group">
         <label for="email">CATEGORY<span>*</span></label>
          <select name="priority" id="priority" class="form-control" <?php if($rowDetailsArr['HANDLED_BY']!='' && $rowDetailsArr['ADDITIONAL_INFO']!='') echo "disabled"; else if($rowDetailsArr['HANDLED_BY']=='' && $rowDetailsArr['ADDITIONAL_INFO']!='') echo "";else if($rowDetailsArr['RECEIVED_BY']!='') echo "disabled";?> required onchange="return changeCategory(this.value)">
          <option value="">--Category--</option>
          <?php
            $queryProrty= "SELECT EMP_GRV_SRNO,EMP_GRV_CATEGORY FROM EMPLOYEE_GRIEVANCE_PRIORITY ORDER BY EMP_GRV_SRNO"; 
            $prirotyDets = oci_parse($dbcon, $queryProrty);
            oci_execute($prirotyDets);
            while($row=oci_fetch_array($prirotyDets))
            { 
           ?>
            <option value="<?php echo $row['EMP_GRV_CATEGORY']."_".$row['EMP_GRV_SRNO']?>" <?php if(isset($_SESSION['global_category']) && $_SESSION['global_category']!="") echo "selected"; else if(trim($rowDetailsArr['CATEGORY_GRV'])==trim($row['EMP_GRV_CATEGORY'])) echo "selected";?>><?php echo $row['EMP_GRV_CATEGORY']?></option>
            <?php
            }
            ?>
          </select>
        </div>
      </div>        
      <!--Form Column Start-->
       <div class="col-lg-6 col-md-12 col-sm-12 col-6 autodropdownlist">
        <div class="form-group">
         <label for="email">ASSIGN TO<span>*</span></label>
         <input type="text" style="text-transform: uppercase;" class="form-control" <?php if($rowDetailsArr['HANDLED_BY']!='' && $rowDetailsArr['ADDITIONAL_INFO']!='') echo "disabled"; else if($rowDetailsArr['HANDLED_BY']=='' && $rowDetailsArr['ADDITIONAL_INFO']!='') echo ""; else if($rowDetailsArr['RECEIVED_BY']!='') echo "readonly";?> value="<?php if(isset($_SESSION['global_ename']) && $_SESSION['global_ename']!="") echo $_SESSION['global_ename']; else if($rowDetailsArr['ASSIGN_TO']!="") echo $rowDetailsArr['ASSIGN_TO'];?>"  name="emp_id" required id="emp_id" autocomplete="off" onkeyup="return wating(this.value)" onchange="return checkCategory()">
         <input type="hidden" class="form-control"  name="assign_emp_id" required id="assign_emp_id" value="<?php if(isset($_SESSION['global_eid']) && $_SESSION['global_eid']!="") echo $_SESSION['global_eid'];?>">
         <input type="hidden" class="form-control"  name="update_assign_emp_id" required id="update_assign_emp_id" value="<?php echo $rowDetailsArr['ASSIGN_TO_EMPLOYEE_GRV'];?>">
         <input type="hidden" class="form-control"  name="to_email_id" required id="to_email_id">
        </div>
        <span id="empList"></span>
      </div>
      <!--Form Column End-->
        
    </div>
     <div class="section1bg">
      <!--heading Start-->  
      <div class="col-lg-12 col-12 formheading">CORRECTIVE ACTION</div>
      <!--heading End-->     
      <!--Form Column Start-->
      <div class="col-lg-6 col-md-4 col-sm-4 col-6">
        <div class="form-group">
         <label for="email">HANDLED BY PIC</label>
         <textarea type="text" class="form-control" readonly  name="team_handled" placeholder="Handled by Grievance Adminstrator Team"><?php echo $rowDetailsArr['HANDLED_BY'];?></textarea>
        </div>
      </div>      
      <!--Form Column End-->
      <!--Form Column Start-->
      <div class="col-lg-6 col-md-4 col-sm-4 col-6">
        <div class="form-group">
         <label for="email">ADDITIONAL INFO</label>
         <textarea type="text" class="form-control" readonly  name="addtion_info" placeholder="ADDITIONAL INFO"><?php echo $rowDetailsArr['ADDITIONAL_INFO'];?></textarea>
        </div>
      </div>      
      <!--Form Column End-->
      <div class="col-lg-6 col-md-6 col-sm-6 col-6">
        <div class="form-group">
         <label for="email">RECEIVED BY:  [PIC] NAME AND SIGNATURE</label>
         <input type="text" class="form-control" readonly value="<?php echo $rowDetailsArr['RECEIVED_BY'];?>" name="received_sign" placeholder="">
        </div>
      </div>      
      <!--Form Column End--> 
       <!--Form Column Start-->
      <div class="col-lg-6 col-md-6 col-sm-6 col-6">
        <div class="form-group">
         <label for="email">TARGET COMPLETION DATE</label>
          <input class="form-control" readonly name="date_2" value="<?php if($rowDetailsArr['RECEIVED_DATE']!="") echo date('d-M-Y',strtotime($rowDetailsArr['RECEIVED_DATE']));?>" placeholder="dd-MM-YYY" type="text" autocomplete="off"/>
        </div>
      </div>
      <!--Form Column End--> 
       <!--Form Column Start-->
      <div class="col-lg-6 col-md-12 col-sm-12 col-6">
        <div class="form-group">
         <label for="email">
         <strong class="indicatorbg" style="margin-left:0;">Open &nbsp; <strong class="open" style="margin-right:0;"></strong></strong>
         </label>        
        </div>
      </div> 
        <div class="col-lg-6 col-md-6 col-sm-6 col-6">
        <div class="form-group">
         <label for="email">Attachment(PIC)</label>
         <?php
         $filePath="https://ytyhub.com/formsyty/upload/".$rowDetailsArr['PIC_FILE_NAME'];
         //$filePath="upload/".$rowDetailsArr['PIC_FILE_NAME'];
         if($rowDetailsArr['PIC_FILE_NAME']!="")
         {
           ?>
            <a href="<?php echo $filePath;?>" class="indicatorbg" target="_blank">View File</a>
           <?php
         }
         else{
          echo "<span style='color:red'>&nbsp;-&nbsp;No file attached.</span>";
        }
         ?>
        </div>
      </div>
    </div>    
    <div class="section1bg"> 
      <!--Form Column End-->      
      <div class="col-lg-12 col-12 formheading">MANAGEMENT REVIEW SECTION</div>
       <div class="col-lg-6 col-md-12 col-sm-12 col-6">
        <div class="form-group">
         <label for="email">STATUS OF GRIEVANCE 
         <strong class="indicatorbg">Open <strong class="open"></strong> Close <strong class="close"></strong></strong>
         </label><br>
         <label class="switch">
         <input type="checkbox"  name="grievance_status" id="grievance_status" <?php if($rowDetailsArr['HANDLED_BY']=='' && $rowDetailsArr['ADDITIONAL_INFO']!='') echo "disabled"; elseif($rowDetailsArr['RECEIVED_BY']=='') echo "disabled"; elseif($rowDetailsArr['CLOSURE_ACTIONS_REMARK']!='') { echo "disabled "; }?> <?php if($rowDetailsArr['STATUS_OF_GRIEVANCE']=='1') echo 'checked';?>><div class="status_slider round"></div></label>       
        </div>
      </div> 
       <!--Form Column Start-->
      <div class="col-lg-6 col-md-12 col-sm-12 col-6" style="text-align: right;">
        <div class="form-group">
          <a href="javascript:void(0)" data-toggle="modal" data-target="#myModal" class="formbutton" onclick="return filldata()">Action items</a>
        </div>
      </div>      
      <!--Form Column End--> 
      <div class="col-lg-12 col-md-12 col-sm-12 col-6">
        <div class="form-group">
         <label for="email">Remark <span>*</span></label>
         <textarea type="text" class="form-control" <?php if($rowDetailsArr['HANDLED_BY']=='' && $rowDetailsArr['ADDITIONAL_INFO']!='') echo "disabled"; elseif($rowDetailsArr['RECEIVED_BY']=='') echo "disabled"; elseif($rowDetailsArr['CLOSURE_ACTIONS_REMARK']!='') { echo "disabled "; } ?> name="remark" id="remark" maxlength="3999" placeholder="Remark"><?php echo $rowDetailsArr['CLOSURE_ACTIONS_REMARK'];?></textarea>
        </div>
      </div>      
      <!--Form Column End-->     
      
       <!--Form Column Start-->
      <div class="col-lg-12 col-md-12 col-sm-12 col-6">
        <div class="form-group">
          <input type="hidden" name="cnd_handled_by" value="<?php echo $rowDetailsArr['HANDLED_BY'];?>" />
          <input type="hidden" name="cnd_addtional" value="<?php echo $rowDetailsArr['ADDITIONAL_INFO'];?>" />
         <button type="submit" class="formbutton" <?php if($rowDetailsArr['CLOSURE_ACTIONS_REMARK']!='') { echo "disabled "; echo 'style="color:#000"';}?> onclick="return submitForm();" id="btnLogin">Submit Form</button> 
         <button type="button" class="formbutton" id="btnLogin"><a href="http://ytyportal.ytygroup.my/formsyty/yty-grievance-moderator.php" style="color: #fff;text-decoration:none">Back</a></button>       
        </div>
      </div>      
      <!--Form Column End--> 
     </div> 
      </form>
     </div>  
  </div>
  <?php
    $query= "SELECT * FROM EMPLOYEE_GRIEVANCE_TASK  WHERE EMP_GRV_APPLICATION_ID='".$rowDetailsArr['APPLICATION_ID']."' ORDER BY SRNO"; 
    $tableDetails = oci_parse($dbcon, $query);
    //$rowDetailsArr=oci_fetch_array($tableDetails);
    //echo "<pre>";print_r($rowDetailsArr);
    ?>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>
  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog" style="width: 50%;">
      <!-- Modal content-->
      <div class="modal-content"  style="position: relative;right: 55%;border-radius: 5px !important;">
        <div class="modal-header" style="background-color: #0e4b80;color: #fff;border-radius: 5px;">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title" style="text-align: center;font-weight: bold">Action items For Application No-<?php echo $rowDetailsArr['APPLICATION_ID'];?></h4>
        </div>
        <div class="modal-body">
             <form  method="post" enctype="multipart/form-data" id="submit_form">
              <input type="hidden" name="app_id"  value="<?php echo $rowDetailsArr['APPLICATION_ID'];?>">
                <table class="table align-items-center table-flush">
                  <tr>
                     <td style="text-align: right;    padding-bottom: 30px;" colspan="2"><a href="javascript:void(0);" style="    position: relative; top: 13px; right: 5px;padding: 5px 8px;" class="formbutton addCF"><i class="fa fa-plus" aria-hidden="true"></i>
                </table>
                <table class="table align-items-center table-flush" id="customFields">
                <thead class="thead-light">
                    <tr>
                      <th style="width:1%">S.No.</th>
                      <th style="width:75%">Task Name</th>
                      <th style="width:16%">STATUS</th>
                      <th style="width:8%">&nbsp;</th>
                    </tr>
                </thead>
                <?php
                //$rowDetailsArr=oci_fetch_array($tableDetails);
                $rowFlag=0;
                $sno=1;
                if(oci_execute($tableDetails))
                {
                while ($row=oci_fetch_array($tableDetails)) {
                  $rowFlag=1;
                 ?>
                  <tr valign="top">
                    <td><?php echo $sno;?></td>
                    <td>
                      <textarea class="form-control" id="task_name" name="task_name[]"><?php echo $row['TASK_NAME'];?></textarea>
                    </td>
                    <td>
                     <select class="form-control" id="status" name="status[]"><option value="O" <?php if($row['TASK_STATUS']=='O') echo "selected";?>>Open</option><option value="C" <?php if($row['TASK_STATUS']=='C') echo "selected";?>>Closed</option></select>&nbsp;            
                    </td>
                    <td><a href="javascript:void(0);" style="margin-top: 29px;position: relative; top: 10px;padding: 5px 8px;" class="remCFR formbutton" id="<?php echo $sno;?>"><i class="fa fa-minus"></i></a></td>
                  </tr>            
                <?php
                  $sno++;
                }
                ?>
                <?php
                }
                if($rowFlag==0)
                { 
                ?>
                <tr valign="top">
                <td>1</td>
                <td>
                  <textarea class="form-control" id="task_name" name="task_name[]" value="" placeholder="Task Name"></textarea>
                </td>
                <td>
                 <select class="form-control" id="status" name="status[]"><option value="O">Open</option><option value="C">Closed</option></select>&nbsp;            
                </td>
                <td>&nbsp; </td>
                </tr>
                <tr valign="top">
                 <td>2</td>
                <td>
                  <textarea class="form-control" id="task_name" name="task_name[]" value="" placeholder="Task Name"></textarea>
                </td>
                <td>
                 <select class="form-control" id="status" name="status[]"><option value="O">Open</option><option value="C">Closed</option></select>&nbsp;            
                </td>
                <td>&nbsp; </td>
                </tr>
                <tr valign="top">
                 <td>3</td>
                <td>
                  <textarea class="form-control" id="task_name" name="task_name[]" value="" placeholder="Task Name"></textarea>
                </td>
                <td>
                 <select class="form-control" id="status" name="status[]"><option value="O">Open</option><option value="C">Closed</option></select>&nbsp;            
                </td>
                <td>&nbsp; </td>
                </tr>
                <tr valign="top">
                 <td>4</td>
                <td>
                  <textarea class="form-control" id="task_name" name="task_name[]" value="" placeholder="Task Name"></textarea>
                </td>
                <td>
                 <select class="form-control" id="status" name="status[]"><option value="O">Open</option><option value="C">Closed</option></select>&nbsp;            
                </td>
                <td>&nbsp; </td>
                </tr>
                <tr valign="top">
                 <td>5</td>
                <td>
                  <textarea class="form-control" id="task_name" name="task_name[]" value="" placeholder="Task Name"></textarea>
                </td>
                <td>
                 <select class="form-control" id="status" name="status[]"><option value="O">Open</option><option value="C">Closed</option></select>&nbsp;            
                </td>
                <td>&nbsp; </td>
                </tr>
                  <input type="hidden" name="counter" id="counter" value="5" />

                <?php
                }
                else
                {
                  ?>
                   <input type="hidden" name="counter" id="counter" value="<?php echo ($sno-1);?>" />
                   <?php
                }
                ?>
                </table>
                <table class="table align-items-center table-flush">
                <tr>
                <td style="text-align: right;">
                  <input type="hidden" name="global_comment" id="global_comment"  />
                  <input type="hidden" name="global_category" id="global_category"  />
                  <input type="hidden" name="global_ename" id="global_ename"  />
                  <input type="hidden" name="global_eid" id="global_eid"  />
                  <button type="button" class="formbutton" id="btnLogin" onclick="return saveTaskDetails()">Save</button></td>
                </tr>
                </table>
              </form>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
      
    </div>
  </div>
<script>
  $(document).ready(function(){
  $(".addCF").click(function(){
    var count=Number(document.getElementById('counter').value)+1;
    $("#customFields").append('<tr><td>'+count+'</td><td><textarea class="form-control" id="task_name" name="task_name[]"></textarea></td><td><select class="form-control" id="status" name="status[]"><option value="O">Open</option><option value="C">Closed</option></select></td><td><a href="javascript:void(0);" style="margin-top: 29px;position: relative; top: 10px;padding: 5px 8px;" class="remCF formbutton" id="'+count+'"><i class="fa fa-minus"></i></a></td></tr>');
      document.getElementById('counter').value=count;
  });
    $("#customFields").on('click','.remCF',function(){
        var presentRow=$(this).attr("id");
        var count=document.getElementById('counter').value;
        if(presentRow!=count)
        {
          alert('Please remove last row firstly.');
          return;
        }
        $(this).parent().parent().remove();
        document.getElementById('counter').value=Number(count)-1;
    });
      $("#customFields").on('click','.remCFR',function(){
      var presentRow=$(this).attr("id");
      var appId='<?php echo $rowDetailsArr['APPLICATION_ID'];?>';
      $(this).parent().parent().remove();
      $.ajax({
          url: 'deleteTask.php',
          type: 'post',
          data: {appId:appId,rowId:presentRow},
          dataType: 'json',
          success:function(response) {
            if(response)
            {
            }
          }
        });
      document.getElementById('counter').value=Number(document.getElementById('counter').value)-1;
    });
});


function saveTaskDetails()
{

  $.ajax({
  url: 'InsertUpdateTaskDetail.php',
  type: 'post',
  data: $('#submit_form').serialize(),
  dataType: 'json',
  success:function(response) {
    if(response)
    {
      //{
        window.location.reload(1);
      //}
      //else
      //{
        //document.getElementById(week+"_"+sr_no).innerHTML=remark;
        //$('#showModal_Remark').modal('hide'); 
        //return false;
      //}
    }
    //document.getElementById("show_remark").innerHTML=response;
  }
  });
}
  </script>
  <script>
    function wating(val)
  {
      var category=document.getElementById('priority').value;
      document.getElementById("empList").innerHTML='Loading please wait...';
      document.getElementById('btnLogin').disabled=true;
      $.ajax({
        url: "search_employee_category.php?term="+val+"&type=1&category="+category,
        type: 'get',
        dataType: 'json',
        success:function(response) {
          if(response!="")
          {
              document.getElementById('empList').innerHTML=response[0];
              document.getElementById('btnLogin').disabled=false;
          }
        }
        }); 
    //else
      //document.getElementById("loading").innerHTML='';
  }
  function checkCategory()
  {
    if(document.getElementById('priority').value=="")
      {
          alert('Please select category.');
          document.getElementById('emp_id').value="";
          document.getElementById("empList").innerHTML='';
          return false;
      }
  }
  function changeCategory(val)
  {
    document.getElementById('emp_id').value="";
    document.getElementById('assign_emp_id').value="";
  }
  function fillTextData(data)
  {
    var dataArr=data.split("_");
    $("#assign_emp_id").val(dataArr[0]);
    $("#emp_id").val(dataArr[2]);
    $("#to_email_id").val(dataArr[4]);
    document.getElementById("empList").innerHTML='';
  }
  function getEmployeeDetails(value)
  {
    document.getElementById('validationMsg').innerHTML='Alert !!';
    if(value!=""){
      $.ajax({
        url: "search_employee.php",
        type: 'get',
        data: { term:+val,type:+1}, 
        dataType: 'json',
        success:function(response) {
          if(response[1]==0)
          {
            document.getElementById("messagePara").innerHTML='Invalid Employee ID.';
            $("#txtUserid").val('');
            $("#txtUserid1").val('');
            //document.getElementById("loading").innerHTML='';
            $("#alertModel").modal('show');
          }
        }
        }); 
    }
  }
  function submitForm()
  {
    <?php
      $checkFlag="";
      if($rowDetailsArr['HANDLED_BY']!="")
        $checkFlag=1;
    ?>
    var checkAssignVal='<?php echo $checkFlag;?>';
    if(checkAssignVal!="")
    {
      var status=document.getElementById('grievance_status').checked;
      if(status==false)
      {
        alert('Please close the status of grievance.');
        return false;
      }
      var remark=document.getElementById('remark').value;
      if(remark=="")
      {
        alert('Please enter remark.');
        return false;
      }
    }
    if(document.getElementById('priority').value=="")
    {
        alert('Please select category.');
        return false;
    }
    if(document.getElementById('emp_id').value=="")
    {
        alert('Please enter assign to.');
        return false;
    }
    document.getElementById("btnLogin").style.color='#000 ';
    document.getElementById('btnLogin').innerHTML ="Processing please wait...";
    $('#btnLogin').attr('disabled',true);
    document.getElementById('formSubmit').submit();
  }
  function filldata()
  {
    document.getElementById('global_comment').value=document.getElementById('comment').value;
    document.getElementById('global_category').value=document.getElementById('priority').value;
    document.getElementById('global_ename').value=document.getElementById('emp_id').value;
    document.getElementById('global_eid').value=document.getElementById('assign_emp_id').value;
  }
  </script>
</body>
</html>
