Jump to content

Urgent! help needed in implementing multiple table insert during form submission


Recommended Posts

<?php
// Using the class via include
class ClientRegistration
{
    private $conn;
    private $errors = [];
    public $inputs = [];
    public $types = [];
    public $roles = [];
    public $statuses = [];
    public $titles = [];
    public $relationships = [];
    public $genders = [];
    public $maritalstatuses = [];
    public $nationalities = [];
    public $states = [];
    public $lgas = [];
    public $branches = [];
    public $accountcategories = [];
    public $accounttypes = [];
    public $accountservices = [];
    public $allbanks = [];
    public $idcardtypes = [];
    public $employmentstatuses = [];
    public $employmentsalaryranges = [];
    public $utilitybilltypes = [];
    private $uploadIDCard; 
    private $uploadPassport;
    private $uploadSignature;
    private $uploadUtilityBill;
    private $uploadNextOfKinPassport;
    private $uploadSeal;

    private $currentUserId;
    private $currentUserTypeId;
    private $currentUserRoleId;
    private $currentUserBranchId;

    public function __construct($db)
    {
        $this->conn = $db;
        $this->fetchTypes();
        $this->fetchRoles();
        $this->fetchStatuses();
        $this->fetchTitles();
        $this->fetchRelationships();
        $this->fetchGenders();
        $this->fetchMarital_Statuses();
        $this->fetchNationalities();
        $this->fetchStates();
        $this->fetchLGAs();
        $this->fetchBranches();
        $this->fetchAccountCategories();
        $this->fetchAccountTypes();
        $this->fetchAccountServices();
        $this->fetchAllBanks();
        $this->fetchIDCardTypes();
        $this->fetchEmploymentStatuses();
        $this->fetchEmploymentSalaryRanges();
        $this->fetchUtilityBillTypes();
        $this->uploadIDCard = "../../ESS/ACCT/files/IDCards/";
        $this->uploadPassport = "../../ESS/ACCT/files/Passports/";
        $this->uploadUtilityBill = "../../ESS/ACCT/files/UtilityBills/";
        $this->uploadSignature = "../../ESS/ACCT/files/Signatures/";
        $this->uploadNextOfKinPassport = "../../ESS/ACCT/files/NOK/";
        $this->uploadSeal = "../../ESS/ACCT/files/Seals/";
        $this->currentUserId = $_SESSION["user_id"] ?? null;
        $this->currentUserTypeId = $_SESSION["type"] ?? null;
        $this->currentUserRoleId = $_SESSION["type"] ?? null;
        $this->currentUserBranchId = $_SESSION["branch"] ?? null;
    }

    private function fetchTypes()
    {
        $stmt = $this->conn->query("SELECT id, name FROM types");
        $this->types = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    }

    private function fetchRoles()
    {
        $stmt = $this->conn->query("SELECT id, name FROM roles");
        $this->roles = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    }

    private function fetchStatuses()
    {
        $stmt = $this->conn->query("SELECT id, name FROM statuses");
        $this->statuses = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    }

    private function fetchTitles()
    {
        $stmt = $this->conn->query("SELECT id, name FROM titles");
        $this->titles = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    }

    private function fetchRelationships()
    {
        $stmt = $this->conn->query("SELECT id, name FROM relationships");
        $this->relationships = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    }

    private function fetchGenders()
    {
        $stmt = $this->conn->query("SELECT id, name FROM genders");
        $this->genders = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    }

    private function fetchMarital_Statuses()
    {
        $stmt = $this->conn->query("SELECT id, name FROM marital_statuses");
        $this->maritalstatuses = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    }

    private function fetchNationalities()
    {
        $stmt = $this->conn->query("SELECT id, name FROM nationalities");
        $this->nationalities = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    }

    private function fetchStates()
    {
        $stmt = $this->conn->query("SELECT id, name FROM states");
        $this->states = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    }

    private function fetchLGAs()
    {
        $stmt = $this->conn->query("SELECT id, name FROM lgas");
        $this->lgas = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    }

    private function fetchBranches()
    {
        $stmt = $this->conn->query("SELECT id, name FROM branches");
        $this->branches = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    }

    private function fetchAccountCategories()
    {
        $stmt = $this->conn->query("SELECT id, name FROM account_categories");
        $this->accountcategories = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    }

    private function fetchAccountTypes()
    {
        $stmt = $this->conn->query("SELECT id, name FROM account_types");
        $this->accounttypes = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    }

    private function fetchAccountServices()
    {
        $stmt = $this->conn->query("SELECT id, name FROM account_services");
        $this->accountservices = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    }

    private function fetchAllBanks()
    {
        $stmt = $this->conn->query("SELECT id, name FROM all_banks");
        $this->allbanks = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    }

    private function fetchIDCardTypes()
    {
        $stmt = $this->conn->query("SELECT id, name FROM id_cards");
        $this->idcardtypes = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    }
    private function fetchUtilityBillTypes()
    {
        $stmt = $this->conn->query("SELECT id, name FROM utility_bills");
        $this->utilitybilltypes = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    }
    private function fetchEmploymentStatuses()
    {
        $stmt = $this->conn->query("SELECT id, name FROM employment_statuses");
        $this->employmentstatuses = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    }
    private function fetchEmploymentSalaryRanges()
    {
        $stmt = $this->conn->query("SELECT id, s_range FROM employment_salaries");
        $this->employmentsalaryranges = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
    }
    
    
    public function validateAndRegister()
    {
        if ($_SERVER["REQUEST_METHOD"] == "POST") {
            $this->storeInputs();
            $this->validateFields();

            if (empty($this->errors)) {
                $userId = $this->registerUser();

                if ($userId) {
                    // $_SESSION['user_id'] = $userId;
                    // $_SESSION['username'] = $this->inputs['username'];
                    // $_SESSION['role'] = $this->inputs['role'];
                    // $this->redirectBasedOnRole();

                    // Display success message
                        // echo '<div class="alert alert-success">Registration successful! You will be redirected to the dashboard in 3 seconds.</div>';
                        // echo '<script>setTimeout(function(){ window.location.href = "Dashboard.php"; }, 3000);</script>';


                    // Display success message
                        $_SESSION['success'] = "Registration successful! You are now logged in.";

                        // Redirect to dashboard
                        header("Location: /ESS/ACCT/Clients/Manage.php");
                        exit;
                }
            }
        }
    }

    private function storeInputs()
    {
        $this->inputs['branch'] = $_POST['branch'] ?? '';
        $this->inputs['accountcategory'] = $_POST['accountcategory'] ?? '';
        $this->inputs['accounttype'] = $_POST['accounttype'] ?? '';
        $this->inputs['accountnumber'] = $_POST['accountnumber'] ?? '';
        
        // $this->inputs['alert_sms'] = $_POST['alert_sms'] ?? '';
        // $this->inputs['alert_email'] = $_POST['alert_email'] ?? '';
        // $this->inputs['alert_printed'] = $_POST['alert_printed'] ?? '';
        // $this->inputs['statement_email'] = $_POST['statement_email'] ?? '';
        // $this->inputs['statement_printed'] = $_POST['statement_printed'] ?? '';

        $this->inputs['personalaccountbank'] = $_POST['personalaccountbank'] ?? '';
        $this->inputs['personalaccounttype'] = $_POST['personalaccounttype'] ?? '';
        $this->inputs['personalaccountnumber'] = $_POST['personalaccountnumber'] ?? '';
        $this->inputs['bvn'] = $_POST['bvn'] ?? '';
        $this->inputs['tin'] = $_POST['tin'] ?? '';
        $this->inputs['idcardtype'] = $_POST['idcardtype'] ?? '';
        $this->inputs['idnumber'] = $_POST['idnumber'] ?? '';
        $this->inputs['idissueddate'] = $_POST['idissueddate'] ?? '';
        $this->inputs['idexpirydate'] = $_POST['idexpirydate'] ?? '';
        $this->inputs['title'] = $_POST['title'] ?? '';
        $this->inputs['surname'] = $_POST['surname'] ?? '';
        $this->inputs['firstname'] = $_POST['firstname'] ?? '';
        $this->inputs['othername'] = $_POST['othername'] ?? '';
        $this->inputs['gender'] = $_POST['gender'] ?? '';
        $this->inputs['dob'] = $_POST['dob'] ?? '';
        $this->inputs['maritalstatus'] = $_POST['maritalstatus'] ?? '';
        $this->inputs['phonenumber'] = $_POST['phonenumber'] ?? '';
        $this->inputs['phonenumber2'] = $_POST['phonenumber2'] ?? '';
        $this->inputs['email'] = $_POST['email'] ?? '';
        $this->inputs['email2'] = $_POST['email2'] ?? '';
        $this->inputs['username'] = $_POST['username'] ?? '';
        // $this->inputs['password'] = $_POST['password'] ?? '';
        // $this->inputs['confirmpassword'] = $_POST['confirmpassword'] ?? '';
        $this->inputs['businessorofficeaddress'] = $_POST['businessorofficeaddress'] ?? '';
        $this->inputs['cityortown'] = $_POST['cityortown'] ?? '';
        $this->inputs['nationality'] = $_POST['nationality'] ?? '';
        $this->inputs['stateoforigin'] = $_POST['stateoforigin'] ?? '';
        $this->inputs['lgaoforigin'] = $_POST['lgaoforigin'] ?? '';
        $this->inputs['addressoforigin'] = $_POST['addressoforigin'] ?? '';
        $this->inputs['stateofresidence'] = $_POST['stateofresidence'] ?? '';
        $this->inputs['lgaofresidence'] = $_POST['lgaofresidence'] ?? '';
        $this->inputs['addressofresidence'] = $_POST['addressofresidence'] ?? '';
        $this->inputs['streetname'] = $_POST['streetname'] ?? '';
        $this->inputs['housenumber'] = $_POST['housenumber'] ?? '';
        $this->inputs['nearestbustoporlandmark'] = $_POST['nearestbustoporlandmark'] ?? '';
        $this->inputs['utilitybilltype'] = $_POST['utilitybilltype'] ?? '';
        $this->inputs['employmentstatus'] = $_POST['employmentstatus'] ?? '';
        $this->inputs['employmentsalaryrange'] = $_POST['employmentsalaryrange'] ?? '';
        $this->inputs['natureofemploymentorbusiness'] = $_POST['natureofemploymentorbusiness'] ?? '';
        $this->inputs['employmentindate'] = $_POST['employmentindate'] ?? '';
        $this->inputs['employmentoutdate'] = $_POST['employmentoutdate'] ?? '';
        $this->inputs['employmentphonenumber'] = $_POST['employmentphonenumber'] ?? '';
        $this->inputs['employmentemail'] = $_POST['employmentemail'] ?? '';
        $this->inputs['employmentnationality'] = $_POST['employmentnationality'] ?? '';
        $this->inputs['employmentstate'] = $_POST['employmentstate'] ?? '';
        $this->inputs['employmentlga'] = $_POST['employmentlga'] ?? '';
        $this->inputs['employmentcityortown'] = $_POST['employmentcityortown'] ?? '';
        $this->inputs['employmentnearestbustoporlandmark'] = $_POST['employmentnearestbustoporlandmark'] ?? '';
        $this->inputs['employmentaddress'] = $_POST['employmentaddress'] ?? '';
        $this->inputs['employmentplotorstreetname'] = $_POST['employmentplotorstreetname'] ?? '';
        $this->inputs['employmenthouseorplotnumber'] = $_POST['employmenthouseorplotnumber'] ?? '';
        $this->inputs['nextofkintitle'] = $_POST['nextofkintitle'] ?? '';
        $this->inputs['nextofkinrelationship'] = $_POST['nextofkinrelationship'] ?? '';
        $this->inputs['nextofkinsurname'] = $_POST['nextofkinsurname'] ?? '';
        $this->inputs['nextofkinfirstname'] = $_POST['nextofkinfirstname'] ?? '';
        $this->inputs['nextofkinothername'] = $_POST['nextofkinothername'] ?? '';
        $this->inputs['nextofkinnatureofemploymentorbusiness'] = $_POST['nextofkinnatureofemploymentorbusiness'] ?? '';
        $this->inputs['nextofkinbusinessorofficeaddress'] = $_POST['nextofkinbusinessorofficeaddress'] ?? '';
        $this->inputs['nextofkingender'] = $_POST['nextofkingender'] ?? '';
        $this->inputs['nextofkindob'] = $_POST['nextofkindob'] ?? '';
        $this->inputs['nextofkinmaritalstatus'] = $_POST['nextofkinmaritalstatus'] ?? '';
        $this->inputs['nextofkinphonenumber'] = $_POST['nextofkinphonenumber'] ?? '';
        $this->inputs['nextofkinemail'] = $_POST['nextofkinemail'] ?? '';
        $this->inputs['nextofkinnationality'] = $_POST['nextofkinnationality'] ?? '';
        $this->inputs['nextofkinstate'] = $_POST['nextofkinstate'] ?? '';
        $this->inputs['nextofkinlga'] = $_POST['nextofkinlga'] ?? '';
        $this->inputs['nextofkincityortown'] = $_POST['nextofkincityortown'] ?? '';
        $this->inputs['nextofkinaddress'] = $_POST['nextofkinaddress'] ?? '';
        $this->inputs['nextofkinhousenumber'] = $_POST['nextofkinhousenumber'] ?? '';
        $this->inputs['nextofkinstreetname'] = $_POST['nextofkinstreetname'] ?? '';
        $this->inputs['nextofkinnearestbusstoporlandmark'] = $_POST['nextofkinnearestbusstoporlandmark'] ?? '';
        $this->inputs['sealnumber'] = $_POST['sealnumber'] ?? '';
        
    }

