File: /srv/www/rectt-csmcri.res.in/public_html/gen_tech.php
<?php
require_once 'pdf_primary.php'; // contains getPrimaryDetailsHtml()
require_once 'pdf_tech.php'; // contains getTechSummaryHtml()
require_once dirname(__DIR__) . "/vendor/autoload.php";
function genTechApplicationHtml($user_id, $post_id, $application_id, $registration_id, $ad_id)
{
global $conn;
// 1. Fetch Advertisement details
$advt_no = '<em>-</em>';
if ($ad_id) {
$stmt = $conn->prepare("SELECT Ad_id FROM Advertisement WHERE id = ? LIMIT 1");
if ($stmt) {
$stmt->bind_param("i", $ad_id);
$stmt->execute();
$ad_result = $stmt->get_result()->fetch_assoc();
$stmt->close();
$advt_no = $ad_result['Ad_id'] ?? '<em>-</em>';
}
}
// 2. Fetch Post details
$post_code = $post_name = $category = '<em>-</em>';
if ($post_id) {
$stmt = $conn->prepare("SELECT post_code, post_title, category FROM posts WHERE id = ? LIMIT 1");
if ($stmt) {
$stmt->bind_param("i", $post_id);
$stmt->execute();
$post_result = $stmt->get_result()->fetch_assoc();
$stmt->close();
$post_code = $post_result['post_code'] ?? '<em>-</em>';
$post_name = $post_result['post_title'] ?? '<em>-</em>';
$category = $post_result['category'] ?? '<em>-</em>';
}
}
// Hardcoded Lab Name
$lab_name = "CSIR-CSMCRI";
// Build the HTML
$data = '
<style>
.pdf-header { text-align: center; margin-bottom: 14px; }
.pdf-header h2 { margin-bottom: 7px; font-size: 26px; font-family: "Times New Roman", serif; font-weight: bold; }
.pdf-header .reg-id { font-weight: bold; font-size: 14px; font-family: Arial, sans-serif; }
.pdf-meta { text-align: center; margin-bottom: 8px; font-size: 15px; font-family: Arial, sans-serif; }
.pdf-meta strong,
.pdf-meta b { font-weight: bold; }
.pdf-post { text-align: center; margin-bottom: 20px; font-size: 15px; font-family: Arial, sans-serif; }
.pdf-post b { font-weight: bold; }
.section-divider {
border: none;
border-top: 1px solid #ddd;
margin: 32px auto 22px auto;
width: 820px;
max-width: 100%;
}
</style>
<div class="pdf-header">
<h2>Central Salt and Marine Chemicals Research Institute</h2>
<div class="reg-id">Registration ID: <b>' . htmlspecialchars($registration_id) . '</b></div>
</div>
<div class="pdf-meta">
Advt No: <strong>' . $advt_no . '</strong>
Lab Name: <strong>' . htmlspecialchars($lab_name) . '</strong>
Post Code: <b>' . $post_code . '</b>
</div>
<div class="pdf-post">
Name of Position: <b>' . $post_name . ' (' . $category . ')</b>
</div>
<hr class="section-divider" />
';
// Setup mPDF
$mpdf = new \Mpdf\Mpdf([
"tempDir" => dirname(__DIR__) . "/tmp",
]);
// Prepare Output Path
$outputDir = "sites/upload/tech_applications/" . $application_id . '/';
if (!is_dir($outputDir)) {
mkdir($outputDir, 0777, true);
}
$outputFilename = "application_summary_" . $registration_id . ".pdf";
$outputPath = $outputDir . $outputFilename;
// Write HTML to mPDF
$mpdf->WriteHTML($data);
$mpdf->WriteHTML(getPrimaryDetailsHtml($user_id));
$mpdf->WriteHTML(getTechSummaryHtml($application_id));
// Output PDF to file
$mpdf->Output($outputPath, "F");
return $outputPath;
}
// USAGE EXAMPLE:
// $pdfPath = genTechApplicationHtml(14, 8, 6, "Aoudbec", 5);
// echo "PDF saved to: $pdfPath";
// $html = genTechApplicationHtml(14, 8, 6, "Aoudbec", 5);
// echo $html;