added teacher and option teacher in school
This commit is contained in:
+23
-23
@@ -1,33 +1,33 @@
|
||||
<?php
|
||||
require_once('include/headscript.php');
|
||||
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
header("Location: options.php");
|
||||
exit();
|
||||
header('Location: options.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
if ($conn->connect_error) {
|
||||
header("Location: options.php?message=error");
|
||||
exit();
|
||||
}
|
||||
$waiting = isset($_POST['waitinglist_enabled']) ? 'Y' : 'N';
|
||||
$showTeacher = isset($_POST['show_teacher']) ? 'Y' : 'N';
|
||||
$maxCancel = max(0, (int) ($_POST['maxbeforetimecancell'] ?? 0));
|
||||
|
||||
// Checkbox non spuntata = nessun invio -> default 'N'
|
||||
$waitingEnabled = (isset($_POST['waitinglist_enabled']) && $_POST['waitinglist_enabled'] === 'Y') ? 'Y' : 'N';
|
||||
$maxCancel = isset($_POST['maxbeforetimecancell']) ? (string) (int) $_POST['maxbeforetimecancell'] : '0';
|
||||
try {
|
||||
$exists = (int) $pdo->query("SELECT COUNT(*) AS c FROM `option`")->fetch()['c'] > 0;
|
||||
|
||||
// Aggiorna l'unico record di option (idption = 1)
|
||||
$stmt = $conn->prepare("UPDATE `option` SET waitinglist_enabled = ?, maxbeforetimecancell = ? WHERE idption = 1");
|
||||
$stmt->bind_param("ss", $waitingEnabled, $maxCancel);
|
||||
if ($exists) {
|
||||
$st = $pdo->prepare("UPDATE `option`
|
||||
SET waitinglist_enabled = :w, show_teacher = :s, maxbeforetimecancell = :m
|
||||
LIMIT 1");
|
||||
} else {
|
||||
$st = $pdo->prepare("INSERT INTO `option` (waitinglist_enabled, show_teacher, maxbeforetimecancell)
|
||||
VALUES (:w, :s, :m)");
|
||||
}
|
||||
$st->execute([':w' => $waiting, ':s' => $showTeacher, ':m' => (string) $maxCancel]);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
header("Location: optionsschool.php?message=success");
|
||||
exit();
|
||||
} else {
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
header("Location: optionsschool.php?message=error");
|
||||
exit();
|
||||
header('Location: optionsschool.php?message=success');
|
||||
} catch (Throwable $e) {
|
||||
error_log('options_save: ' . $e->getMessage());
|
||||
header('Location: options.php?message=error');
|
||||
}
|
||||
exit;
|
||||
|
||||
Reference in New Issue
Block a user