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/b2c.hellogtx.com/application/modules/detail/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/b2c.hellogtx.com/application/modules/detail/controllers/IndexController_18-05-21.php
<?php

class Detail_IndexController extends Zend_Controller_Action {

    public $baseUrl = '';
    public $AgencyId;
    protected $objMdl;
    protected $objHelperGeneral;
    protected $tablename;

    const USER_NAMESPACE = 'PSESS';

    public $_storage;
    public $packageSession;
    public $packageTypeStatic = 2;
    public $callusnumber;

    public function init() {

        $aConfig = $this->getInvokeArg('bootstrap')->getOptions();
        $BootStrap = $aConfig['bootstrap'];
        $this->siteName = $BootStrap['siteName'];
        $this->baseUrl = $BootStrap['siteUrl'];
        $this->gtxBtoBsite = $BootStrap['gtxBtoBsite'];
        $this->AgencyId = $BootStrap['gtxagencysysid'];
        $this->AgentSysId = $BootStrap['gtxagentsysid'];
        $this->LeadURL = $BootStrap['siteUrl'] . 'gtxwebservices/index/query';
        $object = Zend_Controller_Front::getInstance();
//        -------
        $this->modulename = $object->getRequest()->getModuleName();
        define('CONST_PACKAGE_TRAVELER_MAX_ROOM', $BootStrap['CONST_PACKAGE_TRAVELER_MAX_ROOM']);
        define('CONST_PACKAGE_TRAVELER_MAX_ADULT_IN_ROOM', $BootStrap['CONST_PACKAGE_TRAVELER_MAX_ADULT_IN_ROOM']);
        define('CONST_PACKAGE_TRAVELER_MAX_CHILD_IN_ROOM', $BootStrap['CONST_PACKAGE_TRAVELER_MAX_CHILD_IN_ROOM']);
        define('CONST_PACKAGE_TRAVELER_MAX_INFANT_IN_ROOM', $BootStrap['CONST_PACKAGE_TRAVELER_MAX_INFANT_IN_ROOM']);
//        -------


        $this->callusnumber = $BootStrap['callusnumber'];
        $this->tollfreenumber = $BootStrap['tollfreenumber'];
        $this->adminEmail = $BootStrap['adminEmail'];

        $this->objMdl = new Admin_Model_CRUD();
        $this->tablename = "tb_tbb2c_packages_master";
        $this->objHelperGeneral = $this->_helper->General;
        $this->_storage = new Zend_Session_Namespace(self::USER_NAMESPACE);
    }

    public function indexAction() {
        $params = $this->getRequest()->getParams();

        $this->view->CONST_PACKAGE_TRAVELER_MAX_ROOM = CONST_PACKAGE_TRAVELER_MAX_ROOM;
        $this->view->CONST_PACKAGE_TRAVELER_MAX_ADULT_IN_ROOM = CONST_PACKAGE_TRAVELER_MAX_ADULT_IN_ROOM;
        $this->view->CONST_PACKAGE_TRAVELER_MAX_CHILD_IN_ROOM = CONST_PACKAGE_TRAVELER_MAX_CHILD_IN_ROOM;
        $this->view->CONST_PACKAGE_TRAVELER_MAX_INFANT_IN_ROOM = CONST_PACKAGE_TRAVELER_MAX_INFANT_IN_ROOM;
        $this->view->modulename = $this->modulename;

        $paramsss = explode('-', trim($params['name'], '.html'));
        krsort($paramsss); // reverse sort the array to find all url param ids for fetching recor
        $listkeys = ['mp', 'tourtype', 'gtxid', 'catid', 'pkgid', 'destname']; // array of parameters

        $i = 0;
        foreach ($paramsss as $value) {
            if ($i == count($listkeys))
                break;
            $param[$listkeys[$i]] = $value;
            $i++;
        }

        $catId = isset($param['catid']) ? (int) $param['catid'] : '';
        $gtxId = isset($param['gtxid']) ? (int) $param['gtxid'] : '';
        $packageId = isset($param['pkgid']) ? (int) $param['pkgid'] : '';
        $tourtype = isset($param['tourtype']) ? (int) $param['tourtype'] : '';
        $mealplantype = (int) $param['mp'];
        $keywords = $param['destname'];

        $customize = (isset($param['customize'])) ? $param['customize'] : 0; // for customization [ 1 , 0]

        $this->view->mealplantype = $mealplantype;

        $model = new Detail_Model_PackageMapper();

        // check package for inactive case
        $checkPackaageSysID = $model->checkPackaageSysID($gtxId);
        //echo"<pre>";print_r($checkPackaageSysID);die;
        if (!empty($checkPackaageSysID)) {
            $packageId = $checkPackaageSysID['PkgSysId'];
        }

        $isModified = 0;

        if (isset($_SESSION['TravelAgent']['session']) && !empty($_SESSION['TravelAgent']['session'])) {
            $getDetail = $model->fetchDetails($catId, $gtxId, $packageId, 'B2B'); // 4th optional parameter [ B2B | B2C ]
        } else {
            $getDetail = $model->fetchDetails($catId, $gtxId, $packageId, 'B2C'); // 4th optional parameter [ B2B | B2C ]
        }
        if (empty($getDetail)) {
            $this->_redirect($this->baseUrl);
        }



        $PackageType = $getDetail['PackageType']; // get package type [ Readymade , Dynamic ]
//        $PackageSubType = $getDetail['PackageSubType']; // get package Sub type 
        $detail['PackageSubType'] = $getDetail['PackageSubType']; // get the package sub category
        // used for update package and send enquiry | category | meal plan change options
        if (isset($_SESSION['TravelAgent']['session']) && !empty($_SESSION['TravelAgent']['session'])) {
            $priceJsonViewFile = $this->objHelperGeneral->getCategoryAndPriceArrayJSON($getDetail['tourTypeFull'], 'B2B', $PackageType, $detail['PackageSubType']);
        } else {
            $priceJsonViewFile = $this->objHelperGeneral->getCategoryAndPriceArrayJSON($getDetail['tourTypeFull'], 'B2C', $PackageType, $detail['PackageSubType']);
        }
        //echo "<pre>";print_r($priceJsonViewFile);exit;
        $this->view->priceJsonViewFile = $priceJsonViewFile['priceArrJson'];

        $detail = $this->objHelperGeneral->createArrayDetailDynamic($getDetail, ['catid' => $catId, 'gtxid' => $gtxId, 'pkgid' => $packageId, 'tourtype' => $tourtype]);
        $detail['PackageSubType'] = $getDetail['PackageSubType']; // get the package sub category

        $detail['TPId'] = $getDetail['TPId']; // get tpid same for all in Dynamic package case
        $detail['Destinations'] = $getDetail['Destinations']; // get package destinations


        $CONST_MEAL_PLAN_ARR = unserialize(CONST_MEAL_PLAN_ARR);
        $detail['MPType'] = $CONST_MEAL_PLAN_ARR[$mealplantype]; // get package meal plan type
        //echo"<pre>";print_r($detail);die;
        $detail['hotels_array_included_only'] = $getDetail['hotels_array_included_only']; // get hotels included in all itineraries

        $detail['CategoriesArray'] = $priceJsonViewFile['priceArrJson'];  // override the variable here new version is included cp,ap,map plan prices too



        $priceArrJson = $detail['CategoriesArray'];
        $tourTypeChar = ($tourtype == 1) ? 'P' : 'G'; // if private than P else G for Group tour type
        $pkgprice = $this->objHelperGeneral->getPackagePriceV3(Catabatic_Helper::getPackageType($catId), $tourTypeChar, $priceArrJson, $mealplantype, true);  // Param 4: true ( if calculate discounted price )
        $pkgpriceDiscount = $this->objHelperGeneral->getPackagePriceV3(Catabatic_Helper::getPackageType($catId), $tourTypeChar, $priceArrJson, $mealplantype);  // Param 4: true ( if calculate discounted price )

        $detail['CategoriesArray']['NetPrice'] = $pkgprice;
        $detail['CategoriesArray']['DiscountNetPrice'] = $pkgpriceDiscount;
        $detail['PackageCategory'] = $getDetail['PackageCategory'];
        $detail['Image'] = $getDetail['Image'];
        $detail['DestinationsId'] = $getDetail['DestinationsId'];
        $detail['isFixedDeparture'] = $getDetail['isFixedDeparture'];

        if ($PackageType == $this->packageTypeStatic) {

            // get transfers array details 
            $TransfersArrayCar = $this->objHelperGeneral->getTransfersArray('car', $detail['TransfersMaster']);
            $OtherServicesArray = $this->objHelperGeneral->getTransfersArray('otherservices', $detail['OtherServices']);
//                    echo '<pre>'; print_r( $OtherServicesArray ); die;

            $customize = 1;

            if ($customize) {
                $sessionid = $this->objHelperGeneral->checksession((int) $packageId, $tourtype, $catId); // create the session

                if (!$sessionid) {
                    //                $this->PSESS_TIMESTAMP  = $sessionid;
                    $others = ['services' => $OtherServicesArray, 'transfers' => $TransfersArrayCar];
                    $this->objHelperGeneral->copysession($packageId, $tourtype, $catId, $detail['itinerariesArray'], $pkgprice, $others); // copy itinerary details to session
                }

                $detail['itinerariesArray'] = $this->_storage->packageSession[$packageId][$tourtype][$catId]['itineraries'];
            }
//            echo '<pre>'; print_r($detail['itinerariesArray']); die;


            @$isModified = $this->_storage->packageSession[$packageId][$tourtype][$catId]['others']['modified']; // get if the package is modified or not
            // show session price only if the package is modified
            if ($isModified) {
                $this->view->sessionPrice = $this->_storage->packageSession[$packageId][$tourtype][$catId]['others']['price'];
            }
        }

        // start : fetch related destinations here 

        $Destinations = $getDetail['Destinations']; // get the destination here

        $whereDestination = '';

        foreach (explode(',', $Destinations) as $key => $value) {
            $whereDestinationArr[] = $value;
        }



        $where = [
            'IsMarkForDel' => 0,
            'IsActive' => 1,
            'IsPublish' => 1,
            'ItemType' => 1 // for Tour Package 1
        ];

        // param conditions

        if (count($whereDestinationArr) > 0) {

            $str = $operator = '';
            foreach ($whereDestinationArr as $k => $val) {
                $operator = ($k != 0) ? ' OR ' : '';
                if ($val) {
                    $str .= " $operator ( Destinations LIKE ('%" . $val . "%') OR Countries LIKE ('%" . $val . "%') ) ";
                }
            }
            if ($str) {
                $whereDestination .= ' (' . $str . ') ';
            }
        }
        $whereCustom = " (1=1) and (`PkgSysId` <> '$packageId') ";
        $whereCustom .= ($whereDestination) ? " AND $whereDestination " : "";

        $currentTime = date('Y-m-d 00:00:00');

        $whereCustom .= " AND ( (`PkgValidFrom` <= '$currentTime') AND (`PkgValidUntil` >= '$currentTime') ) ";
        $whereCustom .= " AND ( `BookingValidUntil` >= '$currentTime')  ";

        $relatedPackages = $this->objMdl->rv_select_all_custom_query($this->tablename, ['Destinations', 'HotDeal', 'LongJsonInfo', 'StarRating', 'Nights', 'GTXPkgId', 'PackageType', 'Image', 'PkgSysId'], $where, $whereCustom, ['MinPrice' => 'ASC'], 4);
        // echo '<pre>';    print_r($relatedPackages);  die;
//        if (empty($relatedPackages)) {
//
//        $relatedPackages = $this->objMdl->rv_select_all('tb_tbb2c_packages_master', ['PkgSysId', 'Image', 'GTXPkgId', 'Destinations', 'Countries', 'BookingValidUntil', 'LongJsonInfo', 'Nights', 'StarRating', 'PackageType', 'PackageSubType','oldPrice'], ['IsActive' => 1, 'IsPublish' => 1, 'IsMarkForDel' => 0, 'ItemType' => 1, 'IsFeatured' => 1,'countryIds'=>101], ['PkgSysId' => 'DESC'], 20);
//       }
//        start : get package price here
        if (isset($_SESSION['TravelAgent']['session']) && !empty($_SESSION['TravelAgent']['session'])) {
            $relatedPackagesArray = $this->objHelperGeneral->getPackageCardDetails($relatedPackages, 'B2B');
        } else {
            $relatedPackagesArray = $this->objHelperGeneral->getPackageCardDetails($relatedPackages, 'B2C');
        }

//        end : get package price here
        // end : fetch related destinations here 
        // Get region id from destination table
        $whereCustomDes = (" FIND_IN_SET (Title, '" . $Destinations . "')");
        $whereDes = ['IsActive' => 1];
        $resultRegionId = $this->objMdl->rv_select_all_custom_query('tb_tbb2c_destinations', ['region_id'], $whereDes, $whereCustomDes, ['Title' => 'ASC'], 6);
        if ($resultRegionId) {
            $RegionId = array();
            foreach ($resultRegionId as $value) {
                $RegionId[] = $value['region_id'];
            }
        }
        $RegionId = array_unique($RegionId);

        if (trim($getDetail['Image']) != '') {

            $explodedImages = explode(',', $getDetail['Image']);
//    print_r($explodedImages); die;
            $countImages = count($explodedImages);
// print_r($countImages); die;
            $detail_image = array();
            foreach ($explodedImages as $explodedvalue) {
                $detail_image[] = $this->baseUrl . "public/upload/tours/" . $packageId . "/{size}/" . $explodedvalue;
            }
        } else {

            $detail_image[] = $getDetail['itementries']['ImgThumbnail'];
        }


        $this->view->hotel_image = $getDetail['hotelWebImage'];
        $this->view->detail_image = $detail_image;
        /* SEO KEYWORD */
        $itementriesName = strtolower($getDetail['itementries']['Name']);
        $detailLayout = array();
        $detailLayout['PackageTitle'] = $getDetail['itementries']['Name'] . ' (' . Catabatic_Helper::getPackageType($catId) . ') | ' . $Destinations . ' Tours Packages '; // get package name
        $detailLayout['Keyword'] = ($getDetail['Keyword'] != '') ? $getDetail['Keyword'] : $itementriesName . ' holiday packages, ' . $itementriesName . ' honeymoon packages, ' . $itementriesName . ' travel package, ' . $itementriesName . ' travel and tours, travel agency, ' . $itementriesName . ' vacation tours, ' . $itementriesName . ' deals on holiday, ' . $itementriesName . ' honeymoon deals, ' . $itementriesName . ' budget tour packages, ' . $itementriesName . ' destination packages, ' . $itementriesName . ' group tours, ' . $itementriesName . ' tour package, ' . $itementriesName . ' holiday tours, ' . $itementriesName . ' honeymoon tours.'; // get package Keyword
        $detailLayout['Description'] = ($getDetail['Description'] != '') ? $getDetail['Description'] : $getDetail['itementries']['Name'] . ' (' . Catabatic_Helper::getPackageType($catId) . ')- Book with us holiday and honeymoon packages and get great deals.'; // get package Description
        $detailLayout['metaTitle'] = (trim($getDetail['Metatag']) != '') ? $getDetail['Metatag'] : $detailLayout['PackageTitle']; // get package Metatag
        //echo "<pre>";print_r($detailLayout);die;
        $packageTheme = $this->objMdl->rv_select_all('tbl_pack_type', ['packType', 'Title'], ['IsActive' => 1], ['packType' => 'ASC']);
        //echo "<pre>";print_r($detail);die;
        $this->view->packageTheme = $packageTheme;
        $this->view->catId = $catId;
        $this->view->gtxId = $gtxId;
        $this->view->packageId = $packageId;
        $this->view->tourtype = $tourtype;
        $this->view->detail = $detail;
        $this->view->baseUrl = $this->baseUrl;
        $this->view->callusnumber = $this->callusnumber;
        $this->view->keywords = $keywords;
        $this->view->detailLayout = $detailLayout;
        $this->view->relatedPackages = $relatedPackagesArray;
        $this->view->resultExpert = $resultExpert;
        $this->view->isModified = $isModified;
        $this->view->params = $params;
        $this->view->actionurl = $this->baseUrl . 'detail/index/index/pkgid/' . $packageId . '/gtxid/' . $gtxId . '/catid/' . $catId . '/tourtype/' . $tourtype . '/';
    }

