Your IP : 216.73.217.79


Current Path : /var/www/cesa.co.za/php/
Upload File :
Current File : /var/www/cesa.co.za/php/cpdproviderapply.php

<?php
//ini_set('display_errors', 1);
//error_reporting(E_ALL);

include_once("inc_db.php");
// include_once($_SERVER['DOCUMENT_ROOT'] . "/phpmailer/PHPMailer.php");
// include_once($_SERVER['DOCUMENT_ROOT'] . "/phpmailer/SMTP.php");
// include_once($_SERVER['DOCUMENT_ROOT'] . "/phpmailer/Exception.php");
include_once($_SERVER['DOCUMENT_ROOT'] . "/cesanet/inc_shared.php");
// include_once($_SERVER['DOCUMENT_ROOT'] . "/php/includes/maill.php");

// use PHPMailer\PHPMailer\PHPMailer;

$Notify = "blessings@cesa.co.za,brenda@cesa.co.za,cpdverification@cesa.co.za,athromethm@cesa.co.za";

//$Notify="julia@xe.co.za";
function WritePhoneField($sName, $bRequired)
{
    return '+<input type="text" style="width:45px !important" placeholder="27" name="' . $sName . '_1" size="2" value="27"' . ($bRequired ? ' required' : '') . '>(0)<input type="text" style="width:45px !important" placeholder="" name="' . $sName . '_2" size="2"' . ($bRequired ? ' required' : '') . '><input type="text" style="width:90px !important" name="' . $sName . '_3" size="3"' . ($bRequired ? ' required' : '') . '><input type="text" style="width:90px !important" name="' . $sName . '_4" size="4"' . ($bRequired ? ' required' : '') . '>';
}

function CombinePhonePost($sName)
{
    return "+" . filter_input(INPUT_POST, $sName . "_1", FILTER_SANITIZE_STRING) . " (0" . filter_input(INPUT_POST, $sName . "_2", FILTER_SANITIZE_STRING) . ") " . filter_input(INPUT_POST, $sName . "_3", FILTER_SANITIZE_STRING) . " " . filter_input(INPUT_POST, $sName . "_4", FILTER_SANITIZE_STRING);
}

