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 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);
68 $this->_eventId
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $this->_participantId
, 'event_id');
69 $this->_fromEmails
= CRM_Event_BAO_Event
::getFromEmailIds($this->_eventId
);
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;
75 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, TRUE);
77 list($this->_contributorDisplayName
, $this->_contributorEmail
) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($this->_contactId
);
78 $this->assign('displayName', $this->_contributorDisplayName
);
79 $this->assign('email', $this->_contributorEmail
);
81 $this->_participantStatus
= CRM_Core_DAO
::getFieldValue('CRM_Event_BAO_Participant', $this->_participantId
, 'status_id');
82 //set the payment mode - _mode property is defined in parent class
83 $this->_mode
= CRM_Utils_Request
::retrieve('mode', 'String', $this);
85 $this->assign('contactId', $this->_contactId
);
86 $this->assign('id', $this->_participantId
);
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']));
92 $title = "Change selections for {$this->_contributorDisplayName}";
94 CRM_Utils_System
::setTitle(ts('%1', array(1 => $title)));
98 public function setDefaultValues() {
99 $params = array('id' => $this->_participantId
);
101 CRM_Event_BAO_Participant
::getValues($params, $defaults, $ids);
102 $priceSetId = CRM_Price_BAO_PriceSet
::getFor('civicrm_event', $this->_eventId
);
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);
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
]));
116 $defaults = $defaults[$this->_participantId
];
120 public function buildQuickForm() {
121 CRM_Core_Resources
::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
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),
127 'participantStatus' => $this->_participantStatus
130 $config = CRM_Core_Config
::singleton();
131 $this->assign('currencySymbol', $config->defaultCurrencySymbol
);
134 $lineItem = $event = array();
135 $params = array('id' => $this->_eventId
);
136 CRM_Event_BAO_Event
::retrieve($params, $event);
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);
143 if (!CRM_Utils_System
::isNull(CRM_Utils_Array
::value('line_items', $this->_values
))) {
144 $lineItem[] = $this->_values
['line_items'];
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
]);
150 $statusOptions = CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label');
151 $this->add('select', 'status_id', ts('Participant Status'),
153 '' => ts('- select -')) +
$statusOptions,
157 $this->addElement('checkbox',
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);")
163 $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails
['from_email_id']);
165 $this->add('textarea', 'receipt_text', ts('Confirmation Message'));
167 $noteAttributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Note');
168 $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
172 'name' => ts('Save'),
178 'name' => ts('Save and Record Payment'),
184 'name' => ts('Cancel'),
187 $this->addButtons($buttons);
188 $this->addFormRule(array('CRM_Event_Form_ParticipantFeeSelection', 'formRule'), $this);
191 static function formRule($fields, $files, $self) {
196 public function postProcess() {
197 $params = $this->controller
->exportValues($this->_name
);
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}"
207 static function emailReceipt(&$form, &$params) {
208 // email receipt sending