Your IP : 216.73.217.79


Current Path : /var/www/cesa.co.za/members/inc/
Upload File :
Current File : /var/www/cesa.co.za/members/inc/submitcheck.inc

<?php

// **** All the variables for the reading of the information of the Annual Declaration
include_once($_SERVER['DOCUMENT_ROOT'] . '/cfg/config.php');

$host = EW_CONN_HOST;
$user = EW_CONN_USER;
$password = EW_CONN_PASS;
$db = EW_CONN_DB;

if (!mysql_connect("$host", "$user", "$password")) {
    throw new Exception("Unable to connect to SQL server");
}
if (!mysql_select_db("$db")) {
    throw new Exception("Unable to select database");
}

include( '../inc/conf.inc' );

// **** Check the fields to see if they were completed correctly

if (!isset($form) && isset($_REQUEST["action"]))
    extract($_REQUEST);

if (empty($_REQUEST["form[firmname]"])) {
    $errorcondition = "no";
} else {
    $errorcondition = "yes";
    $ErrorReport = "<font color = red>ERROR !!! : </font> Please complete the field <b>FIRM NAME</b>.";
}
if ($errorcondition == "no") {
    if ($form['name']) {
        $errorcondition = "no";
    } else {
        $errorcondition = "yes";
        $ErrorReport = "<font color = red>ERROR !!! : </font> Please complete the field <b>NAME OF INSURER</b>.";
    }
}
if ($errorcondition == "no") {
    if ($form['amount'] != '' || $form['LevelOfCoverShort'] != '') {
        $errorcondition = "no";
    } else {
        $errorcondition = "yes";
        $ErrorReport = "<font color = red>ERROR !!! : </font> Please complete the field <b>AMOUNT OF COVER</b>.";
    }
}
$boxselected = 0;
if ($box[1]) {
    $boxselected = $boxselected + 1;
}
if ($box[2]) {
    $boxselected = $boxselected + 1;
}
if ($box[3]) {
    $boxselected = $boxselected + 1;
}
if ($box[4]) {
    $boxselected = $boxselected + 1;
}
if ($box[5]) {
    $boxselected = $boxselected + 1;
}
if ($box[6]) {
    $boxselected = $boxselected + 1;
}

if ($errorcondition == "no") {
    if ($boxselected > 1) {
        $errorcondition = "yes";
        $ErrorReport = "<font color = red>ERROR !!! : </font> Please select only <b>ONE</b> form of the Member Firm.";
    } else {
        $errorcondition = "no";
    }
}
if ($errorcondition == "no") {
    if ($boxselected == 0) {
        $errorcondition = "yes";
        $ErrorReport = "<font color = red>ERROR !!! : </font> Please select at least <b>ONE</b> form of the Member Firm.";
    } else {
        $errorcondition = "no";
    }
}
/*
  if ($errorcondition == "no")
  {
  if ($form[q3])
  { $errorcondition = "no"; }
  else
  {
  $errorcondition = "yes";
  $ErrorReport = "<font color = red>ERROR !!! : </font> Please complete the field <b>Quality Management System Question 1</b>.";
  }
  }
  if ($errorcondition == "no")
  {
  if ($form[q4])
  { $errorcondition = "no"; }
  else
  {
  $errorcondition = "yes";
  $ErrorReport = "<font color = red>ERROR !!! : </font> Please complete the field <b>Quality Management System Question 2(a)</b>.";
  }
  }
 */