    public function indexAjaxTabAction() { 
        $params = $this->getRequest()->getParams();
        // print_r($params['tab']);die;
        $this->view->layout()->disableLayout();
        $this->view->CONST_PACKAGE_TRAVELER_MAX_ROOM = CONST_PACKAGE_TRAVELER_MAX_ROOM;
        $this->view->CONST_PACKAGE_TRAVELER_MAX_ADULT_IN_ROOM = CONST_PACKAGE_TRAVELER_MAX_ADULT_IN_ROOM;
        $this->view->CONST_PACKAGE_TRAVELER_MAX_CHILD_IN_ROOM = CONST_PACKAGE_TRAVELER_MAX_CHILD_IN_ROOM;
        $this->view->CONST_PACKAGE_TRAVELER_MAX_INFANT_IN_ROOM = CONST_PACKAGE_TRAVELER_MAX_INFANT_IN_ROOM;
        $this->view->modulename = $this->modulename;

        $paramsss = explode('-', trim($params['name'], '.html'));

        krsort($paramsss); // reverse sort the array to find all url param ids for fetching recor
        $listkeys = ['mp', 'tourtype', 'gtxid', 'catid', 'pkgid', 'destname']; // array of parameters

        $i = 0;
        foreach ($paramsss as $value) {
            if ($i == count($listkeys))
                break;
            $param[$listkeys[$i]] = $value;
            $i++;
        }

        $catId = isset($param['catid']) ? (int) $param['catid'] : '';
        $gtxId = isset($param['gtxid']) ? (int) $param['gtxid'] : '';
        $packageId = isset($param['pkgid']) ? (int) $param['pkgid'] : '';
        $tourtype = isset($param['tourtype']) ? (int) $param['tourtype'] : '';
        $mealplantype = (int) $param['mp'];
        $keywords = $param['destname'];

        $customize = (isset($param['customize'])) ? $param['customize'] : 0; // for customization [ 1 , 0]

        $this->view->mealplantype = $mealplantype;
        //print_r($mealplantype);die;
        $model = new Detail_Model_PackageMapper();

        // check package for inactive case
        $checkPackaageSysID = $model->checkPackaageSysID($gtxId);
        if (!empty($checkPackaageSysID)) {
            $packageId = $checkPackaageSysID['PkgSysId'];
        }

        $isModified = 0;

        if (isset($_SESSION['TravelAgent']['session']) && !empty($_SESSION['TravelAgent']['session'])) {
            $getDetail = $model->fetchDetails($catId, $gtxId, $packageId, 'B2B'); // 4th optional parameter [ B2B | B2C ]
        } else {
            $getDetail = $model->fetchDetails($catId, $gtxId, $packageId, 'B2C'); // 4th optional parameter [ B2B | B2C ]
        }
       // echo '<pre>';  print_r($getDetail);  die;

        if (!$getDetail) {
            
        }

        if (!$getDetail['tourType']) {
            $this->_redirect($this->baseUrl);
        }

        $PackageType = $getDetail['PackageType']; // get package type [ Readymade , Dynamic ]
//        $PackageSubType = $getDetail['PackageSubType']; // get package Sub type 
        $detail['PackageSubType'] = $getDetail['PackageSubType']; // get the package sub category
        // used for update package and send enquiry | category | meal plan change options
        if (isset($_SESSION['TravelAgent']['session']) && !empty($_SESSION['TravelAgent']['session'])) {
            $priceJsonViewFile = $this->objHelperGeneral->getCategoryAndPriceArrayJSON($getDetail['tourTypeFull'], 'B2B', $PackageType, $detail['PackageSubType']);
        } else {
            $priceJsonViewFile = $this->objHelperGeneral->getCategoryAndPriceArrayJSON($getDetail['tourTypeFull'], 'B2C', $PackageType, $detail['PackageSubType']);
        }
        //echo "<pre>";print_r($priceJsonViewFile);exit;
        $this->view->priceJsonViewFile = $priceJsonViewFile['priceArrJson'];

        $detail = $this->objHelperGeneral->createArrayDetailDynamic($getDetail, ['catid' => $catId, 'gtxid' => $gtxId, 'pkgid' => $packageId, 'tourtype' => $tourtype]);

        $detail['PackageSubType'] = $getDetail['PackageSubType']; // get the package sub category

        $detail['TPId'] = $getDetail['TPId']; // get tpid same for all in Dynamic package case
        $detail['Destinations'] = $getDetail['Destinations']; // get package destinations


        $CONST_MEAL_PLAN_ARR = unserialize(CONST_MEAL_PLAN_ARR);
        $detail['MPType'] = $CONST_MEAL_PLAN_ARR[$mealplantype]; // get package meal plan type

        $detail['hotels_array_included_only'] = $getDetail['hotels_array_included_only']; // get hotels included in all itineraries

        $detail['CategoriesArray'] = $priceJsonViewFile['priceArrJson'];  // override the variable here new version is included cp,ap,map plan prices too
        $detail['TransferDayData'] = $getDetail['TransferDayData'];  // override the variable here new version is included cp,ap,map plan prices too



        $priceArrJson = $detail['CategoriesArray'];
        $tourTypeChar = ($tourtype == 1) ? 'P' : 'G'; // if private than P else G for Group tour type
        $pkgprice = $this->objHelperGeneral->getPackagePriceV3(Catabatic_Helper::getPackageType($catId), $tourTypeChar, $priceArrJson, $mealplantype, true);  // Param 4: true ( if calculate discounted price )
        $pkgpriceDiscount = $this->objHelperGeneral->getPackagePriceV3(Catabatic_Helper::getPackageType($catId), $tourTypeChar, $priceArrJson, $mealplantype);  // Param 4: true ( if calculate discounted price )

        $detail['CategoriesArray']['NetPrice'] = $pkgprice;
        $detail['CategoriesArray']['DiscountNetPrice'] = $pkgpriceDiscount;
        $detail['PackageCategory'] = $getDetail['PackageCategory'];
        $detail['Image'] = $getDetail['Image'];
        $detail['DestinationsId'] = $getDetail['DestinationsId'];
        
        $detail['FlightData'] = $getDetail['FlightData'];

        if ($PackageType == $this->packageTypeStatic) {

            // get transfers array details 
            $TransfersArrayCar = $this->objHelperGeneral->getTransfersArray('car', $detail['TransfersMaster']);
            $OtherServicesArray = $this->objHelperGeneral->getTransfersArray('otherservices', $detail['OtherServices']);
//                    echo '<pre>'; print_r( $OtherServicesArray ); die;

            $customize = 1;

            if ($customize) {
                $sessionid = $this->objHelperGeneral->checksession((int) $packageId, $tourtype, $catId); // create the session

                if (!$sessionid) {
                    //                $this->PSESS_TIMESTAMP  = $sessionid;
                    $others = ['services' => $OtherServicesArray, 'transfers' => $TransfersArrayCar];
                    $this->objHelperGeneral->copysession($packageId, $tourtype, $catId, $detail['itinerariesArray'], $pkgprice, $others); // copy itinerary details to session
                }

                $detail['itinerariesArray'] = $this->_storage->packageSession[$packageId][$tourtype][$catId]['itineraries'];
            }


            @$isModified = $this->_storage->packageSession[$packageId][$tourtype][$catId]['others']['modified']; // get if the package is modified or not
            // show session price only if the package is modified
            if ($isModified) {
                $this->view->sessionPrice = $this->_storage->packageSession[$packageId][$tourtype][$catId]['others']['price'];
            }
        }

        // start : fetch related destinations here 

        $Destinations = $getDetail['Destinations']; // get the destination here

        $whereDestination = '';

        foreach (explode(',', $Destinations) as $key => $value) {
            $whereDestinationArr[] = $value;
        }



        $where = [
            'IsMarkForDel' => 0,
            'IsActive' => 1,
            'IsPublish' => 1,
            'ItemType' => 1 // for Tour Package 1
        ];

        // param conditions

        if (count($whereDestinationArr) > 0) {

            $str = $operator = '';
            foreach ($whereDestinationArr as $k => $val) {
                $operator = ($k != 0) ? ' OR ' : '';
                if ($val) {
                    $str .= " $operator ( Destinations LIKE ('%" . $val . "%') OR Countries LIKE ('%" . $val . "%') ) ";
                }
            }
            if ($str) {
                $whereDestination .= ' (' . $str . ') ';
            }
        }
        $whereCustom = " (1=1) and (`PkgSysId` <> '$packageId') ";
        $whereCustom .= ($whereDestination) ? " AND $whereDestination " : "";

        $currentTime = date('Y-m-d 00:00:00');

        $whereCustom .= " AND ( (`PkgValidFrom` <= '$currentTime') AND (`PkgValidUntil` >= '$currentTime') ) ";
        $whereCustom .= " AND ( `BookingValidUntil` >= '$currentTime')  ";

        $relatedPackages = $this->objMdl->rv_select_all_custom_query($this->tablename, ['Destinations', 'HotDeal', 'LongJsonInfo', 'StarRating', 'Nights', 'GTXPkgId', 'PackageType', 'Image', 'PkgSysId'], $where, $whereCustom, ['MinPrice' => 'ASC'], 4);

//        start : get package price here
        if (isset($_SESSION['TravelAgent']['session']) && !empty($_SESSION['TravelAgent']['session'])) {
            $relatedPackagesArray = $this->objHelperGeneral->getPackageCardDetails($relatedPackages, 'B2B');
        } else {
            $relatedPackagesArray = $this->objHelperGeneral->getPackageCardDetails($relatedPackages, 'B2C');
        }

//        end : get package price here
        // end : fetch related destinations here 
        // Get region id from destination table
        $whereCustomDes = (" FIND_IN_SET (Title, '" . $Destinations . "')");
        $whereDes = ['IsActive' => 1];
        $resultRegionId = $this->objMdl->rv_select_all_custom_query('tb_tbb2c_destinations', ['region_id'], $whereDes, $whereCustomDes, ['Title' => 'ASC'], 6);
        if ($resultRegionId) {
            $RegionId = array();
            foreach ($resultRegionId as $value) {
                $RegionId[] = $value['region_id'];
            }
        }
        $RegionId = array_unique($RegionId);

        if ($Destinations) {

            $selectTitle = explode(",", $Destinations);
            foreach ($selectTitle as $value) {
                $checkdata = $this->objMdl->selectOne('tb_tbb2c_destinations', ['Bannerimg', 'DesSysId'], ['Title' => $value]);
                if (!empty($checkdata['Bannerimg']) && !empty($checkdata)) {
                    $array[] = [
                        'Bannerimg' => $checkdata['Bannerimg'],
                        'DesSysId' => $checkdata['DesSysId'],
                    ];
                }
            }
            $this->view->bannerArray = $array;
            $this->view->DesSysId = $checkdata['DesSysId'];
        }
        $mealforhotel = $getDetail ['finalArray'] ['Hotel'][0]['Hotel'][0]['MealTypeName'];
        /* SEO KEYWORD */
        $detailLayout = array();
        $detailLayout['Keyword'] = $getDetail['Keyword']; // get package Keyword
        $detailLayout['Description'] = $getDetail['Description']; // get package Description
        $detailLayout['Metatag'] = $getDetail['Metatag']; // get package Metatag
        $detailLayout['PackageTitle'] = $getDetail['itementries']['Name'] . ' (' . Catabatic_Helper::getPackageType($catId) . ')'; // get package name

        $packageTheme = $this->objMdl->rv_select_all('tbl_pack_type', ['packType', 'Title'], ['IsActive' => 1], ['packType' => 'ASC']);
//        echo "<pre>";print_r($packageTheme);die;
        $activeHotel = $params['hotel_type'];
        $activeTab = $params['tab'];
        $this->view->activeHotel = $activeHotel;
        $this->view->activeTab = $activeTab;
        $this->view->packageTheme = $packageTheme;
        $this->view->catId = $catId;
        $this->view->gtxId = $gtxId;
        $this->view->packageId = $packageId;
        $this->view->tourtype = $tourtype;
        $this->view->mealforhotel = $mealforhotel;
        $this->view->detail = $detail;
        $this->view->baseUrl = $this->baseUrl;
        $this->view->callusnumber = $this->callusnumber;
        $this->view->keywords = $keywords;
        $this->view->detailLayout = $detailLayout;
        $this->view->relatedPackages = $relatedPackagesArray;
        $this->view->resultExpert = $resultExpert;
        $this->view->isModified = $isModified;
        $this->view->params = $params;
        $this->view->actionurl = $this->baseUrl . 'detail/index/index/pkgid/' . $packageId . '/gtxid/' . $gtxId . '/catid/' . $catId . '/tourtype/' . $tourtype . '/';
    }

