-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_document.php
More file actions
187 lines (155 loc) · 5.46 KB
/
edit_document.php
File metadata and controls
187 lines (155 loc) · 5.46 KB
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
<?php
session_start();
// Σύνδεση με τη βάση δεδομένων χρησιμοποιώντας τον profile χρήστη
$host = "localhost";
$dbname = "student4198partB";
$username = "profileUSER";
$password = "Testing1001@";
$conn = new mysqli($host, $username, $password, $dbname);
// Έλεγχος σύνδεσης
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Έλεγχος αν ο χρήστης είναι Tutor
if (!isset($_SESSION['rolos']) || $_SESSION['rolos'] !== 'Tutor') {
echo "Μη εξουσιοδοτημένη πρόσβαση.";
exit();
}
// Έλεγχος αν υπάρχει το ID του εγγράφου
if (isset($_GET['id'])) {
$id = intval($_GET['id']);
// Ανάκτηση του εγγράφου από τη βάση
$stmt = $conn->prepare("SELECT * FROM Eggrafa WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result()->fetch_assoc();
if (!$result) {
echo "Το έγγραφο δεν βρέθηκε.";
exit();
}
} else {
echo "Το έγγραφο δεν βρέθηκε.";
exit();
}
// Ενημέρωση του εγγράφου
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$titlos = $_POST['titlos'];
$perigrafi = $_POST['perigrafi'];
if (isset($_FILES['arxeio']) && $_FILES['arxeio']['error'] === UPLOAD_ERR_OK) {
$file_path = 'uploads/' . basename($_FILES['arxeio']['name']);
// Διαγραφή του παλιού αρχείου
if (file_exists($result['arxeio'])) {
unlink($result['arxeio']);
}
// Μεταφόρτωση νέου αρχείου
if (move_uploaded_file($_FILES['arxeio']['tmp_name'], $file_path)) {
$stmt = $conn->prepare("UPDATE Eggrafa SET titlos = ?, perigrafi = ?, arxeio = ? WHERE id = ?");
$stmt->bind_param("sssi", $titlos, $perigrafi, $file_path, $id);
} else {
echo "Σφάλμα κατά τη μεταφόρτωση του αρχείου.";
exit();
}
} else {
$stmt = $conn->prepare("UPDATE Eggrafa SET titlos = ?, perigrafi = ? WHERE id = ?");
$stmt->bind_param("ssi", $titlos, $perigrafi, $id);
}
if ($stmt->execute()) {
// Επιστροφή στην προηγούμενη σελίδα
header('Location: documents.php');
exit();
} else {
echo "Υπήρξε πρόβλημα κατά την ενημέρωση του εγγράφου.";
exit();
}
}
?>
<!DOCTYPE html>
<html lang="el">
<head>
<meta charset="UTF-8">
<title>Επεξεργασία Εγγράφου</title>
<style>
body {
font-family: sans-serif;
background-color: #f0f0f0;
}
html, body {
height: 100%;
margin: 0;
}
.container {
height: 100%;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
background-image: url("im2.jpg");
background-size: cover;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
h1 {
text-align: center;
color: white;
}
form {
background-color: rgba(255, 255, 255, 0.9);
padding: 20px;
border-radius: 10px;
display: inline-block;
text-align: left;
}
form label {
display: block;
margin: 10px 0 5px;
font-weight: bold;
color: black;
}
form input, form textarea {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
margin-bottom: 15px;
color: black;
}
form textarea {
resize: both;
min-height: 150px;
}
form button {
background-color: #007bff;
color: #fff;
border: none;
padding: 10px;
cursor: pointer;
border-radius: 5px;
}
form button:hover {
background-color: #0056b3;
}
.current-file {
font-size: 0.9em;
color: #555;
}
</style>
</head>
<body>
<div class="container">
<h1>Επεξεργασία Εγγράφου</h1>
<form action="" method="post" enctype="multipart/form-data">
<label for="titlos">Τίτλος:</label>
<input type="text" id="titlos" name="titlos" value="<?php echo htmlspecialchars($result['titlos']); ?>" required>
<label for="perigrafi">Περιγραφή:</label>
<textarea id="perigrafi" name="perigrafi" required><?php echo htmlspecialchars($result['perigrafi']); ?></textarea>
<label for="arxeio">Αρχείο:</label>
<input type="file" id="arxeio" name="arxeio">
<p class="current-file">Τρέχον Αρχείο: <?php echo htmlspecialchars($result['arxeio']); ?></p>
<button type="submit">Αποθήκευση</button>
</form>
</div>
</body>
</html>