<?php
include("dbConfig.php");
header('Content-type: application/json; charset=utf-8');

// Retrieve the employ_id parameter from the request
$employ_id = $_GET['employ_id'];

// Prepare the SQL query with the parameter
$sql="SELECT * FROM hr_question_tbl where employ_id='$employ_id' AND company_id!='' AND deleted='0'ORDER BY `hr_question_tbl`.`createdDate_timee` DESC ";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    $response = array();
    while ($row = $result->fetch_assoc()) {
        if($row['hr_question_type']=='ghyab'){$question_type = 'absence_question';}elseif($row['hr_question_type']=='hodor'){$question_type = 'emergency';}else{ $question_type = '';}
        /*if($row['hr_question_stat']!='waiting_employee_response'){
            $question_details = $row['employee_reply'];
        }elseif($row_cu['hr_question_stat']=='waiting_employee_response'){
            $question_details = 'waiting_employee_response';
        }else{
            $question_details = '';
        }*/
        if($row['hr_question_stat']=='waiting_employee_response'){
            $question_stat = 'waiting_employee_response';
        }elseif($row['hr_question_stat']=='Answered_by_the_employee'){
            $question_stat = 'Answered_by_the_employee';
        }elseif($row['hr_question_stat']=='Absence_was_approved'){
            $question_stat = 'Absence_was_approved';
        }elseif($row['hr_question_stat']=='Absence_was_rejected'){
            $question_stat = 'Absence_was_rejected';
        }else{
            $question_stat = '';
        }
       
        $sql_ico="SELECT * FROM hr_employ_attachments_tbl where employ_id='$employ_id' AND attach_type='219231' AND connect_id='".$row['hr_question_id']."' AND  stop='0' AND deleted='0' ";
                          $result_ico = $conn->query($sql_ico);
                           if ($result_ico->num_rows > 0) {
                            $row_ico = $result_ico->fetch_assoc();
                              $attach_link='https://www.marsalogistics.com/new/hr_marsa_system/ar/hr_files/'.$row_ico["attach_link"];  
                            }else{
                                $attach_link='';  
                            }
        $a[] = array(
            'success' => true,
            'question_stat' => $question_stat,
            'hr_question_id' => $row['hr_question_id'],
            'question_type' => $question_type,
            'hr_question_date' => $row['hr_question_date'],
            'employee_reply' => $row['employee_reply'],
            'attach_link' => $attach_link,
            'reason_of_reject' => $row['the_reason'],

            
        );
    }
    
    $response = [
        'success' => true,
        'data' => $a,
    ];
} else {
    $a = array();
    $response = [
        'success' => true,
        'msg' => "not found",
        'data' => $a,
    ];
}

echo json_encode($response, JSON_UNESCAPED_UNICODE);
?>