    public function indexAjaxDataAction() {
        $params = $this->getRequest()->getParams();

        $this->view->layout()->disableLayout();
        $this->view->CONST_PACKAGE_TRAVELER_MAX_ROOM = CONST_PACKAGE_TRAVELER_MAX_ROOM;
        $this->view->CONST_PACKAGE_TRAVELER_MAX_ADULT_IN_ROOM = CONST_PACKAGE_TRAVELER_MAX_ADULT_IN_ROOM;
        $this->view->CONST_PACKAGE_TRAVELER_MAX_CHILD_IN_ROOM = CONST_PACKAGE_TRAVELER_MAX_CHILD_IN_ROOM;
        $this->view->CONST_PACKAGE_TRAVELER_MAX_INFANT_IN_ROOM = CONST_PACKAGE_TRAVELER_MAX_INFANT_IN_ROOM;
        $this->view->modulename = $this->modulename;

        $paramsss = explode('-', trim($params['name'], '.html'));
        krsort($paramsss); // reverse sort the array to find all url param ids for fetching recor
        $listkeys = ['mp', 'tourtype', 'gtxid', 'catid', 'pkgid', 'destname']; // array of parameters

        $i = 0;
        foreach ($paramsss as $value) {
            if ($i == count($listkeys))
                break;
            $param[$listkeys[$i]] = $value;
            $i++;
        }

        $catId = isset($param['catid']) ? (int) $param['catid'] : '';
        $gtxId = isset($param['gtxid']) ? (int) $param['gtxid'] : '';
        $packageId = isset($param['pkgid']) ? (int) $param['pkgid'] : '';
        $tourtype = isset($param['tourtype']) ? (int) $param['tourtype'] : '';
        $mealplantype = (int) $param['mp'];
        $keywords = $param['destname'];

        $customize = (isset($param['customize'])) ? $param['customize'] : 0; // for customization [ 1 , 0]

        $this->view->mealplantype = $mealplantype;

        $model = new Detail_Model_PackageMapper();

        // check package for inactive case
        $checkPackaageSysID = $model->checkPackaageSysID($gtxId);
        if (!empty($checkPackaageSysID)) {
            $packageId = $checkPackaageSysID['PkgSysId'];
        }

        $isModified = 0;

        if (isset($_SESSION['TravelAgent']['session']) && !empty($_SESSION['TravelAgent']['session'])) {
            $getDetail = $model->fetchDetails($catId, $gtxId, $packageId, 'B2B'); // 4th optional parameter [ B2B | B2C ]
        } else {
            $getDetail = $model->fetchDetails($catId, $gtxId, $packageId, 'B2C'); // 4th optional parameter [ B2B | B2C ]
        }

//        echo "<pre>";print_r($getDetail['PackageCategory']);die;
        if (!$getDetail) {
            
        }

        if (!$getDetail['tourType']) {
            $this->_redirect($this->baseUrl);
        }

        $PackageType = $getDetail['PackageType']; // get package type [ Readymade , Dynamic ]
//        $PackageSubType = $getDetail['PackageSubType']; // get package Sub type 
        $detail['PackageSubType'] = $getDetail['PackageSubType']; // get the package sub category
        // used for update package and send enquiry | category | meal plan change options
        if (isset($_SESSION['TravelAgent']['session']) && !empty($_SESSION['TravelAgent']['session'])) {
            $priceJsonViewFile = $this->objHelperGeneral->getCategoryAndPriceArrayJSON($getDetail['tourTypeFull'], 'B2B', $PackageType, $detail['PackageSubType']);
        } else {
            $priceJsonViewFile = $this->objHelperGeneral->getCategoryAndPriceArrayJSON($getDetail['tourTypeFull'], 'B2C', $PackageType, $detail['PackageSubType']);
        }
        //echo "<pre>";print_r($priceJsonViewFile);exit;
        $this->view->priceJsonViewFile = $priceJsonViewFile['priceArrJson'];

        $detail = $this->objHelperGeneral->createArrayDetailDynamic($getDetail, ['catid' => $catId, 'gtxid' => $gtxId, 'pkgid' => $packageId, 'tourtype' => $tourtype]);

        $detail['PackageSubType'] = $getDetail['PackageSubType']; // get the package sub category

        $detail['TPId'] = $getDetail['TPId']; // get tpid same for all in Dynamic package case
        $detail['Destinations'] = $getDetail['Destinations']; // get package destinations


        $CONST_MEAL_PLAN_ARR = unserialize(CONST_MEAL_PLAN_ARR);
        $detail['MPType'] = $CONST_MEAL_PLAN_ARR[$mealplantype]; // get package meal plan type

        $detail['hotels_array_included_only'] = $getDetail['hotels_array_included_only']; // get hotels included in all itineraries

        $detail['CategoriesArray'] = $priceJsonViewFile['priceArrJson'];  // override the variable here new version is included cp,ap,map plan prices too



        $priceArrJson = $detail['CategoriesArray'];
        $tourTypeChar = ($tourtype == 1) ? 'P' : 'G'; // if private than P else G for Group tour type
        $pkgprice = $this->objHelperGeneral->getPackagePriceV3(Catabatic_Helper::getPackageType($catId), $tourTypeChar, $priceArrJson, $mealplantype, true);  // Param 4: true ( if calculate discounted price )
        $pkgpriceDiscount = $this->objHelperGeneral->getPackagePriceV3(Catabatic_Helper::getPackageType($catId), $tourTypeChar, $priceArrJson, $mealplantype);  // Param 4: true ( if calculate discounted price )

        $detail['CategoriesArray']['NetPrice'] = $pkgprice;
        $detail['CategoriesArray']['DiscountNetPrice'] = $pkgpriceDiscount;
        $detail['PackageCategory'] = $getDetail['PackageCategory'];
        $detail['Image'] = $getDetail['Image'];
        $detail['DestinationsId'] = $getDetail['DestinationsId'];

        if ($PackageType == $this->packageTypeStatic) {

            // get transfers array details 
            $TransfersArrayCar = $this->objHelperGeneral->getTransfersArray('car', $detail['TransfersMaster']);
            $OtherServicesArray = $this->objHelperGeneral->getTransfersArray('otherservices', $detail['OtherServices']);
//                    echo '<pre>'; print_r( $OtherServicesArray ); die;

            $customize = 1;

            if ($customize) {
                $sessionid = $this->objHelperGeneral->checksession((int) $packageId, $tourtype, $catId); // create the session

                if (!$sessionid) {
                    //                $this->PSESS_TIMESTAMP  = $sessionid;
                    $others = ['services' => $OtherServicesArray, 'transfers' => $TransfersArrayCar];
                    $this->objHelperGeneral->copysession($packageId, $tourtype, $catId, $detail['itinerariesArray'], $pkgprice, $others); // copy itinerary details to session
                }

                $detail['itinerariesArray'] = $this->_storage->packageSession[$packageId][$tourtype][$catId]['itineraries'];
            }


            @$isModified = $this->_storage->packageSession[$packageId][$tourtype][$catId]['others']['modified']; // get if the package is modified or not
            // show session price only if the package is modified
            if ($isModified) {
                $this->view->sessionPrice = $this->_storage->packageSession[$packageId][$tourtype][$catId]['others']['price'];
            }
        }

        // start : fetch related destinations here 

        $Destinations = $getDetail['Destinations']; // get the destination here

        $whereDestination = '';

        foreach (explode(',', $Destinations) as $key => $value) {
            $whereDestinationArr[] = $value;
        }



        $where = [
            'IsMarkForDel' => 0,
            'IsActive' => 1,
            'IsPublish' => 1,
            'ItemType' => 1 // for Tour Package 1
        ];

        // param conditions

        if (count($whereDestinationArr) > 0) {

            $str = $operator = '';
            foreach ($whereDestinationArr as $k => $val) {
                $operator = ($k != 0) ? ' OR ' : '';
                if ($val) {
                    $str .= " $operator ( Destinations LIKE ('%" . $val . "%') OR Countries LIKE ('%" . $val . "%') ) ";
                }
            }
            if ($str) {
                $whereDestination .= ' (' . $str . ') ';
            }
        }
        $whereCustom = " (1=1) and (`PkgSysId` <> '$packageId') ";
        $whereCustom .= ($whereDestination) ? " AND $whereDestination " : "";

        $currentTime = date('Y-m-d 00:00:00');

        $whereCustom .= " AND ( (`PkgValidFrom` <= '$currentTime') AND (`PkgValidUntil` >= '$currentTime') ) ";
        $whereCustom .= " AND ( `BookingValidUntil` >= '$currentTime')  ";

        $relatedPackages = $this->objMdl->rv_select_all_custom_query($this->tablename, ['Destinations', 'HotDeal', 'LongJsonInfo', 'StarRating', 'Nights', 'GTXPkgId', 'PackageType', 'Image', 'PkgSysId'], $where, $whereCustom, ['MinPrice' => 'ASC'], 4);

//        start : get package price here
        if (isset($_SESSION['TravelAgent']['session']) && !empty($_SESSION['TravelAgent']['session'])) {
            $relatedPackagesArray = $this->objHelperGeneral->getPackageCardDetails($relatedPackages, 'B2B');
        } else {
            $relatedPackagesArray = $this->objHelperGeneral->getPackageCardDetails($relatedPackages, 'B2C');
        }

//        end : get package price here
        // end : fetch related destinations here 
        // Get region id from destination table
        $whereCustomDes = (" FIND_IN_SET (Title, '" . $Destinations . "')");
        $whereDes = ['IsActive' => 1];
        $resultRegionId = $this->objMdl->rv_select_all_custom_query('tb_tbb2c_destinations', ['region_id'], $whereDes, $whereCustomDes, ['Title' => 'ASC'], 6);
        if ($resultRegionId) {
            $RegionId = array();
            foreach ($resultRegionId as $value) {
                $RegionId[] = $value['region_id'];
            }
        }
        $RegionId = array_unique($RegionId);

        if ($Destinations) {

            $selectTitle = explode(",", $Destinations);
            foreach ($selectTitle as $value) {
                $checkdata = $this->objMdl->selectOne('tb_tbb2c_destinations', ['Bannerimg', 'DesSysId'], ['Title' => $value]);
                if (!empty($checkdata['Bannerimg']) && !empty($checkdata)) {
                    $array[] = [
                        'Bannerimg' => $checkdata['Bannerimg'],
                        'DesSysId' => $checkdata['DesSysId'],
                    ];
                }
            }
            $this->view->bannerArray = $array;
            $this->view->DesSysId = $checkdata['DesSysId'];
        }

        /* SEO KEYWORD */
        $detailLayout = array();
        $detailLayout['Keyword'] = $getDetail['Keyword']; // get package Keyword
        $detailLayout['Description'] = $getDetail['Description']; // get package Description
        $detailLayout['Metatag'] = $getDetail['Metatag']; // get package Metatag
        $detailLayout['PackageTitle'] = $getDetail['itementries']['Name'] . ' (' . Catabatic_Helper::getPackageType($catId) . ')'; // get package name

        $packageTheme = $this->objMdl->rv_select_all('tbl_pack_type', ['packType', 'Title'], ['IsActive' => 1], ['packType' => 'ASC']);
//        echo "<pre>";print_r($packageTheme);die;
        $this->view->packageTheme = $packageTheme;
        $this->view->catId = $catId;
        $this->view->gtxId = $gtxId;
        $this->view->packageId = $packageId;
        $this->view->tourtype = $tourtype;
        $this->view->detail = $detail;
        $this->view->baseUrl = $this->baseUrl;
        $this->view->callusnumber = $this->callusnumber;
        $this->view->keywords = $keywords;
        $this->view->detailLayout = $detailLayout;
        $this->view->relatedPackages = $relatedPackagesArray;
        $this->view->resultExpert = $resultExpert;
        $this->view->isModified = $isModified;
        $this->view->params = $params;
        $this->view->actionurl = $this->baseUrl . 'detail/index/index/pkgid/' . $packageId . '/gtxid/' . $gtxId . '/catid/' . $catId . '/tourtype/' . $tourtype . '/';
    }

    public function sendQueryAction() {

        $this->_helper->layout()->disableLayout('');
        $this->_helper->viewRenderer->setNoRender(true);
        if ($this->getRequest()->isPost()) {

            $param = $this->getRequest()->getParams();

//            echo '<pre>'; print_r($param); die;
            //check if any of the inputs are empty
            if (empty($param['inputName']) || empty($param['inputEmail']) || empty($param['inputPhone']) || empty($param['inputMessage'])) {
                $result = ['status' => false, 'message' => 'Please fill out the form completely.'];
            } else {

                $DestinationID = '';
                $Destinations = '';
                $roomjson = '';

                $this->postFields = "";
                $this->postFields .= "&AgencySysId=" . $this->AgencyId;
                $this->postFields .= "&TravelPlanId=" . $param['TravelPlanId'];
                $this->postFields .= "&FirstName=" . $param['inputName'];
                $this->postFields .= "&LastName=";
                $this->postFields .= "&Email=" . $param['inputEmail'];
                $this->postFields .= "&MobileNumber=" . $param['inputPhone'];
                $this->postFields .= "&PriceRange=" . $param['PriceRange']; // 2000-50000
                $this->postFields .= "&PKGCheckInDate=" . $param['PKGCheckInDate']; // 12/08/2017
                $this->postFields .= "&PKGCheckOutDate=" . $param['PKGCheckOutDate']; // 19/08/2017
                $this->postFields .= "&MinPrice=" . $param['MinPrice']; // 2000
                $this->postFields .= "&MaxPrice=" . $param['MaxPrice']; // 50000
                $this->postFields .= "&DestinationID=" . $DestinationID; // destination id
                $this->postFields .= "&Destination=" . $Destinations; // destination value
                $this->postFields .= "&roomjson=" . $roomjson; // destination value

                try {
                    $model = new Gtxwebservices_Model_Webservices();
                    $getPackagesData = $model->sendQuery($this->postFields);
//                    print_r($getPackagesData); die;
                    $message = "Your query has been sent successfully.";
                    $status = true;
                } catch (Zend_Exception $error) {
                    $message = $this->view->error_msg = $error->getMessage();
                    $status = false;
                }
                $result = ['status' => $status, 'message' => $message];
            }
        } else {

            $result = ['status' => false, 'message' => 'Invalid Request!'];
        }

        echo Zend_Json::encode($result);
        exit;
    }

