-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddsong.php
191 lines (155 loc) · 6.38 KB
/
addsong.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
<?php
require 'vendor/autoload.php';
include __DIR__ . '/html_private/head.php';
include __DIR__ . '/html_private/lgc.php';
if (!empty($_GET["NoOfSongs"])) {
$noofsongs = $_GET["NoOfSongs"];
} else {
$noofsongs = 1;
}
$_SESSION['song'] = array();
if (isset($_POST["Add"])) {
for ($i = 0; $i < $noofsongs; $i++) {
$songname = $_POST["song,$i"];
$songname = $myConn->sanie($songname);
$bandname = $_POST["band,$i"];
$bandname = $myConn->sanie($bandname);
$_SESSION['song'][] = array($songname, $bandname);
$user = $_POST["user,$i"];
$weekgroup = "week." . date('m.y');
$timestamp = getdate();
$outputDate = $timestamp["year"] . '-' . $timestamp["mon"] . '-' . $timestamp["mday"];
$query = "INSERT INTO `song` (`SongID`, `SongName`, `BandName`, `Submited_by`, `WeekGroup`, `DatePosted`) VALUES (NULL, '$songname', '$bandname', '$user', '$weekgroup', '$outputDate')";
$myConn->InsertQuery($query);
}
$myConn->redirect("display.php");
}
if (isset($_POST["okspot"])) {
if (isset($_POST['uri']) && $_POST['uri'] != "") {
$api = new SpotifyWebAPI\SpotifyWebAPI();
$api->setAccessToken($_COOKIE['spotify']);
$song = $_POST['uri'];
$track = $api->getTrack($song);
$songname = $track->name;
$songname = $myConn->sanie($songname);
$artistname = $track->artists[0]->name;
$artistname = $myConn->sanie($artistname);
$imgsrc = $track->album->images[0]->url;
$_SESSION['song'][] = array($songname, $artistname, $imgsrc);
$user = $_COOKIE['User'];
// $api->addPlaylistTracks('1vOimaoGmDRWT1eGDmdP7R', [$song], "");
$weekgroup = "week." . date('m.y');
$timestamp = getdate();
$outputDate = $timestamp["year"] . '-' . $timestamp["mon"] . '-' . $timestamp["mday"];
$query = "INSERT INTO `song` (`SongID`, `SongName`, `BandName`, `Submited_by`, `WeekGroup`, `DatePosted`) VALUES (NULL, '$songname', '$artistname', '$user', '$weekgroup', '$outputDate')";
$myConn->InsertQuery($query);
//UPDATE `spotify` SET `uri` = 'uri' WHERE `spotify`.`SongID` = 600;
$songIDinDB = $myConn->getDBSongID();
// $uriQuery = "UPDATE `spotify` SET `uri` = '$song' WHERE `spotify`.`SongID` = $songIDinDB";
// $myConn->updateQuery($uriQuery);
$myConn->addUri($song, $songIDinDB);
$myConn->redirect("songdetails.php?ID=$songIDinDB");
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>add songs</title>
<?php
include __DIR__ . '/partials/header.php';
?>
<script>
$(function() {
$('#band').autocomplete({
source: function(request, response) {
$.ajax({
type: "POST",
url: "do_search.php",
data: {
term: request.term,
type: "user"
},
success: response,
dataType: 'json',
minLength: 2,
delay: 100
});
}
});
});
</script>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" rel="Stylesheet" />
<script src="https://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<?php if ($_GET['s'] == "yes") {
if (!empty($_COOKIE['spotify'])) {
?>
<div class="container">
<div class="row row-cols-1 pt-5">
<form action="" method="post">
<!-- <label class="col" for="uri"></label> -->
<!-- <input class="col input-group" type="text" name="uri" placeholder="Spotify URI"> -->
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">share -> copy sotify uri</span>
</div>
<input type="text" name="uri" class="form-control"
placeholder="Spotify Uri eg: spotify:track:0OZFho0a7Pvk1SlLYiDjqM" aria-label="Spotify Uri"
aria-describedby="basic-addon1">
</div>
<input class="col btn btn-warning" type="submit" name="okspot" value="Go">
</form>
</div>
</div>
<?php
} else {
?>
<div class="container">
<div class="row row-cols-1">
<h2 class="col">log in with spotify first</h2>
<a class="col btn btn-warning" href="api.php">login</a>
</div>
</div>
<?php
}
} else {
?>
<div class="container">
<div class="row justify-content-md-center">
<h2 class="capt">Add songs</h2>
</div>
<form action="" method="post">
<?php
for ($i = 0; $i < $noofsongs; $i++) {
?>
<div class="form-group">
<label for="songname <?php echo $i ?>">Song Name</label>
<input type="text" class="form-control" name="song,<?php echo $i ?>"
placeholder="songname <?php echo $i ?>" name="song,<?php echo $i ?>" id="">
</div>
<div class="form-group">
<label for="band,<?php echo $i ?>" name="band,<?php echo $i ?>">Band Name</label>
<input id="band" type="text" class="form-control" placeholder="bandname <?php echo $i ?>"
name="band,<?php echo $i ?>" id="">
</div>
<div>
<label for="user">Submited by</label> <br>
<input type="radio" name="user,<?php echo $i ?>" value="2"> Ruan <br>
<input type="radio" name="user,<?php echo $i ?>" value="3"> Werner <br>
<input type="radio" name="user,<?php echo $i ?>" value="4"> Danie
</div>
<br>
<?php
} ?>
<input class="btn btn-warning form-control" type="submit" name="Add" value="Add">
</form>
</div>
<?php
} ?>
</body>
</html>