if ($errorcondition == "no") {
    if ($form['firstname']) {
        $errorcondition = "no";
    } else {
        $errorcondition = "yes";
        $ErrorReport = "<font color = red>ERROR !!! : </font> Please complete the field <b>FIRST NAME OF MANDATED PRINCIPAL</b>.";
    }
}
if ($errorcondition == "no") {
    if ($form['lastname']) {
        $errorcondition = "no";
    } else {
        $errorcondition = "Yes";
        $ErrorReport = "<font color = red>ERROR !!! : </font> Please complete the field <b>LAST NAME OF MANDATED PRINCIPAL</b>.";
    }
}
if ($errorcondition == "no") {
    if ($form['date']) {
        if (strtotime($form['date']) != -1) {
            $errorcondition = "no";
        } else {
            $errorcondition = "yes";
            $ErrorReport = "<font color = red>ERROR !!! : </font> Please provide a valid date for: <b>DATE DOCUMENT COMPLETED</b>.";
        }
    } else {
        $errorcondition = "yes";
        $ErrorReport = "<font color = red>ERROR !!! : </font> Please complete the field <b>DATE DOCUMENT COMPLETED</b>.";
    }
}
if ($errorcondition == "no") {
    if (!empty($form['BBBEE'])) {
        $errorcondition = "no";
    } else {
        $errorcondition = "yes";
        $ErrorReport = "<font color = red>ERROR !!! : </font> Please complete the field <b>BBBEE Level</b>.";
    }
}
//if ($errorcondition == "no") {
//    if (!empty($form['SMME'])) {
//        $errorcondition = "no";
//    } else {
//        $errorcondition = "yes";
//        $ErrorReport = "<font color = red>ERROR !!! : </font> Please complete the field <b>BBBEE Revenue</b>.";
//    }
//}
if ($errorcondition == "no") {
    if (!empty($form['BlackOwned'])) {
        $errorcondition = "no";
    } else {
        $errorcondition = "yes";
        $ErrorReport = "<font color = red>ERROR !!! : </font> Please complete the field <b>BBBEE Ownership</b>.";
    }
}

if ($errorcondition == "no") {
    if (!empty($form['BlackWomenOwned'])) {
        $errorcondition = "no";
    } else {
        $errorcondition = "yes";
        $ErrorReport = "<font color = red>ERROR !!! : </font> Please complete the field <b>Black Women Ownership</b>.";
    }
}

if ($errorcondition == "no") {
    if (!empty($form['WomenOwned'])) {
        $errorcondition = "no";
    } else {
        $errorcondition = "yes";
        $ErrorReport = "<font color = red>ERROR !!! : </font> Please complete the field <b>Women Ownership</b>.";
    }
}

if ($errorcondition == "no") {
    if (empty($_POST["TotalStaff"]) || !is_numeric($_POST["TotalStaff"])) {
        $errorcondition = "yes";
        $ErrorReport = "<font color = red>ERROR !!! : </font> Please complete the field <b>Total Staff</b> with an integer number only.";
    }
}

if ($errorcondition == "no") {
    if (!is_numeric($_POST["ImmigratedStaff"])) {
        $errorcondition = "yes";
        $ErrorReport = "<font color = red>ERROR !!! : </font> Please complete the field <b>Immigrated Staff</b> with an integer number only.";
    }
}

