Merge pull request #4812 from colemanw/CRM-15495
[civicrm-core.git] / CRM / Contribute / Form / Search.php
index 40e9c60e337edf9b167d10e7ea21381418e51649..212bccfe397b1cbb5f5f623ec49b5b80ffb9baaf 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
 /**
  * advanced search, extends basic search
  */
-class CRM_Contribute_Form_Search extends CRM_Core_Form {
+class CRM_Contribute_Form_Search extends CRM_Core_Form_Search {
 
   /**
-   * Are we forced to run a search
-   *
-   * @var int
-   * @access protected
-   */
-  protected $_force;
-
-  /**
-   * name of search button
-   *
-   * @var string
-   * @access protected
-   */
-  protected $_searchButtonName;
-
-  /**
-   * name of print button
-   *
-   * @var string
-   * @access protected
-   */
-  protected $_printButtonName;
-
-  /**
-   * name of action button
-   *
-   * @var string
-   * @access protected
-   */
-  protected $_actionButtonName;
-
-  /**
-   * form values that we will be using
-   *
-   * @var array
-   * @access public
-   */
-  public $_formValues;
-
-  /**
-   * the params that are sent to the query
+   * The params that are sent to the query
    *
    * @var array
-   * @access protected
    */
   protected $_queryParams;
 
   /**
-   * have we already done this search
+   * Are we restricting ourselves to a single contact
    *
-   * @access protected
-   * @var boolean
-   */
-  protected $_done;
-
-  /**
-   * are we restricting ourselves to a single contact
-   *
-   * @access protected
    * @var boolean
    */
   protected $_single = FALSE;
 
   /**
-   * are we restricting ourselves to a single contact
+   * Are we restricting ourselves to a single contact
    *
-   * @access protected
    * @var boolean
    */
   protected $_limit = NULL;
 
-  /**
-   * what context are we being invoked from
-   *
-   * @access protected
-   * @var string
-   */
-  protected $_context = NULL;
-
   protected $_defaults;
 
   /**
-   * prefix for the controller
+   * Prefix for the controller
    *
    */
   protected $_prefix = "contribute_";
 
   /**
-   * processing needed for buildForm and later
+   * Processing needed for buildForm and later
    *
    * @return void
-   * @access public
    */ function preProcess() {
     $this->set('searchFormName', 'Search');
 
@@ -142,7 +82,6 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form {
      * set the button names
      */
     $this->_searchButtonName = $this->getButtonName('refresh');
-    $this->_printButtonName = $this->getButtonName('next', 'print');
     $this->_actionButtonName = $this->getButtonName('next', 'action');
 
     $this->_done = FALSE;
@@ -222,23 +161,22 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form {
     $this->assign('contributionSummary', $this->get('summary'));
   }
 
-  function setDefaultValues() {
-    if (!CRM_Utils_Array::value('contribution_status',
-        $this->_defaults
-      )) {
+  public function setDefaultValues() {
+    if (empty($this->_defaults
+['contribution_status'])) {
       $this->_defaults['contribution_status'][1] = 1;
     }
     return $this->_defaults;
   }
 
   /**
-   * Build the form
+   * Build the form object
    *
-   * @access public
    *
    * @return void
    */
-  function buildQuickForm() {
+  public function buildQuickForm() {
+    parent::buildQuickForm();
     // text for sort_name
     $this->addElement('text',
       'sort_name',
@@ -248,84 +186,43 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form {
       )
     );
 
-    $this->_group = CRM_Core_PseudoConstant::group();
+    $this->_group = CRM_Core_PseudoConstant::nestedGroup();
 
     // multiselect for groups
     if ($this->_group) {
       $this->add('select', 'group', ts('Groups'), $this->_group, FALSE,
-        array('id' => 'group', 'multiple' => 'multiple', 'title' => ts('- select -'))
+        array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2')
       );
     }
 
     // multiselect for tags
-    require_once 'CRM/Core/BAO/Tag.php';
     $contactTags = CRM_Core_BAO_Tag::getTags();
 
     if ($contactTags) {
       $this->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE,
-        array('id' => 'contact_tags', 'multiple' => 'multiple', 'title' => ts('- select -'))
+        array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2')
       );
     }
 
     CRM_Contribute_BAO_Query::buildSearchForm($this);
 
-    /*
-     * add form checkboxes for each row. This is needed out here to conform to QF protocol
-     * of all elements being declared in builQuickForm
-     */
-
     $rows = $this->get('rows');
     if (is_array($rows)) {
       if (!$this->_single) {
-        $this->addElement('checkbox',
-          'toggleSelect',
-          NULL,
-          NULL,
-          array('onclick' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);")
-        );
-        foreach ($rows as $row) {
-          $this->addElement('checkbox', $row['checkbox'],
-            NULL, NULL,
-            array('onclick' => "toggleTaskAction( true ); return checkSelectedBox('" . $row['checkbox'] . "');")
-          );
-        }
+        $this->addRowSelectors($rows);
       }
 
-      $total = $cancel = 0;
-
       $permission = CRM_Core_Permission::getPermission();
 
-      $tasks = array('' => ts('- actions -')) + CRM_Contribute_Task::permissionedTaskTitles($permission);
-      $this->add('select', 'task', ts('Actions:') . ' ', $tasks);
-      $this->add('submit', $this->_actionButtonName, ts('Go'),
-        array(
-          'class' => 'form-submit',
-          'id' => 'Go',
-          'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);",
-        )
-      );
-
-      $this->add('submit', $this->_printButtonName, ts('Print'),
-        array(
-          'class' => 'form-submit',
-          'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);",
-        )
-      );
-
-      // need to perform tasks on all or selected items ? using radio_ts(task selection) for it
-      $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked'));
-      $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all', array('onclick' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_',this); toggleTaskAction( true );"));
+      $queryParams = $this->get('queryParams');
+      $softCreditFiltering = FALSE;
+      if (!empty($queryParams)) {
+        $softCreditFiltering = CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled($queryParams);
+      }
+      $tasks = CRM_Contribute_Task::permissionedTaskTitles($permission, $softCreditFiltering);
+      $this->addTaskMenu($tasks);
     }
 
-    // add buttons
-    $this->addButtons(array(
-        array(
-          'type' => 'refresh',
-          'name' => ts('Search'),
-          'isDefault' => TRUE,
-        ),
-      )
-    );
   }
 
   /**
@@ -343,9 +240,8 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form {
    * @param
    *
    * @return void
-   * @access public
    */
-  function postProcess() {
+  public function postProcess() {
     if ($this->_done) {
       return;
     }
@@ -359,7 +255,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form {
     $this->fixFormValues();
 
     // We don't show test records in summaries or dashboards
-    if (empty($this->_formValues['contribution_test']) && $this->_force) {
+    if (empty($this->_formValues['contribution_test']) && $this->_force && !empty($this->_context) && $this->_context == 'dashboard') {
       $this->_formValues["contribution_test"] = 0;
     }
 
@@ -371,43 +267,44 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form {
     }
 
     $config = CRM_Core_Config::singleton();
-    // CRM-13848
-    $financialType = CRM_Utils_Array::value('financial_type_id', $this->_formValues);
-    if ($financialType && is_array($financialType)) {
-      unset($this->_formValues['financial_type_id']);
-      foreach($financialType as $notImportant => $typeID) {
-        $this->_formValues['financial_type_id'][$typeID] = 1;
+    if (!empty($_POST)) {
+      // CRM-13848
+      $financialType = CRM_Utils_Array::value('financial_type_id', $this->_formValues);
+      if ($financialType && is_array($financialType)) {
+        unset($this->_formValues['financial_type_id']);
+        foreach($financialType as $notImportant => $typeID) {
+          $this->_formValues['financial_type_id'][$typeID] = 1;
+        }
       }
-    }
 
-    $tags = CRM_Utils_Array::value('contact_tags', $this->_formValues);
-    if ($tags && !is_array($tags)) {
-      unset($this->_formValues['contact_tags']);
-      $this->_formValues['contact_tags'][$tags] = 1;
-    }
+      $tags = CRM_Utils_Array::value('contact_tags', $this->_formValues);
+      if ($tags && !is_array($tags)) {
+        unset($this->_formValues['contact_tags']);
+        $this->_formValues['contact_tags'][$tags] = 1;
+      }
 
-    if ($tags && is_array($tags)) {
-      unset($this->_formValues['contact_tags']);
-      foreach($tags as $notImportant => $tagID) {
-        $this->_formValues['contact_tags'][$tagID] = 1;
+      if ($tags && is_array($tags)) {
+        unset($this->_formValues['contact_tags']);
+        foreach($tags as $notImportant => $tagID) {
+          $this->_formValues['contact_tags'][$tagID] = 1;
+        }
       }
-    }
 
 
-    if (!$config->groupTree) {
-      $group = CRM_Utils_Array::value('group', $this->_formValues);
-      if ($group && !is_array($group)) {
-        unset($this->_formValues['group']);
-        $this->_formValues['group'][$group] = 1;
-      }
+      if (!$config->groupTree) {
+        $group = CRM_Utils_Array::value('group', $this->_formValues);
+        if ($group && !is_array($group)) {
+          unset($this->_formValues['group']);
+          $this->_formValues['group'][$group] = 1;
+        }
 
-      if ($group && is_array($group)) {
-        unset($this->_formValues['group']);
-        foreach($group as $notImportant => $groupID) {
-          $this->_formValues['group'][$groupID] = 1;
+        if ($group && is_array($group)) {
+          unset($this->_formValues['group']);
+          foreach($group as $notImportant => $groupID) {
+            $this->_formValues['group'][$groupID] = 1;
+          }
         }
       }
-
     }
 
     CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($this->_formValues);
@@ -418,7 +315,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form {
     $this->set('queryParams', $this->_queryParams);
 
     $buttonName = $this->controller->getButtonName();
-    if ($buttonName == $this->_actionButtonName || $buttonName == $this->_printButtonName) {
+    if ($buttonName == $this->_actionButtonName) {
       // check actionName and if next, then do not repeat a search, since we are going to the next page
 
       // hack, make sure we reset the task values
@@ -471,11 +368,10 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form {
     $controller->run();
   }
 
-  function fixFormValues() {
+  public function fixFormValues() {
     // if this search has been forced
     // then see if there are any get values, and if so over-ride the post values
     // note that this means that GET over-rides POST :)
-
     if (!$this->_force) {
       return;
     }
@@ -558,10 +454,8 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form {
    * Return a descriptive name for the page, used in wizard header
    *
    * @return string
-   * @access public
    */
   public function getTitle() {
     return ts('Find Contributions');
   }
 }
-