-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplay.php
189 lines (170 loc) · 6.6 KB
/
play.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
<?php
session_start();
include "console.php";
//console_log($_SESSION['signedin']);
//console_log($_SESSION['username']);
$trackid = $_GET['trackid'];
$timestamp = date('Y-m-d H:i:s');
$source = $_GET['source'];
$pdesc = $_GET['pdesc'];
//console_log($trackid);
//console_log($timestamp);
$servername = "127.0.0.1";
$username = "root";
$password = "passmysql";
$dbname = "music";
$conn = new mysqli($servername, $username, $password, $dbname);
// test connection
if ($conn->connect_error) {
die("connect to mysql,failed: " . $conn->connect_error);
}
$record_play_sql = "call record_play('". $trackid ."','".$_SESSION['username']."','" . $timestamp . "','" . $source ."','". $pdesc ."');";
$result = $conn->query($record_play_sql);
$play_playlists_sql = "select playlistid,playlisttitle from Playlist where owner ='" . $_SESSION['username'] . "';";
$result = $conn->query($play_playlists_sql);
$p_playlists = array();
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()){
$p_playlists[] = $row;
}
}
$track_info_sql = "select * from Track natural join Artist where trackid = " . $trackid . ";";
$result = $conn->query($track_info_sql);
$info = $result->fetch_assoc();
//console_log($info);
$rate_sql = "select score from Rate where username = '".$_SESSION['username']. "'and trackid = ". $trackid .";";
$result = $conn->query($rate_sql);
$score = $result->fetch_assoc()['score'];
//console_log($score);
$conn->close();
?>
<meta charset="utf-8">
<title>Cloud Music Play Page</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
<link href="mystyle.css" rel="stylesheet" type="text/css"/>
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<script>
function submitAddPlaylist(playlistid,trackid,username,token){
//console.log("submitAddPlaylist!");
//console.log(playlistid);
//console.log(trackid);
//console.log(username);
//console.log(token);
var http = new XMLHttpRequest();
var url = "data_manager.php";
var params = "q=ADDTOPLAYLIST" + "&playlistid="+ playlistid +
"&trackid=" + trackid +"&username=" + username + "&token=" + token;
//console.log(params);
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);
}
</script>
<script>
function submitRate(score,username,token,trackid){
//console.log(score);
//console.log(username);
//console.log(token);
//console.log(trackid);
var http = new XMLHttpRequest();
var url = "data_manager.php";
var params = "q=ADDRATE" + "&username="+ username + "&token=" + token +
"&trackid=" + trackid +"&score=" + score;
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
//alert(http.responseText);
}
}
http.send(params);
}
</script>
<div class="demo-card-play mdl-card mdl-shadow--2dp">
<div class="mdl-card__title mdl-card--expand">
<h2 class="mdl-card__title-text"><?php echo $info['tracktitle']?></h2>
<br/>
</div>
<div class="mdl-card__supporting-text">
<audio src=<?php echo '"' . 'track/' . $trackid . '.mp3"' ?> controls>
<h6><?php echo $info['aname']?></h6>
</div>
</div>
<div class="demo-card-res mdl-card mdl-shadow--2dp">
<div class="mdl-card__supporting-text">
<fieldset class="rating">
<legend>Give a rate:</legend>
<?php
if(is_null($score))
{
for ($x=5; $x>=1; $x--) {
echo '<input type="radio" onclick="submitRate(this.value,\'' .$_SESSION['username'].'\',\''. $_SESSION['token'] . '\',' .$trackid. ')" id="star' . $x .'" name="rating" value="'.$x.'" /><label for="star'.$x.'">'.$x.' stars</label>';
}
}
else{
for ($x=5; $x>=1; $x--) {
if($x == $score){
echo '<input type="radio" checked onclick="submitRate(this.value,\'' .$_SESSION['username'].'\',\''. $_SESSION['token'] . '\',' .$trackid. ')" id="star' . $x .'" name="rating" value="'.$x.'" /><label for="star'.$x.'">'.$x.' stars</label>';
}
else{
echo '<input type="radio" onclick="submitRate(this.value,\'' .$_SESSION['username'].'\',\''. $_SESSION['token'] . '\',' .$trackid. ')" id="star' . $x .'" name="rating" value="'.$x.'" /><label for="star'.$x.'">'.$x.' stars</label>';
}
}
}
?>
</fieldset>
</div>
<div class="mdl-card__supporting-text">
<p>Artist:</p>
<ul class="demo-list-icon mdl-list">
<?php echo '<li class="mdl-list__item">
<span class="mdl-list__item-primary-content">
<i class="material-icons mdl-list__item-icon">face</i>
<a href="artist.php?artistid=' .
$info['artistid'].
'">' .
$info['aname'].
'</a>
</span>
</li>'?>
</ul>
<p>Add to your list?</p>
<ul class="demo-list-icon mdl-list">
<?php
foreach($p_playlists as $p){
echo '<li class="mdl-list__item">
<span class="mdl-list__item-primary-content">
<i class="material-icons mdl-list__item-icon">queue_music</i>
<a href="playlist.php?playlistid=' .
$p['playlistid'].
'">' .
$p['playlisttitle'].
'</a>
</span>
<span>
<a class="mdl-button mdl-js-button mdl-button--fab mdl-js-ripple-effect mdl-button--colored" onclick="submitAddPlaylist('.
$p['playlistid'].
','.
$trackid.
',\''.
$_SESSION['username'] .
'\',\''.
$_SESSION['token'] .
'\')">
<i class="material-icons">add</i>
</a>
</span>
</li>';
}
?>
</ul>
</div>
</div>