403Webshell
Server IP : 103.234.187.230  /  Your IP : 216.73.216.216
Web Server : Apache
System : Linux lserver42043-ind.megavelocity.net 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/b2bzend/library/Helper/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/b2bzend/library/Helper/Hotel.php
<?php

class Zend_Controller_Action_Helper_Hotel extends Zend_Controller_Action_Helper_Abstract
{

    public function getRoomTypes()
    {
        $objHotelRooms = new Travel_Model_TblHotelRooms();
        return $objHotelRooms->getRoomTypes();
    }

    public function getMealTypes()
    {
        $objHotelMeals = new Travel_Model_TblHotelMeals();
        return $objHotelMeals->getMealTypes();
    }

    public function getMealName($MealTypeId)
    {
        $objHotelMeals = new Travel_Model_TblHotelMeals();
        return $objHotelMeals->getMealName($MealTypeId);
    }

    public function getRoomAmenities($intLoggedinUserAgencySysId = '')
    {
        $objHotelRooms = new Travel_Model_TblHotelRooms();
        return $objHotelRooms->getRoomAmenities($intLoggedinUserAgencySysId);
    }

    public function getStarRatings()
    {
        return array('1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '0' => 'No Star');
    }

    public function getProprtyType()
    {
        return array('1' => 'Hotel', '2' => 'Camp/Tent', '3' => 'Resort', '4' => 'Apartment', '5' => 'Cottage', '6' => 'Heritage Hotel', '7' => 'Castle', '8' => 'House Boat', '9' => 'Motel', '10' => 'Lodge', '11' => 'Villa', '12' => 'Villa', 13 => 'Cruise');
    }

    public function getMealType()
    {
        return array('9' => 'EP', '6' => 'CP', '7' => 'MAP', '8' => 'AP');
    }

    public function getAroundProprty()
    {
        return array(
            '1' => 'Bus Stand',
            '2' => 'Domestic Airport',
            '3' => 'International Airport',
            '4' => 'Train Station',
            '5' => 'Beach Location',
            '6' => 'Police Station',
            '7' => 'Shopping Mall',
            '8' => 'PVR Cinemas'
        );
    }

    public function getWeekend()
    {
        return array(
            'Mon' => 'Monday',
            'Tue' => 'Tuesday',
            'Wed' => 'Wednesday',
            'Thu' => 'Thursday',
            'Fri' => 'Friday',
            'Sat' => 'Saturday',
            'Sun' => 'Sunday'
        );
    }

    public function getRoomTypeWhere($roomType)
    {
        $objHotelRooms = new Travel_Model_TblHotelRooms();
        $res = $objHotelRooms->getRoomType($roomType);
        foreach ($res as $val) {
            echo $val['Title'];
        }
    }

    public function getRoomTypeWhereRate($roomType)
    {
        $objHotelRooms = new Travel_Model_TblHotelRooms();
        $res = $objHotelRooms->getRoomType($roomType);
        foreach ($res as $val) {
            return $val['Title'];
        }
    }

    // Added By Pardeep Panchal Starts Here..
    // getting HotelAmenities Icons By Mapping the Masking.....
    public function getAmenitiesMasking($suppliedMasking, $arrAmenites = array())
    {

        //        $objAmenities = new Travel_Model_TblAmenities();
        //        $arrAmenites = $objAmenities->getAminitiesList();
        $suppliedMasking = !empty($suppliedMasking) ? ltrim($suppliedMasking, "1") : '00000000000000000';
        if (!empty($suppliedMasking)) {
            $arrSuppliedMasking = str_split($suppliedMasking);
            if (count($arrSuppliedMasking) > 0) {
                $arrFinalMaskingIcons = array();

                foreach ($arrSuppliedMasking as $key => $maskValue) {
                    if ($maskValue == 1) {
                        $arrFinalMaskingIcons[$arrAmenites[$key]['Title']] = $arrAmenites[$key]['Icon'];
                    } else {
                        $arrFinalMaskingIcons[$arrAmenites[$key]['Title']] = $arrAmenites[$key]['GreyIcon'];
                    }
                }
            }
        }

        return $arrFinalMaskingIcons;
    }

    public function getAccomdationImages($intGTXCityId)
    {
        $objBuyHotel = new Travel_Model_TblBuyHotel();
        $result = $objBuyHotel->getAccomdationImages($intGTXCityId);
        $arrAccomdationImages = array();
        if (count($result) > 0) {
            $arrAccomdationImages = array();

            for ($i = 0; $i < count($result); $i++) {
                $strHotelCode = trim($result[$i]['HotelCode']);
                if (!in_array($strHotelCode, $arrAccomdationImages)) {
                    $arrImages = array();
                    for ($j = 0; $j < count($result); $j++) {
                        if ($strHotelCode == trim($result[$j]['HotelCode'])) {
                            $arrImages[] = trim($result[$j]['Details']);
                        }
                    }
                    $arrAccomdationImages[$strHotelCode] = $arrImages;
                }
            }
        }
        return $arrAccomdationImages;
    }

    public function searchApiHotels($arrSessionData = array())
    {

        // Common Variables To All Api Calls........
        $strCheckInDate = $arrSessionData['hotelFromDateSession'];
        $strCheckOutDate = $arrSessionData['hotelToDateSession'];
        $intNoOfNights = $arrSessionData['hotelTotalNights'];
        $strselectNationality = $arrSessionData['selectNationality'];
        $strcountryCode = $arrSessionData['countryCode'];
        $strHotelCityTitle = $arrSessionData['hotelCityTitle'];
        $intGTXCityId = $arrSessionData['hotelXrefCityId'];
        $intHotelCityId = $arrSessionData['hidden_selected_hotel_id'];
        $intNoOfRooms = $arrSessionData['hotelTotalRooms'];
        $intNoOfAdults = (int) $arrSessionData['totalMemberCount']['AdultPax'];
        $intNoOfChild = (int) $arrSessionData['totalMemberCount']['ChildPax'];
        $intTotalPaxCount = $arrSessionData['totalMemberCount']['AdultPax'] + $arrSessionData['totalMemberCount']['ChildPax'];
        $intChildAge = $arrSessionData['totalMemberCount']['ChildsAge'];
        $memberDetails = $arrSessionData['memberDetails'];
        $intMaxRating = $arrSessionData['hotelStarRating'];
        $intMinRating = $arrSessionData['hotelStarRating'];
        $tokenId = Zend_Controller_Action_HelperBroker::getStaticHelper('Flight')->authenticateAPI();


        //echo $tokenId; exit;
        $arrSearchResults = array();
        // getting APICity Id..
        // 
        // For GRN Hotel Api Call Starts.....
        $apiGrnIsActive = true;
        $GRN_I = 0;
        if ($apiGrnIsActive == true) {




            // getting APICity Id...
            $objCity = new Travel_Model_TblCity();
            $objCity->intGTXCityId = $intGTXCityId;
            $objCity->intICSourceSysId = '4';
            $strApiCityId = $objCity->getApiCityDetails();
            if (empty($strApiCityId)) {
                //            $arrSearchResults = array(); 
                //            $arrSearchResults['HotelSearchResult']['ResponseStatus']    = '0';
                //            $arrSearchResults['HotelSearchResult']['ErrorCode']         = '';
                //            $arrSearchResults['HotelSearchResult']['ErrorMessage']      = 'City id missing';
                //            return $arrSearchResults;
                //            exit;
            }






            /* Getting Members Details */
            $arrMemberDetails = array();
            if (count($memberDetails) > 0) {
                for ($i = 0; $i < count($memberDetails); $i++) {
                    $arrMemberDetails[$i]['adults'] = $memberDetails[$i]['AdultPax'];
                    //$arrMemberDetails[$i]['NoOfChild'] = $memberDetails[$i]['ChildPax'];
                    if ($memberDetails[$i]['ChildPax'] > 0) {
                        $arrChildAge = explode(",", $memberDetails[$i]['ChildsAge']);
                        $arrMemberDetails[$i]['children_ages'] = $arrChildAge;
                    }
                }
            }
            /* Getting Members Details */

            $arrCheckInDateGRN = explode("/", $strCheckInDate);
            if (count($arrCheckInDateGRN) > 0) {
                $strCheckInDateGRN = $arrCheckInDateGRN[2] . "-" . $arrCheckInDateGRN[1] . "-" . $arrCheckInDateGRN[0];
            }

            $arrCheckOutDateGRN = explode("/", $strCheckOutDate);
            if (count($arrCheckInDateGRN) > 0) {
                $strCheckOutDateGRN = $arrCheckOutDateGRN[2] . "-" . $arrCheckOutDateGRN[1] . "-" . $arrCheckOutDateGRN[0];
            }

            if ($intMaxRating > 5) {
                $arrHotelRating = array(2, $intMaxRating); // Acco. to Doc.. minimum = 2 & maximum = 7 
            } else {
                $arrHotelRating = array($intMaxRating);
            }

            $datah = array(
                "destination_code" => $strApiCityId,
                "checkin" => $strCheckInDateGRN,
                "checkout" => $strCheckOutDateGRN,
                "client_nationality" => $strselectNationality,
                "response" => "fast",
                "currency" => "INR",
                "rates" => "concise", //comprehensive //comprehensive
                "hotel_category" => $arrHotelRating,
                "rooms" => $arrMemberDetails
            );
            //echo "<pre>";print_r($datah);exit;

            $data_stringh = json_encode($datah);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, GRN_HOTEL_API_SEARCH_URL);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Accept: application/json',
                'Content-Type: application/json',
                'api-key: ' . GRN_HOTEL_API_KEY
            ));
            $outputH = curl_exec($ch);
            $responseGRN = json_decode($outputH, true);

            //Write Request Logs starts...
            //                $strFilePath = "apihotels/search/".$tokenId."_search_request.json";
            //                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath,$data_stringh);
            //Write Request Logs starts...
            //Write Request Logs starts...
            //                $strFilePath = "apihotels/search/".$tokenId."_search_response.json";
            //                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath,$outputH);
            //Write Request Logs starts...
            //            echo "<pre>";
            //            print_r($responseGRN);
            //            exit;
            $arrHotelResultsGRN = array();
            $arrHotelResultsGRN = (isset($responseGRN['hotels']) && !empty($responseGRN['hotels'])) ? $responseGRN['hotels'] : '';

