<?php

/*
 +--------------------------------------------------------------------+
 | CiviCRM version 3.3                                                |
 +--------------------------------------------------------------------+
 | Copyright CiviCRM LLC (c) 2004-2010                                |
 +--------------------------------------------------------------------+
 | This file is a part of CiviCRM.                                    |
 |                                                                    |
 | CiviCRM is free software; you can copy, modify, and distribute it  |
 | under the terms of the GNU Affero General Public License           |
 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
 |                                                                    |
 | CiviCRM is distributed in the hope that it will be useful, but     |
 | WITHOUT ANY WARRANTY; without even the implied warranty of         |
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
 | See the GNU Affero General Public License for more details.        |
 |                                                                    |
 | You should have received a copy of the GNU Affero General Public   |
 | License and the CiviCRM Licensing Exception along                  |
 | with this program; if not, contact CiviCRM LLC                     |
 | at info[AT]civicrm[DOT]org. If you have questions about the        |
 | GNU Affero General Public License or the licensing of CiviCRM,     |
 | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
 +--------------------------------------------------------------------+
*/

/**
 *
 * @package CRM
 * @copyright CiviCRM LLC (c) 2004-2010
 * $Id$
 *
 */

require_once 'CRM/Contact/Form/Search/Custom/Base.php';

class CRM_Contact_Form_Search_Custom_SEARCHNAME
   extends    CRM_Contact_Form_Search_Custom_Base
   implements CRM_Contact_Form_Search_Interface {

    function __construct( &$formValues ) {
        parent::__construct( $formValues );

        $this->_columns = array(
          ts('Contact Id')   => 'contact_id'  ,
          ts('Name')         => 'sort_name',
          // Add fields here
				);
    }

    function buildForm( &$form ) {
				$this->setTitle("SEARCHTITLE");

        $form->assign( 'elements', array(/* Add field names here */) );

    }

    function summary( ) {
        $summary = array( 'summary' => 'This is a summary',
                          'total' => 0 );
        return $summary;
    }

    function all( $offset = 0, $rowcount = 0, $sort = null,
                  $includeContactIDs = false ) {
        $selectClause = "...";

				$groupBy = NULL;

        return $this->sql( $selectClause,
                           $offset, $rowcount, $sort,
                           $includeContactIDs, $groupBy );

    }

    function from( ) {
        return "FROM ...";
    }

    function where( $includeContactIDs = false ) {

        $where  = "...";

        $params = array( );

				$count  = 1;
				$clauses = array( );

				$value = CRM_Utils_Array::value( 'FORMVALUE', $this->_formValues );
				if ($value != '') {
					$params[$count] = array( $value, /* CHOOSE EITHER 'Integer' 'String' ... */ );
					$clauses[] = "TABLE.COLUMN = %{$count}";
					$count++;
				}

        if ( ! empty( $clauses ) ) {
            $where .= ' AND ' . implode( ' AND ', $clause );
        }

        return $this->whereClause( $where, $params );
    }

    function templateFile( ) {
        return 'CRM/Contact/Form/Search/Custom.tpl';
    }

    function setDefaultValues( ) {
        // return array( 'FORMVALUE'    => VALUE );
    }

    function alterRow( &$row ) {
        // $row['COLUMN'] = NEWVALUE;
    }

    function setTitle( $title ) {
        if ( $title ) {
            CRM_Utils_System::setTitle( $title );
        } else {
            CRM_Utils_System::setTitle(ts('Search'));
        }
    }
}


