forked from sebastianbadaro/ChallengeVacaiones
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateMovie.php
176 lines (134 loc) · 5.41 KB
/
updateMovie.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
<?php
require_once("functions.php");
require_once("Clases/movies.php");
require_once("Clases/movie.php");
require_once("Clases/genres.php");
require_once("Clases/genre.php");
if (!isLogued()) {
header('location: login.php');
exit;
}
// var_dump($_GET);
// echo '<br>';
// var_dump($_POST);
// echo '<br>';
$genres = Genres::ObtenerTodos();
$errors=[];
$movie = new Movie("","","","","","","","","");
$buttonAction = 'Add movie';
if(isset($_POST["id"])||isset($_GET["id"])){
$buttonAction = 'Update movie';
}
if(isset($_GET["id"])){
$movie = Movies::ObtenerPorId($_GET["id"]);
}
//var_dump($movie);
if($_POST){
if(isset($_POST["genre"])){
$genreId=$_POST["genre"];
}
else {
$genreId='';
}
$movie = new Movie($_POST["id"],"","",$_POST["title"],$_POST["rating"],$_POST["awards"],"",$_POST["length"],$genreId);
$errors=$movie->validate();
if(empty($errors)){
if($_POST["id"]==""){
$movie->saveMovie();
}
else {
$movie->updateMovie();
}
header('location: movies.php');
exit;
}
}
//var_dump($genres);
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<link rel="stylesheet" href="html/css/style.css">
<title>MOVIE</title>
</head>
<body>
<?php include("nav.php") ?>
<div class="">
<div class="d-flex justify-content-around align-items-center register-container">
<div class="col-11 col-sm-8 col-md-6 grey-area align-items-center ">
<form role="form" method="post" enctype="multipart/form-data">
<h2>Complete the movie information. </h2>
<hr class="colorgraph">
<?php if($errors) : ?>
<div class="alert alert-danger" role="alert">
<ul>
<?php foreach($errors as $error): ?>
<li><?=$error ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<div class="row">
<!-- Titulo -->
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group ">
<input hidden type="text" name="id" value="<?=$movie->getId();?>" id="id" class="form-control input-lg" placeholder="Title" tabindex="3">
<input type="text" name="title" value="<?=$movie->getTitle();?>" id="title" class="form-control input-lg" placeholder="Title" tabindex="3">
</div>
</div>
<!-- Fin Titulo -->
<!-- genre -->
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group ">
<select class="selectpicker form-control input-lg" name="genre" id="genre">
<option readonly="readonly" selected value='-1'>Genre</option>
<?php foreach($genres as $genre): ?>
<?php if ($genre->getId()==$movie->getGenreId()): ?>
<option selected value="<?=$genre->getId();?>"><?=$genre->getName();?></option>
<?php else: ?>
<option value="<?=$genre->getId();?>"><?=$genre->getName();?></option>
<?php endif; ?>
<?php endforeach; ?>
</select>
<!-- <input type="text" name="genere" value="" id="genre" class="form-control input-lg" placeholder="Genre" tabindex="3"> -->
</div>
</div>
<!-- Fin genre -->
<!-- Rating -->
<div class="col-xs-12 col-sm-4 col-md-4">
<div class="form-group ">
<input type="number" step="0.1" min=0 max=10 name="rating" value="<?=$movie->getRaiting();?>" id="rating" class="form-control input-lg" placeholder="Rating" tabindex="3">
</div>
</div>
<!--Fin Rating -->
<!-- Awards -->
<div class="col-xs-12 col-sm-4 col-md-4">
<div class="form-group ">
<input type="number" name="awards" min=0 value="<?=$movie->getAwards();?>" id="awards" class="form-control input-lg" placeholder="Awards" tabindex="3">
</div>
</div>
<!--Fin Awards -->
<!-- duracion -->
<div class="col-xs-12 col-sm-4 col-md-4">
<div class="form-group ">
<input type="number" name="length" step="10" min=0 value="<?=$movie->getLength();?>" id="length" class="form-control input-lg" placeholder="Length (min)" tabindex="3">
</div>
</div>
<!--Fin duracion -->
</div>
<hr class="colorgraph">
<div class="row justify-content-around">
<div class="col-xs-12 col-md-6"><input type="submit" value="<?=$buttonAction?>" class="btn btn-primary btn-block btn-lg" tabindex="7"></div>
</div>
</form>
</div>
</div>
</div>
</form>
</body>
</html>