-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_document.php
More file actions
173 lines (148 loc) · 4.96 KB
/
add_document.php
File metadata and controls
173 lines (148 loc) · 4.96 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
<?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 ($_SESSION['rolos'] != 'Tutor') {
header("Location: documents.php");
exit();
}
//Just in case
$upload_dir = 'uploads';
if (!is_dir($upload_dir)) {
mkdir($upload_dir, 0777, true);
}
// Διαχείριση φόρμας προσθήκης εγγράφου
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = $_POST['title'];
$description = $_POST['description'];
$file_path = $upload_dir . '/' . basename($_FILES['file']['name']);
if ($_FILES['file']['error'] === UPLOAD_ERR_OK && is_uploaded_file($_FILES['file']['tmp_name'])) {
if (move_uploaded_file($_FILES['file']['tmp_name'], $file_path)) {
$stmt = $conn->prepare("INSERT INTO Eggrafa (titlos, perigrafi, arxeio) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $title, $description, $file_path);
if ($stmt->execute()) {
header("Location: documents.php");
exit();
} else {
$error = "Υπήρξε πρόβλημα κατά την προσθήκη του εγγράφου.";
}
} else {
$error = "Σφάλμα κατά τη μετακίνηση του αρχείου στον φάκελο προορισμού.";
}
} else {
$error = "Σφάλμα κατά τη μεταφόρτωση του αρχείου.";
}
}
?>
<!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;
}
h1 {
text-align: center;
color: white;
}
.content {
text-align: center;
line-height: 1.6;
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, form button {
width: 100%;
margin-bottom: 15px;
}
form input, form textarea {
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
color:black;
}
form button {
background-color: #007bff;
color: #fff;
border: none;
padding: 10px;
cursor: pointer;
border-radius: 5px;
}
form button:hover {
background-color: #0056b3;
}
.top-link {
display: inline-block;
margin-top: 20px;
padding: 10px 15px;
background-color: black;
color: #fff;
text-decoration: none;
border-radius: 5px;
font-size: 14px;
}
.top-link:hover {
background-color: black;
color:black;
}
</style>
</head>
<body>
<div class="container">
<h1>Προσθήκη Νέου Εγγράφου</h1>
<div class="content">
<?php if (isset($error)): ?>
<p style="color: red;"><?php echo $error; ?></p>
<?php endif; ?>
<form action="add_document.php" method="post" enctype="multipart/form-data">
<label for="title">Τίτλος:</label>
<input type="text" name="title" id="title" required>
<label for="description">Περιγραφή:</label>
<textarea name="description" id="description" required></textarea>
<label for="file">Αρχείο:</label>
<input type="file" name="file" id="file" required>
<button type="submit">Προσθήκη</button>
</form>
</div>
</div>
</body>
</html>