allerta-vvf/server/edit_training.php

74 lines
3.2 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");
2021-04-25 21:49:47 +02:00
if($tools->validate_form(['id', 'token'])) {
2020-11-13 18:57:47 +01:00
if($_POST["token"] == $_SESSION['token']) {
bdump("removing training");
2021-04-25 21:49:47 +02:00
$crud->remove_training($_POST["id"]);
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));
}
$crew = $db->select("SELECT * FROM `".DB_PREFIX."_profiles` ORDER BY name ASC");
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($crud->exists("trainings", $id));
$values = $db->select("SELECT * FROM `".DB_PREFIX."_trainings` WHERE `id` = :id", [":id" => $id])[0];
2020-11-13 18:57:47 +01:00
bdump($values);
} else {
$values = [];
}
if($modalità=="edit" || $modalità=="delete") {
if(empty($id)) {
$tools->redirect("accessdenied.php");
} elseif (!$crud->exists("trainings", $id)) {
2020-11-13 18:57:47 +01:00
//$tools->redirect("accessdenied.php");
}
}
2021-04-26 15:33:44 +02:00
loadtemplate('edit_training.html', ['training' => ['id' => $id, 'token' => $_SESSION['token'], 'modalità' => $modalità, 'crew' => $crew], 'values' => $values, 'title' => t(ucfirst($modalità) . " 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
?>