This commit is contained in:
2026-04-02 16:53:53 +03:00
parent 9775a12d4a
commit 53c223ea5f
9 changed files with 77 additions and 102 deletions
+37 -50
View File
@@ -1,59 +1,46 @@
<?php <?php
require_once dirname(__DIR__, 2) . '/vendor/autoload.php'; // Risale a root/vendor/ require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
use Dotenv\Dotenv; require_once __DIR__ . '/class/db-functions.php';
include dirname(__DIR__) . '/../extra/auth.php';
if (!Auth::check()) { http_response_code(401); echo json_encode(['error' => 'Unauthorized']); exit; }
// Set JSON header
header('Content-Type: application/json'); header('Content-Type: application/json');
// Debug: Log the path where we expect the .env file
$envPath = dirname(__DIR__, 2);
file_put_contents(__DIR__ . '/debug_log.txt', date('Y-m-d H:i:s') . ' - Expected .env path: ' . $envPath . PHP_EOL, FILE_APPEND);
// Carica il file .env dalla root del progetto
try { try {
$dotenv = Dotenv::createImmutable($envPath); // Read from matrici cache (populated by get_matrici.php / warm_cache.php)
$dotenv->load(); $cacheFile = __DIR__ . '/cache/matrici.json';
} catch (Exception $e) { if (file_exists($cacheFile)) {
file_put_contents(__DIR__ . '/error_log.txt', date('Y-m-d H:i:s') . ' - Errore caricamento .env: ' . $e->getMessage() . PHP_EOL, FILE_APPEND); $data = json_decode(file_get_contents($cacheFile), true);
echo json_encode(['success' => false, 'message' => 'Errore caricamento configurazione: ' . $e->getMessage()]); $matrici = $data['value'] ?? [];
exit(1); } else {
} // Fallback: trigger cache creation
require_once __DIR__ . '/class/VisualLimsApiClient.class.php';
$api = VisualLimsApiClient::getInstance();
$apiData = $api->get('Matrice');
$matrici = [];
foreach (($apiData['value'] ?? []) as $item) {
$nome = $item['NomeMatrice'] ?? '';
if ($nome !== '' && substr($nome, 0, 1) !== '*') {
$matrici[] = ['IdMatrice' => $item['IdMatrice'], 'NomeMatrice' => $nome, 'MacroMatrice' => $item['MacroMatrice'] ?? null];
}
}
if (!is_dir(__DIR__ . '/cache')) mkdir(__DIR__ . '/cache', 0777, true);
file_put_contents($cacheFile, json_encode(['success' => true, 'value' => $matrici]));
}
// Recupera le variabili d'ambiente // Extract unique MacroMatrice values
$dbHost = $_ENV['DB_HOST']; $macroValues = [];
$dbName = $_ENV['DB_DATABASE']; foreach ($matrici as $m) {
$dbUser = $_ENV['DB_USERNAME']; $macro = $m['MacroMatrice'] ?? null;
$dbPass = $_ENV['DB_PASSWORD']; if ($macro !== null && $macro !== '' && substr($macro, 0, 1) !== '*') {
$dbPrefix = $_ENV['DB_PREFIX']; $macroValues[$macro] = true;
}
}
$macroMatrici = array_keys($macroValues);
sort($macroMatrici);
// Debug: Log database connection details (excluding password)
file_put_contents(__DIR__ . '/debug_log.txt', date('Y-m-d H:i:s') . " - DB Connection: host=$dbHost, dbname=$dbName, user=$dbUser, prefix=$dbPrefix" . PHP_EOL, FILE_APPEND);
// Connessione al database MySQL
try {
$pdo = new PDO("mysql:host=$dbHost;dbname=$dbName;charset=utf8mb4", $dbUser, $dbPass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
file_put_contents(__DIR__ . '/error_log.txt', date('Y-m-d H:i:s') . ' - Errore connessione DB: ' . $e->getMessage() . PHP_EOL, FILE_APPEND);
echo json_encode(['success' => false, 'message' => 'Errore connessione al database: ' . $e->getMessage()]);
exit(1);
}
try {
// Query per recuperare i valori distinti di MacroMatrice, escludendo quelli che iniziano con '*' e ordinandoli
$query = "SELECT DISTINCT MacroMatrice FROM {$dbPrefix}matrici WHERE MacroMatrice IS NOT NULL AND MacroMatrice NOT LIKE '*%' ORDER BY MacroMatrice ASC";
$stmt = $pdo->prepare($query);
$stmt->execute();
$macroMatrici = $stmt->fetchAll(PDO::FETCH_COLUMN);
// Debug: Log del numero di MacroMatrice recuperate
file_put_contents(__DIR__ . '/debug_log.txt', date('Y-m-d H:i:s') . ' - Retrieved ' . count($macroMatrici) . ' MacroMatrice from database' . PHP_EOL, FILE_APPEND);
// Restituisci risposta JSON
echo json_encode(['success' => true, 'value' => $macroMatrici]); echo json_encode(['success' => true, 'value' => $macroMatrici]);
} catch (PDOException $e) { } catch (Exception $e) {
// Log errore e restituisci risposta di errore http_response_code(500);
file_put_contents(__DIR__ . '/error_log.txt', date('Y-m-d H:i:s') . ' - Errore nel recupero delle MacroMatrice: ' . $e->getMessage() . PHP_EOL, FILE_APPEND); echo json_encode(['success' => false, 'message' => $e->getMessage()]);
echo json_encode(['success' => false, 'message' => 'Errore nel recupero delle MacroMatrice: ' . $e->getMessage()]);
exit(1);
} }
+4
View File
@@ -1,5 +1,9 @@
<?php <?php
require_once dirname(__DIR__, 2) . '/vendor/autoload.php'; require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
require_once __DIR__ . '/class/db-functions.php';
include dirname(__DIR__) . '/../extra/auth.php';
if (!Auth::check()) { http_response_code(401); echo json_encode(['error' => 'Unauthorized']); exit; }
require_once __DIR__ . '/class/VisualLimsApiClient.class.php'; require_once __DIR__ . '/class/VisualLimsApiClient.class.php';
header('Content-Type: application/json'); header('Content-Type: application/json');
+1 -1
View File
@@ -24,7 +24,7 @@ $columns = json_decode(urldecode($_POST['columns'] ?? '[]'), true);
$rows = json_decode(urldecode($_POST['rows'] ?? '[]'), true); $rows = json_decode(urldecode($_POST['rows'] ?? '[]'), true);
$excelrows = json_decode(urldecode($_POST['excelrows'] ?? '[]'), true); $excelrows = json_decode(urldecode($_POST['excelrows'] ?? '[]'), true);
$newFilename = htmlspecialchars($_POST['filename']); $newFilename = $_POST['filename'];
$_SESSION['template_id'] = $template_id; $_SESSION['template_id'] = $template_id;
$_SESSION['selected_rows'] = $selected_rows; $_SESSION['selected_rows'] = $selected_rows;
-2
View File
@@ -19,8 +19,6 @@
<i class="fas fa-flask"></i> Analysis <i class="fas fa-flask"></i> Analysis
</button> </button>
<select id="global-matrice" class="ms-2" style="width: 250px !important; min-width: 250px !important;">
</select>
<input type="checkbox" id="showMixParts" name="showMixParts" style="margin-right: 5px; margin-left: 10px;"> <input type="checkbox" id="showMixParts" name="showMixParts" style="margin-right: 5px; margin-left: 10px;">
<label for="showMixParts" style="font-size: 0.9rem; margin-right: 10px;">Mix</label> <label for="showMixParts" style="font-size: 0.9rem; margin-right: 10px;">Mix</label>
+7 -46
View File
@@ -342,51 +342,12 @@ $(document).ready(function () {
// =================== // ===================
function loadParts(iddatadb, idquotations, callback = null) { function loadParts(iddatadb, idquotations, callback = null) {
if (iddatadb) { if (iddatadb) {
if (matrici.length === 0) { loadMacroMatrici();
$.ajax({ initializeGlobalSelect2();
url: "get_matrici.php", loadPartsExtraField(iddatadb, function () {
method: "GET", loadPhoto(iddatadb, idquotations);
dataType: "json", loadExistingParts(iddatadb, idquotations, callback);
success: function (data) { });
matrici = data.value || [];
loadMacroMatrici();
initializeGlobalSelect2();
loadPartsExtraField(iddatadb, function () {
loadPhoto(iddatadb, idquotations);
loadExistingParts(iddatadb, idquotations, callback);
});
},
error: function (xhr, status, error) {
matrici = [];
loadMacroMatrici();
initializeGlobalSelect2();
loadPartsExtraField(iddatadb, function () {
loadPhoto(iddatadb, idquotations);
loadExistingParts(iddatadb, idquotations, callback);
});
const errorMsg = $(
'<div class="alert alert-danger temp-alert" role="alert">Errore nel caricamento delle matrici: ' +
error +
" (" +
xhr.status +
")</div>",
);
$("#partsModal .modal-body").prepend(errorMsg);
setTimeout(function () {
errorMsg.fadeOut(500, function () {
$(this).remove();
});
}, 5000);
},
});
} else {
loadMacroMatrici();
initializeGlobalSelect2();
loadPartsExtraField(iddatadb, function () {
loadPhoto(iddatadb, idquotations);
loadExistingParts(iddatadb, idquotations, callback);
});
}
} else { } else {
loadPartsExtraField(iddatadb, function () { loadPartsExtraField(iddatadb, function () {
loadPhoto(iddatadb, idquotations); loadPhoto(iddatadb, idquotations);
@@ -1518,7 +1479,7 @@ $(document).ready(function () {
function loadMacroMatrici() { function loadMacroMatrici() {
$.ajax({ $.ajax({
url: "get_macro_matrici.php", url: "search_matrici.php?macro_list=1",
method: "GET", method: "GET",
dataType: "json", dataType: "json",
success: function (data) { success: function (data) {
+1 -1
View File
@@ -154,7 +154,7 @@ try {
$columnLetter = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($physCol); $columnLetter = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($physCol);
$cell = $worksheet->getCell($columnLetter . $row); $cell = $worksheet->getCell($columnLetter . $row);
$cellValue = $cell ? $cell->getCalculatedValue() : ''; $cellValue = $cell ? $cell->getCalculatedValue() : '';
$rowData[] = htmlspecialchars($cellValue ?: ''); $rowData[] = $cellValue ?: '';
} }
// Count how many header columns have data in this row // Count how many header columns have data in this row
+5 -1
View File
@@ -1,6 +1,10 @@
<?php <?php
require_once dirname(__DIR__, 2) . '/vendor/autoload.php'; require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
require_once dirname(__FILE__) . '/class/VisualLimsApiClient.class.php'; require_once __DIR__ . '/class/db-functions.php';
include dirname(__DIR__) . '/../extra/auth.php';
if (!Auth::check()) { http_response_code(401); echo json_encode(['error' => 'Unauthorized']); exit; }
require_once __DIR__ . '/class/VisualLimsApiClient.class.php';
header('Content-Type: application/json'); header('Content-Type: application/json');
ini_set('display_errors', '0'); ini_set('display_errors', '0');
@@ -1,6 +1,10 @@
<?php <?php
require_once dirname(__DIR__, 2) . '/vendor/autoload.php'; require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
require_once dirname(__FILE__) . '/class/VisualLimsApiClient.class.php'; require_once __DIR__ . '/class/db-functions.php';
include dirname(__DIR__) . '/../extra/auth.php';
if (!Auth::check()) { http_response_code(401); echo json_encode(['error' => 'Unauthorized']); exit; }
require_once __DIR__ . '/class/VisualLimsApiClient.class.php';
header('Content-Type: application/json'); header('Content-Type: application/json');
ini_set('display_errors', '0'); ini_set('display_errors', '0');
+17
View File
@@ -1,4 +1,9 @@
<?php <?php
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
require_once __DIR__ . '/class/db-functions.php';
include dirname(__DIR__) . '/../extra/auth.php';
if (!Auth::check()) { http_response_code(401); echo json_encode(['error' => 'Unauthorized']); exit; }
header('Content-Type: application/json'); header('Content-Type: application/json');
ini_set('display_errors', '0'); ini_set('display_errors', '0');
@@ -42,6 +47,18 @@ if ($id !== null) {
exit; exit;
} }
// Return unique MacroMatrice list
if (isset($_GET['macro_list'])) {
$macros = [];
foreach ($matrici as $m) {
$mv = $m['MacroMatrice'] ?? '';
if ($mv !== '' && !in_array($mv, $macros, true)) $macros[] = $mv;
}
sort($macros);
echo json_encode(['success' => true, 'value' => $macros]);
exit;
}
// Search (with optional MacroMatrice filter) // Search (with optional MacroMatrice filter)
$results = []; $results = [];
foreach ($matrici as $m) { foreach ($matrici as $m) {