function GenPassword()
{
    // Password generation
    $length = 8; // Must be a multiple of 2
    $conso = array("b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "v", "w", "x", "y", "z");
    $vocal = array("a", "e", "i", "o", "u");
    $password = "";
    srand((float) microtime() * 1000000);
    $max = $length / 2;
    for ($i = 1; $i <= $max; $i++) {
        $password .= $conso[rand(0, 19)];
        $password .= $vocal[rand(0, 4)];
    }

    return $password;
}

function UniqueFilename($sDir, $sFilename, $sFilenamePrefix = "")
{
    global $conn;

    $ext = pathinfo($sFilename, PATHINFO_EXTENSION);
    $fname = pathinfo($sFilename, PATHINFO_FILENAME);
    $i = 1;
    $sNewFilename = "";
    if (!empty($_SESSION["ProviderID"]))
        $sNewFilename = $_SESSION["ProviderID"];
    if (!empty($sFilenamePrefix)) {
        $sNewFilename .= str_replace(array("'", '"', ",", '#', " "), "_", $sFilenamePrefix);
    } else {
        $sNewFilename .= str_replace(array("'", '"', ",", '#'), "_", $fname);
    }
    $sFinalFilename = $sNewFilename;
    while (file_exists($sDir . $sNewFilename . "." . $ext)) {
        $sNewFilename = $sFinalFilename . "_" . $i;
        $i++;
    }
    return $sDir . $sNewFilename . "." . $ext;
}

//function XMail($to, $subject, $msg, $from, $CC, $type) {
//
//    $mail = new PHPMailer;
//    $mail->Mailer = "mail";
//
//    /*
//      $mail->Mailer="smtp";
//      $mail->Host="relay.aitonline.co.za";
//      $mail->Port=587;
//      $mail->Username="mail@cesa.co.za";
//      $mail->Password="c3SAmail!@!";
//      $mail->SMTPDebug=false;
//      $mail->SMTPAuth=true;
//     */
//    if ($type == "html")
//        $mail->IsHTML(true);
//
//    $mail->From = $from;
//    $mail->FromName = $from;
//
//    $arrto = explode(",", $to);
//    for ($i = 0; $i < count($arrto); $i++) {
//        $mail->AddAddress($arrto[$i]);
//    }
//    $mail->Subject = $subject;
//    $mail->Body = $msg;
//
//    if (!$mail->Send())
//        echo $mail->ErrorInfo;
//}

$sessid = session_id();
if (empty($sessid)) {
    session_start();
    $sessid = session_id();
}
$_COOKIE["PHPSESSID"] = $sessid;
?>
<link rel="stylesheet" href="/js/jQuery-File-Upload-10.32.0/css/jquery.fileupload.css" />
<link rel="stylesheet" href="/js/jQuery-File-Upload-10.32.0/css/jquery.fileupload-ui.css" />
<!-- CSS adjustments for browsers with JavaScript disabled -->
<noscript>
    <link rel="stylesheet" href="/js/jQuery-File-Upload-10.32.0/css/jquery.fileupload-noscript.css" />
</noscript>
<noscript>
    <link rel="stylesheet" href="/js/jQuery-File-Upload-10.32.0/css/jquery.fileupload-ui-noscript.css" />
</noscript>
<!-- The jQuery UI widget factory, can be omitted if jQuery UI is already included -->
<script src="/js/jQuery-File-Upload-10.32.0/js/vendor/jquery.ui.widget.js"></script>
<!-- The Templates plugin is included to render the upload/download listings -->
<!--    <script src="https://blueimp.github.io/JavaScript-Templates/js/tmpl.min.js"></script> -->
<!-- The Iframe Transport is required for browsers without support for XHR file uploads -->
<script src="/js/jQuery-File-Upload-10.32.0/js/jquery.iframe-transport.js"></script>
<!-- The basic File Upload plugin -->
<script src="/js/jQuery-File-Upload-10.32.0/js/jquery.fileupload.js"></script>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>

<h2 style="background-color:#6DA9D4; padding:5px;">Apply to be a CESA / ECSA Verified CPD Service / Training Provider</h2>
<?php
$bDisplayForm = true;
$sUploadDir = $_SERVER['DOCUMENT_ROOT'] . "/js/jQuery-File-Upload-10.32.0/server/php/files/";
if (isset($_POST["do"])) {
    $arrRequired = array("DBCompanyName", "DBContactEmail");
    $bAllRequired = true;
    $bAllFiles = true;
    foreach ($arrRequired as $sField) {
        if (empty(filter_input(INPUT_POST, $sField, FILTER_SANITIZE_STRING))) {
            $bAllRequired = false;
            break;
        }
    }

    if ($bAllRequired) {
        $sql = "SELECT DisplayOrder, PicklistValue, PicklistLabel 
            FROM Picklists 
            WHERE PicklistType='CPD Provider Documents' 
            ORDER BY DisplayOrder, PicklistValue";
        $rec = mysqli_query($conni, $sql);
        $i = 0;
        while ($row = mysqli_fetch_assoc($rec)) {

            if ($row["PicklistLabel"] == 'Proof of Payment') {
                continue;
            }

            $i++;
            if (($row["DisplayOrder"] != 40) && ($row["DisplayOrder"] != 70)) {
                // BBBEE and PoP not required
                $sFilename = $_REQUEST["FLFile" . $i];
                $sFiletype = filter_input(INPUT_POST, "FLName" . $i, FILTER_SANITIZE_STRING);
                if (empty($sFilename) || !file_exists($sUploadDir . $sFilename)) {
                    echo $i . ' - Not found ' . $sUploadDir . $sFilename . ' - ' . file_exists($sUploadDir . $sFilename) . '<br />';
                    //                    var_dump($row);
                    //                    echo '<br />';
                    $bAllFiles = false;
                    break;
                }
            }
        }
    }
    if (!reCaptcha($_POST["g-recaptcha-response"])) {
        //TODO: Fix the google captcha verification
?>
        <div class="alert alert-danger">Error: You could not be verified as not being a robot, please tick the reCaptcha verification option at the bottom of the form.</div>
    <?php
    } elseif (!$bAllRequired) {
    ?>
        <div class="alert alert-danger">Error: please provide all the required fields.</div>
    <?php
    } elseif (!$bAllFiles) {
    ?>
        <div class="alert alert-danger">Error: Please upload the required files.</div>
        <?php
    } else {

        try {

            $sPassword = GenPassword();

            if (isset($_FILES['PrevSPNumberCertificate'])) {
                $uploadfilenamePrevCert = strtolower(str_replace(array("'", "\"", "(", ")", "#", " "), "_", basename(stripslashes($_FILES['PrevSPNumberCertificate']['name']))));
                $uploadfilePrevCert = $uploaddir . $uploadfilenamePrevCert;

                move_uploaded_file($_FILES['ActivityProgramme']['tmp_name'], $uploadfilePrevCert);
                $uploadfilePrevCert = $uploadfilenamePrevCert;
            }

            if (isset($_FILES['OtherVACPDSPNumberCertificate'])) {
                $uploadfilenameOtherPrevCert = strtolower(str_replace(array("'", "\"", "(", ")", "#", " "), "_", basename(stripslashes($_FILES['OtherVACPDSPNumberCertificate']['name']))));
                $uploadfileOtherPrevCert = $uploaddir . $uploadfilenameOtherPrevCert;

                move_uploaded_file($_FILES['OtherVACPDSPNumberCertificate']['tmp_name'], $uploadfileOtherPrevCert);
                $uploadfileOtherPrevCert = $uploadfilenameOtherPrevCert;
            }

            if (isset($_FILES['AccountabilityStructure'])) {
                $uploadfilenameAccountabilityStructure = strtolower(str_replace(array("'", "\"", "(", ")", "#", " "), "_", basename(stripslashes($_FILES['AccountabilityStructure']['name']))));
                $uploadfileAccountabilityStructure = $uploaddir . $uploadfilenameAccountabilityStructure;

                move_uploaded_file($_FILES['AccountabilityStructure']['tmp_name'], $uploadfileAccountabilityStructure);
                $uploadfileAccountabilityStructure = $uploadfilenameAccountabilityStructure;
            }

            $sql = "insert into `CPDServiceProvider` (
        `CompanyName`, `TradingAs`, `ContactTitle`, `ContactInitials`,
        `ContactFirstName`, `ContactSurname`, `ContactPosition`, `ContactIDNum`,
        `PhoneNumber`, `ContactEmail`, `Password`, `PhysicalAddress1`,
        `PhysicalAddress2`, `PhysicalCity`, `PhysicalCode`, `PhysicalProvince`,
        `PhysicalCountry`, `Website`, `VATNumber`, `DateUpdated`, `UpdatedBy`,
        `Archived`, `ContactPhone`, `AdminTitle`, `AdminInitials`, `AdminFirstName`,
        `AdminSurname`, `AdminPosition`, `AdminIDNum`, `AdminEmail`,
        `AdminPhone`, `Approved`, `EmailAddress`, CellNumber, ContactCell, AdminCell, SPNumber, PrevSPNumber, 
        PrevSPNumberCertificate, OtherVACPDSPNumber, OtherVACPDSPNumberCertificate, Renewal, DateCreated, AccountabilityStructure) 
        values (
          '" . filter_input(INPUT_POST, "DBCompanyName", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBTradingAs", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBContactTitle", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBContactInitials", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBContactFirstName", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBContactSurname", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBContactPosition", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBContactIDNum", FILTER_SANITIZE_STRING) . "',
          '" . CombinePhonePost("DBPhoneNumber") . "',
          '" . filter_input(INPUT_POST, "DBContactEmail", FILTER_SANITIZE_STRING) . "',
          '" . $sPassword . "',
          '" . filter_input(INPUT_POST, "DBPhysicalAddress1", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBPhysicalAddress2", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBPhysicalCity", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBPhysicalCode", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBPhysicalProvince", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBPhysicalCountry", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBWebsite", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBVATNumber", FILTER_SANITIZE_STRING) . "',
          NOW(),
          '" . filter_input(INPUT_POST, "DBContactEmail", FILTER_SANITIZE_STRING) . "',
          0,
          '" . CombinePhonePost("DBContactPhone") . "',
          '" . filter_input(INPUT_POST, "DBAdminTitle", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBAdminInitials", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBAdminFirstName", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBAdminSurname", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBAdminPosition", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBAdminIDNum", FILTER_SANITIZE_STRING) . "',
          '" . filter_input(INPUT_POST, "DBAdminEmail", FILTER_SANITIZE_STRING) . "',
          '" . CombinePhonePost("DBAdminPhone") . "',
          'P',
          '" . filter_input(INPUT_POST, "DBEmailAddress", FILTER_SANITIZE_STRING) . "',
          '" . CombinePhonePost("DBCellNumber") . "',
          '" . CombinePhonePost("DBContactCell") . "',
          '" . CombinePhonePost("DBAdminCell") . "',
              'Pending Verification',
          '" . filter_input(INPUT_POST, "DBPrevSPNumber", FILTER_SANITIZE_STRING) . "',
          '" . $uploadfilePrevCert . "',
          '" . filter_input(INPUT_POST, "OtherVACPDSPNumber", FILTER_SANITIZE_STRING) . "',
          '" . $uploadfileOtherPrevCert . "',
          '" . filter_input(INPUT_POST, "DBRenewal", FILTER_SANITIZE_STRING) . "', "
                . "NOW(),
          '" . $uploadfileAccountabilityStructure . "')";

            mysqli_query($conni, $sql);

            $iSPID = mysqli_insert_id($conni);

            $sForm = '
    <table border="1" cellpadding="5" cellspacing="0">
    	<tr><td colspan=2><p style="font-weight: bold">SERVICE PROVIDER APPLYING FOR APPROVAL IN TERMS OF ECSA CPD POLICY</p>
		</td>
        </tr>
        <tr><td colspan="2" bgcolor="#CCCCCC"><b>&nbsp;Organisation Details</b></td></tr>
        <tr><td><b>Company Name *</b></td>
        <td>' . $_POST["DBCompanyName"] . '</td></tr>
        <tr><td><b>Known As / Trading As</b></td>
        <td>' . $_POST["DBTradingAs"] . '</td></tr>
        <tr><td><b>Renewal *</b></td>
        <td>' . $_POST["DBRenewal"] . '</td></tr>
        <tr><td><b>Previous CESA CPD Verification Service Provider Number</b></td>
        <td>' . $_POST['PrevSPNumber'] . '</td></tr>
        <tr><td><b>Other Volunteer Association CPD Verified Service Provider Certificate</b></td>
        <td>' . $_POST["PrevSPNumberCertificate"] . '</td></tr>
        <tr><td><b>Previous CESA CPD Verification Service Provider Certificate</b></td>
        <td>' . $uploadfilePrevCert . '</td></tr>
        <tr><td><b>Other Volunteer Association CPD Verified Service Provider Number</b></td>
        <td>' . $_POST["OtherVACPDSPNumber"] . '</td></tr>
        <tr><td><b>Other Volunteer Association CPD Verified Service Provider Certificate</b></td>
        <td>' . $uploadfileOtherPrevCert . '</td></tr>
        <tr><td><b>Phone Number</b></td>
        <td>' . CombinePhonePost("DBPhoneNumber") . '</td></tr>
        <tr><td><b>Cell Number *</b></td>
        <td>' . CombinePhonePost("DBCellNumber") . '</td></tr>
        <tr><td><b>Website</b></td>
        <td>' . $_POST["DBWebsite"] . '</td></tr>
        <tr><td><b>Email Address *</b></td>
        <td>' . $_POST["DBEmailAddress"] . '</td></tr>
        <tr><td><b>VAT No</b></td>
        <td>' . $_POST["DBVATNumber"] . '</td></tr>
        <tr><td colspan="2" bgcolor="#CCCCCC"><b>&nbsp;Physical Address</b></td></tr>
        <tr><td><b>Physical Address Line 1</b></td>
        <td>' . $_POST["DBPhysicalAddress1"] . '</td></tr>
        <tr><td><b>Physical Address Line 2</b></td>
        <td>' . $_POST["DBPhysicalAddress2"] . '</td></tr>
        <tr><td><b>City *</b></td>
        <td>' . $_POST["DBPhysicalCity"] . '</td></tr>
        <tr><td><b>Code *</b></td>
        <td>' . $_POST["DBPhysicalCode"] . '</td></tr>
        <tr><td><b>Province *</b></td>
        <td>' . $_POST["DBPhysicalProvince"] . '</td></tr>
        <tr><td><b>Country *</b></td>
        <td>' . $_POST["DBPhysicalCountry"] . '</td></tr>
        <tr><td colspan="2" bgcolor="#CCCCCC"><b>&nbsp;Person who is applying for verification on behalf of the organisation</b></td></tr>
        <tr><td width="30%"><b>Title *</b></td>
        <td>' . $_POST["DBContactTitle"] . '</td></tr>
        <tr><td><b>Initials</b></td>
        <td>' . $_POST["DBContactInitials"] . '</td></tr>
        <tr><td><b>First Name (Known As) *</b></td>
        <td>' . $_POST["DBContactFirstName"] . '</td></tr>
        <tr><td><b>Surname *</b></td>
        <td>' . $_POST["DBContactSurname"] . '</td></tr>
        <tr><td><b>Position Held</b></td>
        <td>' . $_POST["DBContactPosition"] . '</td></tr>
        <tr><td><b>ID / Passport Number</b></td>
        <td>' . $_POST["DBContactIDNum"] . '</td></tr>
        <tr><td><b>Phone Number</b></td>
        <td>' . $_POST["DBContactPhone"] . '</td></tr>
        <tr><td><b>Cell Number *</b></td>
        <td>' . CombinePhonePost("DBContactCell") . '</td></tr>
        <tr><td><b>Email Address *</b></td>
        <td>' . $_POST["DBContactEmail"] . '</td></tr>
        <tr><td colspan="2" bgcolor="#CCCCCC"><b>&nbsp;Person who is acting as the administrator on behalf of the organisation</b></td></tr>
        <tr><td width="30%"><b>Title</b></td>
        <td>' . $_POST["DBAdminTitle"] . '</td></tr>
        <tr><td><b>Initials</b></td>
        <td>' . $_POST["DBAdminInitials"] . '</td></tr>
        <tr><td><b>First Name (Known As) *</b></td>
        <td>' . $_POST["DBAdminFirstName"] . '</td></tr>
        <tr><td><b>Surname *</b></td>
        <td>' . $_POST["DBAdminSurname"] . '</td></tr>
        <tr><td><b>Position Held</b></td>
        <td>' . $_POST["DBAdminPosition"] . '</td></tr>
        <tr><td><b>ID / Passport Number</b></td>
        <td>' . $_POST["DBAdminIDNum"] . '</td></tr>
        <tr><td><b>Phone Number</b></td>
        <td>' . CombinePhonePost("DBAdminPhone") . '</td></tr>
        <tr><td><b>Cell Number *</b></td>
        <td>' . CombinePhonePost("DBAdminCell") . '</td></tr>
        <tr><td><b>Email Address *</b></td>
        <td>' . $_POST["DBAdminEmail"] . '</td></tr>
        <tr><td colspan="2" bgcolor="#CCCCCC"><b>&nbsp;Upload Documents</b></td></tr>
        ';

            for ($i = 1; $i <= intval($_POST["NumFiles"]); $i++) {
                $target_dir = $_SERVER['DOCUMENT_ROOT'] . "/cpdadmin/providerdocs/";
                $sFilename = filter_input(INPUT_POST, "FLFile" . $i, FILTER_SANITIZE_STRING);
                $sFiletype = filter_input(INPUT_POST, "FLName" . $i, FILTER_SANITIZE_STRING);
                if (!empty($sFilename) && file_exists($sUploadDir . $sFilename)) {
                    $sNewFilename = $iSPID . $sFilename;
                    $iPrefix = 1;
                    while (file_exists($target_dir . $sNewFilename)) {
                        $sNewFilename = $iPrefix . $sNewFilename;
                        $iPrefix++;
                    }
                    copy($sUploadDir . $sFilename, $target_dir . $sNewFilename);
                    unlink($sUploadDir . $sFilename);
                    $sql = "INSERT INTO CPDProviderDocs (CPDProviderID, DocType, DocFile, UploadedBy, DateUploaded)
            VALUES (" . $iSPID . ", '" . $sFiletype . "', '" . $sNewFilename . "',
            '" . filter_input(INPUT_POST, "DBContactEmail", FILTER_SANITIZE_STRING) . "', NOW())";
                    mysqli_query($conni, $sql);
                    $sForm .= '<tr><td><a href="https://www.cesa.co.za/cpdadmin/providerdocs/' . $sNewFilename . '">' . $sFiletype . '</a></td>
            <td>File uploaded</td></tr>
            ';
                }
            }
            $sForm .= '
            <tr>
                <td><b>Accountability Structure</b></td>
                <td>' . $uploadfileAccountabilityStructure . '</td>
            </tr>
            </table>';

            $sSendFormTo = "cpd@cesa.co.za,brenda@cesa.co.za,blessings@cesa.co.za,cpdverification@cesa.co.za,athromethm@cesa.co.za";
            //$sSendFormTo = "julia@xe.co.za";

            maill($sSendFormTo, "APPLICATION FOR APPROVAL OF A CONTINUING PROFESSIONAL DEVELOPMENT (CPD) SERVICE PROVIDER", $sForm, null, ['isHTML' => true, 'from-name' => 'CPD Verification']);

            $sForm = "<p>Dear " . $_POST["DBContactFirstName"] . " " . $_POST["DBContactSurname"] . "</p>
<p>We acknowledge receipt of your application for verification as an ECSA Service Provider.</p>
<p>Sue Moseley Walker, the CESA CPD Verification Assessor, will be in contact with you shortly.</p>
<p>Kind regards,</p>
<p>CPD Verification Assessments<br>
CESA</p>";

            maill($_POST["DBContactEmail"], "Acknowledgement of application for approval of a CPD Service Provider", $sForm, null, ['bcc' => ['cpd@cesa.co.za'], 'cc' => ['cpdverification@cesa.co.za'], 'isHTML' => true, 'from-name' => 'CPD Verification']);

            $bDisplayForm = false;
        ?>
            <div class="alert alert-success">Thank you for your submission. Your information has been received, and will be assessed. You will be notified of the outcome of your assessment once the process is complete.</div>
        <?php
        } catch (Exception $ex) {
        ?>
            <p><b>There was a problem with your submission.</b></p>
            <p>The error has been reported. Please try again later.</p>
            <p><a href="#" onclick="history.go(-1); return false;">Try again</a></p>
            <p><a href="/cpd-validation/training-material/">Return to main page</a></p>
            <p><a href="/cpd-validation/training-material/?do=addcrs">Submit another activity</a></p>
            <p><a href="/cpd-validation/training-material/?do=logout">Logout</a></p>
    <?php
            maill('cesa-cpd@igotafrica.com', "Error on CPD service provider application", $ex->getMessage() . ' - ' . $ex->getTraceAsString(), null, ['isHTML' => false, 'from-name' => 'CPD Verification']);
        }
    }
}

