Example #1
0
 public function xmlAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     echo "<pre>";
     $filename = "data/sample - Chiang Mai.xml";
     $xml_parser = new Base_Xml_Parser(null, $filename);
     $continentName = $xml_parser->Data['identification']['geoTag1'];
     $countryName = $xml_parser->Data['identification']['geoTag2'];
     $cityName = $xml_parser->Data['identification']['geoTag3'];
     $regionName = $cityName;
     $stateName = $cityName;
     //----insert into continent
     $continent_id = 0;
     $continentM = new Application_Model_Continent();
     $continent = $continentM->fetchRow("name='{$continentName}'");
     if (false === $continent) {
         $continentM->setName($continentName);
         $continent_id = $continentM->save();
     } else {
         $continent_id = $continent->getId();
     }
     //--------------------------
     //----insert into country
     $country_id = 0;
     $countryM = new Application_Model_Country();
     $country = $countryM->fetchRow("name='{$countryName}' and continent_id='{$continent_id}'");
     if (false === $country) {
         $countryM->setName($countryName);
         $countryM->setContinentId($continent_id);
         $country_id = $countryM->save();
     } else {
         $country_id = $country->getId();
     }
     //-------------------------------
     ///------insert into region
     $region_id = 0;
     $regionM = new Application_Model_Region();
     $region = $regionM->fetchRow("name='{$regionName}' and country_id='{$country_id}'");
     if (false === $region) {
         $regionM->setName($regionName);
         $regionM->setCountryId($country_id);
         $region_id = $regionM->save();
     } else {
         $region_id = $region->getId();
     }
     //------------------------
     ///------insert into state
     $state_id = 0;
     $stateM = new Application_Model_State();
     $state = $stateM->fetchRow("name='{$stateName}' and region_id='{$region_id}'");
     if (false === $state) {
         $stateM->setName($stateName);
         $stateM->setRegionId($region_id);
         $state_id = $stateM->save();
     } else {
         $state_id = $state->getId();
     }
     //------------------------
     ///------insert into city
     $city_id = 0;
     $cityM = new Application_Model_City();
     $city = $cityM->fetchRow("name='{$cityName}' and country_id='{$state_id}'");
     if (false === $city) {
         $cityM->setName($cityName);
         $cityM->setCountryId($country_id);
         $city_id = $cityM->save();
     } else {
         $city_id = $city->getId();
     }
     //------------------------
     if ($continent_id > 0 && $country_id > 0 && $city_id > 0) {
         //it is city
         $locationType = "city";
         $locationId = $city_id;
     } else {
         if ($continent_id > 0 && $country_id > 0) {
             //it is country
             $locationType = "country";
             $locationId = $country_id;
         } else {
             if ($continent_id > 0) {
                 //it is continent
                 $locationType = "continent";
                 $locationId = $continent_id;
             }
         }
     }
     ///////////Remove/////////
     $destinationM = new Application_Model_Destination();
     $destinationM->delete();
     $experiencesM = new Application_Model_Experiences();
     $experiencesM->delete();
     $practicalitiesM = new Application_Model_Practicalities();
     $practicalitiesM->delete();
     //------------------------------
     $title = $xml_parser->Data['content']['title'];
     $introduction = $xml_parser->Data['content']['introduction'];
     $destinationM = new Application_Model_Destination();
     $destinationM->setTitle($title);
     $destinationM->setIntroduction($introduction);
     $destinationM->setLocationId($locationId);
     $destinationM->setLocationType($locationType);
     $destination_id = $destinationM->save();
     foreach ($xml_parser->Data['content']['experiences'] as $experiences) {
         foreach ($experiences as $_item) {
             $experiencesM = new Application_Model_Experiences();
             $experiencesM->setTitle($_item['title']);
             $experiencesM->setDestinationId($destination_id);
             $experiencesM->setCopy($_item['copy']);
             $experiencesM->save();
         }
     }
     foreach ($xml_parser->Data['content']['practicalities'] as $practicalities) {
         foreach ($practicalities as $_item) {
             $practicalitiesM = new Application_Model_Practicalities();
             $practicalitiesM->setTitle($_item['title']);
             $practicalitiesM->setDestinationId($destination_id);
             $practicalitiesM->setCopy($_item['copy']);
             $practicalitiesM->save();
         }
     }
     //print_r($xml_parser->Data);
 }
 public function indexAction()
 {
     $this->_helper->layout->setLayout('3column-profile-user-where-i-am');
     $this->view->otherUserId = $this->view->userId = $userid = $this->_getParam('id');
     $userM = new Application_Model_User();
     $userM = $userM->find($userid);
     $this->view->userObject = $userM;
     //Redirect user if not active, added by Mahipal Adhikari on 3-jan-2011
     if (false === $userM->checkUserActiveStatus($userid)) {
         $this->_helper->redirector('index', 'index');
     }
     //get logged in user id
     $userNs = new Zend_Session_Namespace('members');
     $loggedin_id = $userNs->userId;
     //redirect user to Where-I-Am page if viewing own profile, added by mahipal on 7-Feb-2011
     if ($loggedin_id == $userid) {
         $this->_redirect($this->view->seoUrl('/gapper/where-i-am/'));
     }
     /************************ Check user Whre-I-Am privacy settings START *****************/
     $user_id = $userid;
     //echo "user id=".$user_id." and Login id=".$loggedin_id;
     //now check user where-i-am privacy permissions
     $view_profile = false;
     $userObj = new Application_Model_User();
     $view_profile = $userObj->checkUserPrivacySettings($user_id, $loggedin_id, 1);
     //if logged in user has no permission then display error page
     if (!$view_profile) {
         //$this->view->error_message = "You are not authorised to view <b>".$userM->getFirstName()." ".$userM->getLastName()."</b>'s location.";
         $this->view->user_id = $user_id;
         $this->render('error');
     }
     //get Where I am (Map) permission
     $view_map = false;
     $view_map = $userObj->checkUserPrivacySettings($user_id, $loggedin_id, 3);
     if (false == $view_map) {
         $this->_helper->redirector('view', 'profile', 'default', array('username' => $userM->getUsername()));
         //$this->view->error_message = "You are not authorised to view <b>".$userM->getFirstName()." ".$userM->getLastName()."</b>'s map location.";
         //$this->render('error');
     }
     $this->view->view_map = $view_map;
     /************************ Check user privacy settings END *****************/
     $this->view->postWallAccess = false;
     if (false !== $userObj->getUserConnection($user_id, $loggedin_id)) {
         $this->view->postWallAccess = true;
     }
     $this->view->countryName = $userM->getCountryName();
     $this->view->cityName = $userM->getCityName();
     $this->view->userThumb = $userM->getThumbnail();
     $this->view->fullName = $userM->getFirstName() . " " . $userM->getLastName();
     $destinationM = new Application_Model_Destination();
     $destination = $destinationM->fetchAll();
     $this->view->destination = $destination;
     $experienceM = new Application_Model_Experiences();
     $destinationId = $this->getRequest()->getParam('destination_id');
     /*--find the current location coordinates --*/
     $gapperLocationM = new Application_Model_GapperLocation();
     $where = "user_id='{$userid}'";
     $order = "addedon desc";
     $gapperLocation = $gapperLocationM->fetchRow($where, $order);
     if (false == $gapperLocation) {
         //these are default coordinates.
         $this->view->myLongitude = "";
         $this->view->myLatitude = "";
         //if user have no coordinates then redirect its profile page
         $this->_helper->redirector('view', 'profile', 'default', array('username' => $userM->getUsername()));
     } else {
         $this->view->myLongitude = $gapperLocation->getLongitude();
         $this->view->myLatitude = $gapperLocation->getLatitude();
     }
     /*------------------------------------------*/
 }
 public function addCountryAction()
 {
     //get request variables and set to view
     $id = $this->_getParam("id");
     $page = $this->_getParam("page");
     $selTab = $this->_getParam("tab", "tabs-1");
     $this->view->id = $id;
     $this->view->page = $page;
     $this->view->selTab = $selTab;
     $errorMsg = "";
     $request = $this->getRequest();
     if ($request->isPost()) {
         $options = $request->getPost();
         if ($options["update_action"] == "overview") {
             $node_id = 0;
             $destination_name = "";
             $full_destination_name = "";
             $intro_mini = "";
             $intro_short = $options["introShort"];
             $timezones = array("0" => array("gmt_utc" => ""));
             $leaders = array(0 => array("leader_name" => "", "leader_type" => "", "leader_title" => ""));
             $religion = "";
             $currency_code = "";
             $currency_name = "";
             $currency_symbol = "";
             $currency_unit = "";
             $electrical_plugs = array(0 => array("image_filename" => "/images/plug_types/elec_4.gif", "electrical_plug_description" => ""));
             $health_conditions = array("cholera" => "", "dengue fever" => "", "hepatitis" => "", "malaria" => "", "meningococcal meningitis" => "", "typhoid" => "");
             $transport = array("getting there and away" => "", "getting around" => "");
             //$images				= array ("0"=> array("image_caption"=>"", "image_photographer"=>"Administrator", "image_filename"=>"", "image_thumbnail_filename"=>""));
             $images = array();
             $map = array("map_name" => "N/A", "map_filename" => "/maps/", "map_thumbnail_filename" => "/maps/thumbs/");
             $pois = array("0" => array("poi_name" => "", "address_parts" => array("0" => array("address_type" => "street", "address_text" => "")), "address_postcode" => "", "poi_web" => "", "review_summary" => "", "review_full" => "", "keywords" => array("keyword" => array("0" => "NA"))));
             $attractions = array("0" => array("destination_name" => "", "full_destination_name" => "", "intro_short" => "", "intro_medium" => ""));
             $country_id = $options["countryId"];
             $area_sqkm = 0;
             $population = 0;
             $language_spokens = array(0 => array("language_spoken_type" => "official", "language_spoken_name" => "N/A", "language_spoken_description" => "N/A"));
             //get Country name
             $countryM = new Application_Model_Country();
             $countryM = $countryM->find($options["countryId"]);
             if ($countryM !== false) {
                 $destination_name = $countryM->getName();
                 $full_destination_name = $countryM->getName();
             }
             $params["nodeId"] = $node_id;
             $params["destinationName"] = $destination_name;
             $params["fullDestinationName"] = $full_destination_name;
             $params["introMini"] = $intro_mini;
             $params["introShort"] = $intro_short;
             $params["timezones"] = serialize($timezones);
             $params["leaders"] = serialize($leaders);
             $params["areaSqkm"] = $area_sqkm;
             $params["population"] = $population;
             $params["languageSpokens"] = serialize($language_spokens);
             $params["religion"] = $religion;
             $params["currencyCode"] = $currency_code;
             $params["currencyName"] = $currency_name;
             $params["currencySymbol"] = $currency_symbol;
             $params["currencyUnit"] = $currency_unit;
             $params["electricalPlugs"] = serialize($electrical_plugs);
             $params["healthConditions"] = serialize($health_conditions);
             $params["transport"] = serialize($transport);
             $params["images"] = serialize($images);
             $params["map"] = serialize($map);
             $params["pois"] = serialize($pois);
             $params["attractions"] = serialize($attractions);
             $params["countryId"] = $country_id;
             $lonelyPlanetCountryM = new Application_Model_LonelyPlanetCountry($params);
             $res = $lonelyPlanetCountryM->save();
             if ($res) {
                 //save destination information into DB
                 $title = "A guide to " . $destination_name;
                 $introduction = "";
                 $location_id = $country_id;
                 $location_type = "country";
                 $bankBreakerAllArr = array();
                 $bankBreakerArr1 = array();
                 $bankBreakerArr2 = array();
                 for ($item = 0; $item < count($options["bankBreakerItem"]); $item++) {
                     $bankBreakerArr1[$options["bankBreakerItem"][$item]] = $options["bankBreakerRating"][$item];
                 }
                 $bankBreakerArr2["amount"] = $options["bankBreakerAmount"];
                 $bankBreakerArr2["currency"] = $options["bankBreakerCurrency"];
                 $bankBreakerArr2["rate"] = $options["bankBreakerRate"];
                 $bankBreakerAllArr["bankBreaker"] = $bankBreakerArr1;
                 $bankBreakerAllArr["dailyBudget"] = $bankBreakerArr2;
                 $bank_breaker = serialize($bankBreakerAllArr);
                 $knowledgeArr = array(0 => array("title" => "", "copy" => ""));
                 $knowledge = serialize($knowledgeArr);
                 $destination["title"] = $title;
                 $destination["introduction"] = $introduction;
                 $destination["locationId"] = $location_id;
                 $destination["locationType"] = $location_type;
                 $destination["bankBreaker"] = $bank_breaker;
                 $destination["knowledge"] = $knowledge;
                 //if Destination information is already exists then update table record else insert new record
                 $destinationM = new Application_Model_Destination($destination);
                 $destinationM = $destinationM->fetchRow("location_id={$location_id} AND location_type='country'");
                 if (false !== $destinationM) {
                     $destinationM->setTitle($title);
                     $destinationM->setIntroduction($introduction);
                     $destinationM->setLocationId($location_id);
                     $destinationM->setLocationType($location_type);
                     $destinationM->setBankBreaker($bank_breaker);
                     $destinationM->setKnowledge($knowledge);
                     $destinationM->save();
                     $destination_id = $destinationM->getId();
                 } else {
                     $destinationM = new Application_Model_Destination($destination);
                     $destination_id = $destinationM->save();
                 }
                 if ($destination_id) {
                     //save Don't leave Without information
                     for ($dont = 0; $dont < count($options["pracTitle"]); $dont++) {
                         if (trim($options["pracTitle"][$dont]) != "") {
                             $pracTitle = $options["pracTitle"][$dont];
                             $pracCopy = $options["pracCopy"][$dont];
                             $newItem["title"] = $pracTitle;
                             $newItem["copy"] = $pracCopy;
                             $newItem["destinationId"] = $destination_id;
                             $dontLeaveWithoutM = new Application_Model_DontLeaveWithout($newItem);
                             $dontId = $dontLeaveWithoutM->save();
                         }
                         //end if
                     }
                     //end for
                     //$_SESSION['errorMsg'] = "Overview has been saved.";
                     $this->_helper->redirector("edit-country", "featured-city", "admin", array("id" => $id, "page" => $page, "tab" => "tabs-1"));
                 } else {
                     $errorMsg = "Error occured, unable to save data into destination.";
                 }
             } else {
                 $errorMsg = "Error occured, unable to save data into Lonely Planet country.";
             }
         }
         //end if
     }
     //end if
     $this->view->errorMsg = $errorMsg;
 }
 /**
  * @Created By : Mahipal Singh Adhikari
  * @Created On : 6-Dec-2010
  * @Description: Get City/Place information and display city content
  */
 public function cityAction()
 {
     $id = $this->_getParam('id');
     $cityM = new Application_Model_City();
     $city = $cityM->find($id);
     $this->view->invalidCity = "0";
     if (false === $city) {
         $this->view->invalidCity = "1";
     } else {
         //set City and Country name to view
         $this->view->cityName = $cityName = $city->getName();
         $this->view->country_id = $city->getCountryId();
         //now get country in which this city exists
         $countryM = new Application_Model_Country();
         $country_id = $city->getCountryId();
         $countryM = $countryM->find($country_id);
         $this->view->countyName = $countryName = $countryM->getName();
         //set City Google map address
         $searchAddress = $cityName . " ," . $countryName;
         $latitude = "-34.397";
         $longitude = "150.644";
         //if Lat/Lon coordinates available
         if ($city->getLatitude() != "" && $city->getLongitude() != "") {
             $latitude = $city->getLatitude();
             $longitude = $city->getLongitude();
             $searchAddress = "(" . $latitude . ", " . $longitude . ")";
         }
         $this->view->searchAddress = $searchAddress;
         $this->view->latitude = $latitude;
         $this->view->longitude = $longitude;
         $destinationM = new Application_Model_Destination();
         $destination = $destinationM->fetchRow("location_id='{$id}' AND location_type='city'");
         if (false !== $destination) {
             $this->view->overview = $destination->getTitle();
             $this->view->nutshell = $destination->getIntroduction();
             $destination_id = $destination->getId();
             //Get Eat sleep Drink information of city
             $eatSleepDrink = $destinationM->destinationEatSleepDrink($destination_id);
             if (false !== $eatSleepDrink) {
                 if (count($eatSleepDrink) > 0) {
                     $this->view->eatSleepDrink = $eatSleepDrink;
                 }
             }
             //Get Expriences of city
             $exprienceArr = $destinationM->destinationExprience($destination_id);
             if (false !== $exprienceArr) {
                 if (count($exprienceArr) > 0) {
                     $this->view->exprience = $exprienceArr;
                 }
             }
             //Get Practicalities of city
             $practicalArr = $destinationM->destinationPractical($destination_id);
             if (false !== $practicalArr) {
                 if (count($practicalArr) > 0) {
                     $this->view->practical = $practicalArr;
                 }
             }
             //get city/place images
             $cityImagesArr = $destinationM->destinationImages($id, "city");
             if (false !== $cityImagesArr) {
                 if (count($cityImagesArr) > 0) {
                     $this->view->cityImagesArr = $cityImagesArr;
                 }
             }
         }
         //select country information to display in other tabs
         if (false === $countryM) {
             $this->view->countryInfo = "no_data";
         } else {
             $db = Zend_Registry::get("db");
             $sSQL = "SELECT * FROM lonely_planet_country WHERE country_id='{$country_id}'";
             $row = $db->fetchRow($sSQL);
             if (!empty($row)) {
                 $this->view->countryInfo = $row;
                 //$destinationM	=	new Application_Model_Destination();
                 $destination = $destinationM->fetchRow("location_id='{$country_id}' AND location_type='country'");
                 if (false !== $destination) {
                     $bank_breaker = unserialize($destination->getBankBreaker());
                     $this->view->bank_breaker = $bank_breaker;
                     $dontLeaveWithoutM = new Application_Model_DontLeaveWithout();
                     $this->view->dontLeaveWithout = $dontLeaveWithoutM->fetchAll("destination_id='{$destination->getId()}' ");
                 }
             } else {
                 $this->view->countryInfo = "no_data";
             }
         }
     }
     //end of else
 }
