Fixing mobile view and improving some menus.
This commit is contained in:
@@ -47,7 +47,44 @@ if (isset($_GET['delete'])) {
|
||||
<input type="text" name="room" placeholder="Laboratorio (opzionale)">
|
||||
<button type="submit">Aggiungi</button>
|
||||
</form>
|
||||
<?php
|
||||
// 1. Aggiornamento dati
|
||||
if(isset($_POST['update'])){
|
||||
$id = intval($_POST['id']);
|
||||
$name = $conn->real_escape_string($_POST['name']);
|
||||
$teacher = $conn->real_escape_string($_POST['teacher']);
|
||||
$room = $conn->real_escape_string($_POST['room']);
|
||||
|
||||
$conn->query("UPDATE subjects
|
||||
SET name='$name', teacher='$teacher', room='$room'
|
||||
WHERE id=$id");
|
||||
}
|
||||
// 2. Mostrare il form se edit richiesto
|
||||
if(isset($_GET['edit'])){
|
||||
$id = intval($_GET['edit']);
|
||||
$res = $conn->query("SELECT * FROM subjects WHERE id=$id");
|
||||
if($res->num_rows > 0){
|
||||
$subject = $res->fetch_assoc();
|
||||
?>
|
||||
<h3>Modifica materia</h3>
|
||||
<form method="post" action="subjects.php">
|
||||
<input type="hidden" name="id" value="<?php echo $subject['id']; ?>">
|
||||
|
||||
<label>Materia:</label>
|
||||
<input type="text" name="name" value="<?php echo htmlspecialchars($subject['name']); ?>"><br>
|
||||
|
||||
<label>Docente:</label>
|
||||
<input type="text" name="teacher" value="<?php echo htmlspecialchars($subject['teacher']); ?>"><br>
|
||||
|
||||
<label>Aula:</label>
|
||||
<input type="text" name="room" value="<?php echo htmlspecialchars($subject['room']); ?>"><br>
|
||||
|
||||
<button type="submit" name="update">Salva modifiche</button>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
<table>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
@@ -64,7 +101,10 @@ if (isset($_GET['delete'])) {
|
||||
<td>{$row['name']}</td>
|
||||
<td>{$row['teacher']}</td>
|
||||
<td>{$row['room']}</td>
|
||||
<td><a href='subjects.php?delete={$row['id']}' class='delete-link'>Elimina</a></td>
|
||||
<td>
|
||||
<a href='subjects.php?edit={$row['id']}' class='edit-link'>Modifica</a> |
|
||||
<a href='subjects.php?delete={$row['id']}' class='delete-link'>Elimina</a>
|
||||
</td>
|
||||
</tr>";
|
||||
}
|
||||
?>
|
||||
|
@@ -106,62 +106,115 @@ td:hover {
|
||||
td { padding-left: 50%; }
|
||||
}
|
||||
*/
|
||||
|
||||
/* --- tuoi stili desktop (questi restano uguali) --- */
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
max-width: 1000px;
|
||||
margin: 0 auto;
|
||||
background: #fff;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
th, td {
|
||||
border: 1px solid #ccc;
|
||||
text-align: center;
|
||||
padding: 10px;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
th {
|
||||
background-color: #e0e0e0;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
td {
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
td:hover {
|
||||
background-color: #f7f7f7;
|
||||
}
|
||||
|
||||
.subject {
|
||||
font-weight: bold;
|
||||
color: #1f618d;
|
||||
}
|
||||
|
||||
.teacher {
|
||||
font-size: 0.9em;
|
||||
color: #2c3e50;
|
||||
}
|
||||
|
||||
.room {
|
||||
font-size: 0.8em;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* --- qui sostituisci con la versione migliorata --- */
|
||||
@media (max-width: 768px) {
|
||||
table, thead, tbody, th, td, tr {
|
||||
display: block;
|
||||
width: 100%;
|
||||
table {
|
||||
box-shadow: none;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
tr {
|
||||
margin-bottom: 15px;
|
||||
padding: 0;
|
||||
border-bottom: 2px solid #ddd;
|
||||
}
|
||||
|
||||
th {
|
||||
display: none;
|
||||
margin-bottom: 20px;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 6px rgba(0,0,0,0.08);
|
||||
overflow: hidden;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
td {
|
||||
position: relative;
|
||||
padding-left: 50%;
|
||||
text-align: left;
|
||||
padding: 8px 8px 8px 50%;
|
||||
border: none;
|
||||
border-bottom: 1px solid #eee;
|
||||
min-height: 50px; /* ensures consistent vertical spacing */
|
||||
box-sizing: border-box;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
td::before {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
left: 10px;
|
||||
width: 40%;
|
||||
font-weight: bold;
|
||||
white-space: nowrap;
|
||||
color: #1f618d;
|
||||
font-size: 0.85em;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
content: attr(data-label);
|
||||
}
|
||||
|
||||
/* make content stack nicely */
|
||||
td > .subject,
|
||||
td > .teacher,
|
||||
td > .subject {
|
||||
font-weight: 600;
|
||||
font-size: 1em;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
td > .teacher {
|
||||
font-size: 0.85em;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
td > .room {
|
||||
display: block;
|
||||
margin: 2px 0;
|
||||
font-size: 0.75em;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
td:last-child {
|
||||
border-bottom: 0;
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* Extra small screens */
|
||||
@media (max-width: 480px) {
|
||||
td {
|
||||
padding-left: 55%;
|
||||
padding-left: 45%;
|
||||
}
|
||||
td::before {
|
||||
width: 45%;
|
||||
width: 40%;
|
||||
font-size: 0.8em;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -60,11 +60,31 @@ if ($res->num_rows === 0) {
|
||||
WHERE subjects.room='". $conn->real_escape_string($room) ."'
|
||||
AND timetable.day='$d' AND timetable.hour=$hnum
|
||||
");
|
||||
if($row = $q->fetch_assoc()){
|
||||
|
||||
if($q->num_rows > 0){
|
||||
$subject = null;
|
||||
$entries = [];
|
||||
|
||||
while($row = $q->fetch_assoc()){
|
||||
// salvo materia (prendo la prima, di solito è la stessa per tutti)
|
||||
if($subject === null) {
|
||||
$subject = $row['subject_name'];
|
||||
}
|
||||
// accumulo classi + docente
|
||||
$entries[] = $row['class_name'] . " (" . $row['teacher'] . ")";
|
||||
}
|
||||
|
||||
// unisci le classi con " e " se sono 2, altrimenti virgole + "e" finale
|
||||
if(count($entries) > 1){
|
||||
$last = array_pop($entries);
|
||||
$entries_list = implode(", ", $entries) . " e " . $last;
|
||||
} else {
|
||||
$entries_list = $entries[0];
|
||||
}
|
||||
|
||||
echo "<td data-label='$d'>
|
||||
<div class='subject'>{$row['subject_name']}</div>
|
||||
<div class='teacher'>{$row['teacher']}</div>
|
||||
<div class='room'>{$row['class_name']}</div>
|
||||
<div class='subject'>$subject</div>
|
||||
<div class='room'>$entries_list</div>
|
||||
</td>";
|
||||
} else {
|
||||
echo "<td data-label='$d'></td>";
|
||||
|
@@ -54,10 +54,33 @@ if ($res->num_rows === 0) {
|
||||
FROM timetable
|
||||
LEFT JOIN subjects ON timetable.subject_id = subjects.id
|
||||
WHERE class_id=$class_id AND day='$d' AND hour=$hnum");
|
||||
if($row = $q->fetch_assoc()){
|
||||
echo "<td data-label='$d'><div class='subject'>{$row['name']}</div>
|
||||
<div class='teacher'>{$row['teacher']}</div>
|
||||
<div class='room'>{$row['room']}</div></td>";
|
||||
|
||||
if($q->num_rows > 0){
|
||||
$row = $q->fetch_assoc();
|
||||
$subject = $row['name'];
|
||||
$room = $row['room'];
|
||||
|
||||
// metto il primo docente
|
||||
$teachers = [$row['teacher']];
|
||||
|
||||
// aggiungo eventuali altri docenti
|
||||
while($row = $q->fetch_assoc()){
|
||||
$teachers[] = $row['teacher'];
|
||||
}
|
||||
|
||||
// se più docenti -> unisci con virgola e "e" finale
|
||||
if(count($teachers) > 1){
|
||||
$last = array_pop($teachers);
|
||||
$teachers_list = implode(", ", $teachers) . " e " . $last;
|
||||
} else {
|
||||
$teachers_list = $teachers[0];
|
||||
}
|
||||
|
||||
echo "<td data-label='$d'>
|
||||
<div class='subject'>$subject</div>
|
||||
<div class='teacher'>$teachers_list</div>
|
||||
<div class='room'>$room</div>
|
||||
</td>";
|
||||
} else {
|
||||
echo "<td data-label='$d'></td>";
|
||||
}
|
||||
|
Reference in New Issue
Block a user