-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommunication.php
More file actions
255 lines (230 loc) · 7.82 KB
/
communication.php
File metadata and controls
255 lines (230 loc) · 7.82 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
session_start();
if(!isset($_SESSION['user_id'])){
header("Location: login.php");
exit();
}
?>
<!DOCTYPE html>
<html lang="el">
<head>
<meta charset="UTF-8">
<title>Επικοινωνία</title>
<style>
/* --- Βασικό Layout και Sidebar --- */
body {
font-family: Arial, sans-serif;
margin: 0; padding: 0;
}
#header {
width: 100%;
background-color: #333;
color: white;
padding: 10px 0;
text-align: center;
position: fixed; top: 0; z-index: 1000;
}
#header h1 { margin: 0; }
#container {
display: flex;
margin-top: 60px;
height: calc(100vh - 60px);
}
#sidebar {
width: 20%;
background-color: #f0f0f0;
padding: 10px;
position: fixed; top: 60px; bottom: 0;
overflow-y: auto;
}
#sidebar button {
display: block;
width: 100%;
margin-bottom: 20px;
padding: 10px;
border: none;
background-color: #e7e7e7;
cursor: pointer;
text-align: center;
}
#sidebar button:hover {
background-color: #d7d7d7;
}
#content {
flex: 1;
margin-left: 25%;
padding: 20px;
}
#topButton {
position: fixed;
bottom: 20px; right: 20px;
background-color: #333; color: white;
padding: 10px 15px; text-decoration: none;
font-size: 14px; border-radius: 5px;
}
#topButton:hover {
background-color: #555;
}
/* --- Στυλ για τη φόρμα Επικοινωνίας --- */
.form-field {
display: flex;
align-items: center;
margin-bottom: 15px;
gap: 10px; /* Προσθέτει μικρή απόσταση μεταξύ label και input */
}
.form-field label {
width: 100px; /* Σταθερό πλάτος για να ευθυγραμμιστούν όλα τα labels */
font-weight: bold;
text-align: left; /* Στοίχιση αριστερά */
}
.form-field input,
.form-field textarea {
width: 300px;
padding: 5px;
}
.form-field textarea {
height: 80px;
}
/* --- Κουμπί "Αποστολή" --- */
.btn-send {
background-color: #007bff;
color: #fff;
border: none;
padding: 10px 16px;
cursor: pointer;
border-radius: 5px;
font-size: 14px;
transition: background-color 0.3s;
}
.btn-send:hover {
background-color: #0056b3;
}
/* --- Ειδοποίηση επιτυχίας/σφάλματος --- */
#msgContainer {
display: none;
padding: 10px 15px;
margin-left: 80px;
margin-top: 10px;
border-radius: 5px;
}
.msg-success {
background-color: #d4edda;
color: #155724;
}
.msg-error {
background-color: #f8d7da;
color: #721c24;
}
/* Κουμπί Αποσύνδεσης */
#logout-btn {
position: fixed;
top: 60px; right: 20px;
background-color: red;
color: white;
border: none;
padding: 10px 15px;
cursor: pointer;
border-radius: 5px;
font-weight: bold;
}
#logout-btn:hover {
background-color: darkred;
}
</style>
</head>
<body>
<div id="header">
<h1>Επικοινωνία</h1>
</div>
<div id="container">
<div id="sidebar">
<button onclick="location.href='index.php'">Αρχική Σελίδα</button>
<button onclick="location.href='announcement.php'">Ανακοινώσεις</button>
<button onclick="location.href='communication.php'">Επικοινωνία</button>
<button onclick="location.href='document.php'">Έγγραφα Μαθήματος</button>
<button onclick="location.href='homework.php'">Εργασίες</button>
</div>
<div id="content">
<p>Μπορείτε να επικοινωνήσετε με τον διδάσκοντα με τους εξής 2 τρόπους:</p>
<ul>
<li>Μέσω web φόρμας</li>
<li>Με χρήση e-mail διεύθυνσης</li>
</ul>
<h2>Αποστολή μηνύματος μέσω web φόρμας</h2>
<!-- Δεν βάζουμε action, θα χειριστούμε AJAX -->
<form id="contactForm">
<div class="form-field">
<label for="sender">Αποστολέας:</label>
<input type="email" id="sender" name="sender" required
placeholder="π.χ. your_email@domain.com">
</div>
<div class="form-field">
<label for="subject">Θέμα:</label>
<input type="text" id="subject" name="subject" required>
</div>
<div class="form-field">
<label for="body">Κείμενο:</label><br>
<textarea id="body" name="body" required></textarea>
</div>
<div class="form-field">
<button type="submit" class="btn-send">Αποστολή</button>
</div>
</form>
<!-- Εφήμερο μήνυμα (success / error) -->
<div id="msgContainer"></div>
<hr style="margin-left: 80px;">
<h2>Αποστολή μηνύματος με χρήση email διεύθυνσης</h2>
<p style="margin-left:80px;">
Εναλλακτικά, μπορείτε να στείλετε e-mail στο
<a href="mailto:tutor@csd.auth.test.gr">tutor@csd.auth.test.gr</a>.
</p>
</div>
</div>
<a href="#" id="topButton">Top</a>
<script>
document.getElementById("contactForm").addEventListener("submit", function(e) {
e.preventDefault();
let formData = new FormData(this); // όλα τα πεδία της φόρμας
fetch("send_message.php", {
method: "POST",
body: formData
})
.then(response => response.text())
.then(data => {
console.log("Απάντηση:", data);
const msg = document.getElementById("msgContainer");
msg.style.display = "block";
if (data.includes("εστάλη επιτυχώς")) {
msg.className = "msg-success";
msg.textContent = "Το μήνυμα εστάλη επιτυχώς!";
} else {
msg.className = "msg-error";
msg.textContent = "Σφάλμα: " + data;
}
// το μήνυμα εξαφανίζεται μετά από 3 δευτερόλεπτα
setTimeout(() => {
msg.style.display = "none";
}, 3000);
})
.catch(err => {
console.error("Σφάλμα AJAX:", err);
const msg = document.getElementById("msgContainer");
msg.style.display = "block";
msg.className = "msg-error";
msg.textContent = "Πρόβλημα σύνδεσης με τον server.";
setTimeout(() => {
msg.style.display = "none";
}, 3000);
});
});
</script>
<?php if (isset($_SESSION["user_id"])): ?>
<form action="logout.php" method="post">
<button type="submit" id="logout-btn">Αποσύνδεση</button>
</form>
<?php else: ?>
<a href="login.php" class="btn">Σύνδεση</a>
<?php endif; ?>
<a href="#" id="topButton">Top</a>
</body>
</html>