<?php
include("dbConfig.php");
header('Content-type: application/json; charset=utf-8');
$company_id=$_GET["company_id"];
$sql_top="SELECT * FROM waseet_company_user_tbl where stop='0' AND deleted='0' AND company_id='$company_id'AND user_type='Top_Manager' ";
                   $result_top = $conn->query($sql_top);
                   if ($result_top->num_rows > 0) {
                   while($row_top = $result_top->fetch_assoc()) {
                    $user_id_top_manager=$row_top['user_id'];
}}
    $sql_com1="SELECT * FROM hr_request_type_main_tbl where request_type_id!='659762' and user_id_top_manager ='$user_id_top_manager'  AND deleted='0' ORDER BY `hr_request_type_main_tbl`.`id` ASC ";            
     $result_com1 = $conn->query($sql_com1);
                        if ($result_com1->num_rows > 0) {
                        while($row_com1 = $result_com1->fetch_assoc()) {
                            $b = []; 
                            //
                            $sql_op="SELECT * FROM hr_request_type_main_options_tbl where request_type_id='".$row_com1["request_type_id"]."' AND stop='0' AND deleted='0' ";
                            $result_op = $conn->query($sql_op);
                            if ($result_op->num_rows > 0) {
                             while($row_op = $result_op->fetch_assoc()) {
                                if($row_op["value_type"]=="file"){
                                   $files[] = $row_op["options_id"];
                                }
                                $sql_op2="SELECT * FROM hr_request_option_update_tbl where update_options_id='".$row_op['update_options_id']."' AND stop='0' AND deleted='0' ";
                                $result_op2 = $conn->query($sql_op2);
                                if ($result_op2->num_rows > 0) {
                                 while($row_op2 = $result_op2->fetch_assoc()) {      
                                 $option_name_ar=$row_op2['option_name_ar'];
                                 $option_name_en=$row_op2['option_name_en'];
                                 }}
                                 $b[] = array(
                                    'option_name_ar' => $option_name_ar,
                                    'option_name_en' => $option_name_en,
                                    'options_id' => $row_op["options_id"],
                                    'update_options_id' => $row_op["update_options_id"],
                                    'value_type' => $row_op["value_type"],
                                    'required_type' => $row_op["required_type"],
                                    'value_type_checkif' => $row_op["value_type_checkif"],
                                    
                                );
                             }
                             
                            }else{
                                $b = array();
                                $response = [
                                    'success' => true,
                                    'msg' => "not found",
                                    'data' => $b,
                                ];
                            }
                            //
                            $a[] = array(
                                'success' => true,
                                'request_type_id' => $row_com1["request_type_id"],
                                'type_name_ar' => $row_com1["type_name_ar"],
                                'type_name_en' => $row_com1["type_name_en"],
                                'option' => $b,
                                 
                                
                                
                            );
                        }
                        $response = [
                            'success' => true,
                            'data' => $a,
                            'files' => $files,
                           
                        ];
                    }else{
                        $a = array();
                        $response = [
                            'success' => true,
                            'msg' => "not found",
                            'data' => $a,
                        ];
                    }
                    echo json_encode($response, JSON_UNESCAPED_UNICODE);
                    ?>	