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/sched1page2gen.inc

<?php

// SECTION B ********************************************************
// ******************************************************************

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

if ($section == "B") {
    // SECTION B
    // Perform the INSERT of the data to the correct fields in the new tables
    // Set action to yes and complete the document.
    // Test first to see if the information exists.
    // **************************************************************************
    if (!($link = mysql_connect("$host", "$user", "$password"))) {
        throw new Exception("Unable to connect to SQL server");
    }
    if (!($result = mysql_select_db("$db"))) {
        throw new Exception("Unable to select database");
    }
    $query10 = "SELECT * FROM ADec_OfficeContacts WHERE Prev_OfficeID = '$SelectOfficeID' AND DeclarationYear = $DeclarationYear";
    if (!($result10 = mysql_query($query10))) {
        throw new Exception("Select of id Failed: " . $query10);
    }
    if (mysql_fetch_array($result10)) {
        $messages = "You have completed Section A. Please complete the fields and SUBMIT.";
    } else {
        $query5 = "SELECT ADec_tblMemberFirmOffices.OfficeID, ADec_tblMemberFirmOffices.Prev_OfficeID FROM ADec_tblMemberFirmOffices "
                . "WHERE ADec_tblMemberFirmOffices.Prev_OfficeID = '$SelectOfficeID' AND DeclarationYear = $DeclarationYear";
        if (!($result5 = mysql_query($query5))) {
            throw new Exception("Select of id Failed: " . $query5);
        }
        $rq = mysql_fetch_array($result5);
        $Qofficeid = $rq['OfficeID'];
        
        $query = "SELECT * FROM OfficeContacts WHERE OfficeContacts.OfficeID = '$SelectOfficeID'";
        if (!($result = mysql_query($query))) {
            throw new Exception("Select of id Failed: " . $query);
        }

        // write the content of the old records to the new records
        while ($rs = mysql_fetch_array($result)) {
            $Ctherightid = $rs[0];
            $Cposition = $rs[1];
            $Cprevid = $rs[4];
            $Cprincipal = $rs[5];
            // Get the relevant details to display  
            $query2 = "SELECT  * FROM Contacts WHERE Contacts.ContactsID = '$therightid'";
            if (!($result2 = mysql_query($query2))) {
                throw new Exception("Select of id Failed: " . $query2);
            }
            $ps = mysql_fetch_array($result2);
            $Cid = $ps[0];
            $Csurname = $ps[1];
            $Cinitial = $ps[2];
            $Cfirstname = $ps[3];
            $Cpreffreg = $ps[13];
            $Cqual = $ps[14];
            $Ccomments = $ps[12];
            $Cemail = $ps[16];
            
            $query4 = "INSERT INTO ADec_Contacts (Prev_ContactsID,
			 ContactSurname,
			 ContactInitials,
			 ContactFirstName,
			 ProfessionalRegistrations,
			 Qualifications,
			 Comments,
			 PreferredEmail, DeclarationYear)
			 values('$Cid',
			 '$Csurname',
			 '$Cinitial',
			 '$Cfirstname',
			 '$Cpreffreg',
			 '$Cqual',
			 '$Ccomments',
			 '$Cemail', $DeclarationYear)";
            if (!($result4 = mysql_query($query4))) {
                throw new Exception("Insert Failed into ADec_Contacts in sched1page2gen.inc: " . $query4);
            }
            $query6 = "SELECT  * FROM ADec_Contacts WHERE ADec_Contacts.Prev_ContactsID = '$Cid' AND DeclarationYear = $DeclarationYear";
            if (!($result6 = mysql_query($query6))) {
                throw new Exception("Select of id Failed: " . $query6);
            }
            $ts = mysql_fetch_array($result6);
            $newidthingy = $ts[0];
            $query3 = "INSERT INTO ADec_OfficeContacts (ContactsID,
			 Prev_ContactsID,
			 ContactPosition,
			 OfficeID,
			 Prev_OfficeId, DeclarationYear)
			 values('$newidthingy',
			 '$Ctherightid',
			 '$Cposition',
			 '$Qofficeid',
			 '$Cprevid', $DeclarationYear)";
            if (!($result3 = mysql_query($query3))) {
                throw new Exception("Insert Failed into ADec_OfficeContacts in sched1page2gen.inc: " . $query3);
            }
        }
    }
    // *************************** END **********************************
    // ******************************************************************
    // SECTION  D ********************************************************
    // ******************************************************************
    if ($section == "D") {
        $messages = "You have completed the document. Please close the window and return to the Controll Page. ";
        $showbutton = "no";
        
        $query9 = "UPDATE ADec_tblMemberFirmOffices SET ProfessionalStaff = '$form[proff]', NonProfTechStaff = '$form[nonprof]', OtherStaff = '$form[other]', DeclarationYear = $DeclarationYear "
                . "WHERE OfficeID = '$Qofficeid'";
        if (!($result = mysql_query($query9))) {
            throw new Exception("Select of id Failed: " . $query9);
        }
    }
    // *************************** END **********************************
    // ******************************************************************
    // SECTION E ********************************************************
    // ******************************************************************
    if ($section == "E") {
        $query = "SELECT * FROM OfficeContacts WHERE OfficeContacts.OfficeID = '$SelectOfficeID'";
        if (!($result = mysql_query($query))) {
            throw new Exception("Select of id Failed: " . $query);
        }
        $rs = mysql_fetch_array($result);
        $therightid = $rs[0];
        if ($rs[5] == 0) {
            $selected1 = "selected";
            $selected2 = "";
        } else {
            $selected1 = "";
            $selected2 = "selected";
        }
        
        $query2 = "SELECT  * FROM Contacts WHERE Contacts.ContactsID = '$therightid'";
        if (!($result2 = mysql_query($query2))) {
            throw new Exception("Select of id Failed: " . $query2);
        }
        $ps = mysql_fetch_array($result2);
        $messages = "Please edit the fields you want to change and SUBMIT.";
    }
    // *************************** END **********************************
    // ******************************************************************
    // SECTION X ********************************************************
    // ******************************************************************
    if ($section == "X") {
        // UPDATE Office Contacts.
        if ($form[principal] == "No") {
            $Oprincipal = 0;
        } else {
            $Oprincipal = 1;
        }
        $query = "UPDATE OfficeContacts SET ContactPosition = '$form[pos]',
			Principal = '$Oprincipal' WHERE OfficeContacts.ContactsID = '$therightid'";
        if (!($result = mysql_query($query))) {
            throw new Exception("Update OfficeContacts in sched1page2gen.inc: " . $query);
        }

        // UPDATE Contacts.
        
        $query2 = "UPDATE Contacts SET Contacts.ContactSurname = '$form[surname]',
			Contacts.ContactInitials = '$form[initials]',
			Contacts.ContactFirstName = '$form[alsoknown]',
			Contacts.ProfessionalRegistrations = '$form[proffreg]',
			Contacts.Qualifications = '$form[qual]',
			Contacts.Comments = '$form[fields]', Contacts.PreferredEmail = '$form[email]'
			WHERE Contacts.ContactsID = '$therightid'";
        if (!($result2 = mysql_query($query2))) {
            throw new Exception("Update Contacts in sched1page2gen.inc: " . $query2);
        }
        $section = "A";
    }
    // *************************** END **********************************
    // ******************************************************************