| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 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-2015 |
| 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 | */ |
| 48 | public function preProcess() { |
| 49 | parent::preProcess(); |
| 50 | |
| 51 | //check permission for update. |
| 52 | if (!CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::UPDATE)) { |
| 53 | CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Build the form object. |
| 59 | * |
| 60 | * |
| 61 | * @return void |
| 62 | */ |
| 63 | public function buildQuickForm() { |
| 64 | $grantStatus = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'status_id'); |
| 65 | $this->addElement('select', 'status_id', ts('Grant Status'), array('' => '') + $grantStatus); |
| 66 | |
| 67 | $this->addElement('text', 'amount_granted', ts('Amount Granted')); |
| 68 | $this->addRule('amount_granted', ts('Please enter a valid amount.'), 'money'); |
| 69 | |
| 70 | $this->addDate('decision_date', ts('Grant Decision'), FALSE, array('formatType' => 'custom')); |
| 71 | |
| 72 | $this->assign('elements', array('status_id', 'amount_granted', 'decision_date')); |
| 73 | $this->assign('totalSelectedGrants', count($this->_grantIds)); |
| 74 | |
| 75 | $this->addDefaultButtons(ts('Update Grants'), 'done'); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Process the form after the input has been submitted and validated. |
| 80 | * |
| 81 | * |
| 82 | * @return void |
| 83 | */ |
| 84 | public function postProcess() { |
| 85 | $updatedGrants = 0; |
| 86 | |
| 87 | // get the submitted form values. |
| 88 | $params = $this->controller->exportValues($this->_name); |
| 89 | $qfKey = $params['qfKey']; |
| 90 | foreach ($params as $key => $value) { |
| 91 | if ($value == '' || $key == 'qfKey') { |
| 92 | unset($params[$key]); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | if (!empty($params)) { |
| 97 | foreach ($params as $key => $value) { |
| 98 | $values[$key] = $value; |
| 99 | } |
| 100 | foreach ($this->_grantIds as $grantId) { |
| 101 | $ids['grant_id'] = $grantId; |
| 102 | |
| 103 | CRM_Grant_BAO_Grant::add($values, $ids); |
| 104 | $updatedGrants++; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | $status = ts('Updated Grant(s): %1 (Total Selected: %2)', array(1 => $updatedGrants, 2 => count($this->_grantIds))); |
| 109 | CRM_Core_Session::setStatus($status, '', 'info'); |
| 110 | CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/grant/search', 'force=1&qfKey=' . $qfKey)); |
| 111 | } |
| 112 | |
| 113 | } |