allerta-vvf/server/edit_user.php

65 lines
3.0 KiB
PHP
Raw Normal View History

2020-06-17 22:08:59 +02:00
<?php
require_once 'ui.php';
if($tools->validate_form_data('$post-mod', true, "add")) {
2020-07-01 21:27:21 +02:00
if($tools->validate_form_data(['$post-mail', '$post-name', '$post-username', '$post-password', '$post-birthday', '$post-token'])) {
if($_POST["token"] == $_SESSION['token']){
2020-07-03 12:17:46 +02:00
bdump("adding user");
2020-06-17 22:08:59 +02:00
bdump($_POST);
$capo = isset($_POST["capo"]) ? 1 : 0;
$autista = isset($_POST["autista"]) ? 1 : 0;
$hidden = isset($_POST["visible"]) ? 0 : 1;
$disabled = isset($_POST["enabled"]) ? 0 : 1;
$user->add_user($_POST["mail"], $_POST["name"], $_POST["username"], $_POST["password"], $_POST["birthday"], $capo, $autista, $hidden, $disabled, $user->name());
2020-06-17 22:48:10 +02:00
$tools->redirect("lista.php");
2020-07-01 21:27:21 +02:00
} else {
$tools->redirect("nonfareilfurbo.php");
}
2020-06-17 22:08:59 +02:00
}
2020-07-03 12:17:46 +02:00
/*} elseif($tools->validate_form_data('$post-mod', true, "edit")) {
2020-06-17 22:08:59 +02:00
if($tools->validate_form_data(['$post-id', '$post-data', '$post-codice', '$post-uscita', '$post-rientro', '$post-capo', '$post-luogo', '$post-note', '$post-tipo', '$post-token'])) {
if($_POST["token"] == $_SESSION['token']){
bdump($_POST);
2020-07-03 12:17:46 +02:00
bdump("editing service");
2020-07-03 12:10:41 +02:00
$database->change_service($_POST["id"], $_POST["data"], $_POST["codice"], $_POST["uscita"], $_POST["rientro"], $_POST["capo"], $tools->extract_unique($_POST["autisti"]), $tools->extract_unique($_POST["personale"]), $_POST["luogo"], $_POST["note"], $_POST["tipo"], $tools->extract_unique([$_POST["capo"],$_POST["autisti"],$_POST["personale"]]), $user->name());
$tools->redirect("services.php");
2020-06-17 22:08:59 +02:00
} else {
$tools->redirect("nonfareilfurbo.php");
}
}
2020-07-03 12:17:46 +02:00
*/} elseif($tools->validate_form_data('$post-mod', true, "delete")) {
bdump("removing service");
2020-07-01 21:27:21 +02:00
if($tools->validate_form_data(['$post-id', '$post-token'])) {
if($_POST["token"] == $_SESSION['token']){
2020-07-03 12:17:46 +02:00
bdump("removing user");
$user->remove_user($_POST["id"]);
2020-06-17 22:48:10 +02:00
$tools->redirect("lista.php");
2020-07-01 21:27:21 +02:00
} else {
$tools->redirect("nonfareilfurbo.php");
}
2020-06-17 22:08:59 +02:00
}
} else {
2020-07-03 12:17:46 +02:00
if(isset($_GET["add"])||isset($_GET["edit"])||isset($_GET["delete"])||isset($_GET["mod"])){
2020-07-01 21:27:21 +02:00
$_SESSION["token"] = bin2hex(random_bytes(64));
}
2020-07-03 12:17:46 +02:00
$modalità = (isset($_GET["add"])) ? "add" : ((isset($_GET["edit"])) ? "edit" : ((isset($_GET["delete"])) ? "delete" : "add"));
2020-06-17 22:08:59 +02:00
bdump($modalità, "modalità");
$id = "";
if(isset($_GET["id"])){
$id = $_GET["id"];
bdump($database->exists("profiles", $id));
$values = $database->exec("SELECT * FROM `%PREFIX%_profiles` WHERE `id` = :id", true, [":id" => $id])[0]; // Pesco le tipologie della table
bdump($values);
} else {
$values = [];
}
2020-07-03 12:17:46 +02:00
if($modalità=="edit" || $modalità=="delete"){
2020-06-17 22:08:59 +02:00
if(empty($id)){
$tools->redirect("nonfareilfurbo.php");
} elseif (!$database->exists("profiles", $id)){
$tools->redirect("nonfareilfurbo.php");
}
}
2020-07-10 13:07:19 +02:00
loadtemplate('edit_user.html', ['id' => $id, 'token' => $_SESSION["token"], 'modalità' => $modalità, 'values' => $values, 'titolo' => ucfirst($modalità) . ' '.ucfirst(t("user",false))]);
2020-07-01 21:27:21 +02:00
bdump($_SESSION['token'], "token");
2020-06-17 22:08:59 +02:00
}
?>