| Server IP : 69.72.244.102 / Your IP : 216.73.216.164 Web Server : LiteSpeed System : Linux s3434.fra1.stableserver.net 4.18.0-513.24.1.lve.2.el8.x86_64 #1 SMP Fri May 24 12:42:50 UTC 2024 x86_64 User : konzalta ( 1271) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/konzalta/public_html/wp-content/plugins/leads/ |
Upload File : |
<?php
require_once plugin_dir_path(__FILE__) . 'fpdf/fpdf.php';
function generate_lead_pdf($lead) {
$pdf = new FPDF();
$pdf->AddPage();
// Set title
$pdf->SetFont('Arial','B',16);
$pdf->Cell(0,10,'Lead Qualification Submission',0,1,'C');
$pdf->Ln(10); // Line break
$pdf->SetFont('Arial','',12);
foreach ($lead as $label => $value) {
// Format label (e.g. "is_decision_maker" → "Is Decision Maker")
$label = ucwords(str_replace('_', ' ', $label));
$pdf->Cell(60,10, $label, 1);
$pdf->Cell(120,10, $value, 1);
$pdf->Ln();
}
// Output PDF to browser
$pdf->Output('D', 'lead_submission_' . $lead['id'] . '.pdf');
}
// Hook into WordPress admin post
add_action('admin_post_download_lead_pdf', 'handle_pdf_download');
function handle_pdf_download() {
if (!current_user_can('manage_options')) {
wp_die('Unauthorized user');
}
if (!isset($_GET['lead_id'])) {
wp_die('Missing lead ID');
}
global $wpdb;
$table_name = $wpdb->prefix . 'lead_submissions';
$lead_id = intval($_GET['lead_id']);
$lead = $wpdb->get_row("SELECT * FROM $table_name WHERE id = $lead_id", ARRAY_A);
if (!$lead) {
wp_die('Lead not found');
}
generate_lead_pdf($lead);
exit;
}