83 lines
3.5 KiB
PHP
83 lines
3.5 KiB
PHP
<?php
|
|
// Assumendo che $conn sia già stato configurato e che $idtrf sia già definito e sanificato per evitare SQL Injection
|
|
require_once('../Connections/cmctrfdb.php');
|
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
|
|
|
$idtrf = isset($_GET['idtrf']) ? $conn->real_escape_string($_GET['idtrf']) : die('IDTRF non specificato.');
|
|
|
|
// Assicurati che la query includa kindoftest
|
|
$query = "SELECT
|
|
identificationparts.description_identificationparts,
|
|
identificationparts.article_identificationparts,
|
|
identificationparts.color_identificationparts,
|
|
identificationparts.component_identificationparts,
|
|
identificationparts.material_identificationparts,
|
|
identificationparts.cmcreportnumber_identificationparts,
|
|
identificationparts.cmcreportdate_identificationparts,
|
|
identificationparts.reportof,
|
|
identificationparts.partsidnumber,
|
|
identificationparts.kindoftest -- Assicurati che questo campo sia incluso
|
|
FROM identificationparts
|
|
LEFT JOIN partsordercimac ON partsordercimac.arttypeid = identificationparts.arttypeid
|
|
AND partsordercimac.partsidpicture = identificationparts.partsidnumber
|
|
WHERE identificationparts.idtrfdetails = '$idtrf'
|
|
ORDER BY CASE WHEN partsordercimac.partsidcimac IS NULL THEN 9999 ELSE partsordercimac.partsidcimac END";
|
|
|
|
$result = $conn->query($query);
|
|
|
|
if (!$result) {
|
|
die("Errore nell'esecuzione della query: " . $conn->error);
|
|
}
|
|
|
|
// Impostazioni dell'header per il download del file Excel
|
|
header("Content-Type: application/vnd.ms-excel");
|
|
header("Content-Disposition: attachment; filename=lista_parti.xls");
|
|
echo '<html xmlns:o="urn:schemas-microsoft-com:office:office"
|
|
xmlns:x="urn:schemas-microsoft-com:office:excel"
|
|
xmlns="http://www.w3.org/TR/REC-html40">
|
|
<head><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>
|
|
<x:Name>Report Sheet</x:Name>
|
|
<x:WorksheetOptions><x:Print><x:ValidPrinterInfo/></x:Print></x:WorksheetOptions>
|
|
</x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml>
|
|
<meta http-equiv="content-type" content="text/plain; charset=UTF-8"/></head><body>';
|
|
|
|
// Inizializzazione di un array per raccogliere i dati
|
|
$dati = [];
|
|
while ($row = $result->fetch_assoc()) {
|
|
$dati[] = $row;
|
|
}
|
|
|
|
// Inizio della tabella Excel
|
|
echo "<table>";
|
|
|
|
// Creazione delle colonne per ogni record
|
|
$numeroColonne = count($dati);
|
|
if ($numeroColonne > 0) {
|
|
// Calcolo del numero massimo di righe necessarie (uguale al numero di campi per record)
|
|
$numeroRighe = count($dati[0]);
|
|
|
|
// Generazione delle intestazioni di colonna
|
|
echo "<tr>";
|
|
foreach ($dati as $indice => $record) {
|
|
// Usa htmlspecialchars per evitare problemi con caratteri speciali
|
|
echo "<th style='background-color: #FFFF00; text-align: center;'>" . htmlspecialchars($record['description_identificationparts']) . "</th>";
|
|
}
|
|
echo "</tr>";
|
|
|
|
// Array delle chiavi per accedere ai valori in modo ordinato
|
|
$chiavi = array_keys($dati[0]);
|
|
|
|
// Creazione delle righe, escludendo la colonna description_identificationparts dall'essere ripetuta
|
|
for ($i = 1; $i < $numeroRighe; $i++) { // Inizia da 1 per saltare 'description_identificationparts'
|
|
echo "<tr>";
|
|
foreach ($dati as $record) {
|
|
echo "<td style='text-align: center;'>" . htmlspecialchars($record[$chiavi[$i]]) . "</td>";
|
|
}
|
|
echo "</tr>";
|
|
}
|
|
}
|
|
|
|
echo "</table>";
|
|
echo '</body></html>';
|
|
$conn->close();
|