diff --git a/.gitignore b/.gitignore index 2d042e3..fb2dc42 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,7 @@ public/userarea/schemi_base_response.json public/userarea/cache/ public/userarea/error_log.txt + +# File PDF di esempio e importati +/public/userarea/pdftemplates/*.pdf +/public/userarea/pdftemplates/imported/*.pdf \ No newline at end of file diff --git a/db/migrations/20260815054854_add_pdf_support_to_templates.php b/db/migrations/20260815054854_add_pdf_support_to_templates.php new file mode 100644 index 0000000..df06fab --- /dev/null +++ b/db/migrations/20260815054854_add_pdf_support_to_templates.php @@ -0,0 +1,48 @@ +table('excel_templates'); + + if (!$templates->hasColumn('sample_pdf')) { + $templates->addColumn('sample_pdf', 'string', [ + 'limit' => 255, + 'null' => true, + 'default' => null, + 'after' => 'sample_xlsx', + 'comment' => 'Filename of the sample PDF used to draw regions', + ]); + } + + if (!$templates->hasColumn('pdf_page_meta')) { + $templates->addColumn('pdf_page_meta', 'text', [ + 'null' => true, + 'default' => null, + 'comment' => 'JSON: pages count and rendered dimensions per page', + ]); + } + + $templates->update(); + + // 2) Riquadri (etichetta + dato) per ogni campo mappato + $mapping = $this->table('template_mapping'); + + if (!$mapping->hasColumn('pdf_regions')) { + $mapping->addColumn('pdf_regions', 'text', [ + 'null' => true, + 'default' => null, + 'after' => 'json_node', + 'comment' => 'JSON: {page, label:{x,y,w,h}, value:{x,y,w,h}}', + ]); + } + + $mapping->update(); + } +} diff --git a/db/migrations/20260815055418_add_pdf_to_source_type_enum.php b/db/migrations/20260815055418_add_pdf_to_source_type_enum.php new file mode 100644 index 0000000..80ef767 --- /dev/null +++ b/db/migrations/20260815055418_add_pdf_to_source_type_enum.php @@ -0,0 +1,24 @@ +execute( + "ALTER TABLE `excel_templates` + MODIFY `source_type` ENUM('XLS','API','PDF') NOT NULL DEFAULT 'XLS'" + ); + } + + public function down(): void + { + $this->execute( + "ALTER TABLE `excel_templates` + MODIFY `source_type` ENUM('XLS','API') NOT NULL DEFAULT 'XLS'" + ); + } +} diff --git a/public/userarea/import_dashboard.php b/public/userarea/import_dashboard.php index 057b2bd..31d245b 100644 --- a/public/userarea/import_dashboard.php +++ b/public/userarea/import_dashboard.php @@ -297,7 +297,9 @@ wrapper.className = "template-btn-wrapper"; const btn = document.createElement("a"); - btn.href = `import_xls2.php?id=${template.id}`; + btn.href = (sourceType === 'PDF') ? + `import_pdf.php?id=${template.id}` : + `import_xls2.php?id=${template.id}`; btn.className = `btn ${sizeClass}`; btn.style.backgroundColor = template.button_bg_color || '#0d6efd'; btn.style.color = template.button_text_color || '#ffffff'; diff --git a/public/userarea/import_pdf.php b/public/userarea/import_pdf.php new file mode 100644 index 0000000..60c317b --- /dev/null +++ b/public/userarea/import_pdf.php @@ -0,0 +1,321 @@ +getConnection(); + +$stmt = $pdo->prepare("SELECT id, name, source_type, idclient, sample_pdf FROM excel_templates WHERE id = ?"); +$stmt->execute([$id]); +$template = $stmt->fetch(PDO::FETCH_ASSOC); + +if (!$template) { + header("Location: template_dashboard.php?status=error&message=" . urlencode("Template not found")); + exit; +} + +$sourceType = strtoupper($template['source_type'] ?? ''); +if ($sourceType !== 'PDF') { + // Non è un template PDF: rimanda al flusso corretto + header("Location: import_xls2.php?id=" . $id); + exit; +} + +// Conta i mapping con riquadri, per avvisare se non è configurato +$stmt = $pdo->prepare("SELECT COUNT(*) FROM template_mapping WHERE template_id = ? AND pdf_regions IS NOT NULL AND pdf_regions <> ''"); +$stmt->execute([$id]); +$mappedRegions = (int)$stmt->fetchColumn(); +?> + + + +
+ + + + +