big update casadoc
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
// Mostra errori per il debug
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
include('include/headscript.php');
|
||||
|
||||
// Connessione al database
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
die("Errore di connessione: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Controlla se il metodo della richiesta è POST
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Recupera i dati dal form
|
||||
$idsharing = isset($_POST['idsharing']) ? (int)$_POST['idsharing'] : 0;
|
||||
$idhome = isset($_POST['idhome']) ? (int)$_POST['idhome'] : 0;
|
||||
$shared_email = $conn->real_escape_string($_POST['shared_email']);
|
||||
$role_id = isset($_POST['role_id']) ? (int)$_POST['role_id'] : null;
|
||||
$sharing_type = $conn->real_escape_string($_POST['sharing_type']);
|
||||
$expiration_date = !empty($_POST['expiration_date']) ? $conn->real_escape_string($_POST['expiration_date']) : null;
|
||||
$shared_sections = isset($_POST['shared_sections']) ? $_POST['shared_sections'] : [];
|
||||
|
||||
// Prepara le sezioni condivise come stringa JSON
|
||||
$sections_json = json_encode($shared_sections);
|
||||
|
||||
// Aggiorna i dati nella tabella home_Sharing
|
||||
$query = "
|
||||
UPDATE home_Sharing
|
||||
SET
|
||||
shared_email = ?,
|
||||
role_id = ?,
|
||||
sharing_type = ?,
|
||||
shared_sections = ?,
|
||||
expiration_date = ?
|
||||
WHERE idsharing = ?
|
||||
";
|
||||
|
||||
$stmt = $conn->prepare($query);
|
||||
if ($stmt === false) {
|
||||
die("Errore nella preparazione della query: " . $conn->error);
|
||||
}
|
||||
|
||||
// Associa i parametri alla query
|
||||
$stmt->bind_param(
|
||||
'sisssi',
|
||||
$shared_email,
|
||||
$role_id,
|
||||
$sharing_type,
|
||||
$sections_json,
|
||||
$expiration_date,
|
||||
$idsharing
|
||||
);
|
||||
|
||||
// Esegue la query e controlla il risultato
|
||||
if ($stmt->execute()) {
|
||||
// Reindirizza alla pagina delle condivisioni con il messaggio di successo
|
||||
header("Location: share-home.php?idhome=$idhome&success=1");
|
||||
exit();
|
||||
} else {
|
||||
// Reindirizza alla pagina delle condivisioni con il messaggio di errore
|
||||
header("Location: share-home.php?idhome=$idhome&error=1");
|
||||
exit();
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
} else {
|
||||
// Metodo non consentito
|
||||
header("HTTP/1.1 405 Method Not Allowed");
|
||||
echo "Metodo non consentito.";
|
||||
exit();
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
Reference in New Issue
Block a user