    public function getCustomizeDynamicPackageDetailAction() {
        $this->_helper->layout()->disableLayout();
        if ($this->getRequest()->isXmlHttpRequest()) {
            if ($this->getRequest()->isPost()) {
                $param = $this->getRequest()->getParams();
                $CONST_PACKAGE_CAT = unserialize(CONST_PACKAGE_CAT);
                // print_r($param); die;
                $SourcePlaceSysId = trim($param['SourcePlaceSysId']);
                // echo $SourcePlaceSysId ; die;
                $DestinationPlacesSysId = trim($param['DestinationPlacesSysId']);
                // echo $SourcePlaceSysId; die;

                $NoofNights = trim($param['NoofNights']);
                // echo $NoofNights; die;
                $DestinationsIds = trim($param['DestinationsIds']);
                $DestinationsIds = explode(',', $DestinationsIds);

                $adults = 0;
                $childs = 0;
                $infants = 0;
                $roomJsonInfo = array();
                for ($i = 0; $i < $param['room']; $i++) {
                    $adults += $param['Adult'][$i];
                    $childs += $param['Child'][$i];
                    $roomJsonInfo[$i]['Adult'] = $param['Adult'][$i];
                    $roomJsonInfo[$i]['Child'] = $param['Child'][$i];
                    $roomJsonInfo[$i]['infent'] = 0;
                }
                // echo "<pre>";print_r($roomJsonInfo);die;

                $destinationCity = (int) $DestinationsIds[0];
                $adults = (int) $adults;
                $child = (int) $childs;
                $infent = (int) $infants;
                $destIndex = (int) 1;
                $date = $this->getRequest()->getParam('date');
                $getcheckInExplode = explode('/', $date);
                $getcheckIn = $getcheckInExplode[2] . '-' . $getcheckInExplode[1] . '-' . $getcheckInExplode[0];
                $getcheckOut = date('Y-m-d', strtotime($getcheckIn . ' + ' . ($NoofNights) . ' days'));
                $refId = 'eyJUIjoiMTciLCJEIjp7IjkyIjp7IkRlc0lkIjoiNjU2MSIsIlNlcSI6IjEifX19';
                $model = new Travel_Model_HotelMaster();
                $hotelids = isset($param['hotelid']) ? $param['hotelid'] : '';
                $hotelCategory = isset($param['hotelcategoryid']) ? $CONST_PACKAGE_CAT[$param['hotelcategoryid']] : '';

                $hotelidsArr = array();

                // $hotelidsArr = json_decode($hotelids, 1);
                // echo $hotelidsArr['night'][0]; die;

                if ($hotelids != '') {
                    $hotelidsArr = json_decode($hotelids, 1);
                    // print_r($hotelidsArr); die;
                }
                $hotelDataById = array();
                if (!empty($hotelidsArr['haid'][0])) {
                    $hotelDataById = $model->getHotelByHotelid("tb_tbb2c_packages_master", implode(',', $hotelidsArr['haid']), implode(',', $hotelidsArr['night']), implode(',', $hotelidsArr['ROOMTYPE']), implode(',', $hotelidsArr['MEALPLANTYPE']), $getcheckIn, json_encode($roomJsonInfo), $DestinationsIds, $param['package_destination_night_detail']);
                }

                // echo "<pre>";print_r($hotelDataById);die;    
                // echo $SourcePlaceSysId.' '.$DestinationPlacesSysId.' '.$NoofNights;die;
                $TransportRouteData = $model->getAutosuggestTransportRouteData($SourcePlaceSysId, $DestinationPlacesSysId, $NoofNights);
                $transportFinalArray = array();
                foreach ($TransportRouteData as $tKey => $tVal) {
                    $category = json_decode($tVal['category'], 1);
                    foreach ($category as $cKey => $cVal) {
                        $transportFinalArray[$cVal['RouteVechSysId']]['RouteSysId'] = $tVal['RouteSysId'];
                        $transportFinalArray[$cVal['RouteVechSysId']]['RouteName'] = $tVal['RouteName'];
                        $transportFinalArray[$cVal['RouteVechSysId']]['StartCitySysId'] = $tVal['StartCitySysId'];
                        $transportFinalArray[$cVal['RouteVechSysId']]['EndCitySysId'] = $tVal['EndCitySysId'];
                        $transportFinalArray[$cVal['RouteVechSysId']]['Noofnights'] = $tVal['Noofnights'];
                        $transportFinalArray[$cVal['RouteVechSysId']]['CityName'] = $tVal['CityName'];
                        $transportFinalArray[$cVal['RouteVechSysId']]['EndCityName'] = $tVal['EndCityName'];
                        $transportFinalArray[$cVal['RouteVechSysId']]['RouteVechSysId'] = $cVal['RouteVechSysId'];
                        $transportFinalArray[$cVal['RouteVechSysId']]['VehicleSysId'] = $cVal['VehicleSysId'];
                        $transportFinalArray[$cVal['RouteVechSysId']]['VehicleTypeSysId'] = $cVal['VehicleTypeSysId'];
                        $transportFinalArray[$cVal['RouteVechSysId']]['Cost'] = Catabatic_Helper::calculateMarkup($cVal['Cost']);
                        $transportFinalArray[$cVal['RouteVechSysId']]['Capacity'] = $cVal['Capacity'];
                        $transportFinalArray[$cVal['RouteVechSysId']]['CurrencyType'] = $cVal['CurrencyType'];
                        $transportFinalArray[$cVal['RouteVechSysId']]['SupplierName'] = $cVal['SupplierName'];
                        $transportFinalArray[$cVal['RouteVechSysId']]['VehName'] = $cVal['VehName'];
                        $transportFinalArray[$cVal['RouteVechSysId']]['VehicleTypeName'] = $cVal['VehicleTypeName'];
                        $transportFinalArray[$cVal['RouteVechSysId']]['CurrencySymbol'] = $cVal['CurrencySymbol'];
                        $transportFinalArray[$cVal['RouteVechSysId']]['cityIncludes'] = $tVal['cityIncludes'];
                    }
                }
                // print_r($transportFinalArray); die;
                // echo "<pre>";print_r($hotelDataById);die;

                if (!empty($hotelDataById)) {
                    $hotelDataById = $hotelDataById;
                    // print_r($hotelDataById); die("test this"); 
                } else {
                    $package_destination_night_detail = (isset($param['package_destination_night_detail']) && $param['package_destination_night_detail'] != '') ? json_decode($param['package_destination_night_detail'], 1) : '';
                    if (!empty($package_destination_night_detail)) {
                        $checkInDate = $getcheckIn;
                        foreach ($package_destination_night_detail as $pkKey => $pkVal) {
                            $NoofNights = $pkVal['nights'];

                            $checkOutDate = date('Y-m-d', strtotime($checkInDate . ' + ' . ($NoofNights) . ' days'));
                            $hotelDataById[] = array(
                                'destIndex' => $pkKey + 1,
                                'refId' => @$refId,
                                'NoofNights' => $pkVal['nights'],
                                'GTXPkgId' => 121212 + $pkKey,
                                'DestinationId' => $pkVal['cityId'],
                                'Destinations' => $pkVal['title'],
                                'ContSysId' => $pkVal['CountryIds'],
                                'checkInDate' => $checkInDate,
                                'checkOutDate' => $checkOutDate,
                                'isPrice' => 0,
                            );
                            $checkInDate = $checkOutDate;
                        }
                    }
                }
                // echo "<pre>";print_r($hotelDataById);die;
                $this->view->transportFinalArray = $transportFinalArray;
                $this->view->hotellist = $hotelDataById;
                $this->view->hotelCategory = $hotelCategory;
                $this->view->param = $param;
                $this->view->adults = $adults;
                $this->view->childs = $childs;
            }
        }
    }

    public function getHotelListAction() {
        $this->_helper->layout()->disableLayout();

        if ($this->getRequest()->isXmlHttpRequest()) {

            if ($this->getRequest()->isPost()) {
                $param = $this->getRequest()->getParams();
//               echo "<pre>";print_r($param);die;
                $NoofNights = 2;
                $DestinationsIds = $param['DestinationsId'];
                $hotelId = $param['hotelId'];
                $Price = $param['Price'];

                $adults = 0;
                $childs = 0;
                $infants = 0;
                $roomJsonInfo = array();
                for ($i = 0; $i < $param['room']; $i++) {
                    $adults += $param['Adult'][$i];
                    $childs += $param['Child'][$i];
                    $roomJsonInfo[$i]['Adult'] = $param['Adult'][$i];
                    $roomJsonInfo[$i]['Child'] = $param['Child'][$i];
                    $roomJsonInfo[$i]['infent'] = 0;
                }
                $destinationCity = (int) $DestinationsIds;
                $adults = (int) $adults;
                $child = (int) $childs;
                $infent = (int) $infants;
                $destIndex = (int) 1;
                $checkInDate = $this->getRequest()->getParam('checkInDate');
                $checkOutDate = $this->getRequest()->getParam('checkOutDate');

                $refId = 'eyJUIjoiMTciLCJEIjp7IjkyIjp7IkRlc0lkIjoiNjU2MSIsIlNlcSI6IjEifX19';
                $model = new Travel_Model_HotelMaster();

                $hotelData = $model->getHotel($destinationCity, "tb_tbb2c_packages_master", $checkInDate, $checkOutDate, $adults, $child, $infent, $refId, $destIndex, json_encode($roomJsonInfo));
//                 echo "<pre>";print_r(json_decode(base64_decode($hotelData[0]['checkPlan'])));die;
//                 echo "<pre>";print_r($hotelData);die;
                $this->view->hotellist = $hotelData;
                $this->view->hotelId = $hotelId;
                $this->view->Price = $Price;
            }
        }
    }

    public function getHotelDataByIdAction() {
        $this->_helper->layout()->disableLayout();
        if ($this->getRequest()->isXmlHttpRequest()) {
            if ($this->getRequest()->isPost()) {
                $param = $this->getRequest()->getParams();
                // print_r($param); die;
                $hotelData = json_decode(base64_decode($param['hotelJson']), 1);
//                    echo "<pre>";print_r($hotelData);die;
                $this->view->hotelData = $hotelData;
                $this->view->prehotelId = $param['prehotelId'];
            }
        }
    }