    private function validateFields()
    {

        $this->validateIDCard();
        $this->validatePassport();
        $this->validateUtilityBill();
        $this->validateSignature();
        $this->validateNextOfKinPassport();

        $this->validateBranch();
        $this->validateAccountCategory();
        $this->validateAccountType();
        $this->validateAccountNumber();
        $this->validatePersonalAccountBank();
        $this->validatePersonalAccountType();
        $this->validatePersonalAccountNumber();
        $this->validateBVN();
        $this->validateTin();
        $this->validateIDCardType();
        $this->validateIDCardNumber();
        $this->validateIDCardIssuedDate();
        $this->validateIDCardExpiryDate();
        $this->validateTitle();
        $this->validateTextField("surname", 3, 100);
        $this->validateTextField("firstname", 3, 100);
        $this->validateTextField("othername", 3, 50, false);
        $this->validateGender();
        $this->validateDOB();
        $this->validateMaritalStatus();
        $this->validatePhoneNumber();
        $this->validatePhoneNumber2();
        $this->validateEmail();
        $this->validateEmail2();
        $this->validateUsername();
        $this->validatePassword();
        $this->validateBusinessOrOfficeAddress();
        $this->validateCityOrTown();
        $this->validateNationality();
        $this->validateStateOfOrigin();
        $this->validateLGAOfOrigin();
        $this->validateAddressOfOrigin();
        $this->validateStateOfResidence();
        $this->validateLGAOfResidence();
        $this->validateAddressOfResidence();
        $this->validateStreetName();
        $this->validateHouseNumber();
        $this->validateNearestBustoporLandMark();
        $this->validateUtilityBillType();
        $this->validateEmploymentStatus();
        $this->validateEmploymentSalaryRange();
        $this->validateEmploymentNature();
        $this->validateEmploymentName();
        $this->validateEmploymentInDate();
        $this->validateEmploymentOutDtae();
        $this->validateEmploymentPhone();
        $this->validateEmploymentEmail();
        $this->validateEmploymentNationality();
        $this->validateEmploymentState();
        $this->validateEmploymentLGA();
        $this->validateEmploymentCityOrTown();
        $this->validateEmploymentNearestBusStopOrLandMark();
        $this->validateEmploymentAddress();
        $this->validateEmplotmentPlotOrStreetName();
        $this->validateEmploymentHouseOrPlotNumber();
        $this->validateNextofkinTitle();
        $this->validateNextofkinRelationship();
        $this->validateTextField("nextofkinsurname", 3, 100, false);
        $this->validateTextField("nextofkinfirstname", 3, 100, false);
        $this->validateTextField("nextofkinothername", 3, 50, false);
        $this->validateNextofkinNatureOfEmploymentOrBusiness();
        $this->validateNextofkinOfficeOrBusinessAddress();
        $this->validateNextofkinGender();
        $this->validateNextofkinDOB();
        $this->validateNextofkinMaritalStatus();
        $this->validateNextofkinPhonenumber();
        $this->validateNextofkinEmail();
        $this->validateNextofkinNationality();
        $this->validateNextofkinState();
        $this->validateNextofkinLGA();
        $this->validateNextofkinCityOrTown();
        $this->validateNextofkinAddress();
        $this->validateNextofkinHouseNunmber();
        $this->validateNextofkinStreetName();
        $this->validateNextofkinNearestBusStopOrLandMark();
        $this->validateSeal();
        $this->validateSealNumber();

    }

    private function validateIDCard()
    {

        if (!empty($_FILES["idcard"]["name"])) {
            $file = $_FILES["idcard"];
            $this->validateFile($file, "idcard", $this->uploadIDCard);
        } else {
            $this->inputs['idcard'] = '';
            // $this->errors['idcard'] = "Select ID card.";
        }
    }

    private function validatePassport()
    {
        if (!empty($_FILES["passport"]["name"])) {
            $file = $_FILES["passport"];
            $this->validateFile($file, "passport", $this->uploadPassport);
        } else {
            $this->errors['passport'] = "Select a passport.";
        }
    }

    private function validateUtilityBill()
    {
        if (!empty($_FILES["utilitybill"]["name"])) {
            $file = $_FILES["utilitybill"];
            $this->validateFile($file, "utilitybill", $this->uploadUtilityBill);
        } else {
            // $this->errors['utilitybill'] = "Upload utility bill.";
            $this->inputs['utilitybill'] = '';
        }
    }

    private function validateSignature()
    {
        if (!empty($_FILES["signature"]["name"])) {
            $file = $_FILES["signature"];
            $this->validateFile($file, "signature", $this->uploadSignature);
        } else {
            // $this->errors['signature'] = "Upload Client's Signature.";
            $this->inputs['signature'] = '';
        }
    }

    private function validateNextOfKinPassport()
    {
        if (!empty($_FILES["nextofkinpassport"]["name"])) {
            $file = $_FILES["nextofkinpassport"];
            $this->validateFile($file, "nextofkinpassport", $this->uploadNextOfKinPassport);
        } else {
            // $this->errors['nextofkinpassport'] = "Upload Nextofkin Passport.";
            $this->inputs['nextofkinpassport'] = '';
        }
    }

    private function validateSeal()
    {
        if (!empty($_FILES["seal"]["name"])) {
            $file = $_FILES["seal"];
            $this->validateFile($file, "seal", $this->uploadSeal);
        } else {
            $this->errors['seal'] = "Upload your Seal.";
            // $this->inputs['signature'] = '';
        }
    }

    private function validateFile($file, $field, $uploadDir)
    {
        $allowedExtensions = ["png", "jpg", "jpeg"];
        $allowedMimes = ["image/jpeg", "image/png"];
        $maxFileSize = 2000000;

        if ($file["error"] !== UPLOAD_ERR_OK) {
            $this->errors[$field] = "File upload error.";
            return;
        }

        $extension = pathinfo($file["name"], PATHINFO_EXTENSION);
        $finfo = new finfo(FILEINFO_MIME_TYPE);
        $mime = $finfo->file($file["tmp_name"]);

        if (!in_array($extension, $allowedExtensions) || !in_array($mime, $allowedMimes)) {
            $this->errors[$field] = "Invalid file format. Only PNG and JPEG are allowed.";
        } elseif ($file["size"] > $maxFileSize) {
            $this->errors[$field] = "File size exceeds 2MB.";
        } else {
            $filename = "ID-" . bin2hex(random_bytes(10)) . "." . $extension;
            $this->inputs[$field] = $filename;
            move_uploaded_file($file["tmp_name"], $uploadDir . $filename);
        }
    }

    private function validateTextField($field, $minLength, $maxLength, $isRequired = true)
    {
        $value = trim($_POST[$field] ?? '');

        if ($isRequired && empty($value)) {
            $this->errors[$field] = "Please enter " . ucfirst($field) . ".";
        } elseif (!empty($value) && (!preg_match('/^[a-zA-Z\s]+$/', $value) || strlen($value) < $minLength || strlen($value) > $maxLength)) {
            $this->errors[$field] = ucfirst($field) . " must be between $minLength and $maxLength characters long and contain only letters and spaces.";
        } else {
            $this->inputs[$field] = htmlspecialchars($value);
        }
    }

    private function validateBranch()
    {
        $branch = $_POST["branch"] ?? '';

        
        // if (empty($branch)) {
        //     $this->inputs['branch'] = $branch;
        // }
        if (!isset($this->branches[$branch])) {
            $this->errors['branch'] = "Select branch.";
        } else {
            $this->inputs['branch'] = $branch;
        }
    }

    private function validateAccountCategory()
    {
        $accountcategory = $_POST["accountcategory"] ?? '';
        
        if (!isset($this->accountcategories[$accountcategory])) {
            $this->errors['accountcategory'] = "Select Account Category.";
        }else {
            $this->inputs['accountcategory'] = $accountcategory;
        }
    }


    private function validateAccountType()
    {
        $accounttype = $_POST["accounttype"] ?? '';

        if (!isset($this->accounttypes[$accounttype])) {
            $this->errors['accounttype'] = "Select Account Type.";
        } else {
            $this->inputs['accounttype'] = $accounttype;
        }
    }


    private function validateAccountNumber()
    {
        $accountnumber = $_POST["accountnumber"] ?? '';

        /*if (empty($accountnumber)) {
            $this->errors['accountnumber'] = "Please enter Account number.";
        }*/

        if (empty($accountnumber)) {
            $this->inputs['accountnumber'] = $accountnumber;
        }elseif (!ctype_digit($accountnumber) || strlen($accountnumber) < 10 || strlen($accountnumber) > 12) {
            $this->errors['accountnumber'] = "Account number must be between 10 and 12 digits..";
        } else {
            $this->inputs['accountnumber'] = $accountnumber;
        }
    }


    private function validatePersonalAccountBank()
    {
        $personalacccountbank = $_POST["personalacccountbank"] ?? '';

        if (empty($personalacccountbank)) {
            $this->inputs['personalacccountbank'] = $personalacccountbank;
        }/* else if (!isset($this->allbanks[$personalacccountbank])) {
            $this->errors['personalacccountbank'] = "Select Personal Bank Type.";
        }*/ else {
            $this->inputs['personalacccountbank'] = $personalacccountbank;
        }
    }

    private function validatePersonalAccountType()
    {
        $personalacccountype = $_POST["personalacccountype"] ?? '';

        // if (!isset($this->accounttypes[$personalacccountype])) {
        //     $this->errors['personalacccountype'] = "Select Personal Account Type.";
        // }
        // if (!isset($this->accounttypes[$personalacccountype])) {
        //     $this->errors['personalacccountype'] = "Select Personal Account Type.";
        // }

        if (empty($personalacccountype)) {
            $this->inputs['personalacccountype'] = $personalacccountype;
        }else {
            $this->inputs['personalacccountype'] = $personalacccountype;
        }
    }

    private function validatePersonalAccountNumber()
    {
        $personalaccountnumber = $_POST["personalaccountnumber"] ?? '';
        if(empty($accountnumber)) {
            $this->inputs['personalaccountnumber'] = $personalaccountnumber;
        }
        /*if (empty($personalaccountnumber)) {
            $this->errors['personalaccountnumber'] = "Enter Personal Account number.";
        } */elseif (!ctype_digit($personalaccountnumber) || strlen($personalaccountnumber) != 11) {
            $this->errors['personalaccountnumber'] = "Personal Account Number must be 11 digits long.";
        } else {
            $this->inputs['personalaccountnumber'] = $personalaccountnumber;
        }
    }


    private function validateBVN()
    {
        $bvn = $_POST["bvn"] ?? '';

        if(empty($bvn)) {
            $this->errors['bvn'] = "Enter BVN.";
        } elseif (!ctype_digit($bvn) || strlen($bvn) < 11) {
            $this->errors['bvn'] = "BVN must be 11 digits long.";
        } else {
            $this->inputs['bvn'] = $bvn;
        }
    }

    private function validateTin()
    {
        $tin = trim($_POST["tin"] ?? '');

        if (empty($tin)) {
            // If TIN is empty, just assign it to inputs without setting an error
            $this->inputs['tin'] = $tin;
        } elseif (!ctype_alnum($tin)) {
            $this->errors['tin'] = "TIN must be alphanumeric.";
        } elseif (strlen($tin) < 12 || strlen($tin) > 15) {
            $this->errors['tin'] = "TIN must be between 12 and 15 characters long.";
        } else {
            $this->inputs['tin'] = $tin;
        }
    }





    private function validateIDCardType()
    {
        $idcardtype = $_POST["idcardtype"] ?? '';

        // if (!isset($this->idcardtypes[$idcardtype])) {
        //     $this->errors['idcardtype'] = "Select ID Type.";
        // }

        if (empty($idcardtype)) {
            $this->inputs['idcardtype'] = $idcardtype;
        } elseif (!isset($this->idcardtypes[$idcardtype])) {
            $this->errors['idcardtype'] = "Select ID Type.";
        } else {
            $this->inputs['idcardtype'] = $idcardtype;
        }
    }

    private function validateIDCardNumber()
    {
        $idnumber = $_POST["idnumber"] ?? '';
    
        // if (empty($idnumber)) {
        //     $this->errors['idnumber'] = "Enter ID Number.";
        // }

        if (empty($idnumber)) {
            $this->inputs['idnumber'] = $idnumber;
        } elseif (!preg_match('/^[a-zA-Z0-9]+$/', $idnumber)) {
            $this->errors['idnumber'] = "ID Number must contain only alphanumeric characters.";
        } elseif (strlen($idnumber) < 10 || strlen($idnumber) > 12) {
            $this->errors['idnumber'] = "ID Number must be between 10 and 12 characters long.";
        } else {
            $this->inputs['idnumber'] = $idnumber;
        }
    }

    private function validateIDCardIssuedDate()
    {
        $idissueddate = trim($_POST["idissueddate"] ?? '');

        if (empty($idissueddate)) {
            $this->inputs['idissueddate'] = '';
            // $this->errors['idissueddate'] = "Enter ID Issued date ";
        } else if (!DateTime::createFromFormat('Y-m-d', $idissueddate)) {
            $this->errors['idissueddate'] = "Enter ID Issued date using correct format.";
        } else {
            $this->inputs['idissueddate'] = $idissueddate;
        }
    }

    private function validateIDCardExpiryDate()
    {
        $idexpirydate = trim($_POST["idexpirydate"] ?? '');

        if (empty($idexpirydate)) {
            $this->inputs['idexpirydate'] = '';
            // $this->errors['idexpirydate'] = "Enter ID Expiry date ";
        } else if (!DateTime::createFromFormat('Y-m-d', $idexpirydate)) {
            $this->errors['idexpirydate'] = "Enter ID Expiry date using correct format.";
        } else {
            $this->inputs['idexpirydate'] = $idexpirydate;
        }
    }
    


    private function validateTitle()
    {
        $title = $_POST["title"] ?? '';

        if (!isset($this->titles[$title])) {
            $this->errors['title'] = "Select Title.";
        } else {
            $this->inputs['title'] = $title;
        }
    }

    private function validateGender()
    {
        $gender = $_POST["gender"] ?? '';

        if (!isset($this->genders[$gender])) {
            $this->errors['gender'] = "Select Gender.";
        } else {
            $this->inputs['gender'] = $gender;
        }
    }

    private function validateDOB()
    {
        $dob = trim($_POST["dob"] ?? '');

        if (empty($dob)) {
            $this->errors['dob'] = "Enter Date of Birth ";
        }/* else if (!DateTime::createFromFormat('Y-m-d', $dob)) {
            $this->errors['dob'] = "Enter a valid date of birth.";
        }*/ else {
            $this->inputs['dob'] = $dob;
        }
    }

    private function validateMaritalStatus()
    {
        $maritalstatus = $_POST["maritalstatus"] ?? '';

        if (!isset($this->maritalstatuses[$maritalstatus])) {
            $this->errors['maritalstatus'] = "Select Marital Status.";
        } else {
            $this->inputs['maritalstatus'] = $maritalstatus;
        }
    }

    private function validatePhoneNumber()
    {
        $phonenumber = $_POST["phonenumber"] ?? '';

        if (empty($phonenumber)) {
            $this->inputs['phonenumber'] = $phonenumber;
        } elseif (!ctype_digit($phonenumber)) {
            $this->errors['phonenumber'] = "Phone Number must digits long.";
        } elseif (strlen($phonenumber) > 12) {
            $this->errors['phonenumber'] = "Phone Number must be 11 digits long.";
        }elseif (strlen($phonenumber) < 12) {
            $this->errors['phonenumber'] = "Phone Number must be 11 digits long.";
        }  else {
            $this->inputs['phonenumber'] = $phonenumber;
        }
    }

