-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_project_details.php
145 lines (130 loc) · 5.18 KB
/
edit_project_details.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
<?php
session_start();
// Redirect to login page if user is not authenticated
if (!isset($_SESSION['username'])) {
header('Location: login.php');
exit;
}
// check pid in url
if (!isset($_GET['pid'])) {
header('Location: edit_project.php');
exit;
}
// Include the config file
require_once "config.php";
// Create connection
$conn = new mysqli($host, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Get user ID from username
$sql = "SELECT uid FROM users WHERE username = '" . $_SESSION['username'] . "'";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
$uid = $row['uid'];
// Get project ID from URL
$pid = $_GET['pid'];
// Prepare SQL statement
$sql = "SELECT * FROM projects WHERE pid = " . $pid;
$result = $conn->query($sql);
$row = $result->fetch_assoc();
// check current user is owner of project
if ($row['uid'] != $uid) {
header('Location: edit_project.php');
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php
echo "<title>Edit Project: " . $row["title"] . "</title>";
?>
<link rel="stylesheet" href="css/[email protected]">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Montserrat&family=Open+Sans&display=swap" rel="stylesheet">
</head>
<body>
<main>
<div class="container">
<div class="prompt-container">
<?php
echo "<h1>Edit Project: " . $row["title"] . "</h1>";
?>
<?php
echo "<form action=\"edit_project_process.php?pid=" . $pid . "\" method=\"POST\">"
?>
<?php
echo "<input type=\"text\" name=\"project_name\" id=\"project_name\" placeholder=\"Project Name...\" value=\"" . $row["title"] . "\" required>";
echo "<textarea name=\"project_description\" id=\"project_description\" placeholder=\"Project Description...\" value=\"" . $row["description"] . "\" required></textarea>";
echo "<label for=\"start_date\">Start Date:</label>";
echo "<input type=\"date\" name=\"start_date\" id=\"start_date\" value=\"" . $row["start_date"] . "\" required>";
echo "<label for=\"end_date\">End Date:</label>";
echo "<input type=\"date\" name=\"end_date\" id=\"end_date\" value=\"" . $row["end_date"] . "\" required>";
echo "<label for=\"dev_phase\">Current Development Phase:</label>";
?>
<select name="dev_phase" id="dev_phase" required>
<option value="" disabled>Select a phase</option>
<option value="Design" <?php if ($row["phase"] == "design")
echo " selected"; ?>>Design</option>
<option value="Development" <?php if ($row["phase"] == "development")
echo " selected"; ?>>Development
</option>
<option value="Testing" <?php if ($row["phase"] == "testing")
echo " selected"; ?>>Testing</option>
<option value="Deployment" <?php if ($row["phase"] == "deployment")
echo " selected"; ?>>Deployment
</option>
<option value="Complete" <?php if ($row["phase"] == "complete")
echo " selected"; ?>>Maintenance
</option>
</select>
<?php
echo "<button type=\"submit\">Update \"" . $row["title"] . "\" in database as " . $_SESSION['username'] . ".</button>";
?>
</form>
</div>
</div>
</main>
<footer>
<div class="logo-container">
<a href="index.php">
<img src="img/ap.svg" alt="logo">
</a>
</div>
<div class="footer-text">
<span>©2023 M Kalam | [email protected]</span>
</div>
</footer>
<script>
// Validate start and end dates
var startDate = document.getElementById('start_date');
var endDate = document.getElementById('end_date');
var startChangedOnce = false;
startDate.addEventListener('change', function () {
if (!startChangedOnce) {
endDate.value = startDate.value + 1;
startChangedOnce = true;
return;
}
if (startDate.value > endDate.value) {
alert('Start date must be before end date.');
startDate.value = '';
}
});
endDate.addEventListener('change', function () {
if (startDate.value > endDate.value) {
alert('End date must be after start date.');
endDate.value = '';
}
});
<?php
echo "document.getElementById('project_description').value = '" . $row["description"] . "';";
?>
</script>
</body>
</html>