-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovie-info.php
139 lines (130 loc) · 4.82 KB
/
movie-info.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
<?php
session_start();
require('config.php');
//echo $_GET['id'];
$api_url="https://api.themoviedb.org/3/movie/".$_GET['id']."?api_key=".$api_key."&append_to_response=videos,credits,release_dates";
$movie_json=json_decode(file_get_contents($api_url),true);
//print_r($movie_json);
if(!empty($movie_json['videos']['results'])){
//$video_boolean=1;
foreach ($movie_json['videos']['results'] as $tmp){
if($tmp['site']=='YouTube' && $tmp['type']=='Trailer'){
$video_key=$tmp['key'];
break;
}
}
}
$youtube_link="https://www.youtube.com/embed/".$video_key;
//else $video_boolean=0;
$api_video_url="https://api.themoviedb.org/3/movie/".$_GET['id']."/videos?api_key=".$api_key;
$video_json=json_decode(file_get_contents($api_video_url),true);
$movie_overview=$movie_json['overview'];
$movie_year=substr($movie_json['release_dates']['results'][0]['release_dates'][0]['release_date'],0,4);
$movie_cast='';
$count=0;
foreach ($movie_json['credits']['cast'] as $tmp){
if($count==3) break;
if($tmp['known_for_department']=='Acting'){
$movie_cast=$movie_cast.', '.$tmp['name'];
$count+=1;
}
}
$movie_cast=substr($movie_cast,2).', more';
$movie_genres='';
foreach($movie_json['genres'] as $tmp){
$movie_genres=$movie_genres.', '.$tmp['name'];
}
$movie_genres=substr($movie_genres,2);
if(isset($_POST['subscribe'])){
if(isset($_SESSION['username'])){
$username=$_SESSION['username'];
$movie_id=$_GET['id'];
$subscribe_query="insert into subscriptions values('$username','$movie_id')";
$subscribe_result=mysqli_query($conn,$subscribe_query);
}
else{
echo "<script type='text/javascript'>window.alert('You need to be logged in to subscribe/unsubscribe to movies!');</script>";
}
}
if(isset($_POST['unsubscribe'])){
if(isset($_SESSION['username'])){
$username=$_SESSION['username'];
$movie_id=$_GET['id'];
$unsubscribe_query="delete from subscriptions where username='$username' and movie_id='$movie_id'";
$unsubscribe_result=mysqli_query($conn,$unsubscribe_query);
}
else{
echo "<script type='text/javascript'>window.alert('You need to be logged in to subscribe/unsunscribe to movies!');</script>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='styles.css'>
</head>
<body>
<header>
<?php if(isset($_SESSION['username'])) { ?>
<p class="Home"><a href='index.php'>Home</a></p>
<p class="FirstMenu"><a href='my-subscriptions.php'>My Subscriptions</a></p>
<p class="Menu">Hi, <?php echo $_SESSION['username']; ?></p>
<p class="LastMenu"><a href='logout.php'>Logout</a></p>
<?php } else { ?>
<p class="Home"><a href='index.php'>Home</a></p>
<p class="FirstMenu"><a href='register.php'>Register</a></p>
<p class="LastMenu"><a href='login.php'>Login</a></p>
<?php } ?>
</header>
<div class="MovieTitle"><?php echo $movie_json['title'] ?></div>
<iframe class="MovieTrailer" src=<?php echo $youtube_link ?>></iframe>
<table class='MovieInfo'style='float:right;'>
<colgroup>
<col span='1' style='width:61%'>
<col span='1' style='width:39%'>
</colgroup>
<tr>
<td><?php echo $movie_year ?></td>
<td>Cast: <?php echo $movie_cast ?></td>
</tr>
<tr>
<td style='word-wrap:break-word;'><?php echo $movie_overview ?></td>
<td>Genres: <?php echo $movie_genres ?></td>
</tr>
</table>
<?php
if(isset($_SESSION['username'])){
$movie_id=$_GET['id'];
$username=$_SESSION['username'];
$check_subscription_query="select * from subscriptions where username='$username' and movie_id='$movie_id'";
$check_subscription_result=mysqli_query($conn,$check_subscription_query);
if(mysqli_num_rows($check_subscription_result)==1){
echo "<form id='emptyForm' method='post'>
<input id='unsubcribeButton' type='submit' value='Unsubscribe' name='unsubscribe'>
</form>";
}
else{
echo "<form id='emptyForm' method='post'>
<input id='subscribeButton' type='submit' value='Subscribe' name='subscribe'>
</form>";
}
}
else{
echo "<form id='emptyForm' method='post'>
<input id='subscribeButton' type='submit' value='Subscribe' name='subscribe'>
</form>";
}
?>
<!--<pre><?php print_r($movie_json); ?></pre>-->
</body>
</html>
<!--
<div>
<div class="Title"><?php echo $movie_json['title'] ?></div>
<div style='opacity:0.33;position:fixed;z-index:-99;width:100%;height:480px;'>
<iframe width='100%' height='100%' src=<?php echo $youtube_link ?>></iframe>
</div>
<p class="MovieOverview"><?php print_r($movie_json['overview']) ?></p>
<!--<pre><?php print_r($movie_json) ?></pre>
<pre><?php print_r($video_json) ?></pre>-->
</div>