if ($errorcondition == "no") {
    $iTotalStaff = intval($_REQUEST["TotalStaff"]);

    $iTotalStaffB = intval($form['TransTopMA']) + intval($form['TransTopMC']) + intval($form['TransTopMI']) + intval($form['TransTopMW']);
    $iTotalStaffB += intval($form['TransTopFA']) + intval($form['TransTopFC']) + intval($form['TransTopFI']) + intval($form['TransTopFW']);
    $iTotalStaffB += intval($form['TransTopMN']) + intval($form['TransTopFN']);
    $iTotalStaffB += intval($form['TransSeniorMA']) + intval($form['TransSeniorMC']) + intval($form['TransSeniorMI']) + intval($form['TransSeniorMW']);
    $iTotalStaffB += intval($form['TransSeniorFA']) + intval($form['TransSeniorFC']) + intval($form['TransSeniorFI']) + intval($form['TransSeniorFW']);
    $iTotalStaffB += intval($form['TransSeniorMN']) + intval($form['TransSeniorFN']);
    $iTotalStaffB += intval($form['TransProfMA']) + intval($form['TransProfMC']) + intval($form['TransProfMI']) + intval($form['TransProfMW']);
    $iTotalStaffB += intval($form['TransProfFA']) + intval($form['TransProfFC']) + intval($form['TransProfFI']) + intval($form['TransProfFW']);
    $iTotalStaffB += intval($form['TransProfMN']) + intval($form['TransProfFN']);
    $iTotalStaffB += intval($form['TransSkilledMA']) + intval($form['TransSkilledMC']) + intval($form['TransSkilledMI']) + intval($form['TransSkilledMW']);
    $iTotalStaffB += intval($form['TransSkilledFA']) + intval($form['TransSkilledFC']) + intval($form['TransSkilledFI']) + intval($form['TransSkilledFW']);
    $iTotalStaffB += intval($form['TransSkilledMN']) + intval($form['TransSkilledFN']);
    $iTotalStaffB += intval($form['TransSemiMA']) + intval($form['TransSemiMC']) + intval($form['TransSemiMI']) + intval($form['TransSemiMW']);
    $iTotalStaffB += intval($form['TransSemiFA']) + intval($form['TransSemiFC']) + intval($form['TransSemiFI']) + intval($form['TransSemiFW']);
    $iTotalStaffB += intval($form['TransSemiMN']) + intval($form['TransSemiFN']);
    $iTotalStaffB += intval($form['TransUnskillMA']) + intval($form['TransUnskillMC']) + intval($form['TransUnskillMI']) + intval($form['TransUnskillMW']);
    $iTotalStaffB += intval($form['TransUnskillFA']) + intval($form['TransUnskillFC']) + intval($form['TransUnskillFI']) + intval($form['TransUnskillFW']);
    $iTotalStaffB += intval($form['TransUnskillMN']) + intval($form['TransUnskillFN']);
    $iTotalStaffB += intval($form['TransTempMA']) + intval($form['TransTempMC']) + intval($form['TransTempMI']) + intval($form['TransTempMW']);
    $iTotalStaffB += intval($form['TransTempFA']) + intval($form['TransTempFC']) + intval($form['TransTempFI']) + intval($form['TransTempFW']);
    $iTotalStaffB += intval($form['TransTempMN']) + intval($form['TransTempFN']);

    if ($iTotalStaff != $iTotalStaffB) {
        $errorcondition = "yes";
        $ErrorReport = "<font color = red>ERROR !!! : </font> The total number of staff entered in the 'STAFFING TRANSFORMATION STATUS DECLARATION' (" . $iTotalStaffB . ") does not correspond to the total number of staff in your firm (" . $iTotalStaff . ").";
    }
}
// **** Set the values to put in the type of incorporation field
if ($box[1]) {
    $form['incorp'] = "Sole Practice";
}
if ($box[2]) {
    $form['incorp'] = "Limited Company";
}
if ($box[3]) {
    $form['incorp'] = "Partnership";
}
if ($box[4]) {
    $form['incorp'] = "(Pty) Ltd";
}
if ($box[5]) {
    $form['incorp'] = "Close Corporation";
}
if ($box[6]) {
    $form['incorp'] = $form['other'];
}
if ($errorcondition == "no") {
// Update the MemberFirms table
    if ($form['partydate'] . "" > "") {
        $QMSISOCertDate = date('Y-m-d', strtotime($form['partydate']));
    } else {
        $QMSISOCertDate = "";
    }
    $DeclarationReceived = date('Y-m-d', strtotime($form['date']));

    $levelofcover = $form['amount'];
    if (!empty($levelofcover))
        $levelofcover = preg_replace("[^0-9]", "", $levelofcover);

    if ($form['amount'] >= 200000000) {
        $levelOfCoverShort = '>=R200m';
    } elseif ($form['amount'] >= 100000000) {
        $levelOfCoverShort = '>=R100m<R200m';
    } elseif ($form['amount'] >= 50000000) {
        $levelOfCoverShort = '>=R50m<R100m';
    } elseif ($form['amount'] >= 25000000) {
        $levelOfCoverShort = '>=R25m<R50m';
    } elseif ($form['amount'] >= 10000000) {
        $levelOfCoverShort = '>=R10m<R25m';
    } elseif ($form['amount'] >= 5000000) {
        $levelOfCoverShort = '>=R5m<R10m';
    } elseif ($form['amount'] >= 2000000) {
        $levelOfCoverShort = '>=R2m<R5m';
    } else {
//        $levelOfCoverShort = $form['LevelOfCoverShort'];
        $levelOfCoverShort = '<R2m';
    }

    if ($form['SMME'] >= 100000000) {
        $smmeShort = 'GEN8 >= R100 million';
    } elseif ($form['SMME'] < 100000000 && $form['SMME'] >= 90000000) {
        $smmeShort = 'GEN7 >= R90 million < R100 million';
    } elseif ($form['SMME'] < 90000000 && $form['SMME'] >= 80000000) {
        $smmeShort = 'GEN7 >= R80 million < R90 million';
    } elseif ($form['SMME'] < 80000000 && $form['SMME'] >= 70000000) {
        $smmeShort = 'GEN7 >= R70 million < R80 million';
    } elseif ($form['SMME'] < 70000000 && $form['SMME'] >= 60000000) {
        $smmeShort = 'GEN7 >= R60 million < R70 million';
    } elseif ($form['SMME'] < 60000000 && $form['SMME'] >= 50000000) {
        $smmeShort = 'GEN7 >= R50 million < R60 million';
    } elseif ($form['SMME'] < 50000000 && $form['SMME'] >= 35000000) {
        $smmeShort = 'GEN7 >= R35 million < R50 million';
    } elseif ($form['SMME'] < 35000000 && $form['SMME'] >= 25000000) {
        $smmeShort = 'GEN7 >= R25 million < R35 million';
    } elseif ($form['SMME'] < 25000000 && $form['SMME'] >= 20000000) {
        $smmeShort = 'GEN7 >= R20 million < R25 million';
    } elseif ($form['SMME'] < 20000000 && $form['SMME'] >= 15000000) {
        $smmeShort = 'GEN7 >= R15 million < R20 million';
    } elseif ($form['SMME'] < 15000000 && $form['SMME'] >= 10000000) {
        $smmeShort = 'GEN7 >= R10 million < R15 million';
    } elseif ($form['SMME'] < 10000000 && $form['SMME'] >= 6000000) {
        $smmeShort = 'GEN7 >= R6 million < R10 million';
    } elseif ($form['SMME'] < 6000000 && $form['SMME'] >= 3000000) {
        $smmeShort = 'GEN7 >= R3 million < R6 million';
    } else {
        $smmeShort = 'EME1 < R3 million';
    }

    $MentoringProg = "n";
    if (isset($form['MentoringProg']) && ($form['MentoringProg'] == "y"))
        $MentoringProg = "y";

    $CandidateProg = "n";
    if (isset($form['CandidateProg']) && ($form['CandidateProg'] == "y"))
        $CandidateProg = "y";

    $query = "UPDATE ADec_tblMemberFirms SET FirmName = '" . addslashes($form['firmname']) . "', FormOfIncorporation = '" . $form['incorp'] . "', PIUnderwriter = '" . addslashes($form['name']) . "', LevelOfCover = '$levelofcover', LevelOfCoverShort = '$levelOfCoverShort', "
            . "URL='" . $form['www'] . "', QMSISOComply='" . $form['q3'] . "', QMSISOCert='" . $form['q4'] . "', QMSCertBody='" . addslashes($form['q7']) . "', DeclarationReceived = '$DeclarationReceived', MentoringProg='$MentoringProg', CandidateProg='$CandidateProg', "
            . "CaUSigned='" . $form['CaUSigned'] . "', BBBEE='" . $form['BBBEE'] . "', SMMEAmount='" . $form['ThreeYearsAverageTurnover'] . "', SMME='" . $smmeShort . "', BlackOwned='" . addslashes($form['BlackOwned']) . "', "
            . "WomenOwned='" . addslashes($form['WomenOwned']) . "', BlackWomenOwned='" . addslashes($form['BlackWomenOwned']) . "', YPFContact='" . addslashes($form['YPFContact']) . "', "
            . "YPFEmail='" . $form['YPFEmail'] . "', SubscriptionsContact='" . addslashes($form['SubscriptionsContact']) . "', SubscriptionsEmail='" . $form['SubscriptionsEmail'] . "', HRTrainingContact='" . addslashes($form['HRTrainingContact']) . "', "
            . "HRTrainingEmail='" . $form['HRTrainingEmail'] . "', MarketingContact='" . addslashes($form['MarketingContact']) . "', MarketingEmail='" . $form['MarketingEmail'] . "', GoToPersonName = '" . addslashes($form['GoToPersonName']) . "', "
            . "GoToPersonTel = '" . addslashes($form['GoToPersonTel']) . "', GoToPersonEmail = '" . addslashes($form['GoToPersonEmail']) . "', SustainabilityPolicy='" . $form['SustainabilityPolicy'] . "', SustainabilityIssues='" . $form['SustainabilityIssues'] . "', "
            . "SustainabilityProcess='" . $form['SustainabilityProcess'] . "', QMIG='" . addslashes($form['qQMIG']) . "', QMSChampName='" . addslashes($form['qQChampName']) . "', QMSChampEmail='" . addslashes($form['qQChampEmail']) . "', "
            . "SustainabilityChampion='" . addslashes($form['SustainabilityChampion']) . "', SustainabilityChampName='" . addslashes($form['qSChampName']) . "', SustainabilityChampEmail='" . addslashes($form['qSChampEmail']) . "', "
            . "ProcurementContact='" . addslashes($form['ProcurementContact']) . "', ProcurementEmail='" . addslashes($form['ProcurementEmail']) . "', "
            . "SubscriptionsTel='" . addslashes($form['SubscriptionsTel']) . "', HRTrainingTel='" . addslashes($form['HRTrainingTel']) . "', MarketingTel='" . addslashes($form['MarketingTel']) . "', ProcurementTel='" . addslashes($form['ProcurementTel']) . "', "
            . "YPFContactTel='" . addslashes($form['YPFContactTel']) . "', SABTACO='" . $_REQUEST["SABTACO"] . "', BBCBE='" . $_REQUEST["BBCBE"] . "', GBCSA='" . $_REQUEST["GBCSA"] . "', "
            . "TotalStaff='" . intval($_REQUEST["TotalStaff"]) . "', "
            . "ImmigratedStaff='" . intval($_REQUEST["ImmigratedStaff"]) . "' "
            . "WHERE Prev_FirmID='$MemberFirmID' AND DeclarationYear = $DeclarationYear";

    if (false && $_SESSION["username"] == 'cesatesting') {
        // echo '<p>Please ignore debug info: <textarea>' . $query . '</textarea></p>';
        // exit;
    }

    if (!($result = mysql_query($query))) {
        ErrorLog::logInfo(
            "Update of ADec_tblMemberFirms Failed! Please forward the following debug info to gillian@cesa.co.za: " 
            . $query . ' MySQL Error: ' . mysql_error(get_current_connection())
        );
        maill('cesa@igotafrica.com', 'Error on AD update', "Update of ADec_tblMemberFirms Failed: " 
            . $query . ' MySQL Error: ' . mysql_error(get_current_connection()));
        echo '<h3>An error occured. The error has been reported.</h3>';
        exit;
    }

    $aDecTransformationObj = new ADec_Transformation($sqlf);
    $aDecTransformation = $aDecTransformationObj->getOrCreate($MemberFirmID, $DeclarationYear);

    $query = "UPDATE ADec_Transformation SET `TransTopMA` = " . intval($form['TransTopMA']) . ",  `TransTopMC` = " . intval($form['TransTopMC']) . ",  `TransTopMI` = " . intval($form['TransTopMI']) . ",
  `TransTopMW` = " . intval($form['TransTopMW']) . ",  `TransTopFA` = " . intval($form['TransTopFA']) . ",  `TransTopFC` = " . intval($form['TransTopFC']) . ",  `TransTopFI` = " . intval($form['TransTopFI']) . ",
  `TransTopFW` = " . intval($form['TransTopFW']) . ",  `TransTopMN` = " . intval($form['TransTopMN']) . ",  `TransTopFN` = " . intval($form['TransTopFN']) . ",  `TransSeniorMA` = " . intval($form['TransSeniorMA']) . ",
  `TransSeniorMC` = " . intval($form['TransSeniorMC']) . ",  `TransSeniorMI` = " . intval($form['TransSeniorMI']) . ",  `TransSeniorMW` = " . intval($form['TransSeniorMW']) . ",  `TransSeniorFA` = " . intval($form['TransSeniorFA']) . ",
  `TransSeniorFC` = " . intval($form['TransSeniorFC']) . ",  `TransSeniorFI` = " . intval($form['TransSeniorFI']) . ",  `TransSeniorFW` = " . intval($form['TransSeniorFW']) . ",  `TransSeniorMN` = " . intval($form['TransSeniorMN']) . ",
  `TransSeniorFN` = " . intval($form['TransSeniorFN']) . ",  `TransProfMA` = " . intval($form['TransProfMA']) . ",  `TransProfMC` = " . intval($form['TransProfMC']) . ",  `TransProfMI` = " . intval($form['TransProfMI']) . ",
  `TransProfMW` = " . intval($form['TransProfMW']) . ",  `TransProfFA` = " . intval($form['TransProfFA']) . ",  `TransProfFC` = " . intval($form['TransProfFC']) . ",  `TransProfFI` = " . intval($form['TransProfFI']) . ",
  `TransProfFW` = " . intval($form['TransProfFW']) . ",  `TransProfMN` = " . intval($form['TransProfMN']) . ",  `TransProfFN` = " . intval($form['TransProfFN']) . ",  `TransSkilledMA` = " . intval($form['TransSkilledMA']) . ",
  `TransSkilledMC` = " . intval($form['TransSkilledMC']) . ",  `TransSkilledMI` = " . intval($form['TransSkilledMI']) . ",  `TransSkilledMW` = " . intval($form['TransSkilledMW']) . ",  `TransSkilledFA` = " . intval($form['TransSkilledFA']) . ",  `TransSkilledFC` = " . intval($form['TransSkilledFC']) . ",  `TransSkilledFI` = " . intval($form['TransSkilledFI']) . ",  `TransSkilledFW` = " . intval($form['TransSkilledFW']) . ",
  `TransSkilledMN` = " . intval($form['TransSkilledMN']) . ",  `TransSkilledFN` = " . intval($form['TransSkilledFN']) . ",  `TransSemiMA` = " . intval($form['TransSemiMA']) . ",  `TransSemiMC` = " . intval($form['TransSemiMC']) . ",
  `TransSemiMI` = " . intval($form['TransSemiMI']) . ",  `TransSemiMW` = " . intval($form['TransSemiMW']) . ",  `TransSemiFA` = " . intval($form['TransSemiFA']) . ",  `TransSemiFC` = " . intval($form['TransSemiFC']) . ",
  `TransSemiFI` = " . intval($form['TransSemiFI']) . ",  `TransSemiFW` = " . intval($form['TransSemiFW']) . ",  `TransSemiMN` = " . intval($form['TransSemiMN']) . ",  `TransSemiFN` = " . intval($form['TransSemiFN']) . ",
  `TransUnskillMA` = " . intval($form['TransUnskillMA']) . ",  `TransUnskillMC` = " . intval($form['TransUnskillMC']) . ",  `TransUnskillMI` = " . intval($form['TransUnskillMI']) . ",  `TransUnskillMW` = " . intval($form['TransUnskillMW']) . ",  `TransUnskillFA` = " . intval($form['TransUnskillFA']) . ",  `TransUnskillFC` = " . intval($form['TransUnskillFC']) . ",  `TransUnskillFI` = " . intval($form['TransUnskillFI']) . ",
  `TransUnskillFW` = " . intval($form['TransUnskillFW']) . ",  `TransUnskillMN` = " . intval($form['TransUnskillMN']) . ",  `TransUnskillFN` = " . intval($form['TransUnskillFN']) . ",  `TransTempMA` = " . intval($form['TransTempMA']) . ",
  `TransTempMC` = " . intval($form['TransTempMC']) . ",  `TransTempMI` = " . intval($form['TransTempMI']) . ",  `TransTempMW` = " . intval($form['TransTempMW']) . ",  `TransTempFA` = " . intval($form['TransTempFA']) . ",
  `TransTempFC` = " . intval($form['TransTempFC']) . ",  `TransTempFI` = " . intval($form['TransTempFI']) . ",  `TransTempFW` = " . intval($form['TransTempFW']) . ",  `TransTempMN` = " . intval($form['TransTempMN']) . ",
  `TransTempFN` = " . intval($form['TransTempFN']) . ", `ThreeYearsAverageTurnover` = " . floatval($form['ThreeYearsAverageTurnover']) . " ,"
            . " `FirmID` = (SELECT FirmID FROM ADec_tblMemberFirms WHERE Prev_FirmID = " . floatval($MemberFirmID) . " AND DeclarationYear = $DeclarationYear) "
            . "WHERE Prev_FirmID='$MemberFirmID' AND DeclarationYear = $DeclarationYear";
    if (!($result = mysql_query($query))) {
        throw new Exception("Query failed in submitcheck.inc: " . $query);
    }

    $query = "REPLACE INTO QualitySurvey (FirmID, OverallService, OverallServiceSuggestion, PersonnelService, PersonnelServiceSuggestion, FocusNeeds, NeedsService, AwareBenefits,
        QualitySuggestions, BenefitsPublicSector, BenefitsVoice, BenefitsTrends, BenefitsRecognition, BenefitsNetworking, BenefitsTraining, DeclarationYear)
