3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * This form used for changing / updating fee selections for the events
38 * event/contribution is partially paid
41 class CRM_Event_Form_ParticipantFeeSelection
extends CRM_Core_Form
{
43 public $useLivePageJS = TRUE;
45 protected $_contactId = NULL;
47 protected $_contributorDisplayName = NULL;
49 protected $_contributorEmail = NULL;
51 protected $_toDoNotEmail = NULL;
53 protected $_contributionId = NULL;
55 protected $fromEmailId = NULL;
57 public $_eventId = NULL;
59 public $_action = NULL;
61 public $_values = NULL;
63 public $_participantId = NULL;
65 protected $_participantStatus = NULL;
67 protected $_paidAmount = NULL;
69 public $_isPaidEvent = NULL;
71 protected $contributionAmt = NULL;
73 public function preProcess() {
74 $this->_participantId
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
75 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
76 $this->_eventId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_participantId
, 'event_id');
77 $this->_fromEmails
= CRM_Event_BAO_Event
::getFromEmailIds($this->_eventId
);
79 $this->_contributionId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participantId
, 'contribution_id', 'participant_id');
80 if (!$this->_contributionId
) {
81 if ($primaryParticipantId = CRM_Core_DAO
::getFieldValue('CRM_Event_BAO_Participant', $this->_participantId
, 'registered_by_id')) {
82 $this->_contributionId
= CRM_Core_DAO
::getFieldValue('CRM_Event_BAO_ParticipantPayment', $primaryParticipantId, 'contribution_id', 'participant_id');
86 if ($this->_contributionId
) {
87 $this->_isPaidEvent
= TRUE;
89 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, TRUE);
91 list($this->_contributorDisplayName
, $this->_contributorEmail
) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($this->_contactId
);
92 $this->assign('displayName', $this->_contributorDisplayName
);
93 $this->assign('email', $this->_contributorEmail
);
95 $this->_participantStatus
= CRM_Core_DAO
::getFieldValue('CRM_Event_BAO_Participant', $this->_participantId
, 'status_id');
96 //set the payment mode - _mode property is defined in parent class
97 $this->_mode
= CRM_Utils_Request
::retrieve('mode', 'String', $this);
99 $this->assign('contactId', $this->_contactId
);
100 $this->assign('id', $this->_participantId
);
102 $paymentInfo = CRM_Contribute_BAO_Contribution
::getPaymentInfo($this->_participantId
, 'event');
103 $this->_paidAmount
= $paymentInfo['paid'];
104 $this->assign('paymentInfo', $paymentInfo);
105 $this->assign('feePaid', $this->_paidAmount
);
107 $ids = CRM_Event_BAO_Participant
::getParticipantIds($this->_contributionId
);
108 if (count($ids) > 1) {
110 foreach ($ids as $val) {
111 $total +
= CRM_Price_BAO_LineItem
::getLineTotal($val, 'civicrm_participant');
113 $this->assign('totalLineTotal', $total);
115 $lineItemTotal = CRM_Price_BAO_LineItem
::getLineTotal($this->_participantId
, 'civicrm_participant');
116 $this->assign('lineItemTotal', $lineItemTotal);
119 $title = "Change selections for {$this->_contributorDisplayName}";
121 CRM_Utils_System
::setTitle(ts('%1', array(1 => $title)));
125 public function setDefaultValues() {
126 $params = array('id' => $this->_participantId
);
128 CRM_Event_BAO_Participant
::getValues($params, $defaults, $ids);
129 $priceSetId = CRM_Price_BAO_PriceSet
::getFor('civicrm_event', $this->_eventId
);
131 $priceSetValues = CRM_Event_Form_EventFees
::setDefaultPriceSet($this->_participantId
, $this->_eventId
, FALSE);
132 if (!empty($priceSetValues)) {
133 $defaults[$this->_participantId
] = array_merge($defaults[$this->_participantId
], $priceSetValues);
136 $this->assign('totalAmount', CRM_Utils_Array
::value('fee_amount', $defaults[$this->_participantId
]));
137 if ($this->_action
== CRM_Core_Action
::UPDATE
) {
138 $fee_level = $defaults[$this->_participantId
]['fee_level'];
139 CRM_Event_BAO_Participant
::fixEventLevel($fee_level);
140 $this->assign('fee_level', $fee_level);
141 $this->assign('fee_amount', CRM_Utils_Array
::value('fee_amount', $defaults[$this->_participantId
]));
143 $defaults = $defaults[$this->_participantId
];
147 public function buildQuickForm() {
149 $statuses = CRM_Event_PseudoConstant
::participantStatus();
150 $this->assign('partiallyPaid', array_search('Partially paid', $statuses));
151 $this->assign('pendingRefund', array_search('Pending refund', $statuses));
152 $this->assign('participantStatus', $this->_participantStatus
);
154 $config = CRM_Core_Config
::singleton();
155 $this->assign('currencySymbol', $config->defaultCurrencySymbol
);
158 $lineItem = $event = array();
159 $params = array('id' => $this->_eventId
);
160 CRM_Event_BAO_Event
::retrieve($params, $event);
162 //retrieve custom information
163 $this->_values
= array();
164 CRM_Event_Form_Registration
::initEventFee($this, $event['id']);
165 CRM_Event_Form_Registration_Register
::buildAmount($this, TRUE);
167 if (!CRM_Utils_System
::isNull(CRM_Utils_Array
::value('line_items', $this->_values
))) {
168 $lineItem[] = $this->_values
['line_items'];
170 $this->assign('lineItem', empty($lineItem) ?
FALSE : $lineItem);
171 $event = CRM_Event_BAO_Event
::getEvents(0, $this->_eventId
);
172 $this->assign('eventName', $event[$this->_eventId
]);
174 $statusOptions = CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label');
175 $this->add('select', 'status_id', ts('Participant Status'),
177 '' => ts('- select -')) +
$statusOptions,
181 $this->addElement('checkbox',
183 ts('Send Confirmation?'), NULL,
184 array('onclick' => "showHideByValue('send_receipt','','notice','table-row','radio',false); showHideByValue('send_receipt','','from-email','table-row','radio',false);")
187 $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails
['from_email_id']);
189 $this->add('textarea', 'receipt_text', ts('Confirmation Message'));
191 $noteAttributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Note');
192 $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
196 'name' => ts('Save'),
200 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($this->_participantId
)) {
203 'name' => ts('Save and Record Payment'),
209 'name' => ts('Cancel'),
212 $this->addButtons($buttons);
213 $this->addFormRule(array('CRM_Event_Form_ParticipantFeeSelection', 'formRule'), $this);
223 static function formRule($fields, $files, $self) {
228 public function postProcess() {
229 $params = $this->controller
->exportValues($this->_name
);
231 $feeBlock = $this->_values
['fee'];
232 $lineItems = $this->_values
['line_items'];
233 CRM_Event_BAO_Participant
::changeFeeSelections($params, $this->_participantId
, $this->_contributionId
, $feeBlock, $lineItems, $this->_paidAmount
, $params['priceSetId']);
234 $this->contributionAmt
= CRM_Core_DAO
::getFieldValue('CRM_Contribute_BAO_Contribution', $this->_contributionId
, 'total_amount');
236 if (CRM_Utils_Array
::value('send_receipt', $params)){
237 $fetchParticipantVals = array('id' => $this->_participantId
);
238 CRM_Event_BAO_Participant
::getValues($fetchParticipantVals, $participantDetails, CRM_Core_DAO
::$_nullArray);
239 $participantParams = array_merge($params, $participantDetails[$this->_participantId
]);
240 $mailSent = $this->emailReceipt($participantParams);
243 // update participant
244 CRM_Core_DAO
::setFieldValue('CRM_Event_DAO_Participant', $this->_participantId
, 'status_id', $params['status_id']);
245 if(!empty($params['note'])) {
247 'entity_table' => 'civicrm_participant',
248 'note' => $params['note'],
249 'entity_id' => $this->_participantId
,
250 'contact_id' => $this->_contactId
,
251 'modified_date' => date('Ymd'),
253 CRM_Core_BAO_Note
::add($noteParams);
255 CRM_Core_Session
::setStatus(ts("The fee selection has been changed for this participant"), ts('Saved'), 'success');
257 $buttonName = $this->controller
->getButtonName();
258 if ($buttonName == $this->getButtonName('upload', 'new')) {
259 $session = CRM_Core_Session
::singleton();
260 $session->pushUserContext(CRM_Utils_System
::url('civicrm/payment/add',
261 "reset=1&action=add&component=event&id={$this->_participantId}&cid={$this->_contactId}"
271 function emailReceipt(&$params) {
272 $updatedLineItem = CRM_Price_BAO_LineItem
::getLineItems($this->_participantId
, 'participant', NULL, FALSE);
274 if ($updatedLineItem) {
275 $lineItem[] = $updatedLineItem;
277 $this->assign('lineItem', empty($lineItem) ?
FALSE : $lineItem);
279 // offline receipt sending
280 if (array_key_exists($params['from_email_address'], $this->_fromEmails
['from_email_id'])) {
281 $receiptFrom = $params['from_email_address'];
284 $this->assign('module', 'Event Registration');
285 //use of the message template below requires variables in different format
286 $event = $events = array();
287 $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
289 //get all event details.
290 CRM_Core_DAO
::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
291 $event = $events[$params['event_id']];
292 unset($event['start_date']);
293 unset($event['end_date']);
295 $role = CRM_Event_PseudoConstant
::participantRole();
296 $participantRoles = CRM_Utils_Array
::value('role_id', $params);
297 if (is_array($participantRoles)) {
298 $selectedRoles = array();
299 foreach (array_keys($participantRoles) as $roleId) {
300 $selectedRoles[] = $role[$roleId];
302 $event['participant_role'] = implode(', ', $selectedRoles);
305 $event['participant_role'] = CRM_Utils_Array
::value($participantRoles, $role);
307 $event['is_monetary'] = $this->_isPaidEvent
;
309 if ($params['receipt_text']) {
310 $event['confirm_email_text'] = $params['receipt_text'];
313 $this->assign('isAmountzero', 1);
314 $this->assign('event', $event);
316 $this->assign('isShowLocation', $event['is_show_location']);
317 if (CRM_Utils_Array
::value('is_show_location', $event) == 1) {
318 $locationParams = array(
319 'entity_id' => $params['event_id'],
320 'entity_table' => 'civicrm_event',
322 $location = CRM_Core_BAO_Location
::getValues($locationParams, TRUE);
323 $this->assign('location', $location);
326 $status = CRM_Event_PseudoConstant
::participantStatus();
327 if ($this->_isPaidEvent
) {
328 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
330 if (isset($params['payment_instrument_id'])) {
331 $this->assign('paidBy',
332 CRM_Utils_Array
::value($params['payment_instrument_id'],
339 $this->assign('totalAmount', $this->contributionAmt
);
341 $this->assign('isPrimary', 1);
342 $this->assign('checkNumber', CRM_Utils_Array
::value('check_number', $params));
345 $this->assign('register_date', $params['register_date']);
346 $template = CRM_Core_Smarty
::singleton();
348 // Retrieve the name and email of the contact - this will be the TO for receipt email
349 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($this->_contactId
);
351 $this->_contributorDisplayName
= ($this->_contributorDisplayName
== ' ') ?
$this->_contributorEmail
: $this->_contributorDisplayName
;
353 $waitStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
354 if ($waitingStatus = CRM_Utils_Array
::value($params['status_id'], $waitStatus)) {
355 $this->assign('isOnWaitlist', TRUE);
357 $this->assign('contactID', $this->_contactId
);
358 $this->assign('participantID', $this->_participantId
);
360 $sendTemplateParams = array(
361 'groupName' => 'msg_tpl_workflow_event',
362 'valueName' => 'event_offline_receipt',
363 'contactId' => $this->_contactId
,
365 'PDFFilename' => ts('confirmation').'.pdf',
368 // try to send emails only if email id is present
369 // and the do-not-email option is not checked for that contact
370 if ($this->_contributorEmail
&& !$this->_toDoNotEmail
) {
371 $sendTemplateParams['from'] = $receiptFrom;
372 $sendTemplateParams['toName'] = $this->_contributorDisplayName
;
373 $sendTemplateParams['toEmail'] = $this->_contributorEmail
;
374 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc', $this->_fromEmails
);
375 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc', $this->_fromEmails
);
378 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);