CRM-14106 - Regex targeting the first part of if statements
[civicrm-core.git] / CRM / Financial / Form / Search.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35 class CRM_Financial_Form_Search extends CRM_Core_Form {
36
37 public $_batchStatus;
38
39 function preProcess() {
40 $this->_batchStatus = CRM_Utils_Request::retrieve('batchStatus', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL);
41 $this->assign('batchStatus', $this->_batchStatus);
42 }
43
44 function setDefaultValues() {
45 $defaults = array();
46 $status = CRM_Utils_Request::retrieve('status', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, 1);
47 $defaults['batch_update'] = $status;
48 if ($this->_batchStatus) {
49 $defaults['status_id'] = $this->_batchStatus;
50 }
51 return $defaults;
52 }
53
54 public function buildQuickForm() {
55 CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'packages/jquery/plugins/jquery.redirect.min.js', 0, 'html-header');
56 $attributes = CRM_Core_DAO::getAttribute('CRM_Batch_DAO_Batch');
57 $attributes['total']['class'] = $attributes['item_count']['class'] = 'number';
58 $this->add('text', 'title', ts('Batch Name'), $attributes['title']);
59
60 $this->add(
61 'select',
62 'status_id',
63 ts('Batch Status'),
64 array(
65 '' => ts('- any -' ),
66 1 => ts('Open'),
67 2 => ts('Closed'),
68 5 => ts('Exported'),
69 ),
70 false
71 );
72
73 $this->add(
74 'select',
75 'payment_instrument_id',
76 ts('Payment Instrument'),
77 array('' => ts('- any -' )) + CRM_Contribute_PseudoConstant::paymentInstrument(),
78 false
79 );
80
81 $this->add('text', 'total', ts('Total Amount'), $attributes['total']);
82
83 $this->add('text', 'item_count', ts('Number of Items'), $attributes['item_count']);
84 $this->add('text', 'sort_name', ts('Created By'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
85
86 $this->assign('elements', array('status_id', 'title', 'sort_name', 'payment_instrument_id', 'item_count', 'total'));
87 $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('class' => 'select-rows'));
88 $batchAction = array(
89 'reopen' => ts('Re-open'),
90 'close' => ts('Close'),
91 'export' => ts('Export'),
92 'delete' => ts('Delete'),
93 );
94
95 $this->add('select',
96 'batch_update',
97 ts('Task' ),
98 array('' => ts('- actions -')) + $batchAction);
99
100 $this->add('submit','submit', ts('Go'),
101 array(
102 'class' => 'form-submit',
103 'id' => 'Go',
104 ));
105
106 $this->addButtons(
107 array(
108 array(
109 'type' => 'refresh',
110 'name' => ts('Search'),
111 'isDefault' => TRUE,
112 )
113 )
114 );
115 parent::buildQuickForm();
116 }
117
118 function postProcess() {
119 $batchIds = array();
120 foreach ($_POST as $key => $value) {
121 if (substr($key,0,6) == "check_") {
122 $batch = explode("_",$key);
123 $batchIds[] = $batch[1];
124 }
125 }
126 if (!empty($_POST['batch_update'])) {
127 CRM_Batch_BAO_Batch::closeReOpen($batchIds, $_POST['batch_update']);
128 }
129 }
130 }
131