Compare commits

...

28 Commits

Author SHA1 Message Date
dc1d07c015 fix CSS 2025-10-02 12:01:42 +02:00
d405a0e21c troppe modifiche, non so cosa scrivere 2025-10-02 11:54:59 +02:00
f68162b80b some changes 2025-10-02 08:51:47 +00:00
f98f5a3c07 changes, finishing later 2025-10-02 09:45:24 +02:00
7249325faf fixes 2025-10-02 09:23:38 +02:00
b599691c2e Manage users 2025-10-02 09:17:32 +02:00
8a37f24b40 design fix 2025-10-01 17:10:20 +02:00
725518ca8a move error message 2025-10-01 17:09:19 +02:00
cbf6ef27a2 design fix and add back to link 2025-10-01 17:07:54 +02:00
9c936ed3be how fucking much can I be dumb?? 2025-10-01 16:59:18 +02:00
c3f8b52990 fucking readme 2025-10-01 16:57:57 +02:00
4de8528da2 fix 2025-10-01 16:57:39 +02:00
0265af9dd2 Change password feature (maybe) 2025-10-01 16:55:28 +02:00
e8079c2ce7 fix 2025-10-01 16:33:26 +02:00
fb72f23544 Readme 2025-10-01 15:50:13 +02:00
ddfa3d6dd8 Docker 2025-10-01 15:49:06 +02:00
c619b748fa Docker image integration (beta) 2025-10-01 15:42:34 +02:00
906beaaa4b Integrated auth by default 2025-10-01 15:15:28 +02:00
86826c86bb Merge pull request 'Fixing mobile view and improving some menus.' (#3) from daniele/orario:dev into dev
Reviewed-on: #3
2025-09-27 16:10:38 +00:00
79a4823726 Fixing mobile view and improving some menus. 2025-09-27 18:06:46 +02:00
459663e069 Update README.md 2025-09-22 08:50:14 +00:00
ccbb9806f5 Testo del copyright 2025-09-11 10:30:21 +02:00
07b197c89a Link al codice sorgente 2025-09-11 10:21:10 +02:00
fff1e6cddf altra piccola modifica 2025-09-11 09:58:22 +02:00
9c044b051c Piccola modifica 2025-09-11 09:29:59 +02:00
141d78d08b Change estetica gestione orario 2025-09-11 08:47:26 +02:00
81078ddf9c Change gestione orario 2025-09-11 08:32:33 +02:00
397b2bffe3 Update README.md 2025-09-10 21:56:59 +00:00
23 changed files with 828 additions and 274 deletions

16
Dockerfile Normal file
View File

@@ -0,0 +1,16 @@
FROM php:8.2-apache
RUN docker-php-ext-install mysqli pdo pdo_mysql
COPY htdocs/ /var/www/html/
COPY docker/php/config.php /var/www/html/config/config.php
RUN apt-get update && apt-get install -y \
unzip \
curl \
git \
&& rm -rf /var/lib/apt/lists/*
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version
WORKDIR /var/www/html/admin
RUN composer install --no-interaction
RUN chown -R www-data:www-data /var/www/html
RUN a2enmod rewrite
EXPOSE 80

View File

@@ -1,3 +1,6 @@
## AVVISO IMPORTANTE
Questo è il ramo di SVILUPPO. È inteso per testare le ultime funzionalità e aiutarmi nello sviluppo. La stabilità e il funzionamento del codice non sono garantiti. Usare a proprio rischio e pericolo.
# Orario Scuola # Orario Scuola
Una piattaforma web per visualizzare gli orari scolastici delle classi, degli insegnanti e dei vari laboratori (se presenti) Una piattaforma web per visualizzare gli orari scolastici delle classi, degli insegnanti e dei vari laboratori (se presenti)
@@ -50,28 +53,71 @@ C:\xampp\php\php.exe generate_hash.php <password>
VALUES ('admin', '$2y$10$IS9v8CJNJnRXslV1NWDSquAjJ0GgU1sm6spBmGp6mjTLiNApfGcQi'); VALUES ('admin', '$2y$10$IS9v8CJNJnRXslV1NWDSquAjJ0GgU1sm6spBmGp6mjTLiNApfGcQi');
``` ```
5. **Importa il file ``schema.sql`` nel tuo database MySQL** 5. **Importa il file ``schema.sql`` nel tuo database MySQL**
6. **Modifica il file ``db.php`` cambiando l'host, il nome utente e la password (necessari per la connessione al database MySQL)** 6. **Modifica il file ``config/config.php`` inserendo i valori richiesti**
- Esempio: - Esempio file ``config/config.php``:
```php ```php
$host = "localhost"; <?php
$user = "utente"; // Impostazioni Database
$pass = "password123"; if (!defined('DB_HOST')) {
define('DB_HOST', 'db');
}
if (!defined('DB_USER')) {
define('DB_USER', 'orario');
}
if (!defined('DB_PASS')) {
define('DB_PASS', 'orario');
}
if (!defined('DB_NAME')) {
define('DB_NAME', 'school_timetable');
}
// Impostazioni sito generali
if (!defined('APP_NAME')) {
define('APP_NAME', 'Orario Scuola');
}
if (!defined('YEAR')) {
define('YEAR', '2025/26');
}
// Impostazioni autenticazione dashboard amministrativa
if (!defined('AUTH_TYPE')) {
define('AUTH_TYPE','local'); // Può essere keycloak o local (integrata)
}
if (!defined('KEYCLOAK_DOMAIN')) {
define('KEYCLOAK_DOMAIN','');
}
if (!defined('KEYCLOAK_REALM')) {
define('KEYCLOAK_REALM','');
}
if (!defined('KEYCLOAK_CLIENT_ID')) {
define('KEYCLOAK_CLIENT_ID','');
}
if (!defined('KEYCLOAK_CLIENT_SECRET')) {
define('KEYCLOAK_CLIENT_SECRET','');
}
if (!defined('APP_DOMAIN')) {
define('APP_DOMAIN','');
}
?>
``` ```
7. **Modifica ``admin/login.php`` e ``admin/logout.php`` con i dati di un'istanza keycloak. In caso tu voglia usare l'autenticazione via nome utente e password (e non keycloak), cancella quei due file e rinomina ``admin/login.php.backup`` in ``login.php`` e ``admin/logout.php.backup`` in ``logout.php``** 7. **Apri ``http://localhost`` e goditi il sito**
- Esempio (``login.php`` con keycloak):
```php ## Installazione con Docker
$oidc = new OpenIDConnectClient( NOTA: L'installazione con Docker è in fase di sviluppo attivo, quindi potrebbe non funzionare.
'https://keycloak.local/realms/master/', 1. Installa Docker
'orario', ```bash
'abcdefghijklmnop' curl -fsSL https://get.docker.com | bash
);
$oidc->setRedirectURL('https://orario.local/admin/login.php');
``` ```
- Esempio (``logout.php`` con keycloak): 2. Compila e crea il container:
```php ```bash
header('Location: https://keycloak.local/realms/master/protocol/openid-connect/logout?post_logout_redirect_uri=https://orario.local&client_id=orario'); git clone https://git.vichingo455.freeddns.org/emmev-code/orario
cd orario
git checkout dev # richiesto per passare alla versione di sviluppo
docker compose up -d --build
``` ```
8. **Apri ``http://localhost`` e goditi il sito** 3. Il container dovrebbe diventare disponibile su ``http://localhost:8080``
### Per utenti Docker avanzati
Se sei un utente Docker avanzato e vuoi personalizzare puoi modificare la configurazione di docker nei file ``docker/php/config.php``, ``docker-compose.yml`` e ``Dockerfile`` per adattare tutto al tuo ambiente.
Per la maggior parte degli utenti consigliamo di usare la configurazione per Docker predefinita.
## Licenza ## Licenza
**Orario Scuola, Copyright (C) 2025 EmmeV.** **Orario Scuola, Copyright (C) 2025 EmmeV.**

23
docker-compose.yml Normal file
View File

@@ -0,0 +1,23 @@
services:
web:
build: .
container_name: orario-web
ports:
- "8080:80"
depends_on:
- db
restart: unless-stopped
db:
image: mariadb:11
container_name: orario-db
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: P@ssw0rd
MYSQL_DATABASE: school_timetable
MYSQL_USER: orario
MYSQL_PASSWORD: orario
volumes:
- db_data:/var/lib/mysql
- ./schema.sql:/docker-entrypoint-initdb.d/init.sql:ro
volumes:
db_data:

41
docker/php/config.php Normal file
View File

@@ -0,0 +1,41 @@
<?php
// Impostazioni Database
if (!defined('DB_HOST')) {
define('DB_HOST', 'db');
}
if (!defined('DB_USER')) {
define('DB_USER', 'orario');
}
if (!defined('DB_PASS')) {
define('DB_PASS', 'orario');
}
if (!defined('DB_NAME')) {
define('DB_NAME', 'school_timetable');
}
// Impostazioni sito generali
if (!defined('APP_NAME')) {
define('APP_NAME', 'Orario Scuola');
}
if (!defined('YEAR')) {
define('YEAR', '2025/26');
}
// Impostazioni autenticazione dashboard amministrativa
if (!defined('AUTH_TYPE')) {
define('AUTH_TYPE','local'); // Può essere keycloak o local (integrata)
}
if (!defined('KEYCLOAK_DOMAIN')) {
define('KEYCLOAK_DOMAIN','');
}
if (!defined('KEYCLOAK_REALM')) {
define('KEYCLOAK_REALM','');
}
if (!defined('KEYCLOAK_CLIENT_ID')) {
define('KEYCLOAK_CLIENT_ID','');
}
if (!defined('KEYCLOAK_CLIENT_SECRET')) {
define('KEYCLOAK_CLIENT_SECRET','');
}
if (!defined('APP_DOMAIN')) {
define('APP_DOMAIN','');
}
?>

1
docker/readme.txt Normal file
View File

@@ -0,0 +1 @@
These files are used by docker compose builder to create a working image in one command.

View File

@@ -1,7 +1,7 @@
<?php <?php
session_start(); session_start();
if (!isset($_SESSION['admin'])) { header("Location: login.php"); exit; } if (!isset($_SESSION['admin'])) { header("Location: login.php"); exit; }
include("../db.php"); include("../lib/db.php");
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['name'])) { if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['name'])) {
$name = $_POST['name']; $name = $_POST['name'];
@@ -57,7 +57,7 @@ if (isset($_GET['delete'])) {
<p> <p>
Nota: Questa pagina si vede meglio da computer desktop. Se sei da computer, puoi ignorare questo messaggio. Nota: Questa pagina si vede meglio da computer desktop. Se sei da computer, puoi ignorare questo messaggio.
</p> </p>
<p style="text-align: center;">Copyright (C) 2025 EmmeV. All rights reserved.</p> <p style="text-align: center;">Copyright (C) 2025 EmmeV. - Released under <a href="https://git.vichingo455.freeddns.org/emmev-code/orario/src/branch/stable/LICENSE.txt" target="_blank">GNU AGPL 3.0 License</a>.</p>
</div> </div>
</body> </body>
</html> </html>

View File

@@ -29,12 +29,21 @@ if (!isset($_SESSION['admin'])) {
<a href="classes.php">Gestisci Classi</a> <a href="classes.php">Gestisci Classi</a>
<a href="subjects.php">Gestisci Materie</a> <a href="subjects.php">Gestisci Materie</a>
<a href="timetable.php">Gestisci Orario</a> <a href="timetable.php">Gestisci Orario</a>
<!--<a href="logout.php">Logout</a>--> <?php
if ($_SESSION['auth_type'] === 'local') {
echo '<a href="password.php">Cambia Password</a>';
}
?>
<?php
if ($_SESSION['auth_type'] === 'local' && $_SESSION['admin'] === 'admin') {
echo '<a href="users.php">Gestisci Amministratori</a>';
}
?>
</p> </p>
<p> <p>
Nota: Questa pagina si vede meglio da computer desktop. Se sei da computer, puoi ignorare questo messaggio. Nota: Questa pagina si vede meglio da computer desktop. Se sei da computer, puoi ignorare questo messaggio.
</p> </p>
<p style="text-align: center;">Copyright (C) 2025 EmmeV. All rights reserved.</p> <p style="text-align: center;">Copyright (C) 2025 EmmeV. - Released under <a href="https://git.vichingo455.freeddns.org/emmev-code/orario/src/branch/stable/LICENSE.txt" target="_blank">GNU AGPL 3.0 License</a>.</p>
</div> </div>
</body> </body>
</html> </html>

View File

@@ -1,18 +1,74 @@
<?php <?php
require 'vendor/autoload.php';
use Jumbojett\OpenIDConnectClient; use Jumbojett\OpenIDConnectClient;
require 'vendor/autoload.php';
session_start(); session_start();
include("../lib/db.php");
if ($_SERVER["REQUEST_METHOD"] == "POST" && AUTH_TYPE == 'local') {
$username = $_POST['username'];
$password = $_POST['password'];
$stmt = $conn->prepare("SELECT * FROM admin WHERE username = ?");
$stmt->bind_param("s", $username);
$stmt->execute();
$res = $stmt->get_result();
if ($row = $res->fetch_assoc()) {
if (password_verify($password, $row['password'])) {
$_SESSION['admin'] = $row['username'];
$_SESSION['auth_type'] = 'local';
header("Location: index.php");
exit;
}
}
$error = "Credenziali non valide";
}
if (AUTH_TYPE == 'local') {
echo <<<HTML
<!DOCTYPE html>
<html>
<head>
<title>Login Admin</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="navbar">
<div class="logo">Admin Dashboard</div>
<div class="links">
<a href="/">Torna al sito</a>
</div>
</div>
<!-- Container login -->
<div class="login-container">
<h1>Login Admin</h1>
<form method="post">
<input type="text" name="username" placeholder="Username" required><br>
<input type="password" name="password" placeholder="Password" required><br>
<button type="submit">Login</button>
</form>
HTML;
if(isset($error)) echo "<br><div class='error'>$error</div>";
echo <<<HTML
</div>
<p style="text-align: center;">Copyright (C) 2025 EmmeV. - Released under <a href="https://git.vichingo455.freeddns.org/emmev-code/orario/src/branch/stable/LICENSE.txt" target="_blank">GNU AGPL 3.0 License</a>.</p>
</body>
</html>
HTML;
}
else if (AUTH_TYPE === 'keycloak') {
// Configura il client Keycloak // Configura il client Keycloak
$oidc = new OpenIDConnectClient( $oidc = new OpenIDConnectClient(
'https://<KEYCLOAK_URL>/realms/<REALM>/', 'https://' + KEYCLOAK_DOMAIN + '/realms/' + KEYCLOAK_REALM + '/',
'<CLIENT_ID>', KEYCLOAK_CLIENT_ID,
'<CLIENT_SECRET>' KEYCLOAK_CLIENT_SECRET
); );
// Redirect post-login // Redirect post-login
$oidc->setRedirectURL('https://<APP_DOMAIN>/admin/login.php'); $oidc->setRedirectURL('https://' + APP_DOMAIN + '/admin/login.php');
$oidc->authenticate(); $oidc->authenticate();
$userinfo = $oidc->getVerifiedClaims(); $userinfo = $oidc->getVerifiedClaims();
$_SESSION['admin'] = $userinfo->preferred_username; $_SESSION['admin'] = $userinfo->preferred_username;
$_SESSION['auth_type'] = 'keycloak';
header("Location: index.php"); header("Location: index.php");
exit; exit;
}
?>

View File

@@ -1,50 +0,0 @@
<?php
session_start();
include("../db.php");
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$password = $_POST['password'];
$stmt = $conn->prepare("SELECT * FROM admin WHERE username = ?");
$stmt->bind_param("s", $username);
$stmt->execute();
$res = $stmt->get_result();
if ($row = $res->fetch_assoc()) {
if (password_verify($password, $row['password'])) {
$_SESSION['admin'] = $row['username'];
header("Location: index.php");
exit;
}
}
$error = "Credenziali non valide";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login Admin</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="navbar">
<div class="logo">Admin Dashboard</div>
<div class="links">
<a href="/">Torna al sito</a>
</div>
</div>
<!-- Container login -->
<div class="login-container">
<h1>Login Admin</h1>
<?php if(isset($error)) echo "<div class='error'>$error</div>"; ?>
<form method="post">
<input type="text" name="username" placeholder="Username" required><br>
<input type="password" name="password" placeholder="Password" required><br>
<button type="submit">Login</button>
</form>
</div>
<p style="text-align: center;">Copyright (C) 2025 EmmeV. All rights reserved.</p>
</body>
</html>

View File

@@ -1,5 +1,9 @@
<?php <?php
include("../config/config.php");
session_start(); session_start();
session_destroy(); session_destroy();
header('Location: https://<KEYCLOAK_URL>/realms/<REALM>/protocol/openid-connect/logout?post_logout_redirect_uri=https://<APP_DOMAIN>&client_id=<CLIENT_ID>'); if (AUTH_TYPE === 'local')
exit; header("Location: /index.php");
else if (AUTH_TYPE === 'keycloak')
header('Location: https://' + KEYCLOAK_DOMAIN + '/realms/' + KEYCLOAK_REALM + '/protocol/openid-connect/logout?post_logout_redirect_uri=https://' + APP_DOMAIN + '&client_id=' + KEYCLOAK_CLIENT_ID);
?>

View File

@@ -1,5 +0,0 @@
<?php
session_start();
session_destroy();
header("Location: /index.php");
?>

82
htdocs/admin/password.php Normal file
View File

@@ -0,0 +1,82 @@
<?php
session_start();
include("../lib/db.php");
if (!isset($_SESSION['admin']) || $_SESSION['auth_type'] != 'local') {
header("Location: login.php");
exit;
}
$message = '';
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$old = $_POST['old_password'];
$new = $_POST['new_password'];
$confirm = $_POST['confirm_password'];
$user = $_SESSION['admin'];
if ($new !== $confirm) {
$message = "Le nuove password non coincidono.";
} else {
// Recupera hash password attuale
$stmt = $conn->prepare("SELECT password FROM admin WHERE username = ?");
$stmt->bind_param("s", $user);
$stmt->execute();
$res = $stmt->get_result();
$row = $res->fetch_assoc();
if ($row && password_verify($old, $row['password'])) {
$newHash = password_hash($new, PASSWORD_DEFAULT);
$stmt = $conn->prepare("UPDATE admin SET password = ? WHERE username = ?");
$stmt->bind_param("ss", $newHash, $user);
$stmt->execute();
$message = "Password cambiata con successo.";
} else {
$message = "Password attuale errata.";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Cambia Password</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="navbar">
<div class="logo">Admin Dashboard</div>
<div class="links">
<a href="index.php">Dashboard</a>
<a href="logout.php">Logout</a>
</div>
</div>
<div class="admin-container">
<h1>Cambia Password</h1>
<a href="index.php" class="back-link">⬅ Torna al Dashboard</a>
<form method="POST">
<label>Password attuale:<br>
<input type="password" name="old_password" required>
</label><br><br>
<label>Nuova password:<br>
<input type="password" name="new_password" required>
</label><br><br>
<label>Conferma nuova password:<br>
<input type="password" name="confirm_password" required>
</label><br><br>
<button type="submit">Cambia password</button>
</form>
<?php if ($message): ?>
<p style="color:<?php echo strpos($message,'successo')!==false ? 'green':'red'; ?>;"><?php echo $message; ?></p>
<?php endif; ?>
</div>
</body>
</html>

View File

@@ -104,7 +104,8 @@ body {
text-align: center; text-align: center;
} }
.admin-container input[type="text"] { .admin-container input[type="text"],
.admin-container input[type="password"] {
padding: 8px 12px; padding: 8px 12px;
border: 1px solid #ccc; border: 1px solid #ccc;
border-radius: 6px; border-radius: 6px;
@@ -336,6 +337,7 @@ body {
.admin-container form select, .admin-container form select,
.admin-container form input[type="text"], .admin-container form input[type="text"],
.admin-container input[type="password"],
.admin-container form button { .admin-container form button {
width: 100%; width: 100%;
margin: 5px 0; margin: 5px 0;
@@ -409,6 +411,7 @@ body {
.admin-container form select, .admin-container form select,
.admin-container form input[type="text"], .admin-container form input[type="text"],
.admin-container input[type="password"],
.admin-container form button { .admin-container form button {
font-size: 0.95em; font-size: 0.95em;
} }

View File

@@ -1,7 +1,7 @@
<?php <?php
session_start(); session_start();
if (!isset($_SESSION['admin'])) { header("Location: login.php"); exit; } if (!isset($_SESSION['admin'])) { header("Location: login.php"); exit; }
include("../db.php"); include("../lib/db.php");
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['name'])) { if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['name'])) {
$name = $_POST['name']; $name = $_POST['name'];
@@ -47,7 +47,44 @@ if (isset($_GET['delete'])) {
<input type="text" name="room" placeholder="Laboratorio (opzionale)"> <input type="text" name="room" placeholder="Laboratorio (opzionale)">
<button type="submit">Aggiungi</button> <button type="submit">Aggiungi</button>
</form> </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> <table>
<tr> <tr>
<th>ID</th> <th>ID</th>
@@ -64,7 +101,10 @@ if (isset($_GET['delete'])) {
<td>{$row['name']}</td> <td>{$row['name']}</td>
<td>{$row['teacher']}</td> <td>{$row['teacher']}</td>
<td>{$row['room']}</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>"; </tr>";
} }
?> ?>
@@ -72,7 +112,7 @@ if (isset($_GET['delete'])) {
<p> <p>
Nota: Questa pagina si vede meglio da computer desktop. Se sei da computer, puoi ignorare questo messaggio. Nota: Questa pagina si vede meglio da computer desktop. Se sei da computer, puoi ignorare questo messaggio.
</p> </p>
<p style="text-align: center;">Copyright (C) 2025 EmmeV. All rights reserved.</p> <p style="text-align: center;">Copyright (C) 2025 EmmeV. - Released under <a href="https://git.vichingo455.freeddns.org/emmev-code/orario/src/branch/stable/LICENSE.txt" target="_blank">GNU AGPL 3.0 License</a>.</p>
</div> </div>
</body> </body>

View File

@@ -1,33 +1,53 @@
<?php <?php
session_start(); session_start();
if (!isset($_SESSION['admin'])) { header("Location: login.php"); exit; } if (!isset($_SESSION['admin'])) { header("Location: login.php"); exit; }
include("../db.php"); include("../lib/db.php");
if ($_SERVER["REQUEST_METHOD"] == "POST") { // --- Recupera tutte le materie ---
$class_id = $_POST['class_id']; $subjects = [];
$day = $_POST['day']; $res = $conn->query("SELECT * FROM subjects ORDER BY name ASC");
$hour = $_POST['hour']; while ($r = $res->fetch_assoc()) {
$subject_id = $_POST['subject_id']; $label = $r['name'];
$conn->query("INSERT INTO timetable (class_id,day,hour,subject_id) VALUES ($class_id,'$day',$hour,$subject_id)"); if (!empty($r['teacher'])) $label .= " ({$r['teacher']})";
header("Location: timetable.php"); exit; if (!empty($r['room'])) $label .= " ({$r['room']})";
} $subjects[] = ['id' => $r['id'], 'label' => $label];
?>
<?php
include("../db.php"); // o il percorso corretto al tuo DB
// Funzione per eliminare una voce del timetable
function deleteTimetableEntry($conn, $id) {
$id = intval($id); // sicurezza
$conn->query("DELETE FROM timetable WHERE id=$id");
} }
// Se è stato cliccato il link "Elimina" // --- Salvataggio orario ---
if(isset($_GET['delete'])) { if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['class_id']) && isset($_POST['subject'])) {
deleteTimetableEntry($conn, $_GET['delete']); $class_id = intval($_POST['class_id']);
// Dopo l'eliminazione, reindirizza per evitare duplicazioni if ($class_id > 0) {
header("Location: timetable.php"); // Cancella solo l'orario di questa classe
$conn->query("DELETE FROM timetable WHERE class_id=$class_id");
foreach ($_POST['subject'] as $day => $hours) {
foreach ($hours as $hour => $sub_ids) {
foreach ($sub_ids as $subject_id) {
$subject_id = intval($subject_id);
if (!empty($subject_id)) {
$conn->query("INSERT INTO timetable (class_id, day, hour, subject_id)
VALUES ($class_id, '" . $conn->real_escape_string($day) . "', $hour, $subject_id)");
}
}
}
}
header("Location: timetable.php?class_id=$class_id&saved=1");
exit; exit;
} }
}
// --- Selezione classe corrente ---
$class_id = isset($_GET['class_id']) ? intval($_GET['class_id']) : 0;
// --- Precaricamento dati orario ---
$preselectedData = [];
if ($class_id > 0) {
$res = $conn->query("SELECT * FROM timetable WHERE class_id=$class_id");
while ($r = $res->fetch_assoc()) {
$preselectedData[$r['day']][$r['hour']][] = $r['subject_id'];
}
}
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@@ -35,9 +55,25 @@ if(isset($_GET['delete'])) {
<title>Gestisci Orario</title> <title>Gestisci Orario</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<style>
.subject-container select { min-width: 120px; }
.subject-container button { cursor: pointer; margin-left: 3px; }
.admin-container { max-width: 95%; margin: auto; background: #fff; padding: 15px; border-radius: 8px; }
table { border-collapse: collapse; width: 100%; overflow-x: auto; display: block; }
th, td { text-align: center; padding: 6px; border: 1px solid #ccc; }
@media (max-width: 768px) {
table { font-size: 14px; }
th, td { padding: 4px; }
}
.saved-message {
margin-top: 15px;
text-align: center;
font-weight: bold;
color: green;
}
</style>
</head> </head>
<body> <body>
<!-- Navbar -->
<div class="navbar"> <div class="navbar">
<div class="logo">Admin Dashboard</div> <div class="logo">Admin Dashboard</div>
<div class="links"> <div class="links">
@@ -52,98 +88,96 @@ if(isset($_GET['delete'])) {
<form method="POST" autocomplete="off"> <form method="POST" autocomplete="off">
Classe: Classe:
<select name="class_id" required> <select name="class_id" required onchange="window.location='timetable.php?class_id='+this.value;">
<option value="" selected disabled>--Scegli un'opzione--</option> <option value="" disabled <?= $class_id === 0 ? 'selected' : '' ?>>--Scegli un'opzione--</option>
<?php <?php
$res = $conn->query("SELECT * FROM classes ORDER BY name ASC"); $res = $conn->query("SELECT * FROM classes ORDER BY name ASC");
while($r=$res->fetch_assoc())
echo "<option value='{$r['id']}'>{$r['name']}</option>";
?>
</select>
Giorno:
<select name="day" required>
<option value="" selected disabled>--Scegli un'opzione--</option>
<option>Lunedì</option><option>Martedì</option><option>Mercoledì</option>
<option>Giovedì</option><option>Venerdì</option><option>Sabato</option>
</select>
Ora:
<select name="hour" required>
<option value="" selected disabled>--Scegli un'opzione--</option>
<option value="1">1</option><option value="2">2</option><option value="3">3</option>
<option value="4">4</option><option value="5">5</option><option value="6">6</option>
</select>
Materia:
<select name="subject_id" required>
<option value="" selected disabled>--Scegli un'opzione--</option>
<?php
$res = $conn->query("SELECT * FROM subjects ORDER BY name ASC");
while ($r = $res->fetch_assoc()) { while ($r = $res->fetch_assoc()) {
$label = $r['name']; $selected = ($class_id == $r['id']) ? 'selected' : '';
if(!empty($r['teacher'])) { echo "<option value='{$r['id']}' $selected>{$r['name']}</option>";
$label .= " (" . $r['teacher'] . ")";
}
if(!empty($r['room'])) {
$label .= " (" . $r['room'] . ")";
}
echo "<option value='{$r['id']}'>" . htmlspecialchars($label) . "</option>";
} }
?> ?>
</select> </select>
<button type="submit">Aggiungi</button> <br><br>
</form> <?php if ($class_id > 0): ?>
<?php <table>
// Recupera tutte le entry del timetable <thead>
$res = $conn->query("SELECT timetable.id, classes.name AS class_name, timetable.day, timetable.hour, subjects.name AS subject_name, subjects.teacher as teacher, subjects.room as room
FROM timetable
LEFT JOIN classes ON timetable.class_id = classes.id
LEFT JOIN subjects ON timetable.subject_id = subjects.id
ORDER BY class_name, day, hour");
?>
<h2>Orario Inserito</h2>
<div class="table-container">
<table class="responsive-table" border="1" cellpadding="5" style="border-collapse:collapse; width:100%; max-width:1000px; margin:auto;">
<tr> <tr>
<th>Classe</th>
<th>Giorno</th>
<th>Ora</th> <th>Ora</th>
<th>Materia</th> <th>Lunedì</th>
<th>Azione</th> <th>Martedì</th>
<th>Mercoledì</th>
<th>Giovedì</th>
<th>Venerdì</th>
<th>Sabato</th>
</tr> </tr>
</thead>
<?php while($row = $res->fetch_assoc()): ?> <tbody>
<tr> <?php
<td data-label="Classe"><span><?php echo htmlspecialchars($row['class_name']); ?></span></td> $days = ['Lunedì', 'Martedì', 'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato'];
<td data-label="Giorno"><span><?php echo htmlspecialchars($row['day']); ?></span></td> for ($hour = 1; $hour <= 6; $hour++) {
<td data-label="Ora"><span><?php echo htmlspecialchars($row['hour']); ?></span></td> echo "<tr>";
<td data-label="Materia"><span><?php echo "<td>{$hour}ª ora</td>";
echo htmlspecialchars($row['subject_name']); foreach ($days as $day) {
if(!empty($row['teacher'])) { $preselected = $preselectedData[$day][$hour] ?? [''];
echo " (" . htmlspecialchars($row['teacher']) . ")"; echo "<td>";
echo "<div class='subject-container' data-day='$day' data-hour='$hour'>";
foreach ($preselected as $subject_id) {
echo "<div class='subject-row' style='display:flex;align-items:center;gap:5px;margin-bottom:3px;'>";
echo "<select name='subject[$day][$hour][]'>";
echo "<option value=''>--</option>";
foreach ($subjects as $s) {
$sel = ($subject_id == $s['id']) ? 'selected' : '';
echo "<option value='{$s['id']}' $sel>" . htmlspecialchars($s['label']) . "</option>";
} }
// if(!empty($row['room'])) { echo "</select>";
// echo " (" . htmlspecialchars($row['room']) . ")"; echo "<button type='button' class='remove-subject' style='background:#e74c3c;color:white;border:none;border-radius:3px;padding:2px 6px;'></button>";
// } echo "</div>";
?></span></td> }
<td data-label="Azione"><span> echo "<button type='button' class='add-subject' style='background:#28a745;color:white;border:none;border-radius:3px;padding:2px 6px;'>+</button>";
<a href="timetable.php?delete=<?php echo $row['id']; ?>" echo "</div>";
onclick="return confirm('Sei sicuro di voler eliminare questa voce?');" class='delete-link'> echo "</td>";
Elimina }
</a> echo "</tr>";
</span></td> }
</tr> ?>
<?php endwhile; ?> </tbody>
</table> </table>
</div>
<p> <br>
<button type="submit">Salva orario</button>
<?php endif; ?>
<?php if (isset($_GET['saved'])): ?>
<p class="saved-message">✅ Orario salvato con successo!</p>
<?php endif; ?>
</form>
<p style="text-align: center;">
Nota: Questa pagina si vede meglio da computer desktop. Se sei da computer, puoi ignorare questo messaggio. Nota: Questa pagina si vede meglio da computer desktop. Se sei da computer, puoi ignorare questo messaggio.
</p> </p>
<p style="text-align: center;">Copyright (C) 2025 EmmeV. All rights reserved.</p> <p style="text-align: center;">Copyright (C) 2025 EmmeV. - Released under <a href="https://git.vichingo455.freeddns.org/emmev-code/orario/src/branch/stable/LICENSE.txt" target="_blank">GNU AGPL 3.0 License</a>.</p>
</div> </div>
<script>
document.addEventListener('click', function(e){
if(e.target.classList.contains('add-subject')){
const container = e.target.closest('.subject-container');
const firstRow = container.querySelector('.subject-row');
const clone = firstRow.cloneNode(true);
clone.querySelector('select').value = '';
container.insertBefore(clone, e.target);
}
if(e.target.classList.contains('remove-subject')){
const container = e.target.closest('.subject-container');
const rows = container.querySelectorAll('.subject-row');
if(rows.length > 1){
e.target.closest('.subject-row').remove();
} else {
rows[0].querySelector('select').value = '';
}
}
});
</script>
</body> </body>
</html> </html>

115
htdocs/admin/users.php Normal file
View File

@@ -0,0 +1,115 @@
<?php
session_start();
include("../lib/db.php");
if (!isset($_SESSION['admin']) || $_SESSION['auth_type'] != 'local' || $_SESSION['admin'] != 'admin') {
header("Location: login.php");
exit;
}
$message = "";
// Add admin
if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['add_user'])) {
$username = trim($_POST['username']);
$password = $_POST['password'];
if (!empty($username) && !empty($password)) {
$hash = password_hash($password, PASSWORD_DEFAULT);
$stmt = $conn->prepare("INSERT INTO admin (username, password) VALUES (?, ?)");
$stmt->bind_param("ss", $username, $hash);
if ($stmt->execute()) {
$message = "Utente admin aggiunto con successo.";
} else {
$message = "Errore durante l'aggiunta: " . $conn->error;
}
} else {
$message = "Compila tutti i campi.";
}
}
// Delete admin
if (isset($_GET['delete'])) {
$id = intval($_GET['delete']);
if ($id != 1) { // proteggi super admin
$stmt = $conn->prepare("DELETE FROM admin WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$message = "Utente admin rimosso.";
} else {
$message = "Non puoi eliminare il super admin.";
}
}
// Fetch admins
$result = $conn->query("SELECT id, username FROM admin ORDER BY id ASC");
?>
<!DOCTYPE html>
<html>
<head>
<title>Gestione Admin</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="navbar">
<div class="logo">Admin Dashboard</div>
<div class="links">
<a href="index.php">Dashboard</a>
<a href="logout.php">Logout</a>
</div>
</div>
<div class="admin-container">
<h1>Gestione Amministratori</h1>
<a href="index.php" class="back-link">⬅ Torna al Dashboard</a>
<?php if ($message): ?>
<p style="color:<?php echo strpos($message,'successo')!==false ? 'green':'red'; ?>;">
<?php echo htmlspecialchars($message); ?>
</p>
<?php endif; ?>
<h2>Utenti Attivi</h2>
<table border="1" cellspacing="0" cellpadding="6" width="100%">
<thead>
<tr>
<th>ID</th>
<th>Username</th>
<th>Azione</th>
</tr>
</thead>
<tbody>
<?php while ($row = $result->fetch_assoc()): ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo htmlspecialchars($row['username']); ?></td>
<td>
<?php if ($row['id'] != 1): ?>
<a href="?delete=<?php echo $row['id']; ?>"
onclick="return confirm('Vuoi davvero eliminare questo amministratore?')"
style="color:red;">Elimina</a>
<?php else: ?>
<em>Super Admin</em>
<?php endif; ?>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<h2>Aggiungi Nuovo Admin</h2>
<form method="POST">
<label>Username:<br>
<input type="text" name="username" required>
</label><br><br>
<label>Password:<br>
<input type="password" name="password" required>
</label><br><br>
<button type="submit" name="add_user">Aggiungi</button>
</form>
</div>
</body>
</html>

42
htdocs/config/config.php Normal file
View File

@@ -0,0 +1,42 @@
<?php
// Impostazioni Database
if (!defined('DB_HOST')) {
define('DB_HOST', '<MYSQL_HOST>'); // Host del database (ad esempio localhost)
}
if (!defined('DB_USER')) {
define('DB_USER', '<MYSQL_USER>'); // Utente del database (ad esempio orario)
}
if (!defined('DB_PASS')) {
define('DB_PASS', '<MYSQL_PASSWORD>'); // Password dell'utente specificato prima (ad esempio password123)
}
if (!defined('DB_NAME')) {
define('DB_NAME', 'school_timetable'); // Nome del database, non modificare se non sai cosa stai facendo.
}
// Impostazioni sito generali
if (!defined('APP_NAME')) {
define('APP_NAME', 'Orario Scuola'); // Nome del sito
}
if (!defined('YEAR')) {
define('YEAR', '2025/26'); // Anno Scolastico Corrente
}
// Impostazioni autenticazione dashboard amministrativa
if (!defined('AUTH_TYPE')) {
define('AUTH_TYPE','local'); // Può essere keycloak o local (integrata)
}
// Impostazioni autenticazione via Keycloak (facoltative se AUTH_TYPE sta impostato su local)
if (!defined('KEYCLOAK_DOMAIN')) {
define('KEYCLOAK_DOMAIN',''); // Dominio di Keycloak (ad esempio auth.yourdomain.com)
}
if (!defined('KEYCLOAK_REALM')) {
define('KEYCLOAK_REALM',''); // Realm di Keycloak (ad esempio master)
}
if (!defined('KEYCLOAK_CLIENT_ID')) {
define('KEYCLOAK_CLIENT_ID',''); // Client ID per Keycloak (ad esempio orario)
}
if (!defined('KEYCLOAK_CLIENT_SECRET')) {
define('KEYCLOAK_CLIENT_SECRET',''); // Client Secret per Keycloak (ad esempio abcdefghijklm)
}
if (!defined('APP_DOMAIN')) {
define('APP_DOMAIN',''); // Dominio del sito (ad esempio orario.yourdomain.com)
}
?>

View File

@@ -106,62 +106,115 @@ td:hover {
td { padding-left: 50%; } td { padding-left: 50%; }
} }
*/ */
@media (max-width: 768px) {
table, thead, tbody, th, td, tr { /* --- tuoi stili desktop (questi restano uguali) --- */
display: block; table {
border-collapse: collapse;
width: 100%; 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);
} }
tr { th, td {
margin-bottom: 15px; border: 1px solid #ccc;
padding: 0; text-align: center;
border-bottom: 2px solid #ddd; padding: 10px;
vertical-align: top;
} }
th { th {
display: none; background-color: #e0e0e0;
font-weight: bold;
} }
td { td {
position: relative; transition: background-color 0.2s;
padding-left: 50%; }
text-align: left;
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 {
box-shadow: none;
border-radius: 0;
}
tr {
margin-bottom: 20px;
background: #fff;
border-radius: 8px;
box-shadow: 0 2px 6px rgba(0,0,0,0.08);
overflow: hidden;
padding: 10px;
}
td {
padding: 8px 8px 8px 50%;
border: none; border: none;
border-bottom: 1px solid #eee; border-bottom: 1px solid #eee;
min-height: 50px; /* ensures consistent vertical spacing */ font-size: 0.9em;
box-sizing: border-box;
} }
td::before { td::before {
position: absolute; position: absolute;
top: 10px; top: 10px;
left: 10px; left: 10px;
width: 40%; color: #1f618d;
font-weight: bold; font-size: 0.85em;
white-space: nowrap; text-transform: uppercase;
letter-spacing: 0.5px;
content: attr(data-label); content: attr(data-label);
} }
/* make content stack nicely */ td > .subject {
td > .subject, font-weight: 600;
td > .teacher, font-size: 1em;
margin-bottom: 2px;
}
td > .teacher {
font-size: 0.85em;
color: #555;
}
td > .room { td > .room {
display: block; font-size: 0.75em;
margin: 2px 0; color: #888;
} }
td:last-child { td:last-child {
border-bottom: 0; border-bottom: none;
} }
} }
/* Extra small screens */
@media (max-width: 480px) { @media (max-width: 480px) {
td { td {
padding-left: 55%; padding-left: 45%;
} }
td::before { td::before {
width: 45%; width: 40%;
font-size: 0.8em;
} }
} }

