allerta-vvf/server/edit_training.php

79 lines
3.4 KiB
PHP
Raw Normal View History

2020-07-01 21:00:53 +02:00
<?php
require_once 'ui.php';
2020-11-25 11:29:19 +01:00
function debug(){
echo("<pre>"); var_dump($_POST); echo("</pre>"); exit();
}
if($tools->validate_form("mod", "add")) {
if($tools->validate_form(['date', 'name', 'start_time', 'end_time', 'place', 'notes', 'token'])) {
2020-11-13 18:57:47 +01:00
if($_POST["token"] == $_SESSION['token']) {
bdump("adding training");
2021-04-25 17:19:48 +02:00
$place = $tools->checkPlaceParam($_POST["place"]);
$crud->add_training($_POST["date"], $_POST["name"], $_POST["start_time"], $_POST["end_time"], $_POST["chief"][0], $tools->extract_unique($_POST["crew"]), $place, $_POST["notes"], $tools->extract_unique([$_POST["chief"],$_POST["crew"]]), $user->name());
2020-11-13 18:57:47 +01:00
$tools->redirect("trainings.php");
} else {
2020-11-25 11:29:19 +01:00
debug(); //TODO: remove debug info
2020-11-13 18:57:47 +01:00
}
2020-11-25 11:29:19 +01:00
} else {
debug();
2020-07-01 21:27:21 +02:00
}
2020-11-25 11:29:19 +01:00
} elseif($tools->validate_form("mod", "edit")) {
if($tools->validate_form(['id', 'date', 'name', 'start_time', 'end_time', 'chief', 'place', 'notes', 'token'])) {
2020-11-13 18:57:47 +01:00
if($_POST["token"] == $_SESSION['token']) {
bdump($_POST);
bdump("editing training");
2021-04-25 17:19:48 +02:00
$place = $tools->checkPlaceParam($_POST["place"]);
$crud->edit_training($_POST["id"], $_POST["date"], $_POST["name"], $_POST["start_time"], $_POST["end_time"], $_POST["chief"][0], $tools->extract_unique($_POST["crew"]), $place, $_POST["notes"], $tools->extract_unique([$_POST["chief"],$_POST["crew"]]), $user->name());
2020-11-13 18:57:47 +01:00
$tools->redirect("trainings.php");
} else {
2020-11-25 11:29:19 +01:00
debug();
2020-11-13 18:57:47 +01:00
}
2020-11-25 11:29:19 +01:00
} else {
debug();
2020-07-01 21:27:21 +02:00
}
2020-11-25 11:29:19 +01:00
} elseif($tools->validate_form("mod", "delete")) {
2020-11-13 18:57:47 +01:00
bdump("removing training");
2020-11-25 11:29:19 +01:00
if($tools->validate_form(['id', 'increment', 'token'])) {
2020-11-13 18:57:47 +01:00
if($_POST["token"] == $_SESSION['token']) {
bdump("removing training");
2021-03-24 17:10:44 +01:00
$crud->remove_training($_POST["id"], $_POST["increment"]);
2020-11-13 18:57:47 +01:00
$tools->redirect("trainings.php");
} else {
2020-11-25 11:29:19 +01:00
debug();
2020-11-13 18:57:47 +01:00
}
2020-11-25 11:29:19 +01:00
} else {
debug();
2020-07-01 21:27:21 +02:00
}
2020-07-01 21:00:53 +02:00
} else {
2020-11-13 18:57:47 +01:00
if(isset($_GET["add"])||isset($_GET["edit"])||isset($_GET["delete"])||isset($_GET["mod"])) {
$_SESSION["token"] = bin2hex(random_bytes(64));
}
2021-03-04 09:52:11 +01:00
$crew = $database->exec("SELECT * FROM `%PREFIX%_profiles` ORDER BY name ASC;", true);
2020-11-13 18:57:47 +01:00
$modalità = (isset($_GET["add"])) ? "add" : ((isset($_GET["edit"])) ? "edit" : ((isset($_GET["delete"])) ? "delete" : "add"));
bdump($modalità, "modalità");
2020-11-25 11:29:19 +01:00
bdump($crew, "crew");
2020-11-13 18:57:47 +01:00
$id = "";
if(isset($_GET["id"])) {
$id = $_GET["id"];
bdump($database->exists("trainings", $id));
2021-03-04 09:52:11 +01:00
$values = $database->exec("SELECT * FROM `%PREFIX%_trainings` WHERE `id` = :id", true, [":id" => $id])[0];
2020-11-13 18:57:47 +01:00
bdump($values);
} else {
$values = [];
}
if(isset($_GET["increment"])) {
$increment = $_GET["increment"];
} else {
$increment = "";
}
if($modalità=="edit" || $modalità=="delete") {
if(empty($id)) {
$tools->redirect("accessdenied.php");
} elseif (!$database->exists("trainings", $id)) {
//$tools->redirect("accessdenied.php");
}
}
2020-11-25 11:29:19 +01:00
loadtemplate('edit_training.html', ['training' => ['id' => $id, 'token' => $_SESSION['token'], 'modalità' => $modalità, 'crew' => $crew], 'values' => $values, 'increment' => $increment, 'title' => ucfirst($modalità) . ' '.ucfirst(t("training", false))]);
2020-11-13 18:57:47 +01:00
bdump($_SESSION['token'], "token");
2020-07-01 21:00:53 +02:00
}
2020-11-13 18:57:47 +01:00
?>