Compare commits

...

20 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
23 changed files with 663 additions and 146 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

@@ -53,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', // Client ID Keycloak ```bash
'abcdefghijklmnop' // Client secret Keycloak curl -fsSL https://get.docker.com | bash
);
$oidc->setRedirectURL('https://orario.local/admin/login.php'); // orario.local è il dominio base di questa piattaforma
``` ```
- 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'];

View File

@@ -29,7 +29,16 @@ 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.

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();
// Configura il client Keycloak include("../lib/db.php");
$oidc = new OpenIDConnectClient( if ($_SERVER["REQUEST_METHOD"] == "POST" && AUTH_TYPE == 'local') {
'https://<KEYCLOAK_URL>/realms/<REALM>/', $username = $_POST['username'];
'<CLIENT_ID>', $password = $_POST['password'];
'<CLIENT_SECRET>' $stmt = $conn->prepare("SELECT * FROM admin WHERE username = ?");
); $stmt->bind_param("s", $username);
// Redirect post-login $stmt->execute();
$oidc->setRedirectURL('https://<APP_DOMAIN>/admin/login.php'); $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>
$oidc->authenticate(); <div class="navbar">
$userinfo = $oidc->getVerifiedClaims(); <div class="logo">Admin Dashboard</div>
$_SESSION['admin'] = $userinfo->preferred_username; <div class="links">
header("Location: index.php"); <a href="/">Torna al sito</a>
exit; </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
$oidc = new OpenIDConnectClient(
'https://' + KEYCLOAK_DOMAIN + '/realms/' + KEYCLOAK_REALM + '/',
KEYCLOAK_CLIENT_ID,
KEYCLOAK_CLIENT_SECRET
);
// Redirect post-login
$oidc->setRedirectURL('https://' + APP_DOMAIN + '/admin/login.php');
$oidc->authenticate();
$userinfo = $oidc->getVerifiedClaims();
$_SESSION['admin'] = $userinfo->preferred_username;
$_SESSION['auth_type'] = 'keycloak';
header("Location: index.php");
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. - 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>

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>";
} }
?> ?>

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");
// --- Recupera tutte le materie --- // --- Recupera tutte le materie ---
$subjects = []; $subjects = [];

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%; }
} }
*/ */
/* --- 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) { @media (max-width: 768px) {
table, thead, tbody, th, td, tr { table {
display: block; box-shadow: none;
width: 100%; border-radius: 0;
} }
tr { tr {
margin-bottom: 15px; margin-bottom: 20px;
padding: 0; background: #fff;
border-bottom: 2px solid #ddd; border-radius: 8px;
} box-shadow: 0 2px 6px rgba(0,0,0,0.08);
overflow: hidden;
th { padding: 10px;
display: none;
} }
td { td {
position: relative; padding: 8px 8px 8px 50%;
padding-left: 50%;
text-align: left;
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 = [
@@ -37,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>

View File

@@ -1,24 +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> <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>

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>";
} }