Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
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 | ||
36 | /** | |
37 | * This class provides the functionality to update a group of | |
38 | * grants. This class provides functionality for the actual | |
39 | * update. | |
40 | */ | |
41 | class CRM_Grant_Form_Task_Update extends CRM_Grant_Form_Task { | |
42 | ||
43 | /** | |
44 | * build all the data structures needed to build the form | |
45 | * | |
46 | * @return void | |
47 | * @access public | |
48 | */ | |
49 | function preProcess() { | |
50 | parent::preProcess(); | |
51 | ||
52 | //check permission for update. | |
53 | if (!CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::UPDATE)) { | |
0499b0ad | 54 | CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); |
6a488035 TO |
55 | } |
56 | } | |
57 | ||
58 | /** | |
59 | * Build the form | |
60 | * | |
61 | * @access public | |
62 | * | |
63 | * @return void | |
64 | */ | |
65 | function buildQuickForm() { | |
fb1fd730 | 66 | $grantStatus = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'status_id'); |
6a488035 TO |
67 | $this->addElement('select', 'status_id', ts('Grant Status'), array('' => '') + $grantStatus); |
68 | ||
69 | $this->addElement('text', 'amount_granted', ts('Amount Granted')); | |
70 | $this->addRule('amount_granted', ts('Please enter a valid amount.'), 'money'); | |
71 | ||
72 | $this->addDate('decision_date', ts('Grant Decision'), FALSE, array('formatType' => 'custom')); | |
73 | ||
74 | $this->assign('elements', array('status_id', 'amount_granted', 'decision_date')); | |
75 | $this->assign('totalSelectedGrants', count($this->_grantIds)); | |
76 | ||
77 | $this->addDefaultButtons(ts('Update Grants'), 'done'); | |
78 | } | |
79 | ||
80 | /** | |
81 | * process the form after the input has been submitted and validated | |
82 | * | |
83 | * @access public | |
84 | * | |
355ba699 | 85 | * @return void |
6a488035 TO |
86 | */ |
87 | public function postProcess() { | |
88 | $updatedGrants = 0; | |
89 | ||
90 | // get the submitted form values. | |
91 | $params = $this->controller->exportValues($this->_name); | |
92 | $qfKey = $params['qfKey']; | |
93 | foreach ($params as $key => $value) { | |
94 | if ($value == '' || $key == 'qfKey') { | |
95 | unset($params[$key]); | |
96 | } | |
97 | } | |
98 | ||
99 | if (!empty($params)) { | |
100 | foreach ($params as $key => $value) { | |
101 | $values[$key] = $value; | |
102 | } | |
103 | foreach ($this->_grantIds as $grantId) { | |
565df8cf | 104 | $ids['grant_id'] = $grantId; |
6a488035 TO |
105 | |
106 | CRM_Grant_BAO_Grant::add($values, $ids); | |
107 | $updatedGrants++; | |
108 | } | |
109 | } | |
110 | ||
0bc90828 KM |
111 | $status = ts('Updated Grant(s): %1 (Total Selected: %2)', array(1 => $updatedGrants, 2 => count($this->_grantIds))); |
112 | CRM_Core_Session::setStatus($status, '', 'info'); | |
6a488035 TO |
113 | CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/grant/search', 'force=1&qfKey=' . $qfKey)); |
114 | } | |
115 | } | |
116 |