3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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 protected $_contactId = NULL;
45 protected $_contributorDisplayName = NULL;
47 protected $_contributorEmail = NULL;
49 protected $_toDoNotEmail = NULL;
51 protected $_contributionId = NULL;
53 protected $fromEmailId = NULL;
55 protected $_eventId = NULL;
57 public $_action = NULL;
59 public $_values = NULL;
61 public $_participantId = NULL;
63 protected $_participantStatus = NULL;
65 protected $_paidAmount = NULL;
67 public $_isPaidEvent = NULL;
69 protected $contributionAmt = NULL;
71 public function preProcess() {
72 $this->_participantId
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
73 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
74 $this->_eventId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_participantId
, 'event_id');
75 $this->_fromEmails
= CRM_Event_BAO_Event
::getFromEmailIds($this->_eventId
);
77 $this->_contributionId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participantId
, 'contribution_id', 'participant_id');
78 if ($this->_contributionId
) {
79 $this->_isPaidEvent
= TRUE;
81 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, TRUE);
83 list($this->_contributorDisplayName
, $this->_contributorEmail
) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($this->_contactId
);
84 $this->assign('displayName', $this->_contributorDisplayName
);
85 $this->assign('email', $this->_contributorEmail
);
87 $this->_participantStatus
= CRM_Core_DAO
::getFieldValue('CRM_Event_BAO_Participant', $this->_participantId
, 'status_id');
88 //set the payment mode - _mode property is defined in parent class
89 $this->_mode
= CRM_Utils_Request
::retrieve('mode', 'String', $this);
91 $this->assign('contactId', $this->_contactId
);
92 $this->assign('id', $this->_participantId
);
94 $paymentInfo = CRM_Contribute_BAO_Contribution
::getPaymentInfo($this->_participantId
, 'event');
95 $this->_paidAmount
= $paymentInfo['paid'];
96 $this->assign('paymentInfo', $paymentInfo);
97 CRM_Core_Resources
::singleton()->addSetting(array('feePaid' => $this->_paidAmount
));
99 $title = "Change selections for {$this->_contributorDisplayName}";
101 CRM_Utils_System
::setTitle(ts('%1', array(1 => $title)));
105 public function setDefaultValues() {
106 $params = array('id' => $this->_participantId
);
108 CRM_Event_BAO_Participant
::getValues($params, $defaults, $ids);
109 $priceSetId = CRM_Price_BAO_PriceSet
::getFor('civicrm_event', $this->_eventId
);
111 $priceSetValues = CRM_Event_Form_EventFees
::setDefaultPriceSet($this->_participantId
, $this->_eventId
);
112 if (!empty($priceSetValues)) {
113 $defaults[$this->_participantId
] = array_merge($defaults[$this->_participantId
], $priceSetValues);
116 $this->assign('totalAmount', CRM_Utils_Array
::value('fee_amount', $defaults[$this->_participantId
]));
117 if ($this->_action
== CRM_Core_Action
::UPDATE
) {
118 $fee_level = $defaults[$this->_participantId
]['fee_level'];
119 CRM_Event_BAO_Participant
::fixEventLevel($fee_level);
120 $this->assign('fee_level', $fee_level);
121 $this->assign('fee_amount', CRM_Utils_Array
::value('fee_amount', $defaults[$this->_participantId
]));
123 $defaults = $defaults[$this->_participantId
];
127 public function buildQuickForm() {
128 CRM_Core_Resources
::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
130 $statuses = CRM_Event_PseudoConstant
::participantStatus();
131 CRM_Core_Resources
::singleton()->addSetting(array(
132 'partiallyPaid' => array_search('Partially paid', $statuses),
133 'pendingRefund' => array_search('Pending refund', $statuses),
134 'participantStatus' => $this->_participantStatus
137 $config = CRM_Core_Config
::singleton();
138 $this->assign('currencySymbol', $config->defaultCurrencySymbol
);
141 $lineItem = $event = array();
142 $params = array('id' => $this->_eventId
);
143 CRM_Event_BAO_Event
::retrieve($params, $event);
145 //retrieve custom information
146 $this->_values
= array();
147 CRM_Event_Form_Registration
::initEventFee($this, $event['id']);
148 CRM_Event_Form_Registration_Register
::buildAmount($this, TRUE);
150 if (!CRM_Utils_System
::isNull(CRM_Utils_Array
::value('line_items', $this->_values
))) {
151 $lineItem[] = $this->_values
['line_items'];
153 $this->assign('lineItem', empty($lineItem) ?
FALSE : $lineItem);
154 $event = CRM_Event_BAO_Event
::getEvents(0, $this->_eventId
);
155 $this->assign('eventName', $event[$this->_eventId
]);
157 $statusOptions = CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label');
158 $this->add('select', 'status_id', ts('Participant Status'),
160 '' => ts('- select -')) +
$statusOptions,
164 $this->addElement('checkbox',
166 ts('Send Confirmation?'), NULL,
167 array('onclick' => "showHideByValue('send_receipt','','notice','table-row','radio',false); showHideByValue('send_receipt','','from-email','table-row','radio',false);")
170 $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails
['from_email_id']);
172 $this->add('textarea', 'receipt_text', ts('Confirmation Message'));
174 $noteAttributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Note');
175 $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
179 'name' => ts('Save'),
185 'name' => ts('Save and Record Payment'),
191 'name' => ts('Cancel'),
194 $this->addButtons($buttons);
195 $this->addFormRule(array('CRM_Event_Form_ParticipantFeeSelection', 'formRule'), $this);
198 static function formRule($fields, $files, $self) {
203 public function postProcess() {
204 $params = $this->controller
->exportValues($this->_name
);
206 $feeBlock = $this->_values
['fee'];
207 $lineItems = $this->_values
['line_items'];
208 CRM_Event_BAO_Participant
::changeFeeSelections($params, $this->_participantId
, $this->_contributionId
, $feeBlock, $lineItems, $this->_paidAmount
, $params['priceSetId']);
209 $this->contributionAmt
= CRM_Core_DAO
::getFieldValue('CRM_Contribute_BAO_Contribution', $this->_contributionId
, 'total_amount');
211 if (CRM_Utils_Array
::value('send_receipt', $params)){
212 $fetchParticipantVals = array('id' => $this->_participantId
);
213 CRM_Event_BAO_Participant
::getValues($fetchParticipantVals, $participantDetails, CRM_Core_DAO
::$_nullArray);
214 $participantParams = array_merge($params, $participantDetails[$this->_participantId
]);
215 $mailSent = $this->emailReceipt($participantParams);
218 // update participant
219 CRM_Core_DAO
::setFieldValue('CRM_Event_DAO_Participant', $this->_participantId
, 'status_id', $params['status_id']);
220 if(!empty($params['note'])) {
222 'entity_table' => 'civicrm_participant',
223 'note' => $params['note'],
224 'entity_id' => $this->_participantId
,
225 'contact_id' => $this->_contactId
,
226 'modified_date' => date('Ymd'),
228 CRM_Core_BAO_Note
::add($noteParams);
230 CRM_Core_Session
::setStatus(ts("The fee selection has been changed for this participant"), ts('Saved'), 'success');
232 $buttonName = $this->controller
->getButtonName();
233 if ($buttonName == $this->getButtonName('upload', 'new')) {
234 $session = CRM_Core_Session
::singleton();
235 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/payment/add',
236 "reset=1&action=add&component=event&id={$this->_participantId}&cid={$this->_contactId}"
241 function emailReceipt(&$params) {
242 // offline receipt sending
243 if (array_key_exists($params['from_email_address'], $this->_fromEmails
['from_email_id'])) {
244 $receiptFrom = $params['from_email_address'];
247 $this->assign('module', 'Event Registration');
248 //use of the message template below requires variables in different format
249 $event = $events = array();
250 $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
252 //get all event details.
253 CRM_Core_DAO
::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
254 $event = $events[$params['event_id']];
255 unset($event['start_date']);
256 unset($event['end_date']);
258 $role = CRM_Event_PseudoConstant
::participantRole();
259 $participantRoles = CRM_Utils_Array
::value('role_id', $params);
260 if (is_array($participantRoles)) {
261 $selectedRoles = array();
262 foreach (array_keys($participantRoles) as $roleId) {
263 $selectedRoles[] = $role[$roleId];
265 $event['participant_role'] = implode(', ', $selectedRoles);
268 $event['participant_role'] = CRM_Utils_Array
::value($participantRoles, $role);
270 $event['is_monetary'] = $this->_isPaidEvent
;
272 if ($params['receipt_text']) {
273 $event['confirm_email_text'] = $params['receipt_text'];
276 $this->assign('isAmountzero', 1);
277 $this->assign('event', $event);
279 $this->assign('isShowLocation', $event['is_show_location']);
280 if (CRM_Utils_Array
::value('is_show_location', $event) == 1) {
281 $locationParams = array(
282 'entity_id' => $params['event_id'],
283 'entity_table' => 'civicrm_event',
285 $location = CRM_Core_BAO_Location
::getValues($locationParams, TRUE);
286 $this->assign('location', $location);
289 $status = CRM_Event_PseudoConstant
::participantStatus();
290 if ($this->_isPaidEvent
) {
291 $paymentInstrument = CRM_Contribute_PseudoConstant
::paymentInstrument();
293 if (isset($params['payment_instrument_id'])) {
294 $this->assign('paidBy',
295 CRM_Utils_Array
::value($params['payment_instrument_id'],
302 $this->assign('totalAmount', $this->contributionAmt
);
304 $this->assign('isPrimary', 1);
305 $this->assign('checkNumber', CRM_Utils_Array
::value('check_number', $params));
308 $this->assign('register_date', $params['register_date']);
309 $template = CRM_Core_Smarty
::singleton();
311 // Retrieve the name and email of the contact - this will be the TO for receipt email
312 list($this->_contributorDisplayName
, $this->_contributorEmail
, $this->_toDoNotEmail
) = CRM_Contact_BAO_Contact
::getContactDetails($this->_contactId
);
314 $this->_contributorDisplayName
= ($this->_contributorDisplayName
== ' ') ?
$this->_contributorEmail
: $this->_contributorDisplayName
;
316 $waitStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
317 if ($waitingStatus = CRM_Utils_Array
::value($params['status_id'], $waitStatus)) {
318 $this->assign('isOnWaitlist', TRUE);
320 $this->assign('contactID', $this->_contactId
);
321 $this->assign('participantID', $this->_participantId
);
323 $sendTemplateParams = array(
324 'groupName' => 'msg_tpl_workflow_event',
325 'valueName' => 'event_offline_receipt',
326 'contactId' => $this->_contactId
,
328 'PDFFilename' => ts('confirmation').'.pdf',
331 // try to send emails only if email id is present
332 // and the do-not-email option is not checked for that contact
333 if ($this->_contributorEmail
&& !$this->_toDoNotEmail
) {
334 $sendTemplateParams['from'] = $receiptFrom;
335 $sendTemplateParams['toName'] = $this->_contributorDisplayName
;
336 $sendTemplateParams['toEmail'] = $this->_contributorEmail
;
337 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc', $this->_fromEmails
);
338 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc', $this->_fromEmails
);
341 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);