set_time_limit(3600); require_once 'dbConnect.php'; require_once 'xmlReader.php'; require_once 'functions.php'; class Wrapper{ public $feed; public $sites=array(); public $hotels=array(); public $bookingCities=array(); public $airports=array(); public function __construct(){ global $dbh; $this->dbh = $dbh; } public function GetCountrySites(){ $stmt = $this->dbh->query('SELECT * from site where zanoxId!=0'); if($stmt->rowCount()){ $this->sites= $stmt->fetchALL(PDO::FETCH_CLASS, 'Site'); } } public function GetCitySites($and=""){ $stmt = $this->dbh->query('SELECT * from site where siteType="city" '.$and); if($stmt->rowCount()){ $this->sites= $stmt->fetchALL(PDO::FETCH_CLASS, 'Site'); } } public function GetHotelSitesToLinkTo($sId, $and=" limit 5"){ $nrOfSites=0; $stmt = $this->dbh->query('SELECT id, city, url from site where siteType="city" and country="city" and id>'.$sId.' '.$and); if($stmt->rowCount()){ $this->sites= $stmt->fetchALL(PDO::FETCH_CLASS, 'Site'); } if(count($this->sites)<5){ $stmt = $this->dbh->query('SELECT id, city, url from site where siteType="city" and country="Sverige" and id<'.$sId.' '.$and); if($stmt->rowCount()){ $this->sites= $stmt->fetchALL(PDO::FETCH_CLASS, 'Site'); } } } public function ConnectHotelToGoogleMaps(){ $pastDate=date("Y-m-d", time()-1209600); $q='SELECT * FROM hotel where countrySe="Sverige" and lastCheckedGoogleMapsRating< "'.$pastDate.'" group by HotelID order by lastCheckedGoogleMapsRating asc limit 10'; echo $q; $stmt = $this->dbh->query($q); if($stmt->rowCount()){ $this->hotels= $stmt->fetchALL(PDO::FETCH_CLASS, 'Hotel'); foreach($this->hotels as $h){ echo $h->name.'
'; $stmt = $this->dbh->query('SELECT * from hotelReview where HotelID="'.$h->HotelID.'"'); if($stmt->rowCount()){ #continue; } $hr=new HotelReview(); $hr->HotelID=$h->HotelID; #Get info from Google Maps $hr->GetReviewFromGoogleMaps($h->latitude,$h->longitude, $h->name); #Update UpdateLastCheckedGoogleMapsHotelID $h->UpdateLastCheckedGoogleMapsRatingHotelID(); } } } public function ConnectPlaceOfInterestToHotelToGoogleMaps(){ $pastDate=date("Y-m-d", time()-604800); $stmt = $this->dbh->query(' SELECT * FROM hotel where countrySe="Sverige" and lastCheckedGoogleMaps < "'.$pastDate.'" group by HotelID order by lastCheckedGoogleMaps asc limit 4 '); if($stmt->rowCount()){ $this->hotels= $stmt->fetchALL(PDO::FETCH_CLASS, 'Hotel'); foreach($this->hotels as $h){ echo $h->name.'
'; #$stmt = $this->dbh->query('SELECT * from placeOfInterestHotel where ="'.$h->HotelID.'"'); #if($stmt->rowCount()){ #continue; #} $poi=new PlaceOfInterest(); $poi->HotelID=$h->HotelID; #Get info from Google Maps $poi->GetPlaceOfInterestFromGoogleMaps($h->latitude,$h->longitude, "",1000, 'amusement_park|aquarium|art_gallery|casino|church|movie_theater|museum|night_club|park|place_of_worship|shopping_mall|stadium|zoo'); $h->UpdateLastCheckedGoogleMapsHotelID(); } } } public function GetAllSites(){ $stmt = $this->dbh->query('SELECT * from site where siteType!="Other"'); if($stmt->rowCount()){ $this->sites= $stmt->fetchALL(PDO::FETCH_CLASS, 'Site'); foreach($this->sites as $s){ echo $s->url.'
'; $s->CleanDuplicatesForSite(); #exit; } } } public function GetBookingCities($where=" where nr_hotels>0 order by lastCheckedDate asc, nr_hotels desc"){ $stmt = $this->dbh->query('SELECT * from booking_city '.$where); if($stmt->rowCount()){ $this->bookingCities= $stmt->fetchALL(PDO::FETCH_CLASS, 'Site'); } } public function UpdateAgodaId(){ $stmt = $this->dbh->query('SELECT id, agodaHotelId, HotelID from hotel where HotelID<0 and agodaHotelId<=0 limit 3000'); if($stmt->rowCount()){ $this->hotels= $stmt->fetchALL(PDO::FETCH_CLASS, 'Hotel'); foreach($this->hotels as $h){ # echo $h->HotelID.'
'; $agodaHotelId=str_replace("-1", "", $h->HotelID); # echo str_replace("-1", "", $h->HotelID); $up="Update hotel set agodaHotelId=$agodaHotelId where id=".$h->id.' limit 1'; $stmt = $this->dbh->query($up); # echo $up; # exit; #exit; } } } public function GetSitesForHotelLocation($country, $city){ $stmt = $this->dbh->query('SELECT * from site where ((country="'.$country.'" AND siteType="country") || (city="'.$city.'" AND siteType="city"))'); if($stmt->rowCount()){ $this->sites= $stmt->fetchALL(PDO::FETCH_CLASS, 'Site'); } } public function GetAirports($where){ echo 'SELECT * from airport '.$where; $stmt = $this->dbh->query('SELECT * from airport '.$where); if($stmt->rowCount()){ $this->airports= $stmt->fetchALL(PDO::FETCH_CLASS, 'Airport'); } } public function CleanAirports(){ $stmt = $this->dbh->query(' SELECT * FROM airportHotel ah LEFT JOIN airport a ON ah.aId = a.id WHERE a.id IS NULL limit 200 '); if($stmt->rowCount()){ $results = $stmt->fetchAll(PDO::FETCH_OBJ); foreach($results as $r){ #echo $r->aId.'
'; echo 'delete from airportHotel where aId='.$r->aId; $stmt3 = $this->dbh->query('delete from airportHotel where aId='.$r->aId); # exit; } } } public function SetAllHotelsForCountry(){ foreach($this->sites as $s){ $s->id=$s->id; $s->UpdateHotels(); $s->CleanDuplicatesForSite(); } } public function ImportAirportInfoCSV(){ $row = 1; if (($handle = fopen("airports.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, "\t")) !== FALSE) { $num = count($data); echo "

$num fields in line $row:

\n"; $row++; $a=new Airport(); $a->country=str_ireplace('flygplatser i ', '', $data[0]); $a->code=$data[1]; $a->aName=$data[2]; $a->icao=$data[3]; $a->long=$data[4]; $longTemp=explode(' ', $a->long); $a->long=$a->DMS2Decimal($longTemp[0], $longTemp[1], $longTemp[2], $longTemp[3]); $a->lat=$data[5]; $latTemp=explode(' ', $a->lat); $a->lat=$a->DMS2Decimal($latTemp[0], $latTemp[1], $latTemp[2], $latTemp[3]); #print_r($a); if($a->SaveAirport()){ $a->UpdateAirport(); } } fclose($handle); } } public function GetAgodaNotVerified($status='?'){ $stmt = $this->dbh->query('SELECT * from hotel where HotelId<0 and isOriginal="'.$status.'" limit 1'); if($stmt->rowCount()){ $this->hotels= $stmt->fetchALL(PDO::FETCH_CLASS, 'Hotel'); } } public function GetHotelsFor($where=" where countrySe='Sverige'"){ echo 'SELECT * from hotel '.$where; $stmt = $this->dbh->query('SELECT * from hotel '.$where); if($stmt->rowCount()){ $this->hotels= $stmt->fetchALL(PDO::FETCH_CLASS, 'Hotel'); } } public function GetHotelsForSiteJson($where){ $stmt = $this->dbh->query('SELECT id,name, address, citySe from hotel '.$where); if($stmt->rowCount()){ $this->hotels= $stmt->fetchALL(PDO::FETCH_CLASS, 'Hotel'); } } public function GetDupHotels(){ $stmt = $this->dbh->query('SELECT * from dupHotels order by id asc limit 1'); if($stmt->rowCount()){ $this->hotels= $stmt->fetchALL(PDO::FETCH_CLASS, 'Hotel'); } } public function GetCloseHotels($h, $limit){ $stmt = $this->dbh->query(' SELECT name, id, HotelID, address ,city, ( 6371 * acos( cos( radians( -- latitude '.$h->latitude.' ) ) * cos( radians( hotel.latitude ) ) * cos( radians( hotel.longitude ) - radians( -- longitude '.$h->longitude.' ) ) + sin( radians( -- latitude '.$h->latitude.' ) ) * sin( radians( hotel.latitude ) ) ) *1000 ) AS distance -- table containing targets to compare distance FROM hotel where sId='.$h->sId.' AND (HotelID!='.$h->HotelID.' || agodaHotelId!='.$h->agodaHotelId.' ) ORDER BY distance asc LIMIT '.$limit); if($stmt->rowCount()){ $results = $stmt->fetchAll(PDO::FETCH_OBJ); return $results; } else{ return false; } } public function CalculateDistanceHotelAirport(){ $stmt = $this->dbh->query('SELECT ah.id, h.latitude, h.longitude, a.google_lat, a.google_lon, a.long, a.lat FROM airportHotel ah INNER JOIN hotel h ON ah.HotelID = h.HotelID INNER JOIN airport a ON ah.aId = a.id WHERE h.countrySe = "Sverige" AND drivingTimeSeconds =0 group by h.HotelID LIMIT 0 , 100'); echo 'SELECT ah.id, h.latitude, h.longitude, a.google_lat, a.google_lon, a.long, a.lat FROM airportHotel ah INNER JOIN hotel h ON ah.HotelID = h.HotelID INNER JOIN airport a ON ah.aId = a.id WHERE h.countrySe = "Sverige" AND drivingTimeSeconds =0 group by h.HotelID LIMIT 0 , 100'; if($stmt->rowCount()){ $results = $stmt->fetchAll(PDO::FETCH_OBJ); foreach($results as $r){ #print_r($r); $lat=$r->google_lat; $lon=$r->google_lon; if($lat=="0.000000000000000"){ $lat=$r->lat; } if($lon=="0.000000000000000"){ $lon=$r->long; } $url='https://maps.googleapis.com/maps/api/distancematrix/json?origins='.$r->latitude.','.$r->longitude.'&destinations='.$lat.'%2C'.$lon.'&key=AIzaSyBiElx6oQ5jxpZUyOXiVdivBcwxV_gdgA0&language=sv'; echo $url.'
'; $res=file_get_contents($url); $data = json_decode($res, true); print_r($data); if($data['rows'][0]['elements'][0]['status']=="ZERO_RESULTS"){ echo $data['rows'][0]['elements'][0]['status']; $up='UPDATE airportHotel set distanceText="", distanceMeter="", drivingTimeText="", drivingTimeSeconds="-1" where id='.$r->id; echo $up; $stmt3=$this->dbh->query($up); #exit; } #set Geo print($data['rows']); print_r($data['rows'][0]['elements']); $distanceText=""; $distanceMeter=""; $drivingTimeText=""; $drivingTimeSeconds=""; if(isset($data['rows'][0]['elements'][0]['distance'])){ $distanceText=$data['rows'][0]['elements'][0]['distance']['text']; $distanceMeter=$data['rows'][0]['elements'][0]['distance']['value']; $drivingTimeText=$data['rows'][0]['elements'][0]['duration']['text']; $drivingTimeSeconds=$data['rows'][0]['elements'][0]['duration']['value']; $up='UPDATE airportHotel set distanceText="'.$distanceText.'", distanceMeter="'.$distanceMeter.'", drivingTimeText="'.$drivingTimeText.'", drivingTimeSeconds="'.$drivingTimeSeconds.'" where id='.$r->id; echo $up; $stmt3=$this->dbh->query($up); # $this->lon=$data['results'][0]['geometry']['location']['lng']; # $this->place_id=$data['results'][0]['place_id']; } } } } } class File{ public $id; public $url; public $name; public $startAt; public $createDate; public $lastFetchDate; public $lastFinishDate; public function __construct(){ global $dbh; $this->dbh = $dbh; } public function UpdateFile(){ if(!empty($this->lastFinishDate)){ $stmt = $this->dbh->query('Update file set startAt='.$this->startAt.', lastFetchDate=NOW(), lastFinishDate=NOW() where id='.$this->id); } else{ $stmt = $this->dbh->query('Update file set startAt='.$this->startAt.', lastFetchDate=NOW() where id='.$this->id); } } public function SetFile(){ $stmt = $this->dbh->query('SELECT * FROM file where id='.$this->id); if($stmt->rowCount()){ $res= $stmt->fetch(PDO::FETCH_OBJ); $this->url=$res->url; $this->name=$res->name; $this->startAt=$res->startAt; print_r($this); } } public function ReadFile(){ // Open the XML $start = microtime(true); $handle = fopen($this->name, 'r'); #echo "HERE"; // Get the nodestring incrementally from the xml file by defining a callback // In this case using a anon function. # $this->name="aaaaa"; $temp=$this->startAt+300; $time_elapsed_secs = microtime(true) - $start; echo "START to LOOP: ".$time_elapsed_secs.'
'; $cursorPos=$this->startAt; $nodeText=""; $startNode=''; $endNode=''; $i=0; while(true) { echo "
INNE"; ob_flush(); flush(); // Find start position $startPos = getPos($handle, $startNode, $cursorPos); // We reached the end of the file or an error if($startPos === false) { echo "FALSE START POS: $startPos
"; break; } // Find where the node ends $endPos = getPos($handle, $endNode, $startPos) + mb_strlen($endNode); // Jump back to the start position fseek($handle, $startPos); // Read the data $data = fread($handle, ($endPos-$startPos)); // next iteration starts reading from here $cursorPos = ftell($handle); #echo "Cursor Pos". $cursorPos .'
'; $entity=getArrayFromXMLString($data); # $this->name=$entity['Name']; $i++; echo "

$i

"; #if($i>100) #exit; $time_elapsed_secs = microtime(true) - $start; if($time_elapsed_secs>250){ echo "
BREAK TIME
".$time_elapsed_secs; exit; } $h=new Hotel(); #Create Hotel $h->SetHotel($entity); $w=new Wrapper(); #Get all sites for city/country for update/insert, see if we should insert/update based on country/city $w->GetSitesForHotelLocation($h->countrySe, $h->citySe); if(count($w->sites)>0){ foreach ($w->sites as $s) { $h->sId=$s->id; $h->siteType=$s->siteType; if(!$h->sId){ echo "NO HOTELS IN COUNTRY/CITY: ".$this->country.'
'; } else{ #Only Insert into countries that exists #sleep(0.5); if(empty($h->agodaHotelId)){ $h->agodaHotelId=-1; } if(empty($h->bookingHotelId)){ $h->bookingHotelId=-2; } //See if hotel exists for site #print_r($h); $time_elapsed_secs = microtime(true) - $start; echo "
Load Hotel TIME
".$time_elapsed_secs; if($h->CheckIfHotelExistsForSite()){ echo "Hotel Allready exists!: HotelID: ".$h->HotelID.'. AgodaID:'.$h->agodaHotelId.'
'; echo " CheckIfHotelExistsForSite INSERTED AS: ".$h->insertedAs.'
'; } else { // See if there is a matching hotel by address //TO DO CHECK IF WE SHOULD SAVE OR NOT $h->CheckIfHotelExistsByAddress(); echo " CheckIfHotelExistsByAddress INSERTED AS: ".$h->insertedAs.'
'; } $time_elapsed_secs = microtime(true) - $start; echo "
Check If Exisits
".$time_elapsed_secs; $h->SaveHotel(); $time_elapsed_secs = microtime(true) - $start; echo "
AFTER SAVE
".$time_elapsed_secs; echo "
"; echo "HotelId: ".$h->HotelID.'
'; echo "
"; #SET MORE INFO $h->SetArraysFromData($entity['Neighbourhoods'], "Neighbourhood"); $h->SetArraysFromData($entity['Airports'], "Airport"); $h->SetArraysFromData($entity['Regions'], "Region", $h->destinationId, $h->expediaRegionId); $time_elapsed_secs = microtime(true) - $start; echo "
Before Amenities SAVE
".$time_elapsed_secs; $h->SetArraysFromData($entity['Amenities'], "Amenity"); $time_elapsed_secs = microtime(true) - $start; echo "
After Amenities SAVE
".$time_elapsed_secs; $h->SetArraysFromData($entity['Themes'], "Theme"); $time_elapsed_secs = microtime(true) - $start; echo "
BREAK TIME
".$time_elapsed_secs; } } } $this->startAt=$cursorPos; $this->UpdateFile(); } #SET Start to 0 $this->startAt=0; $this->lastFinishDate="NOW()"; $this->UpdateFile(); fclose($handle); #exit; } public function UnzipFile(){ // get the absolute path to $file #$path = pathinfo(realpath($this->name), PATHINFO_DIRNAME); $path= realpath(dirname(__FILE__)); echo "UNZIP: ".$path.'
'; $zip = new ZipArchive; echo " :".$this->name.'.zip
'; $res = $zip->open($this->name.'.zip'); if ($res === TRUE) { // extract it to the path we determined above echo "EXTRACT TO: ".$this->name.'
'; $zip->extractTo($path); $zip->close(); $path=str_ireplace('.zip', '', $path); echo "WOOT! ".$this->name." extracted to ".$path; unlink($this->name.'.zip'); } else { echo "Doh! I couldn't open ".$res; } } public function LogInAndDownloadZIPHotels(){ #http://blog.andyhunt.info/2011/12/21/using-php-and-curl-to-log-in-to-a-website/ $EMAIL = 'Hotellmalta'; $PASSWORD= 'password90!'; $cookie_file_path = "/tmp/cookies.txt"; $LOGINURL = "https://partners.hotels.com/j_spring_security_check"; $agent = "Nokia-Communicator-WWW-Browser/2.0 (Geos 3.0 Nokia-9000i)"; $clientToken=""; // begin script $ch = curl_init(); // extra headers $headers[] = "Accept: */*"; $headers[] = "Connection: Keep-Alive"; // basic curl options for all requests curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); // set first URL curl_setopt($ch, CURLOPT_URL, $LOGINURL); // execute session to get cookies and required form inputs $content = curl_exec($ch); if(preg_match("/clientToken\" value=\"(.*?)\"/is", $content, $res)){ $clientToken=$res[1]; } echo "TOKEN ".$clientToken.'
'; // grab the hidden inputs from the form required to login $fields['j_username'] = $EMAIL; $fields['j_password'] = $PASSWORD; $fields['clientToken']=$clientToken; // set postfields using what we extracted from the form $POSTFIELDS = http_build_query($fields); // change URL to login URL curl_setopt($ch, CURLOPT_URL, $LOGINURL); // set post options curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $POSTFIELDS); // perform login $result = curl_exec($ch); echo "Login:
"; #print_r($result); echo "

"; curl_setopt($ch, CURLOPT_URL, $this->url); //execute the request $content = curl_exec($ch); $file_target=$this->name.'.zip'; echo "write to: ".$file_target.'
'; $fp = fopen($file_target, 'w+');//This is the file where we save the information curl_setopt($ch, CURLOPT_FILE, $fp); // write curl response to file curl_exec($ch); // get curl response print_r(curl_getinfo($ch)); curl_close($ch); fclose($fp); echo "ssss"; } function DownloadAgodaFile(){ // basic curl options for all requests echo "DOWNLOAD: ".$this->url.'
'; $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_URL, $this->url); //execute the request $content = curl_exec($ch); $file_target=$this->name.'.zip'; echo "write to: ".$file_target.'
'; $fp = fopen($file_target, 'w+');//This is the file where we save the information curl_setopt($ch, CURLOPT_FILE, $fp); // write curl response to file curl_exec($ch); // get curl response print_r(curl_getinfo($ch)); curl_close($ch); fclose($fp); echo "
File Downloaded!
"; } public function SetRightCountry(){ $countries=array( 'Belgium'=>'Belgien', 'Bulgaria'=>'Bulgarien', 'Cyprus'=>'Cypern', 'Denmark'=>'Danmark', 'Egypt'=>'Egypten', 'Estonia'=>'Estland', 'Belgium'=>'Finland', 'France'=>'Frankrike', 'Greece'=>'Grekland', 'Iceland'=>'Island', 'Italy'=>'Italien', 'Croatia'=>'Kroatien', 'Macedonia'=>'Makedonien', 'Norway'=>'Norge', 'Poland'=>'Polen', 'Romania'=>'Rumänien', 'Russia'=>'Ryssland', 'Switzerland'=>'Schweiz', 'Serbia'=>'Seribien', 'Slovaia'=>'Slovakien', 'Slovenia'=>'Slovenien', 'Spain'=>'Spanien', 'Sweden'=>'Sverige', 'Czech'=>'Tjeckien', 'Turkey'=>'Turkiet', 'Germany'=>'Tyskland', 'Ukraine'=>'Ukraina'); } function CsvReadTrivago($filename='', $delimiter="\t"){ $start = microtime(true); $original = fopen("http://pf.tradetracker.net/?aid=249445&encoding=utf-8&type=csv&fid=917905&r=hotellNAMN&categoryType=2&additionalType=2&csvDelimiter=%09&csvEnclosure=%22&csvVariationType=2&filter_extended=1", $delimiter); $data=array(); if ($original) { $i=0; sleep(1); $temp=$this->startAt+300; $time_elapsed_secs = microtime(true) - $start; echo "START to LOOP: ".$time_elapsed_secs.'
'; while (($buffer = fgets($original)) !== false) { ob_flush(); flush(); $i++; #Skip rows until its time to start if($i<$this->startAt) continue; echo "

$i

"; # $buffer=$this->FixCSV($buffer); //do modification on $buffer (which is a single line) if(count(str_getcsv($buffer, $delimiter))!=40){ echo "ERROR NR OF COLUMNS".count(str_getcsv($buffer, $delimiter))."
"; # continue; } $data=str_getcsv($buffer, $delimiter); if($i>200){ echo "MAX NUM ROWS EXIT
"; exit; } if(!stristr($data[13], 'Sweden')){ $i--; continue; } $data[13]="Sverige"; $time_elapsed_secs = microtime(true) - $start; if($time_elapsed_secs>240){ echo "
BREAK TIME
".$time_elapsed_secs; exit; } echo "
";
				print_r($data);
				
				#continue;
				$h=new Hotel();
				#Create Hotel
				$h->SetHotelTrivago($data);
				
				$nameOrg=$this->name;
				print_r($h);
				
				
				echo "

".$h->name."

"; echo '

TEMP: '.$temp.' i: '.$i.'

'; $w=new Wrapper(); $this->startAt=$i; #Get all sites for city/country for update/insert if we have hotels in city/country $w->GetSitesForHotelLocation($h->countrySe, $h->citySe); if(count($w->sites)>0){ foreach ($w->sites as $s) { $h->sId=$s->id; $h->siteType=$s->siteType; echo "SITE TYPE: ".$s->siteType.'
'; if(!$h->sId){ echo "NO HOTELS IN COUNTRY/CITY 2: ".$this->country.'
'; $temp++; } else{ #Only Insert into countries/cities that exists //See if hotel exists for site if($h->CheckIfHotelExistsForSite()){ echo "Hotel Allready exists!: HotelID: ".$h->HotelID.'. AgodaID:'.$h->agodaHotelId.'
'; echo " CheckIfHotelExistsForSite INSERTED AS: ".$h->insertedAs.'
'; } else { // See if there is a matching hotel by address //TO DO CHECK IF WE SHOULD SAVE OR NOT #Replace åäö with % $this->name= str_replace(array('å', 'ä', 'ö', 'Å', 'Ä', 'Ö'), array('%', '%', '%', '%', '%', '%'), $this->name); $h->CheckIfHotelExistsByAddress(); echo " CheckIfHotelExistsByAddress INSERTED AS: ".$h->insertedAs.'
'; } exit; $h->SaveHotelAgoda(); $time_elapsed_secs = microtime(true) - $start; echo "SAVE HOTEL: ".$time_elapsed_secs.'
'; #exit; } } $this->UpdateFile(); } else { echo "

NO HOTELS IN COUNTRY/CITY:

"; $temp++; } #$this->startAt=$this->startAt+1; $this->startAt+=1; $this->UpdateFile(); echo "
"; } #SET Start to 0 $this->startAt=1; $this->lastFinishDate="NOW()"; $this->UpdateFile(); } } function CsvReadAgoda($filename='', $delimiter=","){ $start = microtime(true); $original = fopen("http://www.flygresor2.se/hotelAdmin/".$this->name, $delimiter); $data=array(); if ($original) { $i=0; sleep(1); $temp=$this->startAt+300; $time_elapsed_secs = microtime(true) - $start; echo "START to LOOP: ".$time_elapsed_secs.'
'; while (($buffer = fgets($original)) !== false) { ob_flush(); flush(); $i++; #Skip rows until its time to start if($i<$this->startAt) continue; echo "

$i

"; # $buffer=$this->FixCSV($buffer); //do modification on $buffer (which is a single line) if(count(str_getcsv($buffer, $delimiter))!=40){ echo "ERROR NR OF COLUMNS".count(str_getcsv($buffer, $delimiter))."
"; continue; } $data=str_getcsv($buffer, $delimiter); if($i>$temp){ echo "MAX NUM ROWS EXIT
"; exit; } $time_elapsed_secs = microtime(true) - $start; if($time_elapsed_secs>240){ echo "
BREAK TIME
".$time_elapsed_secs; exit; } $h=new Hotel(); #Create Hotel $h->SetHotelAgoda($data); echo "

".$h->name."

"; echo '

TEMP: '.$temp.' i: '.$i.'

'; $w=new Wrapper(); $this->startAt=$i; #Get all sites for city/country for update/insert if we have hotels in city/country $w->GetSitesForHotelLocation($h->countrySe, $h->citySe); if(count($w->sites)>0){ foreach ($w->sites as $s) { $h->sId=$s->id; $h->siteType=$s->siteType; echo "SITE TYPE: ".$s->siteType.'
'; if(!$h->sId){ echo "NO HOTELS IN COUNTRY/CITY 2: ".$this->country.'
'; $temp++; } else{ #Only Insert into countries/cities that exists #$h->SaveHotel(); echo "SAVE HotelId: ".$h->HotelID.'
'; echo "SAVE Sid: ".$h->sId.'
'; //See if hotel exists for site if($h->CheckIfHotelExistsForSite()){ echo "Hotel Allready exists!: HotelID: ".$h->HotelID.'. AgodaID:'.$h->agodaHotelId.'
'; echo " CheckIfHotelExistsForSite INSERTED AS: ".$h->insertedAs.'
'; } else { // See if there is a matching hotel by address //TO DO CHECK IF WE SHOULD SAVE OR NOT $h->CheckIfHotelExistsByAddress(); echo " CheckIfHotelExistsByAddress INSERTED AS: ".$h->insertedAs.'
'; } $h->SaveHotelAgoda(); $time_elapsed_secs = microtime(true) - $start; echo "SAVE HOTEL: ".$time_elapsed_secs.'
'; #exit; } } $this->UpdateFile(); } else { echo "

NO HOTELS IN COUNTRY/CITY:

"; $temp++; } #$this->startAt=$this->startAt+1; $this->startAt+=1; $this->UpdateFile(); echo "
"; } #SET Start to 0 $this->startAt=1; $this->lastFinishDate="NOW()"; $this->UpdateFile(); } } public function ReadHotelsByBooking(){ $start = microtime(true); #$jsondata=file_get_contents('https://11767:word2356@distribution-xml.booking.com/json/bookings.getHotels?city_ids='.$ids.'&languagecodes=se&offset='.$start.'&rows=40'); # echo 'https://11767:word2356@distribution-xml.booking.com/json/bookings.getHotels?languagecodes=se&rows=30&city_ids=-2524279'; $jsondata=file_get_contents('https://11767:word2356@distribution-xml.booking.com/json/bookings.getHotels?languagecodes=se&offset='.$this->startAt.'&rows=30'); $data = json_decode($jsondata, true); if(count($data)<1){ $this->UpdateRowsBooking(false); } foreach($data as $key => $value) { $time_elapsed_secs = microtime(true) - $start; if($time_elapsed_secs>250){ echo "
BREAK TIME
".$time_elapsed_secs; exit; } $h=new Hotel(); $this->startAt++; if(!isset($value['name'])){ $this->UpdateRowsBooking(); } $h->bookingName=$value['name']; $h->bookingAddress=$value['address']; $h->bookingZIP=$value['zip']; $h->bookingHotelUrl=str_replace(".html", ".sv.html?aid=317438&label=SITENAME",$value['url']); $h->bookingRateLow=$value['minrate']; $h->bookingRateHigh=$value['maxrate']; $h->bookingHotelId=$value['hotel_id']; $h->bookingLong=$value['location']['longitude']; $h->bookingLat=$value['location']['latitude']; $h->bookingCityId=$value['city_id']; $h->countrySe="Sverige"; $h->HotelID=-2; $h->name=$h->bookingName; $h->address=$h->bookingAddress; $h->citySe=$value['city']; $h->latitude=$h->bookingLat; $h->longitude=$h->bookingLong; print_r($h); #exit; $w=new Wrapper(); #Get all sites for city/country for update/insert, see if we should insert/update based on country/city $w->GetSitesForHotelLocation($h->countrySe, $h->citySe); if(count($w->sites)>0){ foreach ($w->sites as $s){ $h->sId=$s->id; $h->siteType=$s->siteType; $h->bookingHotelUrl=str_replace("SITENAME", "hotell-".$s->city.'-'.$s->country, $h->bookingHotelUrl); if(!$h->sId){ echo "NO HOTELS IN COUNTRY/CITY: ".$this->country.'
'; } else{ #Only Insert into countries that exists #sleep(0.5); if(empty($h->agodaHotelId)){ $h->agodaHotelId=-2; } //See if hotel exists for site #print_r($h); $time_elapsed_secs = microtime(true) - $start; echo "
Load Hotel TIME
".$time_elapsed_secs; if($h->CheckIfHotelExistsForSite()){ echo "Hotel Allready exists!: HotelID: ".$h->HotelID.'. BookingID:'.$h->bookingHotelId.'
'; echo " CheckIfHotelExistsForSite INSERTED AS: ".$h->insertedAs.'
'; } else { // See if there is a matching hotel by address //TO DO CHECK IF WE SHOULD SAVE OR NOT $h->CheckIfHotelExistsByAddress(); echo " CheckIfHotelExistsByAddress INSERTED AS: ".$h->insertedAs.'
'; } $time_elapsed_secs = microtime(true) - $start; echo "
Check If Exisits
".$time_elapsed_secs; $h->SaveHotelBooking(); $time_elapsed_secs = microtime(true) - $start; #exit; echo "
AFTER SAVE
".$time_elapsed_secs; echo "
"; echo "HotelId: ".$h->HotelID.'
'; echo "
"; $time_elapsed_secs = microtime(true) - $start; echo "
BREAK TIME
".$time_elapsed_secs; } #update $startNum $this->UpdateRowsBooking(); } } } } public function UpdateRowsBooking($end=true){ if($end){ echo 'Update file set startAt='.$this->startAt.' where id='.$this->id.'
'; $stmt = $this->dbh->query('Update file set startAt='.$this->startAt.' where id='.$this->id); } else{ $stmt = $this->dbh->query('Update file set startAt=0 where id='.$this->id); } } public function UpdateLastRunDateBooking($city_id){ echo 'Update booking_city SET lastCheckedDate=NOW() where city_id='.$city_id.'
'; $stmt = $this->dbh->query('Update booking_city SET lastCheckedDate=NOW() where city_id='.$city_id); } public function ReadJsonCities(){ exit; while(true){ $jsondata = file_get_contents('https://11767:word2356@distribution-xml.booking.com/json/bookings.getCities?countrycodes=se&offest=100&rows=100'); $data = json_decode($jsondata, true); echo count($data); exit; #print_r($data); foreach($data as $key => $value) { echo $value['name']; $countrycode=$value['countrycode']; $nr_hotels=$value['nr_hotels']; $name=$value['name']; $longitude=$value['longitude']; $latitude=$value['latitude']; $city_id=$value['city_id']; $languagecode=$value['languagecode']; $in='INSERT INTO booking_city set city_id='.$city_id.', name="'.$name.'", latitude="'.$latitude.'", longitude="'.$longitude.'", nr_hotels='.$nr_hotels.', countrycode="'.$countrycode.'", languagecode="'.$languagecode.'", createDate=Now() '; try{ $stmt = $this->dbh->query($in); } catch (Exception $e) { echo "ERRROR CANT INSERT---!!!!
"; echo $in.'
'; } } } } } class Site{ public $id; public $name; public $text; public $city; public $country; public $zanoxId; public $siteType; public $banner; public $lat; public $lon; public $place_id; public $trivagoUrl; public $lowestPrice; public $higestPrice; public $hotels=array(); public $priceGroups=array(); public $placeTypes=array(); public $amenities=array(); public $neighbourhood=array(); public $airports=array(); public $relatedHotels=array(); public $nrOfHotels; public function __construct(){ global $dbh; $this->dbh = $dbh; } public function SetTrivagoBaseUrlSite(){ $stmt = $this->dbh->query('SELECT trivagoUrl from site where id='.$this->id); if($stmt->rowCount()){ $row = $stmt->fetch(PDO::FETCH_OBJ); $row->trivagoUrl=str_replace('SAJT', $_SERVER['SERVER_NAME'], $row->trivagoUrl); $this->trivagoUrl='http://tc.tradetracker.net/?c=14386&m=12&a=249445&r='.$_SERVER['SERVER_NAME'].'&u='.$row->trivagoUrl; } else{ $this->trivagoUrl= "http://tc.tradetracker.net/?c=14386&m=12&a=249445&r=".$_SERVER['SERVER_NAME']."&u="; } } public function MoveCloseHotelsToCity(){ $q='SELECT HotelID, name, ( 6371 * acos( cos( radians( '.$this->lat.' ) ) * cos( radians( hotel.latitude ) ) * cos( radians( hotel.longitude ) - radians( '.$this->lon.' ) ) + sin( radians( '.$this->lat.' ) ) * sin( radians( hotel.latitude ) ) ) *1000 ) AS distance FROM hotel WHERE sId !='.$this->id.' AND countrySe = "'.$this->country.'" AND citySe != "'.$this->city.'" GROUP BY HotelID ORDER BY distance limit 50 '; echo $q; $stmt = $this->dbh->query($q); if($stmt->rowCount()){ $temp = $stmt->fetchAll(PDO::FETCH_CLASS, 'Hotel'); foreach($temp as $h){ echo "DISTANCE: ".$h->distance.'
'; if($h->distance<15000){ $h->GetHotelByHotelID(); $h->sId=$this->id; if(!$h->CheckIfHotelExistsForSiteSimple()){ echo $h->name.'('.$h->HotelID.') Finns ej för '.$this->url. '
'; $h->FixTextCity(); # print_r($h); $h->SaveHotel(); # exit; } } } } } public function FixBrokenImagesForSite(){ $q='SELECT id, HotelID, name, image, sum( length( image ) ) AS total_size FROM `hotel` GROUP BY id ORDER BY total_size ASC limit 10 '; echo $q; $stmt = $this->dbh->query($q); if($stmt->rowCount()){ $temp = $stmt->fetchAll(PDO::FETCH_CLASS, 'Hotel'); foreach($temp as $h){ echo "total_size: ".$h->total_size.'
'; if($h->total_size<3){ $h->GetHotelByHotelID(); $h->SetImage(); $h->SaveHotel(); # print_r($h); $h->sId=$this->id; } } } } public function GetSiteById($extra=""){ $stmt = $this->dbh->query('SELECT * FROM site where id='.$this->id.$extra); if($stmt->rowCount()){ $temp = $stmt->fetchAll(PDO::FETCH_CLASS, 'Site'); foreach ($temp[0] as $key => $value) { $this->$key = $value; } } } public function GetSiteByDomain($domain){ $stmt = $this->dbh->query(' SELECT s.* , count( h.id ) AS nrOfHotels FROM site s INNER JOIN hotel h ON s.id = h.sId where s.url like "%'.$domain.'%"'); if($stmt->rowCount()){ $temp = $stmt->fetchAll(PDO::FETCH_CLASS, 'Site'); foreach ($temp[0] as $key => $value) { $this->$key = $value; } $this->FixStartPageText(); return true; } else{ return false; } } public function FixStartPageText(){ $this->text=str_replace('#NR#', $this->nrOfHotels, $this->text); } public function SetGeoForCity($and="", $city, $country){ $url='https://maps.googleapis.com/maps/api/geocode/json?address='.$city.'+'.$country.'&key=AIzaSyBiElx6oQ5jxpZUyOXiVdivBcwxV_gdgA0&language=sv'; echo $url.'
'; $res=file_get_contents($url); $data = json_decode($res, true); #print_r($data); if(count($data)<1){ echo "NO DATA"; exit; } #set Geo if(isset($data['results'][0]['place_id'])){ $this->lat=$data['results'][0]['geometry']['location']['lat']; $this->lon=$data['results'][0]['geometry']['location']['lng']; $this->place_id=$data['results'][0]['place_id']; } #print_r($this); echo 'UPDATE site set lat='.$this->lat.', lon='.$this->lon.', place_id="'.$this->place_id.'" where id='.$this->id; $stmt = $this->dbh->query('UPDATE site set lat='.$this->lat.', lon='.$this->lon.', place_id="'.$this->place_id.'" where id='.$this->id); } public function SetAirportsForCitySite(){ echo 'SELECT * , ( 6371 * acos( cos( radians('.$this->lat.') ) * cos( radians( lat ) ) * cos( radians( airport.long ) - radians('.$this->lon.') ) + sin( radians('.$this->lat.') ) * sin( radians( lat ) ) ) *1000 ) AS distance FROM airport ORDER BY distance LIMIT 0 , 30'; $stmt = $this->dbh->query('SELECT * , ( 6371 * acos( cos( radians('.$this->lat.') ) * cos( radians( lat ) ) * cos( radians( airport.long ) - radians('.$this->lon.') ) + sin( radians('.$this->lat.') ) * sin( radians( lat ) ) ) *1000 ) AS distance FROM airport ORDER BY distance LIMIT 0 , 30'); if($stmt->rowCount()){ $rows = $stmt->fetchAll(PDO::FETCH_OBJ); foreach($rows as $row){ if($row->distance<100000){ #print_r($row); echo $row->aName.'
'; #avoid dup echo 'SELECT * FROM airportSite where aId='.$row->id.' and sId='.$this->id; $stmt2 = $this->dbh->query('SELECT * FROM airportSite where aId='.$row->id.' and sId='.$this->id); echo $stmt2->rowCount(); if(!$stmt2->rowCount()){ $distance=round($row->distance, -3); $in='Insert into airportSite set aId='.$row->id.', sId='.$this->id.', distance='.$distance; echo $in; $stmt = $this->dbh->query($in); } } } } } public function UpdateHotels(){ $stmt = $this->dbh->query('SELECT * FROM hotel WHERE url LIKE "%zanox%" AND url NOT LIKE "%]" limit 1000'); if($stmt->rowCount()){ echo 'dddd'; $this->hotels = $stmt->fetchALL(PDO::FETCH_CLASS, 'Hotel'); /*** loop of the object directly ***/ foreach($this->hotels as $h){ $h->SetSIDforHotel(); echo "

ID: ".$h->id.' NAME: '.$h->name.'


'; $h->SetImage(); $h->SetAffiliateLinkZanox(); $h->FixTextCountry(); if(empty($h->citySe)){ $h->citySe=$h->city; } #print_r($h); //Fix type of FixTextCountry/city ### $h->UpdateHotel(); } } echo 'dddd'; } public function CleanDuplicatesForSite(){ echo 'SELECT HotelID FROM hotel where sId='.$this->id.' group by HotelID having count(*) >= 2'; $stmt = $this->dbh->query('SELECT HotelID FROM hotel where sId='.$this->id.' group by HotelID having count(*) >= 2'); if($stmt->rowCount()){ $rows = $stmt->fetchAll(PDO::FETCH_OBJ); foreach($rows as $value){ $stmt = $this->dbh->query('SELECT * FROM hotel where sId='.$this->id.' and HotelID='.$value->HotelID.' order by id desc limit 1'); if($stmt->rowCount()){ $this->hotels = $stmt->fetchALL(PDO::FETCH_CLASS, 'Hotel'); foreach($this->hotels as $h){ echo '
'.$h->name.'
'; $del='DELETE from hotel where id='.$h->id; echo $del; $this->dbh->query($del); echo $del.'
'; echo $h->id.'
'; echo $h->HotelID.'
'; #print_r($h); } } echo '
'; } } } public function GetUniqueTypesFor($where=""){ $stmt = $this->dbh->query(' SELECT pt . *, count(pt.id) as nr FROM placeTypeHotel pth INNER JOIN placeType pt ON pth.ptId = pt.id INNER JOIN hotel h ON h.HotelID = pth.HotelID '.$where.' GROUP BY pt.id '); if($stmt->rowCount()){ $this->placeTypes= $stmt->fetchALL(PDO::FETCH_CLASS, 'PlaceType'); } } public function GetHotelsPriceGroups($where=""){ $q='SELECT SUM(CASE WHEN lowRate <500 THEN 1 ELSE 0 END ) AS below500, SUM( CASE WHEN lowRate >=500 AND lowRate <1000 THEN 1 ELSE 0 END ) AS between500and1000, SUM(CASE WHEN lowRate >=1000 AND lowRate <2000 THEN 1 ELSE 0 END ) AS between1000and2000, SUM(CASE WHEN lowRate >=2000 AND lowRate <4000 THEN 1 ELSE 0 END ) AS between2000and4000, SUM(CASE WHEN lowRate >=4000 THEN 1 ELSE 0 END ) AS over4000 FROM hotel '.$where; #echo $q.'
'; $stmt = $this->dbh->query($q); if($stmt->rowCount()){ $row=$stmt->fetch(PDO::FETCH_OBJ); $i=0; if($row->below500>0){ $this->priceGroups['under500']['anchorText']='Hotell i '.$this->city.' under 500 kr'; $this->priceGroups['under500']['anchorTextMenu']='Under 500 kr'; $this->priceGroups['under500']['nr']=$row->below500; $this->priceGroups['under500']['url']='hotell-'.FixUrl($this->city).'-0-500-kr.html'; $this->priceGroups['under500']['title']='Billiga hotell i '.$this->city.'. '.$row->below500.' hotell under 500 kr!'; $this->priceGroups['under500']['lowRate']='0'; $this->priceGroups['under500']['highRate']='500'; } if($row->between500and1000>0){ $this->priceGroups['between500and1000']['anchorText']='Hotell i '.$this->city.' mellan 500-1000 kr'; $this->priceGroups['between500and1000']['anchorTextMenu']='Mellan 500-1000 kr'; $this->priceGroups['between500and1000']['nr']=$row->between500and1000; $this->priceGroups['between500and1000']['url']='hotell-'.FixUrl($this->city).'-500-1000-kr.html'; $this->priceGroups['between500and1000']['title']=$row->between500and1000. ' billiga hotell i '.$this->city.'. Hotell mellan 500-1000 kr/natt!'; $this->priceGroups['between500and1000']['lowRate']='500'; $this->priceGroups['between500and1000']['highRate']='1000'; } if($row->between1000and2000>0){ $this->priceGroups['between1000and2000']['anchorText']='Hotell i '.$this->city.' mellan 1000-2000 kr'; $this->priceGroups['between1000and2000']['anchorTextMenu']='Mellan 1000-2000 kr'; $this->priceGroups['between1000and2000']['nr']=$row->between1000and2000; $this->priceGroups['between1000and2000']['url']='hotell-'.FixUrl($this->city).'-1000-2000-kr.html'; $this->priceGroups['between1000and2000']['title']=$row->between1000and2000.' trevliga hotell i '.$this->city.'. Hotell mellan 1000 och 2000 kr/natt!'; $this->priceGroups['between1000and2000']['lowRate']='1000'; $this->priceGroups['between1000and2000']['highRate']='2000'; } if($row->between2000and4000>0){ $this->priceGroups['between2000and4000']['anchorText']='Hotell i '.$this->city.' mellan 2000-4000 kr'; $this->priceGroups['between2000and4000']['anchorTextMenu']='Mellan 2000-4000 kr'; $this->priceGroups['between2000and4000']['nr']=$row->between2000and4000; $this->priceGroups['between2000and4000']['url']='hotell-'.FixUrl($this->city).'-2000-4000-kr.html'; $this->priceGroups['between2000and4000']['title']=$row->between2000and4000. ' fina hotell i '.$this->city.'. Hotell mellan 2000-4000kr/natt!'; $this->priceGroups['between2000and4000']['lowRate']='2000'; $this->priceGroups['between2000and4000']['highRate']='4000'; } if($row->over4000>0){ $this->priceGroups['over4000']['anchorText']='Hotell i '.$this->city.' över 4000 kr'; $this->priceGroups['over4000']['anchorTextMenu']='Över 4000 kr'; $this->priceGroups['over4000']['nr']=$row->over4000; $this->priceGroups['over4000']['url']='hotell-'.FixUrl($this->city).'-4000-kr'; $this->priceGroups['over4000']['title']=$row->over4000.' exklusiva hotell i '.$this->city.'. Hotell över 4000 kr/natt!'; $this->priceGroups['over4000']['lowRate']='4000'; $this->priceGroups['over4000']['highRate']='20000'; } } } public function GetAmenities($where=""){ $q=' SELECT a.* , count( h.id ) AS nr FROM amenityHotel ah INNER JOIN amenity a ON ah.aId = a.id INNER JOIN hotel h ON h.HotelID = ah.HotelId '.$where.' AND aValue = "YES" GROUP BY a.id order by nr desc'; # echo $q.'
'; $stmt = $this->dbh->query($q); if($stmt->rowCount()){ $this->amenities= $stmt->fetchALL(PDO::FETCH_CLASS, 'Amenity'); } else{ return false; } } public function GetAmenitiesHotels($where=""){ $q=' SELECT h.id, h.name, h.citySe, SUBSTRING_INDEX(h.textSe, " ", 10) as textSe, h.url, h.price, h.normalPrice, h.address, h.address2, h.zip, h.phone, h.AdvertiserURL, h.zanoxUrl, h.countrySe, h.highRate, h.HotelID, h.latitude, h.longitude, h.lowRate, h.postalcode, h.bookingURL, h.rating, h.reviewScore, h.numberReviews, h.sId, h.agodaName, h.agodaUrl, h.agodaRateLow, h.agodaRateHigh, h.agodaHotelId, h.agodaReviewScore, h.agodaNumberReviews, h.bookingName, h.bookingAddress, h.bookingZIP, h.bookingHotelUrl, h.bookingRateLow, h.bookingRateHigh, h.bookingHotelId, avg( hr.rating ) AS googleRating FROM amenityHotel ah INNER JOIN amenity a ON ah.aId = a.id INNER JOIN hotel h ON h.HotelID = ah.HotelId left JOIN hotelRating hr ON hr.HotelID = h.HotelID '.$where; #echo $q.'
'; $stmt = $this->dbh->query($q); if($stmt->rowCount()){ $this->hotels= $stmt->fetchALL(PDO::FETCH_CLASS, 'Hotel'); } foreach($this->hotels as $h){ $h->displayUrl='hotell/'.FixUrl($h->citySe).'/'.FixUrl($h->name).'-'.$h->id.'.html'; $h->SetOffers(); $h->SetMainImageUrl(); # $h->GetRatingsForHotelByHotelID(); $h->SetLowPriceAndURL(); $h->SetHotelsUrl(); $h->SetBookingComUrl(); $h->SetTrivagoBaseUrl(); } $this->SetLowAndHighPrice(); #echo microtime(true) - $start.'
'; } public function GetHotelsForSiteSitemap($where=" GROUP BY h.id"){ $q=' SELECT h.id, h.name, h.citySe FROM hotel h where h.sId='.$this->id.' '.$where; #echo $q.'
'; $stmt = $this->dbh->query($q); if($stmt->rowCount()){ $this->hotels= $stmt->fetchALL(PDO::FETCH_CLASS, 'Hotel'); foreach($this->hotels as $h){ $h->displayUrl='hotell/'.FixUrl($h->citySe).'/'.FixUrl($h->name).'-'.$h->id.'.html'; } #echo microtime(true) - $start.'
'; return true; } else{ return false; } } public function GetHotelsForSite($where=" GROUP BY h.id"){ $q=' SELECT h.id, h.name, h.address, h.highRate, h.HotelID, h.latitude, h.longitude, h.lowRate, h.rating, h.reviewScore, h.sId, h.agodaRateLow, h.agodaReviewScore, h.bookingRateLow, avg( hr.rating ) AS googleRating FROM hotel h left JOIN hotelRating hr ON hr.HotelID = h.HotelID where h.sId='.$this->id.' '.$where; #echo $q.'
'; $stmt = $this->dbh->query($q); if($stmt->rowCount()){ $this->hotels= $stmt->fetchALL(PDO::FETCH_CLASS, 'Hotel'); foreach($this->hotels as $h){ $h->displayUrl='hotell/'.FixUrl($h->citySe).'/'.FixUrl($h->name).'-'.$h->id.'.html'; # $h->SetOffers(); $h->SetMainImageUrl(); $h->GetRatingsForHotelByHotelID(); $h->SetLowPriceAndURL(); $h->SetHotelsUrl(); $h->SetBookingComUrl(); $h->SetTrivagoBaseUrl(); } #echo microtime(true) - $start.'
'; return true; } else{ return false; } } public function GetPlaceTypeForHotels($where=""){ $q=' SELECT h.id, h.name, h.citySe, SUBSTRING_INDEX(h.textSe, " ", 10) as textSe, h.url, h.price, h.normalPrice, h.address, h.address2, h.zip, h.phone, h.AdvertiserURL, h.zanoxUrl, h.countrySe, h.highRate, h.HotelID, h.latitude, h.longitude, h.lowRate, h.postalcode, h.bookingURL, h.rating, h.reviewScore, h.numberReviews, h.sId, h.agodaName, h.agodaUrl, h.agodaRateLow, h.agodaRateHigh, h.agodaHotelId, h.agodaReviewScore, h.agodaNumberReviews, h.bookingName, h.bookingAddress, h.bookingZIP, h.bookingHotelUrl, h.bookingRateLow, h.bookingRateHigh, h.bookingHotelId, avg( hr.rating ) AS googleRating FROM placeTypeHotel pth INNER JOIN placeType pt ON pth.ptId = pt.id INNER JOIN hotel h ON h.HotelID = pth.HotelId left JOIN hotelRating hr ON hr.HotelID = h.HotelID '.$where; #echo $q.'
'; $stmt = $this->dbh->query($q); if($stmt->rowCount()){ $this->hotels= $stmt->fetchALL(PDO::FETCH_CLASS, 'Hotel'); } foreach($this->hotels as $h){ $h->displayUrl='hotell/'.FixUrl($h->citySe).'/'.FixUrl($h->name).'-'.$h->id.'.html'; $h->SetOffers(); $h->SetMainImageUrl(); # $h->GetRatingsForHotelByHotelID(); $h->SetLowPriceAndURL(); $h->SetHotelsUrl(); $h->SetBookingComUrl(); $h->SetTrivagoBaseUrl(); } $this->SetLowAndHighPrice(); #echo microtime(true) - $start.'
'; } public function GetHotelReviewForHotels($neighbourhood, $sId){ $q=' SELECT h.id, h.name, h.citySe, SUBSTRING_INDEX(h.textSe, " ", 10) as textSe, h.url, h.price, h.normalPrice, h.address, h.address2, h.zip, h.phone, h.AdvertiserURL, h.zanoxUrl, h.countrySe, h.highRate, h.HotelID, h.latitude, h.longitude, h.lowRate, h.postalcode, h.bookingURL, h.rating, h.reviewScore, h.numberReviews, h.sId, h.agodaName, h.agodaUrl, h.agodaRateLow, h.agodaRateHigh, h.agodaHotelId, h.agodaReviewScore, h.agodaNumberReviews, h.bookingName, h.bookingAddress, h.bookingZIP, h.bookingHotelUrl, h.bookingRateLow, h.bookingRateHigh, h.bookingHotelId, avg( hrating.rating ) AS googleRating FROM hotel h left JOIN hotelRating hrating ON h.HotelID = hrating.HotelID WHERE h.HotelID IN ( SELECT hr.HotelID FROM hotelReview hr WHERE hr.neighbourhood = "'.$neighbourhood.'" ) AND sId ='.$sId.' GROUP BY h.id'; #echo $q.'
'; $stmt = $this->dbh->query($q); if($stmt->rowCount()){ $this->hotels= $stmt->fetchALL(PDO::FETCH_CLASS, 'Hotel'); } foreach($this->hotels as $h){ $h->displayUrl='hotell/'.FixUrl($h->citySe).'/'.FixUrl($h->name).'-'.$h->id.'.html'; $h->SetOffers(); $h->SetMainImageUrl(); # $h->GetRatingsForHotelByHotelID(); $h->SetLowPriceAndURL(); $h->SetHotelsUrl(); $h->SetBookingComUrl(); $h->SetTrivagoBaseUrl(); } $this->SetLowAndHighPrice(); #echo microtime(true) - $start.'
'; } public function GetHotelPriceBetweenForHotels($low, $max, $limit=""){ $q=' SELECT h.id, h.name, h.citySe, SUBSTRING_INDEX(h.textSe, " ", 10) as textSe, h.url, h.price, h.normalPrice, h.address, h.address2, h.zip, h.phone, h.AdvertiserURL, h.zanoxUrl, h.countrySe, h.highRate, h.HotelID, h.latitude, h.longitude, h.lowRate, h.postalcode, h.bookingURL, h.rating, h.reviewScore, h.numberReviews, h.sId, h.agodaName, h.agodaUrl, h.agodaRateLow, h.agodaRateHigh, h.agodaHotelId, h.agodaReviewScore, h.agodaNumberReviews, h.bookingName, h.bookingAddress, h.bookingZIP, h.bookingHotelUrl, h.bookingRateLow, h.bookingRateHigh, h.bookingHotelId, avg( hrating.rating ) AS googleRating from hotel h LEFT JOIN hotelRating hrating ON h.HotelID = hrating.HotelID where h.sId='.$this->id.' AND price between '.$low.' and '.$max.' GROUP BY h.id'.$limit; #echo $q.'
'; $stmt = $this->dbh->query($q); if($stmt->rowCount()){ $this->hotels= $stmt->fetchALL(PDO::FETCH_CLASS, 'Hotel'); } foreach($this->hotels as $h){ $h->displayUrl='hotell/'.FixUrl($h->citySe).'/'.FixUrl($h->name).'-'.$h->id.'.html'; $h->SetOffers(); $h->SetMainImageUrl(); # $h->GetRatingsForHotelByHotelID(); $h->SetLowPriceAndURL(); $h->SetHotelsUrl(); $h->SetBookingComUrl(); $h->SetTrivagoBaseUrl(); } $this->SetLowAndHighPrice(); #echo microtime(true) - $start.'
'; } public function GetHotelPriceBetweenForHotelsWithoutReview($low, $max, $limit=""){ $q=' SELECT h.id, h.name, h.citySe, SUBSTRING_INDEX(h.textSe, " ", 10) as textSe, h.url, h.price, h.normalPrice, h.address, h.address2, h.zip, h.phone, h.AdvertiserURL, h.zanoxUrl, h.countrySe, h.highRate, h.HotelID, h.latitude, h.longitude, h.lowRate, h.postalcode, h.bookingURL, h.rating, h.reviewScore, h.numberReviews, h.sId, h.agodaName, h.agodaUrl, h.agodaRateLow, h.agodaRateHigh, h.agodaHotelId, h.agodaReviewScore, h.agodaNumberReviews, h.bookingName, h.bookingAddress, h.bookingZIP, h.bookingHotelUrl, h.bookingRateLow, h.bookingRateHigh, h.bookingHotelId from hotel h where h.sId='.$this->id.' AND price between '.$low.' and '.$max.' '.$limit; # echo $q.'
'; $stmt = $this->dbh->query($q); if($stmt->rowCount()){ $this->hotels= $stmt->fetchALL(PDO::FETCH_CLASS, 'Hotel'); } foreach($this->hotels as $h){ $h->displayUrl='hotell/'.FixUrl($h->citySe).'/'.FixUrl($h->name).'-'.$h->id.'.html'; $h->SetOffers(); $h->SetMainImageUrl(); # $h->GetRatingsForHotelByHotelID(); $h->SetLowPriceAndURL(); $h->SetHotelsUrl(); $h->SetBookingComUrl(); $h->SetTrivagoBaseUrl(); } $this->SetLowAndHighPrice(); #echo microtime(true) - $start.'
'; } public function SetLowAndHighPrice(){ $this->lowestPrice=100000; $this->higestPrice=-1; foreach($this->hotels as $h){ if($this->higestPrice<$h->bestPrice){ $this->higestPrice=$h->bestPrice; } if($this->lowestPrice>$h->bestPrice){ $this->lowestPrice=$h->bestPrice; } } } public function GetRelatedHotels($where=' limit 10'){ $q='SELECT * from hotel where sId='.$this->id.$where; $stmt = $this->dbh->query($q); if($stmt->rowCount()){ $this->relatedHotels= $stmt->fetchALL(PDO::FETCH_CLASS, 'Hotel'); } foreach($this->relatedHotels as $h){ $h->SetLowPriceAndURL(); $h->SetMainImageUrl(); $h->displayUrl='hotell/'.FixUrl($h->citySe).'/'.FixUrl($h->name).'-'.$h->id.'.html'; } } public function GetAirportsForSite($and="", $orderBy=" order by distance asc"){ $stmt = $this->dbh->query(' SELECT a.*, air.distance, air.text FROM airportSite air inner join airport a on air.aId=a.id where air.sId='.$this->id.$and.$orderBy); if($stmt->rowCount()){ $this->airports= $stmt->fetchALL(PDO::FETCH_CLASS, 'Airport'); } } public function GetUniqueNeighbourhoodFor($where="", $orderBy=" order by nr desc"){ $q=' SELECT hr.id, hr.neighbourhood, count(hr.id) as nr FROM hotelReview hr inner join hotel h on h.HotelID=hr.HotelID '.$where.' GROUP BY neighbourhood '.$orderBy.' '; #echo '
'.$q.'
'; $stmt = $this->dbh->query($q); if($stmt->rowCount()){ $this->neighbourhood= $stmt->fetchALL(PDO::FETCH_CLASS, 'HotelReview'); } /* #Bad fix for more relavant names if(count($this->neighbourhood)>0){ foreach($this->neighbourhood as $key=>$n){ #Hotell Stockholm if($s->id=42){ #print_r($n); #echo "
".$n->neighbourhood.'
'; #echo "
".$key.'
'; if($n->neighbourhood=="Norrmalm"){ echo "INNE
"; # echo $this->neighbourhood[$key]->neighbourhood.'
'; $this->neighbourhood[$key]->neighbourhood="Norrmalm/Vasastan"; # echo $this->neighbourhood[$key]->neighbourhood.'
'; } } } #echo "ddd"; # print_r($this->neighbourhood); } */ } } class Offer{ public $id; public $network; public $priceFrom; public $priceTo; public $text; public $logo; public $bookingUrl; } class Hotel{ public $id; public $name; public $city; public $citySe; public $text; public $textSe; public $textCity; public $imageUrl; public $imageLocal; public $image; public $mainImageUrl; public $url; public $price; public $normalPrice; public $currency; public $programLogoPath; public $programId; public $advertiserProductUrl; public $address; public $address2; public $zip; public $phone; public $AdvertiserURL; public $zanoxUrl; public $airportCode; public $country; public $countrySe; public $highRate; public $HotelID; public $latitude; public $longitude; public $lowRate; public $postalcode; public $date; public $lastUpdatedDate; public $bookingURL; public $expediaId; public $statusExpedia; public $destinationId; public $expediaRegionId; public $state; public $chain; public $welcomeRewardsEligible; public $rating=0; public $reviewScore; public $numberReviews; public $cityLandingPage; public $propertyType; public $nearestLandmarkId; public $nearestLandmarkName; public $sId; public $views; public $clicks; public $built; public $lastRenovated; public $nrOfRooms; public $nrOfFloors; public $checkIn; public $checkOut; public $yearOpen; public $agodaName; public $hotelFormerlyName; #new ADD FUNCTIONALLITY!!!! public $agodaAddress; public $agodaZIP;#new public $agodaAddressCity; #new public $agodaUrl; public $agodaRateLow; public $agodaRateHigh; public $agodaText; public $agodaHotelId; public $agodaReviewScore; public $agodaNumberReviews; public $agodaLastUpdatedDate; public $agodaCreateDate; public $siteName; public $siteType; public $insertedAs; public $bookingName; public $bookingAddress; public $bookingZIP; public $bookingHotelUrl; public $bookingRateLow; public $bookingRateHigh; public $bookingHotelId; public $bookingCreateDate; public $bookingLastUpdatedDate; public $bookingLong; public $bookingLat; public $bookingCityId; public $trivagoName; public $trivagoHotelUrl; public $trivagoRateLow; public $trivagoRateHigh; public $trivagoHotelId; public $trivagoCreateDate; public $trivagoLastUpdatedDate; public $trivagoLong; public $trivagoLat; public $review; public $avgRating; public $nrOfReviews; public $bestPrice; public $bestUrl; public $googleRating; public $googleRatingNr; #Arrays public $regions=array(); public $amenities=array(); public $themes=array(); public $airports=array(); public $images=array(); public $ratings=array(); public $aboutPoints=array(); public $typeOfHotel=array(); public $placeOfInterest=array(); public $transitStation=array(); public $publicTransport=array(); public $topPlaceOfInterest=array(); public $offers=array(); public function __construct(){ global $dbh; $this->dbh = $dbh; } public function SetAvgRating(){ $avg=0; $nr=0; if($this->reviewScore>0){ $avg+=$this->reviewScore; $nr++; } if($this->agodaReviewScore>0){ $avg+=$this->agodaReviewScore; $nr++; } if($this->googleRating>0){ $avg+=$this->googleRating; $nr++; } if($avg>0){ $this->nrOfReviews=$nr; $this->avgRating=round($avg/$nr,2); } } public function SetGoogleRating(){ $stmt = $this->dbh->query('SELECT AVG( rating ) as avgRating , sum( rating ) as nrRating FROM hotelRating WHERE HotelID ='.$this->HotelID); if($stmt->rowCount()){ $row = $stmt->fetch(PDO::FETCH_OBJ); $this->googleRating=$row->avgRating; $this->googleRatingNr=$row->nrRating; } } public function SetMainImageUrl(){ $this->mainImageUrl='hotellbild/'.FixUrl($this->name).'/'.$this->id.'.jpg'; } public function SetOffers(){ #Set Hotels if($this->HotelID>0){ $offer=new Offer(); $offer->network='Hotels'; $offer->logo="hotels.png"; if($this->lowRate>0) $offer->priceFrom=$this->price. ' kr'; if($this->highRate>0) $offer->priceTo=$this->highRate. ' kr'; $offer->text='Samla 10 nätter, få 1 bonusnatt!'; $offer->bookingUrl=FixUrl($offer->network).'/boka-hotell-'.$this->id; $this->offers[]=$offer; } #set Agoda if (!empty($this->agodaHotelId)) { $offer=new Offer(); $offer->network='Agoda'; $offer->logo="agoda.png"; if($this->agodaRateLow>0) $offer->priceFrom=$this->agodaRateLow. ' kr'; if($this->agodaRateHigh>0) $offer->priceTo=$this->agodaRateHigh. ' kr'; $offer->text='Du kan få ett lägre pris på det här boendet genom att logga in. '; $offer->bookingUrl=FixUrl($offer->network).'/boka-hotell-'.$this->id; $this->offers[]=$offer; } #set Bookings if (!empty($this->bookingHotelId)) { $offer=new Offer(); $offer->network='Booking'; $offer->logo="booking.png"; if($this->bookingRateLow>0) $offer->priceFrom=$this->bookingRateLow. ' kr'; if($this->agodaRateHigh>0) $offer->priceTo=$this->bookingRateHigh. ' kr'; $offer->text='GRATIS avbokning på de flesta hotellen & rummen. '; $offer->bookingUrl=FixUrl($offer->network).'/boka-hotell-'.$this->id; $this->offers[]=$offer; } #Order by lowest Price usort($this->offers, function($a, $b) { return strcmp($a->priceFrom, $b->priceFrom); }); #Se if we should set trivago try{ $stmt = $this->dbh->query('SELECT trivagoUrl from site where id='.$this->sId); if($stmt->rowCount()){ $row = $stmt->fetch(PDO::FETCH_OBJ); if(!empty($row->trivagoUrl)){ $offer=new Offer(); $offer->network='Trivago'; $offer->logo="trivago.png"; $offer->text='Över 1 miljon hotell och 250 bokningssidor att jämföra pris för!'; $offer->priceFrom="Kontrollera"; $offer->bookingUrl='trivago/boka-hotell-'.$this->id; $this->offers[]=$offer; } } } catch (Exception $e) { header("Location: http://".$_SERVER['SERVER_NAME']); } } public function SetTrivagoBaseUrl(){ $stmt = $this->dbh->query('SELECT trivagoUrl from site where id='.$this->sId); if($stmt->rowCount()){ $row = $stmt->fetch(PDO::FETCH_OBJ); $row->trivagoUrl=str_replace('SAJT', $_SERVER['SERVER_NAME'], $row->trivagoUrl); return 'http://tc.tradetracker.net/?c=14386&m=12&a=249445&r='.$_SERVER['SERVER_NAME'].'&u='.$row->trivagoUrl; } else{ return "http://tc.tradetracker.net/?c=14386&m=12&a=249445&r=".$_SERVER['SERVER_NAME']."&u="; } } public function SetAirportsForHotel(){ echo 'SELECT * , ( 6371 * acos( cos( radians('.$this->latitude.') ) * cos( radians( lat ) ) * cos( radians( airport.long ) - radians('.$this->longitude.') ) + sin( radians('.$this->latitude.') ) * sin( radians( lat ) ) ) *1000 ) AS distance FROM airport ORDER BY distance LIMIT 0 , 10'; $stmt = $this->dbh->query('SELECT * , ( 6371 * acos( cos( radians('.$this->latitude.') ) * cos( radians( lat ) ) * cos( radians( airport.long ) - radians('.$this->longitude.') ) + sin( radians('.$this->latitude.') ) * sin( radians( lat ) ) ) *1000 ) AS distance FROM airport ORDER BY distance LIMIT 0 , 10'); if($stmt->rowCount()){ $rows = $stmt->fetchAll(PDO::FETCH_OBJ); foreach($rows as $row){ if($row->distance<100000){ #print_r($row); echo $row->aName.'
'; #avoid dup echo 'SELECT * FROM airportHotel where aId='.$row->id.' and HotelID='.$this->HotelID.'
'; $stmt2 = $this->dbh->query('SELECT * FROM airportHotel where aId='.$row->id.' and HotelID='.$this->HotelID); echo $stmt2->rowCount(); if(!$stmt2->rowCount()){ $distance=round($row->distance, -3); $in='Insert into airportHotel set aId='.$row->id.', HotelID='.$this->HotelID; echo $in; $stmt = $this->dbh->query($in); } } } } } public function UpdateClicks($and=""){ $stmt = $this->dbh->query('UPDATE hotel SET clicks = clicks +1 WHERE id ='.$this->id); } public function SetPlacePhotoForHotel($and=""){ $stmt = $this->dbh->query(' SELECT pp . * FROM hotelReview hr INNER JOIN hotel h ON hr.HotelID = h.HotelID INNER JOIN placePhoto pp ON pp.place_id = hr.place_id where h.id='.$this->id.' '.$and); if($stmt->rowCount()){ $this->images= $stmt->fetchALL(PDO::FETCH_CLASS, 'PlacePhoto'); } } public function SetExtraImagesForHotel($and=""){ $stmt = $this->dbh->query(' SELECT * from image where hId='.$this->HotelID.' '.$and); if($stmt->rowCount()){ $results = $stmt->fetchAll(PDO::FETCH_OBJ); foreach($results as $r){ $pp=new PlacePhoto(); $pp->html_attributions=""; $pp->imageUrl=$r->imageUrl; $this->images[]=$pp; } } } public function SetTypeOfHotel($and=""){ $stmt = $this->dbh->query(' SELECT pt . * FROM placeTypeHotel pth INNER JOIN placeType pt ON pth.ptId = pt.id INNER JOIN hotel h ON h.HotelID = pth.HotelID where h.id='.$this->id.' '.$and); if($stmt->rowCount()){ $this->typeOfHotel= $stmt->fetchALL(PDO::FETCH_CLASS, 'PlaceType'); } } public function SetAboutPoints($extra=""){ if(!empty($this->nearestLandmarkName)){ $this->aboutPoints[]="Nära ".$this->nearestLandmarkName; } if(!empty($this->chain)){ $this->aboutPoints[]="Hotelkedja ".$this->chain; } if(!empty($this->bookingName)){ if($this->bookingName!=$this->name) $this->aboutPoints[]="Andra namn på hotellet är ".$this->bookingName; } if(!empty($this->agodaName)){ if($this->agodaName!=$this->name) $this->aboutPoints[]="Andra namn på hotellet är ".$this->bookingName; } if(!empty($this->hotelFormerlyName)){ if($this->hotelFormerlyName!=$this->name) $this->aboutPoints[]="Hotellet hette tidigare ".$this->bookingName; } if(!empty($this->agodaHotelId)){ if(!empty($this->agodaName)){ $this->aboutPoints[]="Andra namn på hotellet är ".$this->agodaName; } if(!empty($this->built)){ $this->aboutPoints[]="Byggt ".$this->built; } if(!empty($this->lastRenovated)){ $this->aboutPoints[]="Renoverades senast ".$this->lastRenovated; } if(!empty($this->nrOfRooms)){ $this->aboutPoints[]=$this->nrOfRooms.' rum.'; } if(!empty($this->nrOfFloors)){ $this->aboutPoints[]=$this->nrOfFloors.' våningar'; } if(!empty($this->checkIn)){ $this->aboutPoints[]="Checka in från: ".str_replace("PM", " eftermiddag",$this->checkIn); } if(!empty($this->checkOut)){ $this->aboutPoints[]="Checka ut innan: ".str_replace("PM", "eftermiddag",$this->checkOut); } if(!empty($this->yearOpen)){ $this->aboutPoints[]="Öppnade: ".$this->yearOpen; } if(!empty($this->hotelFormerlyName)){ $this->aboutPoints[]="Hette tidigare: ".$this->hotelFormerlyName; } } if(!empty($this->review->neighbourhood)){ $this->aboutPoints[]='Statdsdel i '.$this->citySe.' är '.$this->review->neighbourhood; } } public function SetAffiliateLinkZanox(){ if(strlen($this->advertiserProductUrl)){ $this->url='https://ad.zanox.com/ppc/?31818807C1143643396&zpar0=[['.$this->siteName.']]&zpar1=[[HotelClick]]&ulp=[['.$this->advertiserProductUrl.']]'; } else $this->url=""; } public function SetSIDforHotel(){ $stmt=""; if($this->siteType=='country'){ $stmt = $this->dbh->query('SELECT * FROM site where country like "'.$this->country.'" and siteType="country"'); } else if($this->siteType=='city'){ $stmt = $this->dbh->query('SELECT * FROM site where city like "'.$this->city.'" and siteType="city"'); } if($stmt->rowCount()){ $results = $stmt->fetch(PDO::FETCH_OBJ); $this->sId=$results->id; $temp=parse_url($results->url); $this->siteName=$temp['host']; #$this->url=str_replace('&zpar0=[[SAJT_NAME]]', '&zpar0=[[]]',$this->url); #print_r($this); #exit; return $this->sId; } else{ return 0; } } public function SetHotelTrivago($data){ $this->trivagoName=addslashes($data[1]); $this->trivagoHotelUrl=$data[5]; $this->trivagoRateLow=str_replace(" SEK", "", $data[10]); $this->trivagoRateHigh=str_replace(" SEK", "", $data[10]); $this->trivagoHotelId=$data[0]; $latLong=explode(",", $data[15]); $this->trivagoLong=$latLong[0]; $this->trivagoLat=$latLong[1]; } public function SetHotelAgoda($data){ $this->agodaText=addslashes($data[30]); $this->agodaText=$data[30]; $this->agodaUrl='http://www.agoda.com/sv-se'.$data[18].'?cid=1730476'; $this->url='http://www.agoda.com/sv-se'.$data[18].'?cid=1730476'; #Make sure price is right, high/low if($this->agodaRateLow=$data[31]<$this->agodaRateHigh){ $this->agodaRateLow=$data[31]; $this->agodaRateHigh=$data[39]; } else{ $this->agodaRateLow=$data[39]; $this->agodaRateHigh=$data[31]; } #fix empty rates $this->lastRenovated=$data[24]; $this->nrOfRooms=$data[21]; $this->nrOfFloors=$data[22]; $this->checkIn=$data[19]; $this->checkOut=$data[20]; $this->yearOpen=$data[23]; $this->name=addslashes($data[5]); $this->agodaName=addslashes($data[5]); $this->city=addslashes($data[11]); $this->citySe=addslashes($data[11]); $this->address=addslashes($data[8]); $this->address2=addslashes($data[9]); $this->country=$data[13]; $this->countrySe=$data[13]; $this->HotelID='-1'.$data[0]; $this->latitude=$data[17]; $this->longitude=$data[16]; $this->postalcode=$data[10]; $this->state=addslashes($data[12]); $this->chain=addslashes($data[2]); $this->agodaAddress=addslashes($data[8]); $this->agodaReviewScore=$data[37]/2; $this->agodaNumberReviews=$data[36]; $this->agodaHotelId=$data[0]; $this->images[]=$data[25]; $this->images[]=$data[26]; $this->images[]=$data[27]; $this->images[]=$data[28]; $this->images[]=$data[29]; } public function SetHotel($data){ #print_r($data); #exit; #SÄTT!!!! $data['citySe']=""; $data['textSe']=""; $data['textCity']=""; $data['zanoxUrl']=""; $data['aaa']=""; $this->name=addslashes($data['Name']); $this->city=addslashes($data['City']); $this->citySe=addslashes($data['City']); $this->text=addslashes($data['Description']); $this->textSe=$data['textSe']; $this->textCity=$data['textCity']; $this->imageUrl=$data['ImageURL']; $this->url='https://ad.zanox.com/ppc/?31818807C1143643396&zpar0=[[SAJT_NAME]]&zpar1=[[HotelClick]]&ulp=[['.$data['PropertyDetailsLink'].']]'; $this->price=$data['Price']; $this->normalPrice=$data['Strike_Through_Price']; $this->currency=$data['Currency']; $this->advertiserProductUrl=$data['PropertyDetailsLink']; $this->address=addslashes($data['Address1']); $this->address2=addslashes($data['Address2']); $this->zip=addslashes($data['Zip']); $this->phone=$data['Telephone']; $this->zanoxUrl=$data['zanoxUrl']; $this->airportCode=$data['aaa']; # Set the first airport in array? $this->country=$data['Country']; $this->countrySe=$data['Country']; $this->highRate=$data['Price']*1.5; $this->HotelID=$data['Id']; $this->latitude=$data['Latitude']; $this->longitude=$data['Longitude']; $this->lowRate=$data['Price']; $this->postalcode=$data['Zip']; $this->date='NOW()'; $this->bookingURL=$data['PropertyDetailsLink']; $this->expediaId=$data['ExpediaId']; $this->statusExpedia=$data['Status']; $this->destinationId=$data['DestinationId']; $this->expediaRegionId=$data['ExpediaRegionId']; $this->state=addslashes($data['State']); $this->chain=addslashes($data['Chain']); $this->welcomeRewardsEligible=$data['WelcomeRewardsEligible']; $this->rating=$data['Star_rating']; $this->reviewScore=$data['Review_score']; $this->numberReviews=$data['Number_Reviews']; $this->cityLandingPage=$data['CityLandingLink']; $this->propertyType=$data['PropertyType']; $this->nearestLandmarkId=$data['NearestLandmarkId']; $this->nearestLandmarkName=addslashes($data['NearestLandmarkName']); echo "
"; } public function SaveHotel(){ # print_r($this); if(empty($this->agodaHotelId)){ $this->agodaHotelId=-1; } if(empty($this->bookingHotelId)){ $this->bookingHotelId=-2; } if($this->CheckIfHotelExistsForSite()){ echo $this->name." Duplicate ".$this->id."
"; $this->SetImage(); $this->SetAffiliateLinkZanox(); if($this->siteType=='country'){ $this->FixTextCountry(); } if($this->siteType=='city'){ $this->FixTextCity(); } $this->UpdateHotel(); #Save Image if(!empty($this->imageUrl)){ $i=new Image(); $i->hId=$this->HotelID; $i->imageUrl=$this->imageUrl; $i->SaveImage(); } } else{ echo "
HERE 3"; try { $this->SetImage(); $this->SetAffiliateLinkZanox(); $this->insertedAs="inserted as unique"; if($this->siteType=='country'){ $this->FixTextCountry(); } if($this->siteType=='city'){ $this->FixTextCity(); } $in='INSERT into hotel set name="'.$this->name.'", city="'.$this->city.'", citySe="'.$this->citySe.'", text="'.$this->text.'", textSe="'.$this->textSe.'", textCity="'.$this->textCity.'", imageUrl="'.$this->imageUrl.'", imageLocal="'.$this->imageLocal.'", image="'.$this->image.'", url="'.$this->url.'", price="'.$this->price.'", normalPrice="'.$this->normalPrice.'", currency="'.$this->currency.'", programLogoPath="'.$this->programLogoPath.'", programId="'.$this->programId.'", advertiserProductUrl="'.$this->advertiserProductUrl.'", address="'.$this->address.'", address2="'.$this->address2.'", zip="'.$this->zip.'", phone="'.$this->phone.'", AdvertiserURL="'.$this->AdvertiserURL.'", zanoxUrl="'.$this->zanoxUrl.'", airportCode="'.$this->airportCode.'", country="'.$this->country.'", countrySe="'.$this->countrySe.'", highRate="'.$this->highRate.'", HotelID="'.$this->HotelID.'", latitude="'.$this->latitude.'", longitude="'.$this->longitude.'", lowRate="'.$this->lowRate.'", postalcode="'.$this->postalcode.'", date=NOW(), lastUpdatedDate=NOW(), bookingURL="'.$this->bookingURL.'", expediaId="'.$this->expediaId.'", statusExpedia="'.$this->statusExpedia.'", destinationId="'.$this->destinationId.'", expediaRegionId="'.$this->expediaRegionId.'", state="'.$this->state.'", chain="'.$this->chain.'", welcomeRewardsEligible="'.$this->welcomeRewardsEligible.'", rating="'.$this->rating.'", reviewScore="'.$this->reviewScore.'", numberReviews="'.$this->numberReviews.'", cityLandingPage="'.$this->cityLandingPage.'", propertyType="'.$this->propertyType.'", nearestLandmarkId="'.$this->nearestLandmarkId.'", nearestLandmarkName="'.addslashes($this->nearestLandmarkName).'", insertedAs="'.$this->insertedAs.'", sId='.$this->sId; #echo $in; #exit; $stmt = $this->dbh->query($in); $this->id=$this->dbh->lastInsertId(); #Save Image if(!empty($this->imageUrl)){ $i=new Image(); $i->hId=$this->HotelID; $i->imageUrl=$this->imageUrl; $i->SaveImage(); } } catch (Exception $e) { echo "ERRROR CANT INSERT---!!!!
"; echo $in.'
'; exit; } } # return $this->id; } public function SaveHotelBooking(){ if($this->CheckIfHotelExistsForSite()){ echo $this->name." Duplicate ".$this->id."
"; echo '

CheckIfHotelExistsForSite: '.$this->name.'=='.$this->bookingName.'

'; echo '

HoteID: '.$this->HotelID.'==Booking HotelID: '.$this->bookingHotelId.'

'; echo "HID: ".$this->HotelID; $this->UpdateHotelBooking(); } } public function SaveHotelAgoda(){ # print_r($this); if($this->CheckIfHotelExistsForSite()){ echo $this->name." Duplicate ".$this->id."
"; echo '

CheckIfHotelExistsForSite: '.$this->name.'=='.$this->agodaName.'

'; echo '

HoteID: '.$this->HotelID.'==AgodaID: '.$this->agodaHotelId.'

'; if($this->siteType=='country'){ #$this->FixTextCountry(); } if($this->siteType=='city'){ #$this->FixTextCity(); } echo "HID: ".$this->HotelID; #Save Image if(!empty($this->images)){ $i=new Image(); $i->hId=$this->HotelID; foreach($this->images as $value){ $i->imageUrl=$value; $i->SaveImage(); } } else{ $this->SetImage(); } $this->UpdateHotelAgoda(); } else{ echo "

INSERT AGODA

"; $this->insertedAs="inserted as unique"; echo "
HERE 3"; try { if($this->siteType=='country'){ $this->FixTextCountryAgoda(); $this->textSe=$this->agodaText; $this->agodaText=$this->textSe; } if($this->siteType=='city'){ # $this->FixTextCity(); $this->FixTextCityAgoda(); $this->agodaText=$this->textSe; } $this->imageUrl=$this->images[0]; $this->SetImage(); $in='INSERT into hotel set name="'.$this->name.'", city="'.$this->city.'", citySe="'.$this->citySe.'", text="'.$this->text.'", textSe="

'.$this->textSe.'

", price="'.$this->agodaRateLow.'", lowRate="'.$this->agodaRateLow.'", normalPrice="'.$this->agodaRateLow.'", highRate="'.$this->agodaRateHigh.'", imageUrl="'.$this->imageUrl.'", image="'.$this->image.'", url="'.$this->url.'", address="'.$this->address.'", address2="'.$this->address2.'", zip="'.$this->agodaZIP.'", country="'.$this->country.'", countrySe="'.$this->countrySe.'", HotelID="'.$this->HotelID.'", latitude="'.$this->latitude.'", longitude="'.$this->longitude.'", postalcode="'.$this->postalcode.'", date=NOW(), state="'.$this->state.'", chain="'.$this->chain.'", lastRenovated="'.$this->lastRenovated.'", nrOfRooms="'.$this->nrOfRooms.'", nrOfFloors="'.$this->nrOfFloors.'", checkIn="'.$this->checkIn.'", checkOut="'.$this->checkOut.'", yearOpen="'.$this->yearOpen.'", agodaName="'.$this->agodaName.'", agodaAddress="'.$this->agodaAddress.'", agodaUrl="'.$this->agodaUrl.'", agodaRateLow="'.$this->agodaRateLow.'", agodaRateHigh="'.$this->agodaRateHigh.'", agodaText="'.$this->agodaText.'", agodaHotelId='.$this->agodaHotelId.', agodaReviewScore="'.$this->agodaReviewScore.'", agodaNumberReviews="'.$this->agodaNumberReviews.'", agodaLastUpdatedDate=NOW(), agodaCreateDate=NOW(), insertedAs="'.$this->insertedAs.'", sId='.$this->sId; echo $in.'
'."\n"; $stmt = $this->dbh->query($in); $this->id=$this->dbh->lastInsertId(); #Save Image if(!empty($this->images)){ $i=new Image(); $i->hId=$this->HotelID; foreach($this->images as $value){ $i->imageUrl=$value; $i->SaveImage(); } } else{ $this->SetImage(); } } catch (Exception $e) { echo "ERRROR CANT INSERT !!!!
"; echo $in.'
'; #exit; } exit; } # return $this->id; } public function UpdateHotel(){ # print_r($this); $up='Update hotel set name="'.$this->name.'", city="'.$this->city.'", citySe="'.$this->citySe.'", text="'.$this->text.'", textSe="'.$this->textSe.'", textCity="'.$this->textCity.'", imageUrl="'.$this->imageUrl.'", imageLocal="'.$this->imageLocal.'", image="'.$this->image.'", url="'.$this->url.'", price="'.$this->price.'", normalPrice="'.$this->normalPrice.'", currency="'.$this->currency.'", programLogoPath="'.$this->programLogoPath.'", programId="'.$this->programId.'", advertiserProductUrl="'.$this->advertiserProductUrl.'", address="'.$this->address.'", address2="'.$this->address2.'", zip="'.$this->zip.'", phone="'.$this->phone.'", AdvertiserURL="'.$this->AdvertiserURL.'", zanoxUrl="'.$this->zanoxUrl.'", airportCode="'.$this->airportCode.'", country="'.$this->country.'", countrySe="'.$this->countrySe.'", highRate="'.$this->highRate.'", HotelID="'.$this->HotelID.'", latitude="'.$this->latitude.'", longitude="'.$this->longitude.'", lowRate="'.$this->lowRate.'", postalcode="'.$this->postalcode.'", lastUpdatedDate=NOW(), bookingURL="'.$this->bookingURL.'", expediaId="'.$this->expediaId.'", statusExpedia="'.$this->statusExpedia.'", destinationId="'.$this->destinationId.'", expediaRegionId="'.$this->expediaRegionId.'", state="'.$this->state.'", chain="'.$this->chain.'", welcomeRewardsEligible="'.$this->welcomeRewardsEligible.'", rating="'.$this->rating.'", reviewScore="'.$this->reviewScore.'", numberReviews="'.$this->numberReviews.'", cityLandingPage="'.$this->cityLandingPage.'", propertyType="'.$this->propertyType.'", nearestLandmarkId="'.$this->nearestLandmarkId.'", nearestLandmarkName="'.addslashes($this->nearestLandmarkName).'" where id='.$this->id.' limit 1'; try { #echo $up; $stmt = $this->dbh->query($up); } catch (Exception $e) { print_r($e); exit; } # return $this->id; } public function UpdateHotelAgoda(){ echo "

UPDATE AGODA

"; $up='Update hotel set lastRenovated="'.$this->lastRenovated.'", nrOfRooms="'.$this->nrOfRooms.'", nrOfFloors="'.$this->nrOfFloors.'", checkIn="'.$this->checkIn.'", checkOut="'.$this->checkOut.'", yearOpen="'.$this->yearOpen.'", agodaUrl="'.$this->agodaUrl.'", agodaName="'.$this->agodaName.'", agodaAddress="'.$this->agodaAddress.'", agodaRateLow="'.$this->agodaRateLow.'", agodaRateHigh="'.$this->agodaRateHigh.'", agodaText="'.$this->agodaText.'", agodaHotelId="'.$this->agodaHotelId.'", agodaReviewScore="'.$this->agodaReviewScore.'", agodaNumberReviews="'.$this->agodaNumberReviews.'", agodaLastUpdatedDate=NOW(), insertedAs="'.$this->insertedAs.'" where id='.$this->id.' and agodaHotelId<=0'; echo $up.'
'; try { $stmt = $this->dbh->query($up); } catch (Exception $e) { echo"

".$up."

\n\n"; print_r($e); exit; } } public function UpdateHotelBooking(){ echo "

UPDATE Bookings

"; $up='Update hotel set bookingName="'.$this->bookingName.'", bookingAddress="'.$this->bookingAddress.'", bookingZIP="'.$this->bookingZIP.'", bookingHotelUrl="'.$this->bookingHotelUrl.'", bookingRateLow="'.$this->bookingRateLow.'", bookingRateHigh="'.$this->bookingRateHigh.'", bookingHotelId="'.$this->bookingHotelId.'", bookingLastUpdatedDate=NOW(), bookingLong="'.$this->bookingLong.'", bookingLat="'.$this->bookingLat.'", bookingCityId="'.$this->bookingCityId.'" where id='.$this->id.' limit 1'; echo $up.'
'; try { $stmt = $this->dbh->query($up); } catch (Exception $e) { echo"

".$up."

\n\n"; print_r($e); exit; } } public function FixTextCountry(){ $this->textSe=$this->text; $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_replace('

', '', $this->textSe); $this->textSe=str_replace(' mest exklusiva ', 'vackraste ', $this->textSe); $this->textSe=str_replace(' erbjuder boende ', ' erbjuder rum ', $this->textSe); $this->textSe=str_replace(' endast ett par kvarter ', ' endast ett stenkast ', $this->textSe); $this->textSe=str_replace(' gratis wi-fi ', 'gratis wi-fi/internet ', $this->textSe); $this->textSe=str_replace(' plattskärms-tv ', ' TV ', $this->textSe); $this->textSe=str_replace(' shoppingcentra ', ' shoppingcentrum ', $this->textSe); $this->textSe=str_replace(' Gäster vallfärdar hit ', ' Gäster vallfärdar ständigt hit ', $this->textSe); $this->textSe=str_replace(' ett par minuter ', ' några minuter ', $this->textSe); $this->textSe=str_replace('Shoppa det senaste modet ', 'Shopping i världsklass ', $this->textSe); $this->textSe=str_replace('Du behöver bara gå ett par minuter', 'Endast några minuters promenad ', $this->textSe); $this->textSe=str_replace('Gäster erbjuds städning dagligen', 'Alla rum på '.$this->name.' städas dagligen', $this->textSe); $this->textSe=str_replace('

Läge. ', '

Läge för '.$this->name.' ', $this->textSe); $this->textSe=str_replace('Hotellegenskaper. ', ''.$this->name.' erbjuder flera bekvämligheter', $this->textSe); $this->textSe=str_replace('erbjuder restaurang och bar. ', 'har både en bar och restaurang på hotellet.', $this->textSe); $this->textSe=str_replace('I närheten ligger även ', 'Nära hotellet ligger även ', $this->textSe); $this->textSe=str_replace('Kostnadsfri wi-fi ', ' Gratis/fritt wi-fi/internet ', $this->textSe); $this->textSe=str_replace('Gäster har tillgång till bland annat hjälp med bokning av biljetter och guidade turer', 'Hotellet erbjuder sina gäster hjälp med bokning av biljetter samt guidade turer', $this->textSe); $this->textSe=str_replace('Rum. ', 'Rummen på '.$this->name.'', $this->textSe); $this->textSe=str_replace('värdeförvaringsskåp ', 'värdeförvaringsskåp/säkerhetsskåp ', $this->textSe); $this->textSe=str_replace('gratis toalettartiklar.', 'fria toalettartiklar. ', $this->textSe); $this->textSe=str_replace('Gäster har tillgång till ', 'Hotellets gäster har tillgång till ', $this->textSe); $this->textSe=str_replace('gratis wi-fi ', 'gratis wi-fi/internet ', $this->textSe); $this->textSe=str_replace('hårtork finns tillgänglig på begäran.', 'hårtork finns tillgänglig.', $this->textSe); $this->textSe=str_replace('är tillgängligt i allmänna utrymmen', 'är tillgängligt i publika utrymmen', $this->textSe); $this->textSe=str_replace('Parkeringsservice är kostnadsfri. ', 'Det finns grats Parkeringsservice. ', $this->textSe); $this->textSe=str_replace('Särskilda områden för rökning finns tillgängliga. ', 'Det finns särskilda områden där rökning är tillåtet.', $this->textSe); $this->textSe=str_replace('satellitkanaler.', 'kabelkanaler. ', $this->textSe); $this->textSe=str_replace('Alla enheter på denna lägenhet med ', 'Alla rum på detta hotell med ', $this->textSe); $this->textSe=str_replace(' i ett historiskt område nära ', 'i ett område som andas historia nära ', $this->textSe); $this->textSe=str_replace(' I närheten ligger även ', ' I närheten av hotellet ligger även ', $this->textSe); $this->textSe=str_replace('En kostnadsfri frukost', 'En gratis frukost', $this->textSe); $this->textSe=str_replace('har även expressincheckning och expressutcheckning. ', 'erbjuder sina gäster även express-/expressutcheckning. ', $this->textSe); $this->textSe=str_replace(' En fullständig renovering slutfördes ', ' En fullständig renovering av byggnaden slutfördes ', $this->textSe); $this->textSe=str_replace('Detta hotell erbjuder ett familjevänligt boende', 'Detta hotell är ett familjevänligt hotell', $this->textSe); $this->textSe=str_replace('i allmänna utrymmen (avgift tillkommer); ', 'i allmänna utrymmen (mot en avgift); ', $this->textSe); $this->textSe=str_replace('en dator finns tillgänglig', 'en dator finns tillgänglig till ditt förfogande', $this->textSe); $this->textSe=str_replace('trädgård', 'hotellets trädgård', $this->textSe); $this->textSe=str_replace('rumsservice (under begränsade tider)', 'roomservice (under vissa tider på dygnet)', $this->textSe); $this->textSe=str_replace('Badrummen har badkar eller dusch, ', 'Badrummen har badkar och/eller dusch, ', $this->textSe); $this->textSe=str_replace('allergitestade sängkläder. ', 'allergitestade sängkläder om så önskas. ', $this->textSe); $this->textSe=str_replace('>. Badrummen har bidé ', '>. Badrummen på '.$this->name.' är utrustade med bidé ', $this->textSe); $this->textSe=str_replace('ligger bekvämt i anslutning till flygplatsen i hjärtat av', 'ligger nära i anslutning till flygplatsen och centralt i ', $this->textSe); $this->textSe=str_replace('Andra sevärdheter i området inkluderar ', 'Andra kända sevärdigheter i området innefattar ', $this->textSe); $this->textSe=str_replace('utomhuspool', 'pool utomhus', $this->textSe); $this->textSe=str_replace('inomhuspool', 'inomhus pool', $this->textSe); $this->textSe=str_replace('På detta hotell med familjevänlig profil kan man äta på ', 'På detta hotell med en familjevänlig profil kan man i lugn och ro äta på ', $this->textSe); $this->textSe=str_replace('Gästerna serveras en ', 'Gäster på '.$this->name.' serveras en ', $this->textSe); $this->textSe=str_replace('en säsongsöppen utomhuspool, ', 'en säsongsöppen pool utomhus, ', $this->textSe); $this->textSe=str_replace('takterrass. ', 'trevlig takterrass. ', $this->textSe); $this->textSe=str_replace('en terrass ', 'en trevlig terrass ', $this->textSe); $this->textSe=str_replace('en rökfri anläggning. ', 'ett rökfritt boende. ', $this->textSe); $this->textSe=str_replace('Rummen har balkonger', 'Rummen på hotellet har även balkonger', $this->textSe); $this->textSe=str_replace('> bara några steg från <', '> precis vid <', $this->textSe); $this->textSe=str_replace('kostnadsfri parkering.', 'gratis parkering.', $this->textSe); $this->textSe=str_replace('grytor/köksredskap', 'enklare köksutrustning', $this->textSe); $this->textSe=str_replace(' höghastighetsinternet ', ' internet med hög hastighet ', $this->textSe); $this->textSe=str_replace(' Gäster har även tillgång till en terrass', ' Hotellets gäster får även ta del av hotellets terras', $this->textSe); $this->textSe=str_replace(' Kostnadsfri parkering.', ' Gratis parkering.', $this->textSe); $this->textSe=str_replace('Förlängd parkering kan erbjudas efter utcheckning', 'Du kan även få möjlighet till förlängd parkering efter utcheckning', $this->textSe); $this->textSe=str_replace('luftkonditionerade gästrummen på', 'luftkonditionerade rummen på', $this->textSe); $this->textSe=str_replace('Sängarna har duntäcken och sängtillbehör av högsta kvalitet.', 'Alla sängar på '.$this->name.' har duntäcke och exklusiva sängtillbehör.', $this->textSe); $this->textSe=str_replace('Badrummen har dusch', 'Badrummen är utrustade med dusch', $this->textSe); $this->textSe=str_replace('Gäster har bland annat tillgång till flerspråkig personal', 'Hotellet kan även erbjuda flerspråkig personal', $this->textSe); $this->textSe=str_replace('Parkering erbjuds mot en tilläggsavgift', 'Parkering vid '.$this->name.' erbjuds mot en avgift', $this->textSe); $this->textSe=str_replace('Städning erbjuds dagligen.', 'Städning av rum utförs dagligen.', $this->textSe); $this->textSe=str_replace('Badrummen har badkar eller dusch och hårtork.', 'Badrummen på '.$this->name.' har badkar och/eller dusch samt hårfön.', $this->textSe); $this->textSe=str_replace('Nära hotellet ligger även ', 'I närheten av '.$this->name.' ligger även ', $this->textSe); $this->textSe=str_replace('erbjuder flera bekvämligheter<', 'erbjuder sina gäster flera bekvämligheter:<', $this->textSe); $this->textSe=str_replace('>Bekvämligheter. <', '>'.$this->name.' erbjuder: <', $this->textSe); $this->textSe=str_replace('utomhustennisbana', 'tennisbana utomhus', $this->textSe); $this->textSe=str_replace('fitnessanläggning', 'gym/fitnesscenter', $this->textSe); $this->textSe=str_replace('i allmänna utrymmen.', 'i gemensamma utrymmen.', $this->textSe); $this->textSe=str_replace('På detta lägenhetshotell i', 'På detta trevliga lägenhetshotell i', $this->textSe); $this->textSe=str_replace(', bar vid poolen ', ', baren vid poolen ', $this->textSe); $this->textSe=str_replace('eller bar.', 'eller baren.', $this->textSe); $this->textSe=str_replace('Gäster har även tillgång till', 'Gäster på hotellet har även tillgång till', $this->textSe); $this->textSe=str_replace(' och utomhusgrill', ' samt utomhusgrill', $this->textSe); $this->textSe=str_replace('fria toalettartiklar', 'gratis toalettartiklar', $this->textSe); $this->textSe=str_replace('Alla enheter på detta ', 'Alla rum på detta ', $this->textSe); $this->textSe=str_replace('kylskåp och enklare ', 'kylskåp samt enklare ', $this->textSe); $this->textSe=str_ireplace(' modebutiker ', ' klädbutiker ', $this->textSe); $this->textSe=str_ireplace(' modebutiker ', ' klädbutiker ', $this->textSe); $this->textSe=str_ireplace(' exklusiv shopping ', ' exklusiv-shopping ', $this->textSe); $this->textSe=str_ireplace('Personalen kan ordna kemtvätts-/tvättjänster och valutaväxling', 'Personalen på '.$this->name.' kan erbjuda kemtvätts-/tvättjänster samt valutaväxling', $this->textSe); $this->textSe=str_ireplace('Hotellet erbjuder dessutom en hiss', $this->name.' erbjuder även hiss', $this->textSe); $this->textSe=str_ireplace('Hotellet erbjuder dessutom en hiss', $this->name.' erbjuder även hiss', $this->textSe); if($this->id%2==0){ $this->textSe=str_ireplace('Hotellet erbjuder dessutom en hiss', $this->name.' erbjuder hiss', $this->textSe); $this->textSe=str_ireplace('Hotellets gäster har tillgång till bland annat takterrass och hiss. ', 'Hotellets gäster har tillgång till både hiss och takterrass. ', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); } $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=addslashes($this->textSe); $this->text=addslashes($this->text); if(strlen($this->text)<10){ $this->text="

Vi saknar just nu information om ".$this->name.'.

'; $this->textSe=$this->text; } } public function FixTextCity(){ $this->textSe=$this->text; $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_replace('Samtliga gästrum erbjuder kök', 'Samtliga rum har kök', $this->textSe); $this->textSe=str_replace('Här erbjuds gäster gratis förmåner', 'Här erbjuds gäster fria faciliteter', $this->textSe); $this->textSe=str_replace('minuters bilfärd', 'minuter med bil', $this->textSe); $this->textSe=str_replace('platt-tv', 'plasma-/lcd-tv', $this->textSe); $this->textSe=str_replace('Här har du tillgång till', 'Här får du tillgång till', $this->textSe); $this->textSe=str_replace('fitnesscenter', 'gym/fitnesscenter', $this->textSe); $this->textSe=str_replace('

', '', $this->textSe); $this->textSe=str_replace(' mest exklusiva ', 'finaste ', $this->textSe); $this->textSe=str_replace(' erbjuder boende ', ' erbjuder hotellrum ', $this->textSe); $this->textSe=str_replace(' endast ett par kvarter ', ' i närheten ', $this->textSe); $this->textSe=str_replace(' gratis wi-fi ', 'gratis internet/wi-fi ', $this->textSe); $this->textSe=str_replace(' plattskärms-tv ', ' platt-TV ', $this->textSe); $this->textSe=str_replace(' shoppingcentra ', ' köpcentrum ', $this->textSe); $this->textSe=str_replace(' Gäster vallfärdar hit ', ' Gäster vallfärdar ofta hit ', $this->textSe); $this->textSe=str_replace(' ett par minuter ', ' endast några minuter ', $this->textSe); $this->textSe=str_replace('Shoppa det senaste modet ', 'Perfekt för shopping i '.$this->city.' ', $this->textSe); $this->textSe=str_replace('Du behöver bara gå ett par minuter', 'Endast några minuter bort ', $this->textSe); $this->textSe=str_replace('Gäster erbjuds städning dagligen', 'Städning på '.$this->name.' utförs dagligen', $this->textSe); $this->textSe=str_replace('

Läge. ', '

Läget för '.$this->name.' ', $this->textSe); $this->textSe=str_replace('Hotellegenskaper. ', ''.$this->name.' erbjuder bland annat ', $this->textSe); $this->textSe=str_replace('erbjuder restaurang och bar. ', 'har både en fin bar och en trevlig restaurang på hotellet.', $this->textSe); $this->textSe=str_replace('I närheten ligger även ', 'Nära hotellet ligger även ', $this->textSe); $this->textSe=str_replace('Kostnadsfri wi-fi ', ' Gratis/fritt wi-fi/trådlöst internet ', $this->textSe); $this->textSe=str_replace('Gäster har tillgång till bland annat hjälp med bokning av biljetter och guidade turer', $this->name.' erbjuder gäster både assistans med bokning av biljetter samt guidade turer', $this->textSe); $this->textSe=str_replace('Rum. ', 'Fakta om hotellrum på '.$this->name.'', $this->textSe); $this->textSe=str_replace('värdeförvaringsskåp ', 'säkerhetsskåp ', $this->textSe); $this->textSe=str_replace('gratis toalettartiklar.', 'toalettartiklar ingår. ', $this->textSe); $this->textSe=str_replace('Gäster har tillgång till ', 'Gäster på '.$this->name.' har tillgång till ', $this->textSe); $this->textSe=str_replace('gratis wi-fi ', 'gratis wi-fi/trådlöst internet ', $this->textSe); $this->textSe=str_replace('hårtork finns tillgänglig på begäran.', 'hårfön finns tillgänglig.', $this->textSe); $this->textSe=str_replace('är tillgängligt i allmänna utrymmen', 'är tillgängligt i gemensamma utrymmen', $this->textSe); $this->textSe=str_replace('Parkeringsservice är kostnadsfri. ', 'Det finns grats parkering. ', $this->textSe); $this->textSe=str_replace('Särskilda områden för rökning finns tillgängliga. ', 'Det finns utmärkta platser där rökning är tillåtet.', $this->textSe); $this->textSe=str_replace('satellitkanaler.', 'kabel/satellitkanaler. ', $this->textSe); $this->textSe=str_replace('Alla enheter på denna lägenhet med ', 'Alla hotellrum på detta hotell med ', $this->textSe); $this->textSe=str_replace(' i ett historiskt område nära ', 'i ett klassiskt område nära ', $this->textSe); $this->textSe=str_replace(' I närheten ligger även ', ' Nära hotellet ligger även ', $this->textSe); $this->textSe=str_replace('En kostnadsfri frukost', 'En fri frukost', $this->textSe); $this->textSe=str_replace('har även expressincheckning och expressutcheckning. ', 'erbjuder express-/expressutcheckning. ', $this->textSe); $this->textSe=str_replace(' En fullständig renovering slutfördes ', ' En fullständig renovering av hotellet genomfördes ', $this->textSe); $this->textSe=str_replace('Detta hotell erbjuder ett familjevänligt boende', ''.$this->name.' är ett familjevänligt hotell', $this->textSe); $this->textSe=str_replace('i allmänna utrymmen (avgift tillkommer); ', 'i gemensamma utrymmen (mot en avgift); ', $this->textSe); $this->textSe=str_replace('en dator finns tillgänglig', 'en dator finns till ditt förfogande', $this->textSe); $this->textSe=str_replace('trädgård', 'hotellets trädgård', $this->textSe); $this->textSe=str_replace('rumsservice (under begränsade tider)', 'roomservice (under vissa tider)', $this->textSe); $this->textSe=str_replace('Badrummen har badkar eller dusch, ', 'Badrummen är utrustade med badkar och/eller dusch, ', $this->textSe); $this->textSe=str_replace('allergitestade sängkläder. ', 'allergitestade sängkläder finns tillgängliga. ', $this->textSe); $this->textSe=str_replace('>. Badrummen har bidé ', '>. Badrummen på '.$this->name.' har bidé ', $this->textSe); $this->textSe=str_replace('ligger bekvämt i anslutning till flygplatsen i hjärtat av', 'ligger nära flygplatsen och centralt i', $this->textSe); $this->textSe=str_replace('Andra sevärdheter i området inkluderar ', 'Andra kända attraktioner i området är ', $this->textSe); $this->textSe=str_replace('utomhuspool', 'pool', $this->textSe); $this->textSe=str_replace('inomhuspool', 'pool', $this->textSe); $this->textSe=str_replace('På detta hotell med familjevänlig profil kan man äta på ', 'På detta familjevänliga hotell med kan du i lugn och ro äta på ', $this->textSe); $this->textSe=str_replace('Gästerna serveras en ', 'Gäster på '.$this->name.' serveras en ', $this->textSe); $this->textSe=str_replace('en säsongsöppen utomhuspool, ', 'en säsongsöppen pool, ', $this->textSe); $this->textSe=str_replace('takterrass. ', 'fin takterrass. ', $this->textSe); $this->textSe=str_replace('en terrass ', 'en fin terrass ', $this->textSe); $this->textSe=str_replace('en rökfri anläggning. ', 'ett rökfritt hotell. ', $this->textSe); $this->textSe=str_replace('Rummen har balkonger', $this->name.' har även balkonger', $this->textSe); $this->textSe=str_replace('> bara några steg från <', '> jämte <', $this->textSe); $this->textSe=str_replace('kostnadsfri parkering.', 'fri parkering.', $this->textSe); $this->textSe=str_replace('grytor/köksredskap', 'enklare kök', $this->textSe); $this->textSe=str_replace(' höghastighetsinternet ', ' internet/wifi med hög hastighet ', $this->textSe); $this->textSe=str_replace(' Gäster har även tillgång till en terrass', ' Gäster på '.$this->name.' får även ta del av hotellets terras', $this->textSe); $this->textSe=str_replace(' Kostnadsfri parkering.', ' Fri parkering.', $this->textSe); $this->textSe=str_replace('Förlängd parkering kan erbjudas efter utcheckning', $this->name.' erbjuder förlängd parkering efter utcheckning', $this->textSe); $this->textSe=str_replace('luftkonditionerade gästrummen på', 'luftkonditionerade hotellrummen på', $this->textSe); $this->textSe=str_replace('Sängarna har duntäcken och sängtillbehör av högsta kvalitet.', 'Rummen på '.$this->name.' har duntäcke och sköna sängtillbehör.', $this->textSe); $this->textSe=str_replace('Badrummen har dusch', 'Badrummen är utrustade med dusch', $this->textSe); $this->textSe=str_replace('Gäster har bland annat tillgång till flerspråkig personal', $this->name.' kan även erbjuda flerspråkig personal', $this->textSe); $this->textSe=str_replace('Parkering erbjuds mot en tilläggsavgift', 'Parkering erbjuds mot avgift', $this->textSe); $this->textSe=str_replace('Städning erbjuds dagligen.', 'Städning av rum på '.$this->name.' utförs dagligen.', $this->textSe); $this->textSe=str_replace('Badrummen har badkar eller dusch och hårtork.', 'Badrummen på har badkar och/eller dusch samt hårfön.', $this->textSe); $this->textSe=str_replace('Nära hotellet ligger även ', 'Nära '.$this->name.' ligger även ', $this->textSe); $this->textSe=str_replace('erbjuder flera bekvämligheter<', 'erbjuder sina hotellgäster flera bekvämligheter:<', $this->textSe); $this->textSe=str_replace('>Bekvämligheter. <', '>'.$this->name.' tillhandahåller: <', $this->textSe); $this->textSe=str_replace('utomhustennisbana', 'tennisbana', $this->textSe); $this->textSe=str_replace('fitnessanläggning', 'gym', $this->textSe); $this->textSe=str_replace('i allmänna utrymmen.', 'i publika utrymmen.', $this->textSe); $this->textSe=str_replace('På detta lägenhetshotell i', 'På detta fina lägenhetshotell i', $this->textSe); $this->textSe=str_replace(', bar vid poolen ', ', baren nära poolen ', $this->textSe); $this->textSe=str_replace('Gäster har även tillgång till', 'Gäster på '.$this->name.' har även tillgång till', $this->textSe); $this->textSe=str_replace(' och utomhusgrill', ' samt grill', $this->textSe); $this->textSe=str_replace('fria toalettartiklar', 'fria toalettartiklar', $this->textSe); $this->textSe=str_replace('Alla enheter på detta ', 'Alla rum på '.$this->name.' ', $this->textSe); $this->textSe=str_replace('kylskåp och enklare ', 'kyl samt enklare ', $this->textSe); $this->textSe=str_ireplace(' modebutiker ', ' butiker ', $this->textSe); $this->textSe=str_ireplace('Personalen kan hjälpa till med conciergetjänster', 'Personalen bistår gärna med conciergetjänster', $this->textSe); $this->textSe=str_ireplace('Hotellet har en egen bar.', '', $this->textSe); $this->textSe=str_ireplace('Gratis wi-fi är tillgängligt', 'Gratis wifi finns tillgängligt', $this->textSe); $this->textSe=str_ireplace('hårtork', 'hårfön', $this->textSe); $this->textSe=str_ireplace('Sängarna har bäddmadrass', 'Sängarna på rummen har bäddmadrass', $this->textSe); $this->textSe=str_ireplace('allergitestade sängkläder finns tillgänglig på begäran', 'allergitestade sängkläder finns tillgängligt om så önskas', $this->textSe); $this->textSe=str_ireplace('Parkeringsplats för gäster finns mot tilläggsavgift', 'Parkeringsplats för gäster finns men det är en parkeringsavgift', $this->textSe); $this->textSe=str_ireplace('. Städning erbjuds dagligen.', '. Städning utförs dagligen.', $this->textSe); $this->textSe=str_ireplace(' Detta hotell har 5 stjärnor', ' '.$this->name.' har 5 stjärnor', $this->textSe); $this->textSe=str_ireplace(' Detta hotell har 4 stjärnor', ' '.$this->name.' har 4 stjärnor', $this->textSe); $this->textSe=str_ireplace(' Detta hotell har 3 stjärnor', ' '.$this->name.' har 3 stjärnor', $this->textSe); $this->textSe=str_ireplace(' Detta hotell har 2 stjärnor', ' '.$this->name.' har 2 stjärnor', $this->textSe); $this->textSe=str_ireplace('Kostnadsfritt höghastighetsinternet/wi-fi ', ' Gratis internet/wifi ', $this->textSe); $this->textSe=str_ireplace(' gratis toalettartiklar', ' fria toalettartiklar', $this->textSe); $this->textSe=str_ireplace('mörkläggningsgardiner', 'soltäckande gardiner', $this->textSe); $this->textSe=str_ireplace('På begäran erbjuds även massage på rummet', 'Vid förfrågan erbjuds massage på hotellrummet', $this->textSe); $this->textSe=str_ireplace('(laptopanpassade)', '(även för laptop)', $this->textSe); $this->textSe=str_ireplace('luftkonditionerade hotellrummen', 'AC utrustade hotellrummen', $this->textSe); $this->textSe=str_ireplace('och limousine- och taxibokning.', 'och limousine- samt taxibokning.', $this->textSe); $this->textSe=str_ireplace('utomhus och barnpool', 'utomhus samt barnpool', $this->textSe); $this->textSe=str_ireplace('tvättmöjligheter', 'tvättmaskin', $this->textSe); $this->textSe=str_ireplace('dagstidningar', 'tidningar', $this->textSe); $this->textSe=str_ireplace('wi-fi på rummet', 'wifi/trådlöst internet på rummet', $this->textSe); $this->textSe=str_ireplace('badrock', 'morgonrock', $this->textSe); $this->textSe=str_ireplace('tebryggare', 'tekokare', $this->textSe); $this->textSe=str_ireplace('Uppbäddningsservice erbjuds ', 'Sängen bäddas ', $this->textSe); $this->textSe=str_ireplace('i hjärtat av', 'i kärnan av ', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=str_ireplace('', '', $this->textSe); $this->textSe=addslashes($this->textSe); $this->text=addslashes($this->text); if(strlen($this->text)<10){ $this->text="

Vi saknar just nu information om ".$this->name.'.

'; $this->textSe=$this->text; } } public function FixTextCityAgoda(){ $temp=$this->agodaText; $temp=str_replace('ligger perfekt till för både affärs- och nöjesresenärer', 'ligger bra för såväl affärsresenärer som för dig som turist', $this->agodaText); $temp=str_replace('Både affärsresenärer och turister', 'Såväl turister som affärsresenärer', $this->agodaText); $temp=str_replace(' har glädje av hotellets', ' har nytta av '.$this->name, $this->agodaText); $temp=str_replace('faciliteter och tjänster', 'utbud och tjänster', $this->agodaText); $temp=str_replace('välkomnas du av serviceinriktad personal', 'möts du av en trevlig och serviceinriktad personal', $this->agodaText); $temp=str_replace('Rummen är designade för att', 'Rummen på '.$this->name.' är inredda för att', $this->agodaText); $temp=str_replace('väckningsservice som utlovar en fridfull, stärkande natt', 'väckningsservice', $this->agodaText); $temp=str_replace('Underhåll dig själv med hotellets fritidsfaciliteter', 'På '.$this->name.' finner du fritidsfaciliteter som bland annat ', $this->agodaText); $temp=str_replace('till din bas.', 'till ditt hotell.', $this->agodaText); $temp=str_replace('är en perfekt utgångspunkt', 'är en perfekt startpunkt', $this->agodaText); $temp=str_replace('varifrån man kan utforska', 'varifrån du kan utforska', $this->agodaText); $temp=str_replace('Hotellet erbjuder sina gäster ett brett utbud', $this->name.' erbjuder dig som gäst ett brett utbud', $this->agodaText); $temp=str_replace('Gratis Wi-Fi', 'Fritt Wi-Fi', $this->agodaText); $temp=str_replace('24-timmarsreception', 'reception dygnet runt', $this->agodaText); $temp=str_replace('room service dygnet runt', 'room service 24/7', $this->agodaText); $temp=str_replace('express in- och utcheckning', 'express incheckning/utcheckning', $this->agodaText); $temp=str_replace('finns med på listan över saker som gästerna', 'finns med på tjänster du som gäst erbjuds ', $this->agodaText); $temp=str_replace('Luftkonditionering', 'AC', $this->agodaText); $temp=str_replace('Internet (trådlös)', 'Internet (Wi-Fi)', $this->agodaText); $temp=str_replace('trådlöst internet (avgiftsfritt)', 'trådlöst Wi-Fi (gratis)', $this->agodaText); $temp=str_replace('i ditt komfortabla rum', 'i ditt sköna rum', $this->agodaText); $temp=str_replace('En välkomnande atmosfär', 'En välkomnande känsla', $this->agodaText); $temp=str_replace('och utmärkt service ', 'och utsökt service ', $this->agodaText); $this->agodaText=$temp; $checkIn=str_ireplace(" AM", "", $this->checkIn); $checkIn=str_ireplace(" PM", "", $this->checkIn); $checkOut=str_ireplace(" AM", "", $this->checkOut); $checkOut=str_ireplace(" PM", "", $this->checkOut); if($this->id%2==0){ if(strlen($checkIn)>2){ $this->textSe.='

'.$this->name.' erbjuder inchecking från '.$checkIn.'.'; if(strlen($checkOut)>2){ $this->textSe.="Check out är senast ".$checkOut.'. '; } $this->textSe.='.

'; } } else { if(strlen($this->yearOpen)>2){ $this->textSe.='

'.$this->name.' öppnade '.$this->yearOpen.'.'; if(strlen($this->lastRenovated)>2) $this->textSe.=' Hotellet renoverades senast '.$this->lastRenovated.'.'; } $this->textSe.='.

'; } $this->textSe.='

'.$temp.'

'; } public function FixTextCountryAgoda(){ $temp=$this->agodaText; $temp=str_replace('ligger perfekt till för både affärs- och nöjesresenärer', 'ligger passande för såväl dig som turist eller om du är affärsresenär', $this->agodaText); $temp=str_replace('Både affärsresenärer och turister', 'Såväl turister som affärsresande', $this->agodaText); $temp=str_replace(' har glädje av hotellets', ' har glädje av '.$this->name, $this->agodaText); $temp=str_replace('faciliteter och tjänster', 'tjänster och utbud', $this->agodaText); $temp=str_replace('välkomnas du av serviceinriktad personal', 'möts du av en trevlig och serviceminded personal', $this->agodaText); $temp=str_replace('Rummen är designade för att', 'Rummen på '.$this->name.' är möblerade för att', $this->agodaText); $temp=str_replace('väckningsservice som utlovar en fridfull, stärkande natt', 'service för väckning', $this->agodaText); $temp=str_replace('Underhåll dig själv med hotellets fritidsfaciliteter', 'På '.$this->name.' finner du bland annat fritidsfaciliteter som ', $this->agodaText); $temp=str_replace('är en perfekt utgångspunkt', 'är en bra startpunkt', $this->agodaText); $temp=str_replace('varifrån man kan utforska', 'varifrån du kan uppleva', $this->agodaText); $temp=str_replace('Hotellet erbjuder sina gäster ett brett utbud', $this->name.' erbjuder dig som gäst sitt breda utbud', $this->agodaText); $temp=str_replace('Gratis Wi-Fi', 'Fritt WiFi', $this->agodaText); $temp=str_replace('24-timmarsreception', 'reception 24/7', $this->agodaText); $temp=str_replace('room service dygnet runt', 'room service dygnets alla timmar', $this->agodaText); $temp=str_replace('express in- och utcheckning', 'express in-/utcheckning', $this->agodaText); $temp=str_replace('finns med på listan över saker som gästerna', 'finns med på services du som gäst erbjuds ', $this->agodaText); $temp=str_replace('Luftkonditionering', 'AirCondition', $this->agodaText); $temp=str_replace('Internet (trådlös)', 'Internet (WiFi)', $this->agodaText); $temp=str_replace('trådlöst internet (avgiftsfritt)', 'trådlöst Wi-Fi (fritt)', $this->agodaText); $temp=str_replace('i ditt komfortabla rum', 'i ditt härliga rum', $this->agodaText); $temp=str_replace('En välkomnande atmosfär', 'En välkomnande miljö', $this->agodaText); $temp=str_replace('och utmärkt service ', 'och bra service ', $this->agodaText); #new $temp=str_replace('utomhuspool', 'pool utomhus', $this->agodaText); $temp=str_replace('minibar', 'minibar på rummet', $this->agodaText); $temp=str_replace('resenärer', 'gäster', $this->agodaText); $temp=str_replace('bagageförvaring', 'förvaring av bagage', $this->agodaText); $temp=str_replace('finns att tillgå', 'finns tillgänglig', $this->agodaText); $temp=str_replace('erbjuda högsta komfort', 'erbjuda bästa komfort', $this->agodaText); $temp=str_replace('icke-rökare', 'icke rökare', $this->agodaText); $temp=str_replace('tillgodosedda', 'uppfyllda', $this->agodaText); $temp=str_replace('', '', $this->agodaText); $temp=str_replace('', '', $this->agodaText); $temp=str_replace('', '', $this->agodaText); $temp=str_replace('', '', $this->agodaText); $this->agodaText=$temp; $checkIn=str_ireplace(" AM", "", $this->checkIn); $checkIn=str_ireplace(" PM", "", $this->checkIn); $checkOut=str_ireplace(" AM", "", $this->checkOut); $checkOut=str_ireplace(" PM", "", $this->checkOut); if($this->id%2==0){ if(strlen($checkIn)>2){ $this->textSe.='

'.$this->name.' har inchecking från '.$checkIn.'.'; if(strlen($checkOut)>2){ $this->textSe.="Checkout på '.$this->name.' är senast ".$checkOut.'. '; } $this->textSe.='.

'; } } else { if(strlen($this->yearOpen)>2){ $this->textSe.='

'.$this->name.' öppnade år '.$this->yearOpen.'.'; if(strlen($this->lastRenovated)>2) $this->textSe.=$this->name.' renoverades senast '.$this->lastRenovated.'.'; } $this->textSe.='.

'; } $this->textSe.='

'.$temp.'

'; } public function SetImage(){ if(strlen($this->imageUrl)<5){ $this->imageUrl='http://flygresor2.se/hotelAdmin/hotelbildsaknas.png'; } if($this->imageUrl=="http://images.travelnow.com/hotels/STO_BERG-exter-1.jpg"){ $this->imageUrl='http://flygresor2.se/hotelAdmin/hotelbildsaknas.png'; } if(stristr($this->imageUrl, "http://images.travelnow.com/hotels/")){ $this->imageUrl='http://flygresor2.se/hotelAdmin/hotelbildsaknas.png'; } $picture=$this->imageUrl; $status=get_headers($picture); #echo $picture.'
'; #echo $status[0].'
'; if($status[0]=="HTTP/1.1 404 "){ $picture="http://extinct-website.com/extinct-website/images/noImageAvailable-0f66616d.jpg"; } # echo $picture.'
'; # echo $status[0].'
'; # exit; $image = chunk_split(base64_encode(file_get_contents($picture))); $this->imageUrl=$picture; $this->image=$image; } public function CheckIfHotelExistsForSite(){ echo 'SELECT id, insertedAs, HotelID FROM hotel where (HotelID='.$this->HotelID.' || agodaHotelId='.$this->agodaHotelId.' || bookingHotelId='.$this->bookingHotelId.') and sId='.$this->sId.'

'; $stmt = $this->dbh->query('SELECT id, insertedAs, HotelID FROM hotel where (HotelID='.$this->HotelID.' || agodaHotelId='.$this->agodaHotelId.' || bookingHotelId='.$this->bookingHotelId.') and sId='.$this->sId); if($stmt->rowCount()){ $results = $stmt->fetch(PDO::FETCH_OBJ); $this->id=$results->id; if(empty($this->insertedAs)){ $this->insertedAs="Same HotelID"; } echo "MATCH CheckIfHotelExistsForSite
"; $this->HotelID=$results->HotelID; return $this->id; } else{ echo "NO MATCH CheckIfHotelExistsForSite
"; return false; } } public function CheckIfHotelExistsForSiteSimple(){ echo 'SELECT id, FROM hotel where HotelID='.$this->HotelID.' and sId='.$this->sId.'

'; $stmt = $this->dbh->query('SELECT id FROM hotel where HotelID='.$this->HotelID.' and sId='.$this->sId); if($stmt->rowCount()){ return $this->id; } else{ echo "NO MATCH CheckIfHotelExistsForSite
"; return false; } } public function CheckIfHotelExistsByAddress(){ #Get 10 closest hotels #Agoda if($this->HotelID<0){ $resCloseBy=$this->CheckHotelsCloseByLonLat(10, " and HotelID>0 "); } else if($this->HotelID>0){ $resCloseBy=$this->CheckHotelsCloseByLonLat(10, " and HotelID<0 "); } if(count($resCloseBy)>0){ echo "

CheckHotelsCloseByLonLat

"; foreach($resCloseBy as $hotelClose){ echo "Distance: ".$hotelClose->distance.'
'; #only check 300 m from Hotel if($hotelClose->distance<300){ if($this->CheckIfHotelExistsByNameAndHotelID($hotelClose->HotelID)){ return true; } } } } else{ echo "NO DUPLICTAE!
"; $this->insertedAs="No Dup"; return false; } # } } public function CheckIfHotelExistsByNameAndHotelID($HotelID){ #IF Name without hotel/l $name1=trim(str_ireplace("hotell", "", $this->name)); $name1=trim(str_ireplace(" ", "%", $name1)); $name2=trim(str_ireplace("hotel", "", $this->name)); $name2=trim(str_ireplace(" ", "%", $name2)); echo 'SELECT id,HotelID, name, agodaHotelId FROM hotel where (name like "%'.$name1.'%" || name like "%'.$name2.'%") and sId='.$this->sId. ' AND HotelID='.$HotelID.'
'; $stmt2 = $this->dbh->query('SELECT id,HotelID,name, agodaHotelId FROM hotel where (name like "%'.$name1.'%" || name like "%'.$name2.'%") and sId='.$this->sId. ' AND HotelID='.$HotelID); if($stmt2->rowCount()){ $results = $stmt2->fetch(PDO::FETCH_OBJ); echo "

Name without hotel/l and same country & city

"; #Make sure we dont update a hotel that is allready set if($results->agodaHotelId>0 && $results->HotelID>0 && $this->agodaHotelId!=-2){ echo "DUPLICATE AGODA HOTEL 1
"; echo "SID: ".$this->sId.'
'; echo "HotelID: ".$results->HotelID.'
'; echo "AgodaHotel ID: ".$this->agodaHotelId.'
'; echo "Allready inserted ".$results->agodaHotelId.'
'; $this->SaveDupHotels($results->HotelID, $results->agodaHotelId); } else if($results->HotelID<0 && $this->HotelID>0){ $this->insertedAs="Same Name"; echo ">Check if Hotels Hotel SAME Name Matches: ".$this->insertedAs.'
'; echo "HOTELSID: ".$this->HotelID.'
'; $this->id=$results->id; $this->UpdateHotelID(); } else{ $this->insertedAs="Same Name"; echo "CheckIfHotelExistsByNameAndHotelID: ".$this->insertedAs.'
'; $this->HotelID=$results->HotelID; } return true; } else if(true){ echo 'SELECT HotelID, name, agodaHotelId FROM hotel where sId='.$this->sId. ' AND HotelID='.$HotelID.'
'; $stmt3 = $this->dbh->query('SELECT id,HotelID,name, agodaHotelId FROM hotel where sId='.$this->sId. ' AND HotelID='.$HotelID); if($stmt3->rowCount()){ $results2 = $stmt3->fetch(PDO::FETCH_OBJ); echo "

Check if Agoda Hotel Name Matches

"; $name1=trim(str_ireplace("hotell", "", $results2->name)); $name2=trim(str_ireplace("hotel", "", $results2->name)); #Set to Name if(strlen($this->agodaName)>3){ $compareWith=$this->agodaName; } else{ $compareWith=$this->name; } echo 'Compare: '.$compareWith.' NAME1: '.$name1. ' or Name2: '.$name2.'
'; similar_text(strtolower(trim(str_ireplace("hotell", "", $compareWith))), strtolower($name1), $sim); echo "SIM1: ".$sim.'
'; if($sim>80){ echo '$results2->HotelID'.$results2->HotelID.'
'; #Make sure we dont update a hotel that is allready set for Agoda if($results2->agodaHotelId>0 && $results2->HotelID>0 && $this->agodaHotelId!=-2){ echo "DUPLICATE AGODA HOTEL 1
"; echo "SID: ".$this->sId.'
'; echo "HotelID: ". $results2->HotelID.'
'; echo "AgodaHotel ID: ".$this->agodaHotelId.'
'; echo "Allready inserted ".$results2->agodaHotelId.'
'; #$this->SaveDupHotels($results->HotelID, $results2->agodaHotelId); } #We need to set HotelID to Hotels.com else if($results2->HotelID<0 && $this->HotelID>0){ $this->insertedAs="Percentage"; echo ">Check if Hotels Hotel Name Matches: ".$this->insertedAs.'
'; echo "HOTELSID: ".$this->HotelID.'
'; $this->id=$results2->id; $this->UpdateHotelID(); } else{ $this->insertedAs="Percentage"; echo ">Check if Agoda Hotel Name Matches: ".$this->insertedAs.'
'; $this->HotelID=$results2->HotelID; } echo $this->HotelID.'
'; return true; } similar_text(strtolower(trim(str_ireplace("hotel", "", $this->agodaName))), strtolower($name2), $sim); echo "SIM2: ".$sim.'
'; if($sim>80){ #Make sure we dont update a hotel that is allready set if($results2->agodaHotelId>0 && $results2->HotelID>0 && $this->agodaHotelId!=-2){ echo "DUPLICATE AGODA HOTEL 1
"; echo "SID: ".$this->sId.'
'; echo "HotelID: ". $results2->HotelID.'
'; echo "AgodaHotel ID: ".$this->agodaHotelId.'
'; echo "Allready inserted ".$results->agodaHotelId.'
'; $this->SaveDupHotels($results->HotelID, $results->agodaHotelId); } #We need to set HotelID to Hotels.com else if($results2->HotelID<0 && $this->HotelID>0){ $this->insertedAs="Percentage"; echo ">Check if Hotels Hotel Name Matches: ".$this->insertedAs.'
'; echo "HOTELSID: ".$this->HotelID.'
'; $this->id=$results2->id; $this->UpdateHotelID(); } else{ $this->insertedAs="Percentage"; echo ">Check if Agoda Hotel Name Matches: ".$this->insertedAs.'
'; $this->HotelID=$results2->HotelID; } return true; } } } else return false; } public function CheckHotelsCloseByLonLat($limit=1, $extraFilter=""){ echo ' SELECT HotelID, name, ( 6371 * acos( cos( radians( '.$this->latitude.' ) ) * cos( radians( hotel.latitude ) ) * cos( radians( hotel.longitude ) - radians( '.$this->longitude.' ) ) + sin( radians( '.$this->latitude.' ) ) * sin( radians( hotel.latitude ) ) ) *1000 ) AS distance FROM hotel where (HotelID!='.$this->HotelID.' || agodaHotelId!='.$this->agodaHotelId.' ) '.$extraFilter.' ORDER BY distance LIMIT '.$limit.'
'; $stmt = $this->dbh->query(' SELECT HotelID, name, ( 6371 * acos( cos( radians( -- latitude '.$this->latitude.' ) ) * cos( radians( hotel.latitude ) ) * cos( radians( hotel.longitude ) - radians( -- longitude '.$this->longitude.' ) ) + sin( radians( -- latitude '.$this->latitude.' ) ) * sin( radians( hotel.latitude ) ) ) *1000 ) AS distance -- table containing targets to compare distance FROM hotel where (HotelID!='.$this->HotelID.' || agodaHotelId!='.$this->agodaHotelId.' ) '.$extraFilter.' ORDER BY distance LIMIT '.$limit); if($stmt->rowCount()){ $results = $stmt->fetchAll(PDO::FETCH_OBJ); #print_r($results); return $results; exit; $distance=$results->distance; echo "

DISTANCE: ".$distance."

"; if($distance<200){ return true; } else{ echo "

No Hotel close to this Hotel

"; return false; } } else{ return false; } } public function SaveDupHotels($HotelID, $currentAgodaHotelId){ try { $in='INSERT into dupHotels set HotelID="'.$HotelID.'", agodaHotelId="'.$this->agodaHotelId.'", currentAgodaHotelId="'.$currentAgodaHotelId.'", createDate=NOW(), sId='.$this->sId; $stmt = $this->dbh->query($in); } catch (Exception $e) { echo "ERRROR CANT INSERT SaveDupHotels---!!!!
"; } #exit; } public function UpdateHotelID(){ $up='UPDATE hotel set HotelID='.$this->HotelID.' where id='.$this->id.' limit 1'; echo $up.'
'; try { $stmt = $this->dbh->query($up); } catch (Exception $e) { echo "ERRROR CANT UpdateHotelID ---!!!!
"; } } public function UpdateLastCheckedGoogleMapsHotelID(){ $up='UPDATE hotel set lastCheckedGoogleMaps=NOW() where HotelID='.$this->HotelID.' limit 10'; echo $up.'
'; try { $stmt = $this->dbh->query($up); } catch (Exception $e) { echo "ERRROR CANT UpdateLastCheckedGoogleMapsHotelID ---!!!!
"; } } public function UpdateLastCheckedGoogleMapsRatingHotelID(){ $up='UPDATE hotel set lastCheckedGoogleMapsRating=NOW() where HotelID='.$this->HotelID.' limit 10'; echo $up.'
'; try { $stmt = $this->dbh->query($up); } catch (Exception $e) { echo "ERRROR CANT UpdateLastCheckedGoogleMapsRatingHotelID ---!!!!
"; } } function SetArraysFromData($data, $name="") { if($name=="Amenity"){ foreach($data[$name] as $key=>$value){ $a=new Amenity(); $a->HotelId=$this->HotelID; $a->aName=$value['@attributes']['name']; $a->aCode=$value['@attributes']['id']; $a->aValue=$value['@attributes']['value']; $a->SaveAmenity(); $a->ConnectAmenityHotel(); } # print_r($a); #exit; } if($name=="Theme"){ foreach($data[$name] as $key=>$value){ $t=new Themes(); $t->HotelId=$this->HotelID; $t->tName=$value['@attributes']['name']; $t->tCode=$value['@attributes']['id']; $t->tValue=$value['@attributes']['value']; $t->SaveTheme(); $t->ConnectThemesHotel(); } } else if($name=="Neighbourhood"){ if(isset($data[$name])){ if(is_array($data[$name])){ foreach($data[$name] as $key=>$value){ $n=new Neighbourhood(); $n->HotelId=$this->HotelID; $n->nName=$value; $n->destinationId=$this->destinationId; $n->expediaRegionId=$this->expediaRegionId; $n->SaveNeighbourhood(); $n->ConnectNeighbourhoodHotel(); } } else if(strlen($data['Neighbourhood'])>2){ $n=new Neighbourhood(); $n->HotelId=$this->HotelID; $n->nName=$data['Neighbourhood'];; $n->destinationId=$this->destinationId; $n->expediaRegionId=$this->expediaRegionId; $n->SaveNeighbourhood(); #connect with Hotel $n->ConnectNeighbourhoodHotel(); } } } else if($name=="Region"){ if(isset($data[$name])){ if(is_array($data[$name])){ foreach($data[$name] as $key=>$value){ $r=new Region(); $r->rName=$value; $r->HotelId=$this->HotelID; $r->destinationId=$this->destinationId; $r->expediaRegionId=$this->expediaRegionId; $r->SaveRegion(); $r->ConnectRegionHotel(); # print_r($r); } } else if(strlen($data['Region'])>2){ $r=new Region(); $r->HotelId=$this->HotelID; $r->rName=$data['Region']; $r->destinationId=$this->destinationId; $r->expediaRegionId=$this->expediaRegionId; $r->SaveRegion(); $r->ConnectRegionHotel(); # print_r($r); } } } else if($name=="Airport"){ if(isset($data[$name])){ if(is_array($data[$name])){ foreach($data[$name] as $key=>$value){ $a=new Airport(); $a->HotelId=$this->HotelID; $a->code=$value; $a->SaveAirport(); $a->ConnectAirportHotel(); } } else if(strlen($data['Airport'])>2){ $a=new Airport(); $a->HotelId=$this->HotelID; $a->code=$data['Airport']; $a->SaveAirport(); $a->ConnectAirportHotel(); } } } } ########## public function GetHotelByHotelID($extra="",$setDisplay=false){ echo 'SELECT * FROM hotel where HotelID='.$this->HotelID.$extra.'
'; $stmt = $this->dbh->query('SELECT * FROM hotel where HotelID='.$this->HotelID.$extra); if($stmt->rowCount()){ $temp = $stmt->fetchAll(PDO::FETCH_CLASS, 'Hotel'); foreach ($temp[0] as $key => $value) { $this->$key = $value; } } } public function GetHotelById($extra="", $setDisplay=false){ $stmt = $this->dbh->query('SELECT * FROM hotel where id='.$this->id.$extra); if($stmt->rowCount()){ $temp = $stmt->fetchAll(PDO::FETCH_CLASS, 'Hotel'); foreach ($temp[0] as $key => $value) { $this->$key = $value; } } else{ return false; } if($setDisplay){ #set Url $h->displayUrl='hotell/'.FixUrl($this->citySe).'/'.FixUrl($this->name).'-'.$this->id.'.html'; $this->SetOffers(); $this->SetMainImageUrl(); $this->GetAmenitiesForHotel(); $this->GetRegionForHotel(); $this->GetNeighbourhoodForHotel(); $this->GetAirportForHotel(' ORDER by distanceMeter asc'); $this->GetPlaceOfInterestForHotel(); $this->GetTransitStationForHotel(); $this->SetPublicTransportForHotel(8); $this->SetPointOfInterestForHotel(8); $this->SetPlacePhotoForHotel(); $this->SetExtraImagesForHotel(); $this->review=new HotelReview(); $this->review->GetReviewByHotelID($this->HotelID); $this->SetAboutPoints(); $this->GetRatingsForHotelByHotelID(); $this->SetGoogleRating(); $this->SetTypeOfHotel(' and displayAs!=""'); $this->SetLowPriceAndURL(); $this->SetHotelsUrl(); $this->SetBookingComUrl(); $this->SetTrivagoBaseUrl(); } return true; } public function SetHotelsUrl(){ $this->url=str_replace("&zpar0=[[", "&zpar0=[[".$_SERVER['SERVER_NAME'], $this->url); } public function SetBookingComUrl(){ $this->bookingHotelUrl=preg_replace("/&label=.*/", "&label=".$_SERVER['SERVER_NAME'], $this->bookingHotelUrl); } public function SetLowPriceAndURL(){ if($this->HotelID>0){ $this->bestPrice=$this->price; $this->bestUrl='hotels/boka-hotell-'.$this->id; } else{ $this->bestPrice=$this->agodaRateLow; $this->bestUrl='agoda/boka-hotell-'.$this->id; } if($this->bestPrice>$this->price && $this->price>0){ $this->bestPrice=$this->price; $this->bestUrl='hotels/boka-hotell-'.$this->id; } if($this->bestPrice>$this->agodaRateLow && $this->agodaRateLow>0){ $this->bestPrice=$this->agodaRateLow; $this->bestUrl='agoda/boka-hotell-'.$this->id; } if($this->bestPrice>$this->bookingRateLow && $this->bookingRateLow>0){ $this->bestPrice=$this->bookingRateLow; $this->bestUrl='booking/boka-hotell-'.$this->id; } if($this->bestPrice==0){ $this->bestUrl='trivago/boka-hotell-'.$this->id; } } public function SetHotelAsOriginal(){ $stmt = $this->dbh->query('UPDATE hotel set isOriginal="YES" where HotelID="'.$this->HotelID.'" limit 5 '); } public function DeleteByHotelID($extraSQL=""){ echo 'DELETE from hotel where HotelID="'.$this->HotelID.'" '.$extraSQL.' limit 10 '; $stmt = $this->dbh->query('DELETE from hotel where HotelID="'.$this->HotelID.'" limit 10 '); } public function DeleteImagesByHotelID(){ echo 'DELETE from image where hId="'.$this->HotelID.'" limit 10'; $stmt = $this->dbh->query('DELETE from image where hId="'.$this->HotelID.'" limit 10'); } public function DeleteDupHotelsById($id){ $del='DELETE from dupHotels where id="'.$id.'" limit 1'; echo $del; $stmt = $this->dbh->query($del); } public function UpdateHotelWithAgodaInfo($originalHotelId){ echo 'UPDATE hotel set state="'.$this->state.'", chain="'.$this->chain.'", agodaName="'.$this->agodaName.'", agodaUrl="'.$this->agodaUrl.'", agodaRateLow="'.$this->agodaRateLow.'", agodaRateHigh="'.$this->agodaRateHigh.'", agodaText="'.$this->agodaText.'", agodaHotelId="'.$this->agodaHotelId.'", agodaReviewScore="'.$this->agodaReviewScore.'", agodaNumberReviews="'.$this->agodaNumberReviews.'", agodaLastUpdatedDate="'.$this->agodaLastUpdatedDate.'" where HotelID="'.$originalHotelId.'" limit 10
'; $stmt = $this->dbh->query('UPDATE hotel set state="'.$this->state.'", chain="'.$this->chain.'", agodaName="'.$this->agodaName.'", agodaUrl="'.$this->agodaUrl.'", agodaRateLow="'.$this->agodaRateLow.'", agodaRateHigh="'.$this->agodaRateHigh.'", agodaText="'.$this->agodaText.'", agodaHotelId="'.$this->agodaHotelId.'", agodaReviewScore="'.$this->agodaReviewScore.'", agodaNumberReviews="'.$this->agodaNumberReviews.'", agodaLastUpdatedDate="'.$this->agodaLastUpdatedDate.'" where HotelID="'.$originalHotelId.'" limit 10'); } public function SetCheckLaterHotel(){ $stmt = $this->dbh->query('Update hotel set isOriginal="C" where HotelId='.$this->HotelID.' limit 10'); } /* * Presentation Hotel * */ public function GetAmenitiesForHotel($sql='and aValue="yes"'){ $stmt = $this->dbh->query(' SELECT a.* FROM amenityHotel ah INNER JOIN amenity a ON ah.aId = a.id WHERE `HotelId` ='.$this->HotelID.' '.$sql); if($stmt->rowCount()){ $this->amenities= $stmt->fetchALL(PDO::FETCH_CLASS, 'Amenity'); } } public function GetPlaceOfInterestForHotel($sql=''){ $q=' SELECT poi . * , pp . * FROM placeOfInterest poi INNER JOIN placeOfInterestHotel poih ON poi.id = poih.poiId INNER JOIN placePhoto pp ON pp.place_id = poi.place_id WHERE `HotelId` ='.$this->HotelID.' '.$sql.' GROUP BY poi.id'; #echo "
$q
"; $stmt = $this->dbh->query($q); if($stmt->rowCount()){ $this->placeOfInterest= $stmt->fetchALL(PDO::FETCH_CLASS, 'PlaceOfInterest'); # foreach($this->placeOfInterest as $poi){ #$poi->GetPlaceType(); #$poi->GetPlacePhoto(); # } } } public function GetTransitStationForHotel($sql=' order by distanceMeter asc'){ $q='SELECT ts . * , tsh.distanceText, tsh.HotelID, tsh.walkingTimeSeconds, tsh.walkingTimeText, GROUP_CONCAT( pt.name SEPARATOR "," ) transitTypes FROM transitStation ts INNER JOIN transitStationHotel tsh ON ts.id = tsh.tId INNER JOIN transitStationType tst ON tst.tsId = ts.id INNER JOIN placeType pt ON pt.id = tst.tId WHERE `HotelId` ='.$this->HotelID.' AND display = "true" group by ts.id '.$sql; # echo '

'.$q.'

'; $stmt = $this->dbh->query($q); if($stmt->rowCount()){ $this->transitStation= $stmt->fetchALL(PDO::FETCH_CLASS, 'TransitStation'); } } public function GetPlaceTypesTransitStation($sql=' where pt.id>49 '){ $q='Select pt.* from placeType pt inner join transitStationType tst on pt.id=tst.tId '.$sql; $stmt = $this->dbh->query($q); echo $q.'
'; if($stmt->rowCount()){ $results = $stmt->fetchAll(PDO::FETCH_OBJ); foreach($results as $r){ $this->placeType[]=$r; } } } public function SetPointOfInterestForHotel($limit){ $familyLimit=$limit; $nightLimit=$limit; $entertainmentLimit=$limit; $religonLimit=$limit; $museumLimit=$limit; $shopLimit=$limit; $foodLimit=$limit; $healthLimit=$limit; $duplicate=false; $q='SELECT poi. * , pt.group FROM placeOfInterest poi INNER JOIN placeOfInterestHotel poih ON poi.id = poih.poiId INNER JOIN placeTypePlaceOfInterest ptpoi ON ptpoi.poiId = poi.id INNER JOIN placeType pt ON ptpoi.ptId = pt.id WHERE `HotelId` ='.$this->HotelID.' AND `group` != ""'; #echo $q; $stmt = $this->dbh->query($q); if($stmt->rowCount()){ $results = $stmt->fetchALL(PDO::FETCH_CLASS, 'PlaceOfInterest'); #print_r($results); $dupCheck=array(); foreach($results as $poi){ #avoid Duplicates if(in_array($poi->id, $dupCheck)){ continue; } $dupCheck[]=$poi->id; if($familyLimit>0 && $poi->group=="Familj"){ $poi->typeText=$poi->group; $this->topPlaceOfInterest['family'][]=$poi; $familyLimit--; } if($nightLimit>0 && $poi->group=="Uteliv & Nattklubb"){ $poi->typeText=$poi->group; $this->topPlaceOfInterest['nightLife'][]=$poi; $nightLimit--; } if($entertainmentLimit>0 && $poi->group=="Underhållning"){ $poi->typeText=$poi->group; $this->topPlaceOfInterest['enter'][]=$poi; $entertainmentLimit--; } if($religonLimit>0 && $poi->group=="Religion & Kyrkor"){ $poi->typeText=$poi->group; $this->topPlaceOfInterest['religon'][]=$poi; $religonLimit--; } if($museumLimit>0 && $poi->group=="Museum, konst & kultur"){ $poi->typeText=$poi->group; $this->topPlaceOfInterest['museum'][]=$poi; $museumLimit--; } if($shopLimit>0 && $poi->group=="Shopping"){ $poi->typeText=$poi->group; $this->topPlaceOfInterest['shop'][]=$poi; $shopLimit--; } if($foodLimit>0 && $poi->group=="Restaurang & Mat"){ $poi->typeText=$poi->group; $this->topPlaceOfInterest['food'][]=$poi; $foodLimit--; } if($healthLimit>0 && $poi->group=="Träning"){ $poi->typeText=$poi->group; $this->topPlaceOfInterest['health'][]=$poi; $healthLimit--; } } } /* $familyLimit=$limit; $nightLimit=$limit; $entertainmentLimit=$limit; $religonLimit=$limit; $museumLimit=$limit; $shopLimit=$limit; $foodLimit=$limit; $healthLimit=$limit; $duplicate=false; foreach($this->placeOfInterest as $poi){ $duplicate=false; foreach($poi->placeType as $key=>$pt){ #check if placeOfInterest allready in array if(!empty($this->topPlaceOfInterest)){ foreach($this->topPlaceOfInterest as $poiCheck){ foreach($poiCheck as $poiCheck2){ if($poi->name==$poiCheck2->name){ $duplicate=true; } } } } if($duplicate){ continue; } if($familyLimit>0 && $pt->group=="Familj"){ $poi->SetAllTypeText(); $this->topPlaceOfInterest['family'][]=$poi; $familyLimit--; echo "TOP PLACE OF INTEREST
"; print_r($this->topPlaceOfInterest['family']); exit; } if($nightLimit>0 && $pt->group=="Uteliv & Nattklubb"){ $poi->SetAllTypeText(); $this->topPlaceOfInterest['nightLife'][]=$poi; $nightLimit--; } if($entertainmentLimit>0 && $pt->group=="Underhållning"){ $poi->SetAllTypeText(); $this->topPlaceOfInterest['enter'][]=$poi; $entertainmentLimit--; } if($religonLimit>0 && $pt->group=="Religion & Kyrkor"){ $poi->SetAllTypeText(); $this->topPlaceOfInterest['religon'][]=$poi; $religonLimit--; } if($museumLimit>0 && $pt->group=="Museum, konst & kultur"){ $poi->SetAllTypeText(); $this->topPlaceOfInterest['museum'][]=$poi; $museumLimit--; } if($shopLimit>0 && $pt->group=="Shopping"){ $poi->SetAllTypeText(); $this->topPlaceOfInterest['shop'][]=$poi; $shopLimit--; } if($foodLimit>0 && $pt->group=="Restaurang & Mat"){ $poi->SetAllTypeText(); $this->topPlaceOfInterest['food'][]=$poi; $foodLimit--; } if($healthLimit>0 && $pt->group=="Träning"){ $poi->SetAllTypeText(); $this->topPlaceOfInterest['health'][]=$poi; $healthLimit--; } } } echo "\n\n"; #print_r($this->topPlaceOfInterest); */ } public function SetPublicTransportForHotel($limit){ $airportLimit=$limit; $subwayLimit=$limit; $lightRailLimit=$limit; $trainLimit=$limit; $busLimit=$limit; foreach($this->transitStation as $ts){ if($airportLimit>0 && stristr($ts->transitTypes,"airport")){ $this->publicTransport['airport'][]=$ts; $airportLimit--; } if($subwayLimit>0 && stristr($ts->transitTypes,"subway_station")){ $this->publicTransport['subway'][]=$ts; $subwayLimit--; } if($lightRailLimit>0 && stristr($ts->transitTypes,"light_rail_station")){ $this->publicTransport['lightRail'][]=$ts; $lightRailLimit--; } if($trainLimit>0 && stristr($ts->transitTypes,"train_station")){ $this->publicTransport['train'][]=$ts; $trainLimit--; } if($busLimit>0 && stristr($ts->transitTypes,"bus_station")){ $this->publicTransport['bus'][]=$ts; $busLimit--; } } } public function GetRegionForHotel($sql=''){ $stmt = $this->dbh->query(' SELECT * FROM regionHotel rh INNER JOIN region r ON rh.rId = r.id WHERE `HotelId` ='.$this->HotelID.' '.$sql); if($stmt->rowCount()){ $this->region= $stmt->fetchALL(PDO::FETCH_CLASS, 'Region'); } } public function GetNeighbourhoodForHotel($sql=''){ $q=' SELECT * FROM neighbourhoodHotel nh INNER JOIN neighbourhood n ON nh.nId = n.id WHERE `HotelId` ='.$this->HotelID.' '.$sql; $stmt = $this->dbh->query($q); if($stmt->rowCount()){ $this->neighbourhood= $stmt->fetchALL(PDO::FETCH_CLASS, 'Neighbourhood'); } } public function GetAirportForHotel($sql=''){ $stmt = $this->dbh->query(' SELECT * FROM airportHotel ah INNER JOIN airport a ON ah.aId = a.id WHERE `HotelId` ='.$this->HotelID.' '.$sql); if($stmt->rowCount()){ $this->airports= $stmt->fetchALL(PDO::FETCH_CLASS, 'Airport'); } } public function GetRatingsForHotelByHotelID($sql=''){ $stmt = $this->dbh->query(' SELECT * FROM hotelRating WHERE `HotelId` ='.$this->HotelID.' '.$sql); if($stmt->rowCount()){ $this->ratings= $stmt->fetchALL(PDO::FETCH_CLASS, 'HotelRating'); #print_r($this->ratings); #$avg $sum = 0; foreach($this->ratings as $key=>$r){ if(isset($r->rating)) $sum += $r->rating; } } } } class Neighbourhood{ public $id; public $nName; public $createDate; public $destinationId; public $expediaRegionId; public $HotelId; public $dbh; public function __construct(){ global $dbh; $this->dbh = $dbh; } public function SaveNeighbourhood(){ # print_r($this); if($this->CheckIfNeighbourhoodExists()){ #echo $this->nName." Duplicate ".$this->id."
"; } else{ try { $stmt = $this->dbh->query('INSERT into neighbourhood set nName="'.$this->nName.'", destinationId="'.$this->destinationId.'", expediaRegionId="'.$this->expediaRegionId.'", createDate=NOW()'); $this->id=$this->dbh->lastInsertId(); } catch (Exception $e) { echo "ERRROR CANT INSERT SaveNeighbourhood---!!!!
"; exit; } } return $this->id; } public function CheckIfNeighbourhoodExists(){ $stmt = $this->dbh->query('SELECT * FROM neighbourhood where nName like "'.$this->nName.'" and destinationId="'.$this->destinationId.'" and expediaRegionId="'.$this->expediaRegionId.'"'); if($stmt->rowCount()){ $results = $stmt->fetch(PDO::FETCH_OBJ); $this->id=$results->id; return $this->id; } else{ return false; } } public function ConnectNeighbourhoodHotel(){ $stmt = $this->dbh->query('SELECT * FROM neighbourhoodHotel where nId='.$this->id.' and HotelId='.$this->HotelId); if(!$stmt->rowCount()){ $stmt = $this->dbh->query('INSERT into neighbourhoodHotel set nId='.$this->id.', HotelId='.$this->HotelId); } } } class Region{ public $id; public $rName; public $destinationId; public $expediaRegionId; public $createDate; public $HotelId; public $dbh; public function __construct(){ global $dbh; $this->dbh = $dbh; } public function SaveRegion(){ if($this->CheckIfRegionExists()){ #echo $this->rName." Duplicate ".$this->id."
"; } else{ try { $stmt = $this->dbh->query('INSERT into region set rName="'.$this->rName.'", destinationId="'.$this->destinationId.'", expediaRegionId="'.$this->expediaRegionId.'", createDate=NOW()'); $this->id=$this->dbh->lastInsertId(); } catch (Exception $e) { echo "ERRROR CANT INSERT--- SaveRegion !!!!
"; echo $in.'
'; exit; } } return $this->id; } public function CheckIfRegionExists(){ $stmt = $this->dbh->query('SELECT * FROM region where rName="'.$this->rName.'" and destinationId="'.$this->destinationId.'" and expediaRegionId="'.$this->expediaRegionId.'"'); if($stmt->rowCount()){ $results = $stmt->fetch(PDO::FETCH_OBJ); $this->id=$results->id; return $this->id; } else{ return false; } } public function ConnectRegionHotel(){ $stmt = $this->dbh->query('SELECT * FROM regionHotel where rId='.$this->id.' and HotelId='.$this->HotelId); if(!$stmt->rowCount()){ $stmt = $this->dbh->query('INSERT into regionHotel set rId='.$this->id.', HotelId='.$this->HotelId); } } } class Airport{ public $id; public $code; public $createDate; public $country; public $aName; public $icao; public $long; public $lat; public $HotelId; public $distance; public $text; public $dbh; public $google_lat; public $google_lon; public $google_name; public $place_id; public $rating; public $address; public $html_attributions; public $photo_reference; public $height; public $width; public $photoImage; public function __construct(){ global $dbh; $this->dbh = $dbh; } public function SaveAirport(){ if($this->CheckIfAirportExists()){ echo $this->code." Duplicate ".$this->id."
"; } else{ try { $stmt = $this->dbh->query('INSERT into airport set code="'.$this->code.'", createDate=NOW()'); $this->id=$this->dbh->lastInsertId(); } catch (Exception $e) { echo "ERRROR CANT INSERT-- SaveAirport-!!!!
"; echo $in.'
'; exit; } } return $this->id; } public function DMS2Decimal($degrees = 0, $minutes = 0, $seconds = 0, $direction = 'n') { //converts DMS coordinates to decimal //returns false on bad inputs, decimal on success //direction must be n, s, e or w, case-insensitive $d = strtolower($direction); $ok = array('n', 's', 'e', 'w'); //degrees must be integer between 0 and 180 if(!is_numeric($degrees) || $degrees < 0 || $degrees > 180) { $decimal = false; } //minutes must be integer or float between 0 and 59 elseif(!is_numeric($minutes) || $minutes < 0 || $minutes > 59) { $decimal = false; } //seconds must be integer or float between 0 and 59 elseif(!is_numeric($seconds) || $seconds < 0 || $seconds > 59) { $decimal = false; } elseif(!in_array($d, $ok)) { $decimal = false; } else { //inputs clean, calculate $decimal = $degrees + ($minutes / 60) + ($seconds / 3600); //reverse for south or west coordinates; north is assumed if($d == 's' || $d == 'w') { $decimal *= -1; } } return $decimal; } public function ConnectToAirportGoogleMaps($radius=10000, $type="airport"){ $url='https://maps.googleapis.com/maps/api/place/nearbysearch/json?location='.$this->lat.','.$this->long.'&radius='.$radius.'&keyword='.urlencode($this->aName).'&lang=sv&type='.$type.'&key=AIzaSyBiElx6oQ5jxpZUyOXiVdivBcwxV_gdgA0'; echo $url.'
'; $run=true; $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $res = curl_exec($ch); curl_close($ch); $data = json_decode($res, true); echo "\n\n

PRINT DATA:::

\n\n"; #print_r($res); print_r($data); if(count($data['results'])<1){ echo "
\nNO RESULTS
"; echo $url."
\n"; echo "NUMBER: ".count($data['results']); exit; $run=false; } else{ foreach($data['results'] as $result){ echo $result['vicinity'].'
'; print_r($result); $this->google_lat = $result['geometry']['location']['lat']; $this->google_lon = $result['geometry']['location']['lng']; $this->google_name = addslashes($result['name']); $this->address=addslashes($result['vicinity']); $this->place_id=$result['place_id']; if(isset($result['rating'])){ $this->rating=$result['rating']; } #save or set id for PlaceOfInterest #$this->SavePlaceOfInterest(); #Save PhotoPlace if(isset($result['photos'])){ foreach($result['photos'] as $rows){ print_r($rows); echo $rows['photo_reference'].'
'; $this->photo_reference=$rows['photo_reference']; $this->height=$rows['height']; $this->html_attributions=addslashes($rows['html_attributions'][0]); $this->width=$rows['width']; $this->place_id=$this->place_id; $urlPhoto='https://maps.googleapis.com/maps/api/place/photo?maxwidth=800&photoreference='.$this->photo_reference.'&key=AIzaSyBiElx6oQ5jxpZUyOXiVdivBcwxV_gdgA0'; echo $urlPhoto.'
'; $this->photoImage=$this->GetRedirectUrl($urlPhoto); if($this->photoImage){ } } } #Update airport with Google Goodies $this->UpdateAirportWithGooglePlaces(); print_r($this); } } } public function UpdateAirportWithGooglePlaces(){ $up='Update airport set google_lat="'.$this->google_lat.'", google_lon="'.$this->google_lon.'", google_name="'.$this->google_name.'", place_id="'.$this->place_id.'", rating="'.$this->rating.'", address="'.$this->address.'", html_attributions="'.$this->html_attributions.'", photo_reference="'.$this->photo_reference.'", height="'.$this->height.'", width="'.$this->width.'", photoImage="'.$this->photoImage.'" where id ='.$this->id; echo $up; #exit; $stmt = $this->dbh->query($up); } public function GetRedirectUrl ($url) { stream_context_set_default(array( 'http' => array( 'method' => 'HEAD' ) )); $headers = get_headers($url, 1); if ($headers !== false && isset($headers['Location'])) { return $headers['Location']; } return false; } public function UpdateAirport(){ $stmt = $this->dbh->query('UPDATE airport set country="'.$this->country.'", aName="'.$this->aName.'", icao="'.$this->icao.'", `long`="'.$this->long.'", `lat`="'.$this->lat.'" where code="'.$this->code.'"'); } public function CheckIfAirportExists(){ $stmt = $this->dbh->query('SELECT * FROM airport where code="'.$this->code.'"'); if($stmt->rowCount()){ $results = $stmt->fetch(PDO::FETCH_OBJ); $this->id=$results->id; return $this->id; } else{ return false; } } public function ConnectAirportHotel(){ $stmt = $this->dbh->query('SELECT * FROM airportHotel where aId='.$this->id.' and HotelId='.$this->HotelId); if(!$stmt->rowCount()){ echo 'INSERT into airportHotel set aId='.$this->id.', HotelId='.$this->HotelId; $stmt = $this->dbh->query('INSERT into airportHotel set aId='.$this->id.', HotelId='.$this->HotelId); } } } class Amenity{ public $id; public $aCode; public $aName; public $aValue; public $HotelId; public $createDate; public $icon; public $dbh; public function __construct(){ global $dbh; $this->dbh = $dbh; } public function GetAmenityById(){ $stmt = $this->dbh->query('SELECT * FROM amenity where id='.$this->id); if($stmt->rowCount()){ $temp = $stmt->fetchAll(PDO::FETCH_CLASS, 'Amenity'); foreach ($temp[0] as $key => $value) { $this->$key = $value; } } else{ return false; } } public function SaveAmenity(){ if($this->CheckIfAmenityExists()){ #echo $this->aName." Duplicate ".$this->id."
"; } else{ try { $stmt = $this->dbh->query('INSERT into amenity set aCode="'.$this->aCode.'", aName="'.$this->aName.'", createDate=NOW()'); $this->id=$this->dbh->lastInsertId(); } catch (Exception $e) { echo "ERRROR CANT INSERT--- SaveAmenity !!!!
"; echo $in.'
'; exit; } } return $this->id; } public function CheckIfAmenityExists(){ # echo 'SELECT * FROM amenity where aCode="'.$this->aCode.'"'; $stmt = $this->dbh->query('SELECT * FROM amenity where aCode="'.$this->aCode.'"'); if($stmt->rowCount()){ $results = $stmt->fetch(PDO::FETCH_OBJ); $this->id=$results->id; return $this->id; } else{ return false; } } public function ConnectAmenityHotel(){ if($this->aValue=="YES"){ $in='INSERT INTO amenityHotel set aId='.$this->id.', aValue="'.$this->aValue.'", HotelId='.$this->HotelId.' ON DUPLICATE KEY UPDATE aId='.$this->id.', HotelId='.$this->HotelId; # echo $in; $stmt = $this->dbh->query($in); } /* exit; echo $in; echo 'SELECT * FROM amenityHotel where aId='.$this->id.' and HotelId='.$this->HotelId.'
'; $stmt = $this->dbh->query('SELECT * FROM amenityHotel where aId='.$this->id.' and HotelId='.$this->HotelId); echo 'INSERT into amenityHotel set aId='.$this->id.', aValue="'.$this->aValue.'", HotelId='.$this->HotelId.'
'; if(!$stmt->rowCount()){ $stmt = $this->dbh->query('INSERT into amenityHotel set aId='.$this->id.', aValue="'.$this->aValue.'", HotelId='.$this->HotelId); } * */ } } class Themes{ public $id; public $tCode; public $tName; public $tValue; public $HotelId; public $createDate; public $dbh; public function __construct(){ global $dbh; $this->dbh = $dbh; } public function SaveTheme(){ if($this->CheckIfThemeExists()){ #echo $this->tName." Duplicate ".$this->id."
"; } else{ try { $stmt = $this->dbh->query('INSERT into themes set tCode="'.$this->tCode.'", tName="'.$this->tName.'", createDate=NOW()'); $this->id=$this->dbh->lastInsertId(); } catch (Exception $e) { echo "ERRROR CANT INSERT--- SaveTheme !!!!
"; echo $in.'
'; exit; } } return $this->id; } public function CheckIfThemeExists(){ $stmt = $this->dbh->query('SELECT * FROM themes where tCode="'.$this->tCode.'"'); if($stmt->rowCount()){ $results = $stmt->fetch(PDO::FETCH_OBJ); $this->id=$results->id; return $this->id; } else{ return false; } } public function ConnectThemesHotel(){ if($this->tValue=="YES"){ $stmt = $this->dbh->query('SELECT * FROM themesHotel where tId='.$this->id.' and HotelId='.$this->HotelId); if(!$stmt->rowCount()){ $stmt = $this->dbh->query('INSERT into themesHotel set tId='.$this->id.', tValue="'.$this->tValue.'", HotelId='.$this->HotelId); } } } } class Image{ public $id; public $imageUrl; public $createDate; public $hId; public $dbh; public function __construct(){ global $dbh; $this->dbh = $dbh; } public function SaveImage(){ if($this->CheckIfImageExist()){ echo $this->imageUrl." Duplicate ".$this->id."
"; } else if(strlen($this->imageUrl)<10){ } else{ try { $stmt = $this->dbh->query('INSERT into image set imageUrl="'.$this->imageUrl.'", hId='.$this->hId.', createDate=NOW()'); $this->id=$this->dbh->lastInsertId(); } catch (Exception $e) { echo "ERRROR CANT INSERT SaveImage---!!!!
"; exit; } } return $this->id; } public function CheckIfImageExist(){ $stmt = $this->dbh->query('SELECT * FROM image where imageUrl="'.$this->imageUrl.'" and hId='.$this->hId); if($stmt->rowCount()){ $results = $stmt->fetch(PDO::FETCH_OBJ); $this->id=$results->id; return $this->id; } else{ return false; } } } class HotelReview{ public $id; public $name; public $city; public $address; public $zip; public $postal_town; public $county; public $country; public $phone; public $website; public $neighbourhood; public $nId; public $lat; public $lon; public $photo; public $price_level=0; public $openHours; public $place_id; public $rating=0; public $HotelID; public $displayUrl; public function __construct(){ global $dbh; $this->dbh = $dbh; } public function GetHotelReviewById(){ # echo 'SELECT * FROM placeType where id='.$this->id; $stmt = $this->dbh->query('SELECT * FROM hotelReview where id='.$this->id); if($stmt->rowCount()){ $temp = $stmt->fetchAll(PDO::FETCH_CLASS, 'HotelReview'); foreach ($temp[0] as $key => $value) { $this->$key = $value; } } else{ return false; } } public function GetReviewFromGoogleMaps($lat, $lon, $keyword, $radius=100, $type="lodging"){ $url='https://maps.googleapis.com/maps/api/place/nearbysearch/json?location='.$lat.','.$lon.'&radius='.$radius.'&keyword='.urlencode($keyword).'&type='.$type.'&language=sv&key=AIzaSyBiElx6oQ5jxpZUyOXiVdivBcwxV_gdgA0'; echo $url.'

'; $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $res = curl_exec($ch); curl_close($ch); $data = json_decode($res, true); print_r($data); echo "NR: ".count($data['results']).'
'; if($data['status']=="ZERO_RESULTS"){ echo "NO RESULTS"; echo "NUMBER: ".count($data['results']); } else{ $this->lat = $data['results'][0]['geometry']['location']['lat']; $this->lon = $data['results'][0]['geometry']['location']['lng']; $this->name = addslashes($data['results'][0]['name']); $this->address=$data['results'][0]['vicinity']; $this->place_id=$data['results'][0]['place_id']; if(isset($data['results'][0]['rating'])){ $this->rating=$data['results'][0]['rating']; } if(isset($data['results'][0]['price_level'])){ $this->price_level=$data['results'][0]['price_level']; } $this->GetPlaceInfoFromGoogleMaps(); #print_r($this); } } public function GetPlaceInfoFromGoogleMaps(){ $url='https://maps.googleapis.com/maps/api/place/details/json?placeid='.$this->place_id.'&key=AIzaSyBiElx6oQ5jxpZUyOXiVdivBcwxV_gdgA0&language=sv'; echo "UR GetPlaceInfoFromGoogleMapsL: ".$url.'
'; $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $res = curl_exec($ch); curl_close($ch); $data = json_decode($res, true); if(count($data)<1){ //Sss } #Save PhotoPlace if(isset($data['result']['photos'])){ foreach($data['result']['photos'] as $rows){ $photo=new PlacePhoto(); $photo->photo_reference=$rows['photo_reference']; $photo->height=$rows['height']; $photo->html_attributions=addslashes($rows['html_attributions'][0]); $photo->width=$rows['width']; $photo->place_id=$this->place_id; #print_r($photo); $urlPhoto='https://maps.googleapis.com/maps/api/place/photo?maxwidth=800&photoreference='.$photo->photo_reference.'&key=AIzaSyBiElx6oQ5jxpZUyOXiVdivBcwxV_gdgA0'; echo $urlPhoto.'
'; $photo->imageUrl=$photo->GetRedirectUrl($urlPhoto); echo "

Photo URL: ".$photo->imageUrl.'

'; if($photo->imageUrl){ $photo->SavePlacePhoto(); # $photo->ConnectPlacePhotoPlaceOfInterest($this->id); } } } #set Geo if(isset($data['result']['address_components'])){ foreach($data['result']['address_components'] as $row){ print_r($row); if($row['types'][0]=="locality"){ $this->city=$row['long_name']; } if($row['types'][0]=="postal_town"){ $this->postal_town=$row['long_name']; } if($row['types'][0]=="sublocality_level_1"){ $this->neighbourhood=$row['long_name']; } if($row['types'][0]=="administrative_area_level_1"){ $this->county=$row['long_name']; } if($row['types'][0]=="country"){ $this->country=$row['long_name']; } if($row['types'][0]=="postal_code"){ $this->zip=$row['long_name']; } } } #save Ratings if(isset($data['result']['reviews'])){ foreach($data['result']['reviews'] as $row){ $hotelRating=new HotelRating(); $hotelRating->HotelID=$this->HotelID; echo $row['author_name'].'
'; $hotelRating->author=$row['author_name']; if(isset($row['author_url'])){ $hotelRating->author_url=$row['author_url']; } if(isset($row['profile_photo_url'])){ $hotelRating->profile_photo_url='http:'.$row['profile_photo_url']; } $hotelRating->language=$row['language']; $hotelRating->comment=addslashes($row['text']); $hotelRating->dateTime=$row['time']; $dt = new DateTime("@".$hotelRating->dateTime, new DateTimeZone('Europe/Stockholm')); $hotelRating->dateTime=$dt->format('Y-m-d H:i:s'); $hotelRating->rating=$row['rating']; $hotelRating->place_id=$this->place_id; $hotelRating->SaveHotelRating(); } } #Save placeTypeHotel $placeType=new PlaceType(); $placeType->HotelID=$this->HotelID; foreach($data['result']['types'] as $row){ $placeType->name=$row; #Save placeType if needed $stmt = $this->dbh->query('SELECT * from placeType where name like "'.$placeType->name.'"'); if(!$stmt->rowCount()){ $placeType->SavePlaceType(); } else{ $results = $stmt->fetch(PDO::FETCH_OBJ); $placeType->id=$results->id; } #connect placeType & Hotel if needed echo 'SELECT * from placeTypeHotel where ptId='.$placeType->id.' AND HotelID='.$placeType->HotelID; $stmt = $this->dbh->query('SELECT * from placeTypeHotel where ptId='.$placeType->id.' AND HotelID='.$placeType->HotelID); if(!$stmt->rowCount()){ $placeType->ConnectPlaceTypeHotel(); } } echo "DEBUG3"; print_r($this); $this->phone=$data['result']['formatted_phone_number']; $this->website=$data['result']['website']; #Save HotelReview #Save right name for stadsdel if($this->sId==42){ if($this->neighbourhood=="Norrmalm"){ $this->neighbourhood="Norrmalm-Vasastan"; } if($this->neighbourhood=="Södermalm"){ $this->neighbourhood="Södermalm-Gamla Stan"; } if(stristr($this->neighbourhood, "Strängnäs")){ $this->neighbourhood="Strängnäs"; } if(stristr($this->neighbourhood, "Märsta")){ $this->neighbourhood="Märsta"; } if(stristr($this->neighbourhood, "södertälje")){ $this->neighbourhood="Södertälje"; } if(stristr($this->neighbourhood, "nynäshamn")){ $this->neighbourhood="Nynäshamn"; } if(stristr($this->neighbourhood, "Upplands väsby")){ $this->neighbourhood="Upplands Väsby"; } if(stristr($this->neighbourhood, "Flen")){ $this->neighbourhood="Flen"; } if(stristr($this->neighbourhood, "Norrtälje")){ $this->neighbourhood="Norrtälje"; } if(stristr($this->neighbourhood, "Mosebacke-storste")){ $this->neighbourhood="Norrtälje"; } if(stristr($this->neighbourhood, "Skarpnäcks gård")){ $this->neighbourhood="Farsta"; } if(stristr($this->neighbourhood, "Värmdö")){ $this->neighbourhood="Värmdö"; } if(stristr($this->neighbourhood, "Nacka")){ $this->neighbourhood="Nacka"; } if(stristr($this->neighbourhood, "Jakobsberg")){ $this->neighbourhood="Jakobsberg"; } if(stristr($this->neighbourhood, "Haninge C")){ $this->neighbourhood="Haninge"; } if(stristr($this->neighbourhood, "Gnesta")){ $this->neighbourhood="Gnesta"; } if(stristr($this->neighbourhood, "Sigtuna")){ $this->neighbourhood="Arlanda"; } } $stmt = $this->dbh->query('SELECT * from hotelReview where place_id="'.$this->place_id.'"'); if(strlen($this->name)>2){ if(!$stmt->rowCount()){ echo "

Save HOTEL

"; $this->SaveHotelReview(); } else{ print_r($this); $results = $stmt->fetch(PDO::FETCH_OBJ); echo "

UPDATE

"; $this->id=$results->id; $this->UpdateHotelReview(); } } } public function SaveHotelReview(){ $in= 'Insert into hotelReview set name="'.$this->name.'", address="'.$this->address.'", zip="'.$this->zip.'", postal_town="'.$this->postal_town.'", county="'.$this->county.'", country="'.$this->country.'", phone="'.$this->phone.'", website="'.$this->website.'", neighbourhood="'.$this->neighbourhood.'", nId="'.$this->nId.'", lat="'.$this->lat.'", lon="'.$this->lon.'", photo="'.$this->photo.'", openHours="'.$this->openHours.'", price_level="'.$this->price_level.'", rating='.$this->rating.', HotelID='.$this->HotelID.', place_id="'.$this->place_id.'", createDate=NOW(), lastUpdatedDate=NOW()'; echo $in; $stmt = $this->dbh->query($in); } public function UpdateHotelReview(){ $up= 'Update hotelReview set name="'.$this->name.'", address="'.$this->address.'", zip="'.$this->zip.'", postal_town="'.$this->postal_town.'", county="'.$this->county.'", phone="'.$this->phone.'", website="'.$this->website.'", neighbourhood="'.$this->neighbourhood.'", nId="'.$this->nId.'", lat="'.$this->lat.'", lon="'.$this->lon.'", photo="'.$this->photo.'", openHours="'.$this->openHours.'", price_level="'.$this->price_level.'", rating='.$this->rating.', HotelID='.$this->HotelID.', lastUpdatedDate=NOW() where id='.$this->id; echo $up; $stmt = $this->dbh->query($up); } public function GetReviewByHotelID($HotelID,$extra=""){ $this->HotelID=$HotelID; $stmt = $this->dbh->query('SELECT * FROM hotelReview where HotelID='.$this->HotelID.$extra); if($stmt->rowCount()){ $temp = $stmt->fetchAll(PDO::FETCH_CLASS, 'HotelReview'); foreach ($temp[0] as $key => $value) { $this->$key = $value; } } } } class HotelRating{ public $id; public $rating=0; public $comment; public $author; public $profile_photo_url="images/avatar.png"; public $dateTime; public $language; public $HotelID; public $place_id; public $author_url; public function __construct(){ global $dbh; $this->dbh = $dbh; } public function SaveHotelRating(){ $stmt = $this->dbh->query('SELECT * from hotelRating where HotelID='.$this->HotelID.' and author="'.$this->author.'" and rating='.$this->rating); if(!$stmt->rowCount()){ $in='Insert into hotelRating set rating='.$this->rating.', comment="'.$this->comment.'", author="'.$this->author.'", profile_photo_url="'.$this->profile_photo_url.'", dateTime="'.$this->dateTime.'", language="'.$this->language.'", HotelID='.$this->HotelID.', place_id="'.$this->place_id.'", author_url="'.$this->author_url.'"'; echo $in.'
'; $stmt = $this->dbh->query($in); } } } class PlaceType{ public $id; public $name; public $displayAs; public $nr; public $HotelID; public function __construct(){ global $dbh; $this->dbh = $dbh; } public function GetPlaceTypeById(){ $stmt = $this->dbh->query('SELECT * FROM placeType where id='.$this->id); if($stmt->rowCount()){ $temp = $stmt->fetchAll(PDO::FETCH_CLASS, 'placeType'); foreach ($temp[0] as $key => $value) { $this->$key = $value; } } else{ return false; } } public function SavePlaceType(){ echo 'Insert into placeType set name="'.$this->name.'"'; $stmt = $this->dbh->query('Insert into placeType set name="'.$this->name.'"'); $this->id= $this->dbh->lastInsertId(); } public function ConnectPlaceTypeHotel(){ $stmt = $this->dbh->query('Insert into placeTypeHotel set HotelID="'.$this->HotelID.'", ptId='.$this->id); } } class PlaceOfInterest{ public $id; public $name; public $lat; public $lon; public $place_id; public $price_level; public $rating; public $address; public $typeText=""; public $group; public $imageUrl; public $photoName; public $html_attributions; public $HotelID; public $placeType=array(); public $placePhotos=array(); public function __construct(){ global $dbh; $this->dbh = $dbh; } public function SetAllTypeText(){ print_r($this->placeType); exit; foreach($this->placeType as $pt){ if(!empty($pt->group)){ $this->typeText.=$pt->displayAs.', '; } } $this->typeText=substr($this->typeText,0,strrpos($this->typeText,', ')); } public function GetPlaceType(){ $q='Select * from placeType pt inner join placeTypePlaceOfInterest ptpoi on pt.id=ptpoi.ptId where ptpoi.poiId='.$this->id; echo $q.'
'; $stmt = $this->dbh->query($q); #echo $q.'
'; if($stmt->rowCount()){ $results = $stmt->fetchAll(PDO::FETCH_OBJ); foreach($results as $r){ $this->placeType[]=$r; } } } public function GetPlacePhoto(){ $q='Select pp.* from placePhoto pp inner join placeOfInterest poi on pp.place_id=poi.place_id where poi.id='.$this->id.' group by poi.id limit 1'; echo $q.'
'; $stmt = $this->dbh->query($q); if($stmt->rowCount()){ $results = $stmt->fetchAll(PDO::FETCH_OBJ); foreach($results as $r){ $this->placePhotos[]=$r; #print_r($this->placePhotos); #exit; } } } public function SavePlaceOfInterest(){ echo 'SELECT * from placeOfInterest where place_id="'.$this->place_id.'"'; $stmt = $this->dbh->query('SELECT * from placeOfInterest where place_id="'.$this->place_id.'"'); if(!$stmt->rowCount()){ $stmt = $this->dbh->query('Insert into placeOfInterest set name="'.$this->name.'", lat="'.$this->lat.'", lon="'.$this->lon.'", place_id="'.$this->place_id.'", price_level="'.$this->price_level.'", rating="'.$this->rating.'", address="'.$this->address.'" '); $this->id= $this->dbh->lastInsertId(); } else{ $results = $stmt->fetch(PDO::FETCH_OBJ); $this->id=$results->id; } } public function ConnectPlaceOfInterestHotel(){ echo 'SELECT * from placeOfInterestHotel where poiId="'.$this->id.'" and HotelId='.$this->HotelID; $stmt = $this->dbh->query('SELECT * from placeOfInterestHotel where poiId="'.$this->id.'" and HotelId='.$this->HotelID); if(!$stmt->rowCount()){ $stmt2 = $this->dbh->query('Insert into placeOfInterestHotel set HotelID="'.$this->HotelID.'", poiId='.$this->id); } } public function ConnectPlaceOfInterestPlaceType($placeId){ $stmt = $this->dbh->query('SELECT * from placeTypePlaceOfInterest where poiId="'.$this->id.'" and ptId='.$placeId); if(!$stmt->rowCount()){ echo 'Insert into placeTypePlaceOfInterest set poiId="'.$this->id.'", ptId='.$placeId; $stmt2 = $this->dbh->query('Insert into placeTypePlaceOfInterest set poiId="'.$this->id.'", ptId='.$placeId); } } public function GetPlaceOfInterestFromGoogleMaps($lat, $lon, $keyword, $radius=1000, $type="lodging"){ $url='https://maps.googleapis.com/maps/api/place/nearbysearch/json?location='.$lat.','.$lon.'&radius='.$radius.'&type='.$type.'&key=AIzaSyBiElx6oQ5jxpZUyOXiVdivBcwxV_gdgA0'; echo $url.'
'; $pages=0; $run=true; while($run){ $pages++; echo "URl2 \n

"; echo "PAGE: ".$pages."\n\n\n

"; echo "URL: ".$url.'

'; #$res=file_get_contents($url); $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $res = curl_exec($ch); curl_close($ch); $data = json_decode($res, true); echo "\n\n

PRINT DATA:::

\n\n"; if(count($data['results'])<1){ echo "
\nNO RESULTS
"; echo $url."
\n"; echo "NUMBER: ".count($data['results']); $run=false; } else{ foreach($data['results'] as $result){ echo $result['vicinity'].'
'; #print_r($result); $this->lat = $result['geometry']['location']['lat']; $this->lon = $result['geometry']['location']['lng']; $this->name = addslashes($result['name']); $this->address=addslashes($result['vicinity']); $this->place_id=$result['place_id']; if($this->name!="Engelen") continue; if(isset($result['rating'])){ $this->rating=$result['rating']; } if(isset($result['price_level'])){ $this->price_level=$result['price_level']; } #$this->GetPlaceInfoFromGoogleMaps(); #print_r($this); #save or set id for PlaceOfInterest $this->SavePlaceOfInterest(); #Save PhotoPlace if(isset($result['photos'])){ foreach($result['photos'] as $rows){ #print_r($rows); echo $rows['photo_reference'].'
'; $photo=new PlacePhoto(); $photo->photo_reference=$rows['photo_reference']; $photo->height=$rows['height']; $photo->html_attributions=addslashes($rows['html_attributions'][0]); $photo->width=$rows['width']; $photo->place_id=$this->place_id; # print_r($photo); $urlPhoto='https://maps.googleapis.com/maps/api/place/photo?maxwidth=800&photoreference='.$photo->photo_reference.'&key=AIzaSyBiElx6oQ5jxpZUyOXiVdivBcwxV_gdgA0'; echo $urlPhoto.'
'; $photo->imageUrl=$photo->GetRedirectUrl($urlPhoto); echo "

Photo URL: ".$photo->imageUrl.'

'; if($photo->imageUrl){ $photo->SavePlacePhoto(); # $photo->ConnectPlacePhotoPlaceOfInterest($this->id); } } } #Save PlaceOfInterest placeType if(isset($result['types'])){ foreach($result['types'] as $row){ $placeType=new PlaceType(); $placeType->name=$row; $stmt = $this->dbh->query('SELECT * from placeType where name like "'.$placeType->name.'"'); if(!$stmt->rowCount()){ $placeType->SavePlaceType(); } else{ $results = $stmt->fetch(PDO::FETCH_OBJ); print_r($results); $placeType->id=$results->id; } #connect placeOfInterest with PlaceType= placeTypePlaceOfInterest $this->ConnectPlaceOfInterestPlaceType($placeType->id); } } #connect placeOfInterest with Hotel $this->ConnectPlaceOfInterestHotel(); } echo "SLEEP
"; sleep(3); #Get Next Page if(!empty($data['next_page_token'])){ if(strstr($url, "&pagetoken=")){ $url=preg_replace("/&pagetoken=.*/is", "", $url); } $url.='&pagetoken='.$data['next_page_token']; echo "URL:
\n"; echo $url; echo "
\n"; } else{ $run=false; echo "RUN FALSE 1"; } if($pages>4){ $run=false; echo "RUN FALSE 2"; } #print_r(file_get_contents($url)); } } } public function ReduceSize(){ // $dimensions= if(preg_match("/\/s([0-9]+)-\w([0-9]+)\/$/is", $this->imageUrl, $results)){ if($results[1]>1000){ $s=$results[1]/2; $w=$results[2]/2; $this->imageUrl=preg_replace("/\/s[0-9]+-\w[0-9]+/", "/s$s-w$w", $this->imageUrl); } # echo "RES image: " .$results[1]; # echo "
imageUrl; ".$this->imageUrl; } } } class PlacePhoto{ public $id; public $photo_reference; public $html_attributions; public $place_id; public $height; public $width; public $imageUrl; public function __construct(){ global $dbh; $this->dbh = $dbh; } public function SavePlacePhoto(){ # echo 'SELECT * from placePhoto where place_id="'.$this->place_id.'" and imageUrl="'.$this->imageUrl.'"'; $stmt = $this->dbh->query('SELECT * from placePhoto where place_id="'.$this->place_id.'" and imageUrl="'.$this->imageUrl.'"'); if(!$stmt->rowCount()){ $in='Insert into placePhoto set photo_reference="'.$this->photo_reference.'", html_attributions="'.$this->html_attributions.'", place_id="'.$this->place_id.'", height="'.$this->height.'", width="'.$this->width.'", imageUrl="'.$this->imageUrl.'" '; echo "\n".$in."\n"; $stmt = $this->dbh->query($in); $this->id= $this->dbh->lastInsertId(); } else{ $results = $stmt->fetch(PDO::FETCH_OBJ); $this->id=$results->id; } } public function ConnectPlacePhotoPlaceOfInterest($poiId){ $stmt = $this->dbh->query('SELECT * from placePhotoPlaceOfInterest where poiId="'.$poiId.'" and ppId='.$this->id); if(!$stmt->rowCount()){ echo 'Insert into placePhotoPlaceOfInterest set poiId="'.$poiId.'", ppId='.$this->id; $stmt2 = $this->dbh->query('Insert into placePhotoPlaceOfInterest set poiId="'.$poiId.'", ppId='.$this->id); } } public function GetRedirectUrl ($url) { stream_context_set_default(array( 'http' => array( 'method' => 'HEAD' ) )); $headers = get_headers($url, 1); if ($headers !== false && isset($headers['Location'])) { return $headers['Location']; } return false; } } class TransitStation{ public $id; public $name; public $lat; public $lon; public $place_id; public $distanceText; public $distanceMeter; public $walkingTimeText; public $walkingTimeSeconds; public $HotelID; public $transitTypes; public $placeType=array(); public function __construct(){ global $dbh; $this->dbh = $dbh; } public function GetPlaceTypeTransitStation($sql=' where pt.id>49 '){ $q='Select pt.* from placeType pt inner join transitStationType tst on pt.id=tst.tId '.$sql; $stmt = $this->dbh->query($q); echo $q.'
'; if($stmt->rowCount()){ $results = $stmt->fetchAll(PDO::FETCH_OBJ); foreach($results as $r){ $this->placeType[]=$r; } } } public function SaveTransitStation(){ $stmt = $this->dbh->query('SELECT * from transitStation where place_id="'.$this->place_id.'"'); if(!$stmt->rowCount()){ $stmt = $this->dbh->query('Insert into transitStation set name="'.$this->name.'", lat="'.$this->lat.'", lon="'.$this->lon.'", place_id="'.$this->place_id.'" '); $this->id= $this->dbh->lastInsertId(); } else{ $results = $stmt->fetch(PDO::FETCH_OBJ); #print_r($results); $this->id=$results->id; } } public function ConnectTransitStationHotel(){ $stmt = $this->dbh->query('SELECT * from transitStationHotel where tId="'.$this->id.'" and HotelId='.$this->HotelID); if(!$stmt->rowCount()){ $stmt2 = $this->dbh->query('Insert into transitStationHotel set HotelID="'.$this->HotelID.'", tId='.$this->id); } } public function ConnectTransitStationType($typeId){ echo 'SELECT * from transitStationType where tsId='.$this->id.' and tId='.$typeId; $stmt = $this->dbh->query('SELECT * from transitStationType where tsId='.$this->id.' and tId='.$typeId); if(!$stmt->rowCount()){ echo 'Insert into transitStationType set tsId="'.$this->id.'", tId='.$typeId; $stmt2 = $this->dbh->query('Insert into transitStationType set tsId='.$this->id.', tId='.$typeId); } } public function GetTransitStationFromGoogleMaps($latHotel, $lonHotel, $radius=3000, $type="transit_station"){ $url='https://maps.googleapis.com/maps/api/place/nearbysearch/json?location='.$latHotel.','.$lonHotel.'&radius='.$radius.'&type='.$type.'&key=AIzaSyBiElx6oQ5jxpZUyOXiVdivBcwxV_gdgA0'; echo $url.'
'; $pages=0; $run=true; while($run){ $pages++; echo "URl2 \n

"; echo "PAGE: ".$pages."\n\n\n

"; echo "URL: ".$url.'

'; #$res=file_get_contents($url); $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $res = curl_exec($ch); curl_close($ch); $data = json_decode($res, true); echo "\n\n

PRINT DATA:::

\n\n
	";
					#print_r($res);
					#	print_r($data);
				#	exit;
					#if($data['rows'][0]['elements'][0]['status']=="ZERO_RESULTS"){
					if(count($data['results'])<1){
						echo "
\nNO RESULTS
"; echo $url."
\n"; echo "NUMBER: ".count($data['results']); $run=false; } else{ foreach($data['results'] as $result){ #echo $result['vicinity'].'
'; # print_r($result); $this->lat = $result['geometry']['location']['lat']; $this->lon = $result['geometry']['location']['lng']; $this->name = addslashes($result['name']); $this->address=addslashes($result['vicinity']); $this->place_id=$result['place_id']; if(isset($result['rating'])){ $this->rating=$result['rating']; } if(isset($result['price_level'])){ $this->price_level=$result['price_level']; } #$this->GetPlaceInfoFromGoogleMaps(); #print_r($this); #exit; #save or set id for TransitStation $this->SaveTransitStation(); #Save PlaceOfInterest placeType if(isset($result['types'])){ foreach($result['types'] as $row){ $placeType=new PlaceType(); $placeType->name=$row; $stmt = $this->dbh->query('SELECT * from placeType where name like "'.$placeType->name.'"'); if(!$stmt->rowCount()){ $placeType->SavePlaceType(); } else{ $results = $stmt->fetch(PDO::FETCH_OBJ); # print_r($results); $placeType->id=$results->id; } #connect transit_station with PlaceType= transitStationType $this->ConnectTransitStationType($placeType->id); } } #connect TransitWithHotel $this->CalculateDistanceTransitStation($latHotel, $lonHotel); $this->InsertOrUpdateTransitStationHotel(); #exit; #$this->ConnectTransitStationHotel(); #exit; } echo "SLEEP
"; sleep(3); #Get Next Page if(!empty($data['next_page_token'])){ if(strstr($url, "&pagetoken=")){ $url=preg_replace("/&pagetoken=.*/is", "", $url); } $url.='&pagetoken='.$data['next_page_token']; echo "URL:
\n"; echo $url; echo "
\n"; } else{ $run=false; echo "RUN FALSE 1"; } if($pages>4){ $run=false; echo "RUN FALSE 2"; } } } } public function CalculateDistanceTransitStation($latHotel, $lonHotel){ $url='https://maps.googleapis.com/maps/api/distancematrix/json?origins='.$this->lat.','.$this->lon.'&destinations='.$latHotel.'%2C'.$lonHotel.'&mode=walking&key=AIzaSyBiElx6oQ5jxpZUyOXiVdivBcwxV_gdgA0&language=sv'; echo $url.'
'; $res=file_get_contents($url); $data = json_decode($res, true); #print_r($data); if($data['rows'][0]['elements'][0]['status']=="ZERO_RESULTS"){ echo $data['rows'][0]['elements'][0]['status']; $up='UPDATE transitStationHotel set distanceText="", distanceMeter="", walkingTimeText="", walkingTimeSeconds="-1" where HotelID='.$this->HotelID.' and tId='.$this->id;; echo $up; $stmt3=$this->dbh->query($up); #exit; } #set Geo #print($data['rows']); #print_r($data['rows'][0]['elements']); $distanceText=""; $distanceMeter=""; $drivingTimeText=""; $drivingTimeSeconds=""; if(isset($data['rows'][0]['elements'][0]['distance'])){ $this->distanceText=$data['rows'][0]['elements'][0]['distance']['text']; $this->distanceMeter=$data['rows'][0]['elements'][0]['distance']['value']; $this->walkingTimeText=$data['rows'][0]['elements'][0]['duration']['text']; $this->walkingTimeSeconds=$data['rows'][0]['elements'][0]['duration']['value']; } } public function InsertOrUpdateTransitStationHotel(){ $sel='SELECT * from transitStationHotel where HotelID='.$this->HotelID.' and tId='.$this->id; $stmt = $this->dbh->query($sel); if(!$stmt->rowCount()){ $in='insert into transitStationHotel set HotelID="'.$this->HotelID.'", tId="'.$this->id.'", distanceText="'.$this->distanceText.'", distanceMeter="'.$this->distanceMeter.'", walkingTimeText="'.$this->walkingTimeText.'", walkingTimeSeconds="'.$this->walkingTimeSeconds.'"'; echo $in.'
'; $this->dbh->query($in); } else{ $up='UPDATE transitStationHotel set distanceText="'.$this->distanceText.'", distanceMeter="'.$this->distanceMeter.'", walkingTimeText="'.$this->walkingTimeText.'", walkingTimeSeconds="'.$this->walkingTimeSeconds.'" where tId='.$this->id.' and HotelID='.$this->HotelID; echo $up; $this->dbh->query($up); } } } ?> Fatal error: Class 'Site' not found in /storage/content/75/2005275/hotell-karlstad.se/public_html/index.php on line 15