    private function validatePhoneNumber2()
    {
        $phonenumber2 = $_POST["phonenumber2"] ?? '';

        // if (empty($phonenumber2)) {
        //     $this->errors['phonenumber2'] = "EnterSecond Phone Number.";
        // } 

        if (empty($phonenumber2)) {
            $this->inputs['phonenumber2'] = $phonenumber2;
        } elseif (!ctype_digit($phonenumber2)) {
            $this->errors['phonenumber2'] = "Second Phone Number must digits long.";
        } elseif (!strlen($phonenumber2) < 11 || strlen($phonenumber2) > 12) {
            $this->errors['phonenumber2'] = "Second Phone Number must be 11 digits long.";
        } else {
            $this->inputs['phonenumber2'] = $phonenumber2;
        }
    }


    private function validateEmail()
    {
        $email = trim($_POST["email"] ?? '');

        if (empty($email)) {
            $this->errors['email'] = "Please enter an email address.";
        } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            $this->errors['email'] = "Invalid email format.";
        } else {
            $stmt = $this->conn->prepare("SELECT id FROM users WHERE id = :email");
            $stmt->bindParam(":email", $email, PDO::PARAM_STR);
            $stmt->execute();
            if ($stmt->rowCount() > 0) {
                $this->errors['email'] = "Email address is already registered.";
            } else {
                $this->inputs['email'] = $email;
            }
        }
    }

    private function validateEmail2()
    {
        $email2 = trim($_POST["email2"] ?? '');

        if (empty($email2)) {
            $this->inputs['email2'] = '';
        } else if (!filter_var($email2, FILTER_VALIDATE_EMAIL)) {
            $this->errors['email2'] = "Enter second valid email address.";
        } else {
            $this->inputs['email2'] = $email2;
        }
    }

    private function validateUsername()
    {
        $username = trim($_POST["username"] ?? '');
        
        if (empty($username)) {
            $this->errors['username'] = "Please enter a username.";
        } else if (!ctype_alpha($username)) {
            $this->errors['username'] = "Username must be alphabet only";
        }else if (strlen($username) < 10 || strlen($username) > 10) {
            $this->errors['username'] = "Username must be between 10 and 15 characters.";
        } else {
            $stmt = $this->conn->prepare("SELECT id FROM users WHERE username = :username");
            $stmt->bindParam(":username", $username, PDO::PARAM_STR);
            $stmt->execute();
            if ($stmt->rowCount() > 0) {
                $this->errors['username'] = "This username is already taken.";
            } else {
                $this->inputs['username'] = $username;
            }
        }
    }

    private function validatePassword()
    {
        $password = trim($_POST["password"] ?? ''); // Get password from POST
        $confirmpassword = trim($_POST["confirmpassword"] ?? ''); // Get password confirmation from POST

        if (empty($password)) { // Check if password is empty
            $this->errors['password'] = "Enter your password.";
        } elseif (strlen($password) < 8 || strlen($password) > 15) { // Validate password length
            $this->errors['password'] = "Password must be between 8 and 15 characters.";
        } else {
            $this->inputs['password'] = password_hash($password, PASSWORD_DEFAULT); // Hash password for security
        }

        if (empty($confirmpassword)) { // Check if password confirmation is empty
            $this->errors['confirmpassword'] = "Enter confirm your password.";
        } elseif ($password !== $confirmpassword) { // Check if passwords match
            $this->errors['confirmpassword'] = "Passwords do not match.";
        }
    }

    private function validateBusinessOrOfficeAddress()
    {
        $businessorofficeaddress = trim($_POST["businessorofficeaddress"] ?? '');
        
        if (empty($businessorofficeaddress)) {
            $this->errors['businessorofficeaddress'] = "Enter Business or Office Address.";
        } else if (!ctype_alpha($businessorofficeaddress)) {
            $this->errors['businessorofficeaddress'] = "Business or Office Address must be alphabet only";
        }else if (strlen($businessorofficeaddress) < 10 || strlen($businessorofficeaddress) > 100) {
            $this->errors['businessorofficeaddress'] = "Business or Office Address Use must be between 10 and 15 characters.";
        }else {
            $this->inputs['businessorofficeaddress'] = $businessorofficeaddress;
        }
    }

    private function validateCityOrTown()
    {
        $cityortown = trim($_POST["cityortown"] ?? '');
        
        if (empty($cityortown)) {
            $this->errors['cityortown'] = "Enter City or Town Address.";
        } else if (!ctype_alpha($cityortown)) {
            $this->errors['cityortown'] = "City or Town Address must be alphabet only";
        }else if (strlen($cityortown) < 10 || strlen($cityortown) > 30) {
            $this->errors['cityortown'] = "City or Town Address Use must be between 10 and 15 characters.";
        }else {
            $this->inputs['cityortown'] = $cityortown;
        }
    }

    private function validateNationality()
    {
        $nationality = $_POST["nationality"] ?? '';

        if (!isset($this->nationalities[$nationality])) {
            $this->errors['nationality'] = "Select Nationality.";
        } else {
            $this->inputs['nationality'] = $nationality;
        }
    }

    private function validateStateOfOrigin()
    {
        $stateoforigin = $_POST["stateoforigin"] ?? '';

        if (!isset($this->states[$stateoforigin])) {
            $this->errors['stateoforigin'] = "Select State of Origin.";
        } else {
            $this->inputs['stateoforigin'] = $stateoforigin;
        }
    }

    private function validateLGAOfOrigin()
    {
        $lgaoforigin = $_POST["lgaoforigin"] ?? '';

        if (!isset($this->lgas[$lgaoforigin])) {
            $this->errors['lgaoforigin'] = "Select LGA of Origin.";
        } else {
            $this->inputs['lgaoforigin'] = $lgaoforigin;
        }
    }

    private function validateAddressOfOrigin()
    {
        $addressoforigin = trim($_POST["addressoforigin"] ?? '');

        if (empty($addressoforigin)) {
            $this->errors['addressoforigin'] = "Enter address of origin.";
        } elseif (!ctype_alpha(str_replace(' ', '', $addressoforigin))) {
            $this->errors['addressoforigin'] = "Address of origin must contain only alphabetic characters and spaces.";
        } elseif (strlen($addressoforigin) < 3 || strlen($addressoforigin) > 300) {
            $this->errors['addressoforigin'] = "Address of origin must be between 10 and 200 characters.";
        } else {
            $this->inputs['addressoforigin'] = $addressoforigin;
        }
    }


    private function validateStateOfResidence()
    {
        $stateofresidence = $_POST["stateofresidence"] ?? '';

        if (!isset($this->states[$stateofresidence])) {
            $this->errors['stateofresidence'] = "Select State of Origin.";
        } else {
            $this->inputs['stateofresidence'] = $stateofresidence;
        }
    }

    private function validateLGAOfResidence()
    {
        $lgaofresidence = $_POST["lgaofresidence"] ?? '';

        if (!isset($this->lgas[$lgaofresidence])) {
            $this->errors['lgaoforigin'] = "Select LGA of Origin.";
        } else {
            $this->inputs['lgaoforigin'] = $lgaofresidence;
        }
    }

    private function validateAddressOfResidence()
    {
        $addressofresidence = trim($_POST["addressofresidence"] ?? '');
        
        if (empty($addressofresidence)) {
            $this->errors['addressofresidence'] = "Enter address of residence";
        } else if (!ctype_alpha($addressofresidence)) {
            $this->errors['addressofresidence'] = "Address of residence must be alphabet only";
        }else if (strlen($addressofresidence) < 10 || strlen($addressofresidence) > 30) {
            $this->errors['addressofresidence'] = "Address of residence must be between 10 and 200 characters.";
        }else {
            $this->inputs['addressofresidence'] = $addressofresidence;
        }
    }


    private function validateStreetName()
    {
        $streetname = trim($_POST["streetname"] ?? '');

        if (empty($streetname)) {
            $this->errors['streetname'] = 'Enter Street Name';
        } else if (!ctype_alpha($streetname)) {
            $this->errors['streetname'] = "Street name must contain alphabet only.";
        } else if (strlen($streetname) < 10 || strlen($streetname) > 30) {
            $this->errors['streetname'] = "Street name must be between 10 and 30 characters.";
        } else {
            $this->inputs['streetname'] = $streetname;
        }
    }

    private function validateHouseNumber()
    {
        $housenumber = trim($_POST["housenumber"] ?? '');
        
        if (empty($housenumber)) {
            $this->errors['housenumber'] = "Enter house number.";
        } else if (!ctype_alpha($housenumber)) {
            $this->errors['housenumber'] = "House number must be digit only";
        }else if (strlen($housenumber) < 10 || strlen($housenumber) > 20) {
            $this->errors['housenumber'] = "House number must be between 1 and 15 characters.";
        }else {
            $this->inputs['housenumber'] = $housenumber;
        }
    }

    private function validateNearestBustoporLandMark()
    {
        $nearestbustoporlandmark = trim($_POST["nearestbustoporlandmark"] ?? '');
        if (empty($nearestbustoporlandmark)) {
            $this->errors['nearestbustoporlandmark'] = "Enter Nearest bustop or Landmark name.";
        } else if (!ctype_alpha($nearestbustoporlandmark)) {
            $this->errors['nearestbustoporlandmark'] = "Nearest bustop or Landmark name must be alphabet only";
        }else if (strlen($nearestbustoporlandmark) < 10 || strlen($nearestbustoporlandmark) > 20) {
            $this->errors['nearestbustoporlandmark'] = "Nearest bustop or Landmark name must be between 10 and 30 characters.";
        }else {
            $this->inputs['nearestbustoporlandmark'] = $nearestbustoporlandmark;
        }
    }

    private function validateUtilityBillType()
    {
        $utilitybilltype = trim($_POST["utilitybilltype"] ?? '');
        
        // if (!isset($this->utilitybilltypes[$utilitybilltype])) {
        //     $this->errors['utilitybilltype'] = "Select Untility Bill Type.";
        // }
        if (empty($utilitybilltype)) {
            $this->inputs['utilitybilltype'] = '';
        } else if (!isset($this->utilitybilltypes[$utilitybilltype])) {
            $this->errors['utilitybilltype'] = "Select a valid Utility Bill Type.";
        } else {
            $this->inputs['utilitybilltype'] = $utilitybilltype;
        }
    }


    
    /* EMPLOYMENT INFO VALIDATION */
    

    private function validateEmploymentStatus()
    {
        $employmentstatus = $_POST["employmentstatus"] ?? '';

        // if (!isset($this->employmentstatuses[$employmentstatus])) {
        //     $this->errors['employmentstatus'] = "Select employment status.";
        // }
        if (empty($employmentstatus)) {
            $this->inputs['employmentstatus'] = '';
        } else if (!isset($this->employmentstatuses[$employmentstatus])) {
            $this->errors['employmentstatus'] = "Select employment status.";
        } else {
            $this->inputs['employmentstatus'] = $employmentstatus;
        }
    }

    private function validateEmploymentSalaryRange()
    {
        $employmentsalaryrange = $_POST["employmentsalaryrange"] ?? '';

        // if (!isset($this->employmentsalaryranges[$employmentsalaryrange])) {
        //     $this->errors['employmentsalaryrange'] = "Select Salary Range.";
        // }
        if (empty($employmentsalaryrange)) {
            $this->inputs['employmentsalaryrange'] = '';
        } else if (!isset($this->employmentsalaryranges[$employmentsalaryrange])) {
            $this->errors['employmentsalaryrange'] = "Select Salary Range.";
        } else {
            $this->inputs['employmentsalaryrange'] = $employmentsalaryrange;
        }
    }

    private function validateEmploymentName()
    {
        $nameofbusinessoremployment = trim($_POST["nameofbusinessoremployment"] ?? '');

        if (empty($nameofbusinessoremployment)) {
            $this->inputs['nameofbusinessoremployment'] = '';
        } else if (!ctype_alnum($nameofbusinessoremployment)) {
            $this->errors['employmentplotorstreetname'] = "Employer's or Business Name must be alphanumeric only.";
        } else if (strlen($nameofbusinessoremployment) < 10 || strlen($nameofbusinessoremployment) > 30) {
            $this->errors['nameofbusinessoremployment'] = "Employer's or Business Name must be between 10 and 30 digits.";
        } else {
            $this->inputs['nameofbusinessoremployment'] = $nameofbusinessoremployment;
        }
    }

    private function validateEmploymentNature()
    {
        $natureofbuinessoremployment = trim($_POST["natureofbuinessoremployment"] ?? '');

        if (empty($natureofbuinessoremployment)) {
            $this->inputs['natureofbuinessoremployment'] = '';
        } else if (!ctype_alnum($natureofbuinessoremployment)) {
            $this->errors['natureofbuinessoremployment'] = "Nature of Employment or Business must be alphanumeric only.";
        } else if (strlen($natureofbuinessoremployment) < 10 || strlen($natureofbuinessoremployment) > 30) {
            $this->errors['natureofbuinessoremployment'] = "Nature of Employment or Business must be between 10 and 30 digits.";
        } else {
            $this->inputs['natureofbuinessoremployment'] = $natureofbuinessoremployment;
        }
    }

    private function validateEmploymentInDate()
    {
        $employmentindate = trim($_POST["employmentindate"] ?? '');

        if (empty($employmentindate)) {
            $this->inputs['employmentindate'] = '';
            // $this->errors['employmentindate'] = "Enter Date Of Employment ";
        } else if (!DateTime::createFromFormat('Y-m-d', $employmentindate)) {
            $this->errors['nextofkindob'] = "Enter a valid date of employment.";
        } else {
            $this->inputs['employmentindate'] = $employmentindate;
        }
    }

    private function validateEmploymentOutDtae()
    {
        $employmentoutdate = trim($_POST["employmentoutdate"] ?? '');

        if (empty($employmentoutdateb)) {
            $this->inputs['employmentoutdate'] = '';
            // $this->errors['employmentoutdate'] = "Enter Next of kin DOB ";
        } else if (!DateTime::createFromFormat('Y-m-d', $employmentoutdate)) {
            $this->errors['employmentoutdate'] = "Enter a valid date in YYYY-MM-DD format.";
        } else {
            $this->inputs['employmentoutdate'] = $employmentoutdate;
        }
    }

    private function validateEmploymentPhone()
    {
        $employmentphonenumber = trim($_POST["employmentphonenumber"] ?? '');

        if (empty($employmentphonenumber)) {
            $this->inputs['employmentphonenumber'] = '';
        } else if (!ctype_digit($employmentphonenumber)) {
            $this->errors['employmentphonenumber'] = "Phone number must contain only digits.";
        } else if (strlen($employmentphonenumber) < 10 || strlen($employmentphonenumber) > 15) {
            $this->errors['employmentphonenumber'] = "Phone number must be between 10 and 15 digits.";
        } else {
            $this->inputs['employmentphonenumber'] = $employmentphonenumber;
        }
    }

    private function validateEmploymentEmail()
    {
        $employmentemail = trim($_POST["employmentemail"] ?? '');

        if (empty($employmentemail)) {
            $this->inputs['employmentemail'] = '';
        } else if (!filter_var($employmentemail, FILTER_VALIDATE_EMAIL)) {
            $this->errors['employmentemail'] = "Please enter a valid email address.";
        } else {
            $this->inputs['employmentemail'] = $employmentemail;
        }
    }

    private function validateEmploymentNationality()
    {
        $employmentnationality = $_POST["employmentnationality"] ?? '';

        if (empty($employmentnationality)) {
            $this->inputs['employmentnationality'] = '';
        }else if (!isset($this->nationalities[$employmentnationality])) {
            $this->errors['employmentnationality'] = "Select employment Nationality.";
        } else {
            $this->inputs['employmentnationality'] = $employmentnationality;
        }
    }

    private function validateEmploymentState()
    {
        $employmentstate = $_POST["employmentstate"] ?? '';

        if (empty($employmentstate)) {
            $this->inputs['employmentstate'] = '';
        }else if (!isset($this->states[$employmentstate])) {
            $this->errors['employmentstate'] = "Select employment State.";
        } else {
            $this->inputs['employmentstate'] = $employmentstate;
        }
    }

    private function validateEmploymentLGA()
    {
        $employmentlga = $_POST["employmentlga"] ?? '';

        if (empty($employmentlga)) {
            $this->inputs['employmentlga'] = '';
        }else if (!isset($this->lgas[$employmentlga])) {
            $this->errors['employmentlga'] = "Select employment LGA.";
        } else {
            $this->inputs['employmentlga'] = $employmentlga;
        }
    }

    private function validateEmploymentCityOrTown()
    {
        $employmentcityortown = trim($_POST["employmentcityortown"] ?? '');

        if (empty($employmentcityortown)) {
            $this->inputs['employmentcityortown'] = '';
        } else if (!ctype_alpha($employmentcityortown)) {
            $this->errors['employmentcityortown'] = "City or Town Address must contain alphabetic characters only.";
        } else if (strlen($employmentcityortown) > 20) {
            $this->errors['employmentcityortown'] = "City or Town Address must not exceed 20 characters.";
        } else {
            $this->inputs['employmentcityortownn'] = $employmentcityortown;
        }
    }

    private function validateEmploymentNearestBusStopOrLandMark()
    {
        $employmentnearestbustoporlandmark = trim($_POST["employmentnearestbustoporlandmark"] ?? '');

        if (empty($employmentnearestbustoporlandmark)) {
            $this->inputs['employmentnearestbustoporlandmark'] = '';
        } else if (!ctype_alpha($employmentnearestbustoporlandmark)) {
            $this->errors['employmentnearestbustoporlandmark'] = "Employer's or Business Nearest Bus Stop or LandMark must contain alphabetic characters only.";
        } else if (strlen($employmentnearestbustoporlandmark) > 20) {
            $this->errors['employmentnearestbustoporlandmark'] = "Employer's or Business Nearest Bus Stop or LandMark must not exceed 20 characters.";
        } else {
            $this->inputs['employmentnearestbustoporlandmark'] = $employmentnearestbustoporlandmark;
        }
    }

    private function validateEmploymentAddress()
    {
        $employmentaddress = trim($_POST["employmentaddress"] ?? '');

        if (empty($employmentaddress)) {
            $this->inputs['employmentaddress'] = '';
        } else if (!ctype_alpha($employmentaddress)) {
            $this->errors['employmentaddress'] = "Employer's or Business Address must contain alphabetic characters only.";
        } else if (strlen($employmentaddress) > 30) {
            $this->errors['employmentaddress'] = "Employer's or Business Address must not exceed 30 characters.";
        } else {
            $this->inputs['employmentaddress'] = $employmentaddress;
        }
    }

    private function validateEmplotmentPlotOrStreetName()
    {
        $employmentplotorstreetname = trim($_POST["employmentplotorstreetname"] ?? '');

        if (empty($employmentplotorstreetname)) {
            $this->inputs['employmentplotorstreetname'] = '';
        } else if (!ctype_digit($employmentplotorstreetname)) {
            $this->errors['employmentplotorstreetname'] = "Employer's or Business Street name must contain digits only.";
        } else if (strlen($employmentplotorstreetname) < 10 || strlen($employmentplotorstreetname) > 20) {
            $this->errors['employmentplotorstreetname'] = "Employer's or Business Street name must be between 10 and 20 digits.";
        } else {
            $this->inputs['employmentplotorstreetname'] = $employmentplotorstreetname;
        }
    }

    private function validateEmploymentHouseOrPlotNumber()
    {
        $employmenthouseorplotnumber = trim($_POST["employmenthouseorplotnumber"] ?? '');

        if (empty($employmenthouseorplotnumber)) {
            $this->inputs['employmenthouseorplotnumber'] = '';
        }else if (!ctype_digit($employmenthouseorplotnumber)) {
            $this->errors['employmenthouseorplotnumber'] = "Employer's or Business House or Plot Number must contain digits only.";
        } else if (strlen($employmenthouseorplotnumber) > 20) {
            $this->errors['employmenthouseorplotnumber'] = "Employer's or Business House or Plot Number  must not exceed 30 characters.";
        } else {
            $this->inputs['employmenthouseorplotnumber'] = $employmenthouseorplotnumber;
        }
    }

    /* NEXT OF KIN VALIDATION */

    /* Nextofkin Passport */

    private function validateNextofkinTitle()
    {
        $nextofkintitle = trim($_POST["nextofkintitle"] ?? '');

        if (empty($nextofkintitle)) {
            $this->inputs['nextofkintitle'] = '';
        } else if (!isset($this->titles[$nextofkintitle])) {
            $this->errors['nextofkintitle'] = "Select Next of kin title.";
        } else {
            $this->inputs['nextofkintitle'] = $nextofkintitle;
        }
    }

    private function validateNextofkinRelationship()
    {
        $nextofkinrelationship = trim($_POST["nextofkinrelationship"] ?? '');

        if (empty($nextofkinrelationship)) {
            $this->inputs['nextofkinrelationship'] = '';
        } else if (!isset($this->relationships[$nextofkinrelationship])) {
            $this->errors['nextofkinrelationship'] = "Select Next of kin relationship.";
        } else {
            $this->inputs['nextofkinrelationship'] = $nextofkinrelationship;
        }
    }

    private function validateNextofkinNatureOfEmploymentOrBusiness()
    {
        $nextofkinnatureofemploymentorbusiness = trim($_POST["nextofkinnatureofemploymentorbusiness"] ?? '');

        if (empty($nextofkinnatureofemploymentorbusiness)) {
            $this->inputs['nextofkinnatureofemploymentorbusiness'] = '';
        } else if (!ctype_alnum($nextofkinnatureofemploymentorbusiness)) {
            $this->errors['nextofkinnatureofemploymentorbusiness'] = "Next of kin Nature of Employment or Business must be alphanumeric only.";
        } else if (strlen($nextofkinnatureofemploymentorbusiness) < 10 || strlen($nextofkinnatureofemploymentorbusiness) > 30) {
            $this->errors['nextofkinnatureofemploymentorbusiness'] = "Next of kin Nature of Employment or Business must be between 10 and 30 digits.";
        } else {
            $this->inputs['nextofkinnatureofemploymentorbusiness'] = $nextofkinnatureofemploymentorbusiness;
        }
    }

    private function validateNextofkinOfficeOrBusinessAddress()
    {
        $nextofkinbusinessorofficeaddress = trim($_POST["nextofkinbusinessorofficeaddress"] ?? '');

        if (empty($nextofkinbusinessorofficeaddress)) {
            $this->inputs['nextofkinbusinessorofficeaddress'] = '';
        } else if (!ctype_alpha($nextofkinbusinessorofficeaddress)) {
            $this->errors['nextofkinbusinessorofficeaddress'] = "Next of kin Office or Business Address must contain alphabetic characters only.";
        } else if (strlen($nextofkinbusinessorofficeaddress) > 50) {
            $this->errors['nextofkinbusinessorofficeaddress'] = "Next of kin Office or Business Address must not exceed 50 characters.";
        } else {
            $this->inputs['nextofkinbusinessorofficeaddress'] = $nextofkinbusinessorofficeaddress;
        }
    }

    private function validateNextofkinGender()
    {
        $nextofkingender = trim($_POST["nnextofkingender"] ?? '');

        if (empty($nextofkingender)) {
            $this->inputs['nextofkingender'] = '';
        } else if (!isset($this->genders[$nextofkingender])) {
            $this->errors['nextofkingender'] = "Select Next of kin gender.";
        } else {
            $this->inputs['nextofkingender'] = $nextofkingender;
        }
    }

    private function validateNextofkinDOB()
    {
        $nextofkindob = trim($_POST["nextofkindob"] ?? '');

        if (empty($nextofkindob)) {
            $this->inputs['nextofkindob'] = '';
            // $this->errors['nextofkindob'] = "Enter Next of kin DOB ";
        } else if (!DateTime::createFromFormat('Y-m-d', $nextofkindob)) {
            $this->errors['nextofkindob'] = "Enter a valid date in YYYY-MM-DD format.";
        } else {
            $this->inputs['nextofkindob'] = $nextofkindob;
        }
    }

    private function validateNextofkinMaritalStatus()
    {
        $nextofkinmaritalstatus = trim($_POST["nextofkinmaritalstatus"] ?? '');

        if (empty($nextofkinmaritalstatus)) {
            $this->inputs['nextofkinmaritalstatus'] = '';
        } else if (!isset($this->maritalstatuses[$nextofkinmaritalstatus])) {
            $this->errors['nextofkinmaritalstatus'] = "Select Next of kin marital status.";
        } else {
            $this->inputs['nextofkinmaritalstatus'] = $nextofkinmaritalstatus;
        }
    }

    private function validateNextofkinPhonenumber()
    {
        $nextofkinphonenumber = trim($_POST["nextofkinphonenumber"] ?? '');

        if (empty($nextofkinphonenumber)) {
            $this->inputs['nextofkinphonenumber'] = '';
        } else if (!ctype_digit($nextofkinphonenumber)) {
            $this->errors['nextofkinphonenumber'] = "Phone number must contain only digits.";
        } else if (strlen($nextofkinphonenumber) < 10 || strlen($nextofkinphonenumber) > 15) {
            $this->errors['nextofkinphonenumber'] = "Phone number must be between 10 and 15 digits.";
        } else {
            $this->inputs['nextofkinphonenumber'] = $nextofkinphonenumber;
        }
    }

    private function validateNextofkinEmail()
    {
        $nextofkinemail = trim($_POST["nextofkinemail"] ?? '');

        if (empty($employmentemail)) {
            $this->inputs['nextofkinemail'] = '';
        } else if (!filter_var($nextofkinemail, FILTER_VALIDATE_EMAIL)) {
            $this->errors['nextofkinemail'] = "Enter Next of kin valid email address.";
        } else {
            $this->inputs['nextofkinemail'] = $nextofkinemail;
        }
    }

    private function validateNextofkinNationality()
    {
        $nextofkinnationality = $_POST["nextofkinnationality"] ?? '';

        if (empty($nextofkinnationality)) {
            $this->inputs['nextofkinnationality'] = '';
        }else if (!isset($this->nationalities[$nextofkinnationality])) {
            $this->errors['nextofkinnationality'] = "Select Next of kin Nationality.";
        } else {
            $this->inputs['nextofkinnationality'] = $nextofkinnationality;
        }
    }

    private function validateNextofkinState()
    {
        $nextofkinstate = $_POST["nextofkinstate"] ?? '';

        if (empty($nextofkinstate)) {
            $this->inputs['nextofkinstate'] = '';
        }else if (!isset($this->states[$nextofkinstate])) {
            $this->errors['nextofkinstate'] = "Select Next of kin State.";
        } else {
            $this->inputs['nextofkinstate'] = $nextofkinstate;
        }
    }

    private function validateNextofkinLGA()
    {
        $nextofkinlga = $_POST["nextofkinlga"] ?? '';

        if (empty($nextofkinlga)) {
            $this->inputs['nextofkinlga'] = '';
        }else if (!isset($this->lgas[$nextofkinlga])) {
            $this->errors['nextofkinlga'] = "Select Next of kin LGA.";
        } else {
            $this->inputs['nextofkinlga'] = $nextofkinlga;
        }
    }

    private function validateNextofkinCityOrTown()
    {
        $nextofkincityortown = trim($_POST["nextofkincityortown"] ?? '');

        if (empty($nextofkincityortown)) {
            $this->inputs['nextofkincityortown'] = '';
        } else if (!ctype_alpha($nextofkincityortown)) {
            $this->errors['nextofkincityortown'] = "Next of kin City or Town Address must contain alphabetic characters only.";
        } else if (strlen($nextofkincityortown) > 20) {
            $this->errors['nextofkincityortown'] = "Next of kin City or Town Address must not exceed 20 characters.";
        } else {
            $this->inputs['nextofkincityortown'] = $nextofkincityortown;
        }
    }

    private function validateNextofkinAddress()
    {
        $nextofkinaddress = trim($_POST["nextofkinaddress"] ?? '');

        if (empty($nextofkinaddress)) {
            $this->inputs['nextofkinaddress'] = '';
        } else if (!ctype_alpha($nextofkinaddress)) {
            $this->errors['nextofkinaddress'] = "Next of kin Address must contain alphabetic characters only.";
        } else if (strlen($nextofkinaddress) > 30) {
            $this->errors['nextofkinaddress'] = "Next of kin Address must not exceed 30 characters.";
        } else {
            $this->inputs['nextofkinaddress'] = $nextofkinaddress;
        }
    }

    private function validateNextofkinHouseNunmber()
    {
        $nextofkinhousenumber = trim($_POST["nextofkinhousenumber"] ?? '');

        if (empty($nextofkinhousenumber)) {
            $this->inputs['nextofkinhousenumber'] = '';
        }else if (!ctype_digit($nextofkinhousenumber)) {
            $this->errors['nextofkinhousenumber'] = "Next of kin House Number must contain digits only.";
        } else if (strlen($nextofkinhousenumber) > 20) {
            $this->errors['nextofkinhousenumber'] = "Next of kin House Number must not exceed 30 characters.";
        } else {
            $this->inputs['nextofkinhousenumber'] = $nextofkinhousenumber;
        }
    }

    private function validateNextofkinStreetName()
    {
        $nextofkinstreetname = trim($_POST["nextofkinstreetname"] ?? '');

        if (empty($nextofkinstreetname)) {
            $this->inputs['nextofkinstreetname'] = '';
        } else if (!ctype_digit($nextofkinstreetname)) {
            $this->errors['nextofkinstreetname'] = "Next of kin Street name must contain digits only.";
        } else if (strlen($nextofkinstreetname) < 10 || strlen($nextofkinstreetname) > 20) {
            $this->errors['nextofkinstreetname'] = "Next of kin Street name must be between 10 and 20 digits.";
        } else {
            $this->inputs['nextofkinstreetname'] = $nextofkinstreetname;
        }
    }

    private function validateNextofkinNearestBusStopOrLandMark()
    {
        $nextofkinnearestbusstoporlandmark = trim($_POST["nextofkinnearestbusstoporlandmark"] ?? '');

        if (empty($nextofkinnearestbusstoporlandmark)) {
            $this->inputs['nextofkinnearestbusstoporlandmark'] = '';
        } else if (!ctype_alpha($nextofkinnearestbusstoporlandmark)) {
            $this->errors['nextofkinnearestbusstoporlandmark'] = "Next of kin Nearest Bus Stop or LandMark must contain alphabetic characters only.";
        } else if (strlen($nextofkinnearestbusstoporlandmark) > 20) {
            $this->errors['nextofkinnearestbusstoporlandmark'] = "Next of kin Nearest Bus Stop or LandMark must not exceed 20 characters.";
        } else {
            $this->inputs['nextofkinnearestbusstoporlandmark'] = $nextofkinnearestbusstoporlandmark;
        }
    }

    /* UPLOAD SEAL MOVED TO UP */

    private function validateSealNumber()
    {
        $sealnumber = $_POST["sealnumber"] ?? '';

        /*if (empty($sealnumber)) {
            $this->errors['sealnumber'] = "Please enter Seal number.";
        }*/

        if (empty($sealnumber)) {
            $this->inputs['sealnumber'] = $sealnumber;
        }elseif (!ctype_digit($sealnumber) || strlen($sealnumber) < 10 || strlen($sealnumber) > 12) {
            $this->errors['sealnumber'] = "Seal number must be between 10 and 12 digits..";
        } else {
            $this->inputs['sealnumber'] = $sealnumber;
        }
    }
    
    // private function generateUniqueAccountNumber()
    // {
    //     // Generate a random 11-digit account number
    //     $accountNumber = str_pad(mt_rand(1, 99999999999), 11, '0', STR_PAD_LEFT);

    //     // Check if the generated account number already exists in the database
    //     $stmt = $this->conn->prepare("SELECT id FROM users WHERE accountnumber = :accountNumber");
    //     $stmt->bindParam(":accountNumber", $accountNumber, PDO::PARAM_STR);
    //     $stmt->execute();

    //     // If account number exists, recursively generate a new one until a unique one is found
    //     if ($stmt->rowCount() > 0) {
    //         return $this->generateUniqueAccountNumber(); // Recursive call
    //     }

    //     return $accountNumber; // Return unique account number
    // }
    
    private function registerUser()
    {

        try {
            $this->conn->beginTransaction();

            $userId = $this->insertIntoUsers();
            $this->insertIntoClientBanking($userId);
            $this->insertIntoMeanOfIdentification($userId);
            $this->insertIntoClientContactInfo($userId);
            $this->insertIntoClientEmploymentInfo($userId);
            $this->insertIntoClientNextOfKinInfo($userId);

            $this->conn->commit();
            return $userId;
        } catch (Exception $e) {
            $this->conn->rollBack();
            $this->errors['database'] = "Registration failed: " . $e->getMessage();
            return false;
        }
    }

    private function insertIntoUsers()
    {
        $stmt = $this->conn->prepare("INSERT INTO users (title, passport, surname, firstname, othername, username, email, password, status, dob, gender, maritalstatus, signature, type, role, created_by_type_id, created_by_role_id, created_by_id, last_modified_by_type_id, last_modified_by_role_id, last_modified_by_id) VALUES (:title, :passport, :surname, :firstname, :surname, :othername, :username, :email, :password, :status, :dob, :gender, :maritalstatus, :signature, 1, 7, :created_by_type_id, :created_by_role_id, :created_by_id, :last_modified_by_type_id, :last_modified_by_role_id, :last_modified_by_id)");
        $stmt->bindParam(':title', $this->inputs['title']);
        $stmt->bindParam(':passport', $this->inputs['passport']);
        $stmt->bindParam(':surname', $this->inputs['surname']);
        $stmt->bindParam(':firstname', $this->inputs['firstname']);
        $stmt->bindParam(':othername', $this->inputs['othername']);
        $stmt->bindParam(':email', $this->inputs['email']);
        $stmt->bindParam(':password', $this->inputs['password']);
        $stmt->bindParam(':status', $this->inputs['status']);
        $stmt->bindParam(':dob', $this->inputs['dob']);
        $stmt->bindParam(':gender', $this->inputs['gender']);
        $stmt->bindParam(':maritalstatus', $this->inputs['maritalstatus']);
        $stmt->bindParam(':signature', $this->inputs['signature']);
        $stmt->bindParam(':created_by_type_id', $this->currentUserTypeId);
        $stmt->bindParam(':created_by_role_id', $this->currentUserRoleId);
        $stmt->bindParam(':created_by_id', $this->currentUserId);
        $stmt->bindParam(':last_modified_by_type_id', $this->currentUserTypeId);
        $stmt->bindParam(':last_modified_by_role_id', $this->currentUserRoleId);
        $stmt->bindParam(':last_modified_by_id', $this->currentUserId);

        if ($stmt->execute()) {
            return $this->conn->lastInsertId();
        } else {
            throw new Exception("Failed to Insert Client Personnal Information");
        }
    }

    private function insertIntoClientBanking($userId)
    {
         $stmt = $this->conn->prepare("INSERT INTO banking_info (user_id, branch_id, accountcategory_id, accounttype_id, accountnumber, personalaccountbank_id, personalaccountnumber, personalaccounttype_id, created_by_type_id, created_by_role_id, created_by_id, last_modified_by_type_id, last_modified_by_role_id, last_modified_by_id) VALUES (:user_id, :branch, :accountcategory, :accounttype, :accountnumber, :personalacccountbank, :personalacccountype, :personalaccountnumber, :created_by_type_id, :created_by_role_id, :created_by_id, :last_modified_by_type_id, :last_modified_by_role_id, :last_modified_by_id)");
         $stmt->bindParam(':user_id', $userId); 
         $stmt->bindParam(':branch', $this->currentUserBranchId);
         $stmt->bindParam(':accountcategory', $this->inputs['accountcategory']);
         $stmt->bindParam(':accounttype', $this->inputs['accounttype']);
         $stmt->bindParam(':accountnumber', $this->inputs['accountnumber']);
         $stmt->bindParam(':personalacccountbank', $this->inputs['personalacccountbank']);
         $stmt->bindParam(':personalacccountype', $this->inputs['personalacccountype']);
         $stmt->bindParam(':personalaccountnumber', $this->inputs['personalaccountnumber']);
         $stmt->bindParam(':created_by_type_id', $this->currentUserTypeId);
         $stmt->bindParam(':created_by_role_id', $this->currentUserRoleId);
         $stmt->bindParam(':created_by_id', $this->currentUserId);
         $stmt->bindParam(':last_modified_by_type_id', $this->currentUserTypeId);
         $stmt->bindParam(':last_modified_by_role_id', $this->currentUserRoleId);
         $stmt->bindParam(':last_modified_by_id', $this->currentUserId);

        if (!$stmt->execute()) {
            throw new Exception("Failed to insert Client Banking Information.");
        }
    }

    private function insertIntoMeanOfIdentification($userId)
    {
        $stmt = $this->conn->prepare("INSERT INTO means_of_identification_info (user_id, id_type, id_number, id_card, id_date_issued, id_date_expired, bvn, tin, created_by_type_id, created_by_role_id, created_by_id, last_modified_by_type_id, last_modified_by_role_id, last_modified_by_id) VALUES (:user_id, :idcardtype, :idnumber, :idcard, :idissueddate, :idexpirydate, :bvn, :tin, :created_by_type_id, :created_by_role_id, :created_by_id, :last_modified_by_type_id, :last_modified_by_role_id, :last_modified_by_id)");
         $stmt->bindParam(':user_id', $userId); 
         $stmt->bindParam(':idcardtype', $this->inputs['idcardtype']);
         $stmt->bindParam(':idnumber', $this->inputs['idnumber']);
         $stmt->bindParam(':idcard', $this->inputs['idcard']);
         $stmt->bindParam(':idissueddate', $this->inputs['idissueddate']);
         $stmt->bindParam(':idexpirydate', $this->inputs['idexpirydate']);
         $stmt->bindParam(':bvn', $this->inputs['bvn']);
         $stmt->bindParam(':tin', $this->inputs['tin']);
         $stmt->bindParam(':created_by_type_id', $this->currentUserTypeId);
         $stmt->bindParam(':created_by_role_id', $this->currentUserRoleId);
         $stmt->bindParam(':created_by_id', $this->currentUserId);
         $stmt->bindParam(':last_modified_by_type_id', $this->currentUserTypeId);
         $stmt->bindParam(':last_modified_by_role_id', $this->currentUserRoleId);
         $stmt->bindParam(':last_modified_by_id', $this->currentUserId);

        if (!$stmt->execute()) {
            throw new Exception("Failed to insert Means of Identification Information.");
        }
    }

    private function insertIntoClientContactInfo($userId)
    {
         $stmt = $this->conn->prepare("INSERT INTO contacts_info (user_id, email2, phonenumber, phonenumber2, business_or_office_address, nationality, ostate, olga, oaddress, rstate, rlga, raddress, streetname, housenumber, nearestbusstoporlandmark, utilitybill, Utilitybilltype, created_by_type_id, created_by_role_id, created_by_id, last_modified_by_type_id, last_modified_by_role_id, last_modified_by_id) 
         VALUES (:user_id, :email2, :phonenumber, :phonenumber2, :businessorofficeaddress, :cityortown, :nationality, :stateoforigin, :lgaoforigin, :addressoforigin, :stateofresidence, :lgaofresidence, :addressofresidence, :streetname, :housenumber, :nearestbustoporlandmark, :utilitybill, :utilitybilltype, :created_by_type_id, :created_by_role_id, :created_by_id, :last_modified_by_type_id, :last_modified_by_role_id, :last_modified_by_id)");
         $stmt->bindParam(':user_id', $userId);
         $stmt->bindParam(':email2', $this->inputs['email2']);
         $stmt->bindParam(':phonenumber', $this->inputs['phonenumber']);
         $stmt->bindParam(':phonenumber2', $this->inputs['phonenumber2']);
         $stmt->bindParam(':businessorofficeaddress', $this->inputs['businessorofficeaddress']);
         $stmt->bindParam(':cityortown', $this->inputs['cityortown']);
         $stmt->bindParam(':nationality', $this->inputs['nationality']);
         $stmt->bindParam(':stateoforigin', $this->inputs['stateoforigin']);
         $stmt->bindParam(':lgaoforigin', $this->inputs['lgaoforigin']);
         $stmt->bindParam(':addressoforigin', $this->inputs['addressoforigin']);
         $stmt->bindParam(':stateofresidence', $this->inputs['stateofresidence']);
         $stmt->bindParam(':lgaofresidence', $this->inputs['lgaofresidence']);
         $stmt->bindParam(':addressofresidence', $this->inputs['addressofresidence']);
         $stmt->bindParam(':streetname', $this->inputs['streetname']);
         $stmt->bindParam(':housenumber', $this->inputs['housenumber']);
         $stmt->bindParam(':nearestbustoporlandmark', $this->inputs['nearestbustoporlandmark']);
         $stmt->bindParam(':utilitybill', $this->inputs['utilitybill']);
         $stmt->bindParam(':utilitybilltype', $this->inputs['utilitybilltype']);
         $stmt->bindParam(':created_by_type_id', $this->currentUserTypeId);
         $stmt->bindParam(':created_by_role_id', $this->currentUserRoleId);
         $stmt->bindParam(':created_by_id', $this->currentUserId);
         $stmt->bindParam(':last_modified_by_type_id', $this->currentUserTypeId);
         $stmt->bindParam(':last_modified_by_role_id', $this->currentUserRoleId);
         $stmt->bindParam(':last_modified_by_id', $this->currentUserId);

        if (!$stmt->execute()) {
            throw new Exception("Failed to insert into Client Contact Info.");
        }
    }

    private function insertIntoClientEmploymentInfo($userId)
    {
         $stmt = $this->conn->prepare("INSERT INTO employment_info (user_id, employmentstatus, nameofemployment, natureofemployment, salary, in_date, out_date, phonenumber, email, nationality, state, lga, cityortown, nearestbusstoporlandmark, address, plotorstreetname, plotorstreetnumber, created_by_type_id, created_by_role_id, created_by_id, last_modified_by_type_id, last_modified_by_role_id, last_modified_by_id) VALUES (:user_id, :employmentstatus, :employmentsalaryrange, :nameofbusinessoremployment, :natureofbuinessoremployment, :employmentindate, :employmentoutdate, :employmentphonenumber, :employmentemail, :employmentnationality, :employmentstate, :employmentlga, :employmentcityortown, :employmentnearestbustoporlandmark', :employmentaddress, :employmentplotorstreetname, :employmenthouseorplotnumber, :created_by_type_id, :created_by_role_id, :created_by_id, :last_modified_by_type_id, :last_modified_by_role_id, :last_modified_by_id)");
         $stmt->bindParam(':user_id', $userId);
         $stmt->bindParam(':employmentstatus', $this->inputs['employmentstatus']);
         $stmt->bindParam(':employmentsalaryrange', $this->inputs['employmentsalaryrange']);
         $stmt->bindParam(':nameofbusinessoremployment', $this->inputs['nameofbusinessoremployment']);
         $stmt->bindParam(':natureofbuinessoremployment', $this->inputs['natureofbuinessoremployment']);
         $stmt->bindParam(':employmentindate', $this->inputs['employmentindate']);
         $stmt->bindParam(':employmentoutdate', $this->inputs['employmentoutdate']);
         $stmt->bindParam(':employmentphonenumber', $this->inputs['employmentphonenumber']);
         $stmt->bindParam(':employmentemail', $this->inputs['employmentemail']);
         $stmt->bindParam(':employmentnationality', $this->inputs['employmentnationality']);
         $stmt->bindParam(':employmentstate', $this->inputs['employmentstate']);
         $stmt->bindParam(':employmentlga', $this->inputs['employmentlga']);
         $stmt->bindParam(':employmentcityortown', $this->inputs['employmentcityortown']);
         $stmt->bindParam(':employmentnearestbustoporlandmark', $this->inputs['employmentnearestbustoporlandmark']);
         $stmt->bindParam(':employmentaddress', $this->inputs['employmentaddress']);
         $stmt->bindParam(':employmentplotorstreetname', $this->inputs['employmentplotorstreetname']);
         $stmt->bindParam(':employmenthouseorplotnumber', $this->inputs['employmenthouseorplotnumber']);
         $stmt->bindParam(':created_by_type_id', $this->currentUserTypeId);
         $stmt->bindParam(':created_by_role_id', $this->currentUserRoleId);
         $stmt->bindParam(':created_by_id', $this->currentUserId);
         $stmt->bindParam(':last_modified_by_type_id', $this->currentUserTypeId);
         $stmt->bindParam(':last_modified_by_role_id', $this->currentUserRoleId);
         $stmt->bindParam(':last_modified_by_id', $this->currentUserId);
        if (!$stmt->execute()) {
            throw new Exception("Failed to insert into Client Employment Info.");
        }
    }

    private function insertIntoClientNextofkinInfo($userId)
    {
         $stmt = $this->conn->prepare("INSERT INTO nextofkin_info (user_id, thumbnail, title, surname, firstname, othername, natureofemployment, addressofemployment, gender, dob, relationship, phonenumber, email, nationality, state, lga, cityandtown,
         streetname, housenumber, nearest_bus_stop_or_landMark, created_by_type_id, created_by_role_id, created_by_id, last_modified_by_type_id, last_modified_by_role_id, last_modified_by_id) 
         VALUES (:user_id, :nextofkinpassport, :title, :nextofkinrelationship, :nextofkinphonenumber, :nextofkinemail, :nextofkinnationality, :nextofkinstate, :nextofkinlga, :nextofkincityortown, :nextofkinstreetname, :nextofkinhousenumber, :nextofkinnearestbusstoporlandmark, :created_by_type_id, :created_by_role_id, :created_by_id, :last_modified_by_type_id, :last_modified_by_role_id, :last_modified_by_id)");
         $stmt->bindParam(':user_id', $userId);
         $stmt->bindParam(':nextofkinpassport', $this->inputs['nextofkinpassport']);
         $stmt->bindParam(':title', $this->inputs['title']);
         $stmt->bindParam(':nextofkinrelationship', $this->inputs['nextofkinrelationship']);
         $stmt->bindParam(':nextofkinnatureofemploymentorbusiness', $this->inputs['nextofkinnatureofemploymentorbusiness']);
         $stmt->bindParam(':nextofkinbusinessorofficeaddress', $this->inputs['nextofkinbusinessorofficeaddress']);
         $stmt->bindParam(':nextofkingender', $this->inputs['nextofkingender']);
         $stmt->bindParam(':nextofkindob', $this->inputs['nextofkindob']);
         $stmt->bindParam(':nextofkinmaritalstatus', $this->inputs['nextofkinmaritalstatus']);
         $stmt->bindParam(':nextofkinphonenumber', $this->inputs['nextofkinphonenumber']);
         $stmt->bindParam(':nextofkinemail', $this->inputs['nextofkinemail']);
         $stmt->bindParam(':nextofkinnationality', $this->inputs['nextofkinnationality']);
         $stmt->bindParam(':nextofkinstate', $this->inputs['nextofkinstate']);
         $stmt->bindParam(':nextofkinlga', $this->inputs['nextofkinlga']);
         $stmt->bindParam(':nextofkincityortown', $this->inputs['nextofkincityortown']);
         $stmt->bindParam(':nextofkinaddress', $this->inputs['nextofkinaddress']);
         $stmt->bindParam(':nextofkinhousenumber', $this->inputs['nextofkinhousenumber']);
         $stmt->bindParam(':nextofkinstreetname', $this->inputs['nextofkinstreetname']);
         $stmt->bindParam(':nextofkinnearestbusstoporlandmark', $this->inputs['nextofkinnearestbusstoporlandmark']);
        if (!$stmt->execute()) {
            throw new Exception("Failed to insert into Client Next of kin Info.");
        }
    }

    public function getError($field)
    {
        return $this->errors[$field] ?? ''; // Get error message for a specific field
    }
    
    // private function redirectBasedOnRole()
    // {
    //     // Redirect user based on role
    //     switch ($this->inputs['role']) {
    //         case 1: // Admin role
    //             header("Location: admin_dashboard.php");
    //             break;
    //         case 2: // Staff role
    //             header("Location: staff_dashboard.php");
    //             break;
    //         default: // Default redirect
    //             header("Location: user_dashboard.php");
    //             break;
    //     }
    //     exit();
    // }
}