View File

@@ -1,5 +1,5 @@
<?php <?php
include("db.php"); include("lib/db.php");
$teacher = $_GET['teacher']; $teacher = $_GET['teacher'];
$days = ["Lunedì","Martedì","Mercoledì","Giovedì","Venerdì","Sabato"]; $days = ["Lunedì","Martedì","Mercoledì","Giovedì","Venerdì","Sabato"];
$hours = [ $hours = [
@@ -10,7 +10,7 @@ $hours = [
5 => "Quinta ora<br>11:55 - 12:50", 5 => "Quinta ora<br>11:55 - 12:50",
6 => "Sesta ora<br>12:50 - 13:50" 6 => "Sesta ora<br>12:50 - 13:50"
]; ];
if ($teacher == "No Lezione") { if ($teacher == "No Lezione" || $teacher == "sconosciuto") {
header("Location: index.php"); header("Location: index.php");
exit; exit;
} }
@@ -23,7 +23,6 @@ $teacher = $conn->real_escape_string($_GET['teacher']);
$res = $conn->query("SELECT DISTINCT teacher FROM subjects WHERE teacher = '$teacher' LIMIT 1"); $res = $conn->query("SELECT DISTINCT teacher FROM subjects WHERE teacher = '$teacher' LIMIT 1");
if ($res->num_rows === 0) { if ($res->num_rows === 0) {
// Insegnante non trovato
header("Location: index.php"); header("Location: index.php");
exit; exit;
} }
@@ -38,7 +37,7 @@ if ($res->num_rows === 0) {
</head> </head>
<body> <body>
<div class="navbar"> <div class="navbar">
<div class="logo">Orario Scuola 2025/26</div> <div class="logo"><?php echo APP_NAME; ?> <?php echo YEAR; ?></div>
<div class="links"> <div class="links">
<a href="index.php">Home</a> <a href="index.php">Home</a>
</div> </div>
@@ -72,6 +71,6 @@ if ($res->num_rows === 0) {
} }
?> ?>
</table> </table>
<p style="text-align: center;">Copyright (C) 2025 EmmeV. All rights reserved.</p> <p style="text-align: center;">Copyright (C) 2025 EmmeV. - Released under <a href="https://git.vichingo455.freeddns.org/emmev-code/orario/src/branch/stable/LICENSE.txt" target="_blank">GNU AGPL 3.0 License</a>.</p>
</body> </body>
</html> </html>

View File

@@ -1,23 +1,24 @@
<?php <?php
include("db.php"); include("lib/db.php");
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Orario - A.S. 2025/26</title> <title><?php echo APP_NAME; ?> - A.S. <?php echo YEAR; ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/home.css"> <link rel="stylesheet" href="css/home.css">
<link rel="stylesheet" href="css/navbar.css"> <link rel="stylesheet" href="css/navbar.css">
</head> </head>
<body> <body>
<div class="navbar"> <div class="navbar">
<div class="logo">Orario Scuola 2025/26</div> <div class="logo"><?php echo APP_NAME; ?> <?php echo YEAR; ?></div>
<div class="links"> <div class="links">
<a href="index.php">Home</a> <a href="index.php">Home</a>
<a href="admin/index.php">Admin</a> <a href="admin/index.php">Admin</a>
<a href="https://git.vichingo455.freeddns.org/emmev-code/orario" target="_blank">Codice sorgente</a>
</div> </div>
</div> </div>
<h1>Orario - a.s. 2025/26</h1> <h1><?php echo APP_NAME; ?> - A.S. <?php echo YEAR; ?></h1>
<!-- Sezione Classi --> <!-- Sezione Classi -->
<h2>Classi</h2> <h2>Classi</h2>
@@ -41,7 +42,7 @@ include("db.php");
<?php <?php
$res = $conn->query("SELECT DISTINCT teacher FROM subjects ORDER BY teacher"); $res = $conn->query("SELECT DISTINCT teacher FROM subjects ORDER BY teacher");
while($row = $res->fetch_assoc()){ while($row = $res->fetch_assoc()){
if ($row['teacher'] != "No Lezione") { if ($row['teacher'] != "No Lezione" && $row['teacher'] != "sconosciuto") {
$teacher_name = htmlspecialchars($row['teacher']); $teacher_name = htmlspecialchars($row['teacher']);
echo "<ul><li><b>$teacher_name</b></li>"; echo "<ul><li><b>$teacher_name</b></li>";
echo "<li><a href='docenti.php?teacher=".urlencode($teacher_name)."'>Visualizza orario</a></li>"; echo "<li><a href='docenti.php?teacher=".urlencode($teacher_name)."'>Visualizza orario</a></li>";
@@ -65,6 +66,6 @@ while($row = $res->fetch_assoc()){
?> ?>
</div> </div>
<p style="text-align: center;">Copyright (C) 2025 EmmeV. All rights reserved.</p> <p style="text-align: center;">Copyright (C) 2025 EmmeV. - Released under <a href="https://git.vichingo455.freeddns.org/emmev-code/orario/src/branch/stable/LICENSE.txt" target="_blank">GNU AGPL 3.0 License</a>.</p>
</body> </body>
</html> </html>

View File

@@ -1,5 +1,5 @@
<?php <?php
include("db.php"); include("lib/db.php");
$room = $_GET['room']; // aula selezionata $room = $_GET['room']; // aula selezionata
$days = ["Lunedì","Martedì","Mercoledì","Giovedì","Venerdì","Sabato"]; $days = ["Lunedì","Martedì","Mercoledì","Giovedì","Venerdì","Sabato"];
$hours = [ $hours = [
@@ -34,7 +34,7 @@ if ($res->num_rows === 0) {
</head> </head>
<body> <body>
<div class="navbar"> <div class="navbar">
<div class="logo">Orario Scuola 2025/26</div> <div class="logo"><?php echo APP_NAME; ?> <?php echo YEAR; ?></div>
<div class="links"> <div class="links">
<a href="index.php">Home</a> <a href="index.php">Home</a>
</div> </div>
@@ -60,11 +60,31 @@ if ($res->num_rows === 0) {
WHERE subjects.room='". $conn->real_escape_string($room) ."' WHERE subjects.room='". $conn->real_escape_string($room) ."'
AND timetable.day='$d' AND timetable.hour=$hnum 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'> echo "<td data-label='$d'>
<div class='subject'>{$row['subject_name']}</div> <div class='subject'>$subject</div>
<div class='teacher'>{$row['teacher']}</div> <div class='room'>$entries_list</div>
<div class='room'>{$row['class_name']}</div>
</td>"; </td>";
} else { } else {
echo "<td data-label='$d'></td>"; echo "<td data-label='$d'></td>";

View File

@@ -1,8 +1,9 @@
<?php <?php
$host = "<MYSQL_HOST>"; include_once __DIR__ . '/../config/config.php';
$user = "<MYSQL_USER>"; $host = DB_HOST;
$pass = "<MYSQL_PASSWORD>"; $user = DB_USER;
$dbname = "school_timetable"; $pass = DB_PASS;
$dbname = DB_NAME;
$conn = new mysqli($host, $user, $pass, $dbname); $conn = new mysqli($host, $user, $pass, $dbname);
if ($conn->connect_error) { if ($conn->connect_error) {

View File

@@ -1,5 +1,5 @@
<?php <?php
include("db.php"); include("lib/db.php");
$class_id = intval($_GET['class_id']); $class_id = intval($_GET['class_id']);
$class = $conn->query("SELECT * FROM classes WHERE id=$class_id")->fetch_assoc(); $class = $conn->query("SELECT * FROM classes WHERE id=$class_id")->fetch_assoc();
$days = ["Lunedì","Martedì","Mercoledì","Giovedì","Venerdì","Sabato"]; $days = ["Lunedì","Martedì","Mercoledì","Giovedì","Venerdì","Sabato"];
@@ -35,7 +35,7 @@ if ($res->num_rows === 0) {
</head> </head>
<body> <body>
<div class="navbar"> <div class="navbar">
<div class="logo">Orario Scuola 2025/26</div> <div class="logo"><?php echo APP_NAME; ?> <?php echo YEAR; ?></div>
<div class="links"> <div class="links">
<a href="index.php">Home</a> <a href="index.php">Home</a>
</div> </div>
@@ -54,10 +54,33 @@ if ($res->num_rows === 0) {
FROM timetable FROM timetable
LEFT JOIN subjects ON timetable.subject_id = subjects.id LEFT JOIN subjects ON timetable.subject_id = subjects.id
WHERE class_id=$class_id AND day='$d' AND hour=$hnum"); 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> if($q->num_rows > 0){
<div class='teacher'>{$row['teacher']}</div> $row = $q->fetch_assoc();
<div class='room'>{$row['room']}</div></td>"; $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 { } else {
echo "<td data-label='$d'></td>"; echo "<td data-label='$d'></td>";
} }
@@ -66,6 +89,6 @@ if ($res->num_rows === 0) {
} }
?> ?>
</table> </table>
<p style="text-align: center;">Copyright (C) 2025 EmmeV. All rights reserved.</p> <p style="text-align: center;">Copyright (C) 2025 EmmeV. - Released under <a href="https://git.vichingo455.freeddns.org/emmev-code/orario/src/branch/stable/LICENSE.txt" target="_blank">GNU AGPL 3.0 License</a>.</p>
</body> </body>
</html> </html>