Example #5
0
 /**
  * @Created By : Mahipal Singh Adhikari
  * @Created On : 16-March-2011
  * @Description: Set default row data for Country/City if not provided by XML feeds
  */
 public function setDefaultRowData($location_id, $location_type)
 {
     //set default values
     $title = "";
     $introduction = "";
     $location_id = trim($location_id);
     $location_type = trim($location_type);
     $bankbreakerArr = array();
     $bank_breaker = serialize($bankbreakerArr);
     $knowledgeArr = array(0 => array("title" => "", "copy" => ""));
     $knowledge = serialize($knowledgeArr);
     //set title
     if ($location_type == "country") {
         $countryM = new Application_Model_Country();
         $countryM = $countryM->find($location_id);
         if ($countryM !== false) {
             $title = "A guide to " . $countryM->getName();
         }
     }
     if ($location_type == "city") {
         $cityM = new Application_Model_City();
         $cityM = $cityM->find($location_id);
         if ($cityM !== false) {
             $title = "A guide to " . $cityM->getName();
         }
     }
     $model = new Application_Model_Destination();
     $model->setTitle($title);
     $model->setIntroduction($introduction);
     $model->setLocationId($location_id);
     $model->setLocationType($location_type);
     $model->setBankBreaker($bank_breaker);
     $model->setKnowledge($knowledge);
     $res = $model->save();
     if ($res) {
         return $res;
     } else {
         return false;
     }
 }
