/**
  * @Created By	: Mahipal Singh Adhikari
  * @Created On	: 7-Mar-2011
  * @Description	: Manage destination City/Places: Edit city content
  */
 public function editCityAction()
 {
     //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;
     //set error message
     $this->view->errorMsg = "";
     if (isset($_SESSION['errorMsg'])) {
         $this->view->errorMsg = $_SESSION['errorMsg'];
         unset($_SESSION['errorMsg']);
     }
     //select Destinations details
     $destinationId = "";
     $destinationM = new Application_Model_Destination();
     $destinationM = $destinationM->fetchRow("location_id={$id} AND location_type='city'");
     if (false !== $destinationM) {
         $this->view->destination = $destinationM;
         $destinationId = $destinationM->getId();
         //select Experiences details
         $expriencesM = new Application_Model_Experiences();
         $expriencesM = $expriencesM->fetchAll("destination_id={$destinationId}", "id ASC");
         if (false !== $expriencesM) {
             $this->view->expriences = $expriencesM;
         }
         //select EAT, SLEEP, DRINK AND BE MERRY section details
         $eatsleepdrinkM = new Application_Model_EatSleepDrink();
         $eatsleepdrinkM = $eatsleepdrinkM->fetchAll("destination_id={$destinationId}");
         if (false !== $eatsleepdrinkM) {
             $this->view->eatsleepdrink = $eatsleepdrinkM;
         }
         //select Practicalities details
         $practicalitiesM = new Application_Model_Practicalities();
         $practicalitiesM = $practicalitiesM->fetchAll("destination_id={$destinationId}", "id ASC");
         if (false !== $practicalitiesM) {
             $this->view->practicalities = $practicalitiesM;
         }
         //select City/Places images
         $cityimagesM = new Application_Model_CityImages();
         $cityimagesM = $cityimagesM->fetchAll("city_id={$id}", "weight ASC");
         if (false !== $cityimagesM) {
             $this->view->cityimages = $cityimagesM;
         }
         //create image upload form
         $uploadForm = new Admin_Form_CityImages();
         $elements = $uploadForm->getElements();
         $uploadForm->clearDecorators();
         foreach ($elements as $element) {
             $element->removeDecorator('label');
             $element->removeDecorator('td');
             $element->removeDecorator('tr');
             $element->removeDecorator('row');
             $element->removeDecorator('HtmlTag');
             $element->removeDecorator('placement');
             $element->removeDecorator('data');
         }
         $this->view->uploadForm = $uploadForm;
     } else {
         //if not data found, then insert blank empty rows and redirect to this
         //echo "No data provided from XML Feeds.";exit;
         $destinationM = new Application_Model_Destination();
         $destination_id = $destinationM->setDefaultRowData($id, "city");
         $destinationM->setDefaultCityData($destination_id);
         $this->_helper->redirector("edit-city", "featured-city", "admin", array("id" => $id, "page" => $page, "tab" => "tabs-1"));
     }
     //submit form
     $request = $this->getRequest();
     if ($request->isPost()) {
         $options = $request->getPost();
         if ($options["update_action"] == "destination") {
             $response = "";
             $destinationM = new Application_Model_Destination();
             $destinationRes = $destinationM->find($options["destination_id"]);
             if (false !== $destinationRes) {
                 $destinationRes->setTitle($options["title"]);
                 $destinationRes->setIntroduction($options["introduction"]);
                 $destinationRes->save();
                 //update block XML Feeds table
                 $destM = new Application_Model_Destination();
                 $destM->updateXMLFeedsBlockStatus("city", $id, $options["block_ovewrite"]);
                 //$arrayResult = Array("error"=>0, "response"=>"Introduction information has been updated successfully.");
                 $response = "Introduction information has been updated successfully.";
             } else {
                 //$arrayResult = Array("error"=>1, "response"=>"Error occured, no data found.");
                 $response = "Error occured, no data found.";
             }
             $_SESSION['errorMsg'] = $response;
             $this->_helper->redirector("edit-city", "featured-city", "admin", array("id" => $id, "tab" => "tabs-1"));
         } else {
             if ($options["update_action"] == "eat") {
                 for ($eat = 0; $eat < count($options["eatId"]); $eat++) {
                     $eatsleepdrinkM = new Application_Model_EatSleepDrink();
                     $eatsleepdrinkRes = $eatsleepdrinkM->find($options["eatId"][$eat]);
                     if (false !== $eatsleepdrinkRes) {
                         $eatsleepdrinkRes->setTitle($options["eatTitle"][$eat]);
                         $eatsleepdrinkRes->setBackPackerCopy($options["backPackerCopy"][$eat]);
                         $eatsleepdrinkRes->setLocalCopy($options["localCopy"][$eat]);
                         $eatsleepdrinkRes->save();
                     } else {
                         $arrayResult = array("error" => 1, "response" => "Error occured, no data found.");
                     }
                 }
                 $arrayResult = array("error" => 0, "response" => "Eat, Sleep, Drink and be Merry information has been updated successfully.");
             } else {
                 if ($options["update_action"] == "exp") {
                     //remove all existing records
                     $expriencesM = new Application_Model_Experiences();
                     $delRes = $expriencesM->delete("destination_id = {$options['destinationId']}");
                     for ($exp = 0; $exp < count($options["expTitle"]); $exp++) {
                         $dataParams["destinationId"] = $options["destinationId"];
                         $dataParams["title"] = $options["expTitle"][$exp];
                         $dataParams["copy"] = $options["expCopy"][$exp];
                         $expriencesM = new Application_Model_Experiences($dataParams);
                         $expriencesM->save();
                         /*
                         					$expriencesM	=	new Application_Model_Experiences();
                         					$expriencesRes	= $expriencesM->find($options["expId"][$exp]);
                         					if(false!==$expriencesRes)
                         					{
                         						$expriencesRes->setTitle($options["expTitle"][$exp]);
                         						$expriencesRes->setCopy($options["expCopy"][$exp]);
                         						$expriencesRes->save();
                         					}
                         					else
                         					{
                         						$arrayResult = Array("error"=>1, "response"=>"Error occured, no data found.");
                         					}*/
                     }
                     $arrayResult = array("error" => 0, "response" => "Experiences information has been updated successfully.");
                 } else {
                     if ($options["update_action"] == "prac") {
                         //remove all existing record
                         $practicalitiesM = new Application_Model_Practicalities();
                         $delres = $practicalitiesM->delete("destination_id = {$options['destinationId']}");
                         for ($prac = 0; $prac < count($options["pracTitle"]); $prac++) {
                             $dataParams["destinationId"] = $options["destinationId"];
                             $dataParams["title"] = $options["pracTitle"][$prac];
                             $dataParams["copy"] = $options["pracCopy"][$prac];
                             $practicalitiesM = new Application_Model_Practicalities($dataParams);
                             $practicalitiesM->save();
                             /*$practicalitiesM	=	new Application_Model_Practicalities();
                             		$practicalitiesRes	=	$practicalitiesM->find($options["pracId"][$prac]);
                             		if(false!==$practicalitiesRes)
                             		{
                             			$practicalitiesRes->setTitle($options["pracTitle"][$prac]);
                             			$practicalitiesRes->setCopy($options["pracCopy"][$prac]);
                             			$practicalitiesRes->save();
                             		}
                             		else
                             		{
                             			$arrayResult = Array("error"=>1, "response"=>"Error occured, no data found.");
                             		}*/
                         }
                         $arrayResult = array("error" => 0, "response" => "Practicalities information has been updated successfully.");
                     } else {
                         if ($options["update_action"] == "img") {
                             //print_r($options);exit;
                             if ($uploadForm->isValid($options)) {
                                 $city_id = $options["cityId"];
                                 $target_file_name = "";
                                 //Upload image strat here
                                 $upload = new Zend_File_Transfer_Adapter_Http();
                                 if ($upload->isValid()) {
                                     $upload->setDestination("media/picture/city/");
                                     try {
                                         $upload->receive();
                                     } catch (Zend_File_Transfer_Exception $e) {
                                         $msg = $e->getMessage();
                                     }
                                     $upload->setOptions(array('useByteString' => false));
                                     $file_name = $upload->getFileName('cityImage');
                                     $cardImageTypeArr = explode(".", $file_name);
                                     $ext = strtolower($cardImageTypeArr[count($cardImageTypeArr) - 1]);
                                     $target_file_name = "city{$city_id}_" . time() . ".{$ext}";
                                     $targetPath = "media/picture/city/" . $target_file_name;
                                     //$targetPathThumb = "media/picture/home/thumb_".$target_file_name;
                                     $filterFileRename = new Zend_Filter_File_Rename(array('target' => $targetPath, 'overwrite' => true));
                                     $filterFileRename->filter($file_name);
                                     //$thumb = Base_Image_PhpThumbFactory ::create($targetPath);
                                     //$thumb->resize(623, 347);
                                     //$thumb->save($targetPathThumb);
                                 }
                                 //upload image Ends here
                                 //set image
                                 $options['cityImage'] = $target_file_name;
                                 $options['status'] = 1;
                                 $model = new Application_Model_CityImages($options);
                                 $id = $model->save();
                                 if ($id) {
                                     $_SESSION['errorMsg'] = "Images has been saved successfully.";
                                 } else {
                                     $_SESSION['errorMsg'] = "Error occured, please try again later.";
                                 }
                                 $this->_helper->redirector("edit-city", "featured-city", "admin", array("id" => $city_id, "tab" => "tabs-5"));
                             }
                             //end if
                             $this->view->selTab = "tabs-5";
                         }
                     }
                 }
             }
         }
         //disable layout and display JSON response if action is not uploading image
         if ($options["update_action"] != "img") {
             $this->_helper->layout->disableLayout();
             $this->_helper->viewRenderer->setNoRender(true);
             echo Zend_Json::encode($arrayResult);
             exit;
         }
     }
     //end if
 }
