added upload doc
This commit is contained in:
parent
31e76e40cf
commit
d0698f2a6a
230
public/userportal/documents-home.php
Normal file
230
public/userportal/documents-home.php
Normal file
@ -0,0 +1,230 @@
|
||||
<?php include('include/headscript.php'); ?>
|
||||
<?php
|
||||
// Connessione al database
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
|
||||
// Recupera l'id utente loggato
|
||||
$iduserlogin = $_SESSION['iduserlogin'];
|
||||
|
||||
// Recupera l'id della casa dall'URL
|
||||
$idhome = isset($_GET['idhome']) ? intval($_GET['idhome']) : 0;
|
||||
|
||||
// Recupera i dettagli della casa
|
||||
$queryHome = $conn->prepare("SELECT * FROM home WHERE idhome = ? AND iduser = ?");
|
||||
$queryHome->bind_param('ii', $idhome, $iduserlogin);
|
||||
$queryHome->execute();
|
||||
$resultHome = $queryHome->get_result();
|
||||
$homeData = $resultHome->fetch_assoc();
|
||||
|
||||
// Recupera i documenti dalla tabella 'documents' raggruppati per sezione
|
||||
$queryDocuments = $conn->query("SELECT * FROM documents ORDER BY section");
|
||||
|
||||
$documents = [];
|
||||
while ($row = $queryDocuments->fetch_assoc()) {
|
||||
$documents[$row['section']][] = $row;
|
||||
}
|
||||
|
||||
// Recupera i documenti già caricati per questa casa
|
||||
$queryLoadedDocuments = $conn->prepare("SELECT * FROM doc_storage WHERE idhome = ?");
|
||||
$queryLoadedDocuments->bind_param('i', $idhome);
|
||||
$queryLoadedDocuments->execute();
|
||||
$resultLoadedDocuments = $queryLoadedDocuments->get_result();
|
||||
|
||||
$loadedDocuments = [];
|
||||
while ($row = $resultLoadedDocuments->fetch_assoc()) {
|
||||
$loadedDocuments[$row['document_id']][] = $row;
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>Documenti della Casa</title>
|
||||
|
||||
<!-- Bootstrap 4 CSS -->
|
||||
<link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
|
||||
<link href="https://cdn.datatables.net/1.11.5/css/dataTables.bootstrap4.min.css" rel="stylesheet" />
|
||||
|
||||
<!-- Font Awesome -->
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet" />
|
||||
|
||||
<!-- Custom CSS -->
|
||||
<link href="assets/css/style.css" rel="stylesheet" type="text/css">
|
||||
|
||||
<!-- Dropzone CSS -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.2/dropzone.min.css" />
|
||||
|
||||
<style>
|
||||
.section-title {
|
||||
font-size: 1.25rem;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.document-title {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 500;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.dropzone {
|
||||
background-color: #f0f8ff;
|
||||
border: 2px dashed #007bff;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
text-align: center;
|
||||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
.dropzone:hover {
|
||||
background-color: #e6f5ff;
|
||||
}
|
||||
|
||||
.dropzone .dz-message {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 500;
|
||||
color: #007bff;
|
||||
}
|
||||
|
||||
.dropzone .dz-message i {
|
||||
font-size: 3rem;
|
||||
margin-bottom: 10px;
|
||||
color: #007bff;
|
||||
}
|
||||
|
||||
.document-list-table th,
|
||||
.document-list-table td {
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.section-separator {
|
||||
border-top: 2px solid #ddd;
|
||||
margin: 40px 0;
|
||||
}
|
||||
|
||||
.btn {
|
||||
margin-right: 5px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body class="fixed-left">
|
||||
<div id="wrapper">
|
||||
<?php include('include/navigationbar.php'); ?>
|
||||
<div class="content-page">
|
||||
<div class="content">
|
||||
<?php include('include/topbar.php'); ?>
|
||||
|
||||
<div class="page-content-wrapper">
|
||||
<div class="container-fluid">
|
||||
<!-- Dettagli della Casa -->
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<h4 class="page-title">Documenti per la Casa: <?php echo htmlspecialchars($homeData['name']); ?></h4>
|
||||
<p><strong>Indirizzo:</strong> <?php echo htmlspecialchars($homeData['address']) . ', ' . htmlspecialchars($homeData['city']) . ' ' . htmlspecialchars($homeData['zip']); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Sezioni per documenti -->
|
||||
<?php foreach ($documents as $section => $sectionDocuments) { ?>
|
||||
<div class="section-separator"></div>
|
||||
<h5 class="section-title"><?php echo htmlspecialchars($section); ?></h5>
|
||||
<?php foreach ($sectionDocuments as $document) { ?>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="card card-body mb-4">
|
||||
<!-- Titolo del documento -->
|
||||
<p class="document-title">
|
||||
<?php echo htmlspecialchars($document['document_name']); ?>
|
||||
<?php if ($document['is_required']) echo "<strong>(Obbligatorio)</strong>"; ?>
|
||||
<?php if ($document['max_documents'] > 0) echo " - Max: " . $document['max_documents']; ?>
|
||||
</p>
|
||||
|
||||
<!-- Area Drag & Drop per il caricamento -->
|
||||
<div class="dropzone mb-3" id="dropzone-<?php echo $document['document_id']; ?>">
|
||||
<div class="dz-message">
|
||||
<i class="fas fa-cloud-upload-alt"></i><br>
|
||||
Trascina qui i documenti o clicca per caricare
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tabella dei documenti già caricati -->
|
||||
<h6 class="mt-4">Documenti già caricati:</h6>
|
||||
<table class="table table-bordered document-list-table" id="table-<?php echo $document['document_id']; ?>">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nome Documento</th>
|
||||
<th>Data Caricamento</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<!-- Qui verranno inseriti i documenti caricati per quel documento -->
|
||||
<?php if (isset($loadedDocuments[$document['document_id']])) { ?>
|
||||
<?php foreach ($loadedDocuments[$document['document_id']] as $loadedDoc) { ?>
|
||||
<tr>
|
||||
<td><a href="homedocuments/<?php echo $loadedDoc['filename']; ?>" target="_blank"><?php echo htmlspecialchars($loadedDoc['filename']); ?></a></td>
|
||||
<td><?php echo htmlspecialchars($loadedDoc['created_at']); ?></td>
|
||||
<td><button class="btn btn-danger btn-sm">Elimina</button></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</div><!-- container -->
|
||||
</div><!-- Page content Wrapper -->
|
||||
</div><!-- content -->
|
||||
<?php include('include/footer.php'); ?>
|
||||
</div><!-- End Right content here -->
|
||||
</div><!-- END wrapper -->
|
||||
|
||||
<!-- jQuery -->
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.11.5/js/dataTables.bootstrap4.min.js"></script>
|
||||
|
||||
<!-- Plugin Dropzone -->
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.2/dropzone.min.js"></script>
|
||||
|
||||
<script>
|
||||
// Inizializza Dropzone per ciascun documento
|
||||
<?php foreach ($documents as $section => $sectionDocuments) { ?>
|
||||
<?php foreach ($sectionDocuments as $document) { ?>
|
||||
new Dropzone("#dropzone-<?php echo $document['document_id']; ?>", {
|
||||
url: "upload-document.php", // URL del caricamento
|
||||
paramName: "file", // Il nome del campo per il file
|
||||
maxFiles: <?php echo $document['max_documents']; ?>, // Imposta il numero massimo di file
|
||||
addRemoveLinks: true,
|
||||
init: function() {
|
||||
this.on("success", function(file, response) {
|
||||
let tableId = "#table-<?php echo $document['document_id']; ?> tbody";
|
||||
// Aggiorna la tabella dei documenti caricati
|
||||
let row = `<tr>
|
||||
<td><a href="homedocuments/${response.fileName}" target="_blank">${response.fileName}</a></td>
|
||||
<td>${response.uploadDate}</td>
|
||||
<td><button class="btn btn-danger btn-sm">Elimina</button></td>
|
||||
</tr>`;
|
||||
$(tableId).append(row);
|
||||
});
|
||||
},
|
||||
sending: function(file, xhr, formData) {
|
||||
formData.append("idhome", "<?php echo $idhome; ?>");
|
||||
formData.append("document_id", "<?php echo $document['document_id']; ?>");
|
||||
}
|
||||
});
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Binary file not shown.
BIN
public/userportal/homedocuments/1-1726859766-SnapFeet.pdf
Normal file
BIN
public/userportal/homedocuments/1-1726859766-SnapFeet.pdf
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -105,7 +105,7 @@ $result = $stmt->get_result();
|
||||
<a href="manage-home.php?idhome=<?php echo $row['idhome']; ?>" class="btn btn-info btn-sm">
|
||||
<i class="fas fa-info-circle"></i> Dettagli
|
||||
</a>
|
||||
<a href="manage-home.php?idhome=<?php echo $row['idhome']; ?>" class="btn btn-primary btn-sm">
|
||||
<a href="documents-home.php?idhome=<?php echo $row['idhome']; ?>" class="btn btn-primary btn-sm">
|
||||
<i class="fas fa-info-circle"></i> Documenti
|
||||
</a>
|
||||
<a href="manage-home.php?idhome=<?php echo $row['idhome']; ?>" class="btn btn-danger btn-sm">
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
<title>Kering Portal</title>
|
||||
<title>CasaDoc</title>
|
||||
<meta content="Admin Dashboard" name="description" />
|
||||
<meta content="Mannatthemes" name="author" />
|
||||
@ -98,7 +98,7 @@
|
||||
<div class="page-title-box">
|
||||
<div class="btn-group float-right">
|
||||
<ol class="breadcrumb hide-phone p-0 m-0">
|
||||
<li class="breadcrumb-item"><a href="#">Kering Portal</a></li>
|
||||
<li class="breadcrumb-item"><a href="#">CasaDoc</a></li>
|
||||
<li class="breadcrumb-item active">Dashboard</li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
@ -29,7 +29,7 @@ if (!$isNew) {
|
||||
$postal_code = $ownerData['postal_code'];
|
||||
$city = $ownerData['city'];
|
||||
$province = $ownerData['province'];
|
||||
$country = $ownerData['country'];
|
||||
$country = $ownerData['country']; // ID della tabella auth_countries
|
||||
$owner_type = $ownerData['owner_type'];
|
||||
$role = $ownerData['role'];
|
||||
} else {
|
||||
@ -37,6 +37,11 @@ if (!$isNew) {
|
||||
$first_name = $last_name = $company_name = $tax_code = $email = $phone = $address = $postal_code = $city = $province = $country = $role = '';
|
||||
$owner_type = 'individual';
|
||||
}
|
||||
|
||||
// Recupera la lista dei paesi dalla tabella auth_countries
|
||||
$countriesQuery = $conn->prepare("SELECT id, name FROM auth_countries ORDER BY name ASC");
|
||||
$countriesQuery->execute();
|
||||
$countriesResult = $countriesQuery->get_result();
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
@ -57,6 +62,13 @@ if (!$isNew) {
|
||||
|
||||
<!-- Custom CSS -->
|
||||
<link href="assets/css/style.css" rel="stylesheet" type="text/css">
|
||||
|
||||
<!-- Select2 CSS -->
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css" rel="stylesheet" />
|
||||
|
||||
<!-- Select2 JS -->
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body class="fixed-left">
|
||||
@ -155,10 +167,16 @@ if (!$isNew) {
|
||||
<input type="text" name="province" class="form-control" value="<?php echo htmlspecialchars($province); ?>">
|
||||
</div>
|
||||
|
||||
<!-- Nazione -->
|
||||
<!-- Nazione (Dropdown con valori da auth_countries) -->
|
||||
<div class="form-group">
|
||||
<label>Nazione</label>
|
||||
<input type="text" name="country" class="form-control" value="<?php echo htmlspecialchars($country); ?>" readonly>
|
||||
<select name="country" class="form-control">
|
||||
<?php while ($row = $countriesResult->fetch_assoc()) { ?>
|
||||
<option value="<?php echo $row['id']; ?>" <?php echo $country == $row['id'] ? 'selected' : ''; ?>>
|
||||
<?php echo htmlspecialchars($row['name']); ?>
|
||||
</option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Ruolo -->
|
||||
@ -182,7 +200,7 @@ if (!$isNew) {
|
||||
<!-- jQuery -->
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="assets/js/bootstrap.min.js"></script>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
function toggleOwnerFields() {
|
||||
@ -204,6 +222,35 @@ if (!$isNew) {
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Inizializza Select2 per il campo country
|
||||
$('select[name="country"]').select2({
|
||||
placeholder: 'Seleziona una nazione',
|
||||
allowClear: true
|
||||
});
|
||||
|
||||
// Funzione per mostrare/nascondere i campi in base al tipo di proprietario
|
||||
function toggleOwnerFields() {
|
||||
if ($('#owner_type').val() === 'individual') {
|
||||
$('.individual-field').show();
|
||||
$('.company-field').hide();
|
||||
} else {
|
||||
$('.individual-field').hide();
|
||||
$('.company-field').show();
|
||||
}
|
||||
}
|
||||
|
||||
// Inizializza la visualizzazione corretta dei campi
|
||||
toggleOwnerFields();
|
||||
|
||||
// Cambia la visualizzazione dei campi quando cambia il tipo di proprietario
|
||||
$('#owner_type').change(function() {
|
||||
toggleOwnerFields();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@ -38,7 +38,8 @@ $result = $stmt->get_result();
|
||||
<?php include('include/navigationbar.php'); ?>
|
||||
<div class="content-page">
|
||||
<div class="content">
|
||||
<?php include('include/topbar.php'); ?>
|
||||
<?php //include('include/topbar.php');
|
||||
?>
|
||||
|
||||
<div class="page-content-wrapper">
|
||||
<div class="container-fluid">
|
||||
@ -84,7 +85,7 @@ $result = $stmt->get_result();
|
||||
<th>Provincia</th>
|
||||
<th>Nazione</th>
|
||||
<th>Tipo</th>
|
||||
<th>Ruolo</th>
|
||||
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -98,7 +99,7 @@ $result = $stmt->get_result();
|
||||
<th><input type="text" placeholder="Cerca Provincia" class="form-control form-control-sm"></th>
|
||||
<th><input type="text" placeholder="Cerca Nazione" class="form-control form-control-sm"></th>
|
||||
<th><input type="text" placeholder="Cerca Tipo" class="form-control form-control-sm"></th>
|
||||
<th><input type="text" placeholder="Cerca Ruolo" class="form-control form-control-sm"></th>
|
||||
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -122,13 +123,19 @@ $result = $stmt->get_result();
|
||||
<td><?php echo htmlspecialchars($row['province']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['country']); ?></td>
|
||||
<td><?php echo ucfirst($row['owner_type']); ?></td>
|
||||
<td><?php echo htmlspecialchars($row['role']); ?></td>
|
||||
<td>
|
||||
<div class="btn-group" role="group">
|
||||
<!-- Pulsante per modificare i dettagli del proprietario -->
|
||||
<a href="manage-owner.php?owner_id=<?php echo $row['owner_id']; ?>" class="btn btn-info btn-sm">
|
||||
<i class="fas fa-info-circle"></i> Dettagli
|
||||
</a>
|
||||
<!-- Pulsante per i documenti del proprietario con un margine a sinistra -->
|
||||
<a href="add-docs.php?owner_id=<?php echo $row['owner_id']; ?>" class="btn btn-warning btn-sm ml-2">
|
||||
<i class="fas fa-file-alt"></i> DOCS
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
|
||||
128
public/userportal/save-owner.php
Normal file
128
public/userportal/save-owner.php
Normal file
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
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);
|
||||
|
||||
// Verifica della connessione
|
||||
if ($conn->connect_error) {
|
||||
die("Connessione fallita: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Recupera l'id utente loggato dalla sessione
|
||||
$iduserlogin = intval($_SESSION['iduserlogin']);
|
||||
|
||||
// Recupera i dati inviati tramite POST
|
||||
$owner_id = isset($_POST['owner_id']) ? intval($_POST['owner_id']) : 0;
|
||||
$owner_type = isset($_POST['owner_type']) ? $conn->real_escape_string($_POST['owner_type']) : '';
|
||||
$first_name = !empty($_POST['first_name']) ? $conn->real_escape_string($_POST['first_name']) : null;
|
||||
$last_name = !empty($_POST['last_name']) ? $conn->real_escape_string($_POST['last_name']) : null;
|
||||
$company_name = !empty($_POST['company_name']) ? $conn->real_escape_string($_POST['company_name']) : null;
|
||||
$tax_code = isset($_POST['tax_code']) ? $conn->real_escape_string($_POST['tax_code']) : '';
|
||||
$email = isset($_POST['email']) ? $conn->real_escape_string($_POST['email']) : '';
|
||||
$phone = !empty($_POST['phone']) ? $conn->real_escape_string($_POST['phone']) : null;
|
||||
$address = !empty($_POST['address']) ? $conn->real_escape_string($_POST['address']) : null;
|
||||
$postal_code = !empty($_POST['postal_code']) ? $conn->real_escape_string($_POST['postal_code']) : null;
|
||||
$city = !empty($_POST['city']) ? $conn->real_escape_string($_POST['city']) : null;
|
||||
$province = !empty($_POST['province']) ? $conn->real_escape_string($_POST['province']) : null;
|
||||
$country = isset($_POST['country']) ? intval($_POST['country']) : null; // Converti country in intero
|
||||
$role = !empty($_POST['role']) ? $conn->real_escape_string($_POST['role']) : null;
|
||||
$owner_type = isset($_POST['owner_type']) ? $conn->real_escape_string($_POST['owner_type']) : 'individual'; // Default to 'individual'
|
||||
|
||||
|
||||
|
||||
// Verifica se stiamo aggiungendo un nuovo proprietario o aggiornando uno esistente
|
||||
if ($owner_id > 0) {
|
||||
// Aggiorna il proprietario esistente
|
||||
$query = "UPDATE property_owners
|
||||
SET owner_type = ?, first_name = ?, last_name = ?, company_name = ?, tax_code = ?, email = ?, phone = ?, address = ?, postal_code = ?, city = ?, province = ?, country = ?, role = ?
|
||||
WHERE owner_id = ? AND user_id = ?";
|
||||
$stmt = $conn->prepare($query);
|
||||
if ($stmt === false) {
|
||||
die("Errore nella preparazione della query: " . $conn->error);
|
||||
}
|
||||
|
||||
// Imposta i valori nulli per i campi facoltativi
|
||||
$company_name = !empty($company_name) ? $company_name : null;
|
||||
$role = !empty($role) ? $role : null;
|
||||
|
||||
// Binding dei parametri
|
||||
$stmt->bind_param(
|
||||
'ssssssssssssiis', // Formato corretto
|
||||
$owner_type, // s (string)
|
||||
$first_name, // s (string)
|
||||
$last_name, // s (string)
|
||||
$company_name, // s (string, può essere null)
|
||||
$tax_code, // s (string)
|
||||
$email, // s (string)
|
||||
$phone, // s (string)
|
||||
$address, // s (string)
|
||||
$postal_code, // s (string)
|
||||
$city, // s (string)
|
||||
$province, // s (string)
|
||||
$country, // i (intero)
|
||||
$role, // s (string, può essere null)
|
||||
$owner_id, // i (intero)
|
||||
$iduserlogin // i (intero)
|
||||
);
|
||||
|
||||
// Esegui la query
|
||||
if ($stmt->execute()) {
|
||||
// Reindirizza a manage-owner.php dopo il successo
|
||||
header("Location: person-list.php");
|
||||
exit();
|
||||
} else {
|
||||
die("Errore nell'aggiornamento: " . $stmt->error);
|
||||
}
|
||||
// Inserisci un nuovo proprietario
|
||||
$query = "INSERT INTO property_owners
|
||||
(user_id, owner_type, first_name, last_name, company_name, tax_code, email, phone, address, postal_code, city, province, country, role)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
$stmt = $conn->prepare($query);
|
||||
if ($stmt === false) {
|
||||
die("Errore nella preparazione della query: " . $conn->error);
|
||||
}
|
||||
|
||||
$company_name = !empty($company_name) ? $company_name : null;
|
||||
$role = !empty($role) ? $role : null;
|
||||
|
||||
|
||||
|
||||
// Binding dei parametri
|
||||
$stmt->bind_param(
|
||||
'isssssssssssis', // Formato: 2 interi, 12 stringhe
|
||||
$iduserlogin, // i (user_id)
|
||||
$owner_type, // s (owner_type)
|
||||
$first_name, // s (first_name)
|
||||
$last_name, // s (last_name)
|
||||
$company_name, // s (company_name)
|
||||
$tax_code, // s (tax_code)
|
||||
$email, // s (email)
|
||||
$phone, // s (phone)
|
||||
$address, // s (address)
|
||||
$postal_code, // s (postal_code)
|
||||
$city, // s (city)
|
||||
$province, // s (province)
|
||||
$country, // i (country)
|
||||
$role // s (role)
|
||||
);
|
||||
|
||||
// Esegui la query
|
||||
if ($stmt->execute()) {
|
||||
echo "Proprietario salvato con successo.";
|
||||
// Reindirizza a manage-owner.php dopo il successo
|
||||
header("Location: person-list.php");
|
||||
exit(); // Assicurati di terminare l'esecuzione dopo il reindirizzamento
|
||||
} else {
|
||||
die("Errore nell'inserimento o aggiornamento: " . $stmt->error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Chiudi la connessione
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
59
public/userportal/upload-document.php
Normal file
59
public/userportal/upload-document.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
include('include/headscript.php');
|
||||
|
||||
// Connessione al database
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
|
||||
// Controlla la connessione al database
|
||||
if ($conn->connect_error) {
|
||||
die(json_encode(['success' => false, 'message' => "Connection failed: " . $conn->connect_error]));
|
||||
}
|
||||
|
||||
// Impostazioni della cartella di destinazione
|
||||
$targetDir = "homedocuments/";
|
||||
|
||||
// Recupera i dati inviati tramite POST e FILES
|
||||
$idhome = isset($_POST['idhome']) ? intval($_POST['idhome']) : 0;
|
||||
$document_id = isset($_POST['document_id']) ? intval($_POST['document_id']) : 0;
|
||||
$file = isset($_FILES['file']) ? $_FILES['file'] : null;
|
||||
$expirydate = isset($_POST['expirydate']) ? $_POST['expirydate'] : null;
|
||||
$note = isset($_POST['note']) ? $_POST['note'] : null;
|
||||
|
||||
// Controlla se il file è stato caricato correttamente
|
||||
if ($file && $file['error'] === UPLOAD_ERR_OK) {
|
||||
// Rinomina il file con lo schema idhome-timestamp-filename
|
||||
$filename = basename($file['name']);
|
||||
$fileExtension = pathinfo($filename, PATHINFO_EXTENSION);
|
||||
$newFilename = $idhome . '-' . time() . '-' . $filename;
|
||||
$targetFilePath = $targetDir . $newFilename;
|
||||
|
||||
// Verifica e crea la cartella se non esiste
|
||||
if (!is_dir($targetDir)) {
|
||||
mkdir($targetDir, 0777, true);
|
||||
}
|
||||
|
||||
// Sposta il file nella cartella di destinazione
|
||||
if (move_uploaded_file($file['tmp_name'], $targetFilePath)) {
|
||||
// Inserisce il file nel database
|
||||
$expiry_status = ($expirydate) ? 1 : 0;
|
||||
|
||||
$query = "INSERT INTO doc_storage (idhome, document_id, filename, expirystatus, expirydate, note, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, NOW(), NOW())";
|
||||
$stmt = $conn->prepare($query);
|
||||
$stmt->bind_param("iissss", $idhome, $document_id, $newFilename, $expiry_status, $expirydate, $note);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
echo json_encode(['success' => true, 'message' => "File uploaded successfully.", 'filename' => $newFilename]);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => "Failed to insert into database: " . $stmt->error]);
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => "Failed to move the file."]);
|
||||
}
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => "File upload error."]);
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
Loading…
x
Reference in New Issue
Block a user