// Initialize ClientRegistration class with database connection
$clientRegistration = new ClientRegistration($conn);

// Validate and register user
$clientRegistration->validateAndRegister();


// $errors = $clientRegistration->getErrors(); // Get validation errors

function displayError($error)
{
    if (!empty($error)) {
        // echo '<div class="alert alert-danger">' . $error . '</div>';// Display error message - default
        echo '<div class="invalid-feedback" style="display:block;"> ' . $error . ' </div>';// Display error message
    }
}


// Define the roles allowed to access this page
$allowedRoles = ['Admin', 'Marketer']; // Adjust this array based on the roles you want to allow
// Check if the user's role is allowed to access this page
if (!in_array($userRole, $allowedRoles)) {
    // header("Location: /Error/403.php"); // Redirect unauthorized users to the dashboard or another page
    include "../../Error/403.php";
    exit;
}

require_once "../../B-END/CONT/createClient.php";

?>
<!doctype html>
<html lang="en" data-layout="vertical" data-topbar="light" data-sidebar="dark" data-sidebar-size="lg" data-sidebar-image="none" data-preloader="disable">

<head>

    <?php
    include_once '../../B-END/INC/hheader.php';
    ?>
    <title>Create Client | ETMSAVING </title>
    <meta content="" name="description" />
    <?php
    include_once '../../B-END/INC/hfooter.php';
    ?>

