<?php

/***************************Use for developers and chnage it  *****************************/
//------------------------------- get user details -------------------
function getUserDetails($user_id)
{
    include('config.php');
    // echo "SELECT user_type,name, email, password, image,address, mobile,gender, active_flag, notification_status,createtime,approve_flag from user_master where user_id = $user_id";die;
    $check_data_all = $mysqli->prepare("SELECT user_type,l_name,name, email, password, image,address, mobile,gender, active_flag, notification_status,createtime,phone_code from user_master where user_id = ?");
    $check_data_all->bind_param("i", $user_id);
    $check_data_all->execute();
    $check_data_all->store_result();
    $check_data = $check_data_all->num_rows;  //0 1
    if ($check_data > 0) {
        $check_data_all->bind_result($user_type,$l_name,$name, $email, $password, $image, $address, $mobile, $gender, $active_flag, $notification_status, $createtime,$phone_code);
        $check_data_all->fetch();
        $user_arr = array('user_id' => $user_id, 'user_type' => $user_type,  'email' => $email, 'password' => $password, 'image' => $image, 'address' => $address, 'mobile' => $mobile, 'active_flag' => $active_flag, 'notification_status' => $notification_status, 'gender' => $gender, 'createtime' => $createtime,'l_name'=>$l_name,'phone_code'=>$phone_code,'name'=>$name);
    }
    if (empty($user_arr)) {
        $user_arr = "NA";
    }
    return $user_arr;
}

function getBankDetails123($user_id){ 
        include('config.php');
        // print_r($sub_category_id);exit();

          // echo "SELECT `category_name`, `image` FROM `category_master`  WHERE `user_id`=$user_id ";die;

        $check_data_all=$mysqli->prepare("SELECT `id`, `user_token_id`, `user_id`, `country`, `currency`, `user_routing`, `user_account`, `account_holder_name`, `account_holder_type`, `business_type`, `dob_day`, `dob_month`, `dob_year`, `first_name`, `last_name`, `email`, `mobile_num`, `bank_name`, `address_line_1`, `address_line_2`, `city`, `country_short`, `state`, `zip_code`, `date_in_strtime`, `global_ip_address`, `ssn_number`, `photo_fron_id`, `photo_back_id`, `additional_doc`, `default_status`, `createtime`, `updatetime` FROM `stripe_bank_master`  where delete_flag='0'and user_id=? order by id desc ");
        $check_data_all->bind_param("i",$user_id);
        $check_data_all->execute();
        $check_data_all->store_result();
        $check_data=$check_data_all->num_rows;  //0 1
        if($check_data > 0){
            $check_data_all->bind_result($id,$user_token_id,$user_id,$country,$currency,$user_routing,$user_account,$account_holder_name,$account_holder_type,$business_type,$dob_day,$dob_month,$dob_year,$first_name,$last_name,$email,$mobile_num,$bank_name,$address_line_1,$address_line_2,$city,$country_short,$state,$zip_code,$date_in_strtime,$global_ip_address,$ssn_number,$photo_fron_id,$photo_back_id,$additional_doc,$default_status,$createtime,$updatetime);
            $check_data_all->fetch();



            $user_arr=array('id'=>$id,'user_token_id'=>$user_token_id,'country'=>$country,'currency'=>$currency,'user_routing'=>$user_routing,'user_account'=>$user_account,'account_holder_name'=>$account_holder_name,'account_holder_type'=>$account_holder_type,'business_type'=>$business_type,'dob_day'=>$dob_day,'dob_month'=>$dob_month,'dob_year'=>$dob_year,'first_name'=>$first_name,'last_name'=>$last_name,'email'=>$email,'mobile_num'=>$mobile_num,'bank_name'=>$bank_name,'address_line_1'=>$address_line_1,'address_line_2'=>$address_line_2,'city'=>$city,'country_short'=>$country_short,'state'=>$state,'zip_code'=>$zip_code,'date_in_strtime'=>$date_in_strtime,'global_ip_address'=>$global_ip_address,'ssn_number'=>$ssn_number,'photo_fron_id'=>$photo_fron_id,'photo_back_id'=>$photo_back_id,'additional_doc'=>$additional_doc,'default_status'=>$default_status,'createtime'=>$createtime,'updatetime'=>$updatetime);
        }
        if(empty($user_arr)){
            $user_arr="NA";
        }
        return $user_arr;
    }