    public function saveCustomizeDynamicDataAction() {
        $this->_helper->layout()->disableLayout();
        if ($this->getRequest()->isXmlHttpRequest()) {
            if ($this->getRequest()->isPost()) {
                $param = $this->getRequest()->getParams();
                // print_r($param); die;
                $package_hotelcategoryid = $param['hotelcategoryid'];
                $destinationNameIdArr = $hotelDataArr = array();
                $DestinationPlacesArr = array();

                $hotelPrice = !empty($param['hotelPrice']) ? $param['hotelPrice'] : 0;
                $finalHotelPrice = 0;
                foreach ($hotelPrice as $hpKey => $hpVal) {
                    $finalHotelPrice += (int) $hpVal;
                }
                $inc = 1;
                foreach ($param['Destinations'] as $dKey => $dVal) {
                    $DestinationPlacesArr[$param['DestinationId'][$dKey]] = $dVal;

                    for ($n = 0; $n < $param['NoofNights'][$dKey]; $n++) {
                        $destinationNameIdArr[$inc]['DestinationId'] = $param['DestinationId'][$dKey];
                        $destinationNameIdArr[$inc]['Destinations'] = $param['Destinations'][$dKey];
                        $destinationNameIdArr[$inc]['ContSysId'] = isset($param['ContSysId'][0]) ? (int) $param['ContSysId'][0] : 101;
                        $hotelDataArr[$inc]['hidden_selected_hotel_id'] = $param['hotelId'][$dKey];
                        $hotelDataArr[$inc]['mealType'] = $param['MEALPLANTYPEE'][$dKey];
                        $hotelDataArr[$inc]['hotelRoomType'] = $param['ROOMTYPEE'][$dKey];
                        $hotelDataArr[$inc]['hotelName'] = $param['hotelName'][$dKey];
                        $hotelDataArr[$inc]['HotelCityId'] = $param['DestinationId'][$dKey];
                        $hotelDataArr[$inc]['NoofNights'] = $param['NoofNights'][$dKey];
                        $hotelDataArr[$inc]['FromDate'] = $param['checkInDate'][$dKey];
                        $hotelDataArr[$inc]['ToDate'] = $param['checkOutDate'][$dKey];

                        $inc++;
                    }
                }
                $destinationNameIdArr[$inc]['DestinationId'] = $param['DestinationPlacesSysId'];
                $destinationNameIdArr[$inc]['Destinations'] = $param['DestinationPlaces'];
                $destinationNameIdArr[$inc]['ContSysId'] = $param['ContSysId'][0];
                //echo "<pre>";print_r($destinationNameIdArr);die('here');
                $DestinationPlaces = json_encode($DestinationPlacesArr);
                $DestinationID = $param['DestinationPlacesSysId'];
                $Destinations = $param['DestinationPlaces'];
                $pkgCheckinDate = json_decode($param['date']);
                $pkgCheckoutDate = $this->objHelperGeneral->dateAddDays(json_decode($param['date']), array_sum($param['NoofNights']));
                $adult = json_decode($param['Adult'], 1);
                $child = json_decode($param['Child'], 1);
                $roominfojson = [];

                for ($i = 0, $k = 1; $k <= 9; $k++, $i++) {

                    if (trim($adult[$i]) != 0 || trim($child[$i]) != 0) {

                        $roominfojson[$k]['Adult'] = $adult[$i];
                        $roominfojson[$k]['Child'] = $child[$i];
                        $roominfojson[$k]['Infant'] = isset($param['infant'][$i]) ? $param['infant'][$i] : 0;
                        $noOfAdultsar[$k] = $adult[$i];
                        $noOfInfantar[$k] = isset($param['infant'][$i]) ? $param['infant'][$i] : 0;
                        ;

                        if ($adult[$i] == 3) {
                            $roominfojson[$k]['AdultBedType'] = $param['adult_bed_type'][$i];
                        }
                        if ($child[$i] > 0) {
                            for ($c = 1; $c <= $child[$i]; $c++) {
                                $roominfojson[$k]['ChildBedType_' . $c] = $param['child' . $c . '_bed_type'][$i];
                                $roominfojson[$k]['ChildAge_' . $c] = '';
                                $selectnoOfChildar[$k] = $child[$i];
                            }
                        }
                    }
                }

                for ($k = 1; $k <= count($roominfojson); $k++) {
                    $roominfojson[$k]['departuredate'] = $pkgCheckinDate;
                    $roominfojson[$k]['returndate'] = $pkgCheckoutDate;
                }
                $dayView = array();
                $resultSet = $this->objMdl->rv_select_all('tb_tbb2c_packages_master', ['*'], ['GTXPkgId' => $param['gtxpackage'], 'IsActive' => 1, 'IsMarkForDel' => 0, 'PkgSysId' => $param['pkg']], ['PkgSysId' => 'ASC']);
                $LongJsonInfo = json_decode($resultSet[0]['LongJsonInfo'], 1);
                foreach ($LongJsonInfo as $itinerariesDayVise) {
                    $finalArray = array();
                    foreach ($itinerariesDayVise['Itineraries']['Itinerary'] as $dayViewVal) {

                        $dayView[$dayViewVal['Day']]['day'] = $dayViewVal['Day'];
                        $dayView[$dayViewVal['Day']]['Title'] = $dayViewVal['Title'];
                        $dayView[$dayViewVal['Day']]['Program'] = $dayViewVal['Program'];
                        $dayView[$dayViewVal['Day']]['CityName'] = $destinationNameIdArr[$dayViewVal['Day']]['Destinations'];
                        $dayView[$dayViewVal['Day']]['CityId'] = $destinationNameIdArr[$dayViewVal['Day']]['DestinationId'];
                        $dayView[$dayViewVal['Day']]['ContId'] = $destinationNameIdArr[$dayViewVal['Day']]['ContSysId'];
                        $dayView[$dayViewVal['Day']]['Sightseeings'] = $dayViewVal['ItineraryItem'][3];
                    }
                    foreach ($itinerariesDayVise['Cities']['City'] as $finalData) {
                        $finalArray['SightSeeings'][] = $finalData['SightSeeings'];
                    }
                }
                $finalArraySightDaywise = $finalArraySightTransport = array();
                foreach ($dayView as $itKey => $itinerariesItem1) {
                    $itinerariesItem = $itinerariesItem1['Sightseeings'];
                    $itinerariesItem = ( isset($itineraries['repeat']) && $itineraries['repeat'] == 1 ) ? $itinerariesItem[0] : $itinerariesItem;
                    if (!empty($itinerariesItem['Items']['0']['Item'])) {
                        foreach ($itinerariesItem['Items']['0']['Item'] as $itinerariesActivity) {
                            if ($itinerariesActivity['IsIncluded'] == 1) {
                                if ($itinerariesItem['Type'] == 'SIGHTSEEING') {
                                    foreach ($finalArray['SightSeeings'] as $finalSightSeeing => $valfinalSightSeeing) {
                                        if (isset($valfinalSightSeeing['SightSeeing'])) {
                                            foreach ($valfinalSightSeeing['SightSeeing'] as $keySightSeeing => $valSightSeeing) {
                                                if ($itinerariesActivity['Id'] == $valSightSeeing['RefSSId']) {
                                                    $finalArraySightDaywise[$itKey]['Title'][] = $valSightSeeing['Title'];
                                                    $finalArraySightDaywise[$itKey]['SSSysId'][] = $valSightSeeing['RefSSId'];
                                                    $finalArraySightDaywise[$itKey]['CitySysId'][] = $itinerariesItem1['CityId'];
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (isset($param['transportSelectCheck']) && !empty($param['transportSelectCheck'])) {
                    $transportRouteSysId = $transportRouteVechSysId = array();
                    foreach ($param['transportSelectCheck'] as $tKey => $tVal) {
                        $transportSelectCheck = explode('_', $tVal);
                        $transportRouteSysId[] = $transportSelectCheck[0];
                        $transportRouteVechSysId[] = $transportSelectCheck[1];
                    }
                    $transportRouteSysIdU = implode(',', array_unique($transportRouteSysId));
                    $where = "AND IsMarkForDel = '0' AND IsActive = 1";
                    $getResults = $this->objMdl->getAllTransportDetailByIds('tb_transport_route', 'RouteSysId', $transportRouteSysIdU, $where, 'RouteSysId DESC');
                    // echo "<pre>";print_r($getResults);die; 
                    $finalVehicleCost = 0;
                    foreach ($getResults as $trKey => $trVal) {
                        $category = json_decode($trVal['category'], 1);
                        $cityIncludes = json_decode($trVal['cityIncludes'], 1);
                        $SSIncludes = json_decode($trVal['SSIncludes'], 1);
                        foreach ($category as $vKey => $vVal) {
                            if (in_array($vVal['RouteVechSysId'], $transportRouteVechSysId)) {
                                $VehicleData[$trKey]['VehicleSysId'] = $vVal['VehicleSysId'];
                                $VehicleData[$trKey]['vehicleName'] = $vVal['VehName'];
                                $VehicleData[$trKey]['Cost'] = $vVal['Cost'];
                                $VehicleData[$trKey]['Capacity'] = $vVal['Capacity'];
                                $VehicleData[$trKey]['StartCitySysId'] = $trVal['StartCitySysId'];
                                $VehicleData[$trKey]['EndCitySysId'] = $trVal['EndCitySysId'];
                                $VehicleData[$trKey]['CityName'] = $trVal['CityName'];
                                $VehicleData[$trKey]['EndCityName'] = $trVal['EndCityName'];
                                $VehicleData[$trKey]['VehicleSysId'] = $vVal['VehicleSysId'];
                                $VehicleData[$trKey]['VehicleTypeSysId'] = $vVal['VehicleTypeSysId'];
                                $finalVehicleCost += (int) $vVal['Cost'] * $param['noofVehicles'][$trVal['RouteSysId'] . '_' . $vVal['RouteVechSysId']];
                            }
                        }
                        $finalVehicleCost = Catabatic_Helper::calculateMarkup($finalVehicleCost);
                        $dayi = 1;
                        foreach ($cityIncludes as $incKey => $incVal) {
                            for ($ni = 1; $ni <= $incVal['nights']; $ni++) {
                                $checkDsightseeingArr = array();
                                foreach ($SSIncludes[$incVal['destSequence']] as $ssKey => $ssVal) {
                                    foreach ($ssVal as $ssKey1 => $ssVal1) {
                                        if ($ni == $ssVal1['SSDaySequence']) {
                                            if (!in_array($ssVal1['SSSysId'], $checkDsightseeingArr)) {
                                                $finalArraySightTransport[$dayi]['Title'][] = $ssVal1['SightSeeingName'];
                                                $finalArraySightTransport[$dayi]['SSSysId'][] = $ssVal1['SSSysId'];
                                                $finalArraySightTransport[$dayi]['CitySysId'][] = $ssVal1['DestSysId'];
                                                $checkDsightseeingArr[] = $ssVal1['SSSysId'];
                                            }
                                        }
                                    }
                                }
                                $dayi++;
                            }
                        }
                    }
                }
                for ($ss = 1; $ss < count($dayView); $ss++) {
                    $checkFinalsightseeingArr = array();
                    foreach ($finalArraySightDaywise[$ss]['SSSysId'] as $ssdKey => $ssdVal) {
                        if (!in_array($ssdVal, $checkFinalsightseeingArr)) {
                            $finalArraySight[$ss]['Title'][] = $finalArraySightDaywise[$ss]['Title'][$ssdKey];
                            $finalArraySight[$ss]['SSSysId'][] = $ssdVal;
                            $finalArraySight[$ss]['CitySysId'][] = $finalArraySightDaywise[$ss]['CitySysId'][$ssdKey];
                            $checkFinalsightseeingArr[] = $ssdVal;
                        }
                    }
                    foreach ($finalArraySightTransport[$ss]['SSSysId'] as $sstKey => $sstVal) {
                        if (!in_array($sstVal, $checkFinalsightseeingArr)) {
                            $finalArraySight[$ss]['Title'][] = $finalArraySightTransport[$ss]['Title'][$sstKey];
                            $finalArraySight[$ss]['SSSysId'][] = $sstVal;
                            $finalArraySight[$ss]['CitySysId'][] = $finalArraySightTransport[$ss]['CitySysId'][$sstKey];
                            $checkFinalsightseeingArr[] = $sstVal;
                        }
                    }
                }


                $TncData = [
                    'Inclusions' => isset($LongJsonInfo['package']['Terms']['Inclusion']) ? $LongJsonInfo['package']['Terms']['Inclusion'] : 'Inclusion',
                    'Exclusions' => isset($LongJsonInfo['package']['Terms']['Exclusions']) ? $LongJsonInfo['package']['Terms']['Exclusions'] : 'Exclusions',
                    'TermsAndConditions' => isset($LongJsonInfo['package']['Terms']['Conditions']) ? $LongJsonInfo['package']['Terms']['Conditions'] : 'Term & Conditions',
                    'TravelBasics' => isset($LongJsonInfo['package']['Terms']['TravelBasics']) ? $LongJsonInfo['package']['Terms']['TravelBasics'] : 'Travel Basics',
                    'BookingTerms' => isset($LongJsonInfo['package']['Terms']['BookingTerms']) ? $LongJsonInfo['package']['Terms']['BookingTerms'] : 'Booking Terms',
                    'WhyUseUs' => isset($LongJsonInfo['package']['Terms']['WhyUseUs']) ? $LongJsonInfo['package']['Terms']['WhyUseUs'] : 'Why Use Us',
                    'CancellationPolicy' => isset($LongJsonInfo['package']['Terms']['CancellationPolicy']) ? $LongJsonInfo['package']['Terms']['CancellationPolicy'] : 'Cancellation Policy',
                ];

                $Markup = (isset($_SESSION['User']['data']['Markup']) && trim($_SESSION['User']['data']['Markup']) != '' ) ? trim($_SESSION['User']['data']['Markup']) : $this->markup;
                $finalHotelPriceMarkup = $finalHotelPrice * ($Markup / 100);
                $MarkuponMarkup = $finalHotelPriceMarkup * ($Markup / 100);
                $finalHotelPrice = (int) ($finalHotelPrice - $finalHotelPriceMarkup + $MarkuponMarkup);
                $apiData = [];
                $apiData['packid'] = $param['pkg'];
                $apiData['TravelPlanId'] = $param['gtxpackage'];
                $apiData['minpax'] = 2;
                $apiData['catID'] = $package_hotelcategoryid;
                $apiData['FirstName'] = trim($_SESSION['User']['data']['FirstName']) . ' ' . trim($_SESSION['User']['data']['LastName']);
                $apiData['TotalNights'] = array_sum($param['NoofNights']);
                $apiData['DestinationPlaces'] = $DestinationPlaces; // 'eyI3NzAxIjoiRGVsaGkiLCIxMDU3NiI6IkdvYSJ9';
                $apiData['search_going_to'] = $DestinationID . '__' . $Destinations;   // '7701__Delhi';
                $apiData['cityIds'] = $DestinationID;
                $apiData['Destinations'] = $Destinations;
                $apiData['pkgCheckInDate'] = $pkgCheckinDate;
                $apiData['pkgCheckOutDate'] = $pkgCheckoutDate;
                $apiData['tripstartdate'] = $pkgCheckinDate;
                $apiData['custemail'] = trim($_SESSION['User']['data']['EmailId']);
                $apiData['custname'] = trim($_SESSION['User']['data']['FirstName']) . ' ' . trim($_SESSION['User']['data']['LastName']);
                $apiData['custphone'] = trim($_SESSION['User']['data']['ContactNo1']);
                $apiData['tripaddress'] = explode(',', $param['Destinations']);
                $apiData['aboutpackage'] = '';
                $apiData['pricetype'] = 'wp';
                $apiData['AgencySysId'] = $this->gtxagencysysid;
                $apiData['AgentSysId'] = $this->gtxagentsysid;
                $apiData['Email'] = $_SESSION['User']['data']['EmailId'];
                $apiData['MobileNumber'] = $_SESSION['User']['data']['ContactNo1'];
                $apiData['leadsource'] = 'Website';
                $apiData['mealplantype'] = 0;
                $apiData['selectedCustomerId'] = base64_encode($_SESSION['User']['data']['CustomerSysId']);
                $apiData['aId'] = $_SESSION['User']['data']['UserSysId'];
                $apiData['IsB2BCustomer'] = 1;
                $apiData['IsB2BAgent'] = 1;
                $apiData['roomjson'] = json_encode($roominfojson);
                $apiData['dayView'] = json_encode($dayView);
                $apiData['hotelData'] = json_encode(array(1 => $hotelDataArr));
                $apiData['TncData'] = json_encode($TncData);
                $apiData['finalArraySight'] = json_encode($finalArraySight);
                $apiData['VehicleData'] = json_encode($VehicleData);
                $apiData['finalHotelPrice'] = $finalHotelPrice;
                $apiData['finalVehicleCost'] = $finalVehicleCost;
                $apiData['totalPrice'] = json_encode(array(1 => ((int) $finalHotelPrice + (int) $finalVehicleCost)));
                $apiData['MarkupType'] = (isset($_SESSION['User']['data']['MarkupType']) && trim($_SESSION['User']['data']['MarkupType']) != '' ) ? trim($_SESSION['User']['data']['MarkupType']) : $this->markupType;
                $apiData['Markup'] = (isset($_SESSION['User']['data']['Markup']) && trim($_SESSION['User']['data']['Markup']) != '' ) ? trim($_SESSION['User']['data']['Markup']) : $this->markup;
                $apiData['extraMarkUp'] = (isset($param['extraMarkUp']) && trim($param['extraMarkUp']) != '') ? json_encode(array(1 => $param['extraMarkUp'])) : 0;

                //echo "<pre>";print_r($apiData);die('here1');
                try {
                    $model = new Gtxwebservices_Model_Webservices();
                    $responce = $model->sendCustomizeDynamicPackage($apiData);
                    // echo "<pre>";print_r($responce);die('here1');
                } catch (Zend_Exception $error) {
                    echo $message_err = $error->getMessage();
                    $status = false;
                }
                echo "<pre>";
                print_r($responce);
                die('here');
            }
        }
    }

    public function getHotelDetailAction() {

        $this->_helper->layout()->disableLayout();
        if ($this->getRequest()->isXmlHttpRequest()) {
            if ($this->getRequest()->isPost()) {
                $param = $this->getRequest()->getParams();
                $hotelId = $param['hotelId'];
                $type = $param['type'];
                $categoryId = $param['categoryId'];
                $packageId = $param['packageId'];
                $gtxID = $param['gtxID'];
                $model = new Detail_Model_PackageMapper();
                if ($type == 'H') {
                    $getDetail = $model->fetchHotelDetails($categoryId, $gtxID, $packageId, $hotelId);
                } else if ($type == 'A') {
                    $getDetail = $model->fetchActivityDetails($categoryId, $gtxID, $packageId, $hotelId);
                } else {
                    $getDetail = $model->fetchSightSeeingDetails($categoryId, $gtxID, $packageId, $hotelId);
                }
                $this->view->type = $type;
                $this->view->hotelData = $getDetail;
                $this->view->baseUrl = $this->baseUrl;
            }
        }
    }

    public function getOptionalHotelAction() {

        $this->_helper->layout()->disableLayout();
        if ($this->getRequest()->isXmlHttpRequest()) {
            if ($this->getRequest()->isPost()) {
                $param = $this->getRequest()->getParams();
                $day = $param['day'];

                $categoryId = $param['categoryId'];
                $packageId = $param['packageId'];
                $gtxID = $param['gtxID'];
                $model = new Detail_Model_PackageMapper();

                $getDetail = $model->fetchDayWiseHotelDetails($categoryId, $gtxID, $packageId, $day);

//                 if($type == 'H'){
//                     $getDetail = $model->fetchHotelDetails($categoryId, $gtxID, $packageId,$hotelId);        
//                 } else if($type == 'A') {
//                     $getDetail = $model->fetchActivityDetails($categoryId, $gtxID, $packageId,$hotelId);        
//                 } else {
//                     $getDetail = $model->fetchSightSeeingDetails($categoryId, $gtxID, $packageId,$hotelId); 
//                 }

                $this->view->hotelData = $getDetail;
            }
        }
    }

    // get all the other options available for hotel per itinerary
    public function changeOptionsAction() {
        $this->_helper->layout()->disableLayout();

        $getDetail = [];
        $message = '';

        if ($this->getRequest()->getMethod() === 'GET') {

            $param = $this->getRequest()->getParams();

//            echo '<pre>'; print_r($param); die;

            $day = (isset($param['day'])) ? $param['day'] : 0;
            $categoryid = (isset($param['categoryid'])) ? $param['categoryid'] : 1;
            $packageid = (isset($param['packageid'])) ? $param['packageid'] : 0;
            $gtxid = (isset($param['gtxid'])) ? $param['gtxid'] : 0;
            $type = (isset($param['type'])) ? $param['type'] : '';
            $tourtype = (isset($param['tourtype'])) ? $param['tourtype'] : 0;
            $itinerary = (isset($param['itinerary'])) ? $param['itinerary'] : 0;
            $sid = (isset($param['sid']) && !empty($param['sid'])) ? $param['sid'] : 0;
            $group = (isset($param['group']) && !empty($param['group'])) ? $param['group'] : '';
            $countit = (isset($param['countit']) && !empty($param['countit'])) ? $param['countit'] : 1;

            $mp = (isset($param['mp'])) ? $param['mp'] : 0;

            $resultData = $includedItemPriceArray = $markupDetialsArray = [];
            $itemName = '';

            // check the change options
            if (strtolower($type) === 'h') {
                $model = new Detail_Model_PackageMapper();
                $resultData = $model->fetchDayWiseOptionsDetails($categoryid, $gtxid, $packageid, $day, $sid, 'h');
                $itemName = 'hotel';
            } else if (strtolower($type) === 'a') {
                $model = new Detail_Model_PackageMapper();
                $resultData = $model->fetchDayWiseOptionsDetails($categoryid, $gtxid, $packageid, $day, $sid, 'a');
                $itemName = 'activity';
            } else if (strtolower($type) === 's') {
                $model = new Detail_Model_PackageMapper();
                $resultData = $model->fetchDayWiseOptionsDetails($categoryid, $gtxid, $packageid, $day, $sid, 's');
                $itemName = 'sightSeeing';
            } else if (strtolower($type) === 'car') {
                $model = new Detail_Model_PackageMapper();
                $resultData = $model->fetchTransfersDetails($packageid, $gtxid, $tourtype);
                $itemName = 'transfers';
            } else if (strtolower($type) === 'cc') {
                $model = new Detail_Model_PackageMapper();
                $resultData = $model->fetchPackageCateogies($packageid, $gtxid);
//                $itemName   = 'transfers';
            }

//            $type   = 'hotel';
            $masterDataArray = $this->objHelperGeneral->getMasterData($packageid, $type);

            $markupDetialsArray = $this->objHelperGeneral->getMarkupDetailsArray($packageid, $tourtype, $categoryid);

//            $masterDataArray1 = $this->objHelperGeneral->getPackagePriceArray( $packageid  );
//            $this->getPackageMasterData( $packageid );
//            $this->objHelperGeneral->getPackageJSONDataArray( $packageid );
//            echo '<pre>'; print_r( $markupDetialsArray ); die;
//echo $includedItemPriceArray; die;
//        echo '<pre>'; print_r($resultData); die;
            // check for the option type | only if not the category chage popup
            if (strtolower($type) !== 'cc') {

                if ($this->objHelperGeneral->checksession((int) $packageid, $tourtype, $categoryid)) {
                    if (count($resultData['itemArray'])) {

                        $PSESS = $this->_storage->packageSession; // get the session values

                        $tempArr = [];
                        $IsIncluded = false;

                        if (strtolower($type) === 'car') {

                            foreach ($resultData['itemArray'][0] as $key => $value) {
//            echo '<pre>'; print_r( $resultData['itemArray'][0] ); die;
//                                echo $key;
//            echo '<pre>'; print_r( $PSESS[$packageid][$tourtype][$categoryid]['others'][$itemName]);
// echo '</pre>'; 
//                                if( isset($PSESS[$packageid][$tourtype][$categoryid]['others'][$itemName]) ) {
                                $IsIncluded = $PSESS[$packageid][$tourtype][$categoryid]['others'][$itemName][$key]['IsIncluded']; // check the session here
//                                }
//                                else {
//                                    $IsIncluded = false;
//                                }
//                                var_dump($IsIncluded);
                                if ($IsIncluded) {
                                    $itemid = $value['fixTransSysId']; // get recent updated item id
                                }

                                $tempArr[] = [
                                    'fixTransSysId' => $value['fixTransSysId'],
                                    'vehSysId' => $value['vehSysId'],
                                    'cityCovered' => $value['cityCovered'],
                                    'capacity' => $value['capacity'],
                                    'costPerson' => $value['costPerson'],
                                    'routeName' => @$value['routeName'],
                                    'vehicleName' => @$value['vehicleName'],
//                                    'IsIncluded'=> ($IsIncluded) ? true : false
                                    'IsIncluded' => ($value['IsIncluded']) ? true : false
                                ];
                            }
                            $resultData['itemArray'][0] = $tempArr;
//echo $itemid;die;
                        } else {
//echo $packageid , $tourtype , $categoryid ; die;
//                            echo count($resultData['itemArray'][0]);
                            if (count($resultData['itemArray'][0]) && ($resultData['itemArray'][0])) {
//                                            echo '<pre>'; print_r( $resultData['itemArray'][0] ); die;

                                foreach ($resultData['itemArray'][0] as $key => $value) {

                                    $IsIncluded = $PSESS[$packageid][$tourtype][$categoryid]['itineraries'][$itinerary][$itemName][$key]['IsIncluded']; // check the session here

                                    if ($IsIncluded) {
                                        $itemid = $value['Id']; // get recent updated item id
                                    }
                                    $tempArr[] = ['Id' => $value['Id'], 'MasterIntSysId' => $value['MasterIntSysId'], 'IsIncluded' => ($IsIncluded) ? true : false];
                                }
                                $resultData['itemArray'][0] = $tempArr;
                            } else if (count($resultData['itemArray'][1])) {
                                foreach ($resultData['itemArray'][1] as $key => $value) {

                                    $IsIncluded = $PSESS[$packageid][$tourtype][$categoryid]['itineraries'][$itinerary][$itemName][$key]['IsIncluded']; // check the session here

                                    if ($IsIncluded) {
                                        $itemid = $value['Id']; // get recent updated item id
                                    }
                                    $tempArr[] = ['Id' => $value['Id'], 'MasterIntSysId' => $value['MasterIntSysId'], 'IsIncluded' => ($IsIncluded) ? true : false];
                                }
                                $resultData['itemArray'][1] = $tempArr;
                            }
                        }
                    }
                }
            }
//                        echo '<pre>'; print_r($resultData['itemArray']); die;
//                echo $itemid ;
            if ((strtolower($type) === 'h') || (strtolower($type) === 'car')) {
                if (isset($itemid)) {
                    $itemprice = $this->objHelperGeneral->getSelectedItemRate($itemid, $masterDataArray, $type); // get included item price
                    $includedItemPriceArray[$type] = $itemprice;
                }
            }
//                    echo '<pre>'; print_r($masterDataArray); die;
            $status = true;
        } else {
            $status = false;
            $message = 'Invalid request!';
        }

//        echo '<pre>'; print_r($resultData); die;
//        echo '<pre>'; var_dump($resultData);



        $this->view->status = $status;
        $this->view->message = $message;
        $this->view->resultData = $resultData;
        $this->view->param = $param;
        $this->view->sessionPrice = $this->_storage->packageSession[$packageid][$tourtype][$categoryid]['others']['price']; // 
        $this->view->markupDetialsArray = $markupDetialsArray;
//        $this->view->itemPriceArray = $itemPriceArray;
        $this->view->includedItemPriceArray = $includedItemPriceArray;
        $this->view->baseUrl = $this->baseUrl;
        $this->view->mealplantype = $mp;
    }

    public function changeOptionsCustomizeAction() {
        $this->_helper->layout()->disableLayout();

        $getDetail = [];
        $message = '';

        if ($this->getRequest()->getMethod() === 'POST') {

            $param = $this->getRequest()->getParams();

//            echo '<pre>'; print_r($param); die;

            $day = (isset($param['day'])) ? $param['day'] : 0;
            $categoryid = (isset($param['categoryid'])) ? $param['categoryid'] : 1;
            $packageid = (isset($param['packageid'])) ? $param['packageid'] : 0;
            $gtxid = (isset($param['gtxid'])) ? $param['gtxid'] : 0;
            $type = (isset($param['type'])) ? $param['type'] : '';
            $tourtype = (isset($param['tourtype'])) ? $param['tourtype'] : 0;
            $itinerary = (isset($param['itinerary'])) ? $param['itinerary'] : 0;
            $sid = (isset($param['sid']) && !empty($param['sid'])) ? $param['sid'] : 0;
            $group = (isset($param['group']) && !empty($param['group'])) ? $param['group'] : '';
            $countit = (isset($param['countit']) && !empty($param['countit'])) ? $param['countit'] : 1;

            $mp = (isset($param['mp'])) ? $param['mp'] : 0;
            $mp = (isset($param['mp'])) ? $param['mp'] : 0;

            $resultData = $includedItemPriceArray = $markupDetialsArray = [];
            $itemName = '';

            // check the change options
            if (strtolower($type) === 'h') {
                $model = new Detail_Model_PackageMapper();
                $resultData = $model->fetchDayWiseOptionsDetails($categoryid, $gtxid, $packageid, $day, $sid, 'h');
                $itemName = 'hotel';
            } else if (strtolower($type) === 'a') {
                $model = new Detail_Model_PackageMapper();
                $resultData = $model->fetchDayWiseOptionsDetails($categoryid, $gtxid, $packageid, $day, $sid, 'a');
                $itemName = 'activity';
            } else if (strtolower($type) === 's') {
                $model = new Detail_Model_PackageMapper();
                $resultData = $model->fetchDayWiseOptionsDetails($categoryid, $gtxid, $packageid, $day, $sid, 's');
                $itemName = 'sightSeeing';
            } else if (strtolower($type) === 'car') {
                $model = new Detail_Model_PackageMapper();
                $resultData = $model->fetchTransfersDetails($packageid, $gtxid, $tourtype);
                $itemName = 'transfers';
            } else if (strtolower($type) === 'cc') {
                $model = new Detail_Model_PackageMapper();
                $resultData = $model->fetchPackageCateogies($packageid, $gtxid);
//                $itemName   = 'transfers';
            }

//            $type   = 'hotel';
            $masterDataArray = $this->objHelperGeneral->getMasterData($packageid, $type);

            $markupDetialsArray = $this->objHelperGeneral->getMarkupDetailsArray($packageid, $tourtype, $categoryid);

//            $masterDataArray1 = $this->objHelperGeneral->getPackagePriceArray( $packageid  );
//            $this->getPackageMasterData( $packageid );
//            $this->objHelperGeneral->getPackageJSONDataArray( $packageid );
//            echo '<pre>'; print_r( $markupDetialsArray ); die;
//echo $includedItemPriceArray; die;
//        echo '<pre>'; print_r($resultData); die;
            // check for the option type | only if not the category chage popup
            if (strtolower($type) !== 'cc') {

                if ($this->objHelperGeneral->checksession((int) $packageid, $tourtype, $categoryid)) {
                    if (count($resultData['itemArray'])) {

                        $PSESS = $this->_storage->packageSession; // get the session values

                        $tempArr = [];
                        $IsIncluded = false;

                        if (strtolower($type) === 'car') {

                            foreach ($resultData['itemArray'][0] as $key => $value) {
//            echo '<pre>'; print_r( $resultData['itemArray'][0] ); die;
//                                echo $key;
//            echo '<pre>'; print_r( $PSESS[$packageid][$tourtype][$categoryid]['others'][$itemName]);
// echo '</pre>'; 
//                                if( isset($PSESS[$packageid][$tourtype][$categoryid]['others'][$itemName]) ) {
                                $IsIncluded = $PSESS[$packageid][$tourtype][$categoryid]['others'][$itemName][$key]['IsIncluded']; // check the session here
//                                }
//                                else {
//                                    $IsIncluded = false;
//                                }
//                                var_dump($IsIncluded);
                                if ($IsIncluded) {
                                    $itemid = $value['fixTransSysId']; // get recent updated item id
                                }

                                $tempArr[] = [
                                    'fixTransSysId' => $value['fixTransSysId'],
                                    'vehSysId' => $value['vehSysId'],
                                    'cityCovered' => $value['cityCovered'],
                                    'capacity' => $value['capacity'],
                                    'costPerson' => $value['costPerson'],
                                    'routeName' => @$value['routeName'],
                                    'vehicleName' => @$value['vehicleName'],
//                                    'IsIncluded'=> ($IsIncluded) ? true : false
                                    'IsIncluded' => ($value['IsIncluded']) ? true : false
                                ];
                            }
                            $resultData['itemArray'][0] = $tempArr;
//echo $itemid;die;
                        } else {
//echo $packageid , $tourtype , $categoryid ; die;
//                            echo count($resultData['itemArray'][0]);
                            if (count($resultData['itemArray'][0]) && ($resultData['itemArray'][0])) {
//                                            echo '<pre>'; print_r( $resultData['itemArray'][0] ); die;

                                foreach ($resultData['itemArray'][0] as $key => $value) {

                                    $IsIncluded = $PSESS[$packageid][$tourtype][$categoryid]['itineraries'][$itinerary][$itemName][$key]['IsIncluded']; // check the session here

                                    if ($IsIncluded) {
                                        $itemid = $value['Id']; // get recent updated item id
                                    }
                                    $tempArr[] = ['Id' => $value['Id'], 'MasterIntSysId' => $value['MasterIntSysId'], 'IsIncluded' => ($IsIncluded) ? true : false];
                                }
                                $resultData['itemArray'][0] = $tempArr;
                            } else if (count($resultData['itemArray'][1])) {
                                foreach ($resultData['itemArray'][1] as $key => $value) {

                                    $IsIncluded = $PSESS[$packageid][$tourtype][$categoryid]['itineraries'][$itinerary][$itemName][$key]['IsIncluded']; // check the session here

                                    if ($IsIncluded) {
                                        $itemid = $value['Id']; // get recent updated item id
                                    }
                                    $tempArr[] = ['Id' => $value['Id'], 'MasterIntSysId' => $value['MasterIntSysId'], 'IsIncluded' => ($IsIncluded) ? true : false];
                                }
                                $resultData['itemArray'][1] = $tempArr;
                            }
                        }
                    }
                }
            }
//                        echo '<pre>'; print_r($resultData['itemArray']); die;
//                echo $itemid ;
            if ((strtolower($type) === 'h') || (strtolower($type) === 'car')) {
                if (isset($itemid)) {
                    $itemprice = $this->objHelperGeneral->getSelectedItemRate($itemid, $masterDataArray, $type); // get included item price
                    $includedItemPriceArray[$type] = $itemprice;
                }
            }
//                    echo '<pre>'; print_r($masterDataArray); die;
            $status = true;
        } else {
            $status = false;
            $message = 'Invalid request!';
        }

//        echo '<pre>'; print_r($resultData); die;
//        echo '<pre>'; var_dump($resultData);



        $this->view->status = $status;
        $this->view->message = $message;
        $this->view->resultData = $resultData;
        $this->view->param = $param;
        $this->view->sessionPrice = $this->_storage->packageSession[$packageid][$tourtype][$categoryid]['others']['price']; // 
        $this->view->markupDetialsArray = $markupDetialsArray;
//        $this->view->itemPriceArray = $itemPriceArray;
        $this->view->includedItemPriceArray = $includedItemPriceArray;
        $this->view->baseUrl = $this->baseUrl;
        $this->view->mealplantype = $mp;
    }

    // view all the other options available in modal popup
    public function viewOptionsAction() {
        $this->_helper->layout()->disableLayout();

        $getDetail = [];
        $message = '';

        if ($this->getRequest()->getMethod() === 'GET') {

            $param = $this->getRequest()->getParams();

//            var_dump($this->PSESS->packageid); die;
//            echo '<pre>'; print_r($param); die;

            $day = (isset($param['day'])) ? $param['day'] : '';
            $categoryid = (isset($param['categoryid'])) ? $param['categoryid'] : '';
            $packageid = $param['packageid'];
            $gtxid = $param['gtxid'];
            $type = $param['type'];
            $tourtype = (isset($param['tourtype'])) ? $param['tourtype'] : 0;
            $itinerary = (isset($param['itinerary'])) ? $param['itinerary'] : 0;
            $sid = (isset($param['sid']) && !empty($param['sid'])) ? $param['sid'] : 0;

            $markupDetialsArray = [];

            $markupDetialsArray = $this->objHelperGeneral->getMarkupDetailsArray($packageid, $tourtype, $categoryid);

            // view all options available to add into services tab
            if ($type == 'services') {
                $getDetail = $this->objMdl->rv_select_row($this->tablename, ['LongJsonInfo'], ['PkgSysId' => $packageid, 'GTXPkgId' => $gtxid, 'IsMarkForDel' => 0, 'IsActive' => 1, 'IsPublish' => 1], ['PkgSysId' => 'DESC']);

                if ($getDetail['LongJsonInfo']) {

                    $LongJsonInfo = $getDetail['LongJsonInfo'];
                    $dataArray = Zend_Json::decode($LongJsonInfo);
                    $resultData = $dataArray['package']['OtherServices'];
                } else {
                    $resultData = [];
                }
            } else {

                $getDetail = $this->objMdl->rv_select_row($this->tablename, ['LongJsonInfo'], ['PkgSysId' => $packageid, 'GTXPkgId' => $gtxid, 'IsMarkForDel' => 0, 'IsActive' => 1, 'IsPublish' => 1], ['PkgSysId' => 'DESC']);

                if ($getDetail['LongJsonInfo']) {

                    $LongJsonInfo = $getDetail['LongJsonInfo'];
                    $dataArray = Zend_Json::decode($LongJsonInfo);

                    $transferMaster = $dataArray['package']['Transfers'];

                    // get transport itinerarys
                    $getTransportDetails = $this->getTransportDetails($packageid, $gtxid, strtolower($type));

//                        echo '<pre>'; print_r($transferMaster); die('here');
                    $resultData = [];
                    foreach ($getTransportDetails as $k => $v) {

                        $innerArr = $masterTemp = [];
                        foreach ($v['FinalArray'] as $key => $value) {
//                                echo '<pre>';  print_r($value); die;
                            $tempArr = [];
                            foreach ($value as $keyInner => $valueInner) {

//                                    print_r($valueInner['itemid']);
//                                $innerArr[] = [ 'Day'=>$v['Day'] , 'FromPlace'=> $value['FromPlace'], 'ToPlace'=> $value['ToPlace'], 'CostPerson'=> $value['CostPerson'] ];
                                $masterTemp = $this->objHelperGeneral->filterArrayByValueKeyPair(['fixTransSysId', $valueInner['itemid']], $transferMaster);
//                                $masterTemp = $this->objHelperGeneral->filterArrayByValueKeyPair( ['Id', $valueInner['itemid'] ] , $transferMaster );1
//                                echo '<pre>';  print_r($masterTemp);
//                                    $tempArr[] = $masterTemp[0];
//                                    $masterTemp[0];
                                $tempArr[] = [
                                    'Day' => $v['Day'],
                                    'FromPlace' => $masterTemp[0]['fromPlace'],
                                    'ToPlace' => $masterTemp[0]['toPlace'],
                                    'CostPerson' => $masterTemp[0]['costPerson']
                                ];
                            }
//                                                                echo '<pre>';  print_r($tempArr);

                            $innerArr[] = $tempArr;
//                                $innerArr[] = [ 'Day'=>$v['Day'] , 'FromPlace'=> $value['FromPlace'], 'ToPlace'=> $value['ToPlace'], 'CostPerson'=> $value['CostPerson'] ];
                        }
//                            $resultData[] = $innerArr;
                        $resultData[] = ['Day' => $v['Day'], 'FinalArray' => $innerArr];
                    }
//                        echo '<pre>'; print_r($resultData); die;
//                        $resultData     = $dataArray['package']['Transfers'];
                } else {
                    $resultData = [];
                }

//                        echo '<pre>'; print_r($resultData); die;
            }
            $status = true;

//            echo '<pre>'; print_r($resultData); die;
//            echo '<pre>'; print_r($this->_storage->packageSession[$packageid][$tourtype][$categoryid]['others']['services']);

            if ($this->objHelperGeneral->checksession((int) $packageid, $tourtype, $categoryid)) {
                if (count($resultData)) {

                    $PSESS = $this->_storage->packageSession; // get the session values

                    $tempArr = [];
                    $IsIncluded = false;

                    if (strtolower($type) === 'services') {

                        foreach ($resultData as $key => $value) {

                            $IsIncluded = $PSESS[$packageid][$tourtype][$categoryid]['others']['services'][$key]['IsIncluded']; // check the session here
                            $IsIncludedNew = isset($PSESS[$packageid][$tourtype][$categoryid]['others']['services'][$key]['IsIncludedNew']) ? $PSESS[$packageid][$tourtype][$categoryid]['others']['services'][$key]['IsIncludedNew'] : ""; // check the session here

                            if ($IsIncluded) {
                                $itemid = $value['otherSrvSysId']; // get recent updated item id
                            }
//                            print_r($value);
                            $tempArr[] = [
                                'otherSrvSysId' => $value['otherSrvSysId'],
                                'tpIntSysId' => $value['tpIntSysId'],
                                'serviceTitle' => $value['serviceTitle'],
                                'comment' => $value['comment'],
                                'currencyType' => $value['currencyType'],
                                'paxCount' => $value['paxCount'],
                                'cost' => $value['cost'],
                                'supplierName' => $value['supplierName'],
                                'rateType' => $value['rateType'],
                                'isCostInclInTP' => ($IsIncluded) ? true : false,
                                'IsIncludedNew' => ($IsIncludedNew) ? true : false
                            ];
                        }
                        $resultData = $tempArr;
                    }
                }
            }
        } else {
            $status = false;
            $message = 'Invalid request!';
        }


//        echo '<pre>'; print_r($includedItemPriceArray); die;

        $this->view->baseUrl = $this->baseUrl;
        $this->view->status = $status;
        $this->view->message = $message;
        $this->view->resultData = $resultData;
        $this->view->sessionPrice = $this->_storage->packageSession[$packageid][$tourtype][$categoryid]['others']['price']; // 
        $this->view->markupDetialsArray = $markupDetialsArray;
        $this->view->param = $param;
    }

    public function addServicesAction() {

        $this->_helper->layout()->disableLayout();

        $resultData = [];
        $message = '';

        if ($this->getRequest()->getMethod() === 'GET') {

            $param = $this->getRequest()->getParams();

//            echo '<pre>'; print_r($param); die;

            $packageid = $param['packageid'];
            $gtxid = $param['gtxid'];

            $getDetail = $this->objMdl->rv_select_row($this->tablename, ['LongJsonInfo'], ['PkgSysId' => $packageid, 'GTXPkgId' => $gtxid, 'IsMarkForDel' => 0, 'IsActive' => 1, 'IsPublish' => 1], ['PkgSysId' => 'DESC']);

            if ($getDetail['LongJsonInfo']) {

                $LongJsonInfo = $getDetail['LongJsonInfo'];
                $dataArray = Zend_Json::decode($LongJsonInfo);
                $resultData = $dataArray['package']['OtherServices'];
            } else {
                $resultData = [];
            }

//            echo '<pre>'; print_r( ($resultData)); die;

            $status = true;
        } else {
            $status = false;
            $message = 'Invalid request!';
        }

        $this->view->status = $status;
        $this->view->message = $message;
        $this->view->resultData = $resultData;
        $this->view->baseUrl = $this->baseUrl;
    }

    // helper functions below

    public function getTransportDetails($packageid, $gtxid, $type) {
        $getDetail = $this->objMdl->rv_select_row($this->tablename, ['LongJsonInfo'], ['PkgSysId' => $packageid, 'GTXPkgId' => $gtxid, 'IsMarkForDel' => 0, 'IsActive' => 1, 'IsPublish' => 1], ['PkgSysId' => 'DESC']);

        if ($getDetail['LongJsonInfo']) {
            $LongJsonInfo = $getDetail['LongJsonInfo'];
            $dataArray = Zend_Json::decode($LongJsonInfo);
            $resultData = $dataArray['package']['Itineraries']['Itinerary'];
            $masterData = $dataArray['package']['Transfers'];
//            echo '<pre>'; print_r( ($resultData)); die;
            // param : itinerary array 
            // return : array of transports
            $result = $this->objHelperGeneral->getTransportItinerary($resultData, $masterData, $type);

//            echo '<pre>'; print_r( $result); die;
        } else {
            $result = [];
        }

        return $result;
    }

    public function getPackageMasterData($packageid) {
        $model = new Admin_Model_CRUD();
        $result = $model->rv_select_row($this->tablename, ['LongJsonInfo'], ['IsMarkForDel' => 0, 'IsActive' => 1, 'IsPublish' => 1, 'PkgSysId' => $packageid], ['PkgSysId' => 'DESC']);

//        echo '<pre>'; print_r( $result ); die;

        return $result;
    }

    public function viewAction() {
        $this->view->url = '';
        if ($this->getRequest()->isGet()) {

            $param = $this->getRequest()->getParams();
            $feed = isset($param['feed']) ? $param['feed'] : '';
            if ($feed != 1) {
                $this->_helper->layout()->disableLayout();
            }
            /*  echo "<pre>";
              print_r($param);
              exit; */
            $addtionalField = '';
            if (isset($param['FN']) && trim($param['FN']) != '{FirstName}') {
                $FirstName = $param['FN'];
                $addtionalField .= '&FN=' . $FirstName;
            } else if (isset($param['FirstName']) && $param['FirstName'] != "") {
                $FirstName = $param['FirstName'];
                $addtionalField .= '&FN=' . $FirstName;
            }
            if (isset($param['LN']) && trim($param['LN']) != '{LastName}') {
                $LastName = $param['LN'];
                $addtionalField .= '&LN=' . $LastName;
            } else if (isset($param['LastName']) && $param['LastName'] != "") {
                $LastName = $param['LastName'];
                $addtionalField .= '&LN=' . $LastName;
            }
            if (isset($param['Email']) && $param['Email'] != "") {
                $Email = $param['Email'];
                $addtionalField .= '&Email=' . $Email;
            }
            if (isset($param['MNo']) && trim($param['MNo']) != '{MobileNo}') {
                $MobileNo = $param['MNo'];
                $addtionalField .= '&MNo=' . $MobileNo;
            } else if (isset($param['MobileNo']) && $param['MobileNo'] != "") {
                $MobileNo = $param['MobileNo'];
                $addtionalField .= '&MNo=' . $MobileNo;
            }

            if (isset($param['AUID']) && trim($param['AUID']) != '{aid}') {
                $AUID = $param['AUID'];
                $addtionalField .= '&AUID=' . (int) $AUID;
            }
//             if (isset($param['source']) && trim($param['source']) != '{aid}') {
//                $source = $param['source'];
//                $addtionalField .= '&source=' . (int) $source;
//            }
            if (isset($param['campId']) && trim($param['campId']) != '{campSysId}') {
                $campId = $param['campId'];
                $addtionalField .= '&campId=' . $campId;
            }
            if ($feed == 1) {
                $addtionalField .= '&source=Website';
            }
            //   echo $addtionalField;

            $this->view->addtionalField = $addtionalField;
            $this->view->url = isset($param['id']) ? $param['id'] : '';
        }
        $this->view->baseUrl = $this->baseUrl;
        $this->view->siteName = $this->siteName;
        $this->view->feed = $feed;
    }

    public function writeSessionModifytrueAction() {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        $param = $this->getRequest()->getParams();

        $this->objHelperGeneral->flushSession();
        echo Zend_Json::encode(['status' => 'success', 'mealplantype' => $param['mealplantype']]);
    }

    public function viewproposalAction() {
//        $this->view->url = '';
//        if ($this->getRequest()->isGet()) {
//            $this->_helper->layout()->disableLayout();
        $param = $this->getRequest()->getParams();
        $this->view->url = isset($param['code']) ? $param['code'] : '';
//        }
    }

//    update or write the session here 
    public function writeSessionAction() {
        // $this->_helper->layout()->disableLayout();
        // $this->_helper->viewRenderer->setNoRender(true);

        $this->_helper->layout()->disableLayout();
        if ($this->getRequest()->isXmlHttpRequest()) {
            if ($this->getRequest()->isPost()) {

                $param = $this->getRequest()->getParams();
                //  echo '<pre>'; print_r($param); 
                // die("test"); finalPrice
                foreach ($param['itinerary'] as $key => $HotelVal) {

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





                    $type = $HotelVal['type'];
                    $catid = $HotelVal['catid'];

//        $gtxid      = $param['gtxid'];
                    $pkgid = $param['pkgid'];
                    $tourtype = $param['tourtype']; // Group or Private        
                    $itinerary = (isset($key)) ? $key : 0;
                    $myaction = (isset($param['myaction'])) ? $param['myaction'] : '';
                    $group = (isset($param['group'])) ? $param['group'] : '';
                    // echo $group; die;

                    $ismulti = 0;
                    if ($type === 'services') {
                        $itemid = $param['itemid'];
                        $price = ($param['price']);
                        $ismulti = 1;
                    } else {
                        $itemid = $HotelVal['itemid'];
                        $price = $param['price'];
                    }

                    // die($itemid);

                    if (strtolower($type) === 'h') {
                        $typeAlpha = 'hotel';
                    } else if (strtolower($type) === 'a') {
                        $typeAlpha = 'activity';
                    } else if (strtolower($type) === 's') {
                        $typeAlpha = 'sightSeeing';
                    } else if (strtolower($type) === 'car') {
                        $typeAlpha = 'transfers';
                    } else if (strtolower($type) === 'services') {
                        $typeAlpha = 'services';
                    }
                    // echo $type , $typeAlpha;

                    $PSESS = $this->_storage->packageSession;
                    //  echo "<pre>"; print_r($PSESS);
                    $markupDetialsArray = $this->objHelperGeneral->getMarkupDetailsArray($pkgid, $tourtype, $catid); // get markup details
                    // echo '<pre>'; print_r($markupDetialsArray); die;
//        if ( $PSESS['ID'] == $pkgid )

                    if (array_key_exists($pkgid, $PSESS)) {
//            die("gj");
                        // chaeck tour type
                        if (array_key_exists($tourtype, $PSESS[$pkgid])) {
                            // chaeck type category
                            if (array_key_exists($catid, $PSESS[$pkgid][$tourtype])) {

                                if ($typeAlpha == 'hotel') {

                                    if ($group === 'yes') {
                                        //echo "<pre>";print_r($PSESS[$pkgid][$tourtype][$catid]); die("test");
                                        // iterate the array
                                        $tempArr = [];

                                        $countITIHotel = 0;
                                        foreach ($PSESS[$pkgid][$tourtype][$catid] as $keyO => $valueO) {
                                            if ($keyO === 'itineraries') {
                                                $tempArr1 = [];
                                                foreach ($valueO as $keyH => $valueH) {
                                                    // $keyH = itinerary id here
//echo $keyH ; print_r($valueH); die;
                                                    if (is_array($valueH['hotel']) && count($valueH['hotel'])) {

                                                        $innerArr = [];
                                                        $MasterIntSysId = $itemidID = 0;
                                                        $IsIncluded = false;
                                                        foreach ($valueH['hotel'] as $key => $value) {
//                                                print_r($value);
                                                            if ($keyH == $itinerary) {
                                                                $IsIncluded = ($value['itemid'] == $itemid) ? true : false;
                                                            } else {
                                                                if ($value['MasterIntSysId'] == $itinerary) {
                                                                    $IsIncluded = ($value['itemid'] == $itemid) ? true : false;
                                                                    $countITIHotel++;
                                                                } else {
                                                                    $IsIncluded = $value['IsIncluded'];
                                                                }
                                                            }
                                                            $MealPlanId = $value['MealPlanId'];
                                                            $MasterIntSysId = $value['MasterIntSysId'];
                                                            $itemidID = $value['itemid'];
                                                            $innerArr[] = ['itemid' => $itemidID, 'MasterIntSysId' => $MasterIntSysId, 'MealPlanId' => $MealPlanId, 'IsIncluded' => $IsIncluded];
                                                        }

                                                        $PSESS[$pkgid][$tourtype][$catid]['itineraries'][$keyH][$typeAlpha] = $innerArr; // rewrite the session here
                                                    }
                                                }
                                            }
                                        }
//                             print_r($tempArr);
//                              die('here');
//                            $PSESS[$pkgid][$tourtype][$catid]['itineraries'][$itinerary][$typeAlpha] = $tempArr;
//                            $PSESS[$pkgid][$tourtype][$catid]['itineraries'][$itinerary][$typeAlpha] = $tempArr;

                                        $PSESS[$pkgid][$tourtype][$catid]['others']['price'] = ( $price); // update price here in session
//                            $PSESS[$pkgid][$tourtype][$catid]['others']['price'] = $PSESS[$pkgid][$tourtype][$catid]['others']['price'] + ( $price); // update price here in session
                                    } else {
                                        foreach ($PSESS[$pkgid][$tourtype][$catid]['itineraries'][$itinerary][$typeAlpha] as $key => $value) {
                                            $tempArr[] = ['itemid' => $value['itemid'], 'MasterIntSysId' => $value['MasterIntSysId'], 'IsIncluded' => ($value['itemid'] == $itemid) ? true : false];
                                        }
                                        $PSESS[$pkgid][$tourtype][$catid]['itineraries'][$itinerary][$typeAlpha] = $tempArr;

                                        $PSESS[$pkgid][$tourtype][$catid]['others']['price'] = $PSESS[$pkgid][$tourtype][$catid]['others']['price'] + ( $price); // update price here in session
                                    }
                                } else if (($typeAlpha == 'activity') || ($typeAlpha == 'sightSeeing')) {

                                    $masterDataArray = $this->objHelperGeneral->getMasterData($pkgid, $type); // get master data for price calculation
//                        echo '<pre>'; print_r($masterDataArray); die;

                                    $tempArr = [];
                                    $IsIncluded = '';
                                    foreach ($PSESS[$pkgid][$tourtype][$catid]['itineraries'][$itinerary][$typeAlpha] as $key => $value) {

                                        if ($value['itemid'] == $itemid) {
                                            $IsIncludedNew = true;
                                        } else {
                                            $IsIncludedNew = false;
                                        }

                                        // this is case only in remove action
                                        if (($myaction === 'remove') && ($value['itemid'] == $itemid)) {
                                            $IsIncludedNew = false;
                                        }

                                        $tempArr[] = ['itemid' => $value['itemid'], 'IsIncluded' => $value['IsIncluded'], 'IsIncludedNew' => $IsIncludedNew];
                                    }
                                    $price = $masterDataArray[$param['itemid']]['priceaditionals']['netCost']; // get price from master data array
                                    // if markup type is % than add here
                                    if ((array_key_exists('MarkType', $markupDetialsArray)) && ($markupDetialsArray['MarkType'] == 2)) {
                                        $price = $this->objHelperGeneral->calculateMarkupOnPrice($markupDetialsArray, $price, 1);
                                    }

//                        echo $price;
                                    $PSESS[$pkgid][$tourtype][$catid]['itineraries'][$itinerary][$typeAlpha] = $tempArr;

                                    if ($myaction === 'remove')
                                        $PSESS[$pkgid][$tourtype][$catid]['others']['price'] = $PSESS[$pkgid][$tourtype][$catid]['others']['price'] - ( $price); // update price here in session
                                    else
                                        $PSESS[$pkgid][$tourtype][$catid]['others']['price'] = $PSESS[$pkgid][$tourtype][$catid]['others']['price'] + ( $price); // update price here in session
                                } else if (($typeAlpha == 'services')) {

                                    $masterDataArray = $this->objHelperGeneral->getMasterData($pkgid, $type); // get master data for price calculation
//echo $pkgid , $type;
//  echo '<pre>';
//                print_r($masterDataArray); //die;
//                        echo $itemid;
                                    $tempArr = [];
                                    $recentChecked = [];
                                    $recentPrice = $currentPrice = 0;

                                    foreach ($PSESS[$pkgid][$tourtype][$catid]['others']['services'] as $key => $value) {
                                        $tempArr[] = [
                                            'itemid' => $value['itemid'],
                                            'IsIncluded' => $value['IsIncluded'],
                                            'IsIncludedNew' => (in_array($value['itemid'], explode(',', $itemid)) ) ? true : false
                                        ];

                                        if ($value['IsIncludedNew']) {
                                            $recentChecked[] = $value['itemid'];
                                            $recentPrice += $masterDataArray[$value['itemid']]['cost'];
                                        }
                                        if (in_array($value['itemid'], explode(',', $itemid))) {
//                                var_dump($value['IsIncludedNew']);
//                                if(isset($value['IsIncludedNew']) && ($value['IsIncludedNew'] !=null )) {
                                            $currentPrice += $masterDataArray[$value['itemid']]['cost'];
//                                }
                                        }
                                    }
//                        echo $currentPrice ."/". $recentPrice;

                                    $price = $currentPrice - $recentPrice;

//                        print_r($recentChecked);
//                        print_r($tempArr);
                                    $PSESS[$pkgid][$tourtype][$catid]['others']['services'] = $tempArr;
                                    $PSESS[$pkgid][$tourtype][$catid]['others']['price'] = $PSESS[$pkgid][$tourtype][$catid]['others']['price'] + ( $price); // update price here in session
                                } else if (($typeAlpha == 'transfers')) {
                                    $tempArr = [];
                                    foreach ($PSESS[$pkgid][$tourtype][$catid]['others']['transfers'] as $key => $value) {
                                        $tempArr[] = ['itemid' => $value['itemid'], 'IsIncluded' => ($value['itemid'] == $itemid) ? true : false];
                                    }
                                    $PSESS[$pkgid][$tourtype][$catid]['others']['transfers'] = $tempArr;
                                    $PSESS[$pkgid][$tourtype][$catid]['others']['price'] = $PSESS[$pkgid][$tourtype][$catid]['others']['price'] + ( $price); // update price here in session
                                }

                                // write a variable here to check whether the package is modified or not
                                $PSESS[$pkgid][$tourtype][$catid]['others']['modified'] = 1;
                            }
                        }
                    }

                    $this->_storage->packageSession = $PSESS;

//                echo '<pre>';
//                print_r($this->_storage->packageSession);die("test");
//        $this->PSESS_VAL = $PSESS;
//        print_r($this->PSESS_VAL);

                    echo Zend_Json::encode(['status' => 'success', 'price' => $price]);
                    die;
                }
            }
        }
    }

    public function flushSessionAction() {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        /*
          if(Zend_Session::namespaceUnset($this->SESSION_NAMESPACE) !== null)
          {
          echo 'Flushed all session.';
          }
          else {
          echo 'Already Flushed.';
          }
         */
        $this->objHelperGeneral->flushSession();
        echo 'Flushed';
        exit;
    }

    public function showSessionAction() {
        echo "<pre>";
        print_r($this->_storage->packageSession);
        exit;
    }

    public function downloadPackagePdfAction() {
        $this->view->layout()->disableLayout();
        $this->view->CONST_PACKAGE_TRAVELER_MAX_ROOM = CONST_PACKAGE_TRAVELER_MAX_ROOM;
        $this->view->CONST_PACKAGE_TRAVELER_MAX_ADULT_IN_ROOM = CONST_PACKAGE_TRAVELER_MAX_ADULT_IN_ROOM;
        $this->view->CONST_PACKAGE_TRAVELER_MAX_CHILD_IN_ROOM = CONST_PACKAGE_TRAVELER_MAX_CHILD_IN_ROOM;
        $this->view->CONST_PACKAGE_TRAVELER_MAX_INFANT_IN_ROOM = CONST_PACKAGE_TRAVELER_MAX_INFANT_IN_ROOM;
        $this->view->modulename = $this->modulename;
        $param = $this->getRequest()->getParams();
        $catId = isset($param['catid']) ? (int) $param['catid'] : '';
        $gtxId = isset($param['gtxid']) ? (int) $param['gtxid'] : '';
        $packageId = isset($param['pkgid']) ? (int) $param['pkgid'] : '';
        $tourtype = isset($param['tourtype']) ? (int) $param['tourtype'] : 1;
        $mealplantype = 0;
        $keywords = $param['destname'];
        $customize = (isset($param['customize'])) ? $param['customize'] : 0; // for customization [ 1 , 0]
        $this->view->mealplantype = $mealplantype;
        $model = new Detail_Model_PackageMapper();
        // check package for inactive case
        $checkPackaageSysID = $model->checkPackaageSysID($gtxId);
        if (!empty($checkPackaageSysID)) {
            $packageId = $checkPackaageSysID['PkgSysId'];
        }
        $isModified = 0;
        if (isset($_SESSION['TravelAgent']['session']) && !empty($_SESSION['TravelAgent']['session'])) {
            $getDetail = $model->fetchDetails($catId, $gtxId, $packageId, 'B2B'); // 4th optional parameter [ B2B | B2C ]
        } else {
            $getDetail = $model->fetchDetails($catId, $gtxId, $packageId, 'B2C'); // 4th optional parameter [ B2B | B2C ]
        }

        $CONST_MEAL_PLAN_ARR = unserialize(CONST_MEAL_PLAN_ARR);
        $MPType = $CONST_MEAL_PLAN_ARR[$mealplantype]; // get package meal plan type
        if (isset($_SESSION['TravelAgent']['session']) && !empty($_SESSION['TravelAgent']['session'])) {
            $priceJsonViewFile = $this->objHelperGeneral->getCategoryAndPriceArrayJSON($getDetail['tourTypeFull'], 'B2B', $getDetail['PackageType'], $getDetail['PackageSubType']);
        } else {
            $priceJsonViewFile = $this->objHelperGeneral->getCategoryAndPriceArrayJSON($getDetail['tourTypeFull'], 'B2C', $getDetail['PackageType'], $getDetail['PackageSubType']);
        }

        $priceArrJson = $priceJsonViewFile['priceArrJson'];
        $tourTypeChar = ($tourtype == 1) ? 'P' : 'G'; // if private than P else G for Group tour type
        $pkgprice = $this->objHelperGeneral->getPackagePriceV3(Catabatic_Helper::getPackageType($catId), $tourTypeChar, $priceArrJson, $mealplantype, true);  // Param 4: true ( if calculate discounted price )
        $pkgpriceDiscount = $this->objHelperGeneral->getPackagePriceV3(Catabatic_Helper::getPackageType($catId), $tourTypeChar, $priceArrJson, $mealplantype);  // Param 4: true ( if calculate discounted price )
        $currencyTypeArray = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->getCurrencyData();
        $getCurrencyType = $currencyTypeArray[$priceArrJson[$tourTypeChar][Catabatic_Helper::getPackageType($catId)]['price'][0]['Currency']];
        $this->view->getCurrencyType = ($getCurrencyType) ? $getCurrencyType : 'INR';
        $this->view->pkgprice = round($pkgprice);
        $this->view->pkgpriceDiscount = $pkgpriceDiscount;

        $PackageSubType = $getDetail['PackageSubType'];
        $CONST_MEAL_PLAN_ARR = unserialize(CONST_MEAL_PLAN_ARR);
        $objHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('General');
        $masterDataHotel = $objHelper->getMasterData($packageId, 'h');
        $hotels_array_included_only = $getDetail['hotels_array_included_only'];
        $inner_hotels = $temparray = $hotels_array_included_only_view = [];
        foreach ($hotels_array_included_only as $key => $value_hotel) {
            $inner_hotels = $value_hotel[Catabatic_Helper::getPackageType($catId)];
            $hotel_id = '';
            foreach ($inner_hotels as $k => $val) {
                if ($PackageSubType == 1) {
                    if ($CONST_MEAL_PLAN_ARR[$val['mp']] == $getDetail['MPType']) {
                        $hotel_id = $val['id'];
                    }
                } else {
                    $hotel_id = $val['id'];
                }
            }

            $value = ($hotel_id) ? $masterDataHotel[$hotel_id] : [];

            if (array_key_exists('RefHotelId', $value) && !in_array($hotel_id, $temparray)) {
                $hotels_array_included_only_view[] = $value;
            }
            $temparray[] = $hotel_id;
        }
        $hotelHotelArrayU = $hotels_array_included_only_view;
        $pdfArray = array();
        $pdfArray['PackageName'] = $getDetail['itementries']['Name'];
        $pdfArray['InclusionsT'] = $getDetail['itementries']['Inclusions'];
        $pdfArray['Inclusions'] = $getDetail['itementries']['Terms']['Inclusion'];
        $pdfArray['Exclusions'] = $getDetail['itementries']['Terms']['Exclusions'];
        $pdfArray['TermsConditions'] = $getDetail['itementries']['Terms']['Conditions'];
        $pdfArray['TravelBasics'] = $getDetail['itementries']['Terms']['TravelBasics'];
        $pdfArray['BookingTerm'] = $getDetail['itementries']['Terms']['BookingTerms'];
        $pdfArray['WhyChooseUs'] = $getDetail['itementries']['Terms']['WhyUseUs'];
        $pdfArray['CancellationPolicy'] = $getDetail['itementries']['Terms']['CancellationPolicy'];
        foreach ($getDetail['dayView'] as $itinerariesKey => $itineraries) {
            $count = count($itineraries['day']);
            $pdfArray['Itinerary'][$itinerariesKey]['Title'] = $itineraries['day'][$count - 2];
            $pdfArray['Itinerary'][$itinerariesKey]['Program'] = $itineraries['day'][$count - 1];

            foreach ($itineraries['Hotel'] as $itinerariesItem) {
                foreach ($itinerariesItem['Items'] as $hotelKey => $hotelVal1) {
                    if ($hotelVal1['Id'] == $catId) {
                        foreach ($hotelVal1['Item'] as $hotelVal2) {
                            if (($PackageType == $packageTypeStatic)) {
                                if ($CONST_MEAL_PLAN_ARR[$hotelVal2['MealPlanId']] == $MPType) {
                                    $isMealplanType = true;
                                } else {
                                    $isMealplanType = false;
                                }
                            } else {
                                $isMealplanType = true;
                            }
                            if ($hotelVal2['IsIncluded'] == true && $isMealplanType) {
                                foreach ($hotelHotelArrayU as $hotelId) {
                                    if ($hotelId['RefHotelId'] == $hotelVal2['Id']) {
                                        $pdfArray['Itinerary'][$itinerariesKey]['Hotel'][] = $masterDataHotel[$hotelVal2['Id']]['Name'];
                                    }
                                }
                            }
                        }
                    }
                }
            }

            foreach ($itineraries['SightSeeings'] as $itinerariesItems) {

                if (!empty($itinerariesItems['Items'][0]['Item'])) {
                    foreach ($itinerariesItems['Items'][0]['Item'] as $itinerariesActivitys) {

                        if ($itinerariesActivitys['IsIncluded'] == true) {
                            if ($itinerariesItems['Type'] == 'SIGHTSEEING') {
                                foreach ($getDetail['finalArray']['SightSeeings'] as $finalSightSeeing => $valfinalSightSeeing) {
                                    if (isset($valfinalSightSeeing['SightSeeing'])) {
                                        foreach ($valfinalSightSeeing['SightSeeing'] as $keySightSeeing => $valSightSeeing) {
                                            if ($itinerariesActivitys['Id'] == $valSightSeeing['RefSSId']) {
                                                $pdfArray['Itinerary'][$itinerariesKey]['SIGHTSEEING'][] = trim($valSightSeeing['Title']);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

//        echo "<pre>";
//        print_r($pdfArray);
//        exit;
//        $finalArray = array();
//        if (!empty($getDetail)) {
//           
//            $i = 0;
//            foreach ($getDetail['itementries']['Itineraries']['Itinerary'] as $value) {
//                $finalArray['Itinerary'][$value['Day']]['Title'][] = $value['Title'];
//                $finalArray['Itinerary'][$value['Day']]['Program'][] = $value['Program'];
//                $i++;
//            }
//        }
//        echo "<pre>";
//        print_r($finalArray);
//        exit;

        if ($PackageType == 2) {
            if ($tourtype == 1) {
                $sizeT = $getDetail['itementries']['AllowMinPax'];
            } else {
                $sizeT = $getDetail['itementries']['GroupSize'];
            }
            $perperson = "Per Person For a Group Size of $sizeT Pax";
        } else {

            $perperson = 'Per Person twin sharing';
        }

        $this->view->perperson = $perperson;
        $this->view->pdfArray = $pdfArray;
        $this->view->baseUrl = $this->baseUrl;
    }

    public function saveChangeHotelDataAction() {
        $this->_helper->layout()->disableLayout();
        if ($this->getRequest()->isXmlHttpRequest()) {
            if ($this->getRequest()->isPost()) {
                $param = $this->getRequest()->getParams();
                echo "<pre>";
                print_r($param);
                die;
            }
        }
    }

}

Youez - 2016 - github.com/yon3zu
LinuXploit