Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Financial_Form_Search extends CRM_Core_Form { | |
36 | ||
37 | public $_batchStatus; | |
38 | ||
00be9182 | 39 | public function preProcess() { |
6a488035 TO |
40 | $this->_batchStatus = CRM_Utils_Request::retrieve('batchStatus', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL); |
41 | $this->assign('batchStatus', $this->_batchStatus); | |
42 | } | |
43 | ||
e0ef6999 EM |
44 | /** |
45 | * @return array | |
46 | */ | |
00be9182 | 47 | public function setDefaultValues() { |
6a488035 TO |
48 | $defaults = array(); |
49 | $status = CRM_Utils_Request::retrieve('status', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, 1); | |
50 | $defaults['batch_update'] = $status; | |
51 | if ($this->_batchStatus) { | |
52 | $defaults['status_id'] = $this->_batchStatus; | |
53 | } | |
54 | return $defaults; | |
55 | } | |
56 | ||
57 | public function buildQuickForm() { | |
353ffa53 TO |
58 | CRM_Core_Resources::singleton() |
59 | ->addScriptFile('civicrm', 'packages/jquery/plugins/jquery.redirect.min.js', 0, 'html-header'); | |
6a488035 TO |
60 | $attributes = CRM_Core_DAO::getAttribute('CRM_Batch_DAO_Batch'); |
61 | $attributes['total']['class'] = $attributes['item_count']['class'] = 'number'; | |
62 | $this->add('text', 'title', ts('Batch Name'), $attributes['title']); | |
e0ef6999 | 63 | |
fd7abdce | 64 | $batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name')); |
6a488035 TO |
65 | $this->add( |
66 | 'select', | |
67 | 'status_id', | |
68 | ts('Batch Status'), | |
69 | array( | |
481a74f4 | 70 | '' => ts('- any -'), |
fd7abdce PN |
71 | array_search('Open', $batchStatus) => ts('Open'), |
72 | array_search('Closed', $batchStatus) => ts('Closed'), | |
73 | array_search('Exported', $batchStatus) => ts('Exported'), | |
6a488035 | 74 | ), |
045f52a3 | 75 | FALSE |
6a488035 TO |
76 | ); |
77 | ||
78 | $this->add( | |
79 | 'select', | |
80 | 'payment_instrument_id', | |
81 | ts('Payment Instrument'), | |
481a74f4 | 82 | array('' => ts('- any -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), |
045f52a3 | 83 | FALSE |
6a488035 TO |
84 | ); |
85 | ||
86 | $this->add('text', 'total', ts('Total Amount'), $attributes['total']); | |
87 | ||
88 | $this->add('text', 'item_count', ts('Number of Items'), $attributes['item_count']); | |
89 | $this->add('text', 'sort_name', ts('Created By'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); | |
90 | ||
91 | $this->assign('elements', array('status_id', 'title', 'sort_name', 'payment_instrument_id', 'item_count', 'total')); | |
92 | $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('class' => 'select-rows')); | |
93 | $batchAction = array( | |
94 | 'reopen' => ts('Re-open'), | |
95 | 'close' => ts('Close'), | |
96 | 'export' => ts('Export'), | |
97 | 'delete' => ts('Delete'), | |
98 | ); | |
99 | ||
100 | $this->add('select', | |
101 | 'batch_update', | |
481a74f4 | 102 | ts('Task'), |
6a488035 TO |
103 | array('' => ts('- actions -')) + $batchAction); |
104 | ||
045f52a3 | 105 | $this->add('submit', 'submit', ts('Go'), |
6a488035 | 106 | array( |
97e557d7 | 107 | 'class' => 'crm-form-submit', |
6a488035 TO |
108 | 'id' => 'Go', |
109 | )); | |
110 | ||
111 | $this->addButtons( | |
112 | array( | |
113 | array( | |
114 | 'type' => 'refresh', | |
115 | 'name' => ts('Search'), | |
116 | 'isDefault' => TRUE, | |
21dfd5f5 | 117 | ), |
6a488035 TO |
118 | ) |
119 | ); | |
120 | parent::buildQuickForm(); | |
121 | } | |
122 | ||
00be9182 | 123 | public function postProcess() { |
6a488035 TO |
124 | $batchIds = array(); |
125 | foreach ($_POST as $key => $value) { | |
045f52a3 TO |
126 | if (substr($key, 0, 6) == "check_") { |
127 | $batch = explode("_", $key); | |
6a488035 TO |
128 | $batchIds[] = $batch[1]; |
129 | } | |
130 | } | |
a7488080 | 131 | if (!empty($_POST['batch_update'])) { |
6a488035 TO |
132 | CRM_Batch_BAO_Batch::closeReOpen($batchIds, $_POST['batch_update']); |
133 | } | |
134 | } | |
135 | } |