Example #6
0
 public function whereIAmAction()
 {
     $this->_helper->layout->setLayout('3column-my-account');
     $userNs = new Zend_Session_Namespace('members');
     $this->view->userId = $userId = $userNs->userId;
     $user = new Application_Model_User();
     $user = new Application_Model_User();
     $this->view->loc = $user->getNearByUser($userId, 1000, 20);
     //var_dump($this->view->loc);
     $user = $user->find($userNs->userId);
     $this->view->loginUrl = "";
     $facebook = $this->view->facebook();
     if ($user->getFacebookId() == "" || is_null($user->getFacebookId())) {
         $return_url = Zend_Registry::get('siteurl') . "/index/do-fb-return/";
         $cancel_url = Zend_Registry::get('siteurl') . "/index/cancel-facebook";
         $this->view->loginUrl = $loginUrl = $facebook->getLoginUrl(array("cancel_url" => $cancel_url, "next" => $return_url, "req_perms" => "offline_access,publish_stream,read_stream,email,user_birthday,user_location", "display" => "popup"));
     }
     $userM = new Application_Model_User();
     $userM = $userM->find($userId);
     $this->view->countryName = $userM->getCountryName();
     $this->view->cityName = $userM->getCityName();
     $this->view->userThumb = $userM->getThumbnail();
     $this->view->fullName = $userM->getFirstName() . " " . $userM->getLastName();
     $destinationM = new Application_Model_Destination();
     $destination = $destinationM->fetchAll();
     $this->view->destination = $destination;
     $experienceM = new Application_Model_Experiences();
     $destinationId = $this->getRequest()->getParam('destination_id');
     /*--find the current location coordinates --*/
     $gapperLocationM = new Application_Model_GapperLocation();
     $where = "user_id='{$userId}'";
     $order = "addedon desc";
     $gapperLocation = $gapperLocationM->fetchRow($where, $order);
     if (false == $gapperLocation) {
         //these are default coordinates.
         $this->view->myLongitude = "";
         $this->view->myLatitude = "";
         $this->view->addedon = "";
     } else {
         $this->view->myLongitude = $gapperLocation->getLongitude();
         $this->view->myLatitude = $gapperLocation->getLatitude();
         $this->view->addedon = $gapperLocation->getAddedon();
     }
     /*------------------------------------------*/
 }