if ($bDisplayForm) {

    foreach ($_POST as $key => $val) {
        $sFieldName = str_replace("DB", "Exist_", $key);
        ${$sFieldName} = $val;
    }

    ?>
    <p><b>* = required field</b></p>
    <form method="post" action="/cpd-validation/cpd-service-provider/" enctype="multipart/form-data">
        <input type="hidden" name="do" value="1">
        <table border="1" width="100%" cellspacing="0" cellpadding="2" class="tpedittable">
            <tr>
                <td colspan="2" bgcolor="#CCCCCC"><b>&nbsp;Organisation Details</b></td>
            </tr>
            <tr>
                <td><b>Company Name *</b></td>
                <td><input type="text" name="DBCompanyName" value="<?php echo $Exist_CompanyName; ?>" size="40" required></td>
            </tr>
            <tr>
                <td><b>Known As / Trading As</b></td>
                <td><input type="text" name="DBTradingAs" value="<?php echo $Exist_TradingAs; ?>" size="40"></td>
            </tr>
            <tr>
                <td><b>New or Renewal *</b></td>
                <td>
                    <input type="radio" name="DBRenewal" id="DBRenewal_0" value="0" checked required /> New <input type="radio" name="DBRenewal" id="DBRenewal_1" value="1" required /> Renewal
                </td>
            </tr>
            <tr>
                <td>
                    <b>Previous CESA CPD Verification Service Provider Number</b>
                </td>
                <td>
                    <?php
                    $serviceProviderObj = new CPDServiceProvider($sqlf);
                    echo HTMLHelper::drawSelect(['name' => 'DBPrevSPNumber', 'value' => $PrevSPNumber, 'choices' => $serviceProviderObj->getPreviousSPNumbersSelectArray()]);
                    ?>
                </td>
            </tr>
            <tr>
                <td>
                    <b>Previous CESA CPD Verification Service Provider Certificate</b>
                </td>
                <td>
                    <input id="PrevSPNumberCertificate" name="PrevSPNumberCertificate" type="file" />
                </td>
            </tr>
            <tr>
                <td>
                    <b>Other Volunteer Association CPD Verified Service Provider Number</b>
                </td>
                <td>
                    <textarea id="OtherVACPDSPNumber" name="OtherVACPDSPNumber" cols="80" rows="5"></textarea>
                </td>
            </tr>
            <tr>
                <td>
                    <b>Other Volunteer Association CPD Verified Service Provider Certificate</b>
                </td>
                <td>
                    <input id="OtherVACPDSPNumberCertificate" name="OtherVACPDSPNumberCertificate" type="file" />
                </td>
            </tr>
            <tr>
                <td><b>Phone Number</b><br>Format e.g.: +27 (0)11 463 2022</td>
                <td><?php echo WritePhoneField("DBPhoneNumber", false); ?></td>
            </tr>
            <tr>
                <td><b>Cell Number *</b><br>Format e.g.: +27 (0)82 XXX YYYY</td>
                <td><?php echo WritePhoneField("DBCellNumber", true); ?></td>
            </tr>
            <tr>
                <td><b>Website</b></td>
                <td><input type="text" name="DBWebsite" value="<?php echo $Exist_Website; ?>" size="40"></td>
            </tr>
            <tr>
                <td><b>Email Address *</b></td>
                <td><input type="text" name="DBEmailAddress" value="<?php echo $Exist_EmailAddress; ?>" size="40" required></td>
            </tr>
            <tr>
                <td><b>VAT No</b></td>
                <td><input type="text" name="DBVATNumber" value="<?php echo $Exist_VATNumber; ?>" size="40"></td>
            </tr>
            <tr>
                <td colspan="2" bgcolor="#CCCCCC"><b>&nbsp;Physical Address</b></td>
            </tr>
            <tr>
                <td><b>Physical Address Line 1</b></td>
                <td><input type="text" name="DBPhysicalAddress1" value="<?php echo $Exist_PhysicalAddress1; ?>" size="40"></td>
            </tr>
            <tr>
                <td><b>Physical Address Line 2</b></td>
                <td><input type="text" name="DBPhysicalAddress2" value="<?php echo $Exist_PhysicalAddress2; ?>" size="40"></td>
            </tr>
            <tr>
                <td><b>City *</b></td>
                <td><input type="text" name="DBPhysicalCity" value="<?php echo $Exist_PhysicalCity; ?>" size="40" required></td>
            </tr>
            <tr>
                <td><b>Code *</b></td>
                <td><input type="text" name="DBPhysicalCode" value="<?php echo $Exist_PhysicalCode; ?>" size="40" required></td>
            </tr>
            <tr>
                <td><b>Province *</b></td>
                <td><select name="DBPhysicalProvince" required>
                        <option value="" <?php if (empty($Exist_PhysicalProvince)) echo " selected"; ?>>Please select</option>
                        <?php
                        $sql = "SELECT PicklistValue FROM Picklists WHERE PicklistType='Province' ORDER BY DisplayOrder, PicklistValue";
                        $rec = mysqli_query($conni, $sql);
                        while ($row = mysqli_fetch_assoc($rec)) {
                        ?>
                            <option value="<?php echo $row["PicklistValue"]; ?>" <?php if ($Exist_PhysicalProvince == $row["PicklistValue"]) echo " selected"; ?>><?php echo $row["PicklistValue"]; ?></option>
                        <?php
                        }
                        ?>
                        <option value="International" <?php if ($Exist_PhysicalProvince == "International") echo " selected"; ?>>International</option>
                    </select></td>
            </tr>
            <tr>
                <td><b>Country *</b></td>
                <td><select name="DBPhysicalCountry" required>
                        <?php
                        if (!isset($Exist_PhysicalCountry) || empty($Exist_PhysicalCountry))
                            $Exist_PhysicalCountry = 'South Africa';
                        $sql = "SELECT PicklistValue FROM Picklists WHERE PicklistType='Country' ORDER BY DisplayOrder, PicklistValue";
                        $rec = mysqli_query($conni, $sql);
                        while ($row = mysqli_fetch_assoc($rec)) {
                        ?>
                            <option value="<?php echo $row["PicklistValue"]; ?>" <?php if ($Exist_PhysicalCountry == $row["PicklistValue"]) echo " selected"; ?>><?php echo $row["PicklistValue"]; ?></option>
                        <?php
                        }
                        ?>
                    </select>
                </td>
            </tr>

            <tr>
                <td colspan="2" bgcolor="#CCCCCC"><b>&nbsp;Person who is applying for verification on behalf of the organisation</b></td>
            </tr>
            <tr>
                <td width="30%"><b>Title *</b></td>
                <td><select name="DBContactTitle" id="Contact1_1" required>
                        <?php
                        $sql = "SELECT PicklistValue FROM Picklists WHERE PicklistType='Title' ORDER BY DisplayOrder, PicklistValue";
                        $rec = mysqli_query($conni, $sql);
                        while ($row = mysqli_fetch_assoc($rec)) {
                        ?>
                            <option value="<?php echo $row["PicklistValue"]; ?>" <?php if ($Exist_ContactTitle == $row["PicklistValue"]) echo " selected"; ?>><?php echo $row["PicklistValue"]; ?></option>
                        <?php
                        }
                        ?>
                    </select></td>
            </tr>
            <tr>
                <td><b>Initials</b></td>
                <td><input type="text" name="DBContactInitials" id="Contact1_2" value="<?php echo $Exist_ContactInitials; ?>" size="40"></td>
            </tr>
            <tr>
                <td><b>First Name (Known As) *</b></td>
                <td><input type="text" name="DBContactFirstName" id="Contact1_3" value="<?php echo $Exist_ContactFirstName; ?>" size="40" required></td>
            </tr>
            <tr>
                <td><b>Surname *</b></td>
                <td><input type="text" name="DBContactSurname" id="Contact1_4" value="<?php echo $Exist_ContactSurname; ?>" size="40" required></td>
            </tr>
            <tr>
                <td><b>Position Held</b></td>
                <td><input type="text" name="DBContactPosition" id="Contact1_5" value="<?php echo $Exist_ContactPosition; ?>" size="40"></td>
            </tr>
            <tr>
                <td><b>ID / Passport Number</b></td>
                <td><input type="text" name="DBContactIDNum" id="Contact1_6" value="<?php echo $Exist_ContactIDNum; ?>" size="40"></td>
            </tr>
            <tr>
                <td><b>Phone Number</b></td>
                <td><?php echo WritePhoneField("DBContactPhone", false); ?></td>
            </tr>
            <tr>
                <td><b>Cell Number *</b></td>
                <td><?php echo WritePhoneField("DBContactCell", true); ?></td>
            </tr>
            <tr>
                <td><b>Email Address *</b></td>
                <td><input type="text" name="DBContactEmail" id="Contact1_9" value="<?php echo $Exist_ContactEmail; ?>" size="40" required></td>
            </tr>

            <tr>
                <td colspan="2" bgcolor="#CCCCCC"><b>&nbsp;Person who is acting as the administrator on behalf of the organisation</b></td>
            </tr>
            <tr>
                <td colspan="2"><input type="checkbox" id="SameAs" value="1" onclick="if (this.checked)
                            CopyContact();"> Same as above</td>
            </tr>
            <tr>
                <td width="30%"><b>Title</b></td>
                <td><select name="DBAdminTitle" id="Contact2_1">
                        <?php
                        $sql = "SELECT PicklistValue FROM Picklists WHERE PicklistType='Title' ORDER BY DisplayOrder, PicklistValue";
                        $rec = mysqli_query($conni, $sql);
                        while ($row = mysqli_fetch_assoc($rec)) {
                        ?>
                            <option value="<?php echo $row["PicklistValue"]; ?>" <?php if ($Exist_AdminTitle == $row["PicklistValue"]) echo " selected"; ?>><?php echo $row["PicklistValue"]; ?></option>
                        <?php
                        }
                        ?>
                    </select></td>
            </tr>
            <tr>
                <td><b>Initials</b></td>
                <td><input type="text" name="DBAdminInitials" id="Contact2_2" value="<?php echo $Exist_AdminInitials; ?>" size="40"></td>
            </tr>
            <tr>
                <td><b>First Name (Known As) *</b></td>
                <td><input type="text" name="DBAdminFirstName" id="Contact2_3" value="<?php echo $Exist_AdminFirstName; ?>" size="40" required></td>
            </tr>
            <tr>
                <td><b>Surname *</b></td>
                <td><input type="text" name="DBAdminSurname" id="Contact2_4" value="<?php echo $Exist_AdminSurname; ?>" size="40" required></td>
            </tr>
            <tr>
                <td><b>Position Held</b></td>
                <td><input type="text" name="DBAdminPosition" id="Contact2_5" value="<?php echo $Exist_AdminPosition; ?>" size="40"></td>
            </tr>
            <tr>
                <td><b>ID / Passport Number</b></td>
                <td><input type="text" name="DBAdminIDNum" id="Contact2_6" value="<?php echo $Exist_AdminIDNum; ?>" size="40"></td>
            </tr>
            <tr>
                <td><b>Phone Number</b></td>
                <td><?php echo WritePhoneField("DBAdminPhone", false); ?></td>
            </tr>
            <tr>
                <td><b>Cell Number *</b></td>
                <td><?php echo WritePhoneField("DBAdminCell", true); ?></td>
            </tr>
            <tr>
                <td><b>Email Address *</b></td>
                <td><input type="text" name="DBAdminEmail" id="Contact2_9" value="<?php echo $Exist_AdminEmail; ?>" size="40" required></td>
            </tr>
        </table>
        <table border="1" width="100%" cellspacing="0" cellpadding="2" class="tpedittable">
            <tr>
                <td colspan="2" bgcolor="#CCCCCC"><b>&nbsp;Upload Documents</b><br>
                    The CPD Service/Training Provider is required to upload evidence of the following, related to your company, the administration and offering of CPD Activities.</td>
            </tr>
            <?php
            $sql = "SELECT DisplayOrder, PicklistValue, PicklistLabel FROM Picklists WHERE PicklistType='CPD Provider Documents' ORDER BY DisplayOrder, PicklistValue";
            $rec = mysqli_query($conni, $sql);
            $i = 0;
            $bShowBullet = false;
            while ($row = mysqli_fetch_assoc($rec)) {

                if ($row["PicklistLabel"] == 'Proof of Payment') {
                    continue;
                }

                $i++;
                if ($row["DisplayOrder"] == 80) {
                    echo '<tr><td valign="top" colspan="2"><b>Evidence of a comprehensive <a href="https://www.cesa.co.za/wp-content/uploads/2022/03/11-Quality-Management-System-Templates.pdf" target="_blank"><u>Quality Management System (QMS)</u></a>, which includes the following elements:</b></td></tr>';
                    $bShowBullet = true;
                }
                $sFileRequired = " *";
                if (($row["DisplayOrder"] == 40) || ($row["DisplayOrder"] == 70))
                    $sFileRequired = ""; // BBBEE certificate and Proof of Payment
            ?>
                <tr>
                    <td valign="top"><b><?php if ($bShowBullet) echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#x2022;&nbsp;"; ?><?php echo $row["PicklistLabel"]; ?><input type="hidden" name="FLName<?php echo $i; ?>" value="<?php echo $row["PicklistValue"]; ?>"><?php echo $sFileRequired; ?></b><?php
                                                                                                                                                                                                                                                                                                    if ($row["DisplayOrder"] == 50)
                                                                                                                                                                                                                                                                                                        echo "<br><i>Any valid documents reflecting your company's name and physical office address. i.e. Recent active lease or rental agreement, Municipal rates and taxes invoice</i>";
                                                                                                                                                                                                                                                                                                    ?></td>
                    <td valign="top">
                        <div id="filelist<?php echo $i; ?>">
                        </div>
                        <input id="FLFile<?php echo $i; ?>" type="hidden" name="FLFile<?php echo $i; ?>" value="">
                        <input id="fileupload<?php echo $i; ?>" type="file" data-url="/js/jQuery-File-Upload-10.32.0/server/php/">
                    </td>
                </tr>
            <?php
            }
            $iNumFiles = $i;
            ?>
            <tr>
                <td>
                    <b>Accountability Structure</b>
                </td>
                <td>
                    <input id="AccountabilityStructure" name="AccountabilityStructure" type="file" required />
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <p><input type="checkbox" name="Confirm1" value="1" required="required"> I confirm that I am an authorised representative of the above organisation, and authorised to hereby apply
                        on behalf of the organisation to be recognised as a ECSA CPD Verified Service Provider in terms of the Rules:
                        Continuing Professional Development and Renewal of Registration (Board notice 86 of 2017)
                        and Section 10 of the Standard for Continuing Professional Development (<a href="https://www.ecsa.co.za/ECSADocuments/Shared Documents/ECPD-01-STA Standard for Continuing Professional Development.pdf" target="_blank">ECPD-01-STA</a>).</p>
                    <p><input type="checkbox" name="Confirm2" value="1" required="required"> I confirm that the information and documentation supplied is, to the best of my knowledge, accurate and complete.</p>
                    </p>
                    <div class="g-recaptcha" data-sitekey="6LcoIWUrAAAAAKBLHpjS7GyroBey9G6yhilbpyNa"></div>

                    <input type="submit" value="Submit">
                </td>
            </tr>
        </table>
        <input type="hidden" name="NumFiles" value="<?php echo $iNumFiles; ?>">
    </form>
    <script>
        function CopyContact() {
            for (i = 1; i <= 9; i++) {
                jQuery('#Contact2_' + i).val(jQuery('#Contact1_' + i).val());
            }
        }

        function DeleteFile(sFilename, iIndex) {
            if (confirm('Are you sure you want to delete this file?')) {
                /*
                 $.ajax({
                 url: '/php/ajax_cpdprovdocs.php?type=del&filename='+sFilename
                 });
                 */
                jQuery('#uploadfile' + iIndex).remove();
                jQuery('#FLFile' + iIndex).val('');
                jQuery('#fileupload' + iIndex).show();
            }
        }

        <?php
        for ($i = 1; $i <= $iNumFiles; $i++) {
        ?>

            function ShowFileUploaded<?php echo $i; ?>(sFilename) {
                sDelete = '<button id="deletefile<?php echo $i; ?>" type="button" class="btn btn-sm btn-danger" onclick="DeleteFile(\'' + sFilename + '\', <?php echo $i; ?>)">Delete file</button>';
                jQuery("<div class='alert alert-success' id='uploadfile<?php echo $i; ?>'></div>").html('<p>Uploaded successfully: <b>' + sFilename + '</b>' + sDelete + '</p>').appendTo('#filelist<?php echo $i; ?>');
                jQuery('#fileupload<?php echo $i; ?>').hide();
                jQuery('#FLFile<?php echo $i; ?>').val(sFilename);

            }
        <?php
        }
        ?>

        jQuery(document).ready(function($) {

            $('input[name="DBRenewal"]').click(function() {
                if ($('#DBRenewal_1').is(':checked')) {
                    $('#DBPrevSPNumber').attr('required', 1);
                    $('#PrevSPNumberCertificate').attr('required', 1);
                } else {
                    $('#DBPrevSPNumber').removeAttr('required');
                    $('#PrevSPNumberCertificate').removeAttr('required');
                }
            });

            <?php
            for ($i = 1; $i <= $iNumFiles; $i++) {
            ?>

                $('#fileupload<?php echo $i; ?>').fileupload({
                    url: '/js/jQuery-File-Upload-10.32.0/server/php/',
                    dataType: 'json',
                    acceptFileTypes: /(\.|\/)(txt|pdf|doc|docx|xls|xlsx|csv|zip|jpg|png|bmp|tif|tiff|gif|ppt|pptx)$/i,
                    done: function(e, data) {
                        $.each(data.result.files, function(index, file) {
                            if (file.error) {
                                $("<div class='alert alert-danger'></div>").html('<p>' + file.error + ': <b>' + file.name + '</b></p>').appendTo('#filelist<?php echo $i; ?>');
                            } else {
                                ShowFileUploaded<?php echo $i; ?>(file.name);
                                /*
                                 $.ajax({
                                 url: '/php/ajax_cpdprovdocs.php?type=add&filename='+file.name
                                 });
                                 */
                            }
                        });
                    }
                });

                <?php
                $sFilename = filter_input(INPUT_POST, "FLFile" . $i, FILTER_SANITIZE_STRING);
                if (!empty($sFilename) && file_exists($sUploadDir . $sFilename)) {
                ?>
                    ShowFileUploaded<?php echo $i; ?>("<?php echo $sFilename; ?>");
            <?php
                }
            }
            ?>
        });
    </script>
<?php
}

if (isset($conni) && is_object($conni)) {
    mysqli_close($conni);
}