function getWebContent()
{
    include('config.php');
    $content_arr = array();
    $select_about = $mysqli->prepare("SELECT content_id, content_type,content FROM content_master where delete_flag='0'");
    $select_about->execute();
    $select_about->store_result();
    $select_about_all = $select_about->num_rows;
    if ($select_about_all > 0) {
        $select_about->bind_result($content_id, $content_type, $content);
        while ($select_about->fetch()) {
            $content_arr[] = array('content_id' => $content_id, 'content_type' => $content_type, 'content' => $content);
        }
    }
    if (empty($content_arr)) {
        $content_arr = 'NA';
    }
    // print_r($content_arr) ;die;
    return $content_arr;
}
function getUserPlayerId($user_id)
{
    include('config.php');
    $select_all = $mysqli->prepare("SELECT player_id from user_notification where user_id=?");
    $select_all->bind_param("i", $user_id);
    $select_all->execute();
    $select_all->store_result();
    $select = $select_all->num_rows;
    //echo "select===";print_r($select);die();
    if ($select > 0) {
        $select_all->bind_result($player_id);
        $select_all->fetch();
        //echo "select===";print_r($player_id);die();
        if ($player_id == '123456') {
            $player_id = 'no';
        }
    } else {
        $player_id = 'no';
    }
    return $player_id;
}

function getNotificationStatus($user_id)
{
    include('config.php');
    $select_all = $mysqli->prepare("SELECT user_id  from user_master where user_id=? and delete_flag =0 and notification_status=1 ");
    $select_all->bind_param("i", $user_id);
    $select_all->execute();
    $select_all->store_result();
    $select = $select_all->num_rows;
    if ($select > 0) {
        $notification = 'yes';
    } else {
        $notification = 'no';
    }
    // $notification='on';
    return $notification;
}