VALUES (" . $MemberFirmID . ", '" . $_REQUEST["OverallService"] . "', '" . $_REQUEST["OverallServiceSuggestion"] . "', '" . $_REQUEST["PersonnelService"] . "', '" . $_REQUEST["PersonnelServiceSuggestion"] . "', '" . $_REQUEST["FocusNeeds"] . "',
'" . $_REQUEST["NeedsService"] . "', '" . $_REQUEST["AwareBenefits"] . "', '" . addslashes($_REQUEST["QualitySuggestions"]) . "',
'" . $_REQUEST["BenefitsPublicSector"] . "', '" . $_REQUEST["BenefitsVoice"] . "', '" . $_REQUEST["BenefitsTrends"] . "', '" . $_REQUEST["BenefitsRecognition"] . "',
'" . $_REQUEST["BenefitsNetworking"] . "', '" . $_REQUEST["BenefitsTraining"] . "', $DeclarationYear)";
    if (!($result = mysql_query($query))) {
        throw new Exception("Query failed in submitcheck.inc: " . $query);
    }

    for ($iEvent = 1; $iEvent <= 20; $iEvent++) {
        if (isset($_REQUEST["Event" . $iEvent])) {
            $query = "INSERT INTO QualitySurveyEvents (QSID, EventName, Participation, Rating, DeclarationYear)
		SELECT MAX(QSID), '" . addslashes($_REQUEST["Event" . $iEvent]) . "', '" . $_REQUEST["Event" . $iEvent . "_Participation"] . "', '" . $_REQUEST["Event" . $iEvent . "_Rating"] . "',
                    $DeclarationYear
		FROM QualitySurvey WHERE FirmID=" . $MemberFirmID . " AND DeclarationYear = $DeclarationYear";
            if (!($result = mysql_query($query))) {
                throw new Exception("Query failed in submitcheck.inc: " . $query);
            }
        }
    } //for
