/
var
/
www
/
barefootlaw.org
/
will-generator
/
Upload File
HOME
<?php // Include the necessary autoload file for autoloading classes require 'vendor/autoload.php'; // Import necessary classes from libraries use setasign\Fpdi\Fpdi; use Endroid\QrCode\Color\Color; use Endroid\QrCode\Encoding\Encoding; use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelLow; use Endroid\QrCode\QrCode; use Endroid\QrCode\Label\Label; use Endroid\QrCode\Logo\Logo; use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeEnlarge; use Endroid\QrCode\Writer\PngWriter; use Endroid\QrCode\Writer\ValidationException; // Define a custom class for handling PDF certificate generation class CustomCertificate extends Fpdi { // Property to store participant data private $participantData; // Constructor to initialize the participant data public function __construct() { parent::__construct(); } // Method to add certificate content to the PDF public function addCertificateContent( $fname = '', $lname = '', $othername = '', $subcounty = '', $age = '', $dob = '', $marital_status = '', $spouse_name = '', $spouse_age = '', $gender = '', $email = '', $district = '', $contact = '', $childs_name = '', $childs_age = '', $dependants_name = '', $guardians_name = '', $guardians_address = '', $executor_name = '', $heir_name = '', $heir_address = '', $property_name = '', $witness_name = '', $witness_address = '', $distribution = '', $distribution_name = '', $burry_wishes = '', $charity = '', $other_wishes = '', $charity_distribution = '' ) { // Add a new page to the PDF $this->SetMargins(10, 40, 10); $this->AddPage([210, 140]); // Import the custom PDF template // Add the font to the PDF $this->AddFont('Poppins', '', 'Poppins-Regular.php'); $this->SetTextColor(0, 0, 0); $this->SetXY(-280, 50); $this->SetFont('Arial', 'B', 18); $this->MultiCell(260, 5, "THE REPUBLIC OF UGANDA\n\nTHE SUCCESSION ACT CAP 162\n\nAS AMENDED BY THE SUCCESSION (AMENDMENT) ACT, 2022", 0, 'C'); $this->SetTextColor(65, 65, 65); $this->SetFont('Poppins', '', 20); $this->Ln(20); $this->SetFont('Arial', 'B', 27); $this->SetTextColor(0, 0, 0); $this->MultiCell(260, 9, "THE WILL AND LAST TESTAMENT OF DISPOSITION OF $fname $lname ESTATE OF $subcounty, $district ", 0, 'C'); // Move down 10 units $this->Ln(47); // Genjerate QR code // $qrCodeImage = $this->generateQRCode(); // Output QR code image directly into the PDF // $this->Image($qrCodeImage, 248, 160, 50, 50); // First paragraph $this->SetFont('Poppins', '', 18); // Move down 10 units $this->Ln(30); // Second paragraph $this->SetFont('Poppins', '', 14); $this->MultiCell(250, 5, "I $fname $lname of $district, $subcounty, $age years of age make and declare that this my last will and I hereby revoke all earlier wills and testaments of dispositioning my estate whether written or verbal made by me in my previous perfect mind.", 0, 'C'); // Move down 10 units $this->Ln(20); if (!empty($childs_name)) { // Third paragraph - Replace this block of code with the table $this->SetFont('Poppins', '', 14); $this->MultiCell(250, 5, "The people left behind as part of my family are as hereunder:- ", 0, 'C'); $this->MultiCell(250, 5, "I have the following children: -", 0, 'C'); $this->Ln(5); // Add a small space between the text and the table // Add a table header $this->SetFont('Arial', 'B', 14); $this->Cell(125, 10, 'Name', 1, 0, 'C'); // Cell for Name $this->Cell(125, 10, 'Age', 1, 1, 'C'); // Cell for Age, 1 indicates move to the next line // Data for the table (assuming $familyMembers is an array of arrays containing Name and Age) $familyMembers = []; // Explode the data stored in $childs_name and $childs_age fields $names = explode(',', $childs_name); $ages = explode(',', $childs_age); // Combine the exploded data into $familyMembers array foreach ($names as $index => $name) { $familyMembers[] = [$name, isset($ages[$index]) ? $ages[$index] : '']; // If age is not provided for a name, use an empty string } $this->SetFont('Poppins', '', 14); foreach ($familyMembers as $member) { $this->Cell(125, 10, $member[0], 1, 0, 'C'); // Cell for Name $this->Cell(125, 10, $member[1], 1, 1, 'C'); // Cell for Age, 1 indicates move to the next line } // Move down 10 units after the table $this->Ln(10); } // Move down 10 units $this->Ln(10); // Check if spouse name is provided if (!empty($spouse_name)) { // Sixth paragraph $this->SetFont('Poppins', '', 14); $this->MultiCell(250, 5, "My wife(s) / husband/l am unmarried. [HUSBAND/ WIFE/ WIVES IF ANY] ", 0, 'C'); $this->SetFont('Poppins', '', 14); // Add a small space between the text and the table $this->Ln(5); // Add a table header $this->SetFont('Arial', 'B', 14); $this->Cell(125, 10, 'Name', 1, 0, 'C'); // Cell for Name $this->Cell(125, 10, 'Age', 1, 1, 'C'); // Cell for Age, 1 indicates move to the next line // Data for the table (assuming $familyMembers is an array of arrays containing Name and Age) $familyMembers = []; // Explode the data stored in $spouse_name and $spouse_age fields $names = explode(',', $spouse_name); $ages = explode(',', $spouse_age); // Combine the exploded data into $familyMembers array foreach ($names as $index => $name) { $familyMembers[] = [$name, isset($ages[$index]) ? $ages[$index] : '']; // If age is not provided for a name, use an empty string } $this->SetFont('Poppins', '', 14); foreach ($familyMembers as $member) { $this->Cell(125, 10, $member[0], 1, 0, 'C'); // Cell for Name $this->Cell(125, 10, $member[1], 1, 1, 'C'); // Cell for Age, 1 indicates move to the next line } // Move down 10 units after the table $this->Ln(55); } // Eighth paragraph if (!empty($dependants_name)) { // Check if dependants names are provided $this->SetFont('Poppins', '', 14); $this->MultiCell(250, 5, "I have the following dependants ", 0, 'C'); $this->Ln(5); // Add a small space between the text and the table // Add a table header $this->SetFont('Arial', 'B', 14); $this->Cell(250, 10, 'Name', 1, 1, 'C'); // Cell for Name, 1 indicates move to the next line // Data for the table (assuming $familyMembers is an array containing names) $familyMembers = explode(',', $dependants_name); $this->SetFont('Poppins', '', 14); foreach ($familyMembers as $name) { $this->Cell(250, 10, $name, 1, 1, 'C'); // Cell for Name, 1 indicates move to the next line } // Move down 10 units after the table $this->Ln(30); } // Tenth paragraph $this->SetFont('Poppins', '', 14); $this->MultiCell(250, 5, "I own the following properties (i.e. Land, Shares, Vehicles, Bank Accounts etc.) ", 0, 'C'); $this->Ln(15); // Add a small space between the text and the table // Add a table header $this->SetFont('Arial', 'B', 14); $this->Cell(250, 10, 'List of Property', 1, 1, 'C'); // Cell for Name, 1 indicates move to the next line // Data for the table (assuming $familyMembers is an array containing names) $familyMembers = explode(',', $property_name); $this->SetFont('Poppins', '', 14); foreach ($familyMembers as $name) { $this->Cell(250, 10, $name, 1, 1, 'C'); // Cell for Name, 1 indicates move to the next line } // Move down 10 units after the table $this->Ln(30); // Seventeenth paragraph if (!empty($distribution_name)) { $this->SetFont('Poppins', '', 14); $this->MultiCell(280, 5, "DISTRIBUTION OF PROPERTY ", 0, 'C'); $this->Ln(5); // Add a table header $this->SetFont('Arial', 'B', 14); $this->Cell(125, 10, 'Name', 1, 0, 'C'); // Cell for Name $this->Cell(125, 10, 'Property Given', 1, 1, 'C'); // Cell for Age, 1 indicates move to the next line $familyMembers = []; // Explode the data stored in $childs_name and $childs_age fields $names = explode(',', $distribution_name); $ages = explode(',', $distribution); // Combine the exploded data into $familyMembers array foreach ($names as $index => $name) { $familyMembers[] = [$name, isset($ages[$index]) ? $ages[$index] : '']; // If age is not provided for a name, use an empty string } $this->SetFont('Poppins', '', 14); foreach ($familyMembers as $member) { $this->Cell(125, 10, $member[0], 1, 0, 'C'); // Cell for Name $this->Cell(125, 10, $member[1], 1, 1, 'C'); // Cell for Age, 1 indicates move to the next line } // Move down 10 units after the table $this->Ln(30); } // Twenty eighth paragraph if (!empty($charity)) { // Check if charity name is provided $this->SetFont('Poppins', '', 14); $this->MultiCell(250, 5, " Charity Distribution", 0, 'C'); $this->Ln(5); // Add a table header $this->SetFont('Arial', 'B', 14); $this->Cell(125, 10, 'Name', 1, 0, 'C'); // Cell for Name $this->Cell(125, 10, 'Property Distributed', 1, 1, 'C'); // Cell for Age, 1 indicates move to the next line // Data for the table (assuming $familyMembers is an array of arrays containing Name and Age) $familyMembers = []; // Explode the data stored in $childs_name and $childs_age fields $names = explode(',', $charity); $ages = explode(',', $charity_distribution); // Combine the exploded data into $familyMembers array foreach ($names as $index => $name) { $familyMembers[] = [$name, isset($ages[$index]) ? $ages[$index] : '']; // If age is not provided for a name, use an empty string } $this->SetFont('Poppins', '', 14); foreach ($familyMembers as $member) { $this->Cell(125, 10, $member[0], 1, 0, 'C'); // Cell for Name $this->Cell(125, 10, $member[1], 1, 1, 'C'); // Cell for Age, 1 indicates move to the next line } // Move down 10 units after the table $this->Ln(30); } // Twenty fourth paragraph if (!empty($guardians_name)){ $this->SetFont('Poppins', '', 14); $this->MultiCell(250, 5, "GUARDIAN(S) OF YOUNG CHILDREN ", 0, 'C'); $this->Ln(5); // Add a table header $this->SetFont('Arial', 'B', 14); $this->Cell(125, 10, 'Name', 1, 0, 'C'); // Cell for Name $this->Cell(125, 10, 'Address', 1, 1, 'C'); // Cell for Age, 1 indicates move to the next line // Data for the table (assuming $familyMembers is an array of arrays containing Name and Age) $familyMembers = []; // Explode the data stored in $childs_name and $childs_age fields $names = explode(',', $guardians_name); $ages = explode(',', $guardians_address); // Combine the exploded data into $familyMembers array foreach ($names as $index => $name) { $familyMembers[] = [$name, isset($ages[$index]) ? $ages[$index] : '']; // If age is not provided for a name, use an empty string } $this->SetFont('Poppins', '', 14); foreach ($familyMembers as $member) { $this->Cell(125, 10, $member[0], 1, 0, 'C'); // Cell for Name $this->Cell(125, 10, $member[1], 1, 1, 'C'); // Cell for Age, 1 indicates move to the next line } // Move down 10 units after the table $this->Ln(10); } // Twenty sixth paragraph $this->SetFont('Poppins', '', 14); $this->MultiCell(250, 5, "EXECUTOR ", 0, 'C'); $this->Ln(5); // Add a small space between the text and the table // Add a table header $this->SetFont('Arial', 'B', 14); $this->Cell(250, 10, 'Executor', 1, 1, 'C'); // Cell for Name, 1 indicates move to the next line // Data for the table (assuming $familyMembers is an array containing names) $familyMembers = explode(',', $executor_name); $this->SetFont('Poppins', '', 14); foreach ($familyMembers as $name) { $this->Cell(250, 10, $name, 1, 1, 'C'); // Cell for Name, 1 indicates move to the next line } // Move down 10 units after the table $this->Ln(10); // Twenty eighth paragraph $this->SetFont('Poppins', '', 14); $this->MultiCell(250, 5, "HEIR/HEIRESS ", 0, 'C'); $this->Ln(5); // Add a table header $this->SetFont('Arial', 'B', 14); $this->Cell(125, 10, 'Name', 1, 0, 'C'); // Cell for Name $this->Cell(125, 10, 'Address', 1, 1, 'C'); // Cell for Age, 1 indicates move to the next line // Data for the table (assuming $familyMembers is an array of arrays containing Name and Age) $familyMembers = []; // Explode the data stored in $childs_name and $childs_age fields $names = explode(',', $heir_name); $ages = explode(',', $heir_address); // Combine the exploded data into $familyMembers array foreach ($names as $index => $name) { $familyMembers[] = [$name, isset($ages[$index]) ? $ages[$index] : '']; // If age is not provided for a name, use an empty string } $this->SetFont('Poppins', '', 14); foreach ($familyMembers as $member) { $this->Cell(125, 10, $member[0], 1, 0, 'C'); // Cell for Name $this->Cell(125, 10, $member[1], 1, 1, 'C'); // Cell for Age, 1 indicates move to the next line } // Move down 10 units after the table $this->Ln(20); // Twenty eighth paragraph if (!empty($burry_wishes)){ $this->SetFont('Poppins', '', 14); $this->MultiCell(250, 5, "BURIAL PLACE ", 0, 'C'); $this->Ln(5); // Add a small space between the text and the table // Add a table header $this->SetFont('Arial', 'B', 14); $this->Cell(250, 10, 'Location Of Burial Place', 1, 1, 'C'); // Cell for Name, 1 indicates move to the next line // Data for the table (assuming $familyMembers is an array containing names) $burry = explode(',', $burry_wishes); // <-- Corrected variable name here $this->SetFont('Poppins', '', 14); foreach ($burry as $wish) { $this->Cell(250, 10, $wish, 1, 1, 'C'); // Cell for Name, 1 indicates move to the next line } // Move down 10 units after the table $this->Ln(15); } // Twenty eighth paragraph // Check if other wishes are provided if (!empty($other_wishes)) { // Twenty eighth paragraph $this->SetFont('Poppins', '', 14); $this->MultiCell(250, 5, "OTHER WISHES ", 0, 'C'); $this->Ln(5); // Add a small space between the text and the table // Add a table header $this->SetFont('Arial', 'B', 14); $this->Cell(250, 10, 'Other Last Wishes', 1, 1, 'C'); // Cell for Name, 1 indicates move to the next line // Data for the table (assuming $familyMembers is an array containing names) $other = explode(',', $other_wishes); // <-- Corrected variable name here $this->SetFont('Poppins', '', 14); foreach ($other as $wishes) { $this->Cell(250, 10, $wishes, 1, 1, 'C'); // Cell for Name, 1 indicates move to the next line } // Move down 10 units after the table $this->Ln(20); } // Thirtieth paragraph $this->SetFont('Poppins', '', 14); $this->MultiCell(250, 5, "SIGNED BY ", 0, 'C'); $this->Ln(5); // Add a table header $this->SetFont('Arial', 'B', 14); $this->Cell(125, 10, 'Name', 1, 0, 'C'); // Cell for Name $this->Cell(125, 10, 'Signature/Thumb mark', 1, 1, 'C'); // Cell for Age, 1 indicates move to the next line // Data for the table (assuming $familyMembers is an array of arrays containing Name and Age) $familyMembers = [ [$fname . ' ' . $lname, ''], // Concatenate $fname and $lname for the Name column, leave Signature/Thumb mark empty // Add more rows as needed ]; $this->SetFont('Poppins', '', 14); foreach ($familyMembers as $index => $member) { $this->Cell(125, 10, $member[0], 1, 0, 'C'); // Cell for Name // Determine the height of the cell for the Signature/Thumb mark based on whether it's the last row or not $cellHeight = ($index == count($familyMembers) - 1) ? 10 : 15; $this->Cell(125, $cellHeight, "", 1, 1, 'C'); // Cell for Signature/Thumb mark, 1 indicates move to the next line } // Move down 10 units $this->Ln(30); // Thirtieth paragraph // Set font for the table header $this->SetFont('Poppins', '', 14); $this->MultiCell(250, 5, "WITNESSES", 0, 'C'); $this->Ln(5); // Add a table header $this->SetFont('Arial', 'B', 14); // Add a table header for the first column $this->Cell(85, 10, 'Name', 1, 0, 'C'); // Cell for Witness Name $this->Cell(85, 10, 'Address', 1, 0, 'C'); // Cell for Witness Address $this->Cell(85, 10, 'Signature', 1, 1, 'C'); // Cell for Witness Signature // Explode the witness data stored in the database $witness_names = explode(',', $witness_name); $witness_addresses = explode(',', $witness_address); $this->SetFont('Poppins', '', 14); // Ensure each witness has a name, address, and signature $witness_count = max(count($witness_names), count($witness_addresses)); for ($i = 0; $i < $witness_count; $i++) { // Retrieve data for each witness, or use empty string if not available $name = isset($witness_names[$i]) ? $witness_names[$i] : ''; $address = isset($witness_addresses[$i]) ? $witness_addresses[$i] : ''; // Output the data for each witness $this->Cell(85, 10, $name, 1, 0, 'C'); // Cell for Witness Name $this->Cell(85, 10, $address, 1, 0, 'C'); // Cell for Witness Address $this->Cell(85, 10, "", 1, 1, 'C'); // Cell for Witness Signature, move to the next line } // Move down 10 units after the table $this->Ln(20); } // Method to add a header to each page public function Header() { // Set the path to your header image $headerImagePath = 'logo.jpg'; // Add the header image to each page $this->Image($headerImagePath, 130, 8, 20); } public function Footer() { // Set the position of the footer $this->SetY(-13); // Footer text parts $footerText = [ 'Call 0392177405/0755149984/0800220000 | WhatsApp 0785824078', 'Email: ask@barefootlaw.org | Website: www.barefootlaw.org', 'Facebook: Barefoot Lawyers- Uganda | Twitter: barefootlaw_org' ]; // Set font for footer text $this->SetFont('Poppins', '', 8); // Display footer text vertically foreach ($footerText as $text) { $this->Cell(0, 3, $text, 0, 1, 'C'); } { // Set the position of the footer $this->SetY(-15); // Set font for footer text $this->SetFont('Arial', 'I', 8); // Page number $pageNumber = $this->PageNo(); // Add page number to the footer $this->Cell(0, 10, 'Page ' . $pageNumber, 0, 0, 'R'); } } // Method to generate a QR code for the participant private function generateQRCode() { $writer = new PngWriter(); $verificationLink = "http://localhost/Certificate%20system/2/certificate-generator-PHP-master/verify_certificate.php?id={$this->participantData['id']}"; // Create QR code $qrCode = QrCode::create($verificationLink) ->setEncoding(new Encoding('UTF-8')) ->setErrorCorrectionLevel(new ErrorCorrectionLevelLow()) ->setSize(300) ->setMargin(30) ->setRoundBlockSizeMode(new RoundBlockSizeModeEnlarge()) ->setForegroundColor(new Color(0, 0, 0)) ->setBackgroundColor(new Color(239, 238, 234)); $result = $writer->write($qrCode); $filePath = __DIR__.'/qrcode.png'; $result->saveToFile($filePath); // Generate a data URI to include image data inline (i.e. inside an <img> tag) return $filePath; } } // Check if participant ID is provided in the URL if (isset($_GET['id'])) { $participantId = $_GET['id']; // Connect to the database $conn = new mysqli('localhost', 'root', '', 'certificates'); // Check if the connection was successful if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Fetch participant data from the database using the provided participant ID $query = "SELECT * FROM participant WHERE id = $participantId"; $result = $conn->query($query); // Check if the query returned any results if ($result->num_rows > 0) { // Fetch the participant data as an associative array $participantData = $result->fetch_assoc(); // Create a custom certificate object with the participant data $certificate = new CustomCertificate($participantData); // Add the certificate content to the PDF $certificate->addCertificateContent(); // Output the PDF to the browser $certificate->Output(); } else { // No participant data found for the given ID echo "No participant data found for ID: $participantId"; } // Close the database connection $conn->close(); } ?>