</head>

<body>

    <!-- Begin page -->
    <div id="layout-wrapper">

        <?php
        include_once '../../B-END/INC/bheader.php';
        ?>


        <!-- start Left Sidebar -->
        <!-- ========== start App Left Menu ========== -->
        <?php
        include_once '../../B-END/INC/leftmenu.php';
        ?>
        <!-- Vertical Overlay-->
        <div class="vertical-overlay"></div>

        <!-- ============================================================== -->
        <!-- Start right Content here -->
        <!-- ============================================================== -->
        <div class="main-content">

            <div class="page-content">
                <div class="container-fluid">

                    <!-- start page title -->
                    <div class="row">
                        <div class="col-12">
                            <div class="page-title-box d-sm-flex align-items-center justify-content-between">
                                <h4 class="mb-sm-0">CLIENT </h4>

                                <div class="page-title-right">
                                    <ol class="breadcrumb m-0">
                                        <li class="breadcrumb-item"><a href="javascript: void(0);">Dashboard</a></li>
                                        <li class="breadcrumb-item active">Client</li>
                                    </ol>
                                </div>

                            </div>
                        </div>
                    </div>
                    <!-- end page title -->

                    <div class="row">
                        <div class="col-xxl-6">
                            <?php if (!empty($errors)) : ?>
                                <div class="alert alert-danger">
                                    <?php foreach ($errors as $error) : ?>
                                        <p><?php echo htmlspecialchars($error); ?></p>
                                    <?php endforeach; ?>
                                </div>
                            <?php endif; ?>
                            <div class="card">
                                <div class="card-header align-items-center d-flex">
                                    <h4 class="card-title mb-0 flex-grow-1"><i>CREATE CLIENT</i></h4>
                                    <div class="flex-shrink-0">
                                        <div class="form-check form-switch form-switch-right form-switch-md">
                                            <a href="/ESS/ACCT/"><button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#createboardModal">
                                                    < Return </i>
                                                </button></a>
                                        </div>
                                    </div>
                                </div><!-- end card header -->

                                <div class="card-body">
                                    <p class="text-muted">Before Opening or Creating a Client Account Please ensure the following when opening or creating a client account: Collect all necessary client information, including a valid ID. Accurately enter the client's details into the system. Upload clear copies of required documents. Verify all information with the client before submission Submit the request for approval. Maintain client information confidentiality. For any issues, contact IT support.</p>

                                    <form method="post" action="" enctype="multipart/form-data">
                                        <div class="row">
                                            <!-- Branch info -->
                                            <div class="col-lg-12-hr">
                                                <hr class="left-hr">
                                                <span class="text-between-hr">Client Account Information:</span>
                                                <hr class="right-hr">
                                            </div>

                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="BVNInput" class="form-label">BVN:</label>
                                                    <input name="bvn" type="text" class="form-control" placeholder="Enter BVN" id="" value="<?php echo htmlspecialchars($registration->inputs['bvn'] ?? ''); ?>">
                                                    <?php displayError($clientRegistration->getError('bvn')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="taxinInput" class="form-label">Tax Identification Number:</label>
                                                    <input name="tin" type="text" class="form-control" placeholder="Enter Tax ID Number" id="taxinInput" value="<?php echo htmlspecialchars($registration->inputs['tin'] ?? ''); ?>">
                                                    <?php displayError($clientRegistration->getError('tin')); ?>
                                                </div>
                                            </div>
                                            
                                            <div class="col-md-12">
                                                <div class="mb-3">
                                                    <label for="ForminputBranch" class="form-label"> Branch: <span id="gt">*</span></label>
                                                    <?php if ($userRole === 'Admin'): ?>
                                                    <select name="branch" id="branch" class="form-control">
                                                        <option value=""></option>
                                                        <?php foreach ($clientRegistration->branches as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['branch']) && $clientRegistration->inputs['branch'] == $id) ? 'selected' : ''; ?>>
                                                            <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php elseif ($userRole === 'Marketer'): ?>
                                                     <select name="branch" id="ForminputBranch" class="form-select" disabled>
                                                        <option> </option>
                                                        <option value="<?php echo htmlspecialchars($userBranchId); ?>" selected><?php echo htmlspecialchars($userBranch); ?></option>
                                                    </select>
                                                    <?php endif; ?>
                                                    <?php displayError($clientRegistration->getError('branch')); ?>
                                                </div>
                                            </div>
                                            <!-- start Account  info -->
                                            <div class="col-md-4">
                                                <div class="mb-4">
                                                    <label for="ForminputAccountCategory" class="form-label">Account Category: <span id="gt">*</span></label>
                                                    <select name="accountcategory" id="ForminputAccountCategory" class="form-select">
                                                        <option> </option>
                                                        <?php foreach ($clientRegistration->accountcategories as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['accountcategory']) && $clientRegistration->inputs['accountcategory'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('accountcategory')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="ForminputAccountType" class="form-label">Account Type: <span id="gt">*</span></label>
                                                    <select name="accounttype" id="ForminputAccountType" class="form-select">
                                                        <option> </option>
                                                        <?php foreach ($clientRegistration->accounttypes as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['accounttype']) && $clientRegistration->inputs['accounttype'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('accounttype')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="ForminputAccountNumber" class="form-label">Account Number:</label>
                                                    <input name="accountnumber" type="text" class="form-control" placeholder="Loading..." id="AccountNumberInput" disabled>
                                                    <?php displayError($clientRegistration->getError('accountnumber')); ?>
                                                </div>
                                            </div>

                                            <!-- <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="ForminputAlertPreference" class="form-label"> Alert Preference: </label> <br>
                                                    <input type="checkbox" name="alert_sms" value="1"> SMS <br>
                                                    <input type="checkbox" name="alert_email" value="1"> Email <br>
                                                    <input type="checkbox" name="alert_printed" value="1"> Printed Copy </br>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="ForminputStatementPreference" class="form-label"> Statement Preference: </label><br>
                                                    <input type="checkbox" name="statement_email" value="1"> Email<br>
                                                    <input type="checkbox" name="statement_printed" value="1"> Printed Copy<br>
                                                </div>
                                            </div> -->

                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="ForminputPersonalAccountBank" class="form-label">Personal Account Bank: <i> (To be used for payment) </i> </label>
                                                    <select name="personalacccountbank" id="ForminputPersonalAccountBank" class="form-select">
                                                        <option> </option>
                                                        <?php foreach ($clientRegistration->allbanks as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['personalacccountbank']) && $clientRegistration->inputs['personalacccountbank'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('personalacccountbank')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="ForminputPersonalAccountType" class="form-label">Personal Account Type: <i> (To be used for payment) </i> </label>
                                                    <select name="personalacccountype" id="ForminputPersonalAccountType" class="form-select">
                                                        <option> </option>
                                                        <?php foreach ($clientRegistration->accounttypes as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['accounttype']) && $clientRegistration->inputs['accounttype'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('personalacccountype')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-12">
                                                <div class="mb-3">
                                                    <label for="ForminputPersonalAccountNumber" class="form-label">Personal Account Number: <i> (Prefered Bank Account payment) </i></label>
                                                    <input name="personalaccountnumber" type="text" class="form-control" placeholder="Enter Account Number" id="PersonalAccountNumberInput" value="<?php echo htmlspecialchars($clientRegistration->inputs['personalaccountnumber'] ?? ''); ?>">
                                                    <?php displayError($clientRegistration->getError('personalaccountnumber')); ?>
                                                </div>
                                            </div>
                                            <!-- / end Account  info -->
                                            <!-- start ID info -->
                                           









                                            <!-- / end ID info -->
                                            <!-- start Main ID info -->

                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="ForminputIDCard" class="form-label">ID Card: </label>
                                                    <input name="idcard" class="form-control" type="file" id="idcardimgInput">
                                                    <?php displayError($clientRegistration->getError('idcard')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="ForminputIDType" class="form-label"> ID Type</label>
                                                    <select name="idcardtype" id="ForminputIDType" class="form-select">
                                                        <option> </option>
                                                        <?php foreach ($clientRegistration->idcardtypes as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['idcardtype']) && $clientRegistration->inputs['idcardtype'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('idcardtype')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-12">
                                                <div class="mb-3">
                                                    <label for="ForminputIDCardrInput" class="form-label">ID Number: </label>
                                                    <input name="idnumber" type="text" class="form-control" placeholder="Enter ID number" id="idnumberInput">
                                                    <?php displayError($clientRegistration->getError('idnumber')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="ForminputIDOtherType" class="form-label">ID Issued Date: <i> (if available) </i></label>
                                                    <input name="idissueddate" type="date" class="form-control" placeholder="" id="idothertypeInput">
                                                    <?php displayError($clientRegistration->getError('idissueddate')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="phonenumberInput" class="form-label">ID Expiry Date: <i>(if available) </i></label>
                                                    <input name="idexpirydate" type="date" class="form-control" placeholder="" id="idnumberInput">
                                                    <?php displayError($clientRegistration->getError('idexpirydate')); ?>
                                                </div>
                                            </div>
                                            <!-- end ID info -->
                                            <!--/ end Title info -->
                                            <div class="col-lg-12-hr">
                                                <br>
                                                <hr class="left-hr">
                                                <span class="text-between-hr">Client Personal Information:</span>
                                                <hr class="right-hr">
                                                <br>
                                            </div>
                                            <!-- start Client  info -->
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="ForminputPassport" class="form-label"> Passport: </label>
                                                    <input name="passport" class="form-control" type="file" id="">
                                                    <?php displayError($clientRegistration->getError('passport')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="ForminputUserTitle" class="form-label">Title: </label>
                                                    <select name="title" id="ForminputUserTitle" class="form-select">
                                                        <option> </option>
                                                        <?php foreach ($clientRegistration->titles as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['titles']) && $clientRegistration->inputs['title'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('title')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="surNameinput" class="form-label">Sur Name: <span id="gt">*</span></label>
                                                    <input name="surname" type="text" class="form-control" placeholder="Enter your Sur Name" id="surNameinput" value="<?php echo htmlspecialchars($clientRegistration->inputs['surname'] ?? ''); ?>">
                                                    <?php displayError($clientRegistration->getError('surname')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="firstNameinput" class="form-label">First Name: <span id="gt">*</span></label>
                                                    <input name="firstname" type="text" class="form-control" placeholder="Enter your First Name" id="firstNameinput" value="<?php echo htmlspecialchars($clientRegistration->inputs['firstname'] ?? ''); ?>">
                                                    <?php displayError($clientRegistration->getError('firstname')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="otherNameinput" class="form-label">Other Name:</label>
                                                    <input name="othername" type="text" class="form-control" placeholder="Enter your Other name" id="otherNameinput" value="<?php echo htmlspecialchars($clientRegistration->inputs['othername'] ?? ''); ?>">
                                                    <?php displayError($clientRegistration->getError('othername')); ?>
                                                </div>
                                            </div>
                                            <!-- / end Client  info -->
                                            <!-- start Another Client info -->
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="genderInput" class="form-label">Gender: <span id="gt">*</span></label>
                                                    <select name="gender" id="Forminputgender" class="form-select">
                                                        <option> </option>
                                                        <?php foreach ($clientRegistration->genders as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['gender']) && $clientRegistration->inputs['gender'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('gender')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="ForminputDOB" class="form-label"> D.O.B: <span id="gt">*</span></label>
                                                    <input name="dob" type="date" class="form-control" placeholder="" id="dobInput">
                                                    <?php displayError($clientRegistration->getError('dob')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="ForminputOLGA" class="form-label"> Marital Status: <span id="gt">*</span></label>
                                                    <select name="maritalstatus" id="ForminputOLGA" class="form-select">
                                                        <option> </option>
                                                        <?php foreach ($clientRegistration->maritalstatuses as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['maritalstatus']) && $clientRegistration->inputs['maritalstatus'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('maritalstatus')); ?>
                                                </div>
                                            </div>
                                            <!--/ end Another Client info -->
                                            <!-- Client Phone number info -->
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="phonenumberInput" class="form-label">Phone Number: <span id="gt">*</span></label>
                                                    <input name="phonenumber" type="tel" class="form-control" placeholder="09000000000" id="phonenumberInput" value="<?php echo htmlspecialchars($clientRegistration->inputs['phonenumber'] ?? ''); ?>">
                                                    <?php displayError($clientRegistration->getError('phonenumber')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="phonenumber2Input" class="form-label">Phone Number 2: </label>
                                                    <input name="phonenumber2" type="tel" class="form-control" placeholder="09099999999" id="phonenumber2Input">
                                                    <?php displayError($clientRegistration->getError('phonenumber2')); ?>
                                                </div>
                                            </div>
                                            <!--/ end Client Phone number info -->
                                            <!-- Clients Email info -->
                                            <div class="col-lg-6">
                                                <div class="mb-3">
                                                    <label for="emailidInput" class="form-label">Email Address: <span id="gt">*</span></label>
                                                    <input name="email" type="email" class="form-control" placeholder="example@gamil.com" id="emailidInput" value="<?php echo htmlspecialchars($clientRegistration->inputs['email'] ?? ''); ?>">
                                                    <?php displayError($clientRegistration->getError('email')); ?>
                                                </div>
                                            </div>
                                            <div class="col-lg-6">
                                                <div class="mb-3">
                                                    <label for="emailidInput" class="form-label">Email Address 2: </label>
                                                    <input name="email2" type="email" class="form-control" placeholder="example@gamil.com" id="emailidInput">
                                                    <?php displayError($clientRegistration->getError('email2')); ?>
                                                </div>
                                            </div>
                                            <!-- / end Clients Email info -->
                                            <!-- Clients Username info -->
                                            <div class="col-lg-12">
                                                <div class="mb-3">
                                                    <label for="usernameidInput" class="form-label">Username: <span id="gt">*</span></label>
                                                    <input name="username" class="form-control" placeholder="EnterUsername" id="usernameidInput" value="<?php echo htmlspecialchars($clientRegistration->inputs['username'] ?? ''); ?>">
                                                    <?php displayError($clientRegistration->getError('username')); ?>
                                                </div>
                                            </div>
                                            <!-- / end Client Username -->
                                            <!-- start Client Password -->
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="PasswordInput" class="form-label">Password: <span id="gt">*</span></label>
                                                    <input name="password" type="password" class="form-control" placeholder="Enter password" id="passwordInput">
                                                    <?php displayError($clientRegistration->getError('password')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="ConfirmPasswordInput" class="form-label">Re-type Password:</label>
                                                    <input name="confirmpassword" type="password" class="form-control" placeholder="Re-type password" id="confirmpasswordInput">
                                                    <?php displayError($clientRegistration->getError('confirmpassword')); ?>
                                                </div>
                                            </div>
                                            <!-- / end Client Password  -->
                                            <!-- start Client Business or Office Address  -->
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="address1ControlTextarea" class="form-label">Business / Office Address: </label>
                                                    <input name="businessorofficeaddress" type="text" class="form-control" placeholder="Enter Business or Office address" id="address1ControlTextarea" value="<?php echo htmlspecialchars($clientRegistration->inputs['businessorofficeaddress'] ?? ''); ?>">
                                                    <?php displayError($clientRegistration->getError('businessorofficeaddress')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="address1ControlTextarea" class="form-label">City / Town: </label>
                                                    <input name="cityortown" type="text" class="form-control" placeholder="Enter City or Town" id="address1ControlTextarea"  value="<?php echo htmlspecialchars($clientRegistration->inputs['cityortown'] ?? ''); ?>">
                                                    <?php displayError($clientRegistration->getError('cityortown')); ?>
                                                </div>
                                            </div>
                                            <!--/ end Client Business or Office Address -->
                                            <!-- start Client Nationality -->
                                            <div class="col-md-12">
                                                <div class="mb-3">
                                                    <label for="ForminputNationality" class="form-label">Nationality: </label>
                                                    <select name="nationality" id="ForminputNationality" class="form-select">
                                                        <option> </option>
                                                        <?php foreach ($clientRegistration->nationalities as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['nationality']) && $clientRegistration->inputs['nationality'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('nationality')); ?>
                                                </div>
                                            </div>
                                            <!-- end Client Nationality -->
                                            <!-- start Origin info -->
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="OstatenameInput" class="form-label"> State of Origin: </label>
                                                    <select name="stateoforigin" id="ForminputOState" class="form-select">
                                                        <option> </option>
                                                        <?php foreach ($clientRegistration->states as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['state']) && $clientRegistration->inputs['state'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('stateoforigin')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="ForminputOLGA" class="form-label"> L.G.A of Origin: </label>
                                                    <select name="lgaoforigin" id="ForminputOLGA" class="form-select">
                                                        <option> </option>
                                                        <?php foreach ($clientRegistration->lgas as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['lga']) && $clientRegistration->inputs['lga'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('lgaoforigin')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="oaddress1ControlTextarea" class="form-label">Address of Origin: </label>
                                                    <input name="addressoforigin" type="text" class="form-control" placeholder="Enter address of origin" id="address1ControlTextarea" value="<?php echo htmlspecialchars($registration->inputs['addressoforigin'] ?? ''); ?>">
                                                    <?php displayError($clientRegistration->getError('addressoforigin')); ?>
                                                </div>
                                            </div>
                                            <!-- end Origin info -->
                                            <!-- start Residential info -->
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="RstatenameInput" class="form-label"> State of Residence: </label>
                                                    <select name="stateofresidence" id="ForminputRState" class="form-select">
                                                    <option> </option>
                                                        <?php foreach ($clientRegistration->states as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['state']) && $clientRegistration->inputs['state'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('stateofresidence')); ?>
                                                </div>
                                            </div>
                                            <div class="col-lg-4">
                                                <div class="mb-3">
                                                    <label for="ForminputRLGA" class="form-label"> L.G.A of Residence: </label>
                                                    <select name="lgaofresidence" id="ForminputRLGA" class="form-select">
                                                    <option> </option>
                                                        <?php foreach ($clientRegistration->lgas as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['lga']) && $clientRegistration->inputs['lga'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('lgaoforigin')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="raddress1ControlTextarea" class="form-label">Residential Address: </label>
                                                    <input name="addressofresidence" type="text" class="form-control" placeholder="Enter residential address" id="address1ControlTextarea" value="<?php echo htmlspecialchars($clientRegistration->inputs['addressofresidence'] ?? ''); ?>">
                                                </div>
                                                <?php displayError($clientRegistration->getError('addressofresidence')); ?>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="streetNameinput" class="form-label">Street Name: <span id="gt">*</span></label>
                                                    <input name="streetname" type="text" class="form-control" placeholder="Enter Street Name" id="streetNameinput" value="<?php echo htmlspecialchars($clientRegistration->inputs['streetname'] ?? ''); ?>">
                                                    <?php displayError($clientRegistration->getError('streetname')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="housenumberinput" class="form-label">House Number: <span id="gt">*</span></label>
                                                    <input name="housenumber" type="text" class="form-control" placeholder="Enter House Number" id="houseNumberinput" value="<?php echo htmlspecialchars($clientRegistration->inputs['housenumber'] ?? ''); ?>">
                                                    <?php displayError($clientRegistration->getError('housenumber')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="nearestBusStopinput" class="form-label">Nearest Bus Stop / LandMark:</label>
                                                    <input name="nearestbustoporlandmark" type="text" class="form-control" placeholder="Enter Nearest Bus Stop or Landmark" id="otherNameinput" value="<?php echo htmlspecialchars($clientRegistration->inputs['nearestbustoporlandmark'] ?? ''); ?>">
                                                    <?php displayError($clientRegistration->getError('nearestbustoporlandmark')); ?>
                                                </div>
                                            </div>
                                            <!-- start utility  info -->
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="ForminputUtilityBill" class="form-label"> Utility Bill: </label>
                                                    <input name="utilitybill" class="form-control" type="file" id="profileimgInput">
                                                    <?php displayError($clientRegistration->getError('utilitybill')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="ForminputRLGA" class="form-label"> Utility Bill Type: </label>
                                                    <select name="utilitybilltype" id="ForminputRLGA" class="form-select">
                                                        <option value=""></option>
                                                        <?php foreach ($clientRegistration->utilitybilltypes as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['utilitybilltype']) && $clientRegistration->inputs['utilitybilltype'] == $id) ? 'selected' : ''; ?>>
                                                            <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('utililitybilltype')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-12">
                                                <div class="mb-5">
                                                    <label for="ForminputSignature" class="form-label"> Signature: </label>
                                                    <input name="signature" class="form-control" type="file" id="SignatureimgInput">
                                                    <?php displayError($clientRegistration->getError('signature')); ?>
                                                </div>
                                            </div>
                                            <!-- / end utility info -->
                                            <div class="col-lg-12-hr">
                                                <hr class="left-hr">
                                                <span class="text-between-hr">Employment Info:</span>
                                                <hr class="right-hr">
                                            </div>
                                            <!-- start Client  info -->
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="ForminputUserTitle" class="form-label">Employment Status: </label>
                                                    <select name="employmentstatus" id="Forminputemploymentstatus" class="form-select">
                                                        <option value=""></option>
                                                        <?php foreach ($clientRegistration->employmentstatuses as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['employmentstatus']) && $clientRegistration->inputs['employmentstatus'] == $id) ? 'selected' : ''; ?>>
                                                            <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('employmentstatus')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="streetNameinput" class="form-label">Salary Range: <span id="gt">*</span></label>
                                                    <select name="employmentsalaryrange" id="ForminputOState" class="form-select">
                                                        <option value=""></option>
                                                        <?php foreach ($clientRegistration->employmentsalaryranges as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['employmentsalaryrange']) && $clientRegistration->inputs['employmentsalaryrange'] == $id) ? 'selected' : ''; ?>>
                                                            <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('employmentsalaryrange')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="surNameinput" class="form-label">Name of Employer or Business: <span id="gt">*</span></label>
                                                    <input name="nameofbusinessoremployment" type="text" class="form-control" placeholder="Enter Employer's or Business Name" id="input">
                                                    <?php displayError($clientRegistration->getError('nameofbusinessoremployment')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="surNameinput" class="form-label">Nature of Employment / Business: <span id="gt">*</span></label>
                                                    <input name="natureofbuinessoremployment" type="text" class="form-control" placeholder="Enter Employer's or Business Name" id="input">
                                                    <?php displayError($clientRegistration->getError('natureofbuinessoremployment')); ?>
                                                </div>
                                            </div>
                                            
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="" class="form-label">Employment Start Date: <i> (if available) </i></label>
                                                    <input name="employmentindate" type="date" class="form-control" placeholder="" id="Input">
                                                    <?php displayError($clientRegistration->getError('employmentindate')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="" class="form-label">Employment End Date: <i>(if available) </i></label>
                                                    <input name="employmentoutdate" type="date" class="form-control" placeholder="" id="Input">
                                                    <?php displayError($clientRegistration->getError('employmentoutdate')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="" class="form-label">Phone Number: <span id="gt">*</span></label>
                                                    <input name="employmentphonenumber" type="tel" class="form-control" placeholder="09000000000" id="Input">
                                                    <?php displayError($clientRegistration->getError('employmentphonenumber')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="" class="form-label">Email Address: <span id="gt">*</span></label>
                                                    <input name="employmentemail" type="email" class="form-control" placeholder="example@gamil.com" id="Input">
                                                    <?php displayError($clientRegistration->getError('employmentemail')); ?>
                                                </div>
                                            </div>
                                            <!--/ end Client Phone number info -->
                                            <!-- start Client Nationality -->
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="" class="form-label">Employer / Business Nationality: </label>
                                                    <select name="employmentnationality" id="" class="form-select">
                                                        <option> </option>
                                                        <?php foreach ($clientRegistration->nationalities as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['nationality']) && $clientRegistration->inputs['nationality'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('employmentnationality')); ?>
                                                </div>
                                                
                                            </div>
                                            <!-- end Client Nationality -->
                                            <!-- start Origin info -->
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="OstatenameInput" class="form-label">Employer / Business State: </label>
                                                    <select name="employmentstate" id="ForminputOState" class="form-select">
                                                    <option> </option>
                                                        <?php foreach ($clientRegistration->states as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['state']) && $clientRegistration->inputs['state'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('employmentstate')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="ForminputOLGA" class="form-label"> Employer / Business L.G.A: </label>
                                                    <select name="employmentlga" id="ForminputOLGA" class="form-select">
                                                        <option> </option>
                                                        <?php foreach ($clientRegistration->lgas as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['lga']) && $clientRegistration->inputs['lga'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('employmentlga')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="" class="form-label"> City / Town: </label>
                                                    <input name="employmentcityortown" type="text" class="form-control" placeholder="Enter City or Town" id="">
                                                    <?php displayError($clientRegistration->getError('employmentcityortown')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="nearestBusStopinput" class="form-label">Nearest Bus Stop / LandMark:</label>
                                                    <input name="employmentnearestbustoporlandmark" type="text" class="form-control" placeholder="Enter Nearest Bus Stop or Landmark" id="otherNameinput">
                                                    <?php displayError($clientRegistration->getError('employmentnearestbustoporlandmark')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="raddress1ControlTextarea" class="form-label">Employer / Business Address: </label>
                                                    <input name="employmentaddress" type="text" class="form-control" placeholder="Enter residential address" id="address1ControlTextarea">
                                                    <?php displayError($clientRegistration->getError('employmentaddress')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="streetNameinput" class="form-label"> Plot / Street Name: <span id="gt">*</span></label>
                                                    <input name="employmentplotorstreetname" type="text" class="form-control" placeholder="Enter Street Name" id="streetNameinput">
                                                    <?php displayError($clientRegistration->getError('employmentplotorstreetname')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="housenumberinput" class="form-label">Plot Number / House Number: <span id="gt">*</span></label>
                                                    <input name="employmenthouseorplotnumber" type="text" class="form-control" placeholder="Enter House Number" id="houseNumberinput">
                                                    <?php displayError($clientRegistration->getError('employmenthouseorplotnumber')); ?>
                                                </div>
                                            </div>
                                            <!--end col-->
                                            <div class="col-lg-12-hr">
                                                <hr class="left-hr">
                                                <span class="text-between-hr">Next of Kin:</span>
                                                <hr class="right-hr">
                                            </div>
                                            <!-- start Client  info -->
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="ForminputPassport" class="form-label"> Passport: </label>
                                                    <input name="nextofkinpassport" class="form-control" type="file" id="passportimgInput">
                                                    <?php displayError($clientRegistration->getError('nextofkinpassport')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="ForminputUserTitle" class="form-label">Title: </label>
                                                    <select name="nextofkintitle" id="ForminputUserTitle" class="form-select">
                                                    <option> </option>
                                                        <?php foreach ($clientRegistration->titles as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['titles']) && $clientRegistration->inputs['title'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('nnextofkintitle')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="ForminputOLGA" class="form-label">Relationship: <span id="gt">*</span></label>
                                                    <select name="nextofkinrelationship" id="" class="form-select">
                                                        <option> </option>
                                                        <?php foreach ($clientRegistration->relationships as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['relationship']) && $clientRegistration->inputs['relationship'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('nextofkinrelationship')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="surNameinput" class="form-label">Sur Name: <span id="gt">*</span></label>
                                                    <input name="nextofkinsurname" type="text" class="form-control" placeholder="Enter your Sur Name" id="">
                                                    <?php displayError($clientRegistration->getError('nextofkinsurname')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="firstNameinput" class="form-label">First Name: <span id="gt">*</span></label>
                                                    <input name="nextofkinfirstname" type="text" class="form-control" placeholder="Enter your First Name" id="">
                                                    <?php displayError($clientRegistration->getError('nextofkinfirstname')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="otherNameinput" class="form-label">Other Name:</label>
                                                    <input name="nextofkinothername" type="text" class="form-control" placeholder="Enter your Other name" id="">
                                                    <?php displayError($clientRegistration->getError('nextofkinothername')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="" class="form-label">Nature of Employment / Business: <span id="gt">*</span></label>
                                                    <input name="nextofkinnatureofemploymentorbusiness" type="text" class="form-control" placeholder="Enter Nature of Business or Employment" id="">
                                                    <?php displayError($clientRegistration->getError('nextofkinnatureofemploymentorbusiness')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="address1ControlTextarea" class="form-label">Business / Office Address: </label>
                                                    <input name="nextofkinbusinessorofficeaddress" type="text" class="form-control" placeholder="Enter Business or Office address" id="">
                                                    <?php displayError($clientRegistration->getError('nextofkinbusinessorofficeaddress')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="genderInput" class="form-label">Gender: <span id="gt">*</span></label>
                                                    <select name="nextofkingender" id="Forminputgender" class="form-select">
                                                        <option> </option>
                                                        <?php foreach ($clientRegistration->genders as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['gender']) && $clientRegistration->inputs['gender'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('nextofkingender')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="ForminputDOB" class="form-label"> D.O.B: <span id="gt">*</span></label>
                                                    <input name="nextofkindob" type="date" class="form-control" placeholder="" id="Input">
                                                    <?php displayError($clientRegistration->getError('nextofkindob')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="" class="form-label">Marital Status: <span id="gt">*</span></label>
                                                    <select name="nextofkinmaritalstatus" id="" class="form-select">
                                                    <option> </option>
                                                        <?php foreach ($clientRegistration->maritalstatuses as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['maritalstatus']) && $clientRegistration->inputs['maritalstatus'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('nextofkinmaritalstatus')); ?>
                                                </div>
                                            </div>
                                            <!--/ end Another Client info -->
                                            <!-- Client Phone number info -->
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="phonenumberInput" class="form-label">Phone Number: <span id="gt">*</span></label>
                                                    <input name="nextofkinphonenumber" type="tel" class="form-control" placeholder="09000000000" id="Input">
                                                    <?php displayError($clientRegistration->getError('nextofkinphonenumber')); ?>
                                                </div>
                                            </div>
                                            <!--/ end Client Phone number info -->
                                            <!-- Clients Email info -->
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="emailidInput" class="form-label">Email Address: <span id="gt">*</span></label>
                                                    <input name="nextofkinemail" type="email" class="form-control" placeholder="example@gamil.com" id="emailidInput">
                                                    <?php displayError($clientRegistration->getError('nextofkinemail')); ?>
                                                </div>
                                            </div>
                                            <!-- / end Clients Email info -->
                                            <!-- Clients Username info -->
                                            <!-- start Client Business or Office Address  -->

                                            <!--/ end Client Business or Office Address -->
                                            <!-- start Client Nationality -->
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="ForminputNationality" class="form-label">Nationality: </label>
                                                    <select name="nextofkinnationality" id="ForminputNationality" class="form-select">
                                                    <option> </option>
                                                        <?php foreach ($clientRegistration->nationalities as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['nationality']) && $clientRegistration->inputs['nationality'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('nextofkinnationality')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="RstatenameInput" class="form-label"> State of Residence: </label>
                                                    <select name="nextofkinstate" id="ForminputRState" class="form-select">
                                                    <option> </option>
                                                        <?php foreach ($clientRegistration->states as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['state']) && $clientRegistration->inputs['state'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('nextofkinstate')); ?>
                                                </div>
                                            </div>
                                            <!-- start Residential info -->
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="ForminputRLGA" class="form-label"> L.G.A of Residence: </label>
                                                    <select name="nextofkinlga" id="ForminputRLGA" class="form-select">
                                                    <option> </option>
                                                        <?php foreach ($clientRegistration->lgas as $id => $name) : ?>
                                                        <option value="<?php echo htmlspecialchars($id); ?>" <?php echo (isset($clientRegistration->inputs['lga']) && $clientRegistration->inputs['lga'] == $id) ? 'selected' : ''; ?>>
                                                        <?php echo htmlspecialchars($name); ?>
                                                        </option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <?php displayError($clientRegistration->getError('nextofkinlga')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="raddress1ControlTextarea" class="form-label">City / Town: </label>
                                                    <input name="nextofkincityortown" type="text" class="form-control" placeholder="Enter residential address" id="address1ControlTextarea">
                                                    <?php displayError($clientRegistration->getError('nextofkincityortown')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="raddress1ControlTextarea" class="form-label">Residential Address: </label>
                                                    <input name="nextofkinaddress" type="text" class="form-control" placeholder="Enter residential address" id="address1ControlTextarea">
                                                    <?php displayError($clientRegistration->getError('nextofkinaddress')); ?>
                                                </div>
                                            </div>
                                            <!--/ end Residential info -->
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="housenumberinput" class="form-label">House Number: <span id="gt">*</span></label>
                                                    <input name="nextofkinhousenumber" type="text" class="form-control" placeholder="Enter House Number" id="houseNumberinput">
                                                    <?php displayError($clientRegistration->getError('nextofkinhousenumber')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="streetNameinput" class="form-label">Street Name: <span id="gt">*</span></label>
                                                    <input name="nextofkinstreetname" type="text" class="form-control" placeholder="Enter Street Name" id="streetNameinput">
                                                    <?php displayError($clientRegistration->getError('nextofkinstreetname')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="mb-3">
                                                    <label for="nearestBusStopinput" class="form-label">Nearest Bus Stop / LandMark:</label>
                                                    <input name="nextofkinnearestbusstoporlandmark" type="text" class="form-control" placeholder="Enter Nearest Bus Stop or Landmark" id="otherNameinput">
                                                    <?php displayError($clientRegistration->getError('nextofkinnearestbustoporlandmark')); ?>
                                                </div>
                                            </div>
                                            <br>
                                            <br>
                                            <!--end col-->
                                            <div class="col-lg-12-hr">
                                                <hr class="left-hr">
                                                <span class="text-between-hr"> Official Use Only:</span>
                                                <hr class="right-hr">
                                            </div>
                                            <!-- start Client  info -->
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="ForminputSealImage" class="form-label"> Seal: </label>
                                                    <input name="seal" class="form-control" type="file" id="SealimgInput">
                                                    <?php displayError($clientRegistration->getError('seal')); ?>
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="mb-3">
                                                    <label for="ForminputSealNumber" class="form-label">Seal Number: </label>
                                                    <input name="sealnumber" type="text" class="form-control" placeholder="Enter seal number" id="sealnumberinput">
                                                    <?php displayError($clientRegistration->getError('sealnumber')); ?>
                                                </div>
                                            </div>
                                            <div class="col-lg-12">
                                                <div class="text-end">
                                                    <button type="submit" class="btn btn-primary">Submit</button>
                                                </div>
                                            </div>
                                            <!--end col-->
                                        </div>
                                        <!--end row-->
                                    </form>

                                </div>
                            </div>
                        </div>
                    </div>
                    <!--end row-->



                </div> <!-- container-fluid -->
            </div>
            <!-- End Page-content -->

            <?php
            include_once '../../B-END/INC/mainfooter.php';
            ?>
            </footer>
        </div>
        <!-- end main content-->

    </div>
    <!-- END layout-wrapper -->

    <?php
    include_once '../../B-END/INC/bfooter.php';
    ?>

</body>

</html>

 

Link to comment
Share on other sites

do you have a specific question, problem, or error, related to a small part of the 2809 lines of posted code?

next, OOP is not about wrapping your main code in a class and adding $var-> in front of everything to make it work. all that did is exchange one defining and calling syntax for a more verbose one that didn't make it easier to create an application. you should have instead created a general-purpose validation class, a general-purpose  sql query class, and a general-purpose form class, then define the expected fields, their labels/names, data types, validation rules, sql query rules, and form field rules in an array, then use this definition to control what the general-purpose code does. adding, changing, or deleting a form field, its validation, and its processing should just require adding, changing, or deleting a line in the defining array. 

btw - for file uploads, there are upload errors that result in a non-empty ['name'] element. you must test the ['error'] element to determine if a file uploaded without any error.

Link to comment
Share on other sites

5 hours ago, Dealmightyera said:

Can you help in implementing it for me please, I'm not too advance in ooo

We all have to learn. I get that. I am still learning every day. But, best way to learn is to get your hands dirty and get stuck into it.

Learn about PHP first and then concentrate on OOP (not ooo). There are plenty of resources out there to help you learn.

Link to comment
Share on other sites

On 7/27/2024 at 9:03 PM, Dealmightyera said:

Can you help in implementing it for me please, I'm not too advance in ooo

What specifically doesn't work here?  It looks like there is code to handle the inserts, along with a transaction in the registerUser() method.

Just as a comment, this is a great example of where someone missed the forest for the trees.  

Instead of having this giant class that has individual "validation" methods for every field, a relatively simple validation class could have been written that generically handles a few different types of validation on a field.  Then that class could have been applied.  

This is where the author never asked the question of "am I repeating myself?", or applied the concept of "Don't repeat yourself" aka DRY.

The same idea goes for all the database insert methods.  Create one generic insert method that takes the SQL insert statement as a parameter, and an array parameter keyed with the parameter name and loop through that creating all the binds.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.