            $GRN_I = 0;
            if (count($arrHotelResultsGRN) > 0 && !empty($responseGRN['hotels'])) {

                $arrSearchResults['HotelSearchResult']['ResponseStatus'] = '1';
                $arrSearchResults['HotelSearchResult']['ErrorMessage'] = '';
                $arrSearchResults['HotelSearchResult']['ErrorCode'] = '0';

                //                    echo "<pre>";
                //                    print_R($arrHotelResultsGRN);
                //                    exit;
                $arrHotelFacilities = array();
                foreach ($arrHotelResultsGRN as $resValueGRN) {


                    $arrHotelFacilities = isset($resValueGRN['facilities']) ? explode(";", $resValueGRN['facilities']) : array();

                    //                    echo "<pre>";
                    //                    print_R($arrHotelFacilities);
                    //                    exit;

                    if (count($arrHotelFacilities) > 0) {
                        $strAmenitiesMasking = Zend_Controller_Action_HelperBroker::getStaticHelper('Masking')->createHotelAmenitiesMasking($arrHotelFacilities);
                    }



                    $arrSearchResults['Hotels'][$GRN_I]['ApiSourceSysId'] = '4';
                    $arrSearchResults['Hotels'][$GRN_I]['TraceId'] = $responseGRN['search_id'];
                    $arrSearchResults['Hotels'][$GRN_I]['TokenId'] = $tokenId;
                    $arrSearchResults['Hotels'][$GRN_I]['APICityId'] = $resValueGRN['city_code'];
                    $arrSearchResults['Hotels'][$GRN_I]['HotelCode'] = $resValueGRN['hotel_code'];
                    $arrSearchResults['Hotels'][$GRN_I]['HotelName'] = $resValueGRN['name'];
                    $arrSearchResults['Hotels'][$GRN_I]['ResultIndex'] = '';
                    if (!empty($resValueGRN['images']['main_image'])) {
                        $arrSearchResults['Hotels'][$GRN_I]['HotelPicture'] = GRN_HOTEL_IMAGES_CDN_URL . "/" . $resValueGRN['images']['main_image'];
                    } else {
                        $arrSearchResults['Hotels'][$GRN_I]['HotelPicture'] = "";
                    }
                    $arrSearchResults['Hotels'][$GRN_I]['StarRating'] = $resValueGRN['category'];
                    $arrSearchResults['Hotels'][$GRN_I]['AgencyRating'] = '0';
                    $arrSearchResults['Hotels'][$GRN_I]['AwardRecognizations'] = '';
                    $arrSearchResults['Hotels'][$GRN_I]['AwardURL'] = '';
                    $arrSearchResults['Hotels'][$GRN_I]['AccoAminitiesMask'] = !empty($strAmenitiesMasking) ? $strAmenitiesMasking : '';
                    $arrSearchResults['Hotels'][$GRN_I]['HotelDescription'] = $resValueGRN['description'];
                    $arrSearchResults['Hotels'][$GRN_I]['PublishedPrice'] = $resValueGRN['min_rate']['price']; // //comprehensive $resValueGRN['rates'][0]['price'];
                    $arrSearchResults['Hotels'][$GRN_I]['AgentCommission'] = '0';
                    $arrSearchResults['Hotels'][$GRN_I]['Latitude'] = $resValueGRN['geolocation']['latitude'];
                    $arrSearchResults['Hotels'][$GRN_I]['Longitude'] = $resValueGRN['geolocation']['longitude'];
                    $arrSearchResults['Hotels'][$GRN_I]['HotelAddress'] = $resValueGRN['address'];
                    $GRN_I++;
                }
            } else {

                $arrSearchResults['HotelSearchResult']['ResponseStatus'] = '0';
                $arrSearchResults['HotelSearchResult']['ErrorCode'] = isset($responseGRN['errors'][0]['code']) ? $responseGRN['errors'][0]['code'] : '';
                $arrSearchResults['HotelSearchResult']['ErrorMessage'] = isset($responseGRN['errors'][0]['messages'][0]) ? $responseGRN['errors'][0]['messages'][0] : '';
            }
        }

        //          
        // For GRN Hotel Api Call Ends.....
        // For TBO Hotel Api Call Starts.....
        $apiTboIsActive = true;
        if ($apiTboIsActive == true) { //echo "HI===";exit;
            // getting APICity Id...
            $objCity = new Travel_Model_TblCity();
            $objCity->intGTXCityId = $intGTXCityId;
            $objCity->intICSourceSysId = '3';
            $strApiCityId = $objCity->getApiCityDetails();
            if (empty($strApiCityId)) {
                //                    $arrSearchResults = array(); 
                //                    $arrSearchResults['HotelSearchResult']['ResponseStatus']    = '0';
                //                    $arrSearchResults['HotelSearchResult']['ErrorCode']         = '';
                //                    $arrSearchResults['HotelSearchResult']['ErrorMessage']      = 'City id missing';
                //                    return $arrSearchResults;
                //                    exit;
            }



            //echo "<pre>";print_r($strApiCityId);exit;
            // getting APICity Id..
            /* Getting Members Details */
            $arrMemberDetails = array();
            if (count($memberDetails) > 0) {
                for ($i = 0; $i < count($memberDetails); $i++) {
                    $arrMemberDetails[$i]['NoOfAdults'] = $memberDetails[$i]['AdultPax'];
                    $arrMemberDetails[$i]['NoOfChild'] = $memberDetails[$i]['ChildPax'];
                    if ($memberDetails[$i]['ChildPax'] > 0) {
                        $arrChildAge = explode(",", $memberDetails[$i]['ChildsAge']);
                        $arrMemberDetails[$i]['ChildAge'] = $arrChildAge;
                    } else {
                        $arrMemberDetails[$i]['ChildAge'] = NULL;
                    }
                }
            }
            /* Getting Members Details */

            if ($intMaxRating > 5) {
                $intMaxRating = 5;
                $intMinRating = 1;
            } else {
                $intMaxRating = $intMaxRating;
                $intMinRating = $intMaxRating;
            }

            $datah = array(
                "CheckInDate" => $strCheckInDate,
                "NoOfNights" => $intNoOfNights,
                "CountryCode" => $strcountryCode,
                "CityId" => $strApiCityId,
                "ResultCount" => null,
                "PreferredCurrency" => "INR",
                "GuestNationality" => $strselectNationality,
                "NoOfRooms" => $intNoOfRooms,
                "RoomGuests" => $arrMemberDetails,
                'PreferredHotel' => '',
                'MaxRating' => $intMaxRating,
                'MinRating' => $intMinRating,
                'ReviewScore' => null,
                'IsNearBySearchAllowed' => 'false',
                'EndUserIp' => $_SERVER['REMOTE_ADDR'],
                'TokenId' => $tokenId
            );

            //                echo "<pre>";
            //                print_r($datah);
            //                exit;

            $data_stringh = json_encode($datah);

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, TBO_HOTEL_API_SEARCH_URL);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json',
                'Content-Length: ' . strlen($data_stringh)
            ));
            $outputH = curl_exec($ch);
            $responseTBO = json_decode($outputH, true);
            //                echo "<pre>";
            //                print_r($responseTBO); exit;
            $arrHotelResultsTBO = (array) !isset($responseTBO['HotelSearchResult']['HotelResults']) ? @$responseTBO['HotelSearchResult']['HotelResults'] : '';
            $strTraceIdTBO = $responseTBO['HotelSearchResult']['TraceId'];
            $strCityIdTBO = @$responseTBO['HotelSearchResult']['CityId'];
            $TBO_I = $GRN_I;
            if (count($arrHotelResultsTBO) > 0 && !empty($arrHotelResultsTBO)) {

                $arrSearchResults['HotelSearchResult']['ResponseStatus'] = '1';
                $arrSearchResults['HotelSearchResult']['ErrorMessage'] = '';
                $arrSearchResults['HotelSearchResult']['ErrorCode'] = '';

                foreach ($arrHotelResultsTBO as $resValueTBO) {

                    $strHotelPicture = $resValueTBO['HotelPicture'];
                    $arrHotelPicture = explode("/", $resValueTBO['HotelPicture']);
                    if (isset($arrHotelPicture) && !empty($arrHotelPicture)) {
                        if (end($arrHotelPicture) === "HotelNA.jpg") {
                            $strHotelPicture = "";
                        }
                    }

                    $arrSearchResults['Hotels'][$TBO_I]['ApiSourceSysId'] = '3';
                    $arrSearchResults['Hotels'][$TBO_I]['TraceId'] = $strTraceIdTBO;
                    $arrSearchResults['Hotels'][$TBO_I]['TokenId'] = $tokenId;
                    $arrSearchResults['Hotels'][$TBO_I]['APICityId'] = $strCityIdTBO;
                    $arrSearchResults['Hotels'][$TBO_I]['HotelCode'] = $resValueTBO['HotelCode'];
                    $arrSearchResults['Hotels'][$TBO_I]['HotelName'] = $resValueTBO['HotelName'];
                    $arrSearchResults['Hotels'][$TBO_I]['ResultIndex'] = $resValueTBO['ResultIndex'];
                    $arrSearchResults['Hotels'][$TBO_I]['HotelPicture'] = $strHotelPicture;
                    $arrSearchResults['Hotels'][$TBO_I]['StarRating'] = $resValueTBO['StarRating'];
                    $arrSearchResults['Hotels'][$TBO_I]['AgencyRating'] = !empty($resValueTBO['TripAdvisor']['Rating']) ? $resValueTBO['TripAdvisor']['Rating'] : '';
                    $arrSearchResults['Hotels'][$TBO_I]['AwardRecognizations'] = !empty($resValueTBO['TripAdvisor']['ReviewURL']) ? 'TripAdvisor' : '';
                    $arrSearchResults['Hotels'][$TBO_I]['AwardURL'] = !empty($resValueTBO['TripAdvisor']['ReviewURL']) ? $resValueTBO['TripAdvisor']['ReviewURL'] : '';
                    $arrSearchResults['Hotels'][$TBO_I]['AccoAminitiesMask'] = '';
                    $arrSearchResults['Hotels'][$TBO_I]['HotelDescription'] = $resValueTBO['HotelDescription'];
                    $arrSearchResults['Hotels'][$TBO_I]['PublishedPrice'] = $resValueTBO['Price']['OfferedPrice'];
                    $arrSearchResults['Hotels'][$TBO_I]['AgentCommission'] = $resValueTBO['Price']['AgentCommission'];
                    $arrSearchResults['Hotels'][$TBO_I]['Latitude'] = $resValueTBO['Latitude'];
                    $arrSearchResults['Hotels'][$TBO_I]['Longitude'] = $resValueTBO['Longitude'];
                    $arrSearchResults['Hotels'][$TBO_I]['HotelAddress'] = $resValueTBO['HotelAddress'];

                    $TBO_I++;
                }
            } else {

                if (!empty($arrSearchResults) && isset($arrSearchResults['Hotels']) && count($arrSearchResults['Hotels']) > 0) {
                    $arrSearchResults['HotelSearchResult']['ResponseStatus'] = '1';
                    $arrSearchResults['HotelSearchResult']['ErrorMessage'] = '';
                    $arrSearchResults['HotelSearchResult']['ErrorCode'] = '0';
                } else {
                    $arrSearchResults['HotelSearchResult']['ResponseStatus'] = $responseTBO['HotelSearchResult']['ResponseStatus'];
                    $arrSearchResults['HotelSearchResult']['ErrorCode'] = $responseTBO['HotelSearchResult']['Error']['ErrorCode'];
                    $arrSearchResults['HotelSearchResult']['ErrorMessage'] = $responseTBO['HotelSearchResult']['Error']['ErrorMessage'];
                }
            }
        }


        // For TBO Hotel Api Call Ends.....


        return $arrSearchResults;
    }

    public function getApiHotelRoomInfo($arrSessionData = array())
    {

        // Common Variables To All Api Calls........

        $strCheckInDate = $arrSessionData['hotelFromDateSession'];
        $strCheckOutDate = $arrSessionData['hotelToDateSession'];
        $intNoOfNights = $arrSessionData['hotelTotalNights'];
        $strselectNationality = $arrSessionData['selectNationality'];
        $strcountryCode = $arrSessionData['countryCode'];
        $intGTXCityId = $arrSessionData['hotelXrefCityId'];
        $intHotelCityId = $arrSessionData['hidden_selected_hotel_id'];
        $intNoOfRooms = $arrSessionData['hotelTotalRooms'];
        $intNoOfAdults = (int) $arrSessionData['totalMemberCount']['AdultPax'];
        $intNoOfChild = (int) $arrSessionData['totalMemberCount']['ChildPax'];
        $intTotalPaxCount = $arrSessionData['totalMemberCount']['AdultPax'] + $arrSessionData['totalMemberCount']['ChildPax'];
        $intChildAge = $arrSessionData['totalMemberCount']['ChildsAge'];
        $memberDetails = $arrSessionData['memberDetails'];
        $intMaxRating = $arrSessionData['hotelStarRating'];
        $intMinRating = $arrSessionData['hotelStarRating'];

        $apiSourceSysId = $arrSessionData['apiSourceSysId'];
        $strTraceId = $arrSessionData['strTraceId'];
        $strHotelCode = $arrSessionData['strHotelCode'];
        $strResultIndex = isset($arrSessionData['strResultIndex']) ? $arrSessionData['strResultIndex'] : '';



        // For GRN Hotel Api Call Starts.....
        $apiGrnIsActive = true;
        $response = array();
        if ($apiGrnIsActive == true && $apiSourceSysId == '4') {

            /* Getting Members Details */
            $arrMemberDetails = array();
            if (count($memberDetails) > 0) {
                for ($i = 0; $i < count($memberDetails); $i++) {
                    $arrMemberDetails[$i]['adults'] = $memberDetails[$i]['AdultPax'];
                    //$arrMemberDetails[$i]['NoOfChild'] = $memberDetails[$i]['ChildPax'];
                    if ($memberDetails[$i]['ChildPax'] > 0) {
                        $arrChildAge = explode(",", $memberDetails[$i]['ChildsAge']);
                        $arrMemberDetails[$i]['children_ages'] = $arrChildAge;
                    }
                }
            }
            /* Getting Members Details */



            $arrCheckInDateGRN = explode("/", $strCheckInDate);
            if (count($arrCheckInDateGRN) > 0) {
                $strCheckInDateGRN = $arrCheckInDateGRN[2] . "-" . $arrCheckInDateGRN[1] . "-" . $arrCheckInDateGRN[0];
            }

            $arrCheckOutDateGRN = explode("/", $strCheckOutDate);
            if (count($arrCheckInDateGRN) > 0) {
                $strCheckOutDateGRN = $arrCheckOutDateGRN[2] . "-" . $arrCheckOutDateGRN[1] . "-" . $arrCheckOutDateGRN[0];
            }


            $datah = array(
                "hotel_codes" => [trim($strHotelCode)],
                "checkin" => $strCheckInDateGRN,
                "checkout" => $strCheckOutDateGRN,
                "client_nationality" => $strselectNationality,
                "response" => "full",
                "currency" => "INR",
                "rates" => "comprehensive", //comprehensive //comprehensive
                "hotel_category" => (($intMaxRating > 2) ? array("2", $intMaxRating) : array(2)),
                "rooms" => $arrMemberDetails
            );


            $APIcUrl = GRN_HOTEL_API_SEARCH_URL . "/" . $strTraceId . "?hcode=" . $strHotelCode;
            $data_stringh = json_encode($datah);


            //Write Request Logs starts...
            //                $strFilePath = "apihotels/search/".time()."_roomInfoRequest.json";
            //                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath,$data_stringh);
            //Write Request Logs starts...


            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, GRN_HOTEL_API_SEARCH_URL);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Accept: application/json',
                'Content-Type: application/json',
                'api-key: ' . GRN_HOTEL_API_KEY
            ));
            $outputH = curl_exec($ch);
            $response = json_decode($outputH, true);

            return $response;
            exit;
            //echo "<pre>"; print_r($response); exit;
            //Write Request Logs starts...
            //                $strFilePath = "apihotels/search/".time()."_roomInfoResponse.json";
            //                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath,$outputH);
            //Write Request Logs starts...
        }

        $apiTBOIsActive = true;
        $response = array();
        if ($apiTBOIsActive == true && $apiSourceSysId == '3') {
            $tokenId = Zend_Controller_Action_HelperBroker::getStaticHelper('Flight')->authenticateAPI();
            $datahRoom = array(
                "ResultIndex" => $strResultIndex,
                "HotelCode" => $strHotelCode,
                "EndUserIp" => $_SERVER['REMOTE_ADDR'],
                "TokenId" => $tokenId,
                "TraceId" => $strTraceId
            );
            $data_stringh = json_encode($datahRoom);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, TBO_HOTEL_API_HOTEL_ROOM_INFO);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            //curl_setopt($ch, CURLOPT_HEADER, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json',
                'Content-Length: ' . strlen($data_stringh)
            ));



            $outputH = curl_exec($ch);



            $response = json_decode($outputH, true);
            //            echo "<pre>";
            //            print_r($response);exit;
            //            return $response;
            curl_close($ch);
            return $response;
            exit;
        }


        // For GRN Hotel Api Call Ends.....
    }

    public function getApiHotelRoomImages($strHotelCode)
    {


        // For GRN Hotel Api Call Starts.....
        $datah = array();
        $arrResponse = array();
        $APIcUrl = GRN_HOTEL_API_URL . "/" . $strHotelCode . "/images";
        $data_stringh = json_encode($datah);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $APIcUrl);
        curl_setopt($ch, CURLOPT_ENCODING, "gzip");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Accept: application/json',
            'Content-Type: application/json',
            'api-key: ' . GRN_HOTEL_API_KEY
        ));
        $outputH = curl_exec($ch);
        $response = json_decode($outputH, true);
        // For GRN Hotel Api Call Ends.....

        if (isset($response['images']['regular'])) {
            $arrResponse['errors'] = 0;
            $arrResponse['messages'] = '';
            $arrResponse['images'] = $response['images']['regular'];
        } else {
            $arrResponse['errors'] = 1;
            $arrResponse['messages'] = 'No images found for the hotel';
            $arrResponse['images'] = '';
        }
        return $arrResponse;
        exit;
    }

    public function getHotelCancellationPolicy($arrPostData)
    {  //For GRN....
        //echo "<pre>";print_r($arrPostData);exit;
        $search_id = $arrPostData['search_id'];
        $rate_key = $arrPostData['rate_key'];
        $cp_code = $arrPostData['cp_code'];

        $datah = array(
            "rate_key" => $rate_key,
            "cp_code" => $cp_code
        );

        // For GRN Hotel Api Call Starts.....
        $arrResponse = array();
        $APIcUrl = GRN_HOTEL_API_CANCELLATION_POLICY_URL . "/" . $search_id . "/rates/cancellation_policies/";
        $data_stringh = json_encode($datah);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $APIcUrl);
        curl_setopt($ch, CURLOPT_ENCODING, "gzip");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Accept: application/json',
            'Content-Type: application/json',
            'api-key: ' . GRN_HOTEL_API_KEY
        ));
        $outputH = curl_exec($ch);
        $response = json_decode($outputH, true);
        //echo "<pre>";print_r($response);exit;
        // For GRN Hotel Api Call Ends.....


        return $response;
        exit;
    }

    public function getHotelBookingDetails($strBookingId, $strBookingReference, $intSupplierSysId)
    {

        $response = array();
        if ($intSupplierSysId == '4') {
            // For GRN Hotel Api Call Starts.....
            $datah = array();
            $arrResponse = array();
            $APIcUrl = GRN_HOTEL_API_FETCH_BOOKINGS_URL . "/" . $strBookingReference;
            $data_stringh = json_encode($datah);

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $APIcUrl);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Accept: application/json',
                'Content-Type: application/json',
                'api-key: ' . GRN_HOTEL_API_KEY
            ));
            $outputH = curl_exec($ch);
            $response = json_decode($outputH, true);
            // For GRN Hotel Api Call Ends.....
        } elseif ($intSupplierSysId == '3') {

            $tokenId = Zend_Controller_Action_HelperBroker::getStaticHelper('Flight')->authenticateAPI();
            $datah = array(
                "BookingId" => $strBookingId,
                "EndUserIp" => $_SERVER['REMOTE_ADDR'],
                "TokenId" => $tokenId
            );

            $data_stringh = json_encode($datah);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, TBO_HOTEL_API_FETCH_BOOKING_DETAIL_URL);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json',
                'Content-Length: ' . strlen($data_stringh)
            ));
            $outputH = curl_exec($ch);
            $response = json_decode($outputH, true);
        }
        //echo "<pre>";print_r($response);exit;
        return $response;
        exit;
    }

    public function getApiHotelRateInfo($data)
    {

        // For GRN Hotel Api Call Starts.....
        //echo "<pre>";print_r($data);exit;
        $intApiSourceId = trim($data['apiSource']);
        $strCheckInDate = trim($data['strCheckInDate']);
        $strCheckOutDate = trim($data['strCheckOutDate']);

        $apiGrnIsActive = true;
        if ($apiGrnIsActive == true && $intApiSourceId == '4') {
            $strSearchId = trim($data['strTraceId']);
            $datah = array(
                "rate_key" => trim($data['strRoomRateKey']),
                "group_code" => trim($data['strRoomGroupCode'])
            );
            //http://api-sandbox.grnconnect.com/api/v3/hotels/availability/xnx5tzddcq2q4t2rneoo2zkf4u/rates/?action=recheck [ Sample End Point Url ]
            $APIcUrl = GRN_HOTEL_API_RATE_RECHECK_URL . "/" . $strSearchId . "/rates/?action=recheck";

            $data_stringh = json_encode($datah);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $APIcUrl);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Accept: application/json',
                'Content-Type: application/json',
                'api-key: ' . GRN_HOTEL_API_KEY
            ));
            $outputH = curl_exec($ch);
            $arrResponseData = json_decode($outputH, true);

            // echo "<pre>";print_r($arrResponseData);die;
            //Write Request Logs starts...
            //                $strFilePath = "apihotels/search/".time()."_rateRecheckRequest.json";
            //                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath,$data_stringh);
            //Write Request Logs starts...
            //Write Request Logs starts...
            //                $strFilePath = "apihotels/search/".time()."_rateRecheckResponse.json";
            //                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath,$outputH);
            //Write Request Logs starts...
            //echo "<pre>"; print_r($arrResponseData); exit;
            if (count($arrResponseData > 0) && !empty($arrResponseData['search_id'])) {

                $response['ERROR']['CODE'] = !empty($arrResponseData['errors'][0]['code']) ? $arrResponseData['errors'][0]['code'] : '';
                $response['ERROR']['MESSAGE'] = !empty($arrResponseData['errors'][0]['messages'][0]) ? $arrResponseData['errors'][0]['messages'][0] : '';

                $response['HOTELINFO']['API_SOURCE_ID'] = $intApiSourceId;
                $response['HOTELINFO']['SEARCH_ID'] = $arrResponseData['search_id'];
                $response['HOTELINFO']['HOTEL_NAME'] = $arrResponseData['hotel']['name'];
                $response['HOTELINFO']['HOTEL_CODE'] = $arrResponseData['hotel']['hotel_code'];
                $response['HOTELINFO']['HOTEL_DESC'] = $arrResponseData['hotel']['description'];
                $response['HOTELINFO']['HOTEL_CITY_CODE'] = $arrResponseData['hotel']['city_code'];
                $response['HOTELINFO']['HOTEL_CON_CODE'] = $arrResponseData['hotel']['country'];
                $response['HOTELINFO']['HOTEL_CATE'] = $arrResponseData['hotel']['category'];
                $response['HOTELINFO']['HOTEL_ADDRESS'] = $arrResponseData['hotel']['address'];
                $response['HOTELINFO']['HOTEL_LAT'] = $arrResponseData['hotel']['geolocation']['latitude'];
                $response['HOTELINFO']['HOTEL_LONG'] = $arrResponseData['hotel']['geolocation']['longitude'];
                $response['HOTELINFO']['HOTEL_IMAGE'] = $arrResponseData['hotel']['images']['main_image'];

                $response['ROOMINFO']['ROOM_TYPE'] = $arrResponseData['hotel']['rate']['rooms'][0]['room_type'];
                $response['ROOMINFO']['NO_OF_ROOMS'] = @$arrResponseData['hotel']['rate']['rooms'][0]['no_of_rooms'];
                $response['ROOMINFO']['NO_OF_CHILD'] = isset($arrResponseData['hotel']['rate']['rooms'][0]['no_of_children']) ? $arrResponseData['hotel']['rate']['rooms'][0]['no_of_children'] : $arrResponseData['hotel']['rate']['rooms'][0]['max_room_occupancy']['max_children'];
                $response['ROOMINFO']['NO_OF_ADULTS'] = isset($arrResponseData['hotel']['rate']['rooms'][0]['no_of_children']) ? $arrResponseData['hotel']['rate']['rooms'][0]['no_of_children'] : $arrResponseData['hotel']['rate']['rooms'][0]['max_room_occupancy']['max_adults'];
                $response['ROOMINFO']['ROOM_DESC'] = $arrResponseData['hotel']['rate']['rooms'][0]['description'];
                $response['ROOMINFO']['ROOM_CODE'] = $arrResponseData['hotel']['rate']['room_code'];
                $response['ROOMINFO']['RATE_TYPE'] = $arrResponseData['hotel']['rate']['rate_type'];
                $response['ROOMINFO']['RATE_KEY'] = $arrResponseData['hotel']['rate']['rate_key'];
                $response['ROOMINFO']['ROOM_INSTRUCTIONS_SPL'] = @$arrResponseData['hotel']['rate']['rate_comments']['spl_checkin_instructions'];
                $response['ROOMINFO']['ROOM_INSTRUCTIONS'] = @$arrResponseData['hotel']['rate']['rate_comments']['checkin_instructions'];
                $response['ROOMINFO']['ROOM_INCLUSIONS'] = @implode(",", explode(";", $arrResponseData['hotel']['facilities']));


                $response['ROOMCANCELATIONS']['TAX_INFO'] = @$arrResponseData['hotel']['rate']['rate_comments']['tax_information'];
                $response['ROOMCANCELATIONS']['POLICY'] = @$arrResponseData['hotel']['rate']['cancellation_policy'];
                $response['ROOMCANCELATIONS']['AMOUNT_TYPE'] = @$arrResponseData['hotel']['rate']['cancellation_policy']['amount_type'];

                $response['ROOMPRICE']['PRICE'] = $arrResponseData['hotel']['rate']['price'];
                $response['ROOMPRICE']['SURCHARGE_TAX'] = @$arrResponseData['hotel']['rate']['price_details']['surcharge_or_tax'][0]['amount'];
                $response['ROOMPRICE']['SERVICE_TAX'] = @$arrResponseData['hotel']['rate']['price_details']['servicetax'][0]['amount'];
                $response['ROOMPRICE']['SERVICE_FEE'] = @$arrResponseData['hotel']['rate']['price_details']['servicefee'][0]['amount'];
                $response['ROOMPRICE']['NET_PRICE'] = $arrResponseData['hotel']['rate']['price_details']['net'][0]['amount'];
                $response['ROOMPRICE']['PAYMENT_TYPE'] = $arrResponseData['hotel']['rate']['payment_type'];
                $response['ROOMPRICE']['CURRENCY'] = $arrResponseData['hotel']['rate']['currency'];
                $response['ROOMPRICE']['HOTEL_IMAGE'] = $arrResponseData['hotel']['images']['main_image'];



                $response['GRN_PRE_BOOKING_DATA']['SEARCH_ID'] = $arrResponseData['search_id'];
                $response['GRN_PRE_BOOKING_DATA']['HOTEL_NAME'] = $arrResponseData['hotel']['name'];
                $response['GRN_PRE_BOOKING_DATA']['HOTEL_CODE'] = $arrResponseData['hotel']['hotel_code'];
                $response['GRN_PRE_BOOKING_DATA']['HOTEL_CITY_CODE'] = $arrResponseData['hotel']['city_code'];
                $response['GRN_PRE_BOOKING_DATA']['HOTEL_CON_CODE'] = $arrResponseData['hotel']['country'];
                $response['GRN_PRE_BOOKING_DATA']['HOTEL_CATE'] = $arrResponseData['hotel']['category'];
                $response['GRN_PRE_BOOKING_DATA']['GROUP_CODE'] = $arrResponseData['hotel']['rate']['group_code'];
                $response['GRN_PRE_BOOKING_DATA']['CHECK_IN'] = date("Y-m-d", strtotime($strCheckInDate));
                $response['GRN_PRE_BOOKING_DATA']['CHECK_OUT'] = date("Y-m-d", strtotime($strCheckOutDate));
                $response['GRN_PRE_BOOKING_DATA']['ROOM_CODE'] = $arrResponseData['hotel']['rate']['room_code'];
                $response['GRN_PRE_BOOKING_DATA']['RATE_KEY'] = $arrResponseData['hotel']['rate']['rate_key'];

                $response['GRN_PRE_BOOKING_DATA']['PAXES']['TOTAL_PAX'] = isset($arrResponseData['hotel']['rate']['rooms'][0]['no_of_children']) ? $arrResponseData['hotel']['rate']['rooms'][0]['no_of_children'] : $arrResponseData['hotel']['rate']['rooms'][0]['max_room_occupancy']['max_adults'];
                $response['GRN_PRE_BOOKING_DATA']['PAXES']['DETAILS']['TITLE'] = "";
                $response['GRN_PRE_BOOKING_DATA']['PAXES']['DETAILS']['NAME'] = "";
                $response['GRN_PRE_BOOKING_DATA']['PAXES']['DETAILS']['LASTNAME'] = "";
                $response['GRN_PRE_BOOKING_DATA']['PAXES']['DETAILS']['TYPE'] = "";

                $response['GRN_PRE_BOOKING_DATA']['HOLDER']['DETAILS']['TITLE'] = "";
                $response['GRN_PRE_BOOKING_DATA']['HOLDER']['DETAILS']['NAME'] = "";
                $response['GRN_PRE_BOOKING_DATA']['HOLDER']['DETAILS']['LASTNAME'] = "";
                $response['GRN_PRE_BOOKING_DATA']['HOLDER']['DETAILS']['EMAIL_ID'] = "";
                $response['GRN_PRE_BOOKING_DATA']['HOLDER']['DETAILS']['PHONE_NO'] = "";
                $response['GRN_PRE_BOOKING_DATA']['HOLDER']['DETAILS']['NATIONALITY'] = "";


                if (isset($arrResponseData['hotel']['rate']['cancellation_policy_code']) && !empty($arrResponseData['hotel']['rate']['cancellation_policy_code'])) {
                    $arrPostData = array(
                        "cp_code" => $arrResponseData['hotel']['rate']['cancellation_policy_code'],
                        "rate_key" => $arrResponseData['hotel']['rate']['rate_key'],
                        "search_id" => $arrResponseData['search_id']
                    );

                    $cancellationPolicyReponse = $this->getHotelCancellationPolicy($arrPostData);
                    $response['ROOMCANCELATIONS']['POLICY'] = $cancellationPolicyReponse;
                    //echo "<pre>";print_r($cancellationPolicyReponse);exit;
                }
            } else {
                $response['ERROR']['CODE'] = !empty($arrResponseData['errors'][0]['code']) ? $arrResponseData['errors'][0]['code'] : '';
                $response['ERROR']['MESSAGE'] = !empty($arrResponseData['errors'][0]['messages'][0]) ? $arrResponseData['errors'][0]['messages'][0] : '';
            }


            //            echo "<pre>";
            //            print_r($response);
            //            exit;
        }


        // For GRN Hotel Api Call Ends.....


        return $response;
        exit;
    }

    public function dateFormatHotelApiString($string)
    { // Added for GRN MAy be used for other
        if (empty($string))
            return '';
        $arr = explode("T", $string);
        return date("d-m-Y", strtotime($arr[0]));
    }

    public function apiHotelBooking($data)
    {


        $API_SOURCE_ID = $data['HOTELINFO']['API_SOURCE_ID'];
        if ($API_SOURCE_ID == "4") {

            $SEARCH_ID = trim($data['GRN_PRE_BOOKING_DATA']['SEARCH_ID']);
            $HOTEL_CODE = trim($data['GRN_PRE_BOOKING_DATA']['HOTEL_CODE']);
            $HOTEL_CITY_CODE = trim($data['GRN_PRE_BOOKING_DATA']['HOTEL_CITY_CODE']);
            $HOTEL_CON_CODE = trim($data['GRN_PRE_BOOKING_DATA']['HOTEL_CON_CODE']);
            $GROUP_CODE = trim($data['GRN_PRE_BOOKING_DATA']['GROUP_CODE']);
            $CHECK_IN = trim($data['GRN_PRE_BOOKING_DATA']['CHECK_IN']);
            $CHECK_OUT = trim($data['GRN_PRE_BOOKING_DATA']['CHECK_OUT']);
            $ROOM_CODE = trim($data['GRN_PRE_BOOKING_DATA']['ROOM_CODE']);
            $RATE_KEY = trim($data['GRN_PRE_BOOKING_DATA']['RATE_KEY']);
            $TOTAL_PAX = trim($data['GRN_PRE_BOOKING_DATA']['PAXES']['TOTAL_PAX']);
            $NET_PRICE = trim($data['GRN_PRE_BOOKING_DATA']['ROOMPRICE']['NET_PRICE']);

            $TOTAL_PAX = trim($data['GRN_PRE_BOOKING_DATA']['PAXES']['TOTAL_PAX']);

            $PAXES_TITLE = trim($data['GRN_PRE_BOOKING_DATA']['PAXES']['DETAILS']['TITLE']);
            $PAXES_NAME = trim($data['GRN_PRE_BOOKING_DATA']['PAXES']['DETAILS']['NAME']);
            $PAXES_LASTNAME = trim($data['GRN_PRE_BOOKING_DATA']['PAXES']['DETAILS']['LASTNAME']);
            $PAXES_TYPE = trim($data['GRN_PRE_BOOKING_DATA']['PAXES']['DETAILS']['TYPE']);


            $HOLDER_TITLE = trim($data['GRN_PRE_BOOKING_DATA']['HOLDER']['DETAILS']['TITLE']);
            $HOLDER_NAME = trim($data['GRN_PRE_BOOKING_DATA']['HOLDER']['DETAILS']['NAME']);
            $HOLDER_LASTNAME = trim($data['GRN_PRE_BOOKING_DATA']['HOLDER']['DETAILS']['LASTNAME']);
            $HOLDER_EMAIL_ID = trim($data['GRN_PRE_BOOKING_DATA']['HOLDER']['DETAILS']['EMAIL_ID']);
            $HOLDER_PHONE_NO = trim($data['GRN_PRE_BOOKING_DATA']['HOLDER']['DETAILS']['PHONE_NO']);
            $HOLDER_NATIONALITY = trim($data['GRN_PRE_BOOKING_DATA']['HOLDER']['DETAILS']['NATIONALITY']);


            $arrMemberDetails = $data['memberDetails'];
            $hotelPassenger = array();
            for ($i = 0; $i < count($arrMemberDetails); $i++) {

                $AdultPaxTotal = $arrMemberDetails[$i]['AdultPax'];
                $ChildPaxTotal = $arrMemberDetails[$i]['ChildPax'];

                if ($AdultPaxTotal > 0) {
                    for ($m = 0; $m < $AdultPaxTotal; $m++) {
                        $hotelPassenger[$i]["paxes"][] = array(
                            "title" => $PAXES_TITLE,
                            "name" => trim($PAXES_NAME),
                            "surname" => trim($PAXES_LASTNAME),
                            "type" => "AD" // AD For Adult,CH For Child pass age as well in case of child
                        );
                    }
                }
                if ($ChildPaxTotal > 0) {
                    $arrChildPaxTotal = explode(",", $arrMemberDetails[$i]['ChildsAge']);
                    for ($m = 0; $m < $ChildPaxTotal; $m++) {
                        $hotelPassenger[$i]["paxes"][] = array(
                            "title" => $PAXES_TITLE,
                            "name" => trim($PAXES_NAME),
                            "surname" => trim($PAXES_LASTNAME),
                            "type" => "CH", // AD For Adult,CH For Child pass age as well in case of child
                            "age" => $arrChildPaxTotal[$m]
                        );
                    }
                }
            }

            $arrRoomHolder = array(
                "title" => $HOLDER_TITLE,
                "name" => trim($HOLDER_NAME),
                "surname" => trim($HOLDER_LASTNAME),
                "email" => $HOLDER_EMAIL_ID,
                "phone_number" => $HOLDER_PHONE_NO,
                "client_nationality" => $HOLDER_NATIONALITY
            );

            $arrBookingItems[] = array(
                "room_code" => $ROOM_CODE,
                "rate_key" => $RATE_KEY,
                "rooms" => $hotelPassenger
            );


            /* $arrCreditCard[] = array(
              "city_name" => "delhi",
              "amount" => $NET_PRICE,
              "card_type" => "VISA",
              "card_number" => "5123456789012346",
              "expiry_month" => "05",
              "expiry_year" => "2017",
              "card_cv2" => "123",
              "card_holder_name" => "TEST CUSTOMER",
              "country" => "IN",
              "address_line1" => "delhi, india",
              "state" => "D!001175"
              ); */





            $datah = array(
                "search_id" => $SEARCH_ID,
                "hotel_code" => $HOTEL_CODE,
                "city_code" => $HOTEL_CITY_CODE,
                "group_code" => $GROUP_CODE,
                "checkin" => $CHECK_IN,
                "checkout" => $CHECK_OUT,
                "booking_comments" => "Testing GRN",
                "payment_type" => "AT_WEB", //Fot Bundaled Rate AT_HOTEL
                "booking_items" => $arrBookingItems,
                "holder" => $arrRoomHolder
                //"credit_card" => $arrCreditCard
            );

            //echo "<pre>";print_r($datah);exit;


            $APIcUrl = GRN_HOTEL_API_BOOKING_URL;
            $data_stringh = json_encode($datah);


            //Write Request Logs starts...
            //                $strFilePath = "apihotels/search/".time()."_bookRequest.json";
            //                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath,$data_stringh);
            //Write Request Logs starts...


            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, GRN_HOTEL_API_BOOKING_URL);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Accept: application/json',
                'Content-Type: application/json',
                'api-key: ' . GRN_HOTEL_API_KEY
            ));
            $outputH = curl_exec($ch);
            $response = json_decode($outputH, true);

            //echo "<pre>"; print_r($response); exit;
            //Write Request Logs starts...
            //                $strFilePath = "apihotels/search/".time()."_bookResponse.json";
            //                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath,$outputH);
            //Write Request Logs starts...


            if (count(@$response['errors']) > 0) {
                $res['ERROR']['CODE'] = !empty($response['errors'][0]['code']) ? $response['errors'][0]['code'] : '';
                $res['ERROR']['MESSAGE'] = !empty($response['errors'][0]['messages'][0]) ? $response['errors'][0]['messages'][0] : '';
            } else {
                $res['ERROR']['CODE'] = '';
                $res['ERROR']['MESSAGE'] = '';
                $res['BOOKING_RESPONSE'] = $response;
            }
        }


        return $res;
        exit;
    }

    public function cancelHotelBooking($data)
    {

        $API_SOURCE_ID = $data['API_SOURCE_ID'];
        if ($API_SOURCE_ID == "4") {

            $BOOKING_REFERENCE = $data['BOOKING_REFERENCE_ID'];
            $BOOKING_REFERENCE = explode("/", $BOOKING_REFERENCE);
            $BOOKING_REFERENCE = $BOOKING_REFERENCE[1];
            $CANCELLATION_COMMENTS = $data['CANCELLATION_REMARKS'];

            $datah = array(
                "comments" => $CANCELLATION_COMMENTS
            );

            //http://api-sandbox.grnconnect.com/api/v3/hotels/bookings/<bref> [ Sample End Point Url ]
            $APIcUrl = GRN_HOTEL_API_CANCELLATION_URL . "/" . $BOOKING_REFERENCE;
            $data_stringh = json_encode($datah);

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $APIcUrl);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Accept: application/json',
                'Content-Type: application/json',
                'api-key: ' . GRN_HOTEL_API_KEY
            ));
            $outputH = curl_exec($ch);
            $response = json_decode($outputH, true);


            //Write Request Logs starts...
            //                $strFilePath = "apihotels/search/".time()."_GRN_booking_cancellation_request.json";
            //                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath,$data_stringh);
            //Write Request Logs starts...
            //Write Request Logs starts...
            //                $strFilePath = "apihotels/search/".time()."_GRN_booking_cancellation_response.json";
            //                Zend_Controller_Action_HelperBroker::getStaticHelper("General")->createApiCallLogs($strFilePath,$outputH);
            //Write Request Logs starts...


            return $response;

            //print_r($response); exit;
        } else if ($API_SOURCE_ID == "3") {
            //echo "<pre>";print_r($data);exit;
            $TOKEN_ID = Zend_Controller_Action_HelperBroker::getStaticHelper('Flight')->authenticateAPI();

            $BOOKING_REFERENCE_ID = $data['BOOKING_REFERENCE_ID'];
            $BOOKING_REFERENCE = explode("/", $BOOKING_REFERENCE_ID);
            $BOOKING_REFERENCE = $BOOKING_REFERENCE[0];
            $CANCELLATION_COMMENTS = $data['CANCELLATION_REMARKS'];
            //$REQUEST_TYPE = $data['REQUEST_TYPE'];

            $datah = array(
                "RequestType" => "4",
                "Remarks" => $CANCELLATION_COMMENTS,
                "BookingId" => $BOOKING_REFERENCE,
                "EndUserIp" => $_SERVER['REMOTE_ADDR'],
                "TokenId" => $TOKEN_ID
            );
            //echo "<pre>"; print_r($datah); exit;
            $data_stringh = json_encode($datah);

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, TBO_HOTEL_API_CANCELLATION_URL);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json',
                'Content-Length: ' . strlen($data_stringh)
            ));
            $outputH = curl_exec($ch);
            $responseTBO = json_decode($outputH, true);
            //echo "<pre>"; print_r($data_stringh); print_r($outputH); exit;
            $intChangeRequestId = !empty($responseTBO['HotelChangeRequestResult']['ChangeRequestId']) ? $responseTBO['HotelChangeRequestResult']['ChangeRequestId'] : '';

            if (!empty($intChangeRequestId)) {

                $TOKEN_ID = Zend_Controller_Action_HelperBroker::getStaticHelper('Flight')->authenticateAPI();

                $datah = array(
                    "ChangeRequestId" => $intChangeRequestId,
                    "EndUserIp" => $_SERVER['REMOTE_ADDR'],
                    "TokenId" => $TOKEN_ID
                );
                //echo "<pre>"; print_r($datah); exit;
                $data_stringh = json_encode($datah);


                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, TBO_HOTEL_API_CANCELLATION_STATUS_URL);
                curl_setopt($ch, CURLOPT_ENCODING, "gzip");
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                    'Content-Type: application/json',
                    'Content-Length: ' . strlen($data_stringh)
                ));
                $outputH = curl_exec($ch);
                $responseTBO = json_decode($outputH, true);
                return $responseTBO;
                //echo "<pre>"; print_r($responseTBO); exit; 
            }
        }
    }

    public function getApiPriceWithMarkupAndServiceTax($intPrice, $intSTaxOnBasePrice = NULL, $intNoOfNights, $intNoOfRooms, $strCountryCode = NULL)
    {

        if (!empty($strCountryCode) && $strCountryCode != "IN") {
            $intAccomType = 2;
        } else {
            $intAccomType = 1;
        }

        $arrPriceAndMarkUps = array();
        $objHotel = new Travel_Model_TblBuyHotel();
        //$arrAgencyMarkups = $objHotel->getAgencyMarkups();
        // For GTX MarkUps...
        $arrGTXMarkups = $objHotel->getGTXMarkups($intAccomType);
        if (count($arrGTXMarkups) > 0) {
            $intGTXCurrencySysId = $arrGTXMarkups[0]['Currency'];
            $intGTXAccomType = $arrGTXMarkups[0]['AccomType'];
            $intGTXMarkUpType = !empty($arrGTXMarkups[0]['MarkUpType']) ? $arrGTXMarkups[0]['MarkUpType'] : 0;
            $intGTXMarkUp = $arrGTXMarkups[0]['MarkUp'];

            if ($intGTXMarkUpType == 1) { // For Flat
                $intGTXMarkUp = $intGTXMarkUp * $intNoOfNights * $intNoOfRooms;
                $intPriceWithGTXMarkUp = $intPrice + $intGTXMarkUp;
            } else { // For Percentage
                $intGTXMarkUp = ($intPrice * $intGTXMarkUp) / 100; // mark ups per room / night
                //$intGTXMarkUp = $intGTXMarkUp*$intNoOfNights*$intNoOfRooms; 
                $intPriceWithGTXMarkUp = round($intPrice + $intGTXMarkUp);
            }
        } else {
            $intGTXMarkUp = 0;
            $intPriceWithGTXMarkUp = $intPrice + $intGTXMarkUp;
        }
        //echo $intPriceWithGTXMarkUp."===";
        // For Agency MarkUps...
        $arrAgencyMarkups = $objHotel->getAgencyMarkups($intAccomType);
        if (count($arrAgencyMarkups) > 0) {
            $intAgencyCurrencySysId = $arrAgencyMarkups[0]['Currency'];
            $intAgencyAccomType = $arrAgencyMarkups[0]['AccomType'];
            $intAgencyMarkUpType = !empty($arrAgencyMarkups[0]['MarkUpType']) ? $arrAgencyMarkups[0]['MarkUpType'] : 0;
            $intAgencyMarkUp = $arrAgencyMarkups[0]['MarkUp'];
            $percentAgencySTax = $arrAgencyMarkups[0]['Tax'];
            if ($intAgencyMarkUpType == 1) { // For Flat
                $intAgencyMarkUp = $intAgencyMarkUp * $intNoOfNights * $intNoOfRooms;
            } else { // For Percentage
                $intAgencyMarkUp = ($intPriceWithGTXMarkUp * $intAgencyMarkUp) / 100; // mark ups per room / night
                //$intAgencyMarkUp = $intAgencyMarkUp*$intNoOfNights*$intNoOfRooms;
            }
            //echo $intAgencyMarkUp;
            $intServiceTaxOnAgencyMarkUp = ($intAgencyMarkUp * $percentAgencySTax) / 100;
            $intAgencyMarkUpWithSTax = $intAgencyMarkUp + $intServiceTaxOnAgencyMarkUp;

            $intServiceTaxOnGTXMarkUp = ($intGTXMarkUp * $percentAgencySTax) / 100;
            $intGTXMarkUpWithSTax = $intGTXMarkUp + $intServiceTaxOnGTXMarkUp;

            $intNetPriceWithAllMarkupsAndSTax = $intPrice + $intSTaxOnBasePrice + $intGTXMarkUpWithSTax + $intAgencyMarkUpWithSTax;
            $intNetSTax = $intSTaxOnBasePrice + $intServiceTaxOnGTXMarkUp + $intServiceTaxOnAgencyMarkUp;



            $arrPriceAndMarkUps = array(
                "intBasePrice" => $intPrice,
                "intSTaxOnBasePrice" => $intSTaxOnBasePrice,
                "intPriceWithMarkUpsAndSTax" => $intNetPriceWithAllMarkupsAndSTax,
                "intGTXMarkUp" => $intGTXMarkUp,
                "intSTaxOnGTXMarkUp" => $intServiceTaxOnGTXMarkUp,
                "intGTXMarkUpWithSTax" => $intGTXMarkUpWithSTax,
                "intAgencyMarkUp" => $intAgencyMarkUp,
                "intSTaxOnAgencyMarkUp" => $intServiceTaxOnAgencyMarkUp,
                "intAgencyMarkUpWithSTax" => $intAgencyMarkUpWithSTax,
                "intNetSTax" => $intNetSTax,
                "GTXMarkUpType" => !empty($intGTXMarkUpType) ? $intGTXMarkUpType : 0,
                "AgencyMarkUpType" => $intAgencyMarkUpType,
                "AgencyMarkUpDB" => $arrAgencyMarkups[0]['MarkUp'],
            );
        } else { // IF NO Agency Mark Up Is Set...
            $arrPriceAndMarkUps = array(
                "intBasePrice" => $intPrice,
                "intSTaxOnBasePrice" => 0,
                "intPriceWithMarkUpsAndSTax" => 0,
                "intGTXMarkUp" => 0,
                "intSTaxOnGTXMarkUp" => 0,
                "intGTXMarkUpWithSTax" => 0,
                "intAgencyMarkUp" => 0,
                "intSTaxOnAgencyMarkUp" => 0,
                "intAgencyMarkUpWithSTax" => 0,
                "intNetSTax" => 0,
                "GTXMarkUpType" => '',
                "AgencyMarkUpType" => '',
            );
        }

        //echo "<pre>";print_r($arrPriceAndMarkUps);exit;
        $sessionHotelPriceAndMarkupsDetails = new Zend_Session_Namespace('sessionHotelPriceAndMarkupsDetails');
        $sessionHotelPriceAndMarkupsDetails->params = $arrPriceAndMarkUps;


        return $arrPriceAndMarkUps;
    }

    public function getMarkupAndServiceTaxCalculationForRefund($intPrice, $intSTaxOnBasePrice = NULL, $intNoOfNights, $intNoOfRooms, $strCountryCode = NULL)
    {

        if (!empty($strCountryCode) && $strCountryCode != "IN") {
            $intAccomType = 2;
        } else {
            $intAccomType = 1;
        }

        $arrPriceAndMarkUps = array();
        $objHotel = new Travel_Model_TblBuyHotel();
        //$arrAgencyMarkups = $objHotel->getAgencyMarkups();
        // For GTX MarkUps...
        $arrGTXMarkups = $objHotel->getGTXMarkups($intAccomType);
        if (count($arrGTXMarkups) > 0) {
            $intGTXCurrencySysId = $arrGTXMarkups[0]['Currency'];
            $intGTXAccomType = $arrGTXMarkups[0]['AccomType'];
            $intGTXMarkUpType = !empty($arrGTXMarkups[0]['MarkUpType']) ? $arrGTXMarkups[0]['MarkUpType'] : 0;
            $intGTXMarkUp = $arrGTXMarkups[0]['MarkUp'];

            if ($intGTXMarkUpType == 1) { // For Flat
                $intGTXMarkUp = $intGTXMarkUp * $intNoOfNights * $intNoOfRooms;
                $intPriceWithGTXMarkUp = $intPrice + $intGTXMarkUp;
            } else { // For Percentage
                $intGTXMarkUp = ($intPrice * $intGTXMarkUp) / 100; // mark ups per room / night
                //$intGTXMarkUp = $intGTXMarkUp*$intNoOfNights*$intNoOfRooms; 
                $intPriceWithGTXMarkUp = round($intPrice + $intGTXMarkUp);
            }
        } else {
            $intGTXMarkUp = 0;
            $intPriceWithGTXMarkUp = $intPrice + $intGTXMarkUp;
        }
        //echo $intPriceWithGTXMarkUp."===";
        // For Agency MarkUps...
        $arrAgencyMarkups = $objHotel->getAgencyMarkups($intAccomType);
        if (count($arrAgencyMarkups) > 0) {
            $intAgencyCurrencySysId = $arrAgencyMarkups[0]['Currency'];
            $intAgencyAccomType = $arrAgencyMarkups[0]['AccomType'];
            $intAgencyMarkUpType = !empty($arrAgencyMarkups[0]['MarkUpType']) ? $arrAgencyMarkups[0]['MarkUpType'] : 0;
            $intAgencyMarkUp = $arrAgencyMarkups[0]['MarkUp'];
            $percentAgencySTax = $arrAgencyMarkups[0]['Tax'];
            if ($intAgencyMarkUpType == 1) { // For Flat
                $intAgencyMarkUp = $intAgencyMarkUp * $intNoOfNights * $intNoOfRooms;
            } else { // For Percentage
                $intAgencyMarkUp = ($intPriceWithGTXMarkUp * $intAgencyMarkUp) / 100; // mark ups per room / night
                //$intAgencyMarkUp = $intAgencyMarkUp*$intNoOfNights*$intNoOfRooms;
            }
            //echo $intAgencyMarkUp;
            $intServiceTaxOnAgencyMarkUp = ($intAgencyMarkUp * $percentAgencySTax) / 100;
            $intAgencyMarkUpWithSTax = $intAgencyMarkUp + $intServiceTaxOnAgencyMarkUp;

            $intServiceTaxOnGTXMarkUp = ($intGTXMarkUp * $percentAgencySTax) / 100;
            $intGTXMarkUpWithSTax = $intGTXMarkUp + $intServiceTaxOnGTXMarkUp;

            $intNetPriceWithAllMarkupsAndSTax = $intPrice + $intSTaxOnBasePrice + $intGTXMarkUpWithSTax + $intAgencyMarkUpWithSTax;
            $intNetSTax = $intSTaxOnBasePrice + $intServiceTaxOnGTXMarkUp + $intServiceTaxOnAgencyMarkUp;



            $arrPriceAndMarkUps = array(
                "intBasePrice" => $intPrice,
                "intSTaxOnBasePrice" => $intSTaxOnBasePrice,
                "intPriceWithMarkUpsAndSTax" => $intNetPriceWithAllMarkupsAndSTax,
                "intGTXMarkUp" => $intGTXMarkUp,
                "intSTaxOnGTXMarkUp" => $intServiceTaxOnGTXMarkUp,
                "intGTXMarkUpWithSTax" => $intGTXMarkUpWithSTax,
                "intAgencyMarkUp" => $intAgencyMarkUp,
                "intSTaxOnAgencyMarkUp" => $intServiceTaxOnAgencyMarkUp,
                "intAgencyMarkUpWithSTax" => $intAgencyMarkUpWithSTax,
                "intNetSTax" => $intNetSTax,
                "GTXMarkUpType" => !empty($intGTXMarkUpType) ? $intGTXMarkUpType : 0,
                "AgencyMarkUpType" => $intAgencyMarkUpType,
                "AgencyMarkUpDB" => $arrAgencyMarkups[0]['MarkUp'],
            );
        } else { // IF NO Agency Mark Up Is Set...
            $arrPriceAndMarkUps = array(
                "intBasePrice" => $intPrice,
                "intSTaxOnBasePrice" => 0,
                "intPriceWithMarkUpsAndSTax" => 0,
                "intGTXMarkUp" => 0,
                "intSTaxOnGTXMarkUp" => 0,
                "intGTXMarkUpWithSTax" => 0,
                "intAgencyMarkUp" => 0,
                "intSTaxOnAgencyMarkUp" => 0,
                "intAgencyMarkUpWithSTax" => 0,
                "intNetSTax" => 0,
                "GTXMarkUpType" => '',
                "AgencyMarkUpType" => '',
            );
        }


        return $arrPriceAndMarkUps;
    }

    function getServiceTax($intAmount, $strType)
    { // return ServiceTax Amount Only
        $objHotel = new Travel_Model_TblBuyHotel();
        $arrAgencyMarkups = $objHotel->getAgencyMarkups();
        $arrSerciceTax = array();
        if ($strType == "H") {
            if (count($arrAgencyMarkups) > 0) {
                $percentAgencySTax = $arrAgencyMarkups[0]['Tax'];
                $intNetSTax = ($intAmount * $percentAgencySTax) / 100;
                $BasePriceWithSTax = $intNetSTax + $intAmount;

                $arrSerciceTax = array(
                    "BasePrice" => $intAmount,
                    "serviceTaxAmount" => $intNetSTax,
                    "BasePriceWithSTax" => $BasePriceWithSTax,
                    "Type" => $strType
                );
            }
        }
        return $arrSerciceTax;
    }

    function getServiceTaxByAgencyId($intAmount, $strType, $AgencySysId)
    { // return ServiceTax Amount Only
        $objHotel = new Travel_Model_TblBuyHotel();
        $arrAgencyMarkups = $objHotel->getAgencyMarkupsByAgencyId('', $AgencySysId);
        $arrSerciceTax = array();
        if ($strType == "H") {
            if (count($arrAgencyMarkups) > 0) {
                $percentAgencySTax = $arrAgencyMarkups[0]['Tax'];
                $intNetSTax = ($intAmount * $percentAgencySTax) / 100;
                $BasePriceWithSTax = $intNetSTax + $intAmount;

                $arrSerciceTax = array(
                    "BasePrice" => $intAmount,
                    "serviceTaxAmount" => $intNetSTax,
                    "BasePriceWithSTax" => $BasePriceWithSTax,
                    "Type" => $strType
                );
            }
        }
        return $arrSerciceTax;
    }

    function getApiServiceTax($intAmount = NULL, $strType, $intSource)
    { // $intSource 8 For TBO , 9 For GRN
        $arrSerciceTax = array();
        if ($strType == "H") {
            $objHotel = new Travel_Model_TblBuyHotel();
            $arrApiServiceTax = $objHotel->getApiServiceTax($intSource);
            if (count($arrApiServiceTax) > 0) {
                $percentAgencySTax = $arrApiServiceTax[0]['Percentage'];
                $intNetSTax = ($intAmount * $percentAgencySTax) / 100;
                $BasePriceWithSTax = $intNetSTax + $intAmount;

                $arrSerciceTax = array(
                    "BasePrice" => $intAmount,
                    "serviceTaxAmount" => $intNetSTax,
                    "BasePriceWithSTax" => $BasePriceWithSTax,
                    "ServiceTaxPercentage" => $percentAgencySTax,
                    "Type" => $strType
                );
            }
        } else if ($strType == "F") {

            $percentAgencySTax = 18;
            $intNetSTax = ($intAmount * $percentAgencySTax) / 100;
            $BasePriceWithSTax = $intNetSTax + $intAmount;

            $arrSerciceTax = array(
                "BasePrice" => $intAmount,
                "serviceTaxAmount" => $intNetSTax,
                "BasePriceWithSTax" => $BasePriceWithSTax,
                "ServiceTaxPercentage" => $percentAgencySTax,
                "Type" => $strType
            );
        } else if ($strType == "P") {

            $percentAgencySTax = 18;
            $intNetSTax = ((float)$intAmount * $percentAgencySTax) / 100;
            $BasePriceWithSTax = $intNetSTax + (float)$intAmount;

            $arrSerciceTax = array(
                "BasePrice" => $intAmount,
                "serviceTaxAmount" => $intNetSTax,
                "BasePriceWithSTax" => $BasePriceWithSTax,
                "ServiceTaxPercentage" => $percentAgencySTax,
                "Type" => $strType
            );
        }
        //echo "<pre>";print_r($arrSerciceTax);echo "</pre>";exit;
        return $arrSerciceTax;
    }

    // Added By Pardeep Panchal Ends Here...
    // getting HotelAmenities Icons By Mapping the Masking.....
    public function getAvailableAmenitiesMasking($suppliedMasking)
    {

        $objAmenities = new Travel_Model_TblAmenities();
        $arrAmenites = $objAmenities->getAminitiesList();
        $suppliedMasking = !empty($suppliedMasking) ? $suppliedMasking : '00000000000000000';
        if (!empty($suppliedMasking)) {
            $arrSuppliedMasking = str_split($suppliedMasking);
            if (count($arrSuppliedMasking) > 0) {
                $arrFinalMaskingIcons = array();
                foreach ($arrSuppliedMasking as $key => $maskValue) {
                    if ($maskValue == 1) {
                        $arrFinalMaskingIcons[$arrAmenites[$key]['Title']] = $arrAmenites[$key]['Icon'];
                    }
                    //                    else {
                    //                        $arrFinalMaskingIcons[$arrAmenites[$key]['Title']] = $arrAmenites[$key]['GreyIcon'];
                    //                    }
                }
            }
        }

        return $arrFinalMaskingIcons;
    }

    // getting HotelAmenities Icons By Mapping the Masking added by Er Amit Kumar Dubey
    public function getAvailableAmenitiesMaskingById($suppliedMasking = NULL, $arrAmenites = NULL)
    {

        $objHotel = new Travel_Model_TblHotel();
        $objHotel->orderByField = " TB_Master_Accom_AccomAminity.AminityId";
        $objHotel->orderBy = "";
        if (empty($arrAmenites)) {
            $arrAmenites = $objHotel->getMasterAccomAminities();
        }
        //        $suppliedMasking = !empty($suppliedMasking)?$suppliedMasking:'00000000000000000';
        $arrFinalMaskingIcons = array();
        if (!empty($suppliedMasking)) {
            $arrSuppliedMasking = str_split($suppliedMasking);
            if (count($arrSuppliedMasking) > 0 && $suppliedMasking != '10000000000000000') {

                $counter = 1;
                foreach ($arrAmenites as $key => $value) {
                    if (@$arrSuppliedMasking[$counter] == 1) {
                        $arrFinalMaskingIcons[$value['Title']] = $value['Icon'];
                    }
                    $counter++;
                }
            }
        }

        return $arrFinalMaskingIcons;
    }

    public function getTotalCostOfHotelByTravelers($hotelArray, $roominfoarr, $baseCurreny = 1)
    {
        //echo "<pre>";print_r($hotelArray);
        $PackageHelperObj = Zend_Controller_Action_HelperBroker::getStaticHelper('Package');
        $totalMember = 0;
        $newcost = 0;
        for ($m = 1; $m <= count($roominfoarr); $m++) {
            $totalMember = (int) $roominfoarr[$m]['Adult'] + (int) $roominfoarr[$m]['Child'];
            $AdultBedType = isset($roominfoarr[$m]['AdultBedType']) ? $roominfoarr[$m]['AdultBedType'] : 'none';
            $ChildBedType_1 = isset($roominfoarr[$m]['ChildBedType_1']) ? $roominfoarr[$m]['ChildBedType_1'] : 'none';
            $ChildBedType_2 = isset($roominfoarr[$m]['ChildBedType_2']) ? $roominfoarr[$m]['ChildBedType_2'] : 'none';
            $exchangerate = $baseCurreny;
            if (isset($hotelArray['CostCurrency']) && $hotelArray['CostCurrency'] != 1) {
                $objPackage = new Travel_Model_TblPackage();
                $exchangerate = $objPackage->currencyExchangeRate($hotelArray['CostCurrency'], 1);
            }
            $exchangerate = 1;
            switch ($totalMember) {
                case '1': {
                        $newcost = $newcost + $PackageHelperObj->convertRatetoBaseCurrency($hotelArray['NetSOccupCost'], $exchangerate);
                        break;
                    }
                case '2': {
                        $newcost = $newcost + $PackageHelperObj->convertRatetoBaseCurrency($hotelArray['NetDOccupCost'], $exchangerate);
                        break;
                    }
                default: {
                        $newcost = $newcost + $PackageHelperObj->convertRatetoBaseCurrency($hotelArray['NetDOccupCost'], $exchangerate);
                        if ($AdultBedType == 'extrabed') {
                            $newcost = $newcost + $PackageHelperObj->convertRatetoBaseCurrency($hotelArray['NetExtraBedCost'], $exchangerate);
                        } else if ($AdultBedType == 'withoutbed') {
                            $newcost = $newcost + $PackageHelperObj->convertRatetoBaseCurrency($hotelArray['NetExtraWOBedCost'], $exchangerate);
                        }
                        if ($ChildBedType_1 == 'extrabed') {
                            $newcost = $newcost + $PackageHelperObj->convertRatetoBaseCurrency($hotelArray['NetTriOccupCost'], $exchangerate);
                        } else if ($ChildBedType_1 == 'withoutbed') {
                            $newcost = $newcost + $PackageHelperObj->convertRatetoBaseCurrency($hotelArray['NetExtraWOBedCost'], $exchangerate);
                        }
                        if ($ChildBedType_2 == 'extrabed') {
                            $newcost = $newcost + $PackageHelperObj->convertRatetoBaseCurrency($hotelArray['NetTriOccupCost'], $exchangerate);
                        } else if ($ChildBedType_2 == 'withoutbed') {
                            $newcost = $newcost + $PackageHelperObj->convertRatetoBaseCurrency($hotelArray['NetExtraWOBedCost'], $exchangerate);
                        }
                        break;
                    }
            }
        }
        //        echo "<pre>";print_r($hotelArray);die;
        if (isset($hotelArray['MarkType']) && $hotelArray['MarkType'] == 1) {
            $Markup = $hotelArray['B2CMarkup'];
            $newcost = $newcost + (int)($newcost * $Markup / 100);
        }
        //echo "<pre>";print_r($hotelArray);exit;
        return round($newcost);
    }

    public function getTotalCostOfHotelByTravelersNew($hotelArray, $roominfoarr)
    {

        //echo "<pre>";print_r($hotelArray);exit;
        // Single 
        $NetSOccupCost = isset($hotelArray['NetSOccupCost']) ? $hotelArray['NetSOccupCost'] : 0;
        $SOccupMarkUpAmt = 0;
        $NetSOccupCostWidMrkp = $NetSOccupCost + $SOccupMarkUpAmt;
        // Single
        // Double 
        $NetDOccupCost = isset($hotelArray['NetDOccupCost']) ? $hotelArray['NetDOccupCost'] : 0;
        $DOccupMarkUpAmt = 0;
        $NetDOccupCostWidMrkp = $NetDOccupCost + $DOccupMarkUpAmt;
        // Double
        // ExtraBed 
        $NetExtraBedCost = isset($hotelArray['NetExtraBedCost']) ? $hotelArray['NetExtraBedCost'] : 0;
        $ExtraBedMarkUpAmt = 0;
        $NetExtraBedCostWidMrkp = $NetExtraBedCost + $ExtraBedMarkUpAmt;
        // ExtraBed
        // ExtraBed 
        $NetExtraWOBedCost = isset($hotelArray['NetExtraWOBedCost']) ? $hotelArray['NetExtraWOBedCost'] : 0;
        $ExtraBedMarkUpAmt = 0;
        $NetExtraWOBedCostWidMrkp = $NetExtraWOBedCost + $ExtraBedMarkUpAmt;
        // ExtraBed







        $totalMember = 0;
        $newcost = 0;
        for ($m = 0; $m <= count($roominfoarr); $m++) {
            $AdultPax = (int) @$roominfoarr[$m]['Adult'];
            $ChildPax = (int) @$roominfoarr[$m]['Child'];
            $totalMember = $AdultPax + $ChildPax;

            if ($totalMember == 1) {
                $newcost = $newcost + (isset($hotelArray['NetSOccupCost']) ? $NetSOccupCostWidMrkp : $NetDOccupCostWidMrkp);
                //$newcost = $newcost + $hotelArray['DOccupCost']; 
            } elseif ($totalMember == 2) {
                $newcost = $newcost + $NetDOccupCostWidMrkp;
            } else if ($totalMember > 2) {
                if ($AdultPax == 3 && $ChildPax == 0) {
                    $newcost = $newcost + ($NetDOccupCostWidMrkp + $NetExtraBedCostWidMrkp);
                } else if ($AdultPax == 2 && $ChildPax == 1) {
                    $newcost = $newcost + ($NetDOccupCostWidMrkp + $NetExtraWOBedCostWidMrkp);
                } else if ($AdultPax == 3 && $ChildPax == 1) {
                    $newcost = $newcost + ($NetDOccupCostWidMrkp + $NetExtraBedCostWidMrkp + $NetExtraWOBedCostWidMrkp);
                } else if ($AdultPax == 2 && $ChildPax == 2) {
                    $newcost = $newcost + ($NetDOccupCostWidMrkp + $NetExtraWOBedCostWidMrkp + $NetExtraWOBedCostWidMrkp);
                } else if ($AdultPax == 1 && $ChildPax == 2) {
                    $newcost = $newcost + ($NetSOccupCostWidMrkp + $NetExtraWOBedCostWidMrkp + $NetExtraWOBedCostWidMrkp);
                }
            }
        }

        return round($newcost);
    }

    /*
     * getTotalCostOfHotelByTravelers. Calculate cost from master table
     * Created by Pooja on 16-August-2017
     * @param  array $hotelArray   hotel details
     * @param  array $roominfoarr  room info array
     * @return string (cost)
     */

    public function getTotalCostOfHotelByTravelers_oldLogic_16nov2017($hotelArray, $roominfoarr)
    {
        error_reporting(1); // temp purpose
        //  echo '<pre>'; print_r($roominfoarr); echo '</pre>';

        $newcost = 0;
        for ($m = 1; $m <= count($roominfoarr); $m++) {

            if ($roominfoarr[$m]['Adult'] == 2) {
                $newcost = $newcost + $hotelArray['NetDOccupCost'];
            }
            if ($roominfoarr[$m]['Adult'] == 1) {
                $newcost = $newcost + $hotelArray['NetSOccupCost'];
            }

            $bedtype = $roominfoarr[$m]['bedtype'];
            if ($roominfoarr[$m]['Adult'] == 3) {
                if ($bedtype == "extrabed") {
                    $newcost = $newcost + $hotelArray['NetExtraBedCost'] + $hotelArray['NetDOccupCost'];
                } else {
                    $newcost = $newcost + $hotelArray['NetExtraWOBedCost'] + $hotelArray['NetDOccupCost'];
                }
            }
            if ($roominfoarr[$m]['Child'] > 0) {
                if ($bedtype == "extrabed") {
                    $newcost = $newcost + $hotelArray['NetExtraBedCost'];
                }
                if ($bedtype == "withoutbed") {
                    $newcost = $newcost + $hotelArray['NetExtraWOBedCost'];
                }
            }
        }
        //echo $newcost;
        //echo '<pre>'; print_r($hotelArray); echo '</pre>';exit;
        return round($newcost);
    }

    public function searchApiHotelsNew($arrSessionData = array(), $searchType = "")
    {

        // Common Variables To All Api Calls........
        $strCheckInDate = $arrSessionData['hotelFromDateSession'];
        $strCheckOutDate = $arrSessionData['hotelToDateSession'];
        $intNoOfNights = $arrSessionData['hotelTotalNights'];
        $strselectNationality = $arrSessionData['selectNationality'];
        $strcountryCode = $arrSessionData['countryCode'];
        $strHotelCityTitle = $arrSessionData['hotelCityTitle'];
        $intGTXCityId = $arrSessionData['hotelXrefCityId'];
        $intHotelCityId = $arrSessionData['hidden_selected_hotel_id'];
        $intNoOfRooms = $arrSessionData['hotelTotalRooms'];
        $intNoOfAdults = (int) $arrSessionData['totalMemberCount']['AdultPax'];
        $intNoOfChild = (int) $arrSessionData['totalMemberCount']['ChildPax'];
        $intTotalPaxCount = $arrSessionData['totalMemberCount']['AdultPax'] + $arrSessionData['totalMemberCount']['ChildPax'];
        $intChildAge = $arrSessionData['totalMemberCount']['ChildsAge'];
        $memberDetails = $arrSessionData['memberDetails'];
        $intMaxRating = $arrSessionData['hotelStarRating'];
        $intMinRating = $arrSessionData['hotelStarRating'];
        $tokenId = Zend_Controller_Action_HelperBroker::getStaticHelper('Flight')->authenticateAPI();

        $request = [];
        $apiSourceSysId = 4;

        if ($apiSourceSysId == 4) {

            $request[0]['url'] = GRN_HOTEL_API_SEARCH_URL;

            // For GRN Hotel Api Call Starts.....
            $objCity = new Travel_Model_TblCity();
            $objCity->intGTXCityId = $intGTXCityId;
            $objCity->intICSourceSysId = '4';
            $strApiCityId = $objCity->getApiCityDetails();

            /* Getting Members Details */
            $arrMemberDetails = array();
            if (count($memberDetails) > 0) {
                for ($i = 0; $i < count($memberDetails); $i++) {
                    $arrMemberDetails[$i]['adults'] = $memberDetails[$i]['AdultPax'];
                    //$arrMemberDetails[$i]['NoOfChild'] = $memberDetails[$i]['ChildPax'];
                    if ($memberDetails[$i]['ChildPax'] > 0) {
                        $arrChildAge = explode(",", $memberDetails[$i]['ChildsAge']);
                        $arrMemberDetails[$i]['children_ages'] = $arrChildAge;
                    }
                }
            }
            /* Getting Members Details */

            $arrCheckInDateGRN = explode("/", $strCheckInDate);
            if (count($arrCheckInDateGRN) > 0) {
                $strCheckInDateGRN = $arrCheckInDateGRN[2] . "-" . $arrCheckInDateGRN[1] . "-" . $arrCheckInDateGRN[0];
            }

            $arrCheckOutDateGRN = explode("/", $strCheckOutDate);
            if (count($arrCheckInDateGRN) > 0) {
                $strCheckOutDateGRN = $arrCheckOutDateGRN[2] . "-" . $arrCheckOutDateGRN[1] . "-" . $arrCheckOutDateGRN[0];
            }

            if ($intMaxRating > 5) {
                $arrHotelRating = array(2, $intMaxRating); // Acco. to Doc.. minimum = 2 & maximum = 7 
            } else {
                $arrHotelRating = array($intMaxRating);
            }

            $datah = array(
                "destination_code" => $strApiCityId,
                "checkin" => $strCheckInDateGRN,
                "checkout" => $strCheckOutDateGRN,
                "client_nationality" => $strselectNationality,
                "response" => "fast",
                "currency" => "INR",
                "rates" => "concise", //comprehensive //comprehensive
                "hotel_category" => $arrHotelRating,
                "rooms" => $arrMemberDetails
            );
            //echo "<pre>";print_r($datah);exit;
            $request[0]['post'] = $datah;
            $request[0]['api_key'] = GRN_HOTEL_API_KEY;
        }




        $apiSourceSysId = 3;

        if ($apiSourceSysId == 3) {

            $request[1]['url'] = TBO_HOTEL_API_SEARCH_URL;

            // getting APICity Id...
            $objCity = new Travel_Model_TblCity();
            $objCity->intGTXCityId = $intGTXCityId;
            $objCity->intICSourceSysId = '3';
            $strApiCityId = $objCity->getApiCityDetails();
            // getting APICity Id..

            /* Getting Members Details */
            $arrMemberDetails = array();
            if (count($memberDetails) > 0) {
                for ($i = 0; $i < count($memberDetails); $i++) {
                    $arrMemberDetails[$i]['NoOfAdults'] = $memberDetails[$i]['AdultPax'];
                    $arrMemberDetails[$i]['NoOfChild'] = $memberDetails[$i]['ChildPax'];
                    if ($memberDetails[$i]['ChildPax'] > 0) {
                        $arrChildAge = explode(",", $memberDetails[$i]['ChildsAge']);
                        $arrMemberDetails[$i]['ChildAge'] = $arrChildAge;
                    } else {
                        $arrMemberDetails[$i]['ChildAge'] = NULL;
                    }
                }
            }
            /* Getting Members Details */

            if ($intMaxRating > 5) {
                $intMaxRating = 5;
                $intMinRating = 1;
            } else {
                $intMaxRating = $intMaxRating;
                $intMinRating = $intMaxRating;
            }

            $datah = array(
                "CheckInDate" => $strCheckInDate,
                "NoOfNights" => $intNoOfNights,
                "CountryCode" => $strcountryCode,
                "CityId" => $strApiCityId,
                "ResultCount" => null,
                "PreferredCurrency" => "INR",
                "GuestNationality" => $strselectNationality,
                "NoOfRooms" => $intNoOfRooms,
                "RoomGuests" => $arrMemberDetails,
                'PreferredHotel' => '',
                'MaxRating' => $intMaxRating,
                'MinRating' => $intMinRating,
                'ReviewScore' => null,
                'IsNearBySearchAllowed' => 'false',
                'EndUserIp' => $_SERVER['REMOTE_ADDR'],
                'TokenId' => $tokenId
            );

            $request[1]['post'] = $datah;
        }


        $response = $this->multiRequest($request);
        //echo "<pre>";print_r($response);exit;
        $responseGRN = json_decode($response[0], true);

        $arrHotelResultsGRN = array();
        $arrHotelResultsGRN = (isset($responseGRN['hotels']) && !empty($responseGRN['hotels'])) ? $responseGRN['hotels'] : '';

        $GRN_I = 0;
        if (!empty($arrHotelResultsGRN) && !empty($responseGRN['hotels'])) {

            $arrSearchResults['HotelSearchResult']['ResponseStatus'] = '1';
            $arrSearchResults['HotelSearchResult']['ErrorMessage'] = '';
            $arrSearchResults['HotelSearchResult']['ErrorCode'] = '0';
            $arrHotelFacilities = array();
            foreach ($arrHotelResultsGRN as $resValueGRN) {

                $arrHotelFacilities = isset($resValueGRN['facilities']) ? explode(";", $resValueGRN['facilities']) : array();
                if (count($arrHotelFacilities) > 0) {
                    $strAmenitiesMasking = Zend_Controller_Action_HelperBroker::getStaticHelper('Masking')->createHotelAmenitiesMasking($arrHotelFacilities);
                }

                $MinPublishedFare = round($resValueGRN['min_rate']['price']);
                if ($searchType === "B2B") {
                    $arrPriceAndMarkUps = Zend_Controller_Action_HelperBroker::getStaticHelper('Hotel')->getApiPriceWithMarkupAndServiceTax($MinPublishedFare, "0", $intNoOfNights, $intNoOfRooms, $strcountryCode);
                    $intPriceWithMarkUpsAndSTax = round($arrPriceAndMarkUps['intPriceWithMarkUpsAndSTax']);
                    $intRoomFarePerNightPerPerson = round(($intPriceWithMarkUpsAndSTax / $intNoOfNights) / $intNoOfRooms);
                    $intAgencyMarkUp = ($arrPriceAndMarkUps['intAgencyMarkUp']);
                } else {
                    $intPriceWithMarkUpsAndSTax = $MinPublishedFare;
                    $intRoomFarePerNightPerPerson = round(($intPriceWithMarkUpsAndSTax / $intNoOfNights) / $intNoOfRooms);
                    $intAgencyMarkUp = 0;
                }


                $arrSearchResults['Hotels'][$GRN_I]['ApiSourceSysId'] = '4';
                $arrSearchResults['Hotels'][$GRN_I]['TraceId'] = $responseGRN['search_id'];
                $arrSearchResults['Hotels'][$GRN_I]['TokenId'] = $tokenId;
                $arrSearchResults['Hotels'][$GRN_I]['APICityId'] = $resValueGRN['city_code'];
                $arrSearchResults['Hotels'][$GRN_I]['HotelCode'] = $resValueGRN['hotel_code'];
                $arrSearchResults['Hotels'][$GRN_I]['HotelName'] = $resValueGRN['name'];
                $arrSearchResults['Hotels'][$GRN_I]['ResultIndex'] = '';
                if (!empty($resValueGRN['images']['main_image'])) {
                    $arrSearchResults['Hotels'][$GRN_I]['HotelPicture'] = GRN_HOTEL_IMAGES_CDN_URL . "/" . $resValueGRN['images']['main_image'];
                } else {
                    $arrSearchResults['Hotels'][$GRN_I]['HotelPicture'] = "";
                }
                $arrSearchResults['Hotels'][$GRN_I]['StarRating'] = $resValueGRN['category'];
                $arrSearchResults['Hotels'][$GRN_I]['AgencyRating'] = '0';
                $arrSearchResults['Hotels'][$GRN_I]['AwardRecognizations'] = '';
                $arrSearchResults['Hotels'][$GRN_I]['AwardURL'] = '';
                $arrSearchResults['Hotels'][$GRN_I]['AccoAminitiesMask'] = !empty($strAmenitiesMasking) ? $strAmenitiesMasking : '';
                $arrSearchResults['Hotels'][$GRN_I]['HotelDescription'] = $resValueGRN['description'];
                $arrSearchResults['Hotels'][$GRN_I]['PublishedPrice'] = $intPriceWithMarkUpsAndSTax; // //comprehensive $resValueGRN['rates'][0]['price'];
                $arrSearchResults['Hotels'][$GRN_I]['OfferPrice'] = $MinPublishedFare;
                $arrSearchResults['Hotels'][$GRN_I]['PerNight'] = $intRoomFarePerNightPerPerson; // //comprehensive $resValueGRN['rates'][0]['price'];
                $arrSearchResults['Hotels'][$GRN_I]['amarkup'] = $intAgencyMarkUp; // //comprehensive $resValueGRN['rates'][0]['price'];
                $arrSearchResults['Hotels'][$GRN_I]['AgentCommission'] = '0';
                $arrSearchResults['Hotels'][$GRN_I]['Latitude'] = $resValueGRN['geolocation']['latitude'];
                $arrSearchResults['Hotels'][$GRN_I]['Longitude'] = $resValueGRN['geolocation']['longitude'];
                $arrSearchResults['Hotels'][$GRN_I]['HotelAddress'] = $resValueGRN['address'];
                $arrSearchResults['Hotels'][$GRN_I]['hotelsource'] = "API";
                $GRN_I++;
            }
        } else {

            $arrSearchResults['HotelSearchResult']['ResponseStatus'] = '0';
            $arrSearchResults['HotelSearchResult']['ErrorCode'] = isset($responseGRN['errors'][0]['code']) ? $responseGRN['errors'][0]['code'] : '';
            $arrSearchResults['HotelSearchResult']['ErrorMessage'] = isset($responseGRN['errors'][0]['messages'][0]) ? $responseGRN['errors'][0]['messages'][0] : '';
        }





        $responseTBO = json_decode(@$response[1], true);
        $arrHotelResultsTBO = (array) !isset($responseTBO['HotelSearchResult']['HotelResults']) ? @$responseTBO['HotelSearchResult']['HotelResults'] : '';
        $strTraceIdTBO = $responseTBO['HotelSearchResult']['TraceId'];
        $strCityIdTBO = @$responseTBO['HotelSearchResult']['CityId'];
        $TBO_I = $GRN_I;
        if (!empty($arrHotelResultsTBO) && !empty($arrHotelResultsTBO)) {

            $arrSearchResults['HotelSearchResult']['ResponseStatus'] = '1';
            $arrSearchResults['HotelSearchResult']['ErrorMessage'] = '';
            $arrSearchResults['HotelSearchResult']['ErrorCode'] = '';

            foreach ($arrHotelResultsTBO as $resValueTBO) {

                $strHotelPicture = $resValueTBO['HotelPicture'];
                $arrHotelPicture = explode("/", $resValueTBO['HotelPicture']);
                if (isset($arrHotelPicture) && !empty($arrHotelPicture)) {
                    if (end($arrHotelPicture) === "HotelNA.jpg") {
                        $strHotelPicture = "";
                    }
                }


                $MinPublishedFare = round($resValueTBO['Price']['OfferedPrice']);
                if ($searchType === "B2B") {
                    $arrPriceAndMarkUps = Zend_Controller_Action_HelperBroker::getStaticHelper('Hotel')->getApiPriceWithMarkupAndServiceTax($MinPublishedFare, "0", $intNoOfNights, $intNoOfRooms, $strcountryCode);
                    $intPriceWithMarkUpsAndSTax = round($arrPriceAndMarkUps['intPriceWithMarkUpsAndSTax']);
                    $intRoomFarePerNightPerPerson = round(($intPriceWithMarkUpsAndSTax / $intNoOfNights) / $intNoOfRooms);
                    $intAgencyMarkUp = ($arrPriceAndMarkUps['intAgencyMarkUp']);
                } else {
                    $intPriceWithMarkUpsAndSTax = $MinPublishedFare;
                    $intRoomFarePerNightPerPerson = round(($intPriceWithMarkUpsAndSTax / $intNoOfNights) / $intNoOfRooms);
                    $intAgencyMarkUp = 0;
                }

                $arrSearchResults['Hotels'][$TBO_I]['ApiSourceSysId'] = '3';
                $arrSearchResults['Hotels'][$TBO_I]['TraceId'] = $strTraceIdTBO;
                $arrSearchResults['Hotels'][$TBO_I]['TokenId'] = $tokenId;
                $arrSearchResults['Hotels'][$TBO_I]['APICityId'] = $strCityIdTBO;
                $arrSearchResults['Hotels'][$TBO_I]['HotelCode'] = $resValueTBO['HotelCode'];
                $arrSearchResults['Hotels'][$TBO_I]['HotelName'] = $resValueTBO['HotelName'];
                $arrSearchResults['Hotels'][$TBO_I]['ResultIndex'] = $resValueTBO['ResultIndex'];
                $arrSearchResults['Hotels'][$TBO_I]['HotelPicture'] = $strHotelPicture;
                $arrSearchResults['Hotels'][$TBO_I]['StarRating'] = $resValueTBO['StarRating'];
                $arrSearchResults['Hotels'][$TBO_I]['AgencyRating'] = !empty($resValueTBO['TripAdvisor']['Rating']) ? $resValueTBO['TripAdvisor']['Rating'] : '';
                $arrSearchResults['Hotels'][$TBO_I]['AwardRecognizations'] = !empty($resValueTBO['TripAdvisor']['ReviewURL']) ? 'TripAdvisor' : '';
                $arrSearchResults['Hotels'][$TBO_I]['AwardURL'] = !empty($resValueTBO['TripAdvisor']['ReviewURL']) ? $resValueTBO['TripAdvisor']['ReviewURL'] : '';
                $arrSearchResults['Hotels'][$TBO_I]['AccoAminitiesMask'] = '';
                $arrSearchResults['Hotels'][$TBO_I]['HotelDescription'] = $resValueTBO['HotelDescription'];
                $arrSearchResults['Hotels'][$TBO_I]['OfferPrice'] = $MinPublishedFare;
                $arrSearchResults['Hotels'][$TBO_I]['PublishedPrice'] = $intPriceWithMarkUpsAndSTax;
                $arrSearchResults['Hotels'][$TBO_I]['PerNight'] = $intRoomFarePerNightPerPerson; // //comprehensive $resValueGRN['rates'][0]['price'];
                $arrSearchResults['Hotels'][$TBO_I]['amarkup'] = $intAgencyMarkUp; // //comprehensive $resValueGRN['rates'][0]['price'];
                $arrSearchResults['Hotels'][$TBO_I]['AgentCommission'] = $resValueTBO['Price']['AgentCommission'];
                $arrSearchResults['Hotels'][$TBO_I]['Latitude'] = $resValueTBO['Latitude'];
                $arrSearchResults['Hotels'][$TBO_I]['Longitude'] = $resValueTBO['Longitude'];
                $arrSearchResults['Hotels'][$TBO_I]['HotelAddress'] = $resValueTBO['HotelAddress'];
                $arrSearchResults['Hotels'][$TBO_I]['hotelsource'] = "API";

                $TBO_I++;
            }
        } else {

            if (!empty($arrSearchResults) && isset($arrSearchResults['Hotels']) && count($arrSearchResults['Hotels']) > 0) {
                $arrSearchResults['HotelSearchResult']['ResponseStatus'] = '1';
                $arrSearchResults['HotelSearchResult']['ErrorMessage'] = '';
                $arrSearchResults['HotelSearchResult']['ErrorCode'] = '0';
            } else {
                $arrSearchResults['HotelSearchResult']['ResponseStatus'] = $responseTBO['HotelSearchResult']['ResponseStatus'];
                $arrSearchResults['HotelSearchResult']['ErrorCode'] = $responseTBO['HotelSearchResult']['Error']['ErrorCode'];
                $arrSearchResults['HotelSearchResult']['ErrorMessage'] = $responseTBO['HotelSearchResult']['Error']['ErrorMessage'];
            }
        }


        return $arrSearchResults;
    }

    public function multiRequest($data, $options = array())
    {

        // array of curl handles
        $curly = array();
        // data to be returned
        $result = array();

        // multi handle
        $mh = curl_multi_init();

        // loop through $data and create curl handles
        // then add them to the multi-handle
        foreach ($data as $id => $d) {

            $curly[$id] = curl_init();

            $url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d;

            curl_setopt($curly[$id], CURLOPT_URL, $url);
            curl_setopt($curly[$id], CURLOPT_ENCODING, "gzip");
            curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);
            //curl_setopt($curly[$id], CURLOPT_HEADER, 0);
            curl_setopt($curly[$id], CURLOPT_SSL_VERIFYPEER, false);








            // post?
            if (is_array($d)) {
                if (!empty($d['post'])) {
                    $data_stringh = json_encode($d['post']);
                    curl_setopt($curly[$id], CURLOPT_POST, true);
                    curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $data_stringh);
                    //curl_setopt($curly[$id], CURLOPT_CONNECTTIMEOUT, 10);
                    //curl_setopt($curly[$id], CURLOPT_TIMEOUT, 25); //timeout in seconds
                    if (isset($d['api_key']) && !empty($d['api_key'])) {
                        curl_setopt($curly[$id], CURLOPT_HTTPHEADER, array(
                            'Accept: application/json',
                            'Content-Type: application/json',
                            'api-key: ' . $d['api_key']
                        ));
                    } else {
                        curl_setopt($curly[$id], CURLOPT_HTTPHEADER, array(
                            'Content-Type: application/json',
                            'Content-Length: ' . strlen($data_stringh)
                        ));
                    }
                }
            }

            if (!empty($options)) {
                curl_setopt_array($curly[$id], $options);
            }

            curl_multi_add_handle($mh, $curly[$id]);
        }

        // execute the handles
        $running = null;
        do {
            curl_multi_exec($mh, $running);
        } while ($running > 0);


        // get content and remove handles
        foreach ($curly as $id => $c) {
            $result[$id] = curl_multi_getcontent($c);
            curl_multi_remove_handle($mh, $c);
        }

        // all done
        curl_multi_close($mh);
        return $result;
    }

    // creates price range params : start value , End value , fractions/multiples of number
    function createRange($start, $end, $fraction)
    {
        //        echo $start ."|". $end ."|". $fraction;

        if ($fraction > $end)
            return "Invalid";

        $total = ceil($end / $fraction);
        //        $loopstart  = (floor($start/$fraction) ==0) ? 1 : 0;
        $loopstart = 1;

        $start = ($fraction * $loopstart);
        $end = ($fraction * $total);

        return range($start, $end, $fraction);
    }

    public function checkRangeExists($num, array $arr)
    {
        $returnval = false;

        foreach ($arr as $value) {
            if ($num < $value) {
                $returnval = true;
                break;
            }
        }

        return $returnval;
    }

    // creates price range dropdown | params : start value , End value , fractions/multiples of number
    function getPriceDropdown($min, $max, $fraction, $minPriceArray = [])
    {
        $min = (int) str_replace(',', '', $min);
        $max = (int) str_replace(',', '', $max);

        $limit = $this->createRange($min, $max, $fraction);
        //        print_r($limit);
        //        echo "<pre>";print_r($minPriceArray);die;

        $newarr = [];
        $next = 1;
        if ($limit !== 'Invalid') {
            foreach ($limit as $key => $value) {
                // check if the price range is exists or not
                if ($this->checkRangeExists($value, $minPriceArray)) {
                    $newarr[$next . '-' . $value] = $next . '-' . $value;
                    $next = $value + 1;
                }
                //              if($value==30000) {
                ////                  break;
                //                  echo $value;
                //                    var_dump($this->checkRangeExists( $value , $minPriceArray));
                //              }
            }
        }
        return $newarr;
    }

    public function getApiHotelInfo($arrSessionData = array())
    {

        // Common Variables To All Api Calls........

        $apiSourceSysId = $arrSessionData['source'];
        $strTraceId = $arrSessionData['TraceId'];
        $strHotelCode = $arrSessionData['HotelCode'];
        $strResultIndex = isset($arrSessionData['ResultIndex']) ? $arrSessionData['ResultIndex'] : '';

        $response = array();
        if ($apiSourceSysId == '3') {
            $tokenId = Zend_Controller_Action_HelperBroker::getStaticHelper('Flight')->authenticateAPI();
            $datahRoom = array(
                "ResultIndex" => $strResultIndex,
                "HotelCode" => $strHotelCode,
                "EndUserIp" => $_SERVER['REMOTE_ADDR'],
                "TokenId" => $tokenId,
                "TraceId" => $strTraceId
            );
            $data_stringh = json_encode($datahRoom);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, TBO_HOTEL_API_HOTEL_INFO);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            //curl_setopt($ch, CURLOPT_HEADER, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json',
                'Content-Length: ' . strlen($data_stringh)
            ));

            $response = curl_exec($ch);
            curl_close($ch);
            return $response;
            exit;
        }


        // For GRN Hotel Api Call Ends.....
    }

    public function deleteSearchJsonFile($path)
    {
        $now = time();
        if (is_dir($path)) {
            $files = scandir($path, 1);
            // echo "<pre>";print_r($files);exit;
            foreach ($files as $file) {
                if (is_file($file) && ($now - @filemtime($file) >= 60 * 60 * 24 * 1)) {
                    unlink($path . "/" . $file);
                }
            }
        }
    }



    /**  TJ Hotel Integration code  By Sabir **/

    public function GetTJURLandKey($AgencySysId)
    {
        $checkOptModel = new Payment_Model_Checkotp();
        $ApiKeyForFlight = $checkOptModel->getTripJectApiKeyForFlight($AgencySysId, 3);
        $TripJackURL = Zend_Controller_Action_HelperBroker::getStaticHelper("Flight")->FlightsTripJackURL($AgencySysId, $ApiKeyForFlight);
        if ($ApiKeyForFlight['IsCheckWallet'] == 1) {
            $APIKEY = $ApiKeyForFlight['APIKEY'];
        } else {
            $APIKEY = $TripJackURL['APIKEY'];
        }
        return ['APIKEY' => $APIKEY, 'TripJackURL' => $TripJackURL];
    }

    public function getHotelSearchId($data, $SecurityKey)
    {
        $APIURL = GTX_API_URL . '/hotel/v1/hotelsearchid';

        $searchID = $data['searchID'];
        $MemberCount = $data['MemberCount'];

        $data_stringh = json_encode($data);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $APIURL);
        curl_setopt($ch, CURLOPT_ENCODING, "gzip");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Accept: application/json',
            'Content-Type: application/json',
            'Accept-Encoding: gzip',
            'SecurityKey:' . $SecurityKey,
            'Content-Length: ' . strlen($data_stringh)
        ));

        $response = curl_exec($ch);
        curl_close($ch);

        $resultSearch = json_decode($response, true);

        $ResponseStatus = isset($resultSearch['status']['success']) ? $resultSearch['status']['success'] : 0;
        $ErrorMessage = isset($resultSearch['errors'][0]['message']) ? $resultSearch['errors'][0]['message'] : '';

        // $logParams = [
        //     "user_id"      => 1,
        //     "AgencySysId"      => $AgencySysId,
        //     "custom_error" => ($ResponseStatus == 1) ? "Hotel Search Query Success" : "Hotel Search Query Failed",
        //     'error'        => $ErrorMessage,
        //     "text_udf"     => ['response' => $resultSearch], // Response
        //     "char_udf"     => ['request' => $data['hotelsearchdata']], // Request
        //     "udf1"         => $searchID,
        //     "udf5"         => "searchquery",
        //     "flight_type"         => 5,
        //     "source"         => 3,
        //     "Pax"         => $MemberCount,
        //     "Supplier"    => "TRIPJACK",
        //     "status"       => ($ResponseStatus == 1) ? 2 : 1,
        // ];
        // Zend_Controller_Action_HelperBroker::getStaticHelper("General")->CreateLogs($logParams);


        return $resultSearch;
    }

    function  getHotelSearchResult($data, $SecurityKey)
    {
        $APIURL = GTX_API_URL . '/hotel/v1/hotelsearch';

        $searchID = $data['searchID'];
        $MemberCount = $data['MemberCount'];
        $jsonSearchID = json_encode($data);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $APIURL);
        curl_setopt($ch, CURLOPT_ENCODING, "gzip");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonSearchID);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Accept: application/json',
            'Content-Type: application/json',
            'Accept-Encoding: gzip',
            'SecurityKey:' . $SecurityKey,
            'Content-Length: ' . strlen($jsonSearchID)
        ));
        $resp = curl_exec($ch);
        curl_close($ch);
        // echo $resp;
        // die('s');
        $hotelsResultS = json_decode($resp, true);




        // $ResponseStatus = isset($hotelsResultS['status']['success']) ? $hotelsResultS['status']['success'] : 0;
        // $ErrorMessage = isset($hotelsResultS['errors'][0]['message']) ? $hotelsResultS['errors'][0]['message'] : '';

        // $logParams = [
        //     "user_id"      => 1,
        //     "AgencySysId"      => $AgencySysId,
        //     "custom_error" => ($ResponseStatus == 1) ? "Hotel Search Success" : "Hotel Search Failed",
        //     'error'        => $ErrorMessage,
        //     "text_udf"     => ['response' => $hotelsResultS], // Response
        //     "char_udf"     => ['request' => $data], // Request
        //     "udf1"         => $searchID,
        //     "udf5"         => "search",
        //     "flight_type"         => 5,
        //     "source"         => 3,
        //     "Pax"         => $MemberCount,
        //     "Supplier"    => "TRIPJACK",
        //     "status"       => ($ResponseStatus == 1) ? 2 : 1,
        // ];
        // Zend_Controller_Action_HelperBroker::getStaticHelper("General")->CreateLogs($logParams);


        return $hotelsResultS;
    }

    public function getHotelDetails($data, $SecurityKey)
    {
        $APIURL = GTX_API_URL . '/hotel/v2/hoteldetails';

        $searchID = $data['searchID'];
        $MemberCount = $data['MemberCount'];

        $data_stringh = json_encode($data);
        // print_r($data_stringh);
        // die;

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $APIURL);
        curl_setopt($ch, CURLOPT_ENCODING, "gzip");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Accept: application/json',
            'Content-Type: application/json',
            'Accept-Encoding: gzip',
            'SecurityKey:' . $SecurityKey,
            'Content-Length: ' . strlen($data_stringh)
        ));

        $response = curl_exec($ch);
        curl_close($ch);

        $resultSearch = json_decode($response, true);

        $ResponseStatus = isset($resultSearch['status']['success']) ? $resultSearch['status']['success'] : 0;
        $ErrorMessage = isset($resultSearch['errors'][0]['message']) ? $resultSearch['errors'][0]['message'] : '';


        return $resultSearch;
    }

    public function searchcitydata($keyword = null, $ICSourceSysId = null, $CountryName = null)
    {

        $query = urlencode(strtoupper($keyword));

        if (!empty(trim($query))) {
            if ($ICSourceSysId != 3) {
                if (!empty($CountryName)) {
                    $url = 'https://hotels.globaltravelexchange.com/api/v1/trip-jack-hotel-cities/?keywords=' . $query . '&CountryName=' . urlencode($CountryName);
                } else {
                    $url = 'https://hotels.globaltravelexchange.com/api/v1/trip-jack-hotel-cities/?keywords=' . $query;
                }
            } else {
                if (!empty($CountryName)) {
                    $url = 'https://hotels.globaltravelexchange.com/api/v1/tbo-hotel-cities/?CityName=' . $query . '&CountryName=' . urlencode($CountryName);
                } else {
                    $url = 'https://hotels.globaltravelexchange.com/api/v1/tbo-hotel-cities/?CityName=' . $query;
                }
            }
            $data = array(
                'CityName' => $query,
                'CountryName' => $CountryName
            );
            $data_stringh = json_encode($data);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Accept: application/json',
                'Content-Type: application/json',
                'Accept-Encoding: gzip',
                'Content-Length: ' . strlen($data_stringh)
            ));

            $outputH      = curl_exec($ch);
            if (curl_errno($ch)) {
                print(curl_error($ch));
                exit;
            }
            curl_close($ch);
            return json_decode($outputH, 1);
        }
    }


    public function apiHttpRequest($Request, $arrData, $url)
    {
        $SecurityKey = $arrData['SecurityKey'];
        $ICSourceSysId = isset($arrData['ICSourceSysId']) ? $arrData['ICSourceSysId'] : 0;
        if ($arrData) {
            $data_stringh = json_encode($Request);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_stringh);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Accept: application/json',
                'Content-Type: application/json',
                'Accept-Encoding: gzip',
                'SecurityKey: ' . $SecurityKey,
                'Content-Length: ' . strlen($data_stringh)
            ));
            $outputH = curl_exec($ch);
            $response = json_decode($outputH, true);
            // echo "<pre>";
            // print_r($outputH);
            // die();
            return $response;
        } else {
            return $response = [];
        }
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit