-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateStudio.php
172 lines (157 loc) · 8.33 KB
/
updateStudio.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
<?php
session_start();
require("functions.php");
checkLogin();
checkAdmin();
$dbc = dbConn();
if(isset($_REQUEST['id'])){
$studioId = $_REQUEST['id'];
//set the studioif in the session
$_SESSION['updateStudio'] = $studioId;
//get the studio
$getStudioQuery = "SELECT * FROM studios s WHERE s.studio_Id = $studioId";
$result = mysqli_query($dbc, $getStudioQuery);
$studio = mysqli_fetch_array($result);
//set the values
$studioname = $studio[1];
$location = $studio[2];
$mobile = $studio[3];
$email = $studio[4];
$founddate = $studio[5];
}
if($_SERVER['REQUEST_METHOD'] == "POST"){
$studioId = $_SESSION['updateStudio'];
$studioname = $_POST['studioname'];
$location = $_POST['location'];
//check if email is in the right format
if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
$email = $_POST['email'];
}else{
//error message if email is not valid
$invalidEmail = "This email is not valid";//declare a variable that tells that email is invalid
}
$founddate = $_POST['founddate'];
$mobile = $_POST['mobile'];
if(!empty($studioname) && !empty($location) && !empty($email) && !empty($mobile)){
if($_FILES['studioPhoto']){
$filename = $_FILES['studioPhoto']['name'];
$tmpName = $_FILES['studioPhoto']['tmp_name'];
$filepath = "images/" . $filename;
move_uploaded_file($tmpName, $filepath);
}
mysqli_query($dbc, "UPDATE studios s SET s.name = '$studioname', s.location = '$location',
s.mobile = '$mobile', s.email = '$email', s.foundation_date = '$founddate',
s.photoSrc = '$filepath' WHERE s.studio_Id = $studioId");
$studioUpdated = "Studio updated successfully";
}else{
$required = '*';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Update Studio</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-light bg-light">
<div class="container-fluid d-flex justify-content-between">
<a class="navbar-brand" href="http://localhost/Music%20Studio%20System/index.php">MusicMania</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-center text-center" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="http://localhost/Music%20Studio%20System/albums.php">
Albums</a>
</li>
<li class="nav-item">
<a class="nav-link" href="http://localhost/Music%20Studio%20System/systemStudios.php">
Studios</a>
</li>
</ul>
<?php if(isset($_SESSION['role'])&& $_SESSION['role'] == 'admin')
{echo"<a href =\"http://localhost/Music%20Studio%20System/addUser.php\" class = \"nav-link\">Add User</a>";
echo "<a href =\"http://localhost/Music%20Studio%20System/Users.php\" class = \"nav-link\">Users</a>";
echo "<a href =\"http://localhost/Music%20Studio%20System/addStudio.php\" class = \"nav-link\">Add Studio</a>";
echo "<a href=\"http://localhost/Music%20Studio%20System/Studios.php\" class=\"nav-link\">Studios</a>";
}if(isset($_SESSION['role']) && $_SESSION['role'] == 'artist'){
echo "<a href =\"http://localhost/Music%20Studio%20System/artistSongs.php\" class = \"nav-link\">Your Songs</a>";
echo "<a href =\"http://localhost/Music%20Studio%20System/artistAlbum.php\" class = \"nav-link\">Your Albums</a>";;
} ?>
</div>
<a class="nav-link" href="logout.php">Log out</a>
</div>
</nav>
<div class="d-flex min-vh-100 justify-content-center align-items-center">
<form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"
enctype="multipart/form-data"
class="pe-2 ps-2 col-md-4 d-flex flex-column justify-content-evenly">
<?php if(isset($required)){echo "<span class = \"text-danger align-self-center\">Please fill all the required fields</span>";} ?>
<?php if(isset($studioUpdated)){echo "<span class = \"text-success align-self-center\">$studioUpdated</span>";} ?>
<div class="d-flex justify-content-evenly mb-3">
<label for="studioname" class="form-label align-self-center mb-0 me-auto">Studio Name:</label>
<input class="form-control w-50" type="text"
value="<?php if(isset($studioname))
{echo $studioname;} ?>"
name="studioname">
<div>
<?php if(isset($required)){echo "<span class = \"align-middle text-danger\">$required</span>";} ?>
</div>
</div>
<div class="d-flex justify-content-evenly mb-3">
<label for="location" class="form-label align-self-center mb-0 me-auto">Location:</label>
<input class="form-control w-50" type="text"
value="<?php if(isset($location))
{echo $location;} ?>"
name="location">
<div>
<?php if(isset($required)){echo "<span class = \"align-middle text-danger\">$required</span>";} ?>
</div>
</div>
<div class="d-flex justify-content-evenly mb-3">
<label for="firstname" class="form-label align-self-center mb-0 me-auto">Mobile:</label>
<input class="form-control w-50" type="text"
value="<?php if(isset($mobile))
{echo $mobile;} ?>"
name="mobile">
<div>
<?php if(isset($required)){echo "<span class = \"align-middle text-danger\">$required</span>";} ?>
</div>
</div>
<div class="d-flex justify-content-evenly mb-3">
<label for="email" class="form-label align-self-center mb-0 me-auto">Email:</label>
<input type="text" class="form-control w-50"
value="<?php if(isset($email))
{echo $email;} ?>"
name="email">
<div>
<?php if(isset($required)){echo "<span class = \"align-middle text-danger\">$required</span>";} ?>
</div>
</div>
<?php if(isset($invalidEmail)){echo "<span class=\"text-danger\">$invalidEmail</span>"; }?>
<div class="d-flex justify-content-evenly mb-3">
<label for="founddate" class="form-label align-self-center mb-0 me-auto">Foundation Date:</label>
<input type="date" class="form-control w-50"
value="<?php if(isset($founddate))
{echo $founddate;} ?>"
name="founddate">
</div>
<div class="d-flex justify-content-evenly mb-3">
<label for="studioPhoto" class="form-label align-self-center mb-0 me-auto">Studio Logo</label>
<input type="file" class="form-control w-50" name="studioPhoto">
</div>
<div class="d-flex justify-content-center align-items-center mb-3">
<input type="submit" class="btn-primary rounded" id="signUp" value="Add Studio">
</div>
</form>
</div>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-SR1sx49pcuLnqZUnnPwx6FCym0wLsk5JZuNx2bPPENzswTNFaQU1RDvt3wT4gWFG" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-j0CNLUeiqtyaRmlzUHCPZ+Gy5fQu0dQ6eZ/xAww941Ai1SxSY+0EQqNXNE6DZiVc" crossorigin="anonymous"></script>
</body>
</html>