update dossier chekcqual
This commit is contained in:
+93
-52
@@ -5,23 +5,77 @@ error_reporting(E_ALL);
|
||||
ini_set('display_errors', TRUE);
|
||||
ini_set('display_startup_errors', TRUE);
|
||||
include 'include/headscript.php';
|
||||
|
||||
// Recupera idcompany
|
||||
if (isset($_POST['idcompany'])) {
|
||||
$idcompany = intval($_POST['idcompany']);
|
||||
} elseif (isset($_GET['idcompany'])) {
|
||||
$idcompany = intval($_GET['idcompany']);
|
||||
} else {
|
||||
die("Errore: idcompany non specificato.");
|
||||
}
|
||||
include('languages/' . $_SESSION['langselect'] . '/tdgen.php');
|
||||
?>
|
||||
<?php
|
||||
if (isset($_POST['submit'])) {
|
||||
$description = $_POST['descriptionqualcheck']; // Assicurati che la validazione dell'input sia stata fatta
|
||||
$qualchecktext = $_POST['qualchecktext']; // Testo dalla textarea
|
||||
|
||||
// Variabili per modalità modifica
|
||||
$editMode = false;
|
||||
$qualcheckId = 0;
|
||||
$description = '';
|
||||
$qualchecktext = '';
|
||||
|
||||
// Verifica se siamo in modalità modifica
|
||||
if (isset($_GET['edit_id']) && !isset($_POST['submit'])) {
|
||||
$editMode = true;
|
||||
$qualcheckId = intval($_GET['edit_id']);
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
$sql = "INSERT INTO qualcheck_td (descriptionqualcheck, qualchecktext, idcompany) VALUES (?, ?, ?)";
|
||||
$stmt = $conn->prepare($sql);
|
||||
|
||||
if ($stmt) {
|
||||
$stmt->bind_param("ssi", $description, $qualchecktext, $idcompany);
|
||||
$stmt->execute();
|
||||
$query = "SELECT descriptionqualcheck, qualchecktext FROM qualcheck_td WHERE idqualcheck_td = ? AND idcompany = ?";
|
||||
$stmt = $conn->prepare($query);
|
||||
$stmt->bind_param("ii", $qualcheckId, $idcompany);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
if ($row = $result->fetch_assoc()) {
|
||||
$description = htmlspecialchars($row['descriptionqualcheck']);
|
||||
$qualchecktext = htmlspecialchars($row['qualchecktext']);
|
||||
} else {
|
||||
echo "Errore durante l'inserimento nel database.";
|
||||
$editMode = false; // Se non troviamo il record, usciamo dalla modalità modifica
|
||||
}
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
}
|
||||
|
||||
// Gestione del submit
|
||||
if (isset($_POST['submit'])) {
|
||||
$description = $_POST['descriptionqualcheck'];
|
||||
$qualchecktext = $_POST['qualchecktext'];
|
||||
$qualcheckId = isset($_POST['qualcheck_id']) ? intval($_POST['qualcheck_id']) : 0;
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
|
||||
if ($qualcheckId > 0) {
|
||||
// Modalità UPDATE
|
||||
$sql = "UPDATE qualcheck_td SET descriptionqualcheck = ?, qualchecktext = ? WHERE idqualcheck_td = ? AND idcompany = ?";
|
||||
$stmt = $conn->prepare($sql);
|
||||
if ($stmt) {
|
||||
$stmt->bind_param("ssii", $description, $qualchecktext, $qualcheckId, $idcompany);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
} else {
|
||||
echo "Errore durante l'aggiornamento nel database.";
|
||||
}
|
||||
} else {
|
||||
// Modalità INSERT
|
||||
$sql = "INSERT INTO qualcheck_td (descriptionqualcheck, qualchecktext, idcompany) VALUES (?, ?, ?)";
|
||||
$stmt = $conn->prepare($sql);
|
||||
if ($stmt) {
|
||||
$stmt->bind_param("ssi", $description, $qualchecktext, $idcompany);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
} else {
|
||||
echo "Errore durante l'inserimento nel database.";
|
||||
}
|
||||
}
|
||||
$conn->close();
|
||||
// Reindirizza per evitare duplicati
|
||||
header("Location: qualcheck.php?idcompany=$idcompany");
|
||||
exit();
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -31,10 +85,9 @@ if (isset($_POST['submit'])) {
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Aggiungi Qualificazione</title>
|
||||
<title><?php echo $editMode ? 'Modifica Qualificazione' : 'Aggiungi Qualificazione'; ?></title>
|
||||
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" rel="stylesheet">
|
||||
|
||||
<script src="ckeditor/build/ckeditor.js"></script>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
@@ -42,31 +95,19 @@ if (isset($_POST['submit'])) {
|
||||
.create(document.querySelector('#qualcheckText'), {
|
||||
toolbar: {
|
||||
items: [
|
||||
'undo', 'redo',
|
||||
'|', 'heading',
|
||||
'|', 'fontFamily', 'fontSize',
|
||||
'|', 'bold', 'italic',
|
||||
'|', 'link', 'blockQuote',
|
||||
'|', 'alignment:left', 'alignment:right', 'alignment:center', 'alignment:justify',
|
||||
'|', 'bulletedList', 'numberedList', 'outdent', 'indent',
|
||||
'|', 'insertTable',
|
||||
'|', 'imageUpload'
|
||||
'undo', 'redo', '|', 'heading', '|', 'fontFamily', 'fontSize', '|',
|
||||
'bold', 'italic', '|', 'link', 'blockQuote', '|',
|
||||
'alignment:left', 'alignment:right', 'alignment:center', 'alignment:justify', '|',
|
||||
'bulletedList', 'numberedList', 'outdent', 'indent', '|', 'insertTable', '|', 'imageUpload'
|
||||
],
|
||||
shouldNotGroupWhenFull: true
|
||||
},
|
||||
// Configurazione per l'inserimento delle tabelle
|
||||
table: {
|
||||
contentToolbar: ['tableColumn', 'tableRow', 'mergeTableCells']
|
||||
},
|
||||
// Configurazione per l'upload delle immagini
|
||||
simpleUpload: {
|
||||
// Il URL dove le immagini caricate vengono processate
|
||||
uploadUrl: 'uploadck.php',
|
||||
|
||||
// Abilita il caricamento automatico di immagini inserite
|
||||
withCredentials: true,
|
||||
|
||||
// Headers aggiuntivi inviati con l'upload dell'immagine
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': 'CSRF-Token',
|
||||
Authorization: 'Bearer <JSON Web Token>'
|
||||
@@ -76,13 +117,16 @@ if (isset($_POST['submit'])) {
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
function closeAndRefresh() {
|
||||
window.opener.location.reload();
|
||||
window.close();
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
.ck-editor__editable_inline {
|
||||
min-height: 200px;
|
||||
/* Adatta questo valore in base alle tue necessità */
|
||||
}
|
||||
|
||||
.ck-editor__editable {
|
||||
@@ -95,28 +139,23 @@ if (isset($_POST['submit'])) {
|
||||
<body>
|
||||
<div class="container mt-5">
|
||||
<button type="button" class="btn btn-secondary" onclick="closeAndRefresh()">Chiudi e Aggiorna</button>
|
||||
<h3><?php echo $editMode ? 'Modifica Controllo Qualità produzione' : 'Aggiungi Controllo Qualità produzione'; ?></h3>
|
||||
|
||||
<script>
|
||||
function closeAndRefresh() {
|
||||
window.opener.location.reload(); // Aggiorna la pagina genitore
|
||||
window.close(); // Chiude il popup
|
||||
}
|
||||
</script>
|
||||
<h3>Aggiungi Controllo Qualità produzione </h3>
|
||||
|
||||
<form action="qualcheck.php" method="post">
|
||||
<form action="qualcheck.php?idcompany=<?php echo $idcompany; ?>" method="post">
|
||||
<input type="hidden" name="idcompany" value="<?php echo $idcompany; ?>">
|
||||
<input type="hidden" name="qualcheck_id" value="<?php echo $qualcheckId; ?>">
|
||||
<div class="form-group">
|
||||
<label for="descriptionQualcheck">Descrizione:</label>
|
||||
<input type="text" class="form-control" id="descriptionQualcheck" name="descriptionqualcheck" required>
|
||||
<input type="text" class="form-control" id="descriptionQualcheck" name="descriptionqualcheck" value="<?php echo $description; ?>" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="qualcheckText">Controllo Qualità produzione:</label>
|
||||
<textarea class="form-control" id="qualcheckText" name="qualchecktext" rows="5"></textarea>
|
||||
<textarea class="form-control" id="qualcheckText" name="qualchecktext" rows="5"><?php echo $qualchecktext; ?></textarea>
|
||||
</div>
|
||||
|
||||
|
||||
<button type="submit" class="btn btn-primary" name="submit">Aggiungi</button>
|
||||
<button type="submit" class="btn btn-primary" name="submit"><?php echo $editMode ? 'Aggiorna' : 'Aggiungi'; ?></button>
|
||||
<?php if ($editMode) { ?>
|
||||
<a href="qualcheck.php?idcompany=<?php echo $idcompany; ?>" class="btn btn-secondary">Annulla Modifica</a>
|
||||
<?php } ?>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -126,7 +165,7 @@ if (isset($_POST['submit'])) {
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Descrizione</th>
|
||||
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -141,17 +180,19 @@ if (isset($_POST['submit'])) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
echo "<tr>";
|
||||
echo "<td>" . htmlspecialchars($row['descriptionqualcheck']) . "</td>";
|
||||
// Aggiungi una colonna con un'icona di cestino che quando cliccata invoca uno script di cancellazione
|
||||
echo "<td><a href='delete_qualcheck.php?id=" . $row['idqualcheck_td'] . "' style='color: red;'><i class='fas fa-trash-alt'></i></a></td>";
|
||||
echo "<td>";
|
||||
echo "<a href='qualcheck.php?idcompany=$idcompany&edit_id=" . $row['idqualcheck_td'] . "' style='color: blue; margin-right: 10px;'><i class='fas fa-edit'></i></a>";
|
||||
echo "<a href='delete_qualcheck.php?id=" . $row['idqualcheck_td'] . "&idcompany=$idcompany' style='color: red;'><i class='fas fa-trash-alt'></i></a>";
|
||||
echo "</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.2/dist/umd/popper.min.js"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user