// Update the Mandated Principal
    $query = "UPDATE ADec_Contacts 
        SET ContactSurname = '" . addslashes($form['lastname']) . "', 
            ContactFirstName = '" . addslashes($form['firstname']) . "', 
            ContactDesignation = '" . addslashes($form['designate']) . "' 
        WHERE Prev_ContactsID = '$MemberContactID' AND DeclarationYear = $DeclarationYear";
    
    if (!($result = mysql_query($query))) {
        throw new Exception("Update ADec_Contacts query failed in submitcheck.inc: " . $query);
    }

    $query101 = "UPDATE ADec_tblMemberFirms 
        SET ADecStatus='U' WHERE Prev_FirmID = '$MemberFirmID' AND DeclarationYear = $DeclarationYear";
    
    if (!($Hresult = mysql_query($query101))) {
        throw new Exception("Update ADec_tblMemberFirms query failed in submitcheck.inc: " . $query101);
    }

    $query = "SELECT  FirmID, Prev_FirmID FROM ADec_tblMemberFirms WHERE Prev_FirmID = '$MemberFirmID' AND DeclarationYear = $DeclarationYear";
    if (!($Hresult = mysql_query($query))) {
        throw new Exception("Select ADec_tblMemberFirms query failed in submitcheck.inc: " . $query);
    }
    $Hrow = mysql_fetch_array($Hresult);
    $Hf[1] = $Hrow['FirmID'];
    $reftype = "FirmID";
    $refdoc = "AnnualDeclaration";
    $adecdate = date("Y-m-d H:i");
    $query = "INSERT INTO ADec_Done (RefID,RefType,RefDoc,ADecDate, DeclarationYear)
values('$Hf[1]','$reftype','$refdoc','$adecdate', $DeclarationYear)";
    if (!($Jresult = mysql_query($query))) {
        throw new Exception("Insert ADec_Done query failed in submitcheck.inc: " . $query);
    }

    $NextSection = "complete";
} else {
    $NextSection = "notcomplete";
}