function InsertNotification($user_id, $other_user_id, $action, $action_id, $action_json, $title, $title_2, $title_3, $title_4, $message, $message_2, $message_3, $message_4)
{
    include('config.php');
    $read_status = '0';
    $delete_flag = '0';
    $updatetime = date("Y-m-d H:i:s");
    $createtime = date("Y-m-d H:i:s");
    $insert = $mysqli->prepare("INSERT into user_notification_message(user_id, other_user_id, action, action_id, action_json, title, title_2, title_3, title_4, message, message_2, message_3, message_4, read_status, delete_flag, createtime, updatetime) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
    $insert->bind_param('iisisssssssssssss', $user_id, $other_user_id, $action, $action_id, $action_json, $title, $title_2, $title_3, $title_4, $message, $message_2, $message_3, $message_4, $read_status, $delete_flag, $createtime, $updatetime);
    $insert->execute();
    $insert_check = $mysqli->affected_rows;
    if ($insert_check <= 0) {
        $status = 'no';
    } else {
        $status = 'yes';
    }

    return $status;
}
function getUserLanguageId($user_id)
{
    include('config.php');
    $select_all = $mysqli->prepare("SELECT language_id  from user_master where user_id=?");
    $select_all->bind_param("i", $user_id);
    $select_all->execute();
    $select_all->store_result();
    $select = $select_all->num_rows;
    if ($select > 0) {
        $select_all->bind_result($language_id);
        $select_all->fetch();
    } else {
        $language_id = 0;
    }
    $language_id    =    0;
    return $language_id;
}
//----------------------------- Notification all functions here -----------------------
function getNotificationArrSingle($user_id = '', $other_user_id = '', $action = '', $action_id = '', $title = '', $title_2 = '', $title_3 = '', $title_4 = '', $message = '', $message_2 = '', $message_3 = '', $message_4 = '', $action_data = '')
{
    $notification_arr = array();
    $action_json = json_encode($action_data);
    $insert_status        =    InsertNotification($user_id, $other_user_id, $action, $action_id, $action_json, $title, $title_2, $title_3, $title_4, $message, $message_2, $message_3, $message_4);
    if ($insert_status == 'yes') {
        $notification_status = getNotificationStatus($other_user_id);
        //echo "notification_status==".$notification_status;die();
        if ($notification_status == 'yes') {
            $player_id             =    getUserPlayerId($other_user_id);
            //echo "player_id==".$player_id;die();
            if ($player_id != 'no') {
                $language_id    =    getUserLanguageId($other_user_id);
                //echo $language_id;
                if ($language_id == 0) {
                    $notification_arr    =    array('player_id' => $player_id, 'title' => $title, 'message' => $message, 'action_json' => $action_data);
                    //	print_r($notification_arr);

                } else if ($language_id == 1) {
                    $notification_arr    =    array('player_id' => $player_id, 'title' => $title_2, 'message' => $message_2, 'action_json' => $action_data);
                } else if ($language_id == 2) {
                    $notification_arr    =    array('player_id' => $player_id, 'title' => $title_3, 'message' => $message_3, 'action_json' => $action_data);
                } else if ($language_id == 3) {
                    $notification_arr    =    array('player_id' => $player_id, 'title' => $title_4, 'message' => $message_4, 'action_json' => $action_data);
                }
                // print_r($notification_arr);
            }
        }
    }
    if (empty($notification_arr)) {
        $notification_arr    =    'NA';
    }
    return $notification_arr;
}
// function DeviceTokenStore_1_Signal($user_id, $device_type, $player_id)
// {
//     include("config.php");
//     $inserttime = date("Y-m-d H:i:s");
//     //---------------------------------- check device token -----------------------
//     $check_player_id_all = $mysqli->prepare("SELECT `player_id` FROM `user_notification` WHERE player_id=?");
//     $check_player_id_all->bind_param('s', $player_id);
//     $check_player_id_all->execute();
//     $check_player_id_all->store_result();
//     $check_player_id = $check_player_id_all->num_rows;
//     if ($check_player_id > 0) {
//         //-------------- delete all record of this player_id -----------------------
//         $delete_device_details = $mysqli->prepare("DELETE from user_notification where player_id=? or user_id=?");
//         $delete_device_details->bind_param('si', $player_id, $user_id);
//         $delete_device_details->execute();
//         $delete_device = $mysqli->affected_rows;
//         if ($delete_device <= 0) {
//             //--------------- 2nd attemp to deleet -------------------
//             $delete_device_details1 = $mysqli->prepare("DELETE from user_notification where player_id=? or user_id=?");
//             $delete_device_details1->bind_param('si', $player_id, $user_id);
//             $delete_device_details1->execute();
//             $delete_device1 = $mysqli->affected_rows;
//             if ($delete_device1 <= 0) {
//                 $result = "no";
//             } else {
//                 $insert_device_details = $mysqli->prepare("INSERT into user_notification (user_id, device_type, player_id, inserttime) values(?,?,?,?)");

//                 $insert_device_details->bind_param('isss', $user_id, $device_type, $player_id, $inserttime);

//                 $insert_device_details->execute();

//                 $insert_check = $mysqli->affected_rows;

//                 if ($insert_check > 0) {
//                     $result = "yes";
//                 } else {
//                     $result  = "no";
//                 } //insert else closed
//             } //insert else closed
//         } //insert else closed
//         else {
//             $insert_device_details = $mysqli->prepare("INSERT into user_notification (user_id, device_type, player_id, inserttime) values(?,?,?,?)");
//             $insert_device_details->bind_param('isss', $user_id, $device_type, $player_id, $inserttime);
//             $insert_device_details->execute();
//             $insert_check = $mysqli->affected_rows;
//             if ($insert_check > 0) {
//                 $result = "yes";
//             } else {
//                 $result  = "no";
//             } //insert else closed
//         }
//     } else {
//         //----------------------- check user_id ------------------------
//         $check_player_id_all = $mysqli->prepare("SELECT `user_id` FROM `user_notification` WHERE user_id=?");
//         $check_player_id_all->bind_param('i', $user_id);
//         $check_player_id_all->execute();
//         $check_player_id_all->store_result();
//         $check_player_id = $check_player_id_all->num_rows;
//         if ($check_player_id > 0) {
//             //-----------------delete all record of this player_id -----------------------
//             $delete_device_details = $mysqli->prepare("delete from user_notification where user_id=?");
//             $delete_device_details->bind_param('i', $user_id);
//             $delete_device_details->execute();
//             $delete_device = $mysqli->affected_rows;
//             if ($delete_device <= 0) {
//                 //--------------- 2nd attemp to deleet -------------------
//                 $delete_device_details1 = $mysqli->prepare("delete from user_notification where user_id=?");
//                 $delete_device_details1->bind_param('i',  $user_id);
//                 $delete_device_details1->execute();
//                 $delete_device1 = $mysqli->affected_rows;
//                 if ($delete_device1 <= 0) {
//                     $result = "no";
//                 } else {
//                     $insert_device_details = $mysqli->prepare("insert into user_notification (user_id, device_type, player_id, inserttime) values(?,?,?,?)");
//                     $insert_device_details->bind_param('isss', $user_id, $device_type, $player_id, $inserttime);
//                     $insert_device_details->execute();
//                     $insert_check = $mysqli->affected_rows;
//                     if ($insert_check > 0) {
//                         $result = "yes";
//                     } else {
//                         $result  = "no";
//                     } //insert else closed
//                 } //insert else closed
//             } //insert else closed
//             else {
//                 $insert_device_details = $mysqli->prepare("insert into user_notification (user_id, device_type, player_id, inserttime) values(?,?,?,?)");
//                 $insert_device_details->bind_param('isss', $user_id, $device_type, $player_id, $inserttime);
//                 $insert_device_details->execute();
//                 $insert_check = $mysqli->affected_rows;
//                 if ($insert_check > 0) {
//                     $result = "yes";
//                 } else {
//                     $result  = "no";
//                 } //insert else closed
//             }
//         } else {
//             //------------------------------ insert new record -------------------
//             $insert_device_details = $mysqli->prepare("insert into user_notification (user_id, device_type, player_id, inserttime) values(?,?,?,?)");
//             $insert_device_details->bind_param('isss', $user_id, $device_type, $player_id, $inserttime);
//             $insert_device_details->execute();
//             $insert_check = $mysqli->affected_rows;
//             if ($insert_check > 0) {
//                 $result = "yes";
//             } else {
//                 $result  = "no";
//             } //insert else closed
//         }
//     } //esle closed of delete
//     return $result;
// }

function getusercountdetail1()
{
    include('config.php');
    $check_data_all = $mysqli->prepare("SELECT count(user_id)  FROM `user_master` WHERE delete_flag=0 and user_type=1 AND profile_complete = 1 ");
    $check_data_all->execute();
    $check_data_all->store_result();
    $check_data = $check_data_all->num_rows;  //0 1
    if ($check_data > 0) {
        $check_data_all->bind_result($user_id);
        $check_data_all->fetch();
    }
    if (empty($user_id)) {
        $user_id = "0";
    }
    return $user_id;
}






  
    
function getcontactdetails()
{
    include('config.php');
    $check_data_all = $mysqli->prepare("SELECT count(contact_id)  FROM `contact_us_master` WHERE delete_flag=0");
    $check_data_all->execute();
    $check_data_all->store_result();
    $check_data = $check_data_all->num_rows;  //0 1
    if ($check_data > 0) {
        $check_data_all->bind_result($contactus_id);
        $check_data_all->fetch();
    }
    if (empty($contactus_id)) {
        $contactus_id = "0";
    }
    return $contactus_id;
}






function gettodaypostdetails()
{
    include('config.php');
    $todaydate = date('Y-m-d');
    $check_data_all = $mysqli->prepare("SELECT  count(post_id)  FROM `post_master` WHERE delete_flag=0 AND DATE(createtime) = ? ");
    $check_data_all->bind_param('s', $todaydate);
    $check_data_all->execute();
    $check_data_all->store_result();
    $check_data = $check_data_all->num_rows;  //0 1
    if ($check_data > 0) {
        $check_data_all->bind_result($post_id);
        $check_data_all->fetch();
    }
    if (empty($post_id)) {
        $post_id = "0";
    }
    return $post_id;
}





function getCountryName($country_id)
{
    include('config.php');
    if ($country_id != "") {
        $get_name = $mysqli->prepare("SELECT GROUP_CONCAT(country_name) FROM `country_master` WHERE `country_id` IN ($country_id)");
        // $get_name->bind_param("i", $key_skill_id);
        $get_name->execute();
        $get_name->store_result();
        $get_name_num = $get_name->num_rows;
        if ($get_name_num > 0) {
            $get_name->bind_result($country_name);
            $get_name->fetch();
        } else {
            $country_name = 'NA';
        }
        $mysqli->close();
        return $country_name;
    }
}



//-----------------new code start--------------------------------------------//





//---------------------new code starts----------------------------------//

function getCategoryName($category_id)
{
    include('config.php');
    if ($category_id != "") {
        $get_name = $mysqli->prepare("SELECT category_name FROM `category_master` WHERE `category_id` =?");
        $get_name->bind_param("i", $category_id);
        $get_name->execute();
        $get_name->store_result();
        $get_name_num = $get_name->num_rows;
        if ($get_name_num > 0) {
            $get_name->bind_result($item_category_name);
            $get_name->fetch();
        } else {
            $item_category_name = 'NA';
        }
        $mysqli->close();
        return $item_category_name;
    }
}


function getUserName($user_id)
{
    include('config.php');
    // print_r($user_id);exit();
    $check_data_all = $mysqli->prepare("SELECT name from user_master where user_id = ? and user_type=1");
    $check_data_all->bind_param("i", $user_id);
    $check_data_all->execute();
    $check_data_all->store_result();
    $check_data = $check_data_all->num_rows;  //0 1
    if ($check_data > 0) {
        $check_data_all->bind_result($name);
        $check_data_all->fetch();
        $user_arr = array('user_id' => $user_id, 'name' => $name);
    }
    if (empty($user_arr)) {
        $user_arr = "NA";
    }
    return $user_arr;
}



function getUserImage($user_id)
{
    include('config.php');
    // print_r($user_id);exit();
    $check_data_all = $mysqli->prepare("SELECT user_image_id,image from user_image_master where user_id = ? and delete_flag =0");
    $check_data_all->bind_param("i", $user_id);
    $check_data_all->execute();
    $check_data_all->store_result();
    $check_data = $check_data_all->num_rows;  //0 1
    if ($check_data > 0) {
        $check_data_all->bind_result($user_image_id,$image);
        while($check_data_all->fetch()){
          $user_arr[] = array('image' => $image,'user_image_id'=>$user_image_id);  
        }
        
    }
    if (empty($user_arr)) {
        $user_arr = "NA";
    }
    return $user_arr;
}

function getCountryCode($country_id)
{
    include('config.php');
    if ($country_id != "") {
        $get_name = $mysqli->prepare("SELECT GROUP_CONCAT(country_name) FROM `country_master` WHERE `country_id` IN ($country_id)");
        // $get_name->bind_param("i", $key_skill_id);
        $get_name->execute();
        $get_name->store_result();
        $get_name_num = $get_name->num_rows;
        if ($get_name_num > 0) {
            $get_name->bind_result($country_name);
            $get_name->fetch();
        } else {
            $country_name = 'NA';
        }
        $mysqli->close();
        return $country_name;
    }
}

function getTodayEarnings(){
    include('config.php');
    $todaydate = date('Y-m-d');
    // echo "SELECT count(job_id)  FROM `job_master` WHERE delete_flag=0";die;
    $check_data_all=$mysqli->prepare("SELECT SUM(admin_earning)  FROM `trip_tip_master` WHERE delete_flag=0 AND DATE(createtime) = ? ");
    $check_data_all->bind_param('s',$todaydate);
    $check_data_all->execute();
    $check_data_all->store_result();
    $check_data=$check_data_all->num_rows;  //0 1
    if($check_data > 0){
        $check_data_all->bind_result($job_id);
        $check_data_all->fetch();
    }
    if(empty($job_id)){
        $job_id="0";
    }
    return $job_id;
}


function getTotalEarnings(){
    include('config.php');
   
    // echo "SELECT count(job_id)  FROM `job_master` WHERE delete_flag=0";die;
    $check_data_all=$mysqli->prepare("SELECT SUM(admin_earning)  FROM `trip_tip_master` WHERE delete_flag=0  ");
    //$check_data_all->bind_param('s',$todaydate);
    $check_data_all->execute();
    $check_data_all->store_result();
    $check_data=$check_data_all->num_rows;  //0 1
    if($check_data > 0){
        $check_data_all->bind_result($job_id);
        $check_data_all->fetch();
    }
    if(empty($job_id)){
        $job_id="0";
    }
    return $job_id;
}



function getRole($role_id)
{
    include('config.php');
    $select_all = $mysqli->prepare("SELECT role  from user_role_master where user_role_id=?");
    $select_all->bind_param("i", $role_id);
    $select_all->execute();
    $select_all->store_result();
    $select = $select_all->num_rows;
    if ($select > 0) {
        $select_all->bind_result($role);
        $select_all->fetch();
    } else {
        $role = 'NA';
    }
   
    return $role;
}

function gettotalCategory()
{
    include('config.php');
    $todaydate = date('Y-m-d');
    $check_data_all = $mysqli->prepare("SELECT  count(category_id)  FROM `category_master` WHERE delete_flag=0 ");
    //$check_data_all->bind_param('s', $todaydate);
    $check_data_all->execute();
    $check_data_all->store_result();
    $check_data = $check_data_all->num_rows;  //0 1
    if ($check_data > 0) {
        $check_data_all->bind_result($post_id);
        $check_data_all->fetch();
    }
    if (empty($post_id)) {
        $post_id = "0";
    }
    return $post_id;
}


function getEquipmentNameall($equipment_id)
{
    include('config.php');
    if ($equipment_id != "") {
        $get_name = $mysqli->prepare("SELECT equipment_name FROM `equipment_master` WHERE `equipment_id` =?");
        $get_name->bind_param("i", $equipment_id);
        $get_name->execute();
        $get_name->store_result();
        $get_name_num = $get_name->num_rows;
        if ($get_name_num > 0) {
            $get_name->bind_result($equipment_name);
            $get_name->fetch();
        } else {
            $equipment_name = 'NA';
        }
        $mysqli->close();
        return $equipment_name;
    }
}


function getInspectionTypeName($inspection_type_id)
{
    include('config.php');
    if ($inspection_type_id != "") {
        $get_name = $mysqli->prepare("SELECT inspection_type FROM `inspection_type_master` WHERE `inspection_type_id` =?");
        $get_name->bind_param("i", $inspection_type_id);
        $get_name->execute();
        $get_name->store_result();
        $get_name_num = $get_name->num_rows;
        if ($get_name_num > 0) {
            $get_name->bind_result($equipment_name);
            $get_name->fetch();
        } else {
            $equipment_name = 'NA';
        }
        $mysqli->close();
        return $equipment_name;
    }
}


function getInspectionDueDate($inspection_id)
{
    include('config.php');

    //echo "SELECT sub_service_id,sub_service_name FROM `sub_service_master` WHERE `sub_service_id`=$sub_service_id";die;

    $get_name = $mysqli->prepare("SELECT `next_inspection_date_id`,  `next_inspection_date` FROM `next_inspection_date_master` WHERE `inspection_id`=? and delete_flag =0");
    $get_name->bind_param("i", $inspection_id);
    $get_name->execute();
    $get_name->store_result();
    $get_name_num = $get_name->num_rows;
    if ($get_name > 0) {
        $get_name->bind_result($next_inspection_date_id,$next_inspection_date);
        while ($get_name->fetch()) {
            $question_name_arr[] = array('next_inspection_date_id' => $next_inspection_date_id, 'next_inspection_date' => $next_inspection_date);
            }
    if (empty($question_name_arr)) {
        $question_name_arr = "NA";
    }
    return $question_name_arr;
}
}


function getAllInspectionDueDate($inspection_id)
{
    include('config.php');
    if ($inspection_id != "") {
        $get_name = $mysqli->prepare("SELECT GROUP_CONCAT(next_inspection_date) FROM `next_inspection_date_master` WHERE `inspection_id`=?");
         $get_name->bind_param("i", $inspection_id);
        $get_name->execute();
        $get_name->store_result();
        $get_name_num = $get_name->num_rows;
        if ($get_name_num > 0) {
            $get_name->bind_result($country_name);
            $get_name->fetch();
        } else {
            $country_name = 'NA';
        }
        $mysqli->close();
        return $country_name;
    }
}



function getEquipmentComponent($equipment_id)
{
    include('config.php');
    if ($equipment_id != "") {
        $get_name = $mysqli->prepare("SELECT GROUP_CONCAT(component) FROM `equipment_component_master` WHERE `equipment_id`=? and delete_flag =0");
         $get_name->bind_param("i", $equipment_id);
        $get_name->execute();
        $get_name->store_result();
        $get_name_num = $get_name->num_rows;
        if ($get_name_num > 0) {
            $get_name->bind_result($country_name);
            $get_name->fetch();
        } else {
            $country_name = 'NA';
        }
        $mysqli->close();
        return $country_name;
    }
}


function getCmpData($equipment_id)
{
    include('config.php');

    //echo "SELECT sub_service_id,sub_service_name FROM `sub_service_master` WHERE `sub_service_id`=$sub_service_id";die;

    $get_name = $mysqli->prepare("SELECT equipment_component_id,component FROM `equipment_component_master` WHERE `equipment_id`=? and delete_flag =0");
    $get_name->bind_param("i", $equipment_id);
    $get_name->execute();
    $get_name->store_result();
    $get_name_num = $get_name->num_rows;
    if ($get_name > 0) {
        $get_name->bind_result($equipment_component_id,$component);
        while ($get_name->fetch()) {
            $category_name_arr[] = array('equipment_component_id' => $equipment_component_id, 'component' => $component);
            }
    if (empty($category_name_arr)) {
        $category_name_arr = "NA";
    }
    return $category_name_arr;
}
}


function getAttachment($equipment_id)
{
    include('config.php');

    //echo "SELECT sub_service_id,sub_service_name FROM `sub_service_master` WHERE `sub_service_id`=$sub_service_id";die;

    $get_name = $mysqli->prepare("SELECT equipment_attachment_id,attachment FROM `equipment_attachment_master` WHERE `equipment_id`=? and delete_flag =0");
    $get_name->bind_param("i", $equipment_id);
    $get_name->execute();
    $get_name->store_result();
    $get_name_num = $get_name->num_rows;
    if ($get_name > 0) {
        $get_name->bind_result($equipment_attachment_id,$attachment);
        while ($get_name->fetch()) {
            $category_name_arr[] = array('equipment_attachment_id' => $equipment_attachment_id, 'attachment' => $attachment);
            }
    if (empty($category_name_arr)) {
        $category_name_arr = "NA";
    }
    return $category_name_arr;
}
}


function getAllInspectionHistoryDueDate($inspection_id)
{
    include('config.php');
    if ($inspection_id != "") {
        $get_name = $mysqli->prepare("SELECT GROUP_CONCAT(next_inspection_date) FROM `request_next_inspection_date_master` WHERE `inspection_request_id`=?");
         $get_name->bind_param("i", $inspection_id);
        $get_name->execute();
        $get_name->store_result();
        $get_name_num = $get_name->num_rows;
        if ($get_name_num > 0) {
            $get_name->bind_result($country_name);
            $get_name->fetch();
        } else {
            $country_name = 'NA';
        }
        $mysqli->close();
        return $country_name;
    }
}


function getAllInspectionHistoryImage($inspection_request_id)
{
    include('config.php');
    // print_r($user_id);exit();
    $check_data_all = $mysqli->prepare("SELECT inspection_request_image_id,image from inspection_request_image_master where inspection_request_id = ? and delete_flag =0");
    $check_data_all->bind_param("i", $inspection_request_id);
    $check_data_all->execute();
    $check_data_all->store_result();
    $check_data = $check_data_all->num_rows;  //0 1
    if ($check_data > 0) {
        $check_data_all->bind_result($inspection_request_image_id,$image);
        while($check_data_all->fetch()){
          $user_arr[] = array('image' => $image,'inspection_request_image_id'=>$inspection_request_image_id);  
        }
        
    }
    if (empty($user_arr)) {
        $user_arr = "NA";
    }
    return $user_arr;
}

function getInspectiondetails($inspection_id)
{
    include('config.php');
    $user_arr=array();
    // print_r($user_id);exit();
    // echo "SELECT  `inspection_id`,`user_id`, `equipment_type_id`,`equipment_id`, `inspection_type_id`, `inspection_title`, `inspection_date`,`description`, `createtime` FROM `inspection_master` where inspection_id = $inspection_id and delete_flag =0";die;
    $check_data_all = $mysqli->prepare("SELECT  `inspection_id`,`user_id`, `equipment_type_id`,`equipment_id`, `inspection_type_id`, `inspection_title`, `inspection_date`,`description`, `createtime` FROM `inspection_master` where inspection_id = ? and delete_flag =0");
    $check_data_all->bind_param("i", $inspection_id);
    $check_data_all->execute();
    $check_data_all->store_result();
    $check_data = $check_data_all->num_rows;  //0 1
    if ($check_data > 0) {
        $check_data_all->bind_result($inspection_id,$user_id,$equipment_type_id,$equipment_id,$inspection_type_id,$inspection_title,$inspection_date,$description,$createtime);
        $check_data_all->fetch();
          $user_arr = array('inspection_id'=>$inspection_id,'user_id'=>$user_id,'equipment_type_id'=>$equipment_type_id,'equipment_id'=>$equipment_id,'inspection_type_id'=>$inspection_type_id,'inspection_title'=>$inspection_title,'inspection_date'=>$inspection_date,'description'=>$description,'createtime'=>$createtime);  
        
        
    }
    if (empty($user_arr)) {
        $user_arr = "NA";
    }
    return $user_arr;
}

?>








