-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-song.php
102 lines (93 loc) · 3.85 KB
/
add-song.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
<?php
require_once __DIR__ . '/vendor/autoload.php';
use \ITP\Base\Database;
use \ITP\Music\ArtistQuery;
use \ITP\Music\GenreQuery;
use \ITP\Music\Song;
use \PDO;
$song = new Song();
use \Symfony\Component\HttpFoundation\Session\Session;
$session = new Session();
$session->start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Insert Song</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</head>
<body>
<?php if(!isset($_POST['submit'])) : ?>
<?php foreach($session->getFlashBag()->get('insertion-success') as $message) : ?>
<p><?php echo $message ?></p>
<?php endforeach ?>
<form action="add-song.php" method="post">
<div class="col-md-2">
<div class="form-group">
<label for="input_title">Song Title</label>
<input type="text" class="form-control" name="song_title" id="input_title">
</div>
</div>
<div class="clearfix visible-lg-block"></div>
<div class="col-md-2">
<div class="form-group">
<label>Artist</label>
<select class="form-control" name="artist_name">
<?php
$aquery = new ArtistQuery();
$artists = $aquery->getAll();
?>
<?php foreach($artists as $artist) : ?>
<option value="<?php echo $artist->id ?>"><?php echo $artist->artist_name ?></option>
<?php endforeach ?>
</select>
</div>
</div>
<div class="clearfix visible-lg-block"></div>
<div class="col-md-2">
<div class="form-group">
<label>Genre</label>
<select class="form-control" name="genre">
<?php
$gquery = new GenreQuery();
$genres = $gquery->getAll();
?>
<?php foreach($genres as $genre) : ?>
<option value="<?php echo $genre->id ?>"><?php echo $genre->genre ?></option>
<?php endforeach ?>
</select>
</div>
</div>
<div class="clearfix visible-lg-block"></div>
<div class="col-md-2">
<div class="form-group">
<label for="price">Price</label>
<input type="text" class="form-control" name="song_price" id="price">
</div>
</div>
<div class="clearfix visible-lg-block"></div>
<div class="col-md-2">
<button type="submit" class="btn btn-primary" name="submit">Insert Song</button>
</div>
</form>
<?php else : ?>
<?php
$song->setTitle($_POST['song_title']);
$song->setArtistId($_POST['artist_name']);
$song->setGenreId($_POST['genre']);
$song->setPrice($_POST['song_price']);
$song->save();
$title = $song->getTitle();
$id = $song->getId();
$session->getFlashBag()->add('insertion-success', "The song $title with an ID of $id was inserted successfully");
header('Location: add-song.php');
?>
<?php endif ?>
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>