<?php

  //================================================================================================
  
  require("../contact/contactSql.inc");

  class ContactSection extends Section {

    //================================================================================================
    // Function Constructor()
    //================================================================================================

    public function __construct($section) {

      // Define product type select options
      $contactTitleOptions = ["1"=>"Mr", "2"=>"Mrs", "3"=>"Ms", "4"=>"Mr & Mrs", "5"=>"Dr", "6"=>"HRH", "7"=>"", "8"=>"Miss", "9"=>"Profesor", "10"=>"Messrs", "11"=>"Rev"];

      // Define section filter form inputs
      $section["sectionFilter"]["sectionFilterInput"] = [
        ["attributes"=>[ "type"=>"text", "id"=>"contactName", "value"=>"" ], "label"=>"Name" ],
        ["attributes"=>[ "type"=>"text", "id"=>"contactPhoneNumber", "value"=>"" ], "label"=>"Phone" ],
        ["attributes"=>[ "type"=>"text", "id"=>"contactInternet", "value"=>"" ], "label"=>"Internet" ]
      ];

      // Define section table columns
      $section["sectionTable"]["sectionTableColumn"] = [
        ["id"=>"contactId", "header"=>"Id", "width"=>30],
        ["id"=>"contactFirstName", "header"=>"First Name", "width"=>150],
        ["id"=>"contactLastName", "header"=>"Last Name", "width"=>150],
        ["id"=>"contactHomePhone", "header"=>"Home Phone", "width"=>120],
        ["id"=>"contactMobilePhone", "header"=>"Mobile Phone", "width"=>120],
        ["id"=>"contactEmailAddress", "header"=>"Email Address", "width"=>240]
      ];

      // Define section record fields
      $section["sectionRecord"]["sectionRecordStructure"] = [
        "contactId"=>["type"=>"int", "length"=>"" ],
        "contactType"=>["type"=>"int", "length"=>"" ],
        "contactTitle"=>["type"=>"int", "length"=>"" ],
        "contactFirstName"=>["type"=>"varchar", "length"=>"100" ],
        "contactLastName"=>["type"=>"varchar", "length"=>"100" ],
        "contactOrganisation"=>["type"=>"varchar", "length"=>"100" ],
        "contactMobilePhone"=>["type"=>"varchar", "length"=>"50" ],
        "contactHomePhone"=>["type"=>"varchar", "length"=>"50" ],
        "contactWorkPhone"=>["type"=>"varchar", "length"=>"50" ],
        "contactEmailAddress"=>["type"=>"varchar", "length"=>"100" ],
        "contactWebAddress"=>["type"=>"varchar", "length"=>"100" ],
        "contactIsCustomer"=>["type"=>"varchar", "length"=>"5" ],
        "contactSageAccountNo"=>["type"=>"varchar", "length"=>"20" ],
        "contactExcludeFromMailshot"=>["type"=>"varchar", "length"=>"5" ],
        "contactAsjVisitingRights"=>["type"=>"int", "length"=>"" ],
        "contactDuplicateRating"=>["type"=>"int", "length"=>"" ],
        "contactDuplicateRatingUser"=>["type"=>"int", "length"=>"" ],
        "contactValidated"=>["type"=>"varchar", "length"=>"5" ],
        "contactDeleted"=>["type"=>"varchar", "length"=>"5" ]
      ];
      
      // Define section record summary items
      $section["sectionRecord"]["sectionRecordSummaryItem"] = [
        ["id"=>"contactName", "label"=>"Name", "value"=>""]
      ];

      // Define section record form columns and groups
      $section["sectionRecord"]["sectionRecordTabColumn"] = [
        ["columnId"=>"1", "columnClass"=>"", "columnGroup"=>[["groupId"=>"1"], ["groupId"=>"2"], ["groupId"=>"3"]]]
      ];

      // Define section record form inputs
      $section["sectionRecord"]["sectionRecordInput"] = [
        ["attributes"=>[ "type"=>"hidden", "id"=>"contactId", "name"=>"contactId", "value"=>"0" ], "label"=>"", "groupId"=>"1" ], 
        ["attributes"=>[ "type"=>"select", "id"=>"contactTitle", "name"=>"contactTitle", "required"=>"", "value"=>"7" ], "label"=>"Title", "groupId"=>"1", "options"=>$contactTitleOptions ],
        ["attributes"=>[ "type"=>"text", "id"=>"contactFirstName", "name"=>"contactFirstName", "required"=>"", "maxlength"=>"100", "value"=>"" ], "label"=>"First Name", "groupId"=>"1" ],
        ["attributes"=>[ "type"=>"text", "id"=>"contactLastName", "name"=>"contactLastName", "required"=>"", "maxlength"=>"100", "value"=>"" ], "label"=>"Last Name", "groupId"=>"1" ],
        ["attributes"=>[ "type"=>"text", "id"=>"contactOrganisation", "name"=>"contactOrganisation", "required"=>"", "maxlength"=>"100", "value"=>"" ], "label"=>"Organisation", "groupId"=>"1" ],
        ["attributes"=>[ "type"=>"text", "id"=>"contactMobilePhone", "name"=>"contactMobilePhone", "required"=>"", "maxlength"=>"50", "value"=>"" ], "label"=>"Mobile Phone", "groupId"=>"2" ],
        ["attributes"=>[ "type"=>"text", "id"=>"contactHomePhone", "name"=>"contactHomePhone", "required"=>"", "maxlength"=>"50", "value"=>"" ], "label"=>"Home Phone", "groupId"=>"2" ],
        ["attributes"=>[ "type"=>"text", "id"=>"contactWorkPhone", "name"=>"contactWorkPhone", "required"=>"", "maxlength"=>"50", "value"=>"" ], "label"=>"Work Phone", "groupId"=>"2" ],
        ["attributes"=>[ "type"=>"text", "id"=>"contactEmailAddress", "name"=>"contactEmailAddress", "required"=>"", "maxlength"=>"100", "value"=>"" ], "label"=>"Email Address", "groupId"=>"3" ],
        ["attributes"=>[ "type"=>"text", "id"=>"contactWebAddress", "name"=>"contactWebAddress", "required"=>"", "maxlength"=>"100", "value"=>"" ], "label"=>"Website Address", "groupId"=>"3" ]
      ];

      // Create the section's sql class
      $sectionSql = new ContactSql();

      // Create the parent section object
			parent :: __construct( $section, $sectionSql );

      // Set the section title, filter inputs, filter limit, menu buttons, table columns and table rows 
      $this->set_sectionTitle($section["sectionTitle"]);
      $this->set_sectionTableRecordset();
    }

    //================================================================================================
    // Function set_sqlSelect()
    //================================================================================================

    public function set_sqlSelectFilters($filters) {

    	$DBGeneric = new DBGeneric();

      $sqlSelectWhere = sprintf("WHERE 1");
      $sqlSelectWhere .= $DBGeneric->getFilterSql(['filterValue'=>$filters["contactName"], 'filterValueType'=>'string', 'filterOperator'=>'', 'filterList'=>['contactFirstName', 'contactLastName']]);			
      $sqlSelectWhere .= $DBGeneric->getFilterSql(['filterValue'=>$filters["contactPhoneNumber"], 'filterValueType'=>'string', 'filterOperator'=>'', 'filterList'=>['contactMobilePhone', 'contactHomePhone', 'contactWorkPhone']]);			
      $sqlSelectWhere .= $DBGeneric->getFilterSql(['filterValue'=>$filters["contactInternet"], 'filterValueType'=>'string', 'filterOperator'=>'', 'filterList'=>['contactEmailAddress', 'contactWebAddress']]);			

      $this->set_sqlSelectWhere($sqlSelectWhere);
      $this->set_sqlSelectLimit($filters["contactLimit"]);
      
    }

  }

  //================================================================================================

?>