-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_edit.php
More file actions
98 lines (83 loc) · 2.93 KB
/
Copy pathgame_edit.php
File metadata and controls
98 lines (83 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
// game_edit.php
require_once 'auth_check.php';
require_once 'db_connection.php';
session_start();
requireRole('Jogador');
// 1) Connect
$pdo = getDBConnection();
// 2) Set @myEmail
$loggedEmail = $_SESSION['dbUser'];
$pdo->exec("SET @myEmail = '" . addslashes($loggedEmail) . "'");
// 3) Which game?
$gameID = $_GET['id'] ?? null;
if (!$gameID) {
die("No game ID specified.");
}
// 4) If POST => “Guardar” or “Retroceder”
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Gather form fields
$newDescricao = $_POST['descricao'] ?? '';
$newIntervaloMinimoAlertas = (int)($_POST['intervalo'] ?? 0);
// Convert radio “sim”/“nao” to 1/0
$vAlertaPerigo = ($_POST['alertaPerigo'] ?? 'nao') === 'sim' ? 1 : 0;
$vAlertaAviso = ($_POST['alertaAviso'] ?? 'nao') === 'sim' ? 1 : 0;
$vAlertaInfo = ($_POST['alertaInfo'] ?? 'nao') === 'sim' ? 1 : 0;
// If user clicked “Retroceder”
if (isset($_POST['retroceder'])) {
header("Location: games.php?msg=Cancelled");
exit;
}
// Otherwise call Alterar_Jogo
try {
$stmt = $pdo->prepare("
CALL Labirinto.Alterar_Jogo(
:jogoid, :descricao, :intervaloMinimoAlertas,
:pAlertaPerigo, :pAlertaAviso, :pAlertaInfo
)
");
$stmt->execute([
':jogoid' => (int)$gameID,
':descricao' => $newDescricao,
':intervaloMinimoAlertas' => $newIntervaloMinimoAlertas,
':pAlertaPerigo' => $vAlertaPerigo,
':pAlertaAviso' => $vAlertaAviso,
':pAlertaInfo' => $vAlertaInfo
]);
$stmt->closeCursor();
header("Location: games.php?msg=Updated");
exit;
} catch (PDOException $ex) {
die("Error calling Alterar_Jogo: " . $ex->getMessage());
}
}
// 5) If GET => fetch existing data with ViewJogo & ViewConfiguracaoAlertas
// (A) ViewJogo(:id)
$stmtJ = $pdo->prepare("CALL Labirinto.ViewJogo(:idParam)");
$stmtJ->execute([':idParam' => (int)$gameID]);
$jRow = $stmtJ->fetch(PDO::FETCH_ASSOC);
$stmtJ->closeCursor();
if (!$jRow) {
die("No such game or not yours.");
}
// store them
$descricaoCurrent = $jRow['Descricao'];
$intervaloMinimoAlertas = $jRow['IntervaloMinimoAlertas'];
// (B) ViewConfiguracaoAlertas(:id)
$stmtA = $pdo->prepare("CALL Labirinto.ViewConfiguracaoAlertas(:idParam)");
$stmtA->execute([':idParam' => (int)$gameID]);
$alertRows = $stmtA->fetchAll(PDO::FETCH_ASSOC);
$stmtA->closeCursor();
// Turn them into a small map e.g. [1=>1,2=>1,3=>1]
$alertSettings = [];
foreach ($alertRows as $ar) {
$alertSettings[$ar['IDTipoAlerta']] = $ar['Visibilidade'];
}
// default 1 if missing
$vAlertaTipo1 = $alertSettings[1] ?? 1;
$vAlertaTipo2 = $alertSettings[2] ?? 1;
$vAlertaTipo3 = $alertSettings[3] ?? 1;
// 6) define layout vars and include the content
$pageTitle = "Editar Jogo #$gameID";
$contentFile = "game_edit_content.php";
include('layout.php');