-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeaters.php
347 lines (240 loc) · 9.66 KB
/
theaters.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
<!DOCTYPE html>
<?php
require_once('simple_html_dom.php');
if($_GET) {
$url = "http://www.google.com/movies?near=" . urlencode($_GET["loc"]);
}
else $url = "http://www.google.com/movies?";
$content = file_get_contents($url);
$html = new simple_html_dom();
$html->load($content);
// $location = $html->find('h1[id="title_bar"]', 0)->innertext;
$locationlist = array();
foreach($html->find('div[class="theater"]') as $theater) {
$theatername = $theater->find('h2[class="name"] a', 0)->innertext;
$theateraddress = $theater->find('div[class="info"]', 0)->innertext;
$theaterinfo = array();
$theaterinfo['name'] = $theatername;
$temp = explode(" -", $theateraddress);
$theaterinfo['adr'] = $temp[0];
array_push($locationlist, $theaterinfo);
}
$html->clear();
unset($html);
global $foodterm;
global $placeterm;
//if logged in, get user ID, call it $id
//for now, i'll just set id to myself
$id = 3;
$myUserName = "arhea01";
$myPassword = "arhea01";
$myDatabase = "arhea01";
$myHost = "mysql-user";
$dbh = mysql_connect($myHost, $myUserName, $myPassword) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db($myDatabase) or die("Unable to select database");
$myQuery = sprintf("SELECT * FROM reelzusers WHERE user_id='%s'",
mysql_real_escape_string($id));
$myResult = mysql_query($myQuery);
$user = mysql_fetch_array($myResult, MYSQL_BOTH);
if ($user[fav_food]!=NULL){
$foodterm = $user[fav_food];
}
else{
$foodterm = "food";
}
if ($user[def_location]!=NULL){
$placeterm = $user[def_location];
}
else if ($_GET['loc']) $placeterm = $_GET['loc'];
else ($placeterm="Davis Square, Somerville MA");
//geolocate option?
$url = "http://api.yelp.com/business_review_search?term=".urlencode($foodterm)."&location=".urlencode($placeterm)."&ywsid=5aI7kCD2Q4IHiHjGca1dPg";
$content = file_get_contents($url);
$yelparray = array();
$yelpinfo = json_decode($content);
if ($yelpinfo == NULL) die('Error retrieving movie information');
foreach ($yelpinfo->businesses as $eatery){
//print_r($eatery);
$business=array();
$business['name'] = $eatery->name;
$business['adr'] = $eatery->address1 . ' ' . $eatery->city . ' ' . $eatery->state;
array_push($yelparray,$business);
/* echo "<a href=".$eatery->url.">".$eatery->name."</a><br/>";
echo $eatery->address1.", ".$eatery->city.", ".$eatery->state."<br/>";
echo "Phone Number: ".$eatery->phone."<br/>";
echo "Average Yelp! Rating: ".$eatery->avg_rating;
echo "<br/><br/>";*/
// $lat = $eatery->latitude;
// $lon = $eatery->longitude;
}
?>
<head>
<title>Theaters</title>
<link rel="stylesheet" href="main.css" type="text/css" />
<link href='http://fonts.googleapis.com/css?family=Amaranth' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=OFL+Sorts+Mill+Goudy+TT' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="scroll.css">
<script src="http://cdn.jquerytools.org/1.2.5/jquery.tools.min.js"></script>
<script type="text/javascript" src="sidebar.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
var localtheaters = <?php echo json_encode($locationlist); ?>;
var localeats = <?php echo json_encode($yelparray); ?>;
var geocoder;
var map;
function getLocation() {
fillSidebar();
geocoder = new google.maps.Geocoder();
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(found, notfound);
} else {
alert("Geolocation is not supported by your web browser.");
}
}
//found and notfound serving as wrapper functions
function found(position) {listings(position, true);}
function notfound(position) {listings(position, false);}
//everythings confined in here because the map var would not cooperate...
function listings(position, found) {
if(found) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
} else {
var lat = 42.3599611; //defaults to faneuil hall
var lng = -71.0567528; //if location isn't found
}
//$('div#content').prepend('<a href="theaters.php?loc=' + encodeURI(address) + '">Find Me!</a><br>');
var initLoc = new google.maps.LatLng(lat, lng);
var infowindow = new google.maps.InfoWindow();
var myOptions = {
zoom: 13, // The larger the zoom number, the bigger the zoom
center: initLoc,
mapTypeId: google.maps.MapTypeId.HYBRID
};
// Create the map in the "map_canvas" <div>
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
// Create a home marker
var image = 'person.png';
var marker = new google.maps.Marker({
position: initLoc,
title: "You Are Here!"
//icon: image
});
marker.setMap(map);
attachToMark(marker, infowindow, map);
infowindow.setContent(marker.title); //set to open at start
infowindow.open(map,marker);
postResults(localtheaters,infowindow);
postResults(localeats,infowindow);
}
function attachToMark(marker, infowindow, map) {
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(marker.title);
infowindow.open(map, marker);
});
}
function postResults (locations,infowindow) {
getLoc(infowindow,locations,0);
}
function getLoc(infowindow,search,index) {
var address = search[index]['adr'];
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
search[index]['lat'] = results[0].geometry.location.Da;
search[index]['lng'] = results[0].geometry.location.Ea;
console.log(search[index]['name']);
postResult(search, index, infowindow);
if (index < 3) getLoc(infowindow,search,++index);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
function postResult (search, key, infowindow) {
var content = '<h2>' + search[key]['name'] + '</h2>';
// '<a href="good.php?id= ' + search[key]['good_id'] + '"/>Link</a>';
var landmark = new google.maps.LatLng(search[key]['lat'],search[key]['lng']);
var marker = new google.maps.Marker({
title: content,
position: landmark,
});
marker.setMap(map);
attachToMark(marker, infowindow, map);
}
// }
/*
function thiy () {
var h = <?php print_r($locationlist); ?>;
}*/
</script>
</head>
<body onload="getLocation()">
<div id="header-wrap">
<!--<div id="header-container">
<div id="header">
<h1>Fixed Header & Footer<em>even IE6 behaves</em></h1>-->
<ul id="navbar">
<li><span class="start"><a href="index.php" title=""><img src="images/logo.png" alt="logo"/></a></span></li>
<li><a href="movie.php" title=""><p>Movies</p></a></li>
<li><a href="theaters.php" title="" class="current"><p>Theaters</p></a></li>
<li><a href="about.php" title=""><p>About</p></a></li>
<li><a href="account.php" title=""><p>Account</p></a></li>
<li><form action="search.php" method="get">
<input type="text" name="q" placeholder="Enter movie name" />
<input type="submit" id="searchbutton" value="Submit" />
</form></li>
</ul>
<!-- </div>
</div>-->
</div>
<div id="map_canvas"></div>
<div id="container">
<div id="content">
<?php
$url = "http://www.google.com/movies?near=" . urlencode($_GET["loc"]);
$content = file_get_contents($url);
$html = new simple_html_dom();
$html->load($content);
$location = $html->find('h1[id="title_bar"]', 0)->innertext;
echo ("<b>$location</b>");
echo ("<form name=\"changeloc\" action=\"theaters.php\" method=\"get\">");
echo ("<input type=\"text\" name=\"loc\" placeholder=\"Change location\" />");
echo ("<input type=\"submit\" value=\"Submit\" /></form>");
$locationlist = array();
foreach($html->find('div[class="theater"]') as $theater) {
$theatername = $theater->find('h2[class="name"] a', 0)->innertext;
$theateraddress = $theater->find('div[class="info"]', 0)->innertext;
$theaterinfo = array();
$theaterinfo['name'] = $theatername;
$temp = explode(" -", $theateraddress);
$theaterinfo['adr'] = $temp[0];
array_push($locationlist, $theaterinfo);
$theaterid = $theater->find('div[class="desc"]')->id;
echo ("<p><h3>$theatername<br>$theateraddress</h3>");
foreach($theater->find('div[class="movie"]') as $movie) {
$moviename = $movie->find('div[class="name"] a', 0)->innertext;
$movietimes = $movie->find('div[class="times"]', 0)->innertext;
//$theatertimes = $theater->find('div[class="times"]', 0)->innertext;
$movietimes = str_replace('/url?q=', "", $movietimes);
$movietimes = str_replace('<a href=', "<a target=\"_blank\" href=", $movietimes);
$movietimes = urldecode($movietimes);
echo ("<b>$moviename</b><br>$movietimes<br>");
}
echo ("</p>");
}
$html->clear();
unset($html);
?>
<script type="text/javascript"> //thiy(); </script>
</div>
<div id="sidebar">
</div>
</div>
<div id="footer-wrap">
<div id="footer-container">
<div id="footer">
</div>
</div>
</div>
</body>
</html>