Commit | Line | Data |
---|---|---|
bc2eeabb PJ |
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 usefusul, 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 | ||
36 | /** | |
2429e40c | 37 | * This form used for changing / updating fee selections for the events |
bc2eeabb PJ |
38 | * event/contribution is partially paid |
39 | * | |
40 | */ | |
41 | class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form { | |
bc2eeabb PJ |
42 | |
43 | protected $_contactId = NULL; | |
44 | ||
45 | protected $_contributorDisplayName = NULL; | |
46 | ||
47 | protected $_contributorEmail = NULL; | |
48 | ||
49 | protected $_toDoNotEmail = NULL; | |
50 | ||
51 | protected $_contributionId = NULL; | |
52 | ||
53 | protected $fromEmailId = NULL; | |
54 | ||
55 | protected $_eventId = NULL; | |
56 | ||
57 | public $_action = NULL; | |
58 | ||
59 | public $_values = NULL; | |
60 | ||
bc2eeabb PJ |
61 | public $_participantId = NULL; |
62 | ||
b17ee3ee PJ |
63 | protected $_participantStatus = NULL; |
64 | ||
bc2eeabb PJ |
65 | public function preProcess() { |
66 | $this->_participantId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); | |
67 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); | |
bc2eeabb | 68 | $this->_eventId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_participantId, 'event_id'); |
2429e40c PJ |
69 | $this->_fromEmails = CRM_Event_BAO_Event::getFromEmailIds($this->_eventId); |
70 | ||
bc2eeabb PJ |
71 | $this->_contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participantId, 'contribution_id', 'participant_id'); |
72 | if ($this->_contributionId) { | |
73 | $this->_isPaidEvent = TRUE; | |
74 | } | |
75 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, TRUE); | |
76 | ||
77 | list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId); | |
78 | $this->assign('displayName', $this->_contributorDisplayName); | |
2429e40c PJ |
79 | $this->assign('email', $this->_contributorEmail); |
80 | ||
b17ee3ee | 81 | $this->_participantStatus = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $this->_participantId, 'status_id'); |
bc2eeabb PJ |
82 | //set the payment mode - _mode property is defined in parent class |
83 | $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this); | |
84 | ||
85 | $this->assign('contactId', $this->_contactId); | |
86 | $this->assign('id', $this->_participantId); | |
87 | ||
88 | $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_participantId, 'event'); | |
89 | $this->assign('paymentInfo', $paymentInfo); | |
90 | CRM_Core_Resources::singleton()->addSetting(array('feePaid' => $paymentInfo['paid'])); | |
91 | ||
92 | $title = "Change selections for {$this->_contributorDisplayName}"; | |
93 | if ($title) { | |
94 | CRM_Utils_System::setTitle(ts('%1', array(1 => $title))); | |
95 | } | |
96 | } | |
97 | ||
98 | public function setDefaultValues() { | |
99 | $params = array('id' => $this->_participantId); | |
100 | ||
101 | CRM_Event_BAO_Participant::getValues($params, $defaults, $ids); | |
102 | $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->_eventId); | |
103 | ||
104 | $priceSetValues = CRM_Event_Form_EventFees::setDefaultPriceSet($this->_participantId, $this->_eventId); | |
105 | if (!empty($priceSetValues)) { | |
106 | $defaults[$this->_participantId] = array_merge($defaults[$this->_participantId], $priceSetValues); | |
107 | } | |
108 | ||
109 | $this->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults[$this->_participantId])); | |
110 | if ($this->_action == CRM_Core_Action::UPDATE) { | |
111 | $fee_level = $defaults[$this->_participantId]['fee_level']; | |
112 | CRM_Event_BAO_Participant::fixEventLevel($fee_level); | |
113 | $this->assign('fee_level', $fee_level); | |
114 | $this->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$this->_participantId])); | |
115 | } | |
116 | $defaults = $defaults[$this->_participantId]; | |
117 | return $defaults; | |
118 | } | |
119 | ||
120 | public function buildQuickForm() { | |
2429e40c PJ |
121 | CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js'); |
122 | ||
123 | $statuses = CRM_Event_PseudoConstant::participantStatus(); | |
124 | CRM_Core_Resources::singleton()->addSetting(array( | |
125 | 'partiallyPaid' => array_search('Partially paid', $statuses), | |
126 | 'pendingRefund' => array_search('Pending refund', $statuses), | |
b17ee3ee | 127 | 'participantStatus' => $this->_participantStatus |
2429e40c PJ |
128 | )); |
129 | ||
bc2eeabb PJ |
130 | $config = CRM_Core_Config::singleton(); |
131 | $this->assign('currencySymbol', $config->defaultCurrencySymbol); | |
132 | ||
133 | // line items block | |
134 | $lineItem = $event = array(); | |
135 | $params = array('id' => $this->_eventId); | |
136 | CRM_Event_BAO_Event::retrieve($params, $event); | |
137 | ||
138 | //retrieve custom information | |
139 | $this->_values = array(); | |
140 | CRM_Event_Form_Registration::initEventFee($this, $event['id']); | |
141 | CRM_Event_Form_Registration_Register::buildAmount($this, TRUE); | |
142 | ||
143 | if (!CRM_Utils_System::isNull(CRM_Utils_Array::value('line_items', $this->_values))) { | |
144 | $lineItem[] = $this->_values['line_items']; | |
145 | } | |
146 | $this->assign('lineItem', empty($lineItem) ? FALSE : $lineItem); | |
147 | $event = CRM_Event_BAO_Event::getEvents(0, $this->_eventId); | |
148 | $this->assign('eventName', $event[$this->_eventId]); | |
149 | ||
150 | $statusOptions = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'); | |
151 | $this->add('select', 'status_id', ts('Participant Status'), | |
152 | array( | |
153 | '' => ts('- select -')) + $statusOptions, | |
154 | TRUE | |
155 | ); | |
156 | ||
2429e40c PJ |
157 | $this->addElement('checkbox', |
158 | 'send_receipt', | |
159 | ts('Send Confirmation?'), NULL, | |
160 | array('onclick' => "showHideByValue('send_receipt','','notice','table-row','radio',false); showHideByValue('send_receipt','','from-email','table-row','radio',false);") | |
161 | ); | |
162 | ||
163 | $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails['from_email_id']); | |
164 | ||
165 | $this->add('textarea', 'receipt_text', ts('Confirmation Message')); | |
166 | ||
167 | $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note'); | |
168 | $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']); | |
169 | ||
bc2eeabb PJ |
170 | $buttons[] = array( |
171 | 'type' => 'upload', | |
172 | 'name' => ts('Save'), | |
173 | 'isDefault' => TRUE, | |
174 | ); | |
175 | ||
2429e40c PJ |
176 | $buttons[] = array( |
177 | 'type' => 'upload', | |
178 | 'name' => ts('Save and Record Payment'), | |
179 | 'subName' => 'new' | |
180 | ); | |
181 | ||
bc2eeabb PJ |
182 | $buttons[] = array( |
183 | 'type' => 'cancel', | |
184 | 'name' => ts('Cancel'), | |
185 | ); | |
186 | ||
187 | $this->addButtons($buttons); | |
188 | $this->addFormRule(array('CRM_Event_Form_ParticipantFeeSelection', 'formRule'), $this); | |
189 | } | |
190 | ||
191 | static function formRule($fields, $files, $self) { | |
192 | $errors = array(); | |
193 | return $errors; | |
194 | } | |
195 | ||
196 | public function postProcess() { | |
197 | $params = $this->controller->exportValues($this->_name); | |
2429e40c PJ |
198 | $session = CRM_Core_Session::singleton(); |
199 | $buttonName = $this->controller->getButtonName(); | |
200 | if ($buttonName == $this->getButtonName('upload', 'new')) { | |
201 | $session->replaceUserContext(CRM_Utils_System::url('civicrm/payment/add', | |
202 | "reset=1&action=add&component=event&id={$this->_participantId}&cid={$this->_contactId}" | |
203 | )); | |
204 | } | |
205 | } | |
bc2eeabb PJ |
206 | |
207 | static function emailReceipt(&$form, &$params) { | |
208 | // email receipt sending | |
209 | } | |
210 | } |