<?php

  //================================================================================================

  class ContactSql extends MySQL {

    public $sectionFilter_sqlSelectColumns;
    public $sectionTable_sqlSelectColumns;
    public $sectionRecord_sqlSelect;

    public $sectionTableName;
    public $sectionTablePrimaryKey;

    //================================================================================================
    // Function Constructor()
    //================================================================================================

    public function __construct() {
      
      $this->set_sectionFilter_sqlSelectColumns();
      
      $this->set_sectionTable_sqlSelectColumns();

      $this->sectionRecord_sqlSelect = '';

      $this->sectionTableName = 'dbo_tblContact';
      $this->sectionTablePrimaryKey = 'contactId';

      // Create the parent MySQL object
			parent :: __construct();
    }

    //================================================================================================
    // Function set_sectionFilter_sqlSelectColumns()
    //================================================================================================

    private function set_sectionFilter_sqlSelectColumns() {

      $this->sectionFilter_sqlSelectColumns = <<<EOD
        SELECT
          contactId AS itemId
        FROM dbo_tblContact
      EOD;
      
    }

    //================================================================================================
    // Function set_sectionTable_sqlSelectColumns()
    //================================================================================================

    private function set_sectionTable_sqlSelectColumns() {

      $this->sectionTable_sqlSelectColumns = <<<EOD
        SELECT
          tblC.contactId, tblC.contactFirstName, tblC.contactLastName, tblC.contactHomePhone, tblC.contactMobilePhone, tblC.contactEmailAddress

        FROM dbo_tblContact AS tblC
        
        INNER JOIN dbo_tblContactAddressLink AS tblCAL ON tblCAL.cal_contactId = tblC.contactId
        INNER JOIN dbo_tblContactAddress AS tblCA ON tblCA.addressId = tblCAL.cal_addressId
      EOD;

    }
    
    //================================================================================================
    // Function set_sectionRecord_sqlSelect()
    //================================================================================================

    public function set_sectionRecord_sqlSelect($contactId) {

      $sectionRecordSqlSelect = <<<EOD
        SELECT
          tblC.contactId, tblC.contactTitle, tblC.contactFirstName, tblC.contactLastName, tblC.contactOrganisation, tblC.contactMobilePhone, tblC.contactHomePhone, tblC.contactWorkPhone, tblC.contactEmailAddress, tblC.contactWebAddress
        FROM dbo_tblContact AS tblC
        WHERE tblC.contactId = %d
      EOD;

      $this->sectionRecord_sqlSelect = sprintf($sectionRecordSqlSelect, $contactId);
    }

    //================================================================================================

  }

  //================================================================================================

?>