84 lines
1.9 KiB
PHP
84 lines
1.9 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
|
|
|
|
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
|
|
|
|
$isTrainer =
|
|
isset($_SESSION['access_granted_trainer'], $_SESSION['passcodetrainer_id']) &&
|
|
$_SESSION['access_granted_trainer'] === true &&
|
|
(int)$_SESSION['passcodetrainer_id'] > 0;
|
|
|
|
if (!$isTrainer) {
|
|
echo json_encode(['success' => false]);
|
|
http_response_code(403);
|
|
exit;
|
|
}
|
|
|
|
if (!isset($_POST['musicId']) || !isset($_POST['turnerinId']) || intval($_POST['musicId']) < 1 || intval($_POST['turnerinId']) < 1) {
|
|
echo json_encode(['success' => false]);
|
|
http_response_code(422);
|
|
exit;
|
|
}
|
|
|
|
if (!isset($baseDir)) $baseDir = $_SERVER['DOCUMENT_ROOT'];
|
|
|
|
$type = 'tr';
|
|
|
|
$data = include $baseDir . '/../scripts/db/db-verbindung-script.php';
|
|
|
|
if ($data['success'] === false){
|
|
echo json_encode(['success' => false, 'message' => $data['message']]);
|
|
http_response_code(500);
|
|
exit;
|
|
}
|
|
|
|
require $baseDir . '/../scripts/db/db-tables.php';
|
|
|
|
$musicId = intval($_POST['musicId']);
|
|
$turnerinId = intval($_POST['turnerinId']);
|
|
|
|
$sql = "UPDATE $tableTurnerinnen SET bodenmusik = ? WHERE id = ?";
|
|
|
|
$stmt = $mysqli->prepare($sql);
|
|
$stmt->bind_param("ss", $musicId, $turnerinId);
|
|
|
|
if (!$stmt->execute()) {
|
|
http_response_code(500);
|
|
exit;
|
|
}
|
|
|
|
$stmt->close();
|
|
|
|
$sql = "SELECT name, vorname FROM $tableTurnerinnen WHERE id = ?";
|
|
|
|
$stmt = $mysqli->prepare($sql);
|
|
$stmt->bind_param("s", $turnerinId);
|
|
|
|
if (!$stmt->execute()) {
|
|
http_response_code(500);
|
|
exit;
|
|
}
|
|
|
|
$result = $stmt->get_result();
|
|
$rows = $result->fetch_all(MYSQLI_ASSOC);
|
|
|
|
$stmt->close();
|
|
|
|
$_SESSION['form_message_type'] = 1;
|
|
|
|
if (!isset($rows) || !is_array($rows) || count($rows) !== 1) {
|
|
$_SESSION['form_message'] = 'Musik aktualisiert';
|
|
} else {
|
|
$_SESSION['form_message'] = 'Musik für '.$rows[0]['name'].' '.$rows[0]['vorname'].' aktualisiert';
|
|
}
|
|
|
|
$mysqli->close();
|
|
|
|
echo json_encode(['success' => true]);
|
|
|
|
|
|
|
|
|
|
|