Example #7
0
 public function xmlAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $db = Zend_Registry::get("db");
     $sanitizeM = new Base_Sanitize();
     $directory = "data/zone/XML/";
     if (!($dp = opendir($directory))) {
         die("Cannot open {$directory}.");
     }
     $ctr = 0;
     //truncate tables
     $db->query("TRUNCATE TABLE destination");
     $db->query("TRUNCATE TABLE experiences");
     $db->query("TRUNCATE TABLE practicalities");
     $db->query("TRUNCATE TABLE dont_leave_without");
     $db->query("TRUNCATE TABLE lonely_planet_country");
     $db->query("TRUNCATE TABLE eat_sleep_drink");
     $db->query("TRUNCATE TABLE log");
     $db->query("TRUNCATE TABLE error_log");
     $db->query("TRUNCATE TABLE area");
     $db->query("TRUNCATE TABLE region");
     $db->query("TRUNCATE TABLE continent");
     $db->query("TRUNCATE TABLE country");
     $db->query("TRUNCATE TABLE city");
     $db->query("TRUNCATE TABLE seo_url");
     //------------------------------
     while ($filename = readdir($dp)) {
         $res = $db->fetchAll("select * from log where message='{$filename}'");
         if (is_dir($filename)) {
             continue;
         } else {
             if ($filename != '.' && $filename != '..' && empty($res)) {
                 $file_path = $directory . $filename;
                 $data['message'] = $filename;
                 $data['log_start'] = date("Y-m-d H:i:s");
                 $log_id = $db->insert("log", $data);
                 $xml_parser = new Base_Xml_Parser(null, $file_path);
                 $continentName = "";
                 if (isset($xml_parser->Data['identification']['geoTag1'])) {
                     $continentName = $sanitizeM->clearInputs($xml_parser->Data['identification']['geoTag1']);
                 }
                 $countryName = "";
                 if (isset($xml_parser->Data['identification']['geoTag2'])) {
                     $countryName = $sanitizeM->clearInputs($xml_parser->Data['identification']['geoTag2']);
                 }
                 $cityName = "";
                 if (isset($xml_parser->Data['identification']['geoTag3'])) {
                     $cityName = $sanitizeM->clearInputs($xml_parser->Data['identification']['geoTag3']);
                 }
                 $regionName = $cityName;
                 $areaName = $cityName;
                 //----insert into continent
                 $continent_id = 0;
                 if ($continentName != "") {
                     $continentM = new Application_Model_Continent();
                     $continent = $continentM->fetchRow("name='{$continentName}'");
                     if (false === $continent) {
                         $continentM->setName($continentName);
                         $continent_id = $continentM->save();
                     } else {
                         $continent_id = $continent->getId();
                     }
                 }
                 //--------------------------
                 //----insert into country
                 $country_id = 0;
                 if ($countryName != "") {
                     //if not exists
                     if (!$this->duplicateCountries($countryName)) {
                         $countryM = new Application_Model_Country();
                         $country = $countryM->fetchRow("name='{$countryName}' and continent_id='{$continent_id}'");
                         if (false === $country) {
                             $countryM->setName($countryName);
                             $countryM->setContinentId($continent_id);
                             $country_id = $countryM->save();
                         } else {
                             $country_id = $country->getId();
                         }
                     }
                 }
                 //-------------------------------
                 //------insert into region
                 $region_id = 0;
                 $regionM = new Application_Model_Region();
                 $region = $regionM->fetchRow("name='{$regionName}' and country_id='{$country_id}' AND continent_id='{$continent_id}'");
                 if (false === $region) {
                     $regionM->setName($regionName);
                     $regionM->setCountryId($country_id);
                     $regionM->setContinentId($continent_id);
                     $region_id = $regionM->save();
                 } else {
                     $region_id = $region->getId();
                 }
                 //------insert into city
                 $city_id = 0;
                 if ($cityName != "") {
                     $cityM = new Application_Model_City();
                     $city = $cityM->fetchRow("name='{$cityName}' and region_id='{$region_id}' AND country_id='{$country_id}' AND continent_id='{$continent_id}'");
                     if (false === $city) {
                         if ($country_id != 0) {
                             //echo "<br />File name=".$file_path;
                             $cityM->setName($cityName);
                             $cityM->setRegionId($region_id);
                             $cityM->setCountryId($country_id);
                             $cityM->setContinentId($continent_id);
                             $cityM->setFeaturedTop(0);
                             $cityM->setFeaturedOther(0);
                             $city_id = $cityM->save();
                         }
                     } else {
                         $city_id = $city->getId();
                     }
                 }
                 //------------------------
                 //------insert into area
                 $area_id = 0;
                 $areaM = new Application_Model_Area();
                 $area = $areaM->fetchRow("name='{$areaName}' and city_id='{$city_id}' and region_id='{$region_id}' AND country_id='{$country_id}' AND continent_id='{$continent_id}' ");
                 if (false === $area) {
                     $areaM->setName($areaName);
                     $areaM->setRegionId($region_id);
                     $areaM->setCountryId($country_id);
                     $areaM->setContinentId($continent_id);
                     $areaM->setCityId($city_id);
                     $area_id = $areaM->save();
                 } else {
                     $area_id = $area->getId();
                 }
                 //------------------------
                 if ($continent_id > 0 && $country_id > 0 && $city_id > 0) {
                     //it is city
                     $locationType = "city";
                     $locationId = $city_id;
                 } else {
                     if ($continent_id > 0 && $country_id > 0) {
                         //it is country
                         $locationType = "country";
                         $locationId = $country_id;
                     } else {
                         if ($continent_id > 0) {
                             //it is continent
                             $locationType = "continent";
                             $locationId = $continent_id;
                         }
                     }
                 }
                 if (isset($xml_parser->Data['content'])) {
                     $title = $sanitizeM->clearInputs($xml_parser->Data['content']['title']);
                     $introduction = "";
                     if (isset($xml_parser->Data['content']['introduction'])) {
                         $introduction = $xml_parser->Data['content']['introduction'];
                     }
                     $destinationM = new Application_Model_Destination();
                     $bankBreakerPincher = "";
                     $knowledgeArr = "";
                     //set bank breaker array to save
                     if (isset($xml_parser->Data['content']['costs'])) {
                         $bank_breaker = array();
                         $bankBreaker = array();
                         foreach ($xml_parser->Data['content']['costs'] as $breaker) {
                             $bank_breaker[] = $breaker;
                         }
                         //break into two array
                         $costItem = $bank_breaker[0];
                         $dailyBudget = $bank_breaker[1];
                         for ($cntBr = 0; $cntBr < count($costItem); $cntBr++) {
                             $bankBreaker[$costItem[$cntBr]['name']] = substr($costItem[$cntBr]['rating'], 0, strlen($costItem[$cntBr]['rating']) - 1);
                         }
                         //keep in one array
                         $bankBreakerPincher = array("bankBreaker" => $bankBreaker, "dailyBudget" => $dailyBudget);
                     }
                     if (isset($xml_parser->Data['content']['knowledge'])) {
                         $knowledgeArr = array();
                         $knowledge = $xml_parser->Data['content']['knowledge'];
                         $knowledgeArr = $knowledge['item'];
                     }
                     $destinationM->setTitle($title);
                     $destinationM->setIntroduction($introduction);
                     $destinationM->setLocationId($locationId);
                     $destinationM->setLocationType($locationType);
                     $destinationM->setBankBreaker(serialize($bankBreakerPincher));
                     $destinationM->setKnowledge(serialize($knowledgeArr));
                     $destination_id = $destinationM->save();
                     if (isset($xml_parser->Data['content']['experiences'])) {
                         foreach ($xml_parser->Data['content']['experiences'] as $experiences) {
                             foreach ($experiences as $_item) {
                                 $experiencesM = new Application_Model_Experiences();
                                 $experiencesM->setTitle($_item['title']);
                                 $experiencesM->setDestinationId($destination_id);
                                 $experiencesM->setCopy($_item['copy']);
                                 $experiencesM->save();
                             }
                         }
                     }
                     if (isset($xml_parser->Data['content']['dontLeaveWithout'])) {
                         foreach ($xml_parser->Data['content']['dontLeaveWithout'] as $dontLeaveWithout) {
                             foreach ($dontLeaveWithout as $_item) {
                                 $dontLeaveWithoutM = new Application_Model_DontLeaveWithout();
                                 $dontLeaveWithoutM->setTitle($_item['title']);
                                 $dontLeaveWithoutM->setDestinationId($destination_id);
                                 $dontLeaveWithoutM->setCopy($_item['copy']);
                                 $dontLeaveWithoutM->save();
                             }
                         }
                     }
                     if (isset($xml_parser->Data['content']['practicalities'])) {
                         foreach ($xml_parser->Data['content']['practicalities'] as $practicalities) {
                             foreach ($practicalities as $_item) {
                                 $practicalitiesM = new Application_Model_Practicalities();
                                 $practicalitiesM->setTitle($_item['title']);
                                 $practicalitiesM->setDestinationId($destination_id);
                                 $practicalitiesM->setCopy($_item['copy']);
                                 $practicalitiesM->save();
                             }
                         }
                     }
                     if (isset($xml_parser->Data['content']['eatSleepDrink'])) {
                         foreach ($xml_parser->Data['content']['eatSleepDrink'] as $eatsleepdrink) {
                             foreach ($eatsleepdrink as $_item) {
                                 $EatSleepDrinkM = new Application_Model_EatSleepDrink();
                                 $EatSleepDrinkM->setTitle($_item['title']);
                                 $EatSleepDrinkM->setDestinationId($destination_id);
                                 $EatSleepDrinkM->setBackPackerCopy($_item['backpackerCopy']);
                                 $EatSleepDrinkM->setLocalCopy($_item['localCopy']);
                                 $EatSleepDrinkM->save();
                             }
                         }
                     }
                     $data['log_end'] = date("Y-m-d H:i:s");
                     $res = $db->update("log", $data, "id='{$log_id}'");
                 }
             }
         }
     }
     //end of main while loop
 }