示例#2
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'];
     //----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 city
     $city_id = 0;
     $cityM = new Application_Model_City();
     $city = $cityM->fetchRow("name='{$cityName}' and country_id='{$country_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;
             }
         }
     }
     $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) {
             //print_r($_item);die();
             $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();
         }
     }
     foreach ($xml_parser->Data['content']['eatSleepDrink'] as $eatsleepdrink) {
         foreach ($eatsleepdrink as $_item) {
             //print_r($_item);die();
             $EatSleepDrinkM = new Application_Model_EatSleepDrink();
             $EatSleepDrinkM->setTitle($_item['title']);
             $EatSleepDrinkM->setDestinationId($destination_id);
             $EatSleepDrinkM->setBackPackerCopy($_item['backpackerCopy']);
             $EatSleepDrinkM->setLocalCopy($_item['localCopy']);
             $EatSleepDrinkM->save();
         }
     }
     //print_r($xml_parser->Data);
 }
示例#3
0
 private function setModel($row)
 {
     //$parent=$row->findParentRow('Application_Model_DbTable_Destination','Continent');
     $model = new Application_Model_EatSleepDrink();
     $model->setId($row->id)->setTitle($row->title)->setBackPackerCopy($row->back_packer_copy)->setlocalCopy($row->local_copy)->setDestinationId($row->destination_id)->setAddedon($row->addedon)->setUpdatedon($row->updatedon);
     return $model;
 }
示例#4
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
 }