First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
515
sites/all/modules/civicrm/CRM/Event/Form/EventFees.php
Normal file
515
sites/all/modules/civicrm/CRM/Event/Form/EventFees.php
Normal file
|
@ -0,0 +1,515 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for processing a participation fee block
|
||||
*/
|
||||
class CRM_Event_Form_EventFees {
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function preProcess(&$form) {
|
||||
//as when call come from register.php
|
||||
if (!$form->_eventId) {
|
||||
$form->_eventId = CRM_Utils_Request::retrieve('eventId', 'Positive', $form);
|
||||
}
|
||||
|
||||
$form->_pId = CRM_Utils_Request::retrieve('participantId', 'Positive', $form);
|
||||
$form->_discountId = CRM_Utils_Request::retrieve('discountId', 'Positive', $form);
|
||||
|
||||
$form->_fromEmails = CRM_Event_BAO_Event::getFromEmailIds($form->_eventId);
|
||||
|
||||
//CRM-6907 set event specific currency.
|
||||
if ($form->_eventId &&
|
||||
($currency = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $form->_eventId, 'currency'))
|
||||
) {
|
||||
CRM_Core_Config::singleton()->defaultCurrency = $currency;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function sets the default values for the form in edit/view mode.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function setDefaultValues(&$form) {
|
||||
$defaults = array();
|
||||
|
||||
if ($form->_eventId) {
|
||||
//get receipt text and financial type
|
||||
$returnProperities = array('confirm_email_text', 'financial_type_id', 'campaign_id', 'start_date');
|
||||
$details = array();
|
||||
CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $form->_eventId, $details, $returnProperities);
|
||||
if (!empty($details[$form->_eventId]['financial_type_id'])) {
|
||||
$defaults[$form->_pId]['financial_type_id'] = $details[$form->_eventId]['financial_type_id'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($form->_pId) {
|
||||
$ids = array();
|
||||
$params = array('id' => $form->_pId);
|
||||
|
||||
CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
|
||||
if ($form->_action == CRM_Core_Action::UPDATE) {
|
||||
$discounts = array();
|
||||
if (!empty($form->_values['discount'])) {
|
||||
foreach ($form->_values['discount'] as $key => $value) {
|
||||
$value = current($value);
|
||||
$discounts[$key] = $value['name'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($form->_discountId && !empty($discounts[$defaults[$form->_pId]['discount_id']])) {
|
||||
$form->assign('discount', $discounts[$defaults[$form->_pId]['discount_id']]);
|
||||
}
|
||||
|
||||
$form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
|
||||
$form->assign('fee_level', CRM_Utils_Array::value('fee_level', $defaults[$form->_pId]));
|
||||
}
|
||||
$defaults[$form->_pId]['send_receipt'] = 0;
|
||||
}
|
||||
else {
|
||||
$defaults[$form->_pId]['send_receipt'] = (strtotime(CRM_Utils_Array::value('start_date', $details[$form->_eventId])) >= time()) ? 1 : 0;
|
||||
if ($form->_eventId && !empty($details[$form->_eventId]['confirm_email_text'])) {
|
||||
//set receipt text
|
||||
$defaults[$form->_pId]['receipt_text'] = $details[$form->_eventId]['confirm_email_text'];
|
||||
}
|
||||
|
||||
list($defaults[$form->_pId]['receive_date'], $defaults[$form->_pId]['receive_date_time']) = CRM_Utils_Date::setDateDefaults();
|
||||
}
|
||||
|
||||
//CRM-11601 we should keep the record contribution
|
||||
//true by default while adding participant
|
||||
if ($form->_action == CRM_Core_Action::ADD && !$form->_mode && $form->_isPaidEvent) {
|
||||
$defaults[$form->_pId]['record_contribution'] = 1;
|
||||
}
|
||||
|
||||
//CRM-13420
|
||||
if (empty($defaults['payment_instrument_id'])) {
|
||||
$defaults[$form->_pId]['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
|
||||
}
|
||||
if ($form->_mode) {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
// set default country from config if no country set
|
||||
if (empty($defaults[$form->_pId]["billing_country_id-{$form->_bltID}"])) {
|
||||
$defaults[$form->_pId]["billing_country_id-{$form->_bltID}"] = $config->defaultContactCountry;
|
||||
}
|
||||
|
||||
if (empty($defaults["billing_state_province_id-{$form->_bltID}"])) {
|
||||
$defaults[$form->_pId]["billing_state_province_id-{$form->_bltID}"] = $config->defaultContactStateProvince;
|
||||
}
|
||||
|
||||
$billingDefaults = $form->getProfileDefaults('Billing', $form->_contactId);
|
||||
$defaults[$form->_pId] = array_merge($defaults[$form->_pId], $billingDefaults);
|
||||
|
||||
// // hack to simplify credit card entry for testing
|
||||
// $defaults[$form->_pId]['credit_card_type'] = 'Visa';
|
||||
// $defaults[$form->_pId]['credit_card_number'] = '4807731747657838';
|
||||
// $defaults[$form->_pId]['cvv2'] = '000';
|
||||
// $defaults[$form->_pId]['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' );
|
||||
}
|
||||
|
||||
// if user has selected discount use that to set default
|
||||
if (isset($form->_discountId)) {
|
||||
$defaults[$form->_pId]['discount_id'] = $form->_discountId;
|
||||
|
||||
//hack to set defaults for already selected discount value
|
||||
if ($form->_action == CRM_Core_Action::UPDATE && !$form->_originalDiscountId) {
|
||||
$form->_originalDiscountId = $defaults[$form->_pId]['discount_id'];
|
||||
if ($form->_originalDiscountId) {
|
||||
$defaults[$form->_pId]['discount_id'] = $form->_originalDiscountId;
|
||||
}
|
||||
}
|
||||
$discountId = $form->_discountId;
|
||||
}
|
||||
else {
|
||||
$discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event');
|
||||
}
|
||||
|
||||
if ($discountId) {
|
||||
$priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id');
|
||||
}
|
||||
else {
|
||||
$priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $form->_eventId);
|
||||
}
|
||||
|
||||
if (($form->_action == CRM_Core_Action::ADD) && $form->_eventId && $discountId) {
|
||||
// this case is for add mode, where we show discount automatically
|
||||
$defaults[$form->_pId]['discount_id'] = $discountId;
|
||||
}
|
||||
|
||||
if ($priceSetId) {
|
||||
// get price set default values, CRM-4090
|
||||
if (in_array(get_class($form),
|
||||
array(
|
||||
'CRM_Event_Form_Participant',
|
||||
'CRM_Event_Form_Registration_Register',
|
||||
'CRM_Event_Form_Registration_AdditionalParticipant',
|
||||
)
|
||||
)) {
|
||||
$priceSetValues = self::setDefaultPriceSet($form->_pId, $form->_eventId);
|
||||
if (!empty($priceSetValues)) {
|
||||
$defaults[$form->_pId] = array_merge($defaults[$form->_pId], $priceSetValues);
|
||||
}
|
||||
}
|
||||
|
||||
if ($form->_action == CRM_Core_Action::ADD && !empty($form->_priceSet['fields'])) {
|
||||
foreach ($form->_priceSet['fields'] as $key => $val) {
|
||||
foreach ($val['options'] as $keys => $values) {
|
||||
if ($values['is_default']) {
|
||||
if (get_class($form) != 'CRM_Event_Form_Participant' && !empty($values['is_full'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($val['html_type'] == 'CheckBox') {
|
||||
$defaults[$form->_pId]["price_{$key}"][$keys] = 1;
|
||||
}
|
||||
else {
|
||||
$defaults[$form->_pId]["price_{$key}"] = $keys;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$form->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
|
||||
if ($form->_action == CRM_Core_Action::UPDATE) {
|
||||
$fee_level = $defaults[$form->_pId]['fee_level'];
|
||||
CRM_Event_BAO_Participant::fixEventLevel($fee_level);
|
||||
$form->assign('fee_level', $fee_level);
|
||||
$form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
|
||||
}
|
||||
}
|
||||
|
||||
//CRM-4453
|
||||
if (!empty($defaults[$form->_pId]['participant_fee_currency'])) {
|
||||
$form->assign('fee_currency', $defaults[$form->_pId]['participant_fee_currency']);
|
||||
}
|
||||
|
||||
// CRM-4395
|
||||
if ($contriId = $form->get('onlinePendingContributionId')) {
|
||||
$defaults[$form->_pId]['record_contribution'] = 1;
|
||||
$contribution = new CRM_Contribute_DAO_Contribution();
|
||||
$contribution->id = $contriId;
|
||||
$contribution->find(TRUE);
|
||||
foreach (array(
|
||||
'financial_type_id',
|
||||
'payment_instrument_id',
|
||||
'contribution_status_id',
|
||||
'receive_date',
|
||||
'total_amount',
|
||||
) as $f) {
|
||||
if ($f == 'receive_date') {
|
||||
list($defaults[$form->_pId]['receive_date']) = CRM_Utils_Date::setDateDefaults($contribution->$f);
|
||||
}
|
||||
else {
|
||||
$defaults[$form->_pId][$f] = $contribution->$f;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $defaults[$form->_pId];
|
||||
}
|
||||
|
||||
/**
|
||||
* This function sets the default values for price set.
|
||||
*
|
||||
* @param int $participantID
|
||||
* @param int $eventID
|
||||
* @param bool $includeQtyZero
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function setDefaultPriceSet($participantID, $eventID = NULL, $includeQtyZero = TRUE) {
|
||||
$defaults = array();
|
||||
if (!$eventID && $participantID) {
|
||||
$eventID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $participantID, 'event_id');
|
||||
}
|
||||
if (!$participantID || !$eventID) {
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
// get price set ID.
|
||||
$priceSetID = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventID);
|
||||
if (!$priceSetID) {
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
// use line items for setdefault price set fields, CRM-4090
|
||||
$lineItems[$participantID] = CRM_Price_BAO_LineItem::getLineItems($participantID, 'participant', FALSE, $includeQtyZero);
|
||||
|
||||
if (is_array($lineItems[$participantID]) &&
|
||||
!CRM_Utils_System::isNull($lineItems[$participantID])
|
||||
) {
|
||||
|
||||
$priceFields = $htmlTypes = $optionValues = array();
|
||||
foreach ($lineItems[$participantID] as $lineId => $items) {
|
||||
$priceFieldId = CRM_Utils_Array::value('price_field_id', $items);
|
||||
$priceOptionId = CRM_Utils_Array::value('price_field_value_id', $items);
|
||||
if ($priceFieldId && $priceOptionId) {
|
||||
$priceFields[$priceFieldId][] = $priceOptionId;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($priceFields)) {
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
// get all price set field html types.
|
||||
$sql = '
|
||||
SELECT id, html_type
|
||||
FROM civicrm_price_field
|
||||
WHERE id IN (' . implode(',', array_keys($priceFields)) . ')';
|
||||
$fieldDAO = CRM_Core_DAO::executeQuery($sql);
|
||||
while ($fieldDAO->fetch()) {
|
||||
$htmlTypes[$fieldDAO->id] = $fieldDAO->html_type;
|
||||
}
|
||||
|
||||
foreach ($lineItems[$participantID] as $lineId => $items) {
|
||||
$fieldId = $items['price_field_id'];
|
||||
$htmlType = CRM_Utils_Array::value($fieldId, $htmlTypes);
|
||||
if (!$htmlType) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($htmlType == 'Text') {
|
||||
$defaults["price_{$fieldId}"] = $items['qty'];
|
||||
}
|
||||
else {
|
||||
$fieldOptValues = CRM_Utils_Array::value($fieldId, $priceFields);
|
||||
if (!is_array($fieldOptValues)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($fieldOptValues as $optionId) {
|
||||
if ($htmlType == 'CheckBox') {
|
||||
$defaults["price_{$fieldId}"][$optionId] = TRUE;
|
||||
}
|
||||
else {
|
||||
$defaults["price_{$fieldId}"] = $optionId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function buildQuickForm(&$form) {
|
||||
if ($form->_eventId) {
|
||||
$form->_isPaidEvent = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $form->_eventId, 'is_monetary');
|
||||
if ($form->_isPaidEvent) {
|
||||
$form->addElement('hidden', 'hidden_feeblock', 1);
|
||||
}
|
||||
|
||||
// make sure this is for backoffice registration.
|
||||
if ($form->getName() == 'Participant') {
|
||||
$eventfullMsg = CRM_Event_BAO_Participant::eventFullMessage($form->_eventId, $form->_pId);
|
||||
$form->addElement('hidden', 'hidden_eventFullMsg', $eventfullMsg, array('id' => 'hidden_eventFullMsg'));
|
||||
}
|
||||
}
|
||||
|
||||
if ($form->_pId) {
|
||||
if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
|
||||
$form->_pId, 'contribution_id', 'participant_id'
|
||||
)
|
||||
) {
|
||||
$form->_online = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if ($form->_isPaidEvent) {
|
||||
$params = array('id' => $form->_eventId);
|
||||
CRM_Event_BAO_Event::retrieve($params, $event);
|
||||
|
||||
//retrieve custom information
|
||||
$form->_values = array();
|
||||
CRM_Event_Form_Registration::initEventFee($form, $event['id']);
|
||||
CRM_Event_Form_Registration_Register::buildAmount($form, TRUE, $form->_discountId);
|
||||
$lineItem = array();
|
||||
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
|
||||
$invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
|
||||
$totalTaxAmount = 0;
|
||||
if (!CRM_Utils_System::isNull(CRM_Utils_Array::value('line_items', $form->_values))) {
|
||||
$lineItem[] = $form->_values['line_items'];
|
||||
foreach ($form->_values['line_items'] as $key => $value) {
|
||||
$totalTaxAmount = $value['tax_amount'] + $totalTaxAmount;
|
||||
}
|
||||
}
|
||||
if ($invoicing) {
|
||||
$form->assign('totalTaxAmount', $totalTaxAmount);
|
||||
}
|
||||
$form->assign('lineItem', empty($lineItem) ? FALSE : $lineItem);
|
||||
$discounts = array();
|
||||
if (!empty($form->_values['discount'])) {
|
||||
foreach ($form->_values['discount'] as $key => $value) {
|
||||
$value = current($value);
|
||||
$discounts[$key] = $value['name'];
|
||||
}
|
||||
|
||||
$element = $form->add('select', 'discount_id',
|
||||
ts('Discount Set'),
|
||||
array(
|
||||
0 => ts('- select -'),
|
||||
) + $discounts,
|
||||
FALSE,
|
||||
array('class' => "crm-select2")
|
||||
);
|
||||
|
||||
if ($form->_online) {
|
||||
$element->freeze();
|
||||
}
|
||||
}
|
||||
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()
|
||||
&& !CRM_Utils_Array::value('fee', $form->_values)
|
||||
&& CRM_Utils_Array::value('snippet', $_REQUEST) == CRM_Core_Smarty::PRINT_NOFORM
|
||||
) {
|
||||
CRM_Core_Session::setStatus(ts('You do not have all the permissions needed for this page.'), 'Permission Denied', 'error');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CRM_Core_Payment_Form::buildPaymentForm($form, $form->_paymentProcessor, FALSE, TRUE, self::getDefaultPaymentInstrumentId());
|
||||
if (!$form->_mode) {
|
||||
$form->addElement('checkbox', 'record_contribution', ts('Record Payment?'), NULL,
|
||||
array('onclick' => "return showHideByValue('record_contribution','','payment_information','table-row','radio',false);")
|
||||
);
|
||||
// Check permissions for financial type first
|
||||
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
|
||||
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $form->_action);
|
||||
}
|
||||
else {
|
||||
$financialTypes = CRM_Contribute_PseudoConstant::financialType();
|
||||
}
|
||||
|
||||
$form->add('select', 'financial_type_id',
|
||||
ts('Financial Type'),
|
||||
array('' => ts('- select -')) + $financialTypes
|
||||
);
|
||||
|
||||
$form->addDateTime('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
|
||||
|
||||
$form->add('select', 'payment_instrument_id',
|
||||
ts('Payment Method'),
|
||||
array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(),
|
||||
FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);")
|
||||
);
|
||||
// don't show transaction id in batch update mode
|
||||
$path = CRM_Utils_System::currentPath();
|
||||
$form->assign('showTransactionId', FALSE);
|
||||
if ($path != 'civicrm/contact/search/basic') {
|
||||
$form->add('text', 'trxn_id', ts('Transaction ID'));
|
||||
$form->addRule('trxn_id', ts('Transaction ID already exists in Database.'),
|
||||
'objectExists', array('CRM_Contribute_DAO_Contribution', $form->_eventId, 'trxn_id')
|
||||
);
|
||||
$form->assign('showTransactionId', TRUE);
|
||||
}
|
||||
|
||||
$form->add('select', 'contribution_status_id',
|
||||
ts('Payment Status'), CRM_Contribute_BAO_Contribution_Utils::getContributionStatuses('participant')
|
||||
);
|
||||
|
||||
$form->add('text', 'check_number', ts('Check Number'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number')
|
||||
);
|
||||
|
||||
$form->add('text', 'total_amount', ts('Amount'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'total_amount')
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$form->add('text', 'amount', ts('Event Fee(s)'));
|
||||
}
|
||||
$form->assign('onlinePendingContributionId', $form->get('onlinePendingContributionId'));
|
||||
|
||||
$form->assign('paid', $form->_isPaidEvent);
|
||||
|
||||
$form->addElement('checkbox',
|
||||
'send_receipt',
|
||||
ts('Send Confirmation?'), NULL,
|
||||
array('onclick' => "showHideByValue('send_receipt','','notice','table-row','radio',false); showHideByValue('send_receipt','','from-email','table-row','radio',false);")
|
||||
);
|
||||
|
||||
$form->add('select', 'from_email_address', ts('Receipt From'), $form->_fromEmails['from_email_id']);
|
||||
|
||||
$form->add('textarea', 'receipt_text', ts('Confirmation Message'));
|
||||
|
||||
// Retrieve the name and email of the contact - form will be the TO for receipt email ( only if context is not standalone)
|
||||
if ($form->_context != 'standalone') {
|
||||
if ($form->_contactId) {
|
||||
list($form->_contributorDisplayName,
|
||||
$form->_contributorEmail
|
||||
) = CRM_Contact_BAO_Contact_Location::getEmailDetails($form->_contactId);
|
||||
$form->assign('email', $form->_contributorEmail);
|
||||
}
|
||||
else {
|
||||
//show email block for batch update for event
|
||||
$form->assign('batchEmail', TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
$mailingInfo = Civi::settings()->get('mailing_backend');
|
||||
$form->assign('outBound_option', $mailingInfo['outBound_option']);
|
||||
$form->assign('hasPayment', $form->_paymentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default payment instrument id.
|
||||
*
|
||||
* @todo resolve relationship between this form & abstractEdit -which should be it's parent.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected static function getDefaultPaymentInstrumentId() {
|
||||
$paymentInstrumentID = CRM_Utils_Request::retrieve('payment_instrument_id', 'Integer');
|
||||
if ($paymentInstrumentID) {
|
||||
return $paymentInstrumentID;
|
||||
}
|
||||
return key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
|
||||
}
|
||||
|
||||
}
|
429
sites/all/modules/civicrm/CRM/Event/Form/ManageEvent.php
Normal file
429
sites/all/modules/civicrm/CRM/Event/Form/ManageEvent.php
Normal file
|
@ -0,0 +1,429 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for processing Event.
|
||||
*/
|
||||
class CRM_Event_Form_ManageEvent extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The id of the event we are processing.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_id;
|
||||
|
||||
/**
|
||||
* Is this the first page?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_first = FALSE;
|
||||
|
||||
/**
|
||||
* Are we in single form mode or wizard mode?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_single;
|
||||
|
||||
public $_action;
|
||||
|
||||
/**
|
||||
* Are we actually managing an event template?
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_isTemplate = FALSE;
|
||||
|
||||
/**
|
||||
* Pre-populate fields based on this template event_id
|
||||
* @var integer
|
||||
*/
|
||||
protected $_templateId;
|
||||
|
||||
protected $_cancelURL = NULL;
|
||||
|
||||
/**
|
||||
* The campaign id of the existing event, we use this to know if we need to update
|
||||
* the participant records
|
||||
*/
|
||||
protected $_campaignID = NULL;
|
||||
|
||||
/**
|
||||
* Check if repeating event.
|
||||
*/
|
||||
public $_isRepeatingEvent;
|
||||
|
||||
/**
|
||||
* Explicitly declare the entity api name.
|
||||
*/
|
||||
public function getDefaultEntity() {
|
||||
return 'Event';
|
||||
}
|
||||
|
||||
/**
|
||||
* Explicitly declare the form context.
|
||||
*/
|
||||
public function getDefaultContext() {
|
||||
return 'create';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
if (in_array('CiviEvent', $config->enableComponents)) {
|
||||
$this->assign('CiviEvent', TRUE);
|
||||
}
|
||||
CRM_Core_Form_RecurringEntity::preProcess('civicrm_event');
|
||||
|
||||
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST');
|
||||
|
||||
$this->assign('action', $this->_action);
|
||||
|
||||
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET');
|
||||
if ($this->_id) {
|
||||
$this->_isRepeatingEvent = CRM_Core_BAO_RecurringEntity::getParentFor($this->_id, 'civicrm_event');
|
||||
$this->assign('eventId', $this->_id);
|
||||
if (!empty($this->_addBlockName) && empty($this->_addProfileBottom) && empty($this->_addProfileBottomAdd)) {
|
||||
$this->add('hidden', 'id', $this->_id);
|
||||
}
|
||||
$this->_single = TRUE;
|
||||
|
||||
$params = array('id' => $this->_id);
|
||||
CRM_Event_BAO_Event::retrieve($params, $eventInfo);
|
||||
|
||||
// its an update mode, do a permission check
|
||||
if (!CRM_Event_BAO_Event::checkPermission($this->_id, CRM_Core_Permission::EDIT)) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
|
||||
}
|
||||
|
||||
$participantListingID = CRM_Utils_Array::value('participant_listing_id', $eventInfo);
|
||||
//CRM_Core_DAO::getFieldValue( 'CRM_Event_DAO_Event', $this->_id, 'participant_listing_id' );
|
||||
if ($participantListingID) {
|
||||
$participantListingURL = CRM_Utils_System::url('civicrm/event/participant',
|
||||
"reset=1&id={$this->_id}",
|
||||
TRUE, NULL, TRUE, TRUE
|
||||
);
|
||||
$this->assign('participantListingURL', $participantListingURL);
|
||||
}
|
||||
|
||||
$this->assign('isOnlineRegistration', CRM_Utils_Array::value('is_online_registration', $eventInfo));
|
||||
|
||||
$this->assign('id', $this->_id);
|
||||
}
|
||||
|
||||
// figure out whether we’re handling an event or an event template
|
||||
if ($this->_id) {
|
||||
$this->_isTemplate = CRM_Utils_Array::value('is_template', $eventInfo);
|
||||
}
|
||||
elseif ($this->_action & CRM_Core_Action::ADD) {
|
||||
$this->_isTemplate = CRM_Utils_Request::retrieve('is_template', 'Boolean', $this);
|
||||
}
|
||||
|
||||
$this->assign('isTemplate', $this->_isTemplate);
|
||||
|
||||
if ($this->_id) {
|
||||
if ($this->_isTemplate) {
|
||||
$title = CRM_Utils_Array::value('template_title', $eventInfo);
|
||||
CRM_Utils_System::setTitle(ts('Edit Event Template') . " - $title");
|
||||
}
|
||||
else {
|
||||
$configureText = ts('Configure Event');
|
||||
$title = CRM_Utils_Array::value('title', $eventInfo);
|
||||
//If it is a repeating event change title
|
||||
if ($this->_isRepeatingEvent) {
|
||||
$configureText = 'Configure Repeating Event';
|
||||
}
|
||||
CRM_Utils_System::setTitle($configureText . " - $title");
|
||||
}
|
||||
$this->assign('title', $title);
|
||||
}
|
||||
elseif ($this->_action & CRM_Core_Action::ADD) {
|
||||
if ($this->_isTemplate) {
|
||||
$title = ts('New Event Template');
|
||||
CRM_Utils_System::setTitle($title);
|
||||
}
|
||||
else {
|
||||
$title = ts('New Event');
|
||||
CRM_Utils_System::setTitle($title);
|
||||
}
|
||||
$this->assign('title', $title);
|
||||
}
|
||||
|
||||
if (CRM_Core_Permission::check('view event participants') &&
|
||||
CRM_Core_Permission::check('view all contacts')
|
||||
) {
|
||||
$statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1', 'label');
|
||||
$statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0', 'label');
|
||||
$findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
|
||||
$findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
|
||||
$this->assign('findParticipants', $findParticipants);
|
||||
}
|
||||
|
||||
$this->_templateId = (int) CRM_Utils_Request::retrieve('template_id', 'Integer', $this);
|
||||
|
||||
//Is a repeating event
|
||||
if ($this->_isRepeatingEvent) {
|
||||
$isRepeatingEntity = TRUE;
|
||||
$this->assign('isRepeatingEntity', $isRepeatingEntity);
|
||||
}
|
||||
|
||||
// CRM-16776 - show edit/copy/create buttons for Profiles if user has required permission.
|
||||
$ufGroups = CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id');
|
||||
$ufCreate = CRM_ACL_API::group(CRM_Core_Permission::CREATE, NULL, 'civicrm_uf_group', $ufGroups);
|
||||
$ufEdit = CRM_ACL_API::group(CRM_Core_Permission::EDIT, NULL, 'civicrm_uf_group', $ufGroups);
|
||||
$checkPermission = array(
|
||||
array(
|
||||
'administer CiviCRM',
|
||||
'manage event profiles',
|
||||
),
|
||||
);
|
||||
if (CRM_Core_Permission::check($checkPermission) || !empty($ufCreate) || !empty($ufEdit)) {
|
||||
$this->assign('perm', TRUE);
|
||||
}
|
||||
|
||||
// also set up tabs
|
||||
CRM_Event_Form_ManageEvent_TabHeader::build($this);
|
||||
|
||||
// Set Done button URL and breadcrumb. Templates go back to Manage Templates,
|
||||
// otherwise go to Manage Event for new event or ManageEventEdit if event if exists.
|
||||
$breadCrumb = array();
|
||||
if (!$this->_isTemplate) {
|
||||
if ($this->_id) {
|
||||
$this->_doneUrl = CRM_Utils_System::url(CRM_Utils_System::currentPath(),
|
||||
"action=update&reset=1&id={$this->_id}"
|
||||
);
|
||||
}
|
||||
else {
|
||||
$this->_doneUrl = CRM_Utils_System::url('civicrm/event/manage',
|
||||
'reset=1'
|
||||
);
|
||||
$breadCrumb = array(
|
||||
array(
|
||||
'title' => ts('Manage Events'),
|
||||
'url' => $this->_doneUrl,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->_doneUrl = CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1');
|
||||
$breadCrumb = array(
|
||||
array(
|
||||
'title' => ts('Manage Event Templates'),
|
||||
'url' => $this->_doneUrl,
|
||||
),
|
||||
);
|
||||
}
|
||||
CRM_Utils_System::appendBreadCrumb($breadCrumb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* For edit/view mode the default values are retrieved from the database.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
if (isset($this->_id)) {
|
||||
$params = array('id' => $this->_id);
|
||||
CRM_Event_BAO_Event::retrieve($params, $defaults);
|
||||
|
||||
$this->_campaignID = CRM_Utils_Array::value('campaign_id', $defaults);
|
||||
}
|
||||
elseif ($this->_templateId) {
|
||||
$params = array('id' => $this->_templateId);
|
||||
CRM_Event_BAO_Event::retrieve($params, $defaults);
|
||||
$defaults['is_template'] = $this->_isTemplate;
|
||||
$defaults['template_id'] = $defaults['id'];
|
||||
unset($defaults['id']);
|
||||
}
|
||||
else {
|
||||
$defaults['is_active'] = 1;
|
||||
$defaults['style'] = 'Inline';
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
|
||||
$this->_cancelURL = CRM_Utils_Array::value('cancelURL', $_POST);
|
||||
|
||||
if (!$this->_cancelURL) {
|
||||
if ($this->_isTemplate) {
|
||||
$this->_cancelURL = CRM_Utils_System::url('civicrm/admin/eventTemplate',
|
||||
'reset=1'
|
||||
);
|
||||
}
|
||||
else {
|
||||
$this->_cancelURL = CRM_Utils_System::url('civicrm/event/manage',
|
||||
'reset=1'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_cancelURL) {
|
||||
$this->addElement('hidden', 'cancelURL', $this->_cancelURL);
|
||||
}
|
||||
|
||||
if ($this->_single) {
|
||||
$buttons = array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save and Done'),
|
||||
'spacing' => ' ',
|
||||
'subName' => 'done',
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
);
|
||||
$this->addButtons($buttons);
|
||||
}
|
||||
else {
|
||||
$buttons = array();
|
||||
if (!$this->_first) {
|
||||
$buttons[] = array(
|
||||
'type' => 'back',
|
||||
'name' => ts('Previous'),
|
||||
'spacing' => ' ',
|
||||
);
|
||||
}
|
||||
$buttons[] = array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Continue'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
);
|
||||
$buttons[] = array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
);
|
||||
|
||||
$this->addButtons($buttons);
|
||||
}
|
||||
$session->replaceUserContext($this->_cancelURL);
|
||||
$this->add('hidden', 'is_template', $this->_isTemplate);
|
||||
}
|
||||
|
||||
public function endPostProcess() {
|
||||
// make submit buttons keep the current working tab opened.
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
$className = CRM_Utils_String::getClassName($this->_name);
|
||||
|
||||
// hack for special cases.
|
||||
switch ($className) {
|
||||
case 'Event':
|
||||
$attributes = $this->getVar('_attributes');
|
||||
$subPage = strtolower(basename(CRM_Utils_Array::value('action', $attributes)));
|
||||
break;
|
||||
|
||||
case 'EventInfo':
|
||||
$subPage = 'settings';
|
||||
break;
|
||||
|
||||
case 'ScheduleReminders':
|
||||
$subPage = 'reminder';
|
||||
break;
|
||||
|
||||
default:
|
||||
$subPage = strtolower($className);
|
||||
break;
|
||||
}
|
||||
|
||||
CRM_Core_Session::setStatus(ts("'%1' information has been saved.",
|
||||
array(1 => CRM_Utils_Array::value('title', CRM_Utils_Array::value($subPage, $this->get('tabHeader')), $className))
|
||||
), ts('Saved'), 'success');
|
||||
|
||||
$config = CRM_Core_Config::singleton();
|
||||
if (in_array('CiviCampaign', $config->enableComponents)) {
|
||||
$values = $this->controller->exportValues($this->_name);
|
||||
$newCampaignID = CRM_Utils_Array::value('campaign_id', $values);
|
||||
$eventID = CRM_Utils_Array::value('id', $values);
|
||||
if ($eventID && $this->_campaignID != $newCampaignID) {
|
||||
CRM_Event_BAO_Event::updateParticipantCampaignID($eventID, $newCampaignID);
|
||||
}
|
||||
}
|
||||
$this->postProcessHook();
|
||||
if ($this->controller->getButtonName('submit') == "_qf_{$className}_upload_done") {
|
||||
if ($this->_isTemplate) {
|
||||
CRM_Core_Session::singleton()
|
||||
->pushUserContext(CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1'));
|
||||
}
|
||||
else {
|
||||
CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/event/manage', 'reset=1'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url("civicrm/event/manage/{$subPage}",
|
||||
"action=update&reset=1&id={$this->_id}"
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTemplateFileName() {
|
||||
if ($this->controller->getPrint() || $this->getVar('_id') <= 0 || $this->_action & CRM_Core_Action::DELETE) {
|
||||
return parent::getTemplateFileName();
|
||||
}
|
||||
else {
|
||||
// hack lets suppress the form rendering for now
|
||||
self::$_template->assign('isForm', FALSE);
|
||||
return 'CRM/Event/Form/ManageEvent/Tab.tpl';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-load libraries required by Online Registration Profile fields
|
||||
*/
|
||||
public static function addProfileEditScripts() {
|
||||
CRM_UF_Page_ProfileEditor::registerProfileScripts();
|
||||
CRM_UF_Page_ProfileEditor::registerSchemas(array('IndividualModel', 'ParticipantModel'));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for Conference Slots.
|
||||
*/
|
||||
class CRM_Event_Form_ManageEvent_Conference extends CRM_Event_Form_ManageEvent {
|
||||
|
||||
/**
|
||||
* Page action.
|
||||
*/
|
||||
public $_action;
|
||||
|
||||
/**
|
||||
* Build quick form.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$slots = CRM_Core_OptionGroup::values('conference_slot');
|
||||
|
||||
$this->add('select',
|
||||
'slot_label_id',
|
||||
ts('Conference Slot'),
|
||||
array(
|
||||
'' => ts('- select -'),
|
||||
) + $slots,
|
||||
FALSE
|
||||
);
|
||||
|
||||
$this->addEntityRef('parent_event_id', ts('Parent Event'), array(
|
||||
'entity' => 'event',
|
||||
'placeholder' => ts('- any -'),
|
||||
'select' => array('minimumInputLength' => 0),
|
||||
)
|
||||
);
|
||||
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Post process form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
$params['id'] = $this->_id;
|
||||
CRM_Event_BAO_Event::add($params);
|
||||
|
||||
parent::endPostProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Conference Slots');
|
||||
}
|
||||
|
||||
}
|
108
sites/all/modules/civicrm/CRM/Event/Form/ManageEvent/Delete.php
Normal file
108
sites/all/modules/civicrm/CRM/Event/Form/ManageEvent/Delete.php
Normal file
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is to build the form for Deleting Group.
|
||||
*/
|
||||
class CRM_Event_Form_ManageEvent_Delete extends CRM_Event_Form_ManageEvent {
|
||||
|
||||
/**
|
||||
* Page title.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_title;
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
if ($this->_isTemplate) {
|
||||
$this->_title = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'template_title');
|
||||
}
|
||||
else {
|
||||
$this->_title = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'title');
|
||||
}
|
||||
|
||||
if (!CRM_Event_BAO_Event::checkPermission($this->_id, CRM_Core_Permission::DELETE)) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->assign('title', $this->_title);
|
||||
|
||||
$buttons = array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => $this->_isTemplate ? ts('Delete Event Template') : ts('Delete Event'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
);
|
||||
$this->addButtons($buttons);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form when submitted.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$participant = new CRM_Event_DAO_Participant();
|
||||
$participant->event_id = $this->_id;
|
||||
|
||||
if ($participant->find()) {
|
||||
$searchURL = CRM_Utils_System::url('civicrm/event/search', 'reset=1');
|
||||
CRM_Core_Session::setStatus(ts('This event cannot be deleted because there are participant records linked to it. If you want to delete this event, you must first find the participants linked to this event and delete them. You can use use <a href=\'%1\'> CiviEvent >> Find Participants page </a>.',
|
||||
array(1 => $searchURL)
|
||||
), ts('Deletion Error'), 'error');
|
||||
return;
|
||||
}
|
||||
CRM_Event_BAO_Event::del($this->_id);
|
||||
if ($this->_isTemplate) {
|
||||
CRM_Core_Session::setStatus(ts("'%1' has been deleted.", array(1 => $this->_title)), ts('Template Deleted'), 'success');
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1'));
|
||||
}
|
||||
else {
|
||||
CRM_Core_Session::setStatus(ts("'%1' has been deleted.", array(1 => $this->_title)), ts('Event Deleted'), 'success');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,309 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for processing Event.
|
||||
*/
|
||||
class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent {
|
||||
|
||||
/**
|
||||
* Event type.
|
||||
*/
|
||||
protected $_eventType = NULL;
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
if ($this->_id) {
|
||||
$this->assign('entityID', $this->_id);
|
||||
$eventType = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event',
|
||||
$this->_id,
|
||||
'event_type_id'
|
||||
);
|
||||
}
|
||||
else {
|
||||
$eventType = 'null';
|
||||
}
|
||||
|
||||
$showLocation = FALSE;
|
||||
// when custom data is included in this page
|
||||
if (!empty($_POST['hidden_custom'])) {
|
||||
$this->set('type', 'Event');
|
||||
$this->set('subType', CRM_Utils_Array::value('event_type_id', $_POST));
|
||||
$this->assign('customDataSubType', CRM_Utils_Array::value('event_type_id', $_POST));
|
||||
$this->set('entityId', $this->_id);
|
||||
|
||||
CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_eventType, 1, 'Event', $this->_id);
|
||||
CRM_Custom_Form_CustomData::buildQuickForm($this);
|
||||
CRM_Custom_Form_CustomData::setDefaultValues($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* For edit/view mode he default values are retrieved from the database.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = parent::setDefaultValues();
|
||||
|
||||
// in update mode, we need to set custom data subtype to tpl
|
||||
if (!empty($defaults['event_type_id'])) {
|
||||
$this->assign('customDataSubType', $defaults['event_type_id']);
|
||||
}
|
||||
|
||||
$this->_showHide = new CRM_Core_ShowHideBlocks();
|
||||
// Show waitlist features or event_full_text if max participants set
|
||||
if (!empty($defaults['max_participants'])) {
|
||||
$this->_showHide->addShow('id-waitlist');
|
||||
if (!empty($defaults['has_waitlist'])) {
|
||||
$this->_showHide->addShow('id-waitlist-text');
|
||||
$this->_showHide->addHide('id-event_full');
|
||||
}
|
||||
else {
|
||||
$this->_showHide->addHide('id-waitlist-text');
|
||||
$this->_showHide->addShow('id-event_full');
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->_showHide->addHide('id-event_full');
|
||||
$this->_showHide->addHide('id-waitlist');
|
||||
$this->_showHide->addHide('id-waitlist-text');
|
||||
}
|
||||
|
||||
$this->_showHide->addToTemplate();
|
||||
$this->assign('elemType', 'table-row');
|
||||
|
||||
$this->assign('description', CRM_Utils_Array::value('description', $defaults));
|
||||
|
||||
// Provide suggested text for event full and waitlist messages if they're empty
|
||||
$defaults['event_full_text'] = CRM_Utils_Array::value('event_full_text', $defaults, ts('This event is currently full.'));
|
||||
|
||||
$defaults['waitlist_text'] = CRM_Utils_Array::value('waitlist_text', $defaults, ts('This event is currently full. However you can register now and get added to a waiting list. You will be notified if spaces become available.'));
|
||||
list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value('start_date', $defaults), 'activityDateTime');
|
||||
|
||||
if (!empty($defaults['end_date'])) {
|
||||
list($defaults['end_date'], $defaults['end_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['end_date'], 'activityDateTime');
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
//need to assign custom data type and subtype to the template
|
||||
$this->assign('customDataType', 'Event');
|
||||
if ($this->_eventType) {
|
||||
$this->assign('customDataSubType', $this->_eventType);
|
||||
}
|
||||
$this->assign('entityId', $this->_id);
|
||||
|
||||
$this->_first = TRUE;
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
$attributes = CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event');
|
||||
|
||||
if ($this->_isTemplate) {
|
||||
$this->add('text', 'template_title', ts('Template Title'), $attributes['template_title'], TRUE);
|
||||
}
|
||||
|
||||
if ($this->_action & CRM_Core_Action::ADD) {
|
||||
$eventTemplates = CRM_Event_PseudoConstant::eventTemplates();
|
||||
if (CRM_Utils_System::isNull($eventTemplates) && !$this->_isTemplate) {
|
||||
$url = CRM_Utils_System::url('civicrm/admin/eventTemplate', array('reset' => 1));
|
||||
CRM_Core_Session::setStatus(ts('If you find that you are creating multiple events with similar settings, you may want to use the <a href="%1">Event Templates</a> feature to streamline your workflow.', array(1 => $url)), ts('Tip'), 'info');
|
||||
}
|
||||
if (!CRM_Utils_System::isNull($eventTemplates)) {
|
||||
$this->add('select', 'template_id', ts('From Template'), array('' => ts('- select -')) + $eventTemplates, FALSE, array('class' => 'crm-select2 huge'));
|
||||
}
|
||||
// Make sure this form redirects properly
|
||||
$this->preventAjaxSubmit();
|
||||
}
|
||||
|
||||
// add event title, make required if this is not a template
|
||||
$this->add('text', 'title', ts('Event Title'), $attributes['event_title'], !$this->_isTemplate);
|
||||
|
||||
$this->addSelect('event_type_id',
|
||||
array('onChange' => "CRM.buildCustomData( 'Event', this.value );"),
|
||||
TRUE
|
||||
);
|
||||
|
||||
//CRM-7362 --add campaigns.
|
||||
$campaignId = NULL;
|
||||
if ($this->_id) {
|
||||
$campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'campaign_id');
|
||||
}
|
||||
CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
|
||||
|
||||
$this->addSelect('default_role_id', array(), TRUE);
|
||||
|
||||
$this->addSelect('participant_listing_id', array('placeholder' => ts('Disabled'), 'option_url' => NULL));
|
||||
|
||||
$this->add('textarea', 'summary', ts('Event Summary'), $attributes['summary']);
|
||||
$this->add('wysiwyg', 'description', ts('Complete Description'), $attributes['event_description'] + array('preset' => 'civievent'));
|
||||
$this->addElement('checkbox', 'is_public', ts('Public Event'));
|
||||
$this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?'));
|
||||
$this->addElement('checkbox', 'is_map', ts('Include Map to Event Location'));
|
||||
|
||||
$this->addDateTime('start_date', ts('Start Date'), FALSE, array('formatType' => 'activityDateTime'));
|
||||
$this->addDateTime('end_date', ts('End Date / Time'), FALSE, array('formatType' => 'activityDateTime'));
|
||||
|
||||
$this->add('text', 'max_participants', ts('Max Number of Participants'),
|
||||
array('onchange' => "if (this.value != '') {cj('#id-waitlist').show(); showHideByValue('has_waitlist','0','id-waitlist-text','table-row','radio',false); showHideByValue('has_waitlist','0','id-event_full','table-row','radio',true); return;} else {cj('#id-event_full, #id-waitlist, #id-waitlist-text').hide(); return;}")
|
||||
);
|
||||
$this->addRule('max_participants', ts('Max participants should be a positive number'), 'positiveInteger');
|
||||
|
||||
$participantStatuses = CRM_Event_PseudoConstant::participantStatus();
|
||||
$waitlist = 0;
|
||||
if (in_array('On waitlist', $participantStatuses) and in_array('Pending from waitlist', $participantStatuses)) {
|
||||
$this->addElement('checkbox', 'has_waitlist', ts('Offer a Waitlist?'), NULL, array('onclick' => "showHideByValue('has_waitlist','0','id-event_full','table-row','radio',true); showHideByValue('has_waitlist','0','id-waitlist-text','table-row','radio',false);"));
|
||||
$this->add('textarea', 'waitlist_text', ts('Waitlist Message'), $attributes['waitlist_text']);
|
||||
$waitlist = 1;
|
||||
}
|
||||
$this->assign('waitlist', $waitlist);
|
||||
|
||||
$this->add('textarea', 'event_full_text', ts('Message if Event Is Full'), $attributes['event_full_text']);
|
||||
|
||||
$this->addElement('checkbox', 'is_active', ts('Is this Event Active?'));
|
||||
|
||||
$this->addFormRule(array('CRM_Event_Form_ManageEvent_EventInfo', 'formRule'));
|
||||
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $values
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($values) {
|
||||
$errors = array();
|
||||
|
||||
if (!$values['is_template']) {
|
||||
if (CRM_Utils_System::isNull($values['start_date'])) {
|
||||
$errors['start_date'] = ts('Start Date and Time are required fields');
|
||||
}
|
||||
else {
|
||||
$start = CRM_Utils_Date::processDate($values['start_date']);
|
||||
$end = CRM_Utils_Date::processDate($values['end_date']);
|
||||
if (($end < $start) && ($end != 0)) {
|
||||
$errors['end_date'] = ts('End date should be after Start date.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//CRM-4286
|
||||
if (strstr($values['title'], '/')) {
|
||||
$errors['title'] = ts("Please do not use '/' in Event Title.");
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
//format params
|
||||
$params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']);
|
||||
$params['end_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('end_date', $params),
|
||||
CRM_Utils_Array::value('end_date_time', $params),
|
||||
TRUE
|
||||
);
|
||||
$params['has_waitlist'] = CRM_Utils_Array::value('has_waitlist', $params, FALSE);
|
||||
$params['is_map'] = CRM_Utils_Array::value('is_map', $params, FALSE);
|
||||
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
|
||||
$params['is_public'] = CRM_Utils_Array::value('is_public', $params, FALSE);
|
||||
$params['is_share'] = CRM_Utils_Array::value('is_share', $params, FALSE);
|
||||
$params['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, FALSE);
|
||||
$params['id'] = $this->_id;
|
||||
|
||||
$customFields = CRM_Core_BAO_CustomField::getFields('Event', FALSE, FALSE,
|
||||
CRM_Utils_Array::value('event_type_id', $params)
|
||||
);
|
||||
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params,
|
||||
$this->_id,
|
||||
'Event'
|
||||
);
|
||||
|
||||
//merge params with defaults from templates
|
||||
if (!empty($params['template_id'])) {
|
||||
$params = array_merge(CRM_Event_BAO_Event::getTemplateDefaultValues($params['template_id']), $params);
|
||||
}
|
||||
|
||||
$event = CRM_Event_BAO_Event::create($params);
|
||||
|
||||
// now that we have the event’s id, do some more template-based stuff
|
||||
if (!empty($params['template_id'])) {
|
||||
CRM_Event_BAO_Event::copy($params['template_id'], $event, TRUE);
|
||||
}
|
||||
|
||||
$this->set('id', $event->id);
|
||||
|
||||
$this->postProcessHook();
|
||||
|
||||
if ($this->_action & CRM_Core_Action::ADD) {
|
||||
$url = 'civicrm/event/manage/location';
|
||||
$urlParams = "action=update&reset=1&id={$event->id}";
|
||||
// special case for 'Save and Done' consistency.
|
||||
if ($this->controller->getButtonName('submit') == '_qf_EventInfo_upload_done') {
|
||||
$url = 'civicrm/event/manage';
|
||||
$urlParams = 'reset=1';
|
||||
CRM_Core_Session::setStatus(ts("'%1' information has been saved.",
|
||||
array(1 => $this->getTitle())
|
||||
), ts('Saved'), 'success');
|
||||
}
|
||||
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams));
|
||||
}
|
||||
|
||||
parent::endPostProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Event Information and Settings');
|
||||
}
|
||||
|
||||
}
|
816
sites/all/modules/civicrm/CRM/Event/Form/ManageEvent/Fee.php
Normal file
816
sites/all/modules/civicrm/CRM/Event/Form/ManageEvent/Fee.php
Normal file
|
@ -0,0 +1,816 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for Event Fees.
|
||||
*/
|
||||
class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent {
|
||||
|
||||
/**
|
||||
* Constants for number of options for data types of multiple option.
|
||||
*/
|
||||
const NUM_OPTION = 11;
|
||||
|
||||
/**
|
||||
* Constants for number of discounts for the event.
|
||||
*/
|
||||
const NUM_DISCOUNT = 6;
|
||||
|
||||
/**
|
||||
* Page action.
|
||||
*/
|
||||
public $_action;
|
||||
|
||||
/**
|
||||
* In Date.
|
||||
*/
|
||||
private $_inDate;
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* For edit/view mode the default values are retrieved from the database.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$parentDefaults = parent::setDefaultValues();
|
||||
|
||||
$eventId = $this->_id;
|
||||
$params = array();
|
||||
$defaults = array();
|
||||
if (isset($eventId)) {
|
||||
$params = array('id' => $eventId);
|
||||
}
|
||||
|
||||
CRM_Event_BAO_Event::retrieve($params, $defaults);
|
||||
|
||||
if (isset($eventId)) {
|
||||
$price_set_id = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventId, NULL, 1);
|
||||
|
||||
if ($price_set_id) {
|
||||
$defaults['price_set_id'] = $price_set_id;
|
||||
}
|
||||
else {
|
||||
$priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventId, NULL);
|
||||
if ($priceSetId) {
|
||||
if ($isQuick = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config')) {
|
||||
$this->assign('isQuick', $isQuick);
|
||||
$priceField = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $priceSetId, 'id', 'price_set_id');
|
||||
$options = array();
|
||||
$priceFieldOptions = CRM_Price_BAO_PriceFieldValue::getValues($priceField, $options, 'weight', TRUE);
|
||||
$defaults['price_field_id'] = $priceField;
|
||||
$countRow = 0;
|
||||
foreach ($options as $optionId => $optionValue) {
|
||||
$countRow++;
|
||||
$defaults['value'][$countRow] = CRM_Utils_Money::format($optionValue['amount'], NULL, '%a');
|
||||
$defaults['label'][$countRow] = $optionValue['label'];
|
||||
$defaults['name'][$countRow] = $optionValue['name'];
|
||||
$defaults['weight'][$countRow] = $optionValue['weight'];
|
||||
$defaults['price_field_value'][$countRow] = $optionValue['id'];
|
||||
if ($optionValue['is_default']) {
|
||||
$defaults['default'] = $countRow;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//check if discounted
|
||||
$discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($this->_id, 'civicrm_event');
|
||||
if (!empty($discountedEvent)) {
|
||||
$defaults['is_discount'] = $i = 1;
|
||||
$totalLables = $maxSize = $defaultDiscounts = array();
|
||||
foreach ($discountedEvent as $optionGroupId) {
|
||||
$defaults['discount_price_set'][] = $optionGroupId;
|
||||
$name = $defaults["discount_name[$i]"] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $optionGroupId, 'title');
|
||||
|
||||
list($defaults["discount_start_date[$i]"]) = CRM_Utils_Date::setDateDefaults(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId,
|
||||
'start_date', 'price_set_id'
|
||||
));
|
||||
list($defaults["discount_end_date[$i]"]) = CRM_Utils_Date::setDateDefaults(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $optionGroupId,
|
||||
'end_date', 'price_set_id'
|
||||
));
|
||||
$defaultDiscounts[] = CRM_Price_BAO_PriceSet::getSetDetail($optionGroupId);
|
||||
$i++;
|
||||
}
|
||||
|
||||
//avoid moving up value of lable when some labels don't
|
||||
//have a value ,fixed for CRM-3088
|
||||
$rowCount = 1;
|
||||
foreach ($defaultDiscounts as $val) {
|
||||
$discountFields = current($val);
|
||||
$discountFields = current($discountFields['fields']);
|
||||
|
||||
foreach ($discountFields['options'] as $discountFieldsval) {
|
||||
$defaults['discounted_label'][$discountFieldsval['weight']] = $discountFieldsval['label'];
|
||||
$defaults['discounted_value'][$discountFieldsval['weight']][$rowCount] = CRM_Utils_Money::format($discountFieldsval['amount'], NULL, '%a');
|
||||
$defaults['discount_option_id'][$rowCount][$discountFieldsval['weight']] = $discountFieldsval['id'];
|
||||
if (!empty($discountFieldsval['is_default'])) {
|
||||
$defaults['discounted_default'] = $discountFieldsval['weight'];
|
||||
}
|
||||
}
|
||||
$rowCount++;
|
||||
}
|
||||
//CRM-12970
|
||||
ksort($defaults['discounted_value']);
|
||||
ksort($defaults['discounted_label']);
|
||||
$rowCount = 1;
|
||||
foreach ($defaults['discounted_label'] as $key => $value) {
|
||||
if ($key != $rowCount) {
|
||||
$defaults['discounted_label'][$rowCount] = $value;
|
||||
$defaults['discounted_value'][$rowCount] = $defaults['discounted_value'][$key];
|
||||
unset($defaults['discounted_value'][$key]);
|
||||
unset($defaults['discounted_label'][$key]);
|
||||
foreach ($defaults['discount_option_id'] as &$optionIds) {
|
||||
if (array_key_exists($key, $optionIds)) {
|
||||
$optionIds[$rowCount] = $optionIds[$key];
|
||||
unset($optionIds[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$rowCount++;
|
||||
}
|
||||
|
||||
$this->set('discountSection', 1);
|
||||
$this->buildQuickForm();
|
||||
}
|
||||
elseif (!empty($defaults['label'])) {
|
||||
//if Regular Fees are present in DB and event fee page is in update mode
|
||||
$defaults['discounted_label'] = $defaults['label'];
|
||||
}
|
||||
elseif (!empty($this->_submitValues['label'])) {
|
||||
//if event is newly created, use submitted values for
|
||||
//discount labels
|
||||
if (is_array($this->_submitValues['label'])) {
|
||||
$k = 1;
|
||||
foreach ($this->_submitValues['label'] as $value) {
|
||||
if ($value) {
|
||||
$defaults['discounted_label'][$k] = $value;
|
||||
$k++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$defaults['id'] = $eventId;
|
||||
if (!empty($totalLables)) {
|
||||
$maxKey = count($totalLables) - 1;
|
||||
if (isset($maxKey) && !empty($totalLables[$maxKey]['value'])) {
|
||||
foreach ($totalLables[$maxKey]['value'] as $i => $v) {
|
||||
if ($totalLables[$maxKey]['amount_id'][$i] == CRM_Utils_Array::value('default_discount_fee_id', $defaults)) {
|
||||
$defaults['discounted_default'] = $i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($defaults['discounted_default'])) {
|
||||
$defaults['discounted_default'] = 1;
|
||||
}
|
||||
|
||||
if (!isset($defaults['is_monetary'])) {
|
||||
$defaults['is_monetary'] = 1;
|
||||
}
|
||||
|
||||
if (!isset($defaults['fee_label'])) {
|
||||
$defaults['fee_label'] = ts('Event Fee(s)');
|
||||
}
|
||||
|
||||
if (!isset($defaults['pay_later_text']) ||
|
||||
empty($defaults['pay_later_text'])
|
||||
) {
|
||||
$defaults['pay_later_text'] = ts('I will send payment by check');
|
||||
}
|
||||
|
||||
$this->_showHide = new CRM_Core_ShowHideBlocks();
|
||||
if (!$defaults['is_monetary']) {
|
||||
$this->_showHide->addHide('event-fees');
|
||||
}
|
||||
|
||||
if (isset($defaults['price_set_id'])) {
|
||||
$this->_showHide->addHide('map-field');
|
||||
}
|
||||
$this->_showHide->addToTemplate();
|
||||
$this->assign('inDate', $this->_inDate);
|
||||
if (!empty($defaults['payment_processor'])) {
|
||||
$defaults['payment_processor'] = array_fill_keys(explode(CRM_Core_DAO::VALUE_SEPARATOR,
|
||||
$defaults['payment_processor']
|
||||
), '1');
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
|
||||
$this->addYesNo('is_monetary',
|
||||
ts('Paid Event'),
|
||||
NULL,
|
||||
NULL,
|
||||
array('onclick' => "return showHideByValue('is_monetary','0','event-fees','block','radio',false);")
|
||||
);
|
||||
|
||||
//add currency element.
|
||||
$this->addCurrency('currency', ts('Currency'), FALSE);
|
||||
|
||||
$paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor();
|
||||
|
||||
$this->assign('paymentProcessor', $paymentProcessor);
|
||||
$this->addCheckBox('payment_processor', ts('Payment Processor'),
|
||||
array_flip($paymentProcessor),
|
||||
NULL, NULL, NULL, NULL,
|
||||
array(' ', ' ', ' ', '<br/>')
|
||||
);
|
||||
|
||||
// financial type
|
||||
if (!CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() ||
|
||||
(CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && CRM_Core_Permission::check('administer CiviCRM Financial Types'))) {
|
||||
$this->addSelect('financial_type_id');
|
||||
}
|
||||
else {
|
||||
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, CRM_Core_Action::ADD);
|
||||
$this->addSelect('financial_type_id', array('context' => 'search', 'options' => $financialTypes));
|
||||
}
|
||||
// add pay later options
|
||||
$this->addElement('checkbox', 'is_pay_later', ts('Enable Pay Later option?'), NULL,
|
||||
array('onclick' => "return showHideByValue('is_pay_later','','payLaterOptions','block','radio',false);")
|
||||
);
|
||||
$this->addElement('textarea', 'pay_later_text', ts('Pay Later Label'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'pay_later_text'),
|
||||
FALSE
|
||||
);
|
||||
$this->add('wysiwyg', 'pay_later_receipt', ts('Pay Later Instructions'), CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'pay_later_receipt'));
|
||||
|
||||
$this->addElement('checkbox', 'is_billing_required', ts('Billing address required'));
|
||||
$this->add('text', 'fee_label', ts('Fee Label'));
|
||||
|
||||
$price = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviEvent');
|
||||
if (CRM_Utils_System::isNull($price)) {
|
||||
$this->assign('price', FALSE);
|
||||
}
|
||||
else {
|
||||
$this->assign('price', TRUE);
|
||||
}
|
||||
$this->add('select', 'price_set_id', ts('Price Set'),
|
||||
array(
|
||||
'' => ts('- none -'),
|
||||
) + $price,
|
||||
NULL, array('onchange' => "return showHideByValue('price_set_id', '', 'map-field', 'block', 'select', false);")
|
||||
);
|
||||
$default = array($this->createElement('radio', NULL, NULL, NULL, 0));
|
||||
$this->add('hidden', 'price_field_id', '', array('id' => 'price_field_id'));
|
||||
for ($i = 1; $i <= self::NUM_OPTION; $i++) {
|
||||
// label
|
||||
$this->add('text', "label[$i]", ts('Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label'));
|
||||
$this->add('hidden', "price_field_value[$i]", '', array('id' => "price_field_value[$i]"));
|
||||
|
||||
// value
|
||||
$this->add('text', "value[$i]", ts('Value'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'value'));
|
||||
$this->addRule("value[$i]", ts('Please enter a valid money value for this field (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
|
||||
|
||||
// default
|
||||
$default[] = $this->createElement('radio', NULL, NULL, NULL, $i);
|
||||
}
|
||||
|
||||
$this->addGroup($default, 'default');
|
||||
|
||||
$this->addElement('checkbox', 'is_discount', ts('Discounts by Signup Date?'), NULL,
|
||||
array('onclick' => "warnDiscountDel(); return showHideByValue('is_discount','','discount','block','radio',false);")
|
||||
);
|
||||
$discountSection = $this->get('discountSection');
|
||||
|
||||
$this->assign('discountSection', $discountSection);
|
||||
|
||||
// form fields of Discount sets
|
||||
$defaultOption = array();
|
||||
$_showHide = new CRM_Core_ShowHideBlocks('', '');
|
||||
|
||||
for ($i = 1; $i <= self::NUM_DISCOUNT; $i++) {
|
||||
//the show hide blocks
|
||||
$showBlocks = 'discount_' . $i;
|
||||
if ($i > 2) {
|
||||
$_showHide->addHide($showBlocks);
|
||||
}
|
||||
else {
|
||||
$_showHide->addShow($showBlocks);
|
||||
}
|
||||
|
||||
//Increment by 1 of start date of previous end date.
|
||||
if (is_array($this->_submitValues) &&
|
||||
!empty($this->_submitValues['discount_name'][$i]) &&
|
||||
!empty($this->_submitValues['discount_name'][$i + 1]) &&
|
||||
isset($this->_submitValues['discount_end_date']) &&
|
||||
isset($this->_submitValues['discount_end_date'][$i]) &&
|
||||
$i < self::NUM_DISCOUNT - 1
|
||||
) {
|
||||
$end_date = CRM_Utils_Date::processDate($this->_submitValues['discount_end_date'][$i]);
|
||||
if (!empty($this->_submitValues['discount_end_date'][$i + 1])
|
||||
&& empty($this->_submitValues['discount_start_date'][$i + 1])
|
||||
) {
|
||||
list($this->_submitValues['discount_start_date'][$i + 1]) = CRM_Utils_Date::setDateDefaults(date('Y-m-d', strtotime("+1 days $end_date")));
|
||||
}
|
||||
}
|
||||
//Decrement by 1 of end date from next start date.
|
||||
if ($i > 1 &&
|
||||
is_array($this->_submitValues) &&
|
||||
!empty($this->_submitValues['discount_name'][$i]) &&
|
||||
!empty($this->_submitValues['discount_name'][$i - 1]) &&
|
||||
isset($this->_submitValues['discount_start_date']) &&
|
||||
isset($this->_submitValues['discount_start_date'][$i])
|
||||
) {
|
||||
$start_date = CRM_Utils_Date::processDate($this->_submitValues['discount_start_date'][$i]);
|
||||
if (!empty($this->_submitValues['discount_start_date'][$i])
|
||||
&& empty($this->_submitValues['discount_end_date'][$i - 1])
|
||||
) {
|
||||
list($this->_submitValues['discount_end_date'][$i - 1]) = CRM_Utils_Date::setDateDefaults(date('Y-m-d', strtotime("-1 days $start_date")));
|
||||
}
|
||||
}
|
||||
|
||||
//discount name
|
||||
$this->add('text', 'discount_name[' . $i . ']', ts('Discount Name'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'title')
|
||||
);
|
||||
|
||||
$this->add('hidden', "discount_price_set[$i]", '', array('id' => "discount_price_set[$i]"));
|
||||
|
||||
//discount start date
|
||||
$this->addDate('discount_start_date[' . $i . ']', ts('Discount Start Date'), FALSE, array('formatType' => 'activityDate'));
|
||||
|
||||
//discount end date
|
||||
$this->addDate('discount_end_date[' . $i . ']', ts('Discount End Date'), FALSE, array('formatType' => 'activityDate'));
|
||||
}
|
||||
$_showHide->addToTemplate();
|
||||
$this->addElement('submit', $this->getButtonName('submit'), ts('Add Discount Set to Fee Table'),
|
||||
array('class' => 'crm-form-submit cancel')
|
||||
);
|
||||
if (CRM_Contribute_BAO_Contribution::checkContributeSettings('deferred_revenue_enabled')) {
|
||||
$deferredFinancialType = CRM_Financial_BAO_FinancialAccount::getDeferredFinancialType();
|
||||
$this->assign('deferredFinancialType', array_keys($deferredFinancialType));
|
||||
}
|
||||
$this->buildAmountLabel();
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add local and global form rules.
|
||||
*/
|
||||
public function addRules() {
|
||||
$this->addFormRule(array('CRM_Event_Form_ManageEvent_Fee', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $values
|
||||
* Posted values of the form.
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($values) {
|
||||
$errors = array();
|
||||
if (!empty($values['is_discount'])) {
|
||||
$occurDiscount = array_count_values($values['discount_name']);
|
||||
$countemptyrows = 0;
|
||||
$countemptyvalue = 0;
|
||||
for ($i = 1; $i <= self::NUM_DISCOUNT; $i++) {
|
||||
$start_date = $end_date = NULL;
|
||||
if (!empty($values['discount_name'][$i])) {
|
||||
if (!empty($values['discount_start_date'][$i])) {
|
||||
$start_date = ($values['discount_start_date'][$i]) ? CRM_Utils_Date::processDate($values['discount_start_date'][$i]) : 0;
|
||||
}
|
||||
if (!empty($values['discount_end_date'][$i])) {
|
||||
$end_date = ($values['discount_end_date'][$i]) ? CRM_Utils_Date::processDate($values['discount_end_date'][$i]) : 0;
|
||||
}
|
||||
|
||||
if ($start_date && $end_date && strcmp($end_date, $start_date) < 0) {
|
||||
$errors["discount_end_date[$i]"] = ts('The discount end date cannot be prior to the start date.');
|
||||
}
|
||||
|
||||
if (!$start_date && !$end_date) {
|
||||
$errors["discount_start_date[$i]"] = $errors["discount_end_date[$i]"] = ts('Please specify either start date or end date.');
|
||||
}
|
||||
|
||||
if ($i > 1) {
|
||||
$end_date_1 = ($values['discount_end_date'][$i - 1]) ? CRM_Utils_Date::processDate($values['discount_end_date'][$i - 1]) : 0;
|
||||
if ($start_date && $end_date_1 && strcmp($end_date_1, $start_date) >= 0) {
|
||||
$errors["discount_start_date[$i]"] = ts('Select non-overlapping discount start date.');
|
||||
}
|
||||
elseif (!$start_date && !$end_date_1) {
|
||||
$j = $i - 1;
|
||||
$errors["discount_start_date[$i]"] = $errors["discount_end_date[$j]"] = ts('Select either of the dates.');
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($occurDiscount as $key => $value) {
|
||||
if ($value > 1 && $key <> '') {
|
||||
if ($key == $values['discount_name'][$i]) {
|
||||
$errors['discount_name[' . $i . ']'] = ts('%1 is already used for Discount Name.', array(1 => $key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//validation for discount labels and values
|
||||
for ($index = (self::NUM_OPTION); $index > 0; $index--) {
|
||||
$label = TRUE;
|
||||
if (empty($values['discounted_label'][$index]) && !empty($values['discounted_value'][$index][$i])) {
|
||||
$label = FALSE;
|
||||
if (!$label) {
|
||||
$errors["discounted_label[{$index}]"] = ts('Label cannot be empty.');
|
||||
}
|
||||
}
|
||||
if (!empty($values['discounted_label'][$index])) {
|
||||
$duplicateIndex = CRM_Utils_Array::key($values['discounted_label'][$index], $values['discounted_label']);
|
||||
|
||||
if ((!($duplicateIndex === FALSE)) && (!($duplicateIndex == $index))) {
|
||||
$errors["discounted_label[{$index}]"] = ts('Duplicate label value');
|
||||
}
|
||||
}
|
||||
if (empty($values['discounted_label'][$index]) && empty($values['discounted_value'][$index][$i])) {
|
||||
$countemptyrows++;
|
||||
}
|
||||
if (empty($values['discounted_value'][$index][$i])) {
|
||||
$countemptyvalue++;
|
||||
}
|
||||
}
|
||||
if (!empty($values['_qf_Fee_next']) && ($countemptyrows == 11 || $countemptyvalue == 11)) {
|
||||
$errors["discounted_label[1]"] = $errors["discounted_value[1][$i]"] = ts('At least one fee should be entered for your Discount Set. If you do not see the table to enter discount fees, click the "Add Discount Set to Fee Table" button.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($values['is_monetary']) {
|
||||
//check if financial type is selected
|
||||
if (!$values['financial_type_id']) {
|
||||
$errors['financial_type_id'] = ts("Please select financial type.");
|
||||
}
|
||||
|
||||
//check for the event fee label (mandatory)
|
||||
if (!$values['fee_label']) {
|
||||
$errors['fee_label'] = ts('Please enter the fee label for the paid event.');
|
||||
}
|
||||
|
||||
if (empty($values['price_set_id'])) {
|
||||
//check fee label and amount
|
||||
$check = 0;
|
||||
$optionKeys = array();
|
||||
foreach ($values['label'] as $key => $val) {
|
||||
if (trim($val) && trim($values['value'][$key])) {
|
||||
$optionKeys[$key] = $key;
|
||||
$check++;
|
||||
}
|
||||
}
|
||||
|
||||
$default = CRM_Utils_Array::value('default', $values);
|
||||
if ($default && !in_array($default, $optionKeys)) {
|
||||
$errors['default'] = ts('Please select an appropriate option as default.');
|
||||
}
|
||||
|
||||
if (!$check) {
|
||||
if (!$values['label'][1]) {
|
||||
$errors['label[1]'] = ts('Please enter a label for at least one fee level.');
|
||||
}
|
||||
if (!$values['value'][1]) {
|
||||
$errors['value[1]'] = ts('Please enter an amount for at least one fee level.');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($values['is_pay_later'])) {
|
||||
if (empty($values['pay_later_text'])) {
|
||||
$errors['pay_later_text'] = ts('Please enter the Pay Later prompt to be displayed on the Registration form.');
|
||||
}
|
||||
if (empty($values['pay_later_receipt'])) {
|
||||
$errors['pay_later_receipt'] = ts('Please enter the Pay Later instructions to be displayed to your users.');
|
||||
}
|
||||
}
|
||||
}
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
public function buildAmountLabel() {
|
||||
$default = array();
|
||||
for ($i = 1; $i <= self::NUM_OPTION; $i++) {
|
||||
// label
|
||||
$this->add('text', "discounted_label[$i]", ts('Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label'));
|
||||
// value
|
||||
for ($j = 1; $j <= self::NUM_DISCOUNT; $j++) {
|
||||
$this->add('text', "discounted_value[$i][$j]", ts('Value'), array('size' => 10));
|
||||
$this->addRule("discounted_value[$i][$j]", ts('Please enter a valid money value for this field (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
|
||||
}
|
||||
|
||||
// default
|
||||
$default[] = $this->createElement('radio', NULL, NULL, NULL, $i);
|
||||
}
|
||||
|
||||
$this->addGroup($default, 'discounted_default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$eventTitle = '';
|
||||
$params = $this->exportValues();
|
||||
|
||||
$this->set('discountSection', 0);
|
||||
|
||||
if (!empty($_POST['_qf_Fee_submit'])) {
|
||||
$this->buildAmountLabel();
|
||||
$this->set('discountSection', 2);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!empty($params['payment_processor'])) {
|
||||
$params['payment_processor'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['payment_processor']));
|
||||
}
|
||||
else {
|
||||
$params['payment_processor'] = 'null';
|
||||
}
|
||||
|
||||
$params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, 0);
|
||||
$params['is_billing_required'] = CRM_Utils_Array::value('is_billing_required', $params, 0);
|
||||
|
||||
if ($this->_id) {
|
||||
|
||||
// delete all the prior label values or discounts in the custom options table
|
||||
// and delete a price set if one exists
|
||||
//@todo note that this removes the reference from existing participants -
|
||||
// even where there is not change - redress?
|
||||
// note that a more tentative form of this is invoked by passing price_set_id as an array
|
||||
// to event.create see CRM-14069
|
||||
// @todo get all of this logic out of form layer (currently partially in BAO/api layer)
|
||||
if (CRM_Price_BAO_PriceSet::removeFrom('civicrm_event', $this->_id)) {
|
||||
CRM_Core_BAO_Discount::del($this->_id, 'civicrm_event');
|
||||
}
|
||||
}
|
||||
|
||||
if ($params['is_monetary']) {
|
||||
if (!empty($params['price_set_id'])) {
|
||||
//@todo this is now being done in the event BAO if passed price_set_id as an array
|
||||
// per notes on that fn - looking at the api converting to an array
|
||||
// so calling via the api may cause this to be done in the api
|
||||
CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $params['price_set_id']);
|
||||
if (!empty($params['price_field_id'])) {
|
||||
$priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $params['price_field_id'], 'price_set_id');
|
||||
CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// if there are label / values, create custom options for them
|
||||
$labels = CRM_Utils_Array::value('label', $params);
|
||||
$values = CRM_Utils_Array::value('value', $params);
|
||||
$default = CRM_Utils_Array::value('default', $params);
|
||||
$options = array();
|
||||
if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
|
||||
for ($i = 1; $i < self::NUM_OPTION; $i++) {
|
||||
if (!empty($labels[$i]) && !CRM_Utils_System::isNull($values[$i])) {
|
||||
$options[] = array(
|
||||
'label' => trim($labels[$i]),
|
||||
'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])),
|
||||
'weight' => $i,
|
||||
'is_active' => 1,
|
||||
'is_default' => $default == $i,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!empty($options)) {
|
||||
$params['default_fee_id'] = NULL;
|
||||
if (empty($params['price_set_id'])) {
|
||||
if (empty($params['price_field_id'])) {
|
||||
$setParams['title'] = $eventTitle = ($this->_isTemplate) ? $this->_defaultValues['template_title'] : $this->_defaultValues['title'];
|
||||
$eventTitle = strtolower(CRM_Utils_String::munge($eventTitle, '_', 245));
|
||||
if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle, 'id', 'name')) {
|
||||
$setParams['name'] = $eventTitle;
|
||||
}
|
||||
elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $this->_id, 'id', 'name')) {
|
||||
$setParams['name'] = $eventTitle . '_' . $this->_id;
|
||||
}
|
||||
else {
|
||||
$timeSec = explode('.', microtime(TRUE));
|
||||
$setParams['name'] = $eventTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
|
||||
}
|
||||
$setParams['is_quick_config'] = 1;
|
||||
$setParams['financial_type_id'] = $params['financial_type_id'];
|
||||
$setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
|
||||
$priceSet = CRM_Price_BAO_PriceSet::create($setParams);
|
||||
|
||||
$fieldParams['name'] = strtolower(CRM_Utils_String::munge($params['fee_label'], '_', 245));
|
||||
$fieldParams['price_set_id'] = $priceSet->id;
|
||||
}
|
||||
else {
|
||||
foreach ($params['price_field_value'] as $arrayID => $fieldValueID) {
|
||||
if (empty($params['label'][$arrayID]) && empty($params['value'][$arrayID]) && !empty($fieldValueID)) {
|
||||
CRM_Price_BAO_PriceFieldValue::setIsActive($fieldValueID, '0');
|
||||
unset($params['price_field_value'][$arrayID]);
|
||||
}
|
||||
}
|
||||
$fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params);
|
||||
$fieldParams['option_id'] = $params['price_field_value'];
|
||||
|
||||
$priceSet = new CRM_Price_BAO_PriceSet();
|
||||
$priceSet->id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('price_field_id', $params), 'price_set_id');
|
||||
|
||||
if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) {
|
||||
CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $priceSet->id, 'financial_type_id', $params['financial_type_id']);
|
||||
}
|
||||
}
|
||||
$fieldParams['label'] = $params['fee_label'];
|
||||
$fieldParams['html_type'] = 'Radio';
|
||||
CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $priceSet->id);
|
||||
$fieldParams['option_label'] = $params['label'];
|
||||
$fieldParams['option_amount'] = $params['value'];
|
||||
$fieldParams['financial_type_id'] = $params['financial_type_id'];
|
||||
foreach ($options as $value) {
|
||||
$fieldParams['option_weight'][$value['weight']] = $value['weight'];
|
||||
}
|
||||
$fieldParams['default_option'] = $params['default'];
|
||||
$priceField = CRM_Price_BAO_PriceField::create($fieldParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$discountPriceSets = !empty($this->_defaultValues['discount_price_set']) ? $this->_defaultValues['discount_price_set'] : array();
|
||||
$discountFieldIDs = !empty($this->_defaultValues['discount_option_id']) ? $this->_defaultValues['discount_option_id'] : array();
|
||||
if (CRM_Utils_Array::value('is_discount', $params) == 1) {
|
||||
// if there are discounted set of label / values,
|
||||
// create custom options for them
|
||||
$labels = CRM_Utils_Array::value('discounted_label', $params);
|
||||
$values = CRM_Utils_Array::value('discounted_value', $params);
|
||||
$default = CRM_Utils_Array::value('discounted_default', $params);
|
||||
|
||||
if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
|
||||
for ($j = 1; $j <= self::NUM_DISCOUNT; $j++) {
|
||||
$discountOptions = array();
|
||||
for ($i = 1; $i < self::NUM_OPTION; $i++) {
|
||||
if (!empty($labels[$i]) &&
|
||||
!CRM_Utils_System::isNull(CRM_Utils_Array::value($j, $values[$i]))
|
||||
) {
|
||||
$discountOptions[] = array(
|
||||
'label' => trim($labels[$i]),
|
||||
'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i][$j])),
|
||||
'weight' => $i,
|
||||
'is_active' => 1,
|
||||
'is_default' => $default == $i,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($discountOptions)) {
|
||||
$fieldParams = array();
|
||||
$params['default_discount_fee_id'] = NULL;
|
||||
$keyCheck = $j - 1;
|
||||
$setParams = array();
|
||||
if (empty($discountPriceSets[$keyCheck])) {
|
||||
if (!$eventTitle) {
|
||||
$eventTitle = strtolower(CRM_Utils_String::munge($this->_defaultValues['title'], '_', 200));
|
||||
}
|
||||
$setParams['title'] = $params['discount_name'][$j];
|
||||
if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $params['discount_name'][$j], 'id', 'name')) {
|
||||
$setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j];
|
||||
}
|
||||
elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id, 'id', 'name')) {
|
||||
$setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . $this->_id;
|
||||
}
|
||||
else {
|
||||
$timeSec = explode('.', microtime(TRUE));
|
||||
$setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . date('is', $timeSec[0]) . $timeSec[1];
|
||||
}
|
||||
$setParams['is_quick_config'] = 1;
|
||||
$setParams['financial_type_id'] = $params['financial_type_id'];
|
||||
$setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
|
||||
$priceSet = CRM_Price_BAO_PriceSet::create($setParams);
|
||||
$priceSetID = $priceSet->id;
|
||||
}
|
||||
else {
|
||||
$priceSetID = $discountPriceSets[$j - 1];
|
||||
$setParams = array(
|
||||
'title' => $params['discount_name'][$j],
|
||||
'id' => $priceSetID,
|
||||
);
|
||||
if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) {
|
||||
$setParams['financial_type_id'] = $params['financial_type_id'];
|
||||
}
|
||||
CRM_Price_BAO_PriceSet::create($setParams);
|
||||
unset($discountPriceSets[$j - 1]);
|
||||
$fieldParams['id'] = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceField', $priceSetID, 'id', 'price_set_id');
|
||||
}
|
||||
|
||||
$fieldParams['name'] = $fieldParams['label'] = $params['fee_label'];
|
||||
$fieldParams['is_required'] = 1;
|
||||
$fieldParams['price_set_id'] = $priceSetID;
|
||||
$fieldParams['html_type'] = 'Radio';
|
||||
$fieldParams['financial_type_id'] = $params['financial_type_id'];
|
||||
foreach ($discountOptions as $value) {
|
||||
$fieldParams['option_label'][$value['weight']] = $value['label'];
|
||||
$fieldParams['option_amount'][$value['weight']] = $value['value'];
|
||||
$fieldParams['option_weight'][$value['weight']] = $value['weight'];
|
||||
if (!empty($value['is_default'])) {
|
||||
$fieldParams['default_option'] = $value['weight'];
|
||||
}
|
||||
if (!empty($discountFieldIDs[$j]) && !empty($discountFieldIDs[$j][$value['weight']])) {
|
||||
$fieldParams['option_id'][$value['weight']] = $discountFieldIDs[$j][$value['weight']];
|
||||
unset($discountFieldIDs[$j][$value['weight']]);
|
||||
}
|
||||
}
|
||||
//create discount priceset
|
||||
$priceField = CRM_Price_BAO_PriceField::create($fieldParams);
|
||||
if (!empty($discountFieldIDs[$j])) {
|
||||
foreach ($discountFieldIDs[$j] as $fID) {
|
||||
CRM_Price_BAO_PriceFieldValue::setIsActive($fID, '0');
|
||||
}
|
||||
}
|
||||
|
||||
$discountParams = array(
|
||||
'entity_table' => 'civicrm_event',
|
||||
'entity_id' => $this->_id,
|
||||
'price_set_id' => $priceSetID,
|
||||
'start_date' => CRM_Utils_Date::processDate($params['discount_start_date'][$j]),
|
||||
'end_date' => CRM_Utils_Date::processDate($params['discount_end_date'][$j]),
|
||||
);
|
||||
CRM_Core_BAO_Discount::add($discountParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($discountPriceSets)) {
|
||||
foreach ($discountPriceSets as $setId) {
|
||||
CRM_Price_BAO_PriceSet::setIsQuickConfig($setId, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!empty($params['price_field_id'])) {
|
||||
$priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $params['price_field_id'], 'price_set_id');
|
||||
CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0);
|
||||
}
|
||||
$params['financial_type_id'] = '';
|
||||
$params['is_pay_later'] = 0;
|
||||
$params['is_billing_required'] = 0;
|
||||
}
|
||||
|
||||
//update 'is_billing_required'
|
||||
if (empty($params['is_pay_later'])) {
|
||||
$params['is_billing_required'] = FALSE;
|
||||
}
|
||||
|
||||
//update events table
|
||||
$params['id'] = $this->_id;
|
||||
// skip update of financial type in price set
|
||||
$params['skipFinancialType'] = TRUE;
|
||||
CRM_Event_BAO_Event::add($params);
|
||||
|
||||
// Update tab "disabled" css class
|
||||
$this->ajaxResponse['tabValid'] = !empty($params['is_monetary']);
|
||||
parent::endPostProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Event Fees');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,284 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for processing Event Location
|
||||
* civicrm_event_page.
|
||||
*/
|
||||
class CRM_Event_Form_ManageEvent_Location extends CRM_Event_Form_ManageEvent {
|
||||
|
||||
/**
|
||||
* How many locationBlocks should we display?
|
||||
*
|
||||
* @var int
|
||||
* @const
|
||||
*/
|
||||
const LOCATION_BLOCKS = 1;
|
||||
|
||||
/**
|
||||
* The variable, for storing the location array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_locationIds = array();
|
||||
|
||||
/**
|
||||
* The variable, for storing location block id with event
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_oldLocBlockId = 0;
|
||||
|
||||
/**
|
||||
* Get the db values for this form.
|
||||
*/
|
||||
public $_values = array();
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
$this->_values = $this->get('values');
|
||||
if ($this->_id && empty($this->_values)) {
|
||||
//get location values.
|
||||
$params = array(
|
||||
'entity_id' => $this->_id,
|
||||
'entity_table' => 'civicrm_event',
|
||||
);
|
||||
$this->_values = CRM_Core_BAO_Location::getValues($params);
|
||||
|
||||
//get event values.
|
||||
$params = array('id' => $this->_id);
|
||||
CRM_Event_BAO_Event::retrieve($params, $this->_values);
|
||||
$this->set('values', $this->_values);
|
||||
}
|
||||
|
||||
//location blocks.
|
||||
CRM_Contact_Form_Location::preProcess($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* Note that in edit/view mode the default values are retrieved from the database.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = $this->_values;
|
||||
|
||||
if (!empty($defaults['loc_block_id'])) {
|
||||
$defaults['loc_event_id'] = $defaults['loc_block_id'];
|
||||
$countLocUsed = CRM_Event_BAO_Event::countEventsUsingLocBlockId($defaults['loc_block_id']);
|
||||
$this->assign('locUsed', $countLocUsed);
|
||||
}
|
||||
|
||||
$config = CRM_Core_Config::singleton();
|
||||
if (!isset($defaults['address'][1]['country_id'])) {
|
||||
$defaults['address'][1]['country_id'] = $config->defaultContactCountry;
|
||||
}
|
||||
|
||||
if (!isset($defaults['address'][1]['state_province_id'])) {
|
||||
$defaults['address'][1]['state_province_id'] = $config->defaultContactStateProvince;
|
||||
}
|
||||
|
||||
$defaults['location_option'] = $this->_oldLocBlockId ? 2 : 1;
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add local and global form rules.
|
||||
*/
|
||||
public function addRules() {
|
||||
$this->addFormRule(array('CRM_Event_Form_ManageEvent_Location', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($fields) {
|
||||
// check for state/country mapping
|
||||
$errors = CRM_Contact_Form_Edit_Address::formRule($fields);
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to build location block.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
//load form for child blocks
|
||||
if ($this->_addBlockName) {
|
||||
$className = "CRM_Contact_Form_Edit_{$this->_addBlockName}";
|
||||
return $className::buildQuickForm($this);
|
||||
}
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
//build location blocks.
|
||||
CRM_Contact_Form_Location::buildQuickForm($this);
|
||||
|
||||
//fix for CRM-1971
|
||||
$this->assign('action', $this->_action);
|
||||
|
||||
if ($this->_id) {
|
||||
$this->_oldLocBlockId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event',
|
||||
$this->_id, 'loc_block_id'
|
||||
);
|
||||
}
|
||||
|
||||
// get the list of location blocks being used by other events
|
||||
|
||||
$locationEvents = CRM_Event_BAO_Event::getLocationEvents();
|
||||
// remove duplicates and make sure that the duplicate entry with key as
|
||||
// loc_block_id of this event (this->_id) is preserved
|
||||
if (!empty($locationEvents[$this->_oldLocBlockId])) {
|
||||
$possibleDuplicate = $locationEvents[$this->_oldLocBlockId];
|
||||
$locationEvents = array_flip(array_unique($locationEvents));
|
||||
if (!empty($locationEvents[$possibleDuplicate])) {
|
||||
$locationEvents[$possibleDuplicate] = $this->_oldLocBlockId;
|
||||
}
|
||||
$locationEvents = array_flip($locationEvents);
|
||||
}
|
||||
else {
|
||||
$locationEvents = array_unique($locationEvents);
|
||||
}
|
||||
|
||||
$events = array();
|
||||
if (!empty($locationEvents)) {
|
||||
$this->assign('locEvents', TRUE);
|
||||
$optionTypes = array(
|
||||
'1' => ts('Create new location'),
|
||||
'2' => ts('Use existing location'),
|
||||
);
|
||||
|
||||
$this->addRadio('location_option', ts("Choose Location"), $optionTypes);
|
||||
|
||||
if (!isset($locationEvents[$this->_oldLocBlockId]) || (!$this->_oldLocBlockId)) {
|
||||
$locationEvents = array('' => ts('- select -')) + $locationEvents;
|
||||
}
|
||||
$this->add('select', 'loc_event_id', ts('Use Location'), $locationEvents, FALSE, array('class' => 'crm-select2'));
|
||||
}
|
||||
$this->addElement('advcheckbox', 'is_show_location', ts('Show Location?'));
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
$deleteOldBlock = FALSE;
|
||||
|
||||
// if 'use existing location' option is selected -
|
||||
if (CRM_Utils_Array::value('location_option', $params) == 2 && !empty($params['loc_event_id']) &&
|
||||
($params['loc_event_id'] != $this->_oldLocBlockId)
|
||||
) {
|
||||
// if new selected loc is different from old loc, update the loc_block_id
|
||||
// so that loc update would affect the selected loc and not the old one.
|
||||
$deleteOldBlock = TRUE;
|
||||
CRM_Core_DAO::setFieldValue('CRM_Event_DAO_Event', $this->_id,
|
||||
'loc_block_id', $params['loc_event_id']
|
||||
);
|
||||
}
|
||||
|
||||
// if 'create new loc' option is selected, set the loc_block_id for this event to null
|
||||
// so that an update would result in creating a new loc.
|
||||
if ($this->_oldLocBlockId && (CRM_Utils_Array::value('location_option', $params) == 1)) {
|
||||
$deleteOldBlock = TRUE;
|
||||
CRM_Core_DAO::setFieldValue('CRM_Event_DAO_Event', $this->_id,
|
||||
'loc_block_id', 'null'
|
||||
);
|
||||
}
|
||||
|
||||
// if 'create new loc' optioin is selected OR selected new loc is different
|
||||
// from old one, go ahead and delete the old loc provided thats not being
|
||||
// used by any other event
|
||||
if ($this->_oldLocBlockId && $deleteOldBlock) {
|
||||
CRM_Event_BAO_Event::deleteEventLocBlock($this->_oldLocBlockId, $this->_id);
|
||||
}
|
||||
|
||||
// get ready with location block params
|
||||
$params['entity_table'] = 'civicrm_event';
|
||||
$params['entity_id'] = $this->_id;
|
||||
|
||||
$defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
|
||||
foreach (array(
|
||||
'address',
|
||||
'phone',
|
||||
'email',
|
||||
) as $block) {
|
||||
if (empty($params[$block]) || !is_array($params[$block])) {
|
||||
continue;
|
||||
}
|
||||
foreach ($params[$block] as $count => & $values) {
|
||||
if ($count == 1) {
|
||||
$values['is_primary'] = 1;
|
||||
}
|
||||
$values['location_type_id'] = ($defaultLocationType->id) ? $defaultLocationType->id : 1;
|
||||
}
|
||||
}
|
||||
|
||||
// create/update event location
|
||||
$location = CRM_Core_BAO_Location::create($params, TRUE, 'event');
|
||||
$params['loc_block_id'] = $location['id'];
|
||||
|
||||
// finally update event params
|
||||
$params['id'] = $this->_id;
|
||||
CRM_Event_BAO_Event::add($params);
|
||||
|
||||
// Update tab "disabled" css class
|
||||
$this->ajaxResponse['tabValid'] = TRUE;
|
||||
parent::endPostProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Event Location');
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load diff
219
sites/all/modules/civicrm/CRM/Event/Form/ManageEvent/Repeat.php
Normal file
219
sites/all/modules/civicrm/CRM/Event/Form/ManageEvent/Repeat.php
Normal file
|
@ -0,0 +1,219 @@
|
|||
<?php
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description of Repeat
|
||||
*
|
||||
* @author Priyanka
|
||||
*/
|
||||
class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent {
|
||||
|
||||
/**
|
||||
* Parent Event Start Date.
|
||||
*/
|
||||
protected $_parentEventStartDate = NULL;
|
||||
|
||||
/**
|
||||
* Parent Event End Date.
|
||||
*/
|
||||
protected $_parentEventEndDate = NULL;
|
||||
|
||||
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
$this->assign('currentEventId', $this->_id);
|
||||
|
||||
$checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor($this->_id, 'civicrm_event');
|
||||
//If this ID has parent, send parent id
|
||||
if ($checkParentExistsForThisId) {
|
||||
/**
|
||||
* Get connected event information list
|
||||
*/
|
||||
//Get all connected event ids
|
||||
$allEventIdsArray = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($checkParentExistsForThisId, 'civicrm_event');
|
||||
$allEventIds = array();
|
||||
if (!empty($allEventIdsArray)) {
|
||||
foreach ($allEventIdsArray as $key => $val) {
|
||||
$allEventIds[] = $val['id'];
|
||||
}
|
||||
if (!empty($allEventIds)) {
|
||||
$params = array();
|
||||
$query = "
|
||||
SELECT *
|
||||
FROM civicrm_event
|
||||
WHERE id IN (" . implode(",", $allEventIds) . ")
|
||||
ORDER BY start_date asc
|
||||
";
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Event_DAO_Event');
|
||||
$permissions = CRM_Event_BAO_Event::checkPermission();
|
||||
while ($dao->fetch()) {
|
||||
if (in_array($dao->id, $permissions[CRM_Core_Permission::VIEW])) {
|
||||
$manageEvent[$dao->id] = array();
|
||||
CRM_Core_DAO::storeValues($dao, $manageEvent[$dao->id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->assign('rows', $manageEvent);
|
||||
}
|
||||
}
|
||||
|
||||
$parentEventParams = array('id' => $this->_id);
|
||||
$parentEventValues = array();
|
||||
$parentEventReturnProperties = array('start_date', 'end_date');
|
||||
$parentEventAttributes = CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $parentEventParams, $parentEventValues, $parentEventReturnProperties);
|
||||
$this->_parentEventStartDate = $parentEventAttributes->start_date;
|
||||
$this->_parentEventEndDate = $parentEventAttributes->end_date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. For edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
|
||||
//Always pass current event's start date by default
|
||||
$currentEventStartDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'start_date', 'id');
|
||||
list($defaults['repetition_start_date'], $defaults['repetition_start_date_time']) = CRM_Utils_Date::setDateDefaults($currentEventStartDate, 'activityDateTime');
|
||||
$recurringEntityDefaults = CRM_Core_Form_RecurringEntity::setDefaultValues();
|
||||
return array_merge($defaults, $recurringEntityDefaults);
|
||||
}
|
||||
|
||||
public function buildQuickForm() {
|
||||
CRM_Core_Form_RecurringEntity::buildQuickForm($this);
|
||||
}
|
||||
|
||||
public function postProcess() {
|
||||
if ($this->_id) {
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
if ($this->_parentEventStartDate && $this->_parentEventEndDate) {
|
||||
$interval = CRM_Core_BAO_RecurringEntity::getInterval($this->_parentEventStartDate, $this->_parentEventEndDate);
|
||||
$params['intervalDateColumns'] = array('end_date' => $interval);
|
||||
}
|
||||
$params['dateColumns'] = array('start_date');
|
||||
$params['excludeDateRangeColumns'] = array('start_date', 'end_date');
|
||||
$params['entity_table'] = 'civicrm_event';
|
||||
$params['entity_id'] = $this->_id;
|
||||
|
||||
// CRM-16568 - check if parent exist for the event.
|
||||
$parentId = CRM_Core_BAO_RecurringEntity::getParentFor($this->_id, 'civicrm_event');
|
||||
$params['parent_entity_id'] = !empty($parentId) ? $parentId : $params['entity_id'];
|
||||
//Unset event id
|
||||
unset($params['id']);
|
||||
|
||||
$url = 'civicrm/event/manage/repeat';
|
||||
$urlParams = "action=update&reset=1&id={$this->_id}";
|
||||
|
||||
$linkedEntities = array(
|
||||
array(
|
||||
'table' => 'civicrm_price_set_entity',
|
||||
'findCriteria' => array(
|
||||
'entity_id' => $this->_id,
|
||||
'entity_table' => 'civicrm_event',
|
||||
),
|
||||
'linkedColumns' => array('entity_id'),
|
||||
'isRecurringEntityRecord' => FALSE,
|
||||
),
|
||||
array(
|
||||
'table' => 'civicrm_uf_join',
|
||||
'findCriteria' => array(
|
||||
'entity_id' => $this->_id,
|
||||
'entity_table' => 'civicrm_event',
|
||||
),
|
||||
'linkedColumns' => array('entity_id'),
|
||||
'isRecurringEntityRecord' => FALSE,
|
||||
),
|
||||
array(
|
||||
'table' => 'civicrm_tell_friend',
|
||||
'findCriteria' => array(
|
||||
'entity_id' => $this->_id,
|
||||
'entity_table' => 'civicrm_event',
|
||||
),
|
||||
'linkedColumns' => array('entity_id'),
|
||||
'isRecurringEntityRecord' => TRUE,
|
||||
),
|
||||
array(
|
||||
'table' => 'civicrm_pcp_block',
|
||||
'findCriteria' => array(
|
||||
'entity_id' => $this->_id,
|
||||
'entity_table' => 'civicrm_event',
|
||||
),
|
||||
'linkedColumns' => array('entity_id'),
|
||||
'isRecurringEntityRecord' => TRUE,
|
||||
),
|
||||
);
|
||||
CRM_Core_Form_RecurringEntity::postProcess($params, 'civicrm_event', $linkedEntities);
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams));
|
||||
}
|
||||
else {
|
||||
CRM_Core_Error::fatal("Could not find Event ID");
|
||||
}
|
||||
parent::endPostProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function gets the number of participant count for the list of related event ids.
|
||||
*
|
||||
* @param array $listOfRelatedEntities
|
||||
* List of related event ids .
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static public function getParticipantCountforEvent($listOfRelatedEntities = array()) {
|
||||
$participantDetails = array();
|
||||
if (!empty($listOfRelatedEntities)) {
|
||||
$implodeRelatedEntities = implode(',', array_map(function ($entity) {
|
||||
return $entity['id'];
|
||||
}, $listOfRelatedEntities));
|
||||
if ($implodeRelatedEntities) {
|
||||
$query = "SELECT p.event_id as event_id,
|
||||
concat_ws(' ', e.title, concat_ws(' - ', DATE_FORMAT(e.start_date, '%b %d %Y %h:%i %p'), DATE_FORMAT(e.end_date, '%b %d %Y %h:%i %p'))) as event_data,
|
||||
count(p.id) as participant_count
|
||||
FROM civicrm_participant p, civicrm_event e
|
||||
WHERE p.event_id = e.id AND p.event_id IN ({$implodeRelatedEntities})
|
||||
GROUP BY p.event_id";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$participantDetails['countByID'][$dao->event_id] = $dao->participant_count;
|
||||
$participantDetails['countByName'][$dao->event_id][$dao->event_data] = $dao->participant_count;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $participantDetails;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks if there was any registraion for related event ids,
|
||||
* and returns array of ids with no regsitrations
|
||||
*
|
||||
* @param string or int or object... $eventID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function checkRegistrationForEvents($eventID) {
|
||||
$eventIdsWithNoRegistration = array();
|
||||
if ($eventID) {
|
||||
$getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($eventID, 'civicrm_event', TRUE);
|
||||
$participantDetails = CRM_Event_Form_ManageEvent_Repeat::getParticipantCountforEvent($getRelatedEntities);
|
||||
//Check if participants exists for events
|
||||
foreach ($getRelatedEntities as $key => $value) {
|
||||
if (!CRM_Utils_Array::value($value['id'], $participantDetails['countByID']) && $value['id'] != $eventID) {
|
||||
//CRM_Event_BAO_Event::del($value['id']);
|
||||
$eventIdsWithNoRegistration[] = $value['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted = $eventIdsWithNoRegistration;
|
||||
return CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for scheduling reminders for Event
|
||||
*
|
||||
*/
|
||||
class CRM_Event_Form_ManageEvent_ScheduleReminders extends CRM_Event_Form_ManageEvent {
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
$setTab = CRM_Utils_Request::retrieve('setTab', 'Int', $this, FALSE, 0);
|
||||
|
||||
$mapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings(array(
|
||||
'id' => ($this->_isTemplate ? CRM_Event_ActionMapping::EVENT_TPL_MAPPING_ID : CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID),
|
||||
)));
|
||||
$reminderList = CRM_Core_BAO_ActionSchedule::getList(FALSE, $mapping, $this->_id);
|
||||
if ($reminderList && is_array($reminderList)) {
|
||||
// Add action links to each of the reminders
|
||||
foreach ($reminderList as & $format) {
|
||||
$action = CRM_Core_Action::UPDATE + CRM_Core_Action::DELETE;
|
||||
if ($format['is_active']) {
|
||||
$action += CRM_Core_Action::DISABLE;
|
||||
}
|
||||
else {
|
||||
$action += CRM_Core_Action::ENABLE;
|
||||
}
|
||||
$scheduleReminder = new CRM_Admin_Page_ScheduleReminders();
|
||||
$links = $scheduleReminder->links();
|
||||
$links[CRM_Core_Action::DELETE]['qs'] .= "&context=event&compId={$this->_id}";
|
||||
$links[CRM_Core_Action::UPDATE]['qs'] .= "&context=event&compId={$this->_id}";
|
||||
$format['action'] = CRM_Core_Action::formLink(
|
||||
$links,
|
||||
$action,
|
||||
array('id' => $format['id']),
|
||||
ts('more'),
|
||||
FALSE,
|
||||
'actionSchedule.manage.action',
|
||||
'ActionSchedule',
|
||||
$this->_id
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('rows', $reminderList);
|
||||
$this->assign('setTab', $setTab);
|
||||
$this->assign('component', 'event');
|
||||
|
||||
// Update tab "disabled" css class
|
||||
$this->ajaxResponse['tabValid'] = is_array($reminderList) && (count($reminderList) > 0);
|
||||
$this->setPageTitle(ts('Scheduled Reminder'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTemplateFileName() {
|
||||
return 'CRM/Admin/Page/ScheduleReminders.tpl';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,249 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper class to build navigation links
|
||||
*/
|
||||
class CRM_Event_Form_ManageEvent_TabHeader {
|
||||
|
||||
/**
|
||||
* @param CRM_Event_Form_ManageEvent $form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function build(&$form) {
|
||||
$tabs = $form->get('tabHeader');
|
||||
if (!$tabs || empty($_GET['reset'])) {
|
||||
$tabs = self::process($form);
|
||||
$form->set('tabHeader', $tabs);
|
||||
}
|
||||
$form->assign_by_ref('tabHeader', $tabs);
|
||||
CRM_Core_Resources::singleton()
|
||||
->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
|
||||
->addSetting(array(
|
||||
'tabSettings' => array(
|
||||
'active' => self::getCurrentTab($tabs),
|
||||
),
|
||||
));
|
||||
CRM_Event_Form_ManageEvent::addProfileEditScripts();
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Event_Form_ManageEvent $form
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function process(&$form) {
|
||||
if ($form->getVar('_id') <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$default = array(
|
||||
'link' => NULL,
|
||||
'valid' => TRUE,
|
||||
'active' => TRUE,
|
||||
'current' => FALSE,
|
||||
'class' => 'ajaxForm',
|
||||
);
|
||||
|
||||
$tabs = array();
|
||||
$tabs['settings'] = array('title' => ts('Info and Settings'), 'class' => 'ajaxForm livePage') + $default;
|
||||
$tabs['location'] = array('title' => ts('Event Location')) + $default;
|
||||
$tabs['fee'] = array('title' => ts('Fees')) + $default;
|
||||
$tabs['registration'] = array('title' => ts('Online Registration')) + $default;
|
||||
if (CRM_Core_Permission::check('administer CiviCRM') || CRM_Event_BAO_Event::checkPermission(NULL, CRM_Core_Permission::EDIT)) {
|
||||
$tabs['reminder'] = array('title' => ts('Schedule Reminders'), 'class' => 'livePage') + $default;
|
||||
}
|
||||
$tabs['conference'] = array('title' => ts('Conference Slots')) + $default;
|
||||
$tabs['friend'] = array('title' => ts('Tell a Friend')) + $default;
|
||||
$tabs['pcp'] = array('title' => ts('Personal Campaigns')) + $default;
|
||||
$tabs['repeat'] = array('title' => ts('Repeat')) + $default;
|
||||
|
||||
// Repeat tab must refresh page when switching repeat mode so js & vars will get set-up
|
||||
if (!$form->_isRepeatingEvent) {
|
||||
unset($tabs['repeat']['class']);
|
||||
}
|
||||
|
||||
// check if we're in shopping cart mode for events
|
||||
$enableCart = Civi::settings()->get('enable_cart');
|
||||
if (!$enableCart) {
|
||||
unset($tabs['conference']);
|
||||
}
|
||||
|
||||
$eventID = $form->getVar('_id');
|
||||
if ($eventID) {
|
||||
// disable tabs based on their configuration status
|
||||
$eventNameMapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings(array(
|
||||
'id' => CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID,
|
||||
)));
|
||||
$sql = "
|
||||
SELECT e.loc_block_id as is_location, e.is_online_registration, e.is_monetary, taf.is_active, pcp.is_active as is_pcp, sch.id as is_reminder, re.id as is_repeating_event
|
||||
FROM civicrm_event e
|
||||
LEFT JOIN civicrm_tell_friend taf ON ( taf.entity_table = 'civicrm_event' AND taf.entity_id = e.id )
|
||||
LEFT JOIN civicrm_pcp_block pcp ON ( pcp.entity_table = 'civicrm_event' AND pcp.entity_id = e.id )
|
||||
LEFT JOIN civicrm_action_schedule sch ON ( sch.mapping_id = %2 AND sch.entity_value = %1 )
|
||||
LEFT JOIN civicrm_recurring_entity re ON ( e.id = re.entity_id AND re.entity_table = 'civicrm_event' )
|
||||
WHERE e.id = %1
|
||||
";
|
||||
//Check if repeat is configured
|
||||
$eventHasParent = CRM_Core_BAO_RecurringEntity::getParentFor($eventID, 'civicrm_event');
|
||||
$params = array(
|
||||
1 => array($eventID, 'Integer'),
|
||||
2 => array($eventNameMapping->getId(), 'Integer'),
|
||||
);
|
||||
$dao = CRM_Core_DAO::executeQuery($sql, $params);
|
||||
if (!$dao->fetch()) {
|
||||
CRM_Core_Error::fatal();
|
||||
}
|
||||
if (!$dao->is_location) {
|
||||
$tabs['location']['valid'] = FALSE;
|
||||
}
|
||||
if (!$dao->is_online_registration) {
|
||||
$tabs['registration']['valid'] = FALSE;
|
||||
}
|
||||
if (!$dao->is_monetary) {
|
||||
$tabs['fee']['valid'] = FALSE;
|
||||
}
|
||||
if (!$dao->is_active) {
|
||||
$tabs['friend']['valid'] = FALSE;
|
||||
}
|
||||
if (!$dao->is_pcp) {
|
||||
$tabs['pcp']['valid'] = FALSE;
|
||||
}
|
||||
if (!$dao->is_reminder) {
|
||||
$tabs['reminder']['valid'] = FALSE;
|
||||
}
|
||||
if (!$dao->is_repeating_event) {
|
||||
$tabs['repeat']['valid'] = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// see if any other modules want to add any tabs
|
||||
// note: status of 'valid' flag of any injected tab, needs to be taken care in the hook implementation.
|
||||
CRM_Utils_Hook::tabset('civicrm/event/manage', $tabs,
|
||||
array('event_id' => $eventID));
|
||||
|
||||
$fullName = $form->getVar('_name');
|
||||
$className = CRM_Utils_String::getClassName($fullName);
|
||||
$new = '';
|
||||
|
||||
// hack for special cases.
|
||||
switch ($className) {
|
||||
case 'Event':
|
||||
$attributes = $form->getVar('_attributes');
|
||||
$class = strtolower(basename(CRM_Utils_Array::value('action', $attributes)));
|
||||
break;
|
||||
|
||||
case 'EventInfo':
|
||||
$class = 'settings';
|
||||
break;
|
||||
|
||||
case 'ScheduleReminders':
|
||||
$class = 'reminder';
|
||||
break;
|
||||
|
||||
default:
|
||||
$class = strtolower($className);
|
||||
break;
|
||||
}
|
||||
|
||||
if (array_key_exists($class, $tabs)) {
|
||||
$tabs[$class]['current'] = TRUE;
|
||||
$qfKey = $form->get('qfKey');
|
||||
if ($qfKey) {
|
||||
$tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
|
||||
}
|
||||
}
|
||||
|
||||
if ($eventID) {
|
||||
$reset = !empty($_GET['reset']) ? 'reset=1&' : '';
|
||||
|
||||
foreach ($tabs as $key => $value) {
|
||||
if (!isset($tabs[$key]['qfKey'])) {
|
||||
$tabs[$key]['qfKey'] = NULL;
|
||||
}
|
||||
|
||||
$action = 'update';
|
||||
if ($key == 'reminder') {
|
||||
$action = 'browse';
|
||||
}
|
||||
|
||||
$link = "civicrm/event/manage/{$key}";
|
||||
$query = "{$reset}action={$action}&id={$eventID}&component=event{$tabs[$key]['qfKey']}";
|
||||
|
||||
$tabs[$key]['link'] = (isset($value['link']) ? $value['link'] :
|
||||
CRM_Utils_System::url($link, $query));
|
||||
}
|
||||
}
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Event_Form_ManageEvent $form
|
||||
*/
|
||||
public static function reset(&$form) {
|
||||
$tabs = self::process($form);
|
||||
$form->set('tabHeader', $tabs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $tabs
|
||||
*
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getCurrentTab($tabs) {
|
||||
static $current = FALSE;
|
||||
|
||||
if ($current) {
|
||||
return $current;
|
||||
}
|
||||
|
||||
if (is_array($tabs)) {
|
||||
foreach ($tabs as $subPage => $pageVal) {
|
||||
if ($pageVal['current'] === TRUE) {
|
||||
$current = $subPage;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$current = $current ? $current : 'settings';
|
||||
return $current;
|
||||
}
|
||||
|
||||
}
|
1814
sites/all/modules/civicrm/CRM/Event/Form/Participant.php
Normal file
1814
sites/all/modules/civicrm/CRM/Event/Form/Participant.php
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,391 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be usefusul, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This form used for changing / updating fee selections for the events
|
||||
* event/contribution is partially paid
|
||||
*
|
||||
*/
|
||||
class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form {
|
||||
|
||||
public $useLivePageJS = TRUE;
|
||||
|
||||
protected $_contactId = NULL;
|
||||
|
||||
protected $_contributorDisplayName = NULL;
|
||||
|
||||
protected $_contributorEmail = NULL;
|
||||
|
||||
protected $_toDoNotEmail = NULL;
|
||||
|
||||
protected $_contributionId = NULL;
|
||||
|
||||
protected $fromEmailId = NULL;
|
||||
|
||||
public $_eventId = NULL;
|
||||
|
||||
public $_action = NULL;
|
||||
|
||||
public $_values = NULL;
|
||||
|
||||
public $_participantId = NULL;
|
||||
|
||||
protected $_participantStatus = NULL;
|
||||
|
||||
protected $_paidAmount = NULL;
|
||||
|
||||
public $_isPaidEvent = NULL;
|
||||
|
||||
protected $contributionAmt = NULL;
|
||||
|
||||
public function preProcess() {
|
||||
$this->_participantId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
|
||||
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
|
||||
$this->_eventId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_participantId, 'event_id');
|
||||
$this->_fromEmails = CRM_Event_BAO_Event::getFromEmailIds($this->_eventId);
|
||||
|
||||
$this->_contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participantId, 'contribution_id', 'participant_id');
|
||||
if (!$this->_contributionId) {
|
||||
if ($primaryParticipantId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $this->_participantId, 'registered_by_id')) {
|
||||
$this->_contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $primaryParticipantId, 'contribution_id', 'participant_id');
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_contributionId) {
|
||||
$this->_isPaidEvent = TRUE;
|
||||
}
|
||||
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, TRUE);
|
||||
|
||||
list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId);
|
||||
$this->assign('displayName', $this->_contributorDisplayName);
|
||||
$this->assign('email', $this->_contributorEmail);
|
||||
|
||||
$this->_participantStatus = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $this->_participantId, 'status_id');
|
||||
//set the payment mode - _mode property is defined in parent class
|
||||
$this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
|
||||
|
||||
$this->assign('contactId', $this->_contactId);
|
||||
$this->assign('id', $this->_participantId);
|
||||
|
||||
$paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_participantId, 'event');
|
||||
$this->_paidAmount = $paymentInfo['paid'];
|
||||
$this->assign('paymentInfo', $paymentInfo);
|
||||
$this->assign('feePaid', $this->_paidAmount);
|
||||
|
||||
$ids = CRM_Event_BAO_Participant::getParticipantIds($this->_contributionId);
|
||||
if (count($ids) > 1) {
|
||||
$total = CRM_Price_BAO_LineItem::getLineTotal($this->_contributionId);
|
||||
$this->assign('totalLineTotal', $total);
|
||||
$this->assign('lineItemTotal', $total);
|
||||
}
|
||||
|
||||
$title = ts("Change selections for %1", array(1 => $this->_contributorDisplayName));
|
||||
if ($title) {
|
||||
CRM_Utils_System::setTitle($title);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$params = array('id' => $this->_participantId);
|
||||
|
||||
CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
|
||||
$priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->_eventId);
|
||||
|
||||
$priceSetValues = CRM_Event_Form_EventFees::setDefaultPriceSet($this->_participantId, $this->_eventId, FALSE);
|
||||
$priceFieldId = (array_keys($this->_values['fee']));
|
||||
if (!empty($priceSetValues)) {
|
||||
$defaults[$this->_participantId] = array_merge($defaults[$this->_participantId], $priceSetValues);
|
||||
}
|
||||
else {
|
||||
foreach ($priceFieldId as $key => $value) {
|
||||
if (!empty($value) && ($this->_values['fee'][$value]['html_type'] == 'Radio' || $this->_values['fee'][$value]['html_type'] == 'Select') && !$this->_values['fee'][$value]['is_required']) {
|
||||
$fee_keys = array_keys($this->_values['fee']);
|
||||
$defaults[$this->_participantId]['price_' . $fee_keys[$key]] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults[$this->_participantId]));
|
||||
if ($this->_action == CRM_Core_Action::UPDATE) {
|
||||
$fee_level = $defaults[$this->_participantId]['fee_level'];
|
||||
CRM_Event_BAO_Participant::fixEventLevel($fee_level);
|
||||
$this->assign('fee_level', $fee_level);
|
||||
$this->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$this->_participantId]));
|
||||
}
|
||||
$defaults = $defaults[$this->_participantId];
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
public function buildQuickForm() {
|
||||
|
||||
$statuses = CRM_Event_PseudoConstant::participantStatus();
|
||||
$this->assign('partiallyPaid', array_search('Partially paid', $statuses));
|
||||
$this->assign('pendingRefund', array_search('Pending refund', $statuses));
|
||||
$this->assign('participantStatus', $this->_participantStatus);
|
||||
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$this->assign('currencySymbol', $config->defaultCurrencySymbol);
|
||||
|
||||
// line items block
|
||||
$lineItem = $event = array();
|
||||
$params = array('id' => $this->_eventId);
|
||||
CRM_Event_BAO_Event::retrieve($params, $event);
|
||||
|
||||
//retrieve custom information
|
||||
$this->_values = array();
|
||||
CRM_Event_Form_Registration::initEventFee($this, $event['id']);
|
||||
CRM_Event_Form_Registration_Register::buildAmount($this, TRUE);
|
||||
|
||||
if (!CRM_Utils_System::isNull(CRM_Utils_Array::value('line_items', $this->_values))) {
|
||||
$lineItem[] = $this->_values['line_items'];
|
||||
}
|
||||
$this->assign('lineItem', empty($lineItem) ? FALSE : $lineItem);
|
||||
$event = CRM_Event_BAO_Event::getEvents(0, $this->_eventId);
|
||||
$this->assign('eventName', $event[$this->_eventId]);
|
||||
|
||||
$statusOptions = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label');
|
||||
$this->add('select', 'status_id', ts('Participant Status'),
|
||||
array(
|
||||
'' => ts('- select -'),
|
||||
) + $statusOptions,
|
||||
TRUE
|
||||
);
|
||||
|
||||
$this->addElement('checkbox',
|
||||
'send_receipt',
|
||||
ts('Send Confirmation?'), NULL,
|
||||
array('onclick' => "showHideByValue('send_receipt','','notice','table-row','radio',false); showHideByValue('send_receipt','','from-email','table-row','radio',false);")
|
||||
);
|
||||
|
||||
$this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails['from_email_id']);
|
||||
|
||||
$this->add('textarea', 'receipt_text', ts('Confirmation Message'));
|
||||
|
||||
$noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note');
|
||||
$this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
|
||||
|
||||
$buttons[] = array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save'),
|
||||
'isDefault' => TRUE,
|
||||
);
|
||||
|
||||
if (CRM_Event_BAO_Participant::isPrimaryParticipant($this->_participantId)) {
|
||||
$buttons[] = array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save and Record Payment'),
|
||||
'subName' => 'new',
|
||||
);
|
||||
}
|
||||
$buttons[] = array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
);
|
||||
|
||||
$this->addButtons($buttons);
|
||||
$this->addFormRule(array('CRM_Event_Form_ParticipantFeeSelection', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $fields
|
||||
* @param $files
|
||||
* @param $self
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function formRule($fields, $files, $self) {
|
||||
$errors = array();
|
||||
return $errors;
|
||||
}
|
||||
|
||||
public function postProcess() {
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
$feeBlock = $this->_values['fee'];
|
||||
$lineItems = $this->_values['line_items'];
|
||||
CRM_Price_BAO_LineItem::changeFeeSelections($params, $this->_participantId, 'participant', $this->_contributionId, $feeBlock, $lineItems, $this->_paidAmount);
|
||||
$this->contributionAmt = CRM_Core_DAO::getFieldValue('CRM_Contribute_BAO_Contribution', $this->_contributionId, 'total_amount');
|
||||
// email sending
|
||||
if (!empty($params['send_receipt'])) {
|
||||
$fetchParticipantVals = array('id' => $this->_participantId);
|
||||
CRM_Event_BAO_Participant::getValues($fetchParticipantVals, $participantDetails, CRM_Core_DAO::$_nullArray);
|
||||
$participantParams = array_merge($params, $participantDetails[$this->_participantId]);
|
||||
$mailSent = $this->emailReceipt($participantParams);
|
||||
}
|
||||
|
||||
// update participant
|
||||
CRM_Core_DAO::setFieldValue('CRM_Event_DAO_Participant', $this->_participantId, 'status_id', $params['status_id']);
|
||||
if (!empty($params['note'])) {
|
||||
$noteParams = array(
|
||||
'entity_table' => 'civicrm_participant',
|
||||
'note' => $params['note'],
|
||||
'entity_id' => $this->_participantId,
|
||||
'contact_id' => $this->_contactId,
|
||||
'modified_date' => date('Ymd'),
|
||||
);
|
||||
CRM_Core_BAO_Note::add($noteParams);
|
||||
}
|
||||
CRM_Core_Session::setStatus(ts("The fee selection has been changed for this participant"), ts('Saved'), 'success');
|
||||
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
if ($buttonName == $this->getButtonName('upload', 'new')) {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->pushUserContext(CRM_Utils_System::url('civicrm/payment/add',
|
||||
"reset=1&action=add&component=event&id={$this->_participantId}&cid={$this->_contactId}"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function emailReceipt(&$params) {
|
||||
$updatedLineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant', FALSE, FALSE);
|
||||
$lineItem = array();
|
||||
if ($updatedLineItem) {
|
||||
$lineItem[] = $updatedLineItem;
|
||||
}
|
||||
$this->assign('lineItem', empty($lineItem) ? FALSE : $lineItem);
|
||||
|
||||
// offline receipt sending
|
||||
if (array_key_exists($params['from_email_address'], $this->_fromEmails['from_email_id'])) {
|
||||
$receiptFrom = $params['from_email_address'];
|
||||
}
|
||||
|
||||
$this->assign('module', 'Event Registration');
|
||||
//use of the message template below requires variables in different format
|
||||
$event = $events = array();
|
||||
$returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
|
||||
|
||||
//get all event details.
|
||||
CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
|
||||
$event = $events[$params['event_id']];
|
||||
unset($event['start_date']);
|
||||
unset($event['end_date']);
|
||||
|
||||
$role = CRM_Event_PseudoConstant::participantRole();
|
||||
$participantRoles = CRM_Utils_Array::value('role_id', $params);
|
||||
if (is_array($participantRoles)) {
|
||||
$selectedRoles = array();
|
||||
foreach (array_keys($participantRoles) as $roleId) {
|
||||
$selectedRoles[] = $role[$roleId];
|
||||
}
|
||||
$event['participant_role'] = implode(', ', $selectedRoles);
|
||||
}
|
||||
else {
|
||||
$event['participant_role'] = CRM_Utils_Array::value($participantRoles, $role);
|
||||
}
|
||||
$event['is_monetary'] = $this->_isPaidEvent;
|
||||
|
||||
if ($params['receipt_text']) {
|
||||
$event['confirm_email_text'] = $params['receipt_text'];
|
||||
}
|
||||
|
||||
$this->assign('isAmountzero', 1);
|
||||
$this->assign('event', $event);
|
||||
|
||||
$this->assign('isShowLocation', $event['is_show_location']);
|
||||
if (CRM_Utils_Array::value('is_show_location', $event) == 1) {
|
||||
$locationParams = array(
|
||||
'entity_id' => $params['event_id'],
|
||||
'entity_table' => 'civicrm_event',
|
||||
);
|
||||
$location = CRM_Core_BAO_Location::getValues($locationParams, TRUE);
|
||||
$this->assign('location', $location);
|
||||
}
|
||||
|
||||
$status = CRM_Event_PseudoConstant::participantStatus();
|
||||
if ($this->_isPaidEvent) {
|
||||
$paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
|
||||
if (!$this->_mode) {
|
||||
if (isset($params['payment_instrument_id'])) {
|
||||
$this->assign('paidBy',
|
||||
CRM_Utils_Array::value($params['payment_instrument_id'],
|
||||
$paymentInstrument
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('totalAmount', $this->contributionAmt);
|
||||
|
||||
$this->assign('isPrimary', 1);
|
||||
$this->assign('checkNumber', CRM_Utils_Array::value('check_number', $params));
|
||||
}
|
||||
|
||||
$this->assign('register_date', $params['register_date']);
|
||||
$template = CRM_Core_Smarty::singleton();
|
||||
|
||||
// Retrieve the name and email of the contact - this will be the TO for receipt email
|
||||
list($this->_contributorDisplayName, $this->_contributorEmail, $this->_toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($this->_contactId);
|
||||
|
||||
$this->_contributorDisplayName = ($this->_contributorDisplayName == ' ') ? $this->_contributorEmail : $this->_contributorDisplayName;
|
||||
|
||||
$waitStatus = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'");
|
||||
if ($waitingStatus = CRM_Utils_Array::value($params['status_id'], $waitStatus)) {
|
||||
$this->assign('isOnWaitlist', TRUE);
|
||||
}
|
||||
$this->assign('contactID', $this->_contactId);
|
||||
$this->assign('participantID', $this->_participantId);
|
||||
|
||||
$sendTemplateParams = array(
|
||||
'groupName' => 'msg_tpl_workflow_event',
|
||||
'valueName' => 'event_offline_receipt',
|
||||
'contactId' => $this->_contactId,
|
||||
'isTest' => FALSE,
|
||||
'PDFFilename' => ts('confirmation') . '.pdf',
|
||||
);
|
||||
|
||||
// try to send emails only if email id is present
|
||||
// and the do-not-email option is not checked for that contact
|
||||
if ($this->_contributorEmail && !$this->_toDoNotEmail) {
|
||||
$sendTemplateParams['from'] = $receiptFrom;
|
||||
$sendTemplateParams['toName'] = $this->_contributorDisplayName;
|
||||
$sendTemplateParams['toEmail'] = $this->_contributorEmail;
|
||||
$sendTemplateParams['cc'] = CRM_Utils_Array::value('cc', $this->_fromEmails);
|
||||
$sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc', $this->_fromEmails);
|
||||
}
|
||||
|
||||
list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
|
||||
return $mailSent;
|
||||
}
|
||||
|
||||
}
|
251
sites/all/modules/civicrm/CRM/Event/Form/ParticipantView.php
Normal file
251
sites/all/modules/civicrm/CRM/Event/Form/ParticipantView.php
Normal file
|
@ -0,0 +1,251 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for Participant
|
||||
*
|
||||
*/
|
||||
class CRM_Event_Form_ParticipantView extends CRM_Core_Form {
|
||||
|
||||
public $useLivePageJS = TRUE;
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
$values = $ids = array();
|
||||
$participantID = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
|
||||
$contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
|
||||
$params = array('id' => $participantID);
|
||||
|
||||
CRM_Event_BAO_Participant::getValues($params,
|
||||
$values,
|
||||
$ids
|
||||
);
|
||||
|
||||
if (empty($values)) {
|
||||
CRM_Core_Error::statusBounce(ts('The requested participant record does not exist (possibly the record was deleted).'));
|
||||
}
|
||||
|
||||
CRM_Event_BAO_Participant::resolveDefaults($values[$participantID]);
|
||||
|
||||
if (!empty($values[$participantID]['fee_level'])) {
|
||||
CRM_Event_BAO_Participant::fixEventLevel($values[$participantID]['fee_level']);
|
||||
}
|
||||
|
||||
$this->assign('contactId', $contactID);
|
||||
$this->assign('participantId', $participantID);
|
||||
|
||||
$paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
|
||||
$participantID, 'id', 'participant_id'
|
||||
);
|
||||
$this->assign('hasPayment', $paymentId);
|
||||
$this->assign('componentId', $participantID);
|
||||
$this->assign('component', 'event');
|
||||
|
||||
if ($parentParticipantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant',
|
||||
$participantID, 'registered_by_id'
|
||||
)
|
||||
) {
|
||||
$parentHasPayment = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
|
||||
$parentParticipantId, 'id', 'participant_id'
|
||||
);
|
||||
$this->assign('parentHasPayment', $parentHasPayment);
|
||||
}
|
||||
|
||||
$statusId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $participantID, 'status_id', 'id');
|
||||
$status = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantStatusType', $statusId, 'name', 'id');
|
||||
$status = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantStatusType', $statusId, 'name', 'id');
|
||||
if ($status == 'Transferred') {
|
||||
$transferId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $participantID, 'transferred_to_contact_id', 'id');
|
||||
$pid = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $transferId, 'id', 'contact_id');
|
||||
$transferName = current(CRM_Contact_BAO_Contact::getContactDetails($transferId));
|
||||
$this->assign('pid', $pid);
|
||||
$this->assign('transferId', $transferId);
|
||||
$this->assign('transferName', $transferName);
|
||||
}
|
||||
$participantStatuses = CRM_Event_PseudoConstant::participantStatus();
|
||||
|
||||
if ($values[$participantID]['is_test']) {
|
||||
$values[$participantID]['status'] .= ' (test) ';
|
||||
}
|
||||
|
||||
// Get Note
|
||||
$noteValue = CRM_Core_BAO_Note::getNote($participantID, 'civicrm_participant');
|
||||
|
||||
$values[$participantID]['note'] = array_values($noteValue);
|
||||
|
||||
// Get Line Items
|
||||
$lineItem = CRM_Price_BAO_LineItem::getLineItems($participantID);
|
||||
|
||||
if (!CRM_Utils_System::isNull($lineItem)) {
|
||||
$values[$participantID]['lineItem'][] = $lineItem;
|
||||
}
|
||||
|
||||
$values[$participantID]['totalAmount'] = CRM_Utils_Array::value('fee_amount', $values[$participantID]);
|
||||
|
||||
// Get registered_by contact ID and display_name if participant was registered by someone else (CRM-4859)
|
||||
if (!empty($values[$participantID]['participant_registered_by_id'])) {
|
||||
$values[$participantID]['registered_by_contact_id'] = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant",
|
||||
$values[$participantID]['participant_registered_by_id'],
|
||||
'contact_id', 'id'
|
||||
);
|
||||
$values[$participantID]['registered_by_display_name'] = CRM_Contact_BAO_Contact::displayName($values[$participantID]['registered_by_contact_id']);
|
||||
}
|
||||
|
||||
// Check if this is a primaryParticipant (registered for others) and retrieve additional participants if true (CRM-4859)
|
||||
if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantID)) {
|
||||
$values[$participantID]['additionalParticipants'] = CRM_Event_BAO_Participant::getAdditionalParticipants($participantID);
|
||||
}
|
||||
|
||||
// get the option value for custom data type
|
||||
$customDataType = CRM_Core_OptionGroup::values('custom_data_type', FALSE, FALSE, FALSE, NULL, 'name');
|
||||
$roleCustomDataTypeID = array_search('ParticipantRole', $customDataType);
|
||||
$eventNameCustomDataTypeID = array_search('ParticipantEventName', $customDataType);
|
||||
$eventTypeCustomDataTypeID = array_search('ParticipantEventType', $customDataType);
|
||||
$allRoleIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, $values[$participantID]['role_id']);
|
||||
$groupTree = array();
|
||||
$finalTree = array();
|
||||
|
||||
foreach ($allRoleIDs as $k => $v) {
|
||||
$roleGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', NULL, $participantID, NULL, $v, $roleCustomDataTypeID);
|
||||
$eventGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', NULL, $participantID, NULL,
|
||||
$values[$participantID]['event_id'], $eventNameCustomDataTypeID
|
||||
);
|
||||
$eventTypeID = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $values[$participantID]['event_id'], 'event_type_id', 'id');
|
||||
$eventTypeGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', NULL, $participantID, NULL, $eventTypeID, $eventTypeCustomDataTypeID);
|
||||
$groupTree = CRM_Utils_Array::crmArrayMerge($roleGroupTree, $eventGroupTree);
|
||||
$groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, $eventTypeGroupTree);
|
||||
$groupTree = CRM_Utils_Array::crmArrayMerge($groupTree, CRM_Core_BAO_CustomGroup::getTree('Participant', NULL, $participantID));
|
||||
foreach ($groupTree as $treeId => $trees) {
|
||||
$finalTree[$treeId] = $trees;
|
||||
}
|
||||
}
|
||||
CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $finalTree, FALSE, NULL, NULL, NULL, $participantID);
|
||||
$eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $values[$participantID]['event_id'], 'title');
|
||||
//CRM-7150, show event name on participant view even if the event is disabled
|
||||
if (empty($values[$participantID]['event'])) {
|
||||
$values[$participantID]['event'] = $eventTitle;
|
||||
}
|
||||
|
||||
//do check for campaigns
|
||||
if ($campaignId = CRM_Utils_Array::value('campaign_id', $values[$participantID])) {
|
||||
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
|
||||
$values[$participantID]['campaign'] = $campaigns[$campaignId];
|
||||
}
|
||||
|
||||
$this->assign($values[$participantID]);
|
||||
|
||||
// add viewed participant to recent items list
|
||||
$url = CRM_Utils_System::url('civicrm/contact/view/participant',
|
||||
"action=view&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"
|
||||
);
|
||||
|
||||
$recentOther = array();
|
||||
if (CRM_Core_Permission::check('edit event participants')) {
|
||||
$recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant',
|
||||
"action=update&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"
|
||||
);
|
||||
}
|
||||
if (CRM_Core_Permission::check('delete in CiviEvent')) {
|
||||
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant',
|
||||
"action=delete&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"
|
||||
);
|
||||
}
|
||||
|
||||
$participantRoles = CRM_Event_PseudoConstant::participantRole();
|
||||
$displayName = CRM_Contact_BAO_Contact::displayName($values[$participantID]['contact_id']);
|
||||
|
||||
$participantCount = array();
|
||||
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
|
||||
$invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
|
||||
$totalTaxAmount = 0;
|
||||
foreach ($lineItem as $k => $v) {
|
||||
if (CRM_Utils_Array::value('participant_count', $lineItem[$k]) > 0) {
|
||||
$participantCount[] = $lineItem[$k]['participant_count'];
|
||||
}
|
||||
$totalTaxAmount = $v['tax_amount'] + $totalTaxAmount;
|
||||
}
|
||||
if ($invoicing) {
|
||||
$this->assign('totalTaxAmount', $totalTaxAmount);
|
||||
}
|
||||
if ($participantCount) {
|
||||
$this->assign('pricesetFieldsCount', $participantCount);
|
||||
}
|
||||
$this->assign('displayName', $displayName);
|
||||
// omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
|
||||
CRM_Utils_System::setTitle(ts('View Event Registration for') . ' ' . $displayName);
|
||||
|
||||
$roleId = CRM_Utils_Array::value('role_id', $values[$participantID]);
|
||||
$title = $displayName . ' (' . CRM_Utils_Array::value($roleId, $participantRoles) . ' - ' . $eventTitle . ')';
|
||||
|
||||
$sep = CRM_Core_DAO::VALUE_SEPARATOR;
|
||||
$viewRoles = array();
|
||||
foreach (explode($sep, $values[$participantID]['role_id']) as $k => $v) {
|
||||
$viewRoles[] = $participantRoles[$v];
|
||||
}
|
||||
$values[$participantID]['role_id'] = implode(', ', $viewRoles);
|
||||
$this->assign('role', $values[$participantID]['role_id']);
|
||||
// add Participant to Recent Items
|
||||
CRM_Utils_Recent::add($title,
|
||||
$url,
|
||||
$values[$participantID]['id'],
|
||||
'Participant',
|
||||
$values[$participantID]['contact_id'],
|
||||
NULL,
|
||||
$recentOther
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Done'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
1710
sites/all/modules/civicrm/CRM/Event/Form/Registration.php
Normal file
1710
sites/all/modules/civicrm/CRM/Event/Form/Registration.php
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,783 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for processing Event.
|
||||
*/
|
||||
class CRM_Event_Form_Registration_AdditionalParticipant extends CRM_Event_Form_Registration {
|
||||
|
||||
/**
|
||||
* Pre-registered additional participant id.
|
||||
*/
|
||||
public $additionalParticipantId = NULL;
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
$participantNo = substr($this->_name, 12);
|
||||
|
||||
//lets process in-queue participants.
|
||||
if ($this->_participantId && $this->_additionalParticipantIds) {
|
||||
$this->_additionalParticipantId = CRM_Utils_Array::value($participantNo, $this->_additionalParticipantIds);
|
||||
}
|
||||
|
||||
$participantCnt = $participantNo + 1;
|
||||
$this->assign('formId', $participantNo);
|
||||
$this->_params = array();
|
||||
$this->_params = $this->get('params');
|
||||
|
||||
$participantTot = $this->_params[0]['additional_participants'] + 1;
|
||||
$skipCount = count(array_keys($this->_params, "skip"));
|
||||
if ($skipCount) {
|
||||
$this->assign('skipCount', $skipCount);
|
||||
}
|
||||
CRM_Utils_System::setTitle(ts('Register Participant %1 of %2', array(1 => $participantCnt, 2 => $participantTot)));
|
||||
|
||||
//CRM-4320, hack to check last participant.
|
||||
$this->_lastParticipant = FALSE;
|
||||
if ($participantTot == $participantCnt) {
|
||||
$this->_lastParticipant = TRUE;
|
||||
}
|
||||
$this->assign('lastParticipant', $this->_lastParticipant);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. For edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = $unsetSubmittedOptions = array();
|
||||
$discountId = NULL;
|
||||
//fix for CRM-3088, default value for discount set.
|
||||
if (!empty($this->_values['discount'])) {
|
||||
$discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
|
||||
if ($discountId && !empty($this->_values['event']['default_discount_fee_id'])) {
|
||||
$discountKey = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_OptionValue", $this->_values['event']['default_discount_fee_id'], 'weight', 'id'
|
||||
);
|
||||
$defaults['amount'] = key(array_slice($this->_values['discount'][$discountId], $discountKey - 1, $discountKey, TRUE));
|
||||
}
|
||||
}
|
||||
if ($this->_priceSetId) {
|
||||
foreach ($this->_feeBlock as $key => $val) {
|
||||
if (empty($val['options'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$optionsFull = CRM_Utils_Array::value('option_full_ids', $val, array());
|
||||
foreach ($val['options'] as $keys => $values) {
|
||||
if ($values['is_default'] && !in_array($keys, $optionsFull)) {
|
||||
if ($val['html_type'] == 'CheckBox') {
|
||||
$defaults["price_{$key}"][$keys] = 1;
|
||||
}
|
||||
else {
|
||||
$defaults["price_{$key}"] = $keys;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($optionsFull)) {
|
||||
$unsetSubmittedOptions[$val['id']] = $optionsFull;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//CRM-4320, setdefault additional participant values.
|
||||
if ($this->_allowConfirmation && $this->_additionalParticipantId) {
|
||||
//hack to get set default from eventFees.php
|
||||
$this->_discountId = $discountId;
|
||||
$this->_pId = $this->_additionalParticipantId;
|
||||
$this->_contactId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_additionalParticipantId, 'contact_id');
|
||||
|
||||
CRM_Event_BAO_Participant::formatFieldsAndSetProfileDefaults($this->_contactId, $this);
|
||||
$participantDefaults = CRM_Event_Form_EventFees::setDefaultValues($this);
|
||||
$participantDefaults = array_merge($this->_defaults, $participantDefaults);
|
||||
// use primary email address if billing email address is empty
|
||||
if (empty($this->_defaults["email-{$this->_bltID}"]) &&
|
||||
!empty($this->_defaults["email-Primary"])
|
||||
) {
|
||||
$participantDefaults["email-{$this->_bltID}"] = $this->_defaults["email-Primary"];
|
||||
}
|
||||
$defaults = array_merge($defaults, $participantDefaults);
|
||||
}
|
||||
|
||||
$defaults = array_merge($this->_defaults, $defaults);
|
||||
|
||||
//reset values for all options those are full.
|
||||
CRM_Event_Form_Registration::resetElementValue($unsetSubmittedOptions, $this);
|
||||
|
||||
//load default campaign from page.
|
||||
if (array_key_exists('participant_campaign_id', $this->_fields)) {
|
||||
$defaults['participant_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
|
||||
}
|
||||
|
||||
//CRM-17865 set custom field defaults
|
||||
if (!empty($this->_fields)) {
|
||||
foreach ($this->_fields as $name => $field) {
|
||||
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
|
||||
if (!isset($defaults[$name])) {
|
||||
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults,
|
||||
NULL, CRM_Profile_Form::MODE_REGISTER
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
|
||||
$button = substr($this->controller->getButtonName(), -4);
|
||||
|
||||
$this->add('hidden', 'scriptFee', NULL);
|
||||
$this->add('hidden', 'scriptArray', NULL);
|
||||
|
||||
if ($this->_values['event']['is_monetary']) {
|
||||
CRM_Event_Form_Registration_Register::buildAmount($this);
|
||||
}
|
||||
$first_name = $last_name = NULL;
|
||||
$pre = $post = array();
|
||||
foreach (array(
|
||||
'pre',
|
||||
'post',
|
||||
) as $keys) {
|
||||
if (isset($this->_values['additional_custom_' . $keys . '_id'])) {
|
||||
$this->buildCustom($this->_values['additional_custom_' . $keys . '_id'], 'additionalCustom' . ucfirst($keys));
|
||||
$$keys = CRM_Core_BAO_UFGroup::getFields($this->_values['additional_custom_' . $keys . '_id']);
|
||||
}
|
||||
foreach (array(
|
||||
'first_name',
|
||||
'last_name',
|
||||
) as $name) {
|
||||
if (array_key_exists($name, $$keys) &&
|
||||
CRM_Utils_Array::value('is_required', CRM_Utils_Array::value($name, $$keys))
|
||||
) {
|
||||
$$name = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$required = ($button == 'skip' ||
|
||||
$this->_values['event']['allow_same_participant_emails'] == 1 &&
|
||||
($first_name && $last_name)
|
||||
) ? FALSE : TRUE;
|
||||
|
||||
//add buttons
|
||||
$js = NULL;
|
||||
if ($this->isLastParticipant(TRUE) && empty($this->_values['event']['is_monetary'])) {
|
||||
$js = array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');");
|
||||
}
|
||||
|
||||
//handle case where user might sart with waiting by group
|
||||
//registration and skip some people and now group fit to
|
||||
//become registered so need to take payment from user.
|
||||
//this case only occurs at dynamic waiting status, CRM-4320
|
||||
$statusMessage = NULL;
|
||||
$allowToProceed = TRUE;
|
||||
$includeSkipButton = TRUE;
|
||||
$this->_resetAllowWaitlist = FALSE;
|
||||
|
||||
$pricesetFieldsCount = CRM_Price_BAO_PriceSet::getPricesetCount($this->_priceSetId);
|
||||
|
||||
if ($this->_lastParticipant || $pricesetFieldsCount) {
|
||||
//get the participant total.
|
||||
$processedCnt = self::getParticipantCount($this, $this->_params, TRUE);
|
||||
}
|
||||
|
||||
if (!$this->_allowConfirmation && !empty($this->_params[0]['bypass_payment']) &&
|
||||
$this->_lastParticipant
|
||||
) {
|
||||
|
||||
//get the event spaces.
|
||||
$spaces = $this->_availableRegistrations;
|
||||
|
||||
$currentPageMaxCount = 1;
|
||||
if ($pricesetFieldsCount) {
|
||||
$currentPageMaxCount = $pricesetFieldsCount;
|
||||
}
|
||||
|
||||
//we might did reset allow waiting in case of dynamic calculation
|
||||
// @TODO - does this bypass_payment still exist?
|
||||
if (!empty($this->_params[0]['bypass_payment']) &&
|
||||
is_numeric($spaces) &&
|
||||
$processedCnt > $spaces
|
||||
) {
|
||||
$this->_allowWaitlist = TRUE;
|
||||
$this->set('allowWaitlist', TRUE);
|
||||
}
|
||||
|
||||
//lets allow to become a part of runtime waiting list, if primary selected pay later.
|
||||
$realPayLater = FALSE;
|
||||
if (!empty($this->_values['event']['is_monetary']) && !empty($this->_values['event']['is_pay_later'])) {
|
||||
$realPayLater = CRM_Utils_Array::value('is_pay_later', $this->_params[0]);
|
||||
}
|
||||
|
||||
//truly spaces are greater than required.
|
||||
if (is_numeric($spaces) && $spaces >= ($processedCnt + $currentPageMaxCount)) {
|
||||
if (CRM_Utils_Array::value('amount', $this->_params[0], 0) == 0 || $this->_requireApproval) {
|
||||
$this->_allowWaitlist = FALSE;
|
||||
$this->set('allowWaitlist', $this->_allowWaitlist);
|
||||
if ($this->_requireApproval) {
|
||||
$statusMessage = ts("It looks like you are now registering a group of %1 participants. The event has %2 available spaces (you will not be wait listed). Registration for this event requires approval. You will receive an email once your registration has been reviewed.", array(
|
||||
1 => ++$processedCnt,
|
||||
2 => $spaces,
|
||||
));
|
||||
}
|
||||
else {
|
||||
$statusMessage = ts("It looks like you are now registering a group of %1 participants. The event has %2 available spaces (you will not be wait listed).", array(
|
||||
1 => ++$processedCnt,
|
||||
2 => $spaces,
|
||||
));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$statusMessage = ts("It looks like you are now registering a group of %1 participants. The event has %2 available spaces (you will not be wait listed). Please go back to the main registration page and reduce the number of additional people. You will also need to complete payment information.", array(
|
||||
1 => ++$processedCnt,
|
||||
2 => $spaces,
|
||||
));
|
||||
$allowToProceed = FALSE;
|
||||
}
|
||||
CRM_Core_Session::setStatus($statusMessage, ts('Registration Error'), 'error');
|
||||
}
|
||||
elseif ($processedCnt == $spaces) {
|
||||
if (CRM_Utils_Array::value('amount', $this->_params[0], 0) == 0
|
||||
|| $realPayLater || $this->_requireApproval
|
||||
) {
|
||||
$this->_resetAllowWaitlist = TRUE;
|
||||
if ($this->_requireApproval) {
|
||||
$statusMessage = ts("If you skip this participant there will be enough spaces in the event for your group (you will not be wait listed). Registration for this event requires approval. You will receive an email once your registration has been reviewed.");
|
||||
}
|
||||
else {
|
||||
$statusMessage = ts("If you skip this participant there will be enough spaces in the event for your group (you will not be wait listed).");
|
||||
}
|
||||
}
|
||||
else {
|
||||
//hey there is enough space and we require payment.
|
||||
$statusMessage = ts("If you skip this participant there will be enough spaces in the event for your group (you will not be wait listed). Please go back to the main registration page and reduce the number of additional people. You will also need to complete payment information.");
|
||||
$includeSkipButton = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for priceset with count
|
||||
if ($pricesetFieldsCount && !empty($this->_values['event']['has_waitlist']) &&
|
||||
!$this->_allowConfirmation
|
||||
) {
|
||||
|
||||
if ($this->_isEventFull) {
|
||||
$statusMessage = ts('This event is currently full. You are registering for the waiting list. You will be notified if spaces become available.');
|
||||
}
|
||||
elseif ($this->_allowWaitlist ||
|
||||
(!$this->_allowWaitlist && ($processedCnt + $pricesetFieldsCount) > $this->_availableRegistrations)
|
||||
) {
|
||||
|
||||
$waitingMsg = ts('It looks like you are registering more participants then there are spaces available. All participants will be added to the waiting list. You will be notified if spaces become available.');
|
||||
$confirmedMsg = ts('It looks like there are enough spaces in this event for your group (you will not be wait listed).');
|
||||
if ($this->_requireApproval) {
|
||||
$waitingMsg = ts('It looks like you are now registering a group of %1 participants. The event has %2 available spaces (you will not be wait listed). Registration for this event requires approval. You will receive an email once your registration has been reviewed.');
|
||||
$confirmedMsg = ts('It looks there are enough spaces in this event for your group (you will not be wait listed). Registration for this event requires approval. You will receive an email once your registration has been reviewed.');
|
||||
}
|
||||
|
||||
$this->assign('waitingMsg', $waitingMsg);
|
||||
$this->assign('confirmedMsg', $confirmedMsg);
|
||||
|
||||
$this->assign('availableRegistrations', $this->_availableRegistrations);
|
||||
$this->assign('currentParticipantCount', $processedCnt);
|
||||
$this->assign('allowGroupOnWaitlist', TRUE);
|
||||
|
||||
$paymentBypassed = NULL;
|
||||
if (!empty($this->_params[0]['bypass_payment']) &&
|
||||
!$this->_allowWaitlist &&
|
||||
!$realPayLater &&
|
||||
!$this->_requireApproval &&
|
||||
!(CRM_Utils_Array::value('amount', $this->_params[0], 0) == 0)
|
||||
) {
|
||||
$paymentBypassed = ts('Please go back to the main registration page, to complete payment information.');
|
||||
}
|
||||
$this->assign('paymentBypassed', $paymentBypassed);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('statusMessage', $statusMessage);
|
||||
|
||||
$buttons = array(
|
||||
array(
|
||||
'type' => 'back',
|
||||
'name' => ts('Go Back'),
|
||||
'spacing' => '  ',
|
||||
),
|
||||
);
|
||||
|
||||
//CRM-4320
|
||||
if ($allowToProceed) {
|
||||
$buttons = array_merge($buttons, array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Continue'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
'js' => $js,
|
||||
),
|
||||
)
|
||||
);
|
||||
if ($includeSkipButton) {
|
||||
$buttons = array_merge($buttons, array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Skip Participant'),
|
||||
'subName' => 'skip',
|
||||
'icon' => 'fa-fast-forward',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->addButtons($buttons);
|
||||
$this->addFormRule(array('CRM_Event_Form_Registration_AdditionalParticipant', 'formRule'), $this);
|
||||
$this->unsavedChangesWarn = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Global form rule.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
* @param array $files
|
||||
* The uploaded files if any.
|
||||
* @param $self
|
||||
*
|
||||
*
|
||||
* @return bool|array
|
||||
* true if no errors, else array of errors
|
||||
*/
|
||||
public static function formRule($fields, $files, $self) {
|
||||
$errors = array();
|
||||
//get the button name.
|
||||
$button = substr($self->controller->getButtonName(), -4);
|
||||
|
||||
$realPayLater = FALSE;
|
||||
if (!empty($self->_values['event']['is_monetary']) && !empty($self->_values['event']['is_pay_later'])) {
|
||||
$realPayLater = CRM_Utils_Array::value('is_pay_later', $self->_params[0]);
|
||||
}
|
||||
|
||||
if ($button != 'skip') {
|
||||
//Check that either an email or firstname+lastname is included in the form(CRM-9587)
|
||||
CRM_Event_Form_Registration_Register::checkProfileComplete($fields, $errors, $self->_eventId);
|
||||
|
||||
//Additional Participant can also register for an event only once
|
||||
$isRegistered = CRM_Event_Form_Registration_Register::checkRegistration($fields, $self, TRUE);
|
||||
if ($isRegistered) {
|
||||
if ($self->_values['event']['allow_same_participant_emails']) {
|
||||
$errors['_qf_default'] = ts('A person is already registered for this event.');
|
||||
}
|
||||
else {
|
||||
$errors["email-{$self->_bltID}"] = ts('A person with this email address is already registered for this event.');
|
||||
}
|
||||
}
|
||||
|
||||
//get the complete params.
|
||||
$params = $self->get('params');
|
||||
|
||||
//take the participant instance.
|
||||
$addParticipantNum = substr($self->_name, 12);
|
||||
|
||||
if (is_array($params)) {
|
||||
foreach ($params as $key => $value) {
|
||||
if ($key != $addParticipantNum) {
|
||||
if (!$self->_values['event']['allow_same_participant_emails']) {
|
||||
//collect all email fields
|
||||
$existingEmails = array();
|
||||
$additionalParticipantEmails = array();
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $key => $val) {
|
||||
if (substr($key, 0, 6) == 'email-' && $val) {
|
||||
$existingEmails[] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($fields as $key => $val) {
|
||||
if (substr($key, 0, 6) == 'email-' && $val) {
|
||||
$additionalParticipantEmails[] = $val;
|
||||
$mailKey = $key;
|
||||
}
|
||||
}
|
||||
//check if any emails are common to both arrays
|
||||
if (count(array_intersect($existingEmails, $additionalParticipantEmails))) {
|
||||
$errors[$mailKey] = ts('The email address must be unique for each participant.');
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// check with first_name and last_name for additional participants
|
||||
if (!empty($value['first_name']) && ($value['first_name'] == CRM_Utils_Array::value('first_name', $fields)) &&
|
||||
(CRM_Utils_Array::value('last_name', $value) == CRM_Utils_Array::value('last_name', $fields))
|
||||
) {
|
||||
$errors['first_name'] = ts('The first name and last name must be unique for each participant.');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//check for atleast one pricefields should be selected
|
||||
if (!empty($fields['priceSetId'])) {
|
||||
$allParticipantParams = $params;
|
||||
|
||||
//format current participant params.
|
||||
$allParticipantParams[$addParticipantNum] = self::formatPriceSetParams($self, $fields);
|
||||
$totalParticipants = self::getParticipantCount($self, $allParticipantParams);
|
||||
|
||||
//validate price field params.
|
||||
$priceSetErrors = self::validatePriceSet($self, $allParticipantParams);
|
||||
$errors = array_merge($errors, CRM_Utils_Array::value($addParticipantNum, $priceSetErrors, array()));
|
||||
|
||||
if (!$self->_allowConfirmation &&
|
||||
is_numeric($self->_availableRegistrations)
|
||||
) {
|
||||
if (!empty($self->_params[0]['bypass_payment']) &&
|
||||
!$self->_allowWaitlist &&
|
||||
!$realPayLater &&
|
||||
!$self->_requireApproval &&
|
||||
!(CRM_Utils_Array::value('amount', $self->_params[0], 0) == 0) &&
|
||||
$totalParticipants < $self->_availableRegistrations
|
||||
) {
|
||||
$errors['_qf_default'] = ts("Your event registration will be confirmed. Please go back to the main registration page, to complete payment information.");
|
||||
}
|
||||
//check for availability of registrations.
|
||||
if (!$self->_allowConfirmation && empty($self->_values['event']['has_waitlist']) &&
|
||||
$totalParticipants > $self->_availableRegistrations
|
||||
) {
|
||||
$errors['_qf_default'] = ts('Sorry, it looks like this event only has %2 spaces available, and you are trying to register %1 participants. Please change your selections accordingly.', array(
|
||||
1 => $totalParticipants,
|
||||
2 => $self->_availableRegistrations,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($button == 'skip' && $self->_lastParticipant && !empty($fields['priceSetId'])) {
|
||||
$pricesetFieldsCount = CRM_Price_BAO_PriceSet::getPricesetCount($fields['priceSetId']);
|
||||
if (($pricesetFieldsCount < 1) || $self->_allowConfirmation) {
|
||||
return $errors;
|
||||
}
|
||||
|
||||
if (!empty($self->_values['event']['has_waitlist']) && !empty($self->_params[0]['bypass_payment']) &&
|
||||
!$self->_allowWaitlist &&
|
||||
!$realPayLater &&
|
||||
!$self->_requireApproval &&
|
||||
!(CRM_Utils_Array::value('amount', $self->_params[0], 0) == 0)
|
||||
) {
|
||||
$errors['_qf_default'] = ts("You are going to skip the last participant, your event registration will be confirmed. Please go back to the main registration page, to complete payment information.");
|
||||
}
|
||||
}
|
||||
|
||||
if ($button != 'skip' &&
|
||||
$self->_values['event']['is_monetary'] &&
|
||||
!isset($errors['_qf_default']) &&
|
||||
!$self->validatePaymentValues($self, $fields)
|
||||
) {
|
||||
$errors['_qf_default'] = ts("Your payment information looks incomplete. Please go back to the main registration page, to complete payment information.");
|
||||
$self->set('forcePayement', TRUE);
|
||||
}
|
||||
elseif ($button == 'skip') {
|
||||
$self->set('forcePayement', TRUE);
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $self
|
||||
* @param $fields
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validatePaymentValues($self, $fields) {
|
||||
|
||||
if (!empty($self->_params[0]['bypass_payment']) ||
|
||||
$self->_allowWaitlist ||
|
||||
empty($self->_fields) ||
|
||||
CRM_Utils_Array::value('amount', $self->_params[0]) > 0
|
||||
) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
$validatePayement = FALSE;
|
||||
if (!empty($fields['priceSetId'])) {
|
||||
$lineItem = array();
|
||||
CRM_Price_BAO_PriceSet::processAmount($self->_values['fee'], $fields, $lineItem);
|
||||
if ($fields['amount'] > 0) {
|
||||
$validatePayement = TRUE;
|
||||
// $self->_forcePayement = true;
|
||||
// return false;
|
||||
}
|
||||
}
|
||||
elseif (!empty($fields['amount']) &&
|
||||
(CRM_Utils_Array::value('value', $self->_values['fee'][$fields['amount']]) > 0)
|
||||
) {
|
||||
$validatePayement = TRUE;
|
||||
}
|
||||
|
||||
if (!$validatePayement) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
$errors = array();
|
||||
|
||||
CRM_Core_Form::validateMandatoryFields($self->_fields, $fields, $errors);
|
||||
|
||||
if (isset($self->_params[0]['payment_processor'])) {
|
||||
// validate supplied payment instrument values (e.g. credit card number and cvv)
|
||||
$payment_processor_id = $self->_params[0]['payment_processor'];
|
||||
CRM_Core_Payment_Form::validatePaymentInstrument($payment_processor_id, $self->_params[0], $errors, (!$self->_isBillingAddressRequiredForPayLater ? NULL : 'billing'));
|
||||
}
|
||||
if (!empty($errors)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
|
||||
if ($greetingType = CRM_Utils_Array::value($greeting, $self->_params[0])) {
|
||||
$customizedValue = CRM_Core_OptionGroup::getValue($greeting, 'Customized', 'name');
|
||||
if ($customizedValue == $greetingType && empty($self->_params[0][$greeting . '_custom'])) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
//get the button name.
|
||||
$button = substr($this->controller->getButtonName(), -4);
|
||||
|
||||
//take the participant instance.
|
||||
$addParticipantNum = substr($this->_name, 12);
|
||||
|
||||
//user submitted params.
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
if (!$this->_allowConfirmation) {
|
||||
// check if the participant is already registered
|
||||
$params['contact_id'] = CRM_Event_Form_Registration_Register::getRegistrationContactID($params, $this, TRUE);
|
||||
}
|
||||
|
||||
if (!empty($params['image_URL'])) {
|
||||
CRM_Contact_BAO_Contact::processImageParams($params);
|
||||
}
|
||||
//carry campaign to partcipants.
|
||||
if (array_key_exists('participant_campaign_id', $params)) {
|
||||
$params['campaign_id'] = $params['participant_campaign_id'];
|
||||
}
|
||||
else {
|
||||
$params['campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
|
||||
}
|
||||
|
||||
// if waiting is enabled
|
||||
if (!$this->_allowConfirmation &&
|
||||
is_numeric($this->_availableRegistrations)
|
||||
) {
|
||||
$this->_allowWaitlist = FALSE;
|
||||
//get the current page count.
|
||||
$currentCount = self::getParticipantCount($this, $params);
|
||||
if ($button == 'skip') {
|
||||
$currentCount = 'skip';
|
||||
}
|
||||
|
||||
//get the total count.
|
||||
$previousCount = self::getParticipantCount($this, $this->_params, TRUE);
|
||||
$totalParticipants = $previousCount;
|
||||
if (is_numeric($currentCount)) {
|
||||
$totalParticipants += $currentCount;
|
||||
}
|
||||
if (!empty($this->_values['event']['has_waitlist']) &&
|
||||
$totalParticipants > $this->_availableRegistrations
|
||||
) {
|
||||
$this->_allowWaitlist = TRUE;
|
||||
}
|
||||
$this->set('allowWaitlist', $this->_allowWaitlist);
|
||||
$this->_lineItemParticipantsCount[$addParticipantNum] = $currentCount;
|
||||
}
|
||||
|
||||
if ($button == 'skip') {
|
||||
//hack for free/zero amount event.
|
||||
if ($this->_resetAllowWaitlist) {
|
||||
$this->_allowWaitlist = FALSE;
|
||||
$this->set('allowWaitlist', FALSE);
|
||||
if ($this->_requireApproval) {
|
||||
$status = ts("You have skipped last participant and which result into event having enough spaces, but your registration require approval, Once your registration has been reviewed, you will receive an email with a link to a web page where you can complete the registration process.");
|
||||
}
|
||||
else {
|
||||
$status = ts("You have skipped last participant and which result into event having enough spaces, hence your group become as register participants though you selected on wait list.");
|
||||
}
|
||||
CRM_Core_Session::setStatus($status);
|
||||
}
|
||||
|
||||
$this->_params[$addParticipantNum] = 'skip';
|
||||
if (isset($this->_lineItem)) {
|
||||
$this->_lineItem[$addParticipantNum] = 'skip';
|
||||
$this->_lineItemParticipantsCount[$addParticipantNum] = 'skip';
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$params['currencyID'] = $config->defaultCurrency;
|
||||
|
||||
if ($this->_values['event']['is_monetary']) {
|
||||
|
||||
//added for discount
|
||||
$discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
|
||||
$params['amount_level'] = $this->getAmountLevel($params, $discountId);
|
||||
if (!empty($this->_values['discount'][$discountId])) {
|
||||
$params['discount_id'] = $discountId;
|
||||
$params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value'];
|
||||
}
|
||||
elseif (empty($params['priceSetId'])) {
|
||||
$params['amount'] = $this->_values['fee'][$params['amount']]['value'];
|
||||
}
|
||||
else {
|
||||
$lineItem = array();
|
||||
CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem);
|
||||
|
||||
//build line item array..
|
||||
//if requireApproval/waitlist is enabled we hide fees for primary participant
|
||||
// (and not for additional participant which might be is a bug)
|
||||
//lineItem are not correctly build for primary participant
|
||||
//this results in redundancy since now lineItems for additional participant will be build against primary participantNum
|
||||
//therefore lineItems must always be build against current participant No
|
||||
$this->_lineItem[$addParticipantNum] = $lineItem;
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('participant_role', $params)) {
|
||||
$params['participant_role_id'] = $params['participant_role'];
|
||||
}
|
||||
|
||||
if (empty($params['participant_role_id']) && $this->_values['event']['default_role_id']) {
|
||||
$params['participant_role_id'] = $this->_values['event']['default_role_id'];
|
||||
}
|
||||
|
||||
if (!empty($this->_params[0]['is_pay_later'])) {
|
||||
$params['is_pay_later'] = 1;
|
||||
}
|
||||
|
||||
//carry additional participant id, contact id if pre-registered.
|
||||
if ($this->_allowConfirmation && $this->_additionalParticipantId) {
|
||||
$params['contact_id'] = $this->_contactId;
|
||||
$params['participant_id'] = $this->_additionalParticipantId;
|
||||
}
|
||||
|
||||
//build the params array.
|
||||
$this->_params[$addParticipantNum] = $params;
|
||||
}
|
||||
|
||||
//finally set the params.
|
||||
$this->set('params', $this->_params);
|
||||
//set the line item.
|
||||
if ($this->_lineItem) {
|
||||
$this->set('lineItem', $this->_lineItem);
|
||||
$this->set('lineItemParticipantsCount', $this->_lineItemParticipantsCount);
|
||||
}
|
||||
|
||||
$participantNo = count($this->_params);
|
||||
if ($button != 'skip') {
|
||||
$statusMsg = ts('Registration information for participant %1 has been saved.', array(1 => $participantNo));
|
||||
CRM_Core_Session::setStatus($statusMsg, ts('Registration Saved'), 'success');
|
||||
}
|
||||
|
||||
// Check whether to process the registration now, calling processRegistration()
|
||||
if (
|
||||
!$this->_values['event']['is_confirm_enabled'] // CRM-11182 - Optional confirmation screen
|
||||
&& !$this->_values['event']['is_monetary']
|
||||
&& CRM_Utils_Array::value('additional_participants', $this->_params[0])
|
||||
&& $this->isLastParticipant()
|
||||
) {
|
||||
$this->processRegistration($this->_params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $additionalParticipant
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function &getPages($additionalParticipant) {
|
||||
$details = array();
|
||||
for ($i = 1; $i <= $additionalParticipant; $i++) {
|
||||
$details["Participant_{$i}"] = array(
|
||||
'className' => 'CRM_Event_Form_Registration_AdditionalParticipant',
|
||||
'title' => "Register Additional Participant {$i}",
|
||||
);
|
||||
}
|
||||
return $details;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether call current participant is last one.
|
||||
*
|
||||
* @param bool $isButtonJs
|
||||
*
|
||||
* @return bool
|
||||
* ture on success.
|
||||
*/
|
||||
public function isLastParticipant($isButtonJs = FALSE) {
|
||||
$participant = $isButtonJs ? $this->_params[0]['additional_participants'] : $this->_params[0]['additional_participants'] + 1;
|
||||
if (count($this->_params) == $participant) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
1335
sites/all/modules/civicrm/CRM/Event/Form/Registration/Confirm.php
Normal file
1335
sites/all/modules/civicrm/CRM/Event/Form/Registration/Confirm.php
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,225 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for processing Event
|
||||
*
|
||||
*/
|
||||
class CRM_Event_Form_Registration_ParticipantConfirm extends CRM_Event_Form_Registration {
|
||||
// optional credit card return status code
|
||||
// CRM-6060
|
||||
protected $_cc = NULL;
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_participantId = CRM_Utils_Request::retrieve('participantId', 'Positive', $this);
|
||||
|
||||
$this->_cc = CRM_Utils_Request::retrieve('cc', 'String', $this);
|
||||
|
||||
//get the contact and event id and assing to session.
|
||||
$values = array();
|
||||
$csContactID = NULL;
|
||||
if ($this->_participantId) {
|
||||
$params = array('id' => $this->_participantId);
|
||||
CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Participant', $params, $values,
|
||||
array('contact_id', 'event_id', 'status_id')
|
||||
);
|
||||
}
|
||||
|
||||
$this->_participantStatusId = CRM_Utils_Array::value('status_id', $values);
|
||||
$this->_eventId = CRM_Utils_Array::value('event_id', $values);
|
||||
$csContactId = CRM_Utils_Array::value('contact_id', $values);
|
||||
|
||||
// make sure we have right permission to edit this user
|
||||
$this->_csContactID = NULL;
|
||||
if ($csContactId && $this->_eventId) {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
if ($csContactId == $session->get('userID')) {
|
||||
$this->_csContactID = $csContactId;
|
||||
}
|
||||
else {
|
||||
if (CRM_Contact_BAO_Contact_Permission::validateChecksumContact($csContactId, $this)) {
|
||||
//since we have landing page so get this contact
|
||||
//id in session if user really want to walk wizard.
|
||||
$this->_csContactID = $csContactId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->_csContactID) {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
CRM_Core_Error::statusBounce(ts('You do not have permission to access this event registration. Contact the site administrator if you need assistance.'), $config->userFrameworkBaseURL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$params = array('id' => $this->_eventId);
|
||||
$values = array();
|
||||
CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $params, $values,
|
||||
array('title')
|
||||
);
|
||||
|
||||
$buttons = array();
|
||||
// only pending status class family able to confirm.
|
||||
|
||||
$statusMsg = NULL;
|
||||
if (array_key_exists($this->_participantStatusId,
|
||||
CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'")
|
||||
)) {
|
||||
|
||||
//need to confirm that though participant confirming
|
||||
//registration - but is there enough space to confirm.
|
||||
$emptySeats = CRM_Event_BAO_Participant::pendingToConfirmSpaces($this->_eventId);
|
||||
$additonalIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_participantId);
|
||||
$requireSpace = 1 + count($additonalIds);
|
||||
if ($emptySeats !== NULL && ($requireSpace > $emptySeats)) {
|
||||
$statusMsg = ts("Oops, it looks like there are currently no available spaces for the %1 event.", array(1 => $values['title']));
|
||||
}
|
||||
else {
|
||||
if ($this->_cc == 'fail') {
|
||||
$statusMsg = '<div class="bold">' . ts('Your Credit Card transaction was not successful. No money has yet been charged to your card.') . '</div><div><br />' . ts('Click the "Confirm Registration" button to complete your registration in %1, or click "Cancel Registration" if you are no longer interested in attending this event.', array(
|
||||
1 => $values['title'],
|
||||
)) . '</div>';
|
||||
}
|
||||
else {
|
||||
$statusMsg = '<div class="bold">' . ts('Confirm your registration for %1.', array(
|
||||
1 => $values['title'],
|
||||
)) . '</div><div><br />' . ts('Click the "Confirm Registration" button to begin, or click "Cancel Registration" if you are no longer interested in attending this event.') . '</div>';
|
||||
}
|
||||
$buttons = array_merge($buttons, array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Confirm Registration'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// status class other than Negative should be able to cancel registration.
|
||||
if (array_key_exists($this->_participantStatusId,
|
||||
CRM_Event_PseudoConstant::participantStatus(NULL, "class != 'Negative'")
|
||||
)) {
|
||||
$cancelConfirm = ts('Are you sure you want to cancel your registration for this event?');
|
||||
$buttons = array_merge($buttons, array(
|
||||
array(
|
||||
'type' => 'submit',
|
||||
'name' => ts('Cancel Registration'),
|
||||
'spacing' => ' ',
|
||||
'js' => array('onclick' => 'return confirm(\'' . $cancelConfirm . '\');'),
|
||||
),
|
||||
));
|
||||
if (!$statusMsg) {
|
||||
$statusMsg = ts('You can cancel your registration for %1 by clicking "Cancel Registration".', array(1 => $values['title']));
|
||||
}
|
||||
}
|
||||
if (!$statusMsg) {
|
||||
$statusMsg = ts("Oops, it looks like your registration for %1 has already been cancelled.",
|
||||
array(1 => $values['title'])
|
||||
);
|
||||
}
|
||||
$this->assign('statusMsg', $statusMsg);
|
||||
|
||||
$this->addButtons($buttons);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
//get the button.
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
$participantId = $this->_participantId;
|
||||
|
||||
if ($buttonName == '_qf_ParticipantConfirm_next') {
|
||||
//lets get contact id in session.
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->set('userID', $this->_csContactID);
|
||||
|
||||
$this->postProcessHook();
|
||||
|
||||
//check user registration status is from pending class
|
||||
$url = CRM_Utils_System::url('civicrm/event/register',
|
||||
"reset=1&id={$this->_eventId}&participantId={$participantId}"
|
||||
);
|
||||
CRM_Utils_System::redirect($url);
|
||||
}
|
||||
elseif ($buttonName == '_qf_ParticipantConfirm_submit') {
|
||||
//need to registration status to 'cancelled'.
|
||||
|
||||
$cancelledId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"));
|
||||
$additionalParticipantIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId);
|
||||
|
||||
$participantIds = array_merge(array($participantId), $additionalParticipantIds);
|
||||
$results = CRM_Event_BAO_Participant::transitionParticipants($participantIds, $cancelledId, NULL, TRUE);
|
||||
|
||||
if (count($participantIds) > 1) {
|
||||
$statusMessage = ts("%1 Event registration(s) have been cancelled.", array(1 => count($participantIds)));
|
||||
}
|
||||
else {
|
||||
$statusMessage = ts("Your Event Registration has been cancelled.");
|
||||
}
|
||||
|
||||
if (!empty($results['mailedParticipants'])) {
|
||||
foreach ($results['mailedParticipants'] as $key => $displayName) {
|
||||
$statusMessage .= "<br />" . ts("Email has been sent to : %1", array(1 => $displayName));
|
||||
}
|
||||
}
|
||||
|
||||
$this->postProcessHook();
|
||||
CRM_Core_Session::setStatus($statusMessage);
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/info',
|
||||
"reset=1&id={$this->_eventId}&noFullMsg=1",
|
||||
FALSE, NULL, FALSE, TRUE
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
1243
sites/all/modules/civicrm/CRM/Event/Form/Registration/Register.php
Normal file
1243
sites/all/modules/civicrm/CRM/Event/Form/Registration/Register.php
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,250 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for processing Event
|
||||
*
|
||||
*/
|
||||
class CRM_Event_Form_Registration_ThankYou extends CRM_Event_Form_Registration {
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
$this->_params = $this->get('params');
|
||||
$this->_lineItem = $this->get('lineItem');
|
||||
$this->_part = $this->get('part');
|
||||
$this->_totalAmount = $this->get('totalAmount');
|
||||
$this->_receiveDate = $this->get('receiveDate');
|
||||
$this->_trxnId = $this->get('trxnId');
|
||||
$finalAmount = $this->get('finalAmount');
|
||||
$this->assign('finalAmount', $finalAmount);
|
||||
$participantInfo = $this->get('participantInfo');
|
||||
$this->assign('part', $this->_part);
|
||||
$this->assign('participantInfo', $participantInfo);
|
||||
$customGroup = $this->get('customProfile');
|
||||
$this->assign('customProfile', $customGroup);
|
||||
$this->assign('individual', $this->get('individual'));
|
||||
|
||||
CRM_Event_Form_Registration_Confirm::assignProfiles($this);
|
||||
|
||||
CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->_values['event']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite action, since we are only showing elements in frozen mode
|
||||
* no help display needed
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAction() {
|
||||
if ($this->_action & CRM_Core_Action::PREVIEW) {
|
||||
return CRM_Core_Action::VIEW | CRM_Core_Action::PREVIEW;
|
||||
}
|
||||
else {
|
||||
return CRM_Core_Action::VIEW;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
// Assign the email address from a contact id lookup as in CRM_Event_BAO_Event->sendMail()
|
||||
$primaryContactId = $this->get('primaryContactId');
|
||||
if ($primaryContactId) {
|
||||
list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($primaryContactId);
|
||||
$this->assign('email', $email);
|
||||
}
|
||||
$this->assignToTemplate();
|
||||
|
||||
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
|
||||
$taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
|
||||
$invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
|
||||
$getTaxDetails = FALSE;
|
||||
$taxAmount = 0;
|
||||
|
||||
$lineItemForTemplate = array();
|
||||
if (!empty($this->_lineItem) && is_array($this->_lineItem)) {
|
||||
foreach ($this->_lineItem as $key => $value) {
|
||||
if (!empty($value) && $value != 'skip') {
|
||||
$lineItemForTemplate[$key] = $value;
|
||||
if ($invoicing) {
|
||||
foreach ($value as $v) {
|
||||
if (isset($v['tax_amount']) || isset($v['tax_rate'])) {
|
||||
$taxAmount += $v['tax_amount'];
|
||||
$getTaxDetails = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_priceSetId &&
|
||||
!CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config') &&
|
||||
!empty($lineItemForTemplate)
|
||||
) {
|
||||
$this->assign('lineItem', $lineItemForTemplate);
|
||||
}
|
||||
|
||||
if ($invoicing) {
|
||||
$this->assign('getTaxDetails', $getTaxDetails);
|
||||
$this->assign('totalTaxAmount', $taxAmount);
|
||||
$this->assign('taxTerm', $taxTerm);
|
||||
}
|
||||
$this->assign('totalAmount', $this->_totalAmount);
|
||||
|
||||
$hookDiscount = $this->get('hookDiscount');
|
||||
if ($hookDiscount) {
|
||||
$this->assign('hookDiscount', $hookDiscount);
|
||||
}
|
||||
|
||||
$this->assign('receive_date', $this->_receiveDate);
|
||||
$this->assign('trxn_id', $this->_trxnId);
|
||||
|
||||
//cosider total amount.
|
||||
$this->assign('isAmountzero', ($this->_totalAmount <= 0) ? TRUE : FALSE);
|
||||
|
||||
$this->assign('defaultRole', FALSE);
|
||||
if (CRM_Utils_Array::value('defaultRole', $this->_params[0]) == 1) {
|
||||
$this->assign('defaultRole', TRUE);
|
||||
}
|
||||
$defaults = array();
|
||||
$fields = array();
|
||||
if (!empty($this->_fields)) {
|
||||
foreach ($this->_fields as $name => $dontCare) {
|
||||
$fields[$name] = 1;
|
||||
}
|
||||
}
|
||||
$fields['state_province'] = $fields['country'] = $fields['email'] = 1;
|
||||
foreach ($fields as $name => $dontCare) {
|
||||
if (isset($this->_params[0][$name])) {
|
||||
$defaults[$name] = $this->_params[0][$name];
|
||||
if (substr($name, 0, 7) == 'custom_') {
|
||||
$timeField = "{$name}_time";
|
||||
if (isset($this->_params[0][$timeField])) {
|
||||
$defaults[$timeField] = $this->_params[0][$timeField];
|
||||
}
|
||||
}
|
||||
elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)
|
||||
&& !empty($this->_params[0][$name . '_custom'])
|
||||
) {
|
||||
$defaults[$name . '_custom'] = $this->_params[0][$name . '_custom'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_submitValues = array_merge($this->_submitValues, $defaults);
|
||||
|
||||
$this->setDefaults($defaults);
|
||||
|
||||
$params['entity_id'] = $this->_eventId;
|
||||
$params['entity_table'] = 'civicrm_event';
|
||||
$data = array();
|
||||
CRM_Friend_BAO_Friend::retrieve($params, $data);
|
||||
if (!empty($data['is_active'])) {
|
||||
$friendText = $data['title'];
|
||||
$this->assign('friendText', $friendText);
|
||||
if ($this->_action & CRM_Core_Action::PREVIEW) {
|
||||
$url = CRM_Utils_System::url('civicrm/friend',
|
||||
"eid={$this->_eventId}&reset=1&action=preview&pcomponent=event"
|
||||
);
|
||||
}
|
||||
else {
|
||||
$url = CRM_Utils_System::url('civicrm/friend',
|
||||
"eid={$this->_eventId}&reset=1&pcomponent=event"
|
||||
);
|
||||
}
|
||||
$this->assign('friendURL', $url);
|
||||
}
|
||||
|
||||
$this->freeze();
|
||||
|
||||
//lets give meaningful status message, CRM-4320.
|
||||
$isOnWaitlist = $isRequireApproval = FALSE;
|
||||
if ($this->_allowWaitlist && !$this->_allowConfirmation) {
|
||||
$isOnWaitlist = TRUE;
|
||||
}
|
||||
if ($this->_requireApproval && !$this->_allowConfirmation) {
|
||||
$isRequireApproval = TRUE;
|
||||
}
|
||||
$this->assign('isOnWaitlist', $isOnWaitlist);
|
||||
$this->assign('isRequireApproval', $isRequireApproval);
|
||||
|
||||
// find pcp info
|
||||
$dao = new CRM_PCP_DAO_PCPBlock();
|
||||
$dao->entity_table = 'civicrm_event';
|
||||
$dao->entity_id = $this->_eventId;
|
||||
$dao->is_active = 1;
|
||||
$dao->find(TRUE);
|
||||
|
||||
if ($dao->id) {
|
||||
$this->assign('pcpLink', CRM_Utils_System::url('civicrm/contribute/campaign', 'action=add&reset=1&pageId=' . $this->_eventId . '&component=event'));
|
||||
$this->assign('pcpLinkText', $dao->link_text);
|
||||
}
|
||||
|
||||
// Assign Participant Count to Lineitem Table
|
||||
$this->assign('pricesetFieldsCount', CRM_Price_BAO_PriceSet::getPricesetCount($this->_priceSetId));
|
||||
|
||||
// can we blow away the session now to prevent hackery
|
||||
$this->controller->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Thank You Page');
|
||||
}
|
||||
|
||||
}
|
481
sites/all/modules/civicrm/CRM/Event/Form/Search.php
Normal file
481
sites/all/modules/civicrm/CRM/Event/Form/Search.php
Normal file
|
@ -0,0 +1,481 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Files required
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is for civievent search
|
||||
*/
|
||||
class CRM_Event_Form_Search extends CRM_Core_Form_Search {
|
||||
|
||||
/**
|
||||
* The params that are sent to the query.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_queryParams;
|
||||
|
||||
/**
|
||||
* Are we restricting ourselves to a single contact.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_single = FALSE;
|
||||
|
||||
/**
|
||||
* Are we restricting ourselves to a single contact.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_limit = NULL;
|
||||
|
||||
/**
|
||||
* Prefix for the controller.
|
||||
*/
|
||||
protected $_prefix = "event_";
|
||||
|
||||
/**
|
||||
* The saved search ID retrieved from the GET vars.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_ssID;
|
||||
|
||||
/**
|
||||
* Processing needed for buildForm and later.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->set('searchFormName', 'Search');
|
||||
|
||||
/**
|
||||
* set the button names
|
||||
*/
|
||||
$this->_searchButtonName = $this->getButtonName('refresh');
|
||||
$this->_actionButtonName = $this->getButtonName('next', 'action');
|
||||
|
||||
$this->_done = FALSE;
|
||||
$this->defaults = array();
|
||||
|
||||
/*
|
||||
* we allow the controller to set force/reset externally, useful when we are being
|
||||
* driven by the wizard framework
|
||||
*/
|
||||
$this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean');
|
||||
$this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE);
|
||||
$this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this);
|
||||
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'search');
|
||||
$this->_ssID = CRM_Utils_Request::retrieve('ssID', 'Positive', $this);
|
||||
$this->assign("context", $this->_context);
|
||||
|
||||
// get user submitted values
|
||||
// get it from controller only if form has been submitted, else preProcess has set this
|
||||
if (!empty($_POST) && !$this->controller->isModal()) {
|
||||
$this->_formValues = $this->controller->exportValues($this->_name);
|
||||
}
|
||||
else {
|
||||
$this->_formValues = $this->get('formValues');
|
||||
}
|
||||
|
||||
if (empty($this->_formValues)) {
|
||||
if (isset($this->_ssID)) {
|
||||
$this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_force) {
|
||||
$this->postProcess();
|
||||
$this->set('force', 0);
|
||||
}
|
||||
|
||||
$sortID = NULL;
|
||||
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
|
||||
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
|
||||
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
|
||||
);
|
||||
}
|
||||
|
||||
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, array('event_id'));
|
||||
$selector = new CRM_Event_Selector_Search($this->_queryParams,
|
||||
$this->_action,
|
||||
NULL,
|
||||
$this->_single,
|
||||
$this->_limit,
|
||||
$this->_context
|
||||
);
|
||||
$prefix = NULL;
|
||||
if ($this->_context == 'user') {
|
||||
$prefix = $this->_prefix;
|
||||
}
|
||||
|
||||
$this->assign("{$prefix}limit", $this->_limit);
|
||||
$this->assign("{$prefix}single", $this->_single);
|
||||
|
||||
$controller = new CRM_Core_Selector_Controller($selector,
|
||||
$this->get(CRM_Utils_Pager::PAGE_ID),
|
||||
$sortID,
|
||||
CRM_Core_Action::VIEW,
|
||||
$this,
|
||||
CRM_Core_Selector_Controller::TRANSFER,
|
||||
$prefix
|
||||
);
|
||||
$controller->setEmbedded(TRUE);
|
||||
$controller->moveFromSessionToTemplate();
|
||||
|
||||
$this->assign('summary', $this->get('summary'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
$this->addSortNameField();
|
||||
|
||||
if (CRM_Core_Permission::check('access deleted contacts') and Civi::settings()->get('contact_undelete')) {
|
||||
$this->addElement('checkbox', 'deleted_contacts', ts('Search in Trash') . '<br />' . ts('(deleted contacts)'));
|
||||
}
|
||||
|
||||
CRM_Event_BAO_Query::buildSearchForm($this);
|
||||
|
||||
$rows = $this->get('rows');
|
||||
if (is_array($rows)) {
|
||||
$lineItems = $eventIds = array();
|
||||
if (!$this->_single) {
|
||||
$this->addRowSelectors($rows);
|
||||
}
|
||||
foreach ($rows as $row) {
|
||||
$eventIds[$row['event_id']] = $row['event_id'];
|
||||
if (CRM_Event_BAO_Event::usesPriceSet($row['event_id'])) {
|
||||
// add line item details if applicable
|
||||
$lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem::getLineItems($row['participant_id']);
|
||||
}
|
||||
}
|
||||
|
||||
//get actual count only when we are dealing w/ single event.
|
||||
$participantCount = 0;
|
||||
if (count($eventIds) == 1) {
|
||||
//convert form values to clause.
|
||||
$seatClause = array();
|
||||
if (CRM_Utils_Array::value('participant_test', $this->_formValues) == '1' || CRM_Utils_Array::value('participant_test', $this->_formValues) == '0') {
|
||||
$seatClause[] = "( participant.is_test = {$this->_formValues['participant_test']} )";
|
||||
}
|
||||
if (!empty($this->_formValues['participant_status_id'])) {
|
||||
$seatClause[] = CRM_Contact_BAO_Query::buildClause("participant.status_id", '=', $this->_formValues['participant_status_id'], 'Int');
|
||||
if ($status = CRM_Utils_Array::value('IN', $this->_formValues['participant_status_id'])) {
|
||||
$this->_formValues['participant_status_id'] = $status;
|
||||
}
|
||||
}
|
||||
if (!empty($this->_formValues['participant_role_id'])) {
|
||||
$escapedRoles = array();
|
||||
foreach ((array) $this->_formValues['participant_role_id'] as $participantRole) {
|
||||
$escapedRoles[] = CRM_Utils_Type::escape($participantRole, 'String');
|
||||
}
|
||||
$seatClause[] = "( participant.role_id IN ( '" . implode("' , '", $escapedRoles) . "' ) )";
|
||||
}
|
||||
|
||||
// CRM-15379
|
||||
if (!empty($this->_formValues['participant_fee_id'])) {
|
||||
$participant_fee_id = $this->_formValues['participant_fee_id'];
|
||||
foreach ($participant_fee_id as $k => &$val) {
|
||||
$val = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $val, 'label');
|
||||
$val = CRM_Core_DAO::escapeString(trim($val));
|
||||
}
|
||||
$feeLabel = implode('|', $participant_fee_id);
|
||||
$seatClause[] = "( participant.fee_level REGEXP '{$feeLabel}' )";
|
||||
}
|
||||
|
||||
$seatClause = implode(' AND ', $seatClause);
|
||||
$participantCount = CRM_Event_BAO_Event::eventTotalSeats(array_pop($eventIds), $seatClause);
|
||||
}
|
||||
$this->assign('participantCount', $participantCount);
|
||||
$this->assign('lineItems', $lineItems);
|
||||
|
||||
$permission = CRM_Core_Permission::getPermission();
|
||||
|
||||
$tasks = CRM_Event_Task::permissionedTaskTitles($permission);
|
||||
if (isset($this->_ssID)) {
|
||||
if ($permission == CRM_Core_Permission::EDIT) {
|
||||
$tasks = $tasks + CRM_Event_Task::optionalTaskTitle();
|
||||
}
|
||||
|
||||
$savedSearchValues = array(
|
||||
'id' => $this->_ssID,
|
||||
'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'),
|
||||
);
|
||||
$this->assign_by_ref('savedSearch', $savedSearchValues);
|
||||
$this->assign('ssID', $this->_ssID);
|
||||
}
|
||||
|
||||
$this->addTaskMenu($tasks);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the label for the sortName field if email searching is on.
|
||||
*
|
||||
* (email searching is a setting under search preferences).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getSortNameLabelWithEmail() {
|
||||
return ts('Participant Name or Email');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the label for the sortName field if email searching is off.
|
||||
*
|
||||
* (email searching is a setting under search preferences).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getSortNameLabelWithOutEmail() {
|
||||
return ts('Participant Name');
|
||||
}
|
||||
|
||||
/**
|
||||
* The post processing of the form gets done here.
|
||||
*
|
||||
* Key things done during post processing are
|
||||
* - check for reset or next request. if present, skip post procesing.
|
||||
* - now check if user requested running a saved search, if so, then
|
||||
* the form values associated with the saved search are used for searching.
|
||||
* - if user has done a submit with new values the regular post submissing is
|
||||
* done.
|
||||
* The processing consists of using a Selector / Controller framework for getting the
|
||||
* search results.
|
||||
*
|
||||
* @param
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
if ($this->_done) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_done = TRUE;
|
||||
|
||||
if (!empty($_POST)) {
|
||||
$this->_formValues = $this->controller->exportValues($this->_name);
|
||||
CRM_Contact_BAO_Query::processSpecialFormValue($this->_formValues, array('participant_status_id'));
|
||||
}
|
||||
|
||||
if (empty($this->_formValues)) {
|
||||
$this->_formValues = $this->controller->exportValues($this->_name);
|
||||
}
|
||||
|
||||
$this->fixFormValues();
|
||||
|
||||
if (isset($this->_ssID) && empty($_POST)) {
|
||||
// if we are editing / running a saved search and the form has not been posted
|
||||
$this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
|
||||
}
|
||||
|
||||
// We don't show test records in summaries or dashboards
|
||||
if (empty($this->_formValues['participant_test']) && $this->_force) {
|
||||
$this->_formValues["participant_test"] = 0;
|
||||
}
|
||||
|
||||
CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues);
|
||||
|
||||
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, array('event_id'));
|
||||
|
||||
$this->set('formValues', $this->_formValues);
|
||||
$this->set('queryParams', $this->_queryParams);
|
||||
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
if ($buttonName == $this->_actionButtonName) {
|
||||
// check actionName and if next, then do not repeat a search, since we are going to the next page
|
||||
|
||||
// hack, make sure we reset the task values
|
||||
$stateMachine = $this->controller->getStateMachine();
|
||||
$formName = $stateMachine->getTaskFormName();
|
||||
$this->controller->resetPage($formName);
|
||||
return;
|
||||
}
|
||||
|
||||
$sortID = NULL;
|
||||
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
|
||||
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
|
||||
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
|
||||
);
|
||||
}
|
||||
|
||||
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, array('event_id'));
|
||||
|
||||
$selector = new CRM_Event_Selector_Search($this->_queryParams,
|
||||
$this->_action,
|
||||
NULL,
|
||||
$this->_single,
|
||||
$this->_limit,
|
||||
$this->_context
|
||||
);
|
||||
|
||||
$selector->setKey($this->controller->_key);
|
||||
|
||||
$prefix = NULL;
|
||||
if ($this->_context == 'user') {
|
||||
$prefix = $this->_prefix;
|
||||
}
|
||||
|
||||
$this->assign("{$prefix}limit", $this->_limit);
|
||||
$this->assign("{$prefix}single", $this->_single);
|
||||
|
||||
$controller = new CRM_Core_Selector_Controller($selector,
|
||||
$this->get(CRM_Utils_Pager::PAGE_ID),
|
||||
$sortID,
|
||||
CRM_Core_Action::VIEW,
|
||||
$this,
|
||||
CRM_Core_Selector_Controller::SESSION,
|
||||
$prefix
|
||||
);
|
||||
$controller->setEmbedded(TRUE);
|
||||
|
||||
$query = $selector->getQuery();
|
||||
if ($this->_context == 'user') {
|
||||
$query->setSkipPermission(TRUE);
|
||||
}
|
||||
$controller->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* add the rules (mainly global rules) for form.
|
||||
* All local rules are added near the element
|
||||
*
|
||||
* @return void
|
||||
* @see valid_date
|
||||
*/
|
||||
public function addRules() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default form values.
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* the default array reference
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
$defaults = $this->_formValues;
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
public function fixFormValues() {
|
||||
// if this search has been forced
|
||||
// then see if there are any get values, and if so over-ride the post values
|
||||
// note that this means that GET over-rides POST :)
|
||||
$event = CRM_Utils_Request::retrieve('event', 'Positive');
|
||||
if ($event) {
|
||||
$this->_formValues['event_id'] = $event;
|
||||
$this->_formValues['event_name'] = CRM_Event_PseudoConstant::event($event, TRUE);
|
||||
}
|
||||
|
||||
$status = CRM_Utils_Request::retrieve('status', 'String');
|
||||
|
||||
if (isset($status)) {
|
||||
if ($status === 'true') {
|
||||
$statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, "is_counted = 1");
|
||||
}
|
||||
elseif ($status === 'false') {
|
||||
$statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, "is_counted = 0");
|
||||
}
|
||||
elseif (is_numeric($status)) {
|
||||
$statusTypes = (int) $status;
|
||||
}
|
||||
elseif (is_array($status) && !array_key_exists('IN', $status)) {
|
||||
$statusTypes = array_keys($status);
|
||||
}
|
||||
$this->_formValues['participant_status_id'] = is_array($statusTypes) ? array('IN' => array_keys($statusTypes)) : $statusTypes;
|
||||
}
|
||||
|
||||
$role = CRM_Utils_Request::retrieve('role', 'String');
|
||||
|
||||
if (isset($role)) {
|
||||
if ($role === 'true') {
|
||||
$roleTypes = CRM_Event_PseudoConstant::participantRole(NULL, "filter = 1");
|
||||
}
|
||||
elseif ($role === 'false') {
|
||||
$roleTypes = CRM_Event_PseudoConstant::participantRole(NULL, "filter = 0");
|
||||
}
|
||||
elseif (is_numeric($role)) {
|
||||
$roleTypes = (int) $role;
|
||||
}
|
||||
$this->_formValues['participant_role_id'] = is_array($roleTypes) ? array_keys($roleTypes) : $roleTypes;
|
||||
}
|
||||
|
||||
$type = CRM_Utils_Request::retrieve('type', 'Positive');
|
||||
if ($type) {
|
||||
$this->_formValues['event_type'] = $type;
|
||||
}
|
||||
|
||||
$cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
|
||||
|
||||
if ($cid) {
|
||||
$cid = CRM_Utils_Type::escape($cid, 'Integer');
|
||||
if ($cid > 0) {
|
||||
$this->_formValues['contact_id'] = $cid;
|
||||
|
||||
// also assign individual mode to the template
|
||||
$this->_single = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getFormValues() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Find Participants');
|
||||
}
|
||||
|
||||
}
|
116
sites/all/modules/civicrm/CRM/Event/Form/SearchEvent.php
Normal file
116
sites/all/modules/civicrm/CRM/Event/Form/SearchEvent.php
Normal file
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
class CRM_Event_Form_SearchEvent extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* Explicitly declare the entity api name.
|
||||
*/
|
||||
public function getDefaultEntity() {
|
||||
return 'Event';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
$defaults['eventsByDates'] = 0;
|
||||
|
||||
$this->_showHide = new CRM_Core_ShowHideBlocks();
|
||||
if (empty($defaults['eventsByDates'])) {
|
||||
$this->_showHide->addHide('id_fromToDates');
|
||||
}
|
||||
|
||||
$this->_showHide->addToTemplate();
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->add('text', 'title', ts('Find'),
|
||||
array(CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'title'))
|
||||
);
|
||||
|
||||
$this->addSelect('event_type_id', array('multiple' => TRUE, 'context' => 'search'));
|
||||
|
||||
$eventsByDates = array();
|
||||
$searchOption = array(ts('Show Current and Upcoming Events'), ts('Search All or by Date Range'));
|
||||
$this->addRadio('eventsByDates', ts('Events by Dates'), $searchOption, array('onclick' => "return showHideByValue('eventsByDates','1','id_fromToDates','block','radio',true);"), "<br />");
|
||||
|
||||
$this->addDate('start_date', ts('From'), FALSE, array('formatType' => 'searchDate'));
|
||||
$this->addDate('end_date', ts('To'), FALSE, array('formatType' => 'searchDate'));
|
||||
|
||||
CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($this);
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'refresh',
|
||||
'name' => ts('Search'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
public function postProcess() {
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
$parent = $this->controller->getParent();
|
||||
$parent->set('searchResult', 1);
|
||||
if (!empty($params)) {
|
||||
$fields = array('title', 'event_type_id', 'start_date', 'end_date', 'eventsByDates', 'campaign_id');
|
||||
foreach ($fields as $field) {
|
||||
if (isset($params[$field]) &&
|
||||
!CRM_Utils_System::isNull($params[$field])
|
||||
) {
|
||||
if (substr($field, -4) == 'date') {
|
||||
$time = ($field == 'end_date') ? '235959' : NULL;
|
||||
$parent->set($field, CRM_Utils_Date::processDate($params[$field], $time));
|
||||
}
|
||||
else {
|
||||
$parent->set($field, $params[$field]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$parent->set($field, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
529
sites/all/modules/civicrm/CRM/Event/Form/SelfSvcTransfer.php
Normal file
529
sites/all/modules/civicrm/CRM/Event/Form/SelfSvcTransfer.php
Normal file
|
@ -0,0 +1,529 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components to transfer an Event to another participant
|
||||
*
|
||||
*/
|
||||
class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form {
|
||||
/**
|
||||
* from particpant id
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
protected $_from_participant_id;
|
||||
/**
|
||||
* from contact id
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
protected $_from_contact_id;
|
||||
/**
|
||||
* last name of the particpant to transfer to
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
protected $_to_contact_last_name;
|
||||
/**
|
||||
* first name of the particpant to transfer to
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
protected $_to_contact_first_name;
|
||||
/**
|
||||
* email of participant
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_to_contact_email;
|
||||
/**
|
||||
* _to_contact_id
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_to_contact_id;
|
||||
/**
|
||||
* event to be cancelled/transferred
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_event_id;
|
||||
/**
|
||||
* event title
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_event_title;
|
||||
/**
|
||||
* event title
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_event_start_date;
|
||||
/**
|
||||
* action
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $_action;
|
||||
/**
|
||||
* participant object
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_participant = array();
|
||||
/**
|
||||
* particpant values
|
||||
*
|
||||
* @array string
|
||||
*/
|
||||
protected $_part_values;
|
||||
/**
|
||||
* details
|
||||
*
|
||||
* @array string
|
||||
*/
|
||||
protected $_details = array();
|
||||
/**
|
||||
* line items
|
||||
*
|
||||
* @array string
|
||||
*/
|
||||
protected $_line_items = array();
|
||||
/**
|
||||
* contact_id
|
||||
*
|
||||
* @array string
|
||||
*/
|
||||
protected $contact_id;
|
||||
|
||||
/**
|
||||
* Get source values for transfer based on participant id in URL. Line items will
|
||||
* be transferred to this participant - at this point no transaction changes processed
|
||||
*
|
||||
* return @void
|
||||
*/
|
||||
public function preProcess() {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$this->_userContext = $session->readUserContext();
|
||||
$this->_from_participant_id = CRM_Utils_Request::retrieve('pid', 'Positive', $this, FALSE, NULL, 'REQUEST');
|
||||
$this->_userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this, FALSE, NULL, 'REQUEST');
|
||||
$params = array('id' => $this->_from_participant_id);
|
||||
$participant = $values = array();
|
||||
$this->_participant = CRM_Event_BAO_Participant::getValues($params, $values, $participant);
|
||||
$this->_part_values = $values[$this->_from_participant_id];
|
||||
$this->set('values', $this->_part_values);
|
||||
$this->_event_id = $this->_part_values['event_id'];
|
||||
$url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}");
|
||||
$this->_from_contact_id = $this->_part_values['participant_contact_id'];
|
||||
$validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($this->_from_contact_id, $this->_userChecksum);
|
||||
if (!$validUser && !CRM_Core_Permission::check('edit all events')) {
|
||||
CRM_Core_Error::statusBounce(ts('You do not have sufficient permission to transfer/cancel this participant.'), $url);
|
||||
}
|
||||
$this->assign('action', $this->_action);
|
||||
if ($this->_from_participant_id) {
|
||||
$this->assign('participantId', $this->_from_participant_id);
|
||||
}
|
||||
$event = array();
|
||||
$daoName = 'title';
|
||||
$this->_event_title = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName);
|
||||
$daoName = 'start_date';
|
||||
$this->_event_start_date = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName);
|
||||
list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_from_contact_id);
|
||||
$this->_contact_name = $displayName;
|
||||
$this->_contact_email = $email;
|
||||
$details = array();
|
||||
$details = CRM_Event_BAO_Participant::participantDetails($this->_from_participant_id);
|
||||
$optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'participant_role', 'id', 'name');
|
||||
$query = "
|
||||
SELECT cpst.name as status, cov.name as role, cp.fee_level, cp.fee_amount, cp.register_date, civicrm_event.start_date
|
||||
FROM civicrm_participant cp
|
||||
LEFT JOIN civicrm_participant_status_type cpst ON cpst.id = cp.status_id
|
||||
LEFT JOIN civicrm_option_value cov ON cov.value = cp.role_id and cov.option_group_id = {$optionGroupId}
|
||||
LEFT JOIN civicrm_event ON civicrm_event.id = cp.event_id
|
||||
WHERE cp.id = {$this->_from_participant_id}";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$details['status'] = $dao->status;
|
||||
$details['role'] = $dao->role;
|
||||
$details['fee_level'] = $dao->fee_level;
|
||||
$details['fee_amount'] = $dao->fee_amount;
|
||||
$details['register_date'] = $dao->register_date;
|
||||
$details['event_start_date'] = $dao->start_date;
|
||||
}
|
||||
$this->assign('details', $details);
|
||||
//This participant row will be cancelled. Get line item(s) to cancel
|
||||
$this->selfsvctransferUrl = CRM_Utils_System::url('civicrm/event/selfsvcupdate',
|
||||
"reset=1&id={$this->_from_participant_id}&id=0");
|
||||
$this->selfsvctransferText = ts('Update');
|
||||
$this->selfsvctransferButtonText = ts('Update');
|
||||
}
|
||||
|
||||
/**
|
||||
* Build form for input of transferree email, name
|
||||
*
|
||||
* return @void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->add('text', 'email', ts('To Email'), ts($this->_contact_email), TRUE);
|
||||
$this->add('text', 'last_name', ts('To Last Name'), ts($this->_to_contact_last_name), TRUE);
|
||||
$this->add('text', 'first_name', ts('To First Name'), ts($this->_to_contact_first_name), TRUE);
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'submit',
|
||||
'name' => ts('Transfer Registration'),),
|
||||
)
|
||||
);
|
||||
$this->addFormRule(array('CRM_Event_Form_SelfSvcTransfer', 'formRule'), $this);
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set defaults
|
||||
*
|
||||
* return @array _defaults
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$this->_defaults = array();
|
||||
return $this->_defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate email and name input
|
||||
*
|
||||
* return array $errors
|
||||
*/
|
||||
public static function formRule($fields, $files, $self) {
|
||||
$errors = array();
|
||||
//check that either an email or firstname+lastname is included in the form(CRM-9587)
|
||||
$to_contact_id = self::checkProfileComplete($fields, $errors, $self);
|
||||
//To check if the user is already registered for the event(CRM-2426)
|
||||
if ($to_contact_id) {
|
||||
self::checkRegistration($fields, $self, $to_contact_id, $errors);
|
||||
}
|
||||
//return parent::formrule($fields, $files, $self);
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether profile (name, email) is complete
|
||||
*
|
||||
* return $contact_id
|
||||
*/
|
||||
public static function checkProfileComplete($fields, &$errors, $self) {
|
||||
$email = '';
|
||||
foreach ($fields as $fieldname => $fieldvalue) {
|
||||
if (substr($fieldname, 0, 5) == 'email' && $fieldvalue) {
|
||||
$email = $fieldvalue;
|
||||
}
|
||||
}
|
||||
if (!$email && !(CRM_Utils_Array::value('first_name', $fields) &&
|
||||
CRM_Utils_Array::value('last_name', $fields))) {
|
||||
$defaults = $params = array('id' => $eventId);
|
||||
CRM_Event_BAO_Event::retrieve($params, $defaults);
|
||||
$message = ts("Mandatory fields (first name and last name, OR email address) are missing from this form.");
|
||||
$errors['_qf_default'] = $message;
|
||||
}
|
||||
$contact = CRM_Contact_BAO_Contact::matchContactOnEmail($email, "");
|
||||
$contact_id = empty($contact->contact_id) ? NULL : $contact->contact_id;
|
||||
if (!CRM_Utils_Rule::email($fields['email'])) {
|
||||
$errors['email'] = ts('Enter valid email address.');
|
||||
}
|
||||
if (empty($errors) && empty($contact_id)) {
|
||||
$params = array(
|
||||
'email-Primary' => CRM_Utils_Array::value('email', $fields, NULL),
|
||||
'first_name' => CRM_Utils_Array::value('first_name', $fields, NULL),
|
||||
'last_name' => CRM_Utils_Array::value('last_name', $fields, NULL),
|
||||
'is_deleted' => CRM_Utils_Array::value('is_deleted', $fields, FALSE),);
|
||||
//create new contact for this name/email pair
|
||||
//if new contact, no need to check for contact already registered
|
||||
$contact_id = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contact_id);
|
||||
}
|
||||
return $contact_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check contact details
|
||||
*
|
||||
* return @void
|
||||
*/
|
||||
public static function checkRegistration($fields, $self, $contact_id, &$errors) {
|
||||
// verify whether this contact already registered for this event
|
||||
$contact_details = CRM_Contact_BAO_Contact::getContactDetails($contact_id);
|
||||
$display_name = $contact_details[0];
|
||||
$query = "select event_id from civicrm_participant where contact_id = " . $contact_id;
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$to_event_id[] = $dao->event_id;
|
||||
}
|
||||
if (!empty($to_event_id)) {
|
||||
foreach ($to_event_id as $id) {
|
||||
if ($id == $self->_event_id) {
|
||||
$errors['email'] = $display_name . ts(" is already registered for this event");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process transfer - first add the new participant to the event, then cancel
|
||||
* source participant - send confirmation email to transferee
|
||||
*/
|
||||
public function postProcess() {
|
||||
//For transfer, process form to allow selection of transferree
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
//cancel 'from' participant row
|
||||
$query = "select contact_id from civicrm_email where email = '" . $params['email'] . "'";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$contact_id = $dao->contact_id;
|
||||
}
|
||||
$from_participant = $params = array();
|
||||
$query = "select role_id, source, fee_level, is_test, is_pay_later, fee_amount, discount_id, fee_currency,campaign_id, discount_amount from civicrm_participant where id = " . $this->_from_participant_id;
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
$value_to = array();
|
||||
while ($dao->fetch()) {
|
||||
$value_to['role_id'] = $dao->role_id;
|
||||
$value_to['source'] = $dao->source;
|
||||
$value_to['fee_level'] = $dao->fee_level;
|
||||
$value_to['is_test'] = $dao->is_test;
|
||||
$value_to['is_pay_later'] = $dao->is_pay_later;
|
||||
$value_to['fee_amount'] = $dao->fee_amount;
|
||||
}
|
||||
$value_to['contact_id'] = $contact_id;
|
||||
$value_to['event_id'] = $this->_event_id;
|
||||
$value_to['status_id'] = 1;
|
||||
$value_to['register_date'] = date("Y-m-d");
|
||||
//first create the new participant row -don't set registered_by yet or email won't be sent
|
||||
$participant = CRM_Event_BAO_Participant::create($value_to);
|
||||
//send a confirmation email to the new participant
|
||||
$this->participantTransfer($participant);
|
||||
//now update registered_by_id
|
||||
$query = "UPDATE civicrm_participant cp SET cp.registered_by_id = %1 WHERE cp.id = ({$participant->id})";
|
||||
$params = array(1 => array($this->_from_participant_id, 'Integer'));
|
||||
$dao = CRM_Core_DAO::executeQuery($query, $params);
|
||||
//copy line items to new participant
|
||||
$line_items = CRM_Price_BAO_LineItem::getLineItems($this->_from_participant_id);
|
||||
foreach ($line_items as $item) {
|
||||
$item['entity_id'] = $participant->id;
|
||||
$item['id'] = NULL;
|
||||
$item['entity_table'] = "civicrm_participant";
|
||||
$new_item = CRM_Price_BAO_LineItem::create($item);
|
||||
}
|
||||
//now cancel the from participant record, leaving the original line-item(s)
|
||||
$value_from = array();
|
||||
$value_from['id'] = $this->_from_participant_id;
|
||||
$tansferId = array_search('Transferred', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"));
|
||||
$value_from['status_id'] = $tansferId;
|
||||
$value_from['transferred_to_contact_id'] = $contact_id;
|
||||
$contact_details = CRM_Contact_BAO_Contact::getContactDetails($contact_id);
|
||||
$display_name = current($contact_details);
|
||||
$this->assign('to_participant', $display_name);
|
||||
CRM_Event_BAO_Participant::create($value_from);
|
||||
$this->sendCancellation();
|
||||
list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contact_id);
|
||||
$statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $displayName));
|
||||
$statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $email));
|
||||
CRM_Core_Session::setStatus($statusMsg, ts('Registration Transferred'), 'success');
|
||||
$url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}");
|
||||
CRM_Utils_System::redirect($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on input, create participant row for transferee and send email
|
||||
*
|
||||
* return @ void
|
||||
*/
|
||||
public function participantTransfer($participant) {
|
||||
$contactDetails = array();
|
||||
$contactIds[] = $participant->contact_id;
|
||||
list($currentContactDetails) = CRM_Utils_Token::getTokenDetails($contactIds, NULL,
|
||||
FALSE, FALSE, NULL, array(), 'CRM_Event_BAO_Participant');
|
||||
foreach ($currentContactDetails as $contactId => $contactValues) {
|
||||
$contactDetails[$contactId] = $contactValues;
|
||||
}
|
||||
$participantRoles = CRM_Event_PseudoConstant::participantRole();
|
||||
$participantDetails = array();
|
||||
$query = "SELECT * FROM civicrm_participant WHERE id = " . $participant->id;
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$participantDetails[$dao->id] = array(
|
||||
'id' => $dao->id,
|
||||
'role' => $participantRoles[$dao->role_id],
|
||||
'is_test' => $dao->is_test,
|
||||
'event_id' => $dao->event_id,
|
||||
'status_id' => $dao->status_id,
|
||||
'fee_amount' => $dao->fee_amount,
|
||||
'contact_id' => $dao->contact_id,
|
||||
'register_date' => $dao->register_date,
|
||||
'registered_by_id' => $dao->registered_by_id,
|
||||
);
|
||||
}
|
||||
$domainValues = array();
|
||||
if (empty($domainValues)) {
|
||||
$domain = CRM_Core_BAO_Domain::getDomain();
|
||||
$tokens = array(
|
||||
'domain' =>
|
||||
array(
|
||||
'name',
|
||||
'phone',
|
||||
'address',
|
||||
'email',
|
||||
),
|
||||
'contact' => CRM_Core_SelectValues::contactTokens(),
|
||||
);
|
||||
foreach ($tokens['domain'] as $token) {
|
||||
$domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain);
|
||||
}
|
||||
}
|
||||
$eventDetails = array();
|
||||
$eventParams = array('id' => $participant->event_id);
|
||||
CRM_Event_BAO_Event::retrieve($eventParams, $eventDetails);
|
||||
//get default participant role.
|
||||
$eventDetails['participant_role'] = CRM_Utils_Array::value($eventDetails['default_role_id'], $participantRoles);
|
||||
//get the location info
|
||||
$locParams = array(
|
||||
'entity_id' => $participant->event_id,
|
||||
'entity_table' => 'civicrm_event',
|
||||
);
|
||||
$eventDetails['location'] = CRM_Core_BAO_Location::getValues($locParams, TRUE);
|
||||
$toEmail = CRM_Utils_Array::value('email', $contactDetails[$participant->contact_id]);
|
||||
if ($toEmail) {
|
||||
//take a receipt from as event else domain.
|
||||
$receiptFrom = $domainValues['name'] . ' <' . $domainValues['email'] . '>';
|
||||
if (!empty($eventDetails['confirm_from_name']) && !empty($eventDetails['confirm_from_email'])) {
|
||||
$receiptFrom = $eventDetails['confirm_from_name'] . ' <' . $eventDetails['confirm_from_email'] . '>';
|
||||
}
|
||||
$participantName = $contactDetails[$participant->contact_id]['display_name'];
|
||||
$tplParams = array(
|
||||
'event' => $eventDetails,
|
||||
'participant' => $participantDetails[$participant->id],
|
||||
'participantID' => $participant->id,
|
||||
'participant_status' => 'Registered',
|
||||
);
|
||||
|
||||
$sendTemplateParams = array(
|
||||
'groupName' => 'msg_tpl_workflow_event',
|
||||
'valueName' => 'event_online_receipt',
|
||||
'contactId' => $participantDetails[$participant->id]['contact_id'],
|
||||
'tplParams' => $tplParams,
|
||||
'from' => $receiptFrom,
|
||||
'toName' => $participantName,
|
||||
'toEmail' => $toEmail,
|
||||
'cc' => CRM_Utils_Array::value('cc_confirm', $eventDetails),
|
||||
'bcc' => CRM_Utils_Array::value('bcc_confirm', $eventDetails),
|
||||
);
|
||||
CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send confirmation of cancellation to source participant
|
||||
*
|
||||
* return @ void
|
||||
*/
|
||||
public function sendCancellation() {
|
||||
$domainValues = array();
|
||||
$domain = CRM_Core_BAO_Domain::getDomain();
|
||||
$tokens = array(
|
||||
'domain' =>
|
||||
array(
|
||||
'name',
|
||||
'phone',
|
||||
'address',
|
||||
'email',
|
||||
),
|
||||
'contact' => CRM_Core_SelectValues::contactTokens(),
|
||||
);
|
||||
foreach ($tokens['domain'] as $token) {
|
||||
$domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain);
|
||||
}
|
||||
$participantRoles = array();
|
||||
$participantRoles = CRM_Event_PseudoConstant::participantRole();
|
||||
$participantDetails = array();
|
||||
$query = "SELECT * FROM civicrm_participant WHERE id = {$this->_from_participant_id}";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$participantDetails[$dao->id] = array(
|
||||
'id' => $dao->id,
|
||||
'role' => $participantRoles[$dao->role_id],
|
||||
'is_test' => $dao->is_test,
|
||||
'event_id' => $dao->event_id,
|
||||
'status_id' => $dao->status_id,
|
||||
'fee_amount' => $dao->fee_amount,
|
||||
'contact_id' => $dao->contact_id,
|
||||
'register_date' => $dao->register_date,
|
||||
'registered_by_id' => $dao->registered_by_id,
|
||||
);
|
||||
}
|
||||
$eventDetails = array();
|
||||
$eventParams = array('id' => $this->_event_id);
|
||||
CRM_Event_BAO_Event::retrieve($eventParams, $eventDetails[$this->_event_id]);
|
||||
//get default participant role.
|
||||
$eventDetails[$this->_event_id]['participant_role'] = CRM_Utils_Array::value($eventDetails[$this->_event_id]['default_role_id'], $participantRoles);
|
||||
//get the location info
|
||||
$locParams = array('entity_id' => $this->_event_id, 'entity_table' => 'civicrm_event');
|
||||
$eventDetails[$this->_event_id]['location'] = CRM_Core_BAO_Location::getValues($locParams, TRUE);
|
||||
//get contact details
|
||||
$contactIds[$this->_from_contact_id] = $this->_from_contact_id;
|
||||
list($currentContactDetails) = CRM_Utils_Token::getTokenDetails($contactIds, NULL,
|
||||
FALSE, FALSE, NULL, array(),
|
||||
'CRM_Event_BAO_Participant'
|
||||
);
|
||||
foreach ($currentContactDetails as $contactId => $contactValues) {
|
||||
$contactDetails[$this->_from_contact_id] = $contactValues;
|
||||
}
|
||||
//send a 'cancelled' email to user, and cc the event's cc_confirm email
|
||||
$mail = CRM_Event_BAO_Participant::sendTransitionParticipantMail($this->_from_participant_id,
|
||||
$participantDetails[$this->_from_participant_id],
|
||||
$eventDetails[$this->_event_id],
|
||||
$contactDetails[$this->_from_contact_id],
|
||||
$domainValues,
|
||||
"Transferred",
|
||||
""
|
||||
);
|
||||
$statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contact_name));
|
||||
$statusMsg .= ' ' . ts('A cancellation email has been sent to %1.', array(1 => $this->_contact_email));
|
||||
CRM_Core_Session::setStatus($statusMsg, ts('Thanks'), 'success');
|
||||
}
|
||||
|
||||
}
|
365
sites/all/modules/civicrm/CRM/Event/Form/SelfSvcUpdate.php
Normal file
365
sites/all/modules/civicrm/CRM/Event/Form/SelfSvcUpdate.php
Normal file
|
@ -0,0 +1,365 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components to allow an Event to be cancelled or transferred from an email link
|
||||
*
|
||||
*/
|
||||
class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form {
|
||||
/**
|
||||
* particpant id
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
protected $_participant_id;
|
||||
/**
|
||||
* contact id
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
protected $_contact_id;
|
||||
/**
|
||||
* name of the particpant
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
protected $_contact_name;
|
||||
/**
|
||||
* email of participant
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_contact_email;
|
||||
/**
|
||||
* event to be cancelled/transferred
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_event_id;
|
||||
/**
|
||||
* event title
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_event_title;
|
||||
/**
|
||||
* event title
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_event_start_date;
|
||||
/**
|
||||
* action
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $_action;
|
||||
/**
|
||||
* participant object
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_participant = array();
|
||||
/**
|
||||
* particpant values
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_part_values;
|
||||
/**
|
||||
* details of event registration values
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_details = array();
|
||||
/**
|
||||
* Set variables up before form is built based on participant ID from URL
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$this->_userContext = $session->readUserContext();
|
||||
$participant = $values = array();
|
||||
$this->_participant_id = CRM_Utils_Request::retrieve('pid', 'Positive', $this, FALSE, NULL, 'REQUEST');
|
||||
$this->_userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this, FALSE, NULL, 'REQUEST');
|
||||
$params = array('id' => $this->_participant_id);
|
||||
$this->_participant = CRM_Event_BAO_Participant::getValues($params, $values, $participant);
|
||||
$this->_part_values = $values[$this->_participant_id];
|
||||
$this->set('values', $this->_part_values);
|
||||
//fetch Event by event_id, verify that this event can still be xferred/cancelled
|
||||
$this->_event_id = $this->_part_values['event_id'];
|
||||
$url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}");
|
||||
$this->_contact_id = $this->_part_values['participant_contact_id'];
|
||||
$validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($this->_contact_id, $this->_userChecksum);
|
||||
if (!$validUser && !CRM_Core_Permission::check('edit all events')) {
|
||||
CRM_Core_Error::statusBounce(ts('You do not have sufficient permission to transfer/cancel this participant.'), $url);
|
||||
}
|
||||
$this->assign('action', $this->_action);
|
||||
if ($this->_participant_id) {
|
||||
$this->assign('participantId', $this->_participant_id);
|
||||
}
|
||||
$event = array();
|
||||
$daoName = 'title';
|
||||
$this->_event_title = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName);
|
||||
$daoName = 'start_date';
|
||||
$this->_event_start_date = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName);
|
||||
list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contact_id);
|
||||
$this->_contact_name = $displayName;
|
||||
$this->_contact_email = $email;
|
||||
$details = array();
|
||||
$details = CRM_Event_BAO_Participant::participantDetails($this->_participant_id);
|
||||
$optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'participant_role', 'id', 'name');
|
||||
$contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participant_id, 'contribution_id', 'participant_id');
|
||||
$this->assign('contributionId', $contributionId);
|
||||
$query = "
|
||||
SELECT cpst.name as status, cov.name as role, cp.fee_level, cp.fee_amount, cp.register_date, cp.status_id, civicrm_event.start_date
|
||||
FROM civicrm_participant cp
|
||||
LEFT JOIN civicrm_participant_status_type cpst ON cpst.id = cp.status_id
|
||||
LEFT JOIN civicrm_option_value cov ON cov.value = cp.role_id and cov.option_group_id = {$optionGroupId}
|
||||
LEFT JOIN civicrm_event ON civicrm_event.id = cp.event_id
|
||||
WHERE cp.id = {$this->_participant_id}";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$details['status'] = $dao->status;
|
||||
$details['role'] = $dao->role;
|
||||
$details['fee_level'] = $dao->fee_level;
|
||||
$details['fee_amount'] = $dao->fee_amount;
|
||||
$details['register_date'] = $dao->register_date;
|
||||
$details['event_start_date'] = $dao->start_date;
|
||||
}
|
||||
//verify participant status is still Registered
|
||||
if ($details['status'] != "Registered") {
|
||||
$status = "You cannot transfer or cancel your registration for " . $this->_event_title . ' as you are not currently registered for this event.';
|
||||
CRM_Core_Session::setStatus($status, ts('Sorry'), 'alert');
|
||||
CRM_Utils_System::redirect($url);
|
||||
}
|
||||
$query = "select start_date as start, selfcancelxfer_time as time from civicrm_event where id = " . $this->_event_id;
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$time_limit = $dao->time;
|
||||
$start_date = $dao->start;
|
||||
}
|
||||
$start_time = new Datetime($start_date);
|
||||
$timenow = new Datetime();
|
||||
if (!empty($start_time) && $start_time < $timenow) {
|
||||
$status = ts("Registration for this event cannot be cancelled or transferred once the event has begun. Contact the event organizer if you have questions.");
|
||||
CRM_Core_Error::statusBounce($status, $url, ts('Sorry'));
|
||||
}
|
||||
if (!empty($time_limit) && $time_limit > 0) {
|
||||
$interval = $timenow->diff($start_time);
|
||||
$days = $interval->format('%d');
|
||||
$hours = $interval->format('%h');
|
||||
if ($hours <= $time_limit && $days < 1) {
|
||||
$status = ts("Registration for this event cannot be cancelled or transferred less than %1 hours prior to the event's start time. Contact the event organizer if you have questions.", array(1 => $time_limit));
|
||||
CRM_Core_Error::statusBounce($status, $url, ts('Sorry'));
|
||||
}
|
||||
}
|
||||
$this->assign('details', $details);
|
||||
$this->selfsvcupdateUrl = CRM_Utils_System::url('civicrm/event/selfsvcupdate', "reset=1&id={$this->_participant_id}&id=0");
|
||||
$this->selfsvcupdateText = ts('Update');
|
||||
$this->selfsvcupdateButtonText = ts('Update');
|
||||
// Based on those ids retrieve event and verify it is eligible
|
||||
// for self update (event.start_date > today, event can be 'self_updated'
|
||||
// retrieve contact name and email, and let user verify his/her identity
|
||||
}
|
||||
/**
|
||||
* buildQuickForm -populate input variables for source Event
|
||||
* to cancel or transfer to another person
|
||||
*
|
||||
* return @void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->add('select', 'action', ts('Transfer or Cancel Registration'), array(ts('-select-'), ts('Transfer'), ts('Cancel')), TRUE);
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'submit',
|
||||
'name' => ts('Submit'),
|
||||
),
|
||||
));
|
||||
$this->addFormRule(array('CRM_Event_Form_SelfSvcUpdate', 'formRule'), $this);
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for contact
|
||||
*
|
||||
* return @void
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$this->_defaults = array();
|
||||
$this->_defaults['details'] = $this->_details;
|
||||
return $this->_defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate action input
|
||||
* @param array $fields
|
||||
* Posted fields of the form.
|
||||
* @param $files
|
||||
* @param $self
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($fields, $files, $self) {
|
||||
$errors = array();
|
||||
if (empty($fields['action'])) {
|
||||
$errors['action'] = ts("Please select Transfer OR Cancel action.");
|
||||
}
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process submit form - based on user selection of action
|
||||
* transfer or cancel the event
|
||||
*
|
||||
* return @void
|
||||
*/
|
||||
public function postProcess() {
|
||||
//if selection is cancel, cancel this participant' registration, process refund
|
||||
//if transfer, process form to allow selection of transferree
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
$action = $params['action'];
|
||||
if ($action == "1") {
|
||||
$action = "Transfer Event";
|
||||
$this->transferParticipant($params);
|
||||
}
|
||||
elseif ($action == "2") {
|
||||
$action = "Cancel Event";
|
||||
$this->cancelParticipant($params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfer to a new form, allowing selection of a new contact
|
||||
* based on email and name. The Event will be transferred to this new participant
|
||||
*
|
||||
* return @void
|
||||
*/
|
||||
public function transferParticipant($params) {
|
||||
$transferUrl = 'civicrm/event/form/selfsvctransfer';
|
||||
$url = CRM_Utils_System::url('civicrm/event/selfsvctransfer', 'reset=1&action=add&pid=' . $this->_participant_id . '&cs=' . $this->_userChecksum);
|
||||
$this->controller->setDestination($url);
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->replaceUserContext($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel this participant and finish, send cancellation email. At this point no
|
||||
* auto-cancellation of payment is handled, so payment needs to be manually cancelled
|
||||
*
|
||||
* return @void
|
||||
*/
|
||||
public function cancelParticipant($params) {
|
||||
//set participant record status to Cancelled, refund payment if possible
|
||||
// send email to participant and admin, and log Activity
|
||||
$value = array();
|
||||
$value['id'] = $this->_participant_id;
|
||||
$cancelledId = array_search('Cancelled',
|
||||
CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"));
|
||||
$value['status_id'] = $cancelledId;
|
||||
CRM_Event_BAO_Participant::create($value);
|
||||
$domainValues = array();
|
||||
$domain = CRM_Core_BAO_Domain::getDomain();
|
||||
$tokens = array(
|
||||
'domain' =>
|
||||
array(
|
||||
'name',
|
||||
'phone',
|
||||
'address',
|
||||
'email',
|
||||
),
|
||||
'contact' => CRM_Core_SelectValues::contactTokens(),
|
||||
);
|
||||
foreach ($tokens['domain'] as $token) {
|
||||
$domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain);
|
||||
}
|
||||
$participantRoles = array();
|
||||
$participantRoles = CRM_Event_PseudoConstant::participantRole();
|
||||
$participantDetails = array();
|
||||
$query = "SELECT * FROM civicrm_participant WHERE id = {$this->_participant_id}";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$participantDetails[$dao->id] = array(
|
||||
'id' => $dao->id,
|
||||
'role' => $participantRoles[$dao->role_id],
|
||||
'is_test' => $dao->is_test,
|
||||
'event_id' => $dao->event_id,
|
||||
'status_id' => $dao->status_id,
|
||||
'fee_amount' => $dao->fee_amount,
|
||||
'contact_id' => $dao->contact_id,
|
||||
'register_date' => $dao->register_date,
|
||||
'registered_by_id' => $dao->registered_by_id,
|
||||
);
|
||||
}
|
||||
$eventDetails = array();
|
||||
$eventParams = array('id' => $this->_event_id);
|
||||
CRM_Event_BAO_Event::retrieve($eventParams, $eventDetails[$this->_event_id]);
|
||||
//get default participant role.
|
||||
$eventDetails[$this->_event_id]['participant_role'] = CRM_Utils_Array::value($eventDetails[$this->_event_id]['default_role_id'], $participantRoles);
|
||||
//get the location info
|
||||
$locParams = array('entity_id' => $this->_event_id, 'entity_table' => 'civicrm_event');
|
||||
$eventDetails[$this->_event_id]['location'] = CRM_Core_BAO_Location::getValues($locParams, TRUE);
|
||||
//get contact details
|
||||
$contactIds[$this->_contact_id] = $this->_contact_id;
|
||||
list($currentContactDetails) = CRM_Utils_Token::getTokenDetails($contactIds, NULL,
|
||||
FALSE, FALSE, NULL, array(),
|
||||
'CRM_Event_BAO_Participant'
|
||||
);
|
||||
foreach ($currentContactDetails as $contactId => $contactValues) {
|
||||
$contactDetails[$this->_contact_id] = $contactValues;
|
||||
}
|
||||
//send a 'cancelled' email to user, and cc the event's cc_confirm email
|
||||
$mail = CRM_Event_BAO_Participant::sendTransitionParticipantMail($this->_participant_id,
|
||||
$participantDetails[$this->_participant_id],
|
||||
$eventDetails[$this->_event_id],
|
||||
$contactDetails[$this->_contact_id],
|
||||
$domainValues,
|
||||
"Cancelled",
|
||||
""
|
||||
);
|
||||
$statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contact_name));
|
||||
$statusMsg .= ' ' . ts('A cancellation email has been sent to %1.', array(1 => $this->_contact_email));
|
||||
CRM_Core_Session::setStatus($statusMsg, ts('Thanks'), 'success');
|
||||
$url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}&noFullMsg=true");
|
||||
CRM_Utils_System::redirect($url);
|
||||
}
|
||||
|
||||
}
|
184
sites/all/modules/civicrm/CRM/Event/Form/Task.php
Normal file
184
sites/all/modules/civicrm/CRM/Event/Form/Task.php
Normal file
|
@ -0,0 +1,184 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates task actions for CiviEvent
|
||||
*
|
||||
*/
|
||||
class CRM_Event_Form_Task extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The task being performed.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_task;
|
||||
|
||||
/**
|
||||
* The additional clause that we restrict the search with.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_componentClause = NULL;
|
||||
|
||||
/**
|
||||
* The array that holds all the component ids.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_componentIds;
|
||||
|
||||
/**
|
||||
* The array that holds all the participant ids.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_participantIds;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @param
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
self::preProcessCommon($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
* @param bool $useTable
|
||||
*/
|
||||
public static function preProcessCommon(&$form, $useTable = FALSE) {
|
||||
$form->_participantIds = array();
|
||||
|
||||
$values = $form->controller->exportValues($form->get('searchFormName'));
|
||||
|
||||
$form->_task = $values['task'];
|
||||
$eventTasks = CRM_Event_Task::tasks();
|
||||
$form->assign('taskName', $eventTasks[$form->_task]);
|
||||
|
||||
$ids = array();
|
||||
if ($values['radio_ts'] == 'ts_sel') {
|
||||
foreach ($values as $name => $value) {
|
||||
if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) {
|
||||
$ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$queryParams = $form->get('queryParams');
|
||||
$sortOrder = NULL;
|
||||
if ($form->get(CRM_Utils_Sort::SORT_ORDER)) {
|
||||
$sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER);
|
||||
}
|
||||
|
||||
$query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE,
|
||||
CRM_Contact_BAO_Query::MODE_EVENT
|
||||
);
|
||||
$query->_distinctComponentClause = "civicrm_participant.id";
|
||||
$query->_groupByComponentClause = " GROUP BY civicrm_participant.id ";
|
||||
$result = $query->searchQuery(0, 0, $sortOrder);
|
||||
while ($result->fetch()) {
|
||||
$ids[] = $result->participant_id;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($ids)) {
|
||||
$form->_componentClause = ' civicrm_participant.id IN ( ' . implode(',', $ids) . ' ) ';
|
||||
$form->assign('totalSelectedParticipants', count($ids));
|
||||
}
|
||||
|
||||
$form->_participantIds = $form->_componentIds = $ids;
|
||||
|
||||
//set the context for redirection for any task actions
|
||||
$session = CRM_Core_Session::singleton();
|
||||
|
||||
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
|
||||
$urlParams = 'force=1';
|
||||
if (CRM_Utils_Rule::qfKey($qfKey)) {
|
||||
$urlParams .= "&qfKey=$qfKey";
|
||||
}
|
||||
|
||||
$searchFormName = strtolower($form->get('searchFormName'));
|
||||
if ($searchFormName == 'search') {
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/event/search', $urlParams));
|
||||
}
|
||||
else {
|
||||
$session->replaceUserContext(CRM_Utils_System::url("civicrm/contact/search/$searchFormName",
|
||||
$urlParams
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the participant id, compute the contact id
|
||||
* since its used for things like send email
|
||||
*/
|
||||
public function setContactIDs() {
|
||||
$this->_contactIds = &CRM_Core_DAO::getContactIDsFromComponent($this->_participantIds,
|
||||
'civicrm_participant'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple shell that derived classes can call to add buttons to.
|
||||
* the form with a customized title for the main Submit
|
||||
*
|
||||
* @param string $title
|
||||
* Title of the main button.
|
||||
* @param string $nextType
|
||||
* @param string $backType
|
||||
* @param bool $submitOnce
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => $nextType,
|
||||
'name' => $title,
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => $backType,
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
256
sites/all/modules/civicrm/CRM/Event/Form/Task/AddToGroup.php
Normal file
256
sites/all/modules/civicrm/CRM/Event/Form/Task/AddToGroup.php
Normal file
|
@ -0,0 +1,256 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to group
|
||||
* contacts. This class provides functionality for the actual
|
||||
* addition of contacts to groups.
|
||||
*/
|
||||
class CRM_Event_Form_Task_AddToGroup extends CRM_Event_Form_Task {
|
||||
|
||||
/**
|
||||
* The context that we are working on.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_context;
|
||||
|
||||
/**
|
||||
* The groupId retrieved from the GET vars.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* The title of the group.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_title;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
// initialize the task and row fields
|
||||
parent::preProcess();
|
||||
|
||||
parent::setContactIDs();
|
||||
$this->_context = $this->get('context');
|
||||
$this->_id = $this->get('amtgID');
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
|
||||
//create radio buttons to select existing group or add a new group
|
||||
$options = array(ts('Add Contact To Existing Group'), ts('Create New Group'));
|
||||
|
||||
if (!$this->_id) {
|
||||
$this->addRadio('group_option', ts('Group Options'), $options, array('onclick' => "return showElements();"));
|
||||
|
||||
$this->add('text', 'title', ts('Group Name:') . ' ',
|
||||
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title')
|
||||
);
|
||||
$this->addRule('title', ts('Name already exists in Database.'),
|
||||
'objectExists', array('CRM_Contact_DAO_Group', $this->_id, 'title')
|
||||
);
|
||||
|
||||
$this->add('textarea', 'description', ts('Description:') . ' ',
|
||||
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'description')
|
||||
);
|
||||
|
||||
$groupTypes = CRM_Core_OptionGroup::values('group_type', TRUE);
|
||||
if (!CRM_Core_Permission::access('CiviMail')) {
|
||||
$isWorkFlowEnabled = CRM_Mailing_Info::workflowEnabled();
|
||||
if ($isWorkFlowEnabled &&
|
||||
!CRM_Core_Permission::check('create mailings') &&
|
||||
!CRM_Core_Permission::check('schedule mailings') &&
|
||||
!CRM_Core_Permission::check('approve mailings')
|
||||
) {
|
||||
unset($groupTypes['Mailing List']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($groupTypes)) {
|
||||
$this->addCheckBox('group_type',
|
||||
ts('Group Type'),
|
||||
$groupTypes,
|
||||
NULL, NULL, NULL, NULL, ' '
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// add select for groups
|
||||
$group = array('' => ts('- select group -')) + CRM_Core_PseudoConstant::group();
|
||||
|
||||
$groupElement = $this->add('select', 'group_id', ts('Select Group'), $group);
|
||||
|
||||
$this->_title = $group[$this->_id];
|
||||
|
||||
if ($this->_context === 'amtg') {
|
||||
$groupElement->freeze();
|
||||
|
||||
// also set the group title
|
||||
$groupValues = array('id' => $this->_id, 'title' => $this->_title);
|
||||
$this->assign_by_ref('group', $groupValues);
|
||||
}
|
||||
|
||||
// Set dynamic page title for 'Add Members Group (confirm)'
|
||||
if ($this->_id) {
|
||||
CRM_Utils_System::setTitle(ts('Add Contacts: %1', array(1 => $this->_title)));
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setTitle(ts('Add Contacts to A Group'));
|
||||
}
|
||||
|
||||
$this->addDefaultButtons(ts('Add to Group'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default form values.
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* the default array reference
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
|
||||
if ($this->_context === 'amtg') {
|
||||
$defaults['group_id'] = $this->_id;
|
||||
}
|
||||
|
||||
$defaults['group_option'] = 0;
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add local and global form rules.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addRules() {
|
||||
$this->addFormRule(array('CRM_Event_Form_Task_AddToGroup', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $params
|
||||
* Posted values of the form.
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($params) {
|
||||
$errors = array();
|
||||
|
||||
if (!empty($params['group_option']) && empty($params['title'])) {
|
||||
$errors['title'] = "Group Name is a required field";
|
||||
}
|
||||
elseif (empty($params['group_option']) && empty($params['group_id'])) {
|
||||
$errors['group_id'] = "Select Group is a required field.";
|
||||
}
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->controller->exportValues();
|
||||
$groupOption = CRM_Utils_Array::value('group_option', $params, NULL);
|
||||
if ($groupOption) {
|
||||
$groupParams = array();
|
||||
$groupParams['title'] = $params['title'];
|
||||
$groupParams['description'] = $params['description'];
|
||||
$groupParams['visibility'] = "User and User Admin Only";
|
||||
if (array_key_exists('group_type', $params) && is_array($params['group_type'])) {
|
||||
$groupParams['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
|
||||
array_keys($params['group_type'])
|
||||
) . CRM_Core_DAO::VALUE_SEPARATOR;
|
||||
}
|
||||
else {
|
||||
$groupParams['group_type'] = '';
|
||||
}
|
||||
$groupParams['is_active'] = 1;
|
||||
|
||||
$createdGroup = CRM_Contact_BAO_Group::create($groupParams);
|
||||
$groupID = $createdGroup->id;
|
||||
$groupName = $groupParams['title'];
|
||||
}
|
||||
else {
|
||||
$groupID = $params['group_id'];
|
||||
$group = CRM_Core_PseudoConstant::group();
|
||||
$groupName = $group[$groupID];
|
||||
}
|
||||
|
||||
list($total, $added, $notAdded) = CRM_Contact_BAO_GroupContact::addContactsToGroup($this->_contactIds, $groupID);
|
||||
|
||||
$status = array(
|
||||
ts('%count contact added to group', array(
|
||||
'count' => $added,
|
||||
'plural' => '%count contacts added to group',
|
||||
)),
|
||||
);
|
||||
if ($notAdded) {
|
||||
$status[] = ts('%count contact was already in group', array(
|
||||
'count' => $notAdded,
|
||||
'plural' => '%count contacts were already in group',
|
||||
));
|
||||
}
|
||||
$status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
|
||||
CRM_Core_Session::setStatus($status, ts('Added Contact to %1', array(
|
||||
1 => $groupName,
|
||||
'count' => $added,
|
||||
'plural' => 'Added Contacts to %1',
|
||||
)), 'success', array('expires' => 0));
|
||||
}
|
||||
|
||||
}
|
114
sites/all/modules/civicrm/CRM/Event/Form/Task/Badge.php
Normal file
114
sites/all/modules/civicrm/CRM/Event/Form/Task/Badge.php
Normal file
|
@ -0,0 +1,114 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class helps to print the labels for contacts.
|
||||
*/
|
||||
class CRM_Event_Form_Task_Badge extends CRM_Event_Form_Task {
|
||||
|
||||
/**
|
||||
* Are we operating in "single mode", i.e. sending email to one
|
||||
* specific contact?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $_single = FALSE;
|
||||
|
||||
/**
|
||||
* Component clause.
|
||||
*/
|
||||
public $_componentClause;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @param
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
|
||||
if ($this->_context == 'view') {
|
||||
$this->_single = TRUE;
|
||||
|
||||
$participantID = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
|
||||
$contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
|
||||
$this->_participantIds = array($participantID);
|
||||
$this->_componentClause = " civicrm_participant.id = $participantID ";
|
||||
$this->assign('totalSelectedParticipants', 1);
|
||||
|
||||
// also set the user context to send back to view page
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view/participant',
|
||||
"reset=1&action=view&id={$participantID}&cid={$contactID}"
|
||||
));
|
||||
}
|
||||
else {
|
||||
parent::preProcess();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
CRM_Utils_System::setTitle(ts('Make Name Badges'));
|
||||
|
||||
// Ajax submit would interfere with file download
|
||||
$this->preventAjaxSubmit();
|
||||
|
||||
//add select for label
|
||||
$label = CRM_Badge_BAO_Layout::getList();
|
||||
|
||||
$this->add('select',
|
||||
'badge_id',
|
||||
ts('Name Badge Format'),
|
||||
array(
|
||||
'' => ts('- select -'),
|
||||
) + $label, TRUE
|
||||
);
|
||||
|
||||
$next = 'next';
|
||||
$back = $this->_single ? 'cancel' : 'back';
|
||||
$this->addDefaultButtons(ts('Make Name Badges'), $next, $back);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
CRM_Badge_BAO_Badge::buildBadges($params, $this);
|
||||
}
|
||||
|
||||
}
|
522
sites/all/modules/civicrm/CRM/Event/Form/Task/Batch.php
Normal file
522
sites/all/modules/civicrm/CRM/Event/Form/Task/Batch.php
Normal file
|
@ -0,0 +1,522 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality for batch profile update for events
|
||||
*/
|
||||
class CRM_Event_Form_Task_Batch extends CRM_Event_Form_Task {
|
||||
|
||||
/**
|
||||
* The title of the group.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_title;
|
||||
|
||||
/**
|
||||
* Maximum profile fields that will be displayed.
|
||||
*/
|
||||
protected $_maxFields = 9;
|
||||
|
||||
/**
|
||||
* Variable to store redirect path.
|
||||
*/
|
||||
protected $_userContext;
|
||||
|
||||
/**
|
||||
* Variable to store previous status id.
|
||||
*/
|
||||
protected $_fromStatusIds;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
/*
|
||||
* initialize the task and row fields
|
||||
*/
|
||||
parent::preProcess();
|
||||
|
||||
//get the contact read only fields to display.
|
||||
$readOnlyFields = array_merge(array('sort_name' => ts('Name')),
|
||||
CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
|
||||
'contact_autocomplete_options',
|
||||
TRUE, NULL, FALSE, 'name', TRUE
|
||||
)
|
||||
);
|
||||
//get the read only field data.
|
||||
$returnProperties = array_fill_keys(array_keys($readOnlyFields), 1);
|
||||
$contactDetails = CRM_Contact_BAO_Contact_Utils::contactDetails($this->_participantIds,
|
||||
'CiviEvent', $returnProperties
|
||||
);
|
||||
$this->assign('contactDetails', $contactDetails);
|
||||
$this->assign('readOnlyFields', $readOnlyFields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$ufGroupId = $this->get('ufGroupId');
|
||||
if (!$ufGroupId) {
|
||||
CRM_Core_Error::fatal('ufGroupId is missing');
|
||||
}
|
||||
|
||||
$this->_title = ts('Update multiple participants') . ' - ' . CRM_Core_BAO_UFGroup::getTitle($ufGroupId);
|
||||
CRM_Utils_System::setTitle($this->_title);
|
||||
$this->addDefaultButtons(ts('Save'));
|
||||
$this->_fields = array();
|
||||
$this->_fields = CRM_Core_BAO_UFGroup::getFields($ufGroupId, FALSE, CRM_Core_Action::VIEW);
|
||||
if (array_key_exists('participant_status', $this->_fields)) {
|
||||
$this->assign('statusProfile', 1);
|
||||
$this->assignToTemplate();
|
||||
}
|
||||
|
||||
// remove file type field and then limit fields
|
||||
$suppressFields = FALSE;
|
||||
$removehtmlTypes = array('File', 'Autocomplete-Select');
|
||||
foreach ($this->_fields as $name => $field) {
|
||||
if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name) &&
|
||||
in_array($this->_fields[$name]['html_type'], $removehtmlTypes)
|
||||
) {
|
||||
$suppressFields = TRUE;
|
||||
unset($this->_fields[$name]);
|
||||
}
|
||||
|
||||
//fix to reduce size as we are using this field in grid
|
||||
if (is_array($field['attributes']) && $this->_fields[$name]['attributes']['size'] > 19) {
|
||||
//shrink class to "form-text-medium"
|
||||
$this->_fields[$name]['attributes']['size'] = 19;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_fields = array_slice($this->_fields, 0, $this->_maxFields);
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'submit',
|
||||
'name' => ts('Update Participant(s)'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$this->assign('profileTitle', $this->_title);
|
||||
$this->assign('componentIds', $this->_participantIds);
|
||||
$fileFieldExists = FALSE;
|
||||
|
||||
//load all campaigns.
|
||||
if (array_key_exists('participant_campaign_id', $this->_fields)) {
|
||||
$this->_componentCampaigns = array();
|
||||
CRM_Core_PseudoConstant::populate($this->_componentCampaigns,
|
||||
'CRM_Event_DAO_Participant',
|
||||
TRUE, 'campaign_id', 'id',
|
||||
' id IN (' . implode(' , ', array_values($this->_participantIds)) . ' ) '
|
||||
);
|
||||
}
|
||||
|
||||
//fix for CRM-2752
|
||||
// get the option value for custom data type
|
||||
$customDataType = CRM_Core_OptionGroup::values('custom_data_type', FALSE, FALSE, FALSE, NULL, 'name');
|
||||
$this->_roleCustomDataTypeID = array_search('ParticipantRole', $customDataType);
|
||||
$this->_eventNameCustomDataTypeID = array_search('ParticipantEventName', $customDataType);
|
||||
$this->_eventTypeCustomDataTypeID = array_search('ParticipantEventType', $customDataType);
|
||||
|
||||
// build custom data getFields array
|
||||
$customFieldsRole = CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, $this->_roleCustomDataTypeID);
|
||||
|
||||
$customFieldsEvent = CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, $this->_eventNameCustomDataTypeID);
|
||||
$customFieldsEventType = CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, $this->_eventTypeCustomDataTypeID);
|
||||
|
||||
$customFields = CRM_Utils_Array::crmArrayMerge($customFieldsRole,
|
||||
CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE)
|
||||
);
|
||||
$customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEventType, $customFields);
|
||||
$this->_customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEvent, $customFields);
|
||||
|
||||
foreach ($this->_participantIds as $participantId) {
|
||||
$roleId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $participantId, 'role_id');
|
||||
$eventId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $participantId, 'event_id');
|
||||
$eventTypeId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $eventId, 'event_type_id');
|
||||
foreach ($this->_fields as $name => $field) {
|
||||
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
|
||||
$customValue = CRM_Utils_Array::value($customFieldID, $this->_customFields);
|
||||
$entityColumnValue = array();
|
||||
if (!empty($customValue['extends_entity_column_value'])) {
|
||||
$entityColumnValue = explode(CRM_Core_DAO::VALUE_SEPARATOR,
|
||||
$customValue['extends_entity_column_value']
|
||||
);
|
||||
}
|
||||
$entityColumnValueRole = CRM_Utils_Array::value($roleId, $entityColumnValue);
|
||||
$entityColumnValueEventType = in_array($eventTypeId, $entityColumnValue) ? $eventTypeId : NULL;
|
||||
if (($this->_roleCustomDataTypeID == $customValue['extends_entity_column_id']) &&
|
||||
($entityColumnValueRole)
|
||||
) {
|
||||
CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $participantId);
|
||||
}
|
||||
elseif (($this->_eventNameCustomDataTypeID == $customValue['extends_entity_column_id']) &&
|
||||
($eventId == $entityColumnValueRole)
|
||||
) {
|
||||
CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $participantId);
|
||||
}
|
||||
elseif ($this->_eventTypeCustomDataTypeID == $customValue['extends_entity_column_id'] &&
|
||||
($entityColumnValueEventType == $eventTypeId)
|
||||
) {
|
||||
CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $participantId);
|
||||
}
|
||||
elseif (CRM_Utils_System::isNull($entityColumnValueRole)) {
|
||||
CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $participantId);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($field['name'] == 'participant_role') {
|
||||
$field['is_multiple'] = TRUE;
|
||||
}
|
||||
// handle non custom fields
|
||||
CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $participantId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('fields', $this->_fields);
|
||||
|
||||
// don't set the status message when form is submitted.
|
||||
$buttonName = $this->controller->getButtonName('submit');
|
||||
|
||||
if ($suppressFields && $buttonName != '_qf_Batch_next') {
|
||||
CRM_Core_Session::setStatus(ts("File or Autocomplete-Select type field(s) in the selected profile are not supported for Update multiple participants."), ts('Unsupported Field Type'), 'info');
|
||||
}
|
||||
|
||||
$this->addDefaultButtons(ts('Update Participant(s)'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
if (empty($this->_fields)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$defaults = array();
|
||||
foreach ($this->_participantIds as $participantId) {
|
||||
$details[$participantId] = array();
|
||||
|
||||
$details[$participantId] = CRM_Event_BAO_Participant::participantDetails($participantId);
|
||||
CRM_Core_BAO_UFGroup::setProfileDefaults(NULL, $this->_fields, $defaults, FALSE, $participantId, 'Event');
|
||||
|
||||
//get the from status ids, CRM-4323
|
||||
if (array_key_exists('participant_status', $this->_fields)) {
|
||||
$this->_fromStatusIds[$participantId] = CRM_Utils_Array::value("field[$participantId][participant_status]", $defaults);
|
||||
}
|
||||
if (array_key_exists('participant_role', $this->_fields)) {
|
||||
if ($defaults["field[{$participantId}][participant_role]"]) {
|
||||
$roles = $defaults["field[{$participantId}][participant_role]"];
|
||||
foreach (explode(CRM_Core_DAO::VALUE_SEPARATOR, $roles) as $k => $v) {
|
||||
$defaults["field[$participantId][participant_role][{$v}]"] = 1;
|
||||
}
|
||||
unset($defaults["field[{$participantId}][participant_role]"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('details', $details);
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
$statusClasses = CRM_Event_PseudoConstant::participantStatusClass();
|
||||
if (isset($params['field'])) {
|
||||
foreach ($params['field'] as $key => $value) {
|
||||
|
||||
//check for custom data
|
||||
$value['custom'] = CRM_Core_BAO_CustomField::postProcess($value,
|
||||
$key,
|
||||
'Participant'
|
||||
);
|
||||
|
||||
$value['id'] = $key;
|
||||
|
||||
if (!empty($value['participant_role'])) {
|
||||
if (is_array($value['participant_role'])) {
|
||||
$value['role_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($value['participant_role']));
|
||||
}
|
||||
else {
|
||||
$value['role_id'] = $value['participant_role'];
|
||||
}
|
||||
}
|
||||
|
||||
//need to send mail when status change
|
||||
$statusChange = FALSE;
|
||||
$relatedStatusChange = FALSE;
|
||||
if (!empty($value['participant_status'])) {
|
||||
$value['status_id'] = $value['participant_status'];
|
||||
$fromStatusId = CRM_Utils_Array::value($key, $this->_fromStatusIds);
|
||||
if (!$fromStatusId) {
|
||||
$fromStatusId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $key, 'status_id');
|
||||
}
|
||||
|
||||
if ($fromStatusId != $value['status_id']) {
|
||||
$relatedStatusChange = TRUE;
|
||||
}
|
||||
if ($statusClasses[$fromStatusId] != $statusClasses[$value['status_id']]) {
|
||||
$statusChange = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
unset($value['participant_status']);
|
||||
|
||||
civicrm_api3('Participant', 'create', $value);
|
||||
|
||||
//need to trigger mails when we change status
|
||||
if ($statusChange) {
|
||||
CRM_Event_BAO_Participant::transitionParticipants(array($key), $value['status_id'], $fromStatusId);
|
||||
}
|
||||
if ($relatedStatusChange) {
|
||||
//update related contribution status, CRM-4395
|
||||
self::updatePendingOnlineContribution($key, $value['status_id']);
|
||||
}
|
||||
}
|
||||
CRM_Core_Session::setStatus(ts('The updates have been saved.'), ts('Saved'), 'success');
|
||||
}
|
||||
else {
|
||||
CRM_Core_Session::setStatus(ts('No updates have been saved.'), ts('Not Saved'), 'alert');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $participantId
|
||||
* @param int $statusId
|
||||
*
|
||||
* @return Ambigous|void
|
||||
*/
|
||||
public static function updatePendingOnlineContribution($participantId, $statusId) {
|
||||
if (!$participantId || !$statusId) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$contributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($participantId,
|
||||
'Event'
|
||||
);
|
||||
if (!$contributionId) {
|
||||
return;
|
||||
}
|
||||
|
||||
//status rules.
|
||||
//1. participant - positive => contribution - completed.
|
||||
//2. participant - negative => contribution - cancelled.
|
||||
|
||||
$positiveStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Positive'");
|
||||
$negativeStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'");
|
||||
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
|
||||
|
||||
$contributionStatusId = NULL;
|
||||
if (array_key_exists($statusId, $positiveStatuses)) {
|
||||
$contributionStatusId = array_search('Completed', $contributionStatuses);
|
||||
}
|
||||
if (array_key_exists($statusId, $negativeStatuses)) {
|
||||
$contributionStatusId = array_search('Cancelled', $contributionStatuses);
|
||||
}
|
||||
|
||||
if (!$contributionStatusId) {
|
||||
return;
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'component_id' => $participantId,
|
||||
'componentName' => 'Event',
|
||||
'contribution_id' => $contributionId,
|
||||
'contribution_status_id' => $contributionStatusId,
|
||||
'IAmAHorribleNastyBeyondExcusableHackInTheCRMEventFORMTaskClassThatNeedsToBERemoved' => 1,
|
||||
);
|
||||
|
||||
//change related contribution status.
|
||||
$updatedStatusId = self::updateContributionStatus($params);
|
||||
|
||||
return $updatedStatusId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update contribution status.
|
||||
*
|
||||
* @deprecated
|
||||
* This is only called from one place in the code &
|
||||
* it is unclear whether it is a function on the way in or on the way out
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return NULL|int
|
||||
*/
|
||||
public static function updateContributionStatus($params) {
|
||||
// get minimum required values.
|
||||
$statusId = CRM_Utils_Array::value('contribution_status_id', $params);
|
||||
$componentId = CRM_Utils_Array::value('component_id', $params);
|
||||
$componentName = CRM_Utils_Array::value('componentName', $params);
|
||||
$contributionId = CRM_Utils_Array::value('contribution_id', $params);
|
||||
|
||||
if (!$contributionId || !$componentId || !$componentName || !$statusId) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$input = $ids = $objects = array();
|
||||
|
||||
//get the required ids.
|
||||
$ids['contribution'] = $contributionId;
|
||||
|
||||
if (!$ids['contact'] = CRM_Utils_Array::value('contact_id', $params)) {
|
||||
$ids['contact'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution',
|
||||
$contributionId,
|
||||
'contact_id'
|
||||
);
|
||||
}
|
||||
|
||||
if ($componentName == 'Event') {
|
||||
$name = 'event';
|
||||
$ids['participant'] = $componentId;
|
||||
|
||||
if (!$ids['event'] = CRM_Utils_Array::value('event_id', $params)) {
|
||||
$ids['event'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant',
|
||||
$componentId,
|
||||
'event_id'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($componentName == 'Membership') {
|
||||
$name = 'contribute';
|
||||
$ids['membership'] = $componentId;
|
||||
}
|
||||
$ids['contributionPage'] = NULL;
|
||||
$ids['contributionRecur'] = NULL;
|
||||
$input['component'] = $name;
|
||||
|
||||
$baseIPN = new CRM_Core_Payment_BaseIPN();
|
||||
$transaction = new CRM_Core_Transaction();
|
||||
|
||||
// reset template values.
|
||||
$template = CRM_Core_Smarty::singleton();
|
||||
$template->clearTemplateVars();
|
||||
|
||||
if (!$baseIPN->validateData($input, $ids, $objects, FALSE)) {
|
||||
CRM_Core_Error::fatal();
|
||||
}
|
||||
|
||||
$contribution = &$objects['contribution'];
|
||||
|
||||
$contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', array(
|
||||
'labelColumn' => 'name',
|
||||
'flip' => 1,
|
||||
));
|
||||
$input['IAmAHorribleNastyBeyondExcusableHackInTheCRMEventFORMTaskClassThatNeedsToBERemoved'] = CRM_Utils_Array::value('IAmAHorribleNastyBeyondExcusableHackInTheCRMEventFORMTaskClassThatNeedsToBERemoved', $params);
|
||||
if ($statusId == $contributionStatuses['Cancelled']) {
|
||||
$baseIPN->cancelled($objects, $transaction, $input);
|
||||
$transaction->commit();
|
||||
return $statusId;
|
||||
}
|
||||
elseif ($statusId == $contributionStatuses['Failed']) {
|
||||
$baseIPN->failed($objects, $transaction, $input);
|
||||
$transaction->commit();
|
||||
return $statusId;
|
||||
}
|
||||
|
||||
// status is not pending
|
||||
if ($contribution->contribution_status_id != $contributionStatuses['Pending']) {
|
||||
$transaction->commit();
|
||||
return;
|
||||
}
|
||||
|
||||
//set values for ipn code.
|
||||
foreach (array(
|
||||
'fee_amount',
|
||||
'check_number',
|
||||
'payment_instrument_id',
|
||||
) as $field) {
|
||||
if (!$input[$field] = CRM_Utils_Array::value($field, $params)) {
|
||||
$input[$field] = $contribution->$field;
|
||||
}
|
||||
}
|
||||
if (!$input['trxn_id'] = CRM_Utils_Array::value('trxn_id', $params)) {
|
||||
$input['trxn_id'] = $contribution->invoice_id;
|
||||
}
|
||||
if (!$input['amount'] = CRM_Utils_Array::value('total_amount', $params)) {
|
||||
$input['amount'] = $contribution->total_amount;
|
||||
}
|
||||
$input['is_test'] = $contribution->is_test;
|
||||
$input['net_amount'] = $contribution->net_amount;
|
||||
if (!empty($input['fee_amount']) && !empty($input['amount'])) {
|
||||
$input['net_amount'] = $input['amount'] - $input['fee_amount'];
|
||||
}
|
||||
|
||||
//complete the contribution.
|
||||
// @todo use the api - ie civicrm_api3('Contribution', 'completetransaction', $input);
|
||||
// as this method is not preferred / supported.
|
||||
$baseIPN->completeTransaction($input, $ids, $objects, $transaction, FALSE);
|
||||
|
||||
// reset template values before processing next transactions
|
||||
$template->clearTemplateVars();
|
||||
|
||||
return $statusId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign the minimal set of variables to the template.
|
||||
*/
|
||||
public function assignToTemplate() {
|
||||
$notifyingStatuses = array('Pending from waitlist', 'Pending from approval', 'Expired', 'Cancelled');
|
||||
$notifyingStatuses = array_intersect($notifyingStatuses, CRM_Event_PseudoConstant::participantStatus());
|
||||
$this->assign('status', TRUE);
|
||||
if (!empty($notifyingStatuses)) {
|
||||
$s = '<em>' . implode('</em>, <em>', $notifyingStatuses) . '</em>';
|
||||
$this->assign('notifyingStatuses', $s);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
90
sites/all/modules/civicrm/CRM/Event/Form/Task/Cancel.php
Normal file
90
sites/all/modules/civicrm/CRM/Event/Form/Task/Cancel.php
Normal file
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality for cancel registration for event participations
|
||||
*/
|
||||
class CRM_Event_Form_Task_Cancel extends CRM_Event_Form_Task {
|
||||
|
||||
/**
|
||||
* Variable to store redirect path.
|
||||
*/
|
||||
protected $_userContext;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
// initialize the task and row fields
|
||||
parent::preProcess();
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$this->_userContext = $session->readUserContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
CRM_Utils_System::setTitle(ts('Cancel Registration for Event Participation'));
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$this->addDefaultButtons(ts('Continue'), 'done');
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
$value = array();
|
||||
|
||||
foreach ($this->_participantIds as $participantId) {
|
||||
$value['id'] = $participantId;
|
||||
|
||||
// Cancelled status id = 4
|
||||
$value['status_id'] = 4;
|
||||
CRM_Event_BAO_Participant::create($value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
143
sites/all/modules/civicrm/CRM/Event/Form/Task/Delete.php
Normal file
143
sites/all/modules/civicrm/CRM/Event/Form/Task/Delete.php
Normal file
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to delete a group of
|
||||
* participations. This class provides functionality for the actual
|
||||
* deletion.
|
||||
*/
|
||||
class CRM_Event_Form_Task_Delete extends CRM_Event_Form_Task {
|
||||
|
||||
/**
|
||||
* Are we operating in "single mode", i.e. deleting one
|
||||
* specific participation?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_single = FALSE;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
|
||||
//check for delete
|
||||
if (!CRM_Core_Permission::checkActionPermission('CiviEvent', CRM_Core_Action::DELETE)) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
|
||||
}
|
||||
parent::preProcess();
|
||||
foreach ($this->_participantIds as $participantId) {
|
||||
if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantId)) {
|
||||
$this->assign('additionalParticipants', TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$deleteParticipants = array(
|
||||
1 => ts('Delete this participant record along with associated participant record(s).'),
|
||||
2 => ts('Delete only this participant record.'),
|
||||
);
|
||||
|
||||
$this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
|
||||
$this->setDefaults(array('delete_participant' => 1));
|
||||
|
||||
$this->addDefaultButtons(ts('Delete Participations'), 'done');
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
$participantLinks = NULL;
|
||||
if (CRM_Utils_Array::value('delete_participant', $params) == 2) {
|
||||
$links = array();
|
||||
foreach ($this->_participantIds as $participantId) {
|
||||
$additionalId = (CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId));
|
||||
$participantLinks = (CRM_Event_BAO_Participant::getAdditionalParticipantUrl($additionalId));
|
||||
}
|
||||
}
|
||||
$deletedParticipants = $additionalCount = 0;
|
||||
foreach ($this->_participantIds as $participantId) {
|
||||
if (CRM_Utils_Array::value('delete_participant', $params) == 1) {
|
||||
$primaryParticipantId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $participantId, 'registered_by_id', 'id');
|
||||
if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantId)) {
|
||||
$additionalIds = (CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId));
|
||||
$additionalCount += count($additionalIds);
|
||||
foreach ($additionalIds as $value) {
|
||||
CRM_Event_BAO_Participant::deleteParticipant($value);
|
||||
}
|
||||
CRM_Event_BAO_Participant::deleteParticipant($participantId);
|
||||
$deletedParticipants++;
|
||||
}
|
||||
// delete participant only if it is not an additional participant
|
||||
// or if it is additional and its primary participant is not selected in $this->_participantIds.
|
||||
elseif (empty($primaryParticipantId) || (!in_array($primaryParticipantId, $this->_participantIds))) {
|
||||
CRM_Event_BAO_Participant::deleteParticipant($participantId);
|
||||
$deletedParticipants++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
CRM_Event_BAO_Participant::deleteParticipant($participantId);
|
||||
$deletedParticipants++;
|
||||
}
|
||||
}
|
||||
if ($additionalCount) {
|
||||
$deletedParticipants += $additionalCount;
|
||||
}
|
||||
|
||||
$status = ts('%count participant deleted.', array('plural' => '%count participants deleted.', 'count' => $deletedParticipants));
|
||||
|
||||
if ($participantLinks) {
|
||||
$status .= '<p>' . ts('The following participants no longer have an event fee recorded. You can edit their registration and record a replacement contribution by clicking the links below:')
|
||||
. '</p>' . $participantLinks;
|
||||
}
|
||||
CRM_Core_Session::setStatus($status, ts('Removed'), 'info');
|
||||
}
|
||||
|
||||
}
|
104
sites/all/modules/civicrm/CRM/Event/Form/Task/Email.php
Normal file
104
sites/all/modules/civicrm/CRM/Event/Form/Task/Email.php
Normal file
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id: Email.php 45499 2013-02-08 12:31:05Z kurund $
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to email a group of
|
||||
* contacts.
|
||||
*/
|
||||
class CRM_Event_Form_Task_Email extends CRM_Event_Form_Task {
|
||||
|
||||
/**
|
||||
* Are we operating in "single mode", i.e. sending email to one
|
||||
* specific contact?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $_single = FALSE;
|
||||
|
||||
/**
|
||||
* Are we operating in "single mode", i.e. sending email to one
|
||||
* specific contact?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $_noEmails = FALSE;
|
||||
|
||||
/**
|
||||
* All the existing templates in the system.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_templates = NULL;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
CRM_Contact_Form_Task_EmailCommon::preProcessFromAddress($this);
|
||||
parent::preProcess();
|
||||
|
||||
// we have all the participant ids, so now we get the contact ids
|
||||
parent::setContactIDs();
|
||||
|
||||
$this->assign('single', $this->_single);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
//enable form element
|
||||
$this->assign('emailTask', TRUE);
|
||||
|
||||
CRM_Contact_Form_Task_EmailCommon::buildQuickForm($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
CRM_Contact_Form_Task_EmailCommon::postProcess($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* List available tokens for this form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listTokens() {
|
||||
$tokens = CRM_Core_SelectValues::contactTokens();
|
||||
return $tokens;
|
||||
}
|
||||
|
||||
}
|
105
sites/all/modules/civicrm/CRM/Event/Form/Task/PDF.php
Normal file
105
sites/all/modules/civicrm/CRM/Event/Form/Task/PDF.php
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id: PDF.php 45499 2013-02-08 12:31:05Z kurund $
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to create PDF letter for a group of
|
||||
* participants or a single participant.
|
||||
*/
|
||||
class CRM_Event_Form_Task_PDF extends CRM_Event_Form_Task {
|
||||
|
||||
/**
|
||||
* Are we operating in "single mode", i.e. printing letter to one
|
||||
* specific participant?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $_single = FALSE;
|
||||
|
||||
/**
|
||||
* All the existing templates in the system.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_templates = NULL;
|
||||
public $_cid = NULL;
|
||||
public $_activityId = NULL;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this);
|
||||
parent::preProcess();
|
||||
|
||||
// we have all the participant ids, so now we get the contact ids
|
||||
parent::setContactIDs();
|
||||
|
||||
$this->assign('single', $this->_single);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
CRM_Contact_Form_Task_PDFLetterCommon::postProcess($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
return CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* List available tokens for this form.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listTokens() {
|
||||
$tokens = CRM_Core_SelectValues::contactTokens();
|
||||
return $tokens;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
class CRM_Event_Form_Task_ParticipantStatus extends CRM_Event_Form_Task_Batch {
|
||||
public function buildQuickForm() {
|
||||
// CRM_Event_Form_Task_Batch::buildQuickForm() gets ufGroupId
|
||||
// from the form, so set it here to the id of the reserved profile
|
||||
$dao = new CRM_Core_DAO_UFGroup();
|
||||
$dao->name = 'participant_status';
|
||||
$dao->find(TRUE);
|
||||
$this->set('ufGroupId', $dao->id);
|
||||
|
||||
$statuses = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label');
|
||||
asort($statuses, SORT_STRING);
|
||||
$this->add('select', 'status_change', ts('Change All Statuses'),
|
||||
array(
|
||||
'' => ts('- select status -'),
|
||||
) + $statuses
|
||||
);
|
||||
|
||||
$this->assign('context', 'statusChange');
|
||||
# CRM-4321: display info on users being notified if any of the below statuses is enabled
|
||||
parent::assignToTemplate();
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
}
|
146
sites/all/modules/civicrm/CRM/Event/Form/Task/PickProfile.php
Normal file
146
sites/all/modules/civicrm/CRM/Event/Form/Task/PickProfile.php
Normal file
|
@ -0,0 +1,146 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality for batch profile update for event participations
|
||||
*/
|
||||
class CRM_Event_Form_Task_PickProfile extends CRM_Event_Form_Task {
|
||||
|
||||
/**
|
||||
* The title of the group.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_title;
|
||||
|
||||
/**
|
||||
* Maximum event participations that should be allowed to update.
|
||||
*/
|
||||
protected $_maxParticipations = 100;
|
||||
|
||||
/**
|
||||
* Variable to store redirect path.
|
||||
*/
|
||||
protected $_userContext;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
// initialize the task and row fields
|
||||
parent::preProcess();
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$this->_userContext = $session->readUserContext();
|
||||
|
||||
CRM_Utils_System::setTitle(ts('Update multiple participants'));
|
||||
|
||||
$validate = FALSE;
|
||||
//validations
|
||||
if (count($this->_participantIds) > $this->_maxParticipations) {
|
||||
CRM_Core_Session::setStatus("The maximum number of records you can select for Update multiple participants is {$this->_maxParticipations}. You have selected " . count($this->_participantIds) . ". Please select fewer participantions from your search results and try again.");
|
||||
$validate = TRUE;
|
||||
}
|
||||
|
||||
// then redirect
|
||||
if ($validate) {
|
||||
CRM_Utils_System::redirect($this->_userContext);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$types = array('Participant');
|
||||
$profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE);
|
||||
|
||||
if (empty($profiles)) {
|
||||
CRM_Core_Session::setStatus("To use Update multiple participants, you need to configure a profile containing only Participant fields (e.g. Participant Status, Participant Role, etc.). Configure a profile at 'Administer CiviCRM >> Customize >> CiviCRM Profile'.");
|
||||
CRM_Utils_System::redirect($this->_userContext);
|
||||
}
|
||||
|
||||
$ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'),
|
||||
array(
|
||||
'' => ts('- select profile -'),
|
||||
) + $profiles, TRUE
|
||||
);
|
||||
$this->addDefaultButtons(ts('Continue'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add local and global form rules.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addRules() {
|
||||
$this->addFormRule(array('CRM_Event_Form_Task_PickProfile', 'formRule'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($fields) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->exportValues();
|
||||
|
||||
$this->set('ufGroupId', $params['uf_group_id']);
|
||||
|
||||
// also reset the batch page so it gets new values from the db
|
||||
$this->controller->resetPage('Batch');
|
||||
}
|
||||
|
||||
}
|
105
sites/all/modules/civicrm/CRM/Event/Form/Task/Print.php
Normal file
105
sites/all/modules/civicrm/CRM/Event/Form/Task/Print.php
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to participant records
|
||||
*/
|
||||
class CRM_Event_Form_Task_Print extends CRM_Event_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preprocess();
|
||||
|
||||
// set print view, so that print templates are called
|
||||
$this->controller->setPrint(1);
|
||||
|
||||
// get the formatted params
|
||||
$queryParams = $this->get('queryParams');
|
||||
|
||||
$sortID = NULL;
|
||||
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
|
||||
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
|
||||
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
|
||||
);
|
||||
}
|
||||
|
||||
$selector = new CRM_Event_Selector_Search($queryParams, $this->_action, $this->_componentClause);
|
||||
$controller = new CRM_Core_Selector_Controller($selector, NULL, $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SCREEN);
|
||||
$controller->setEmbedded(TRUE);
|
||||
$controller->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object - it consists of
|
||||
* - displaying the QILL (query in local language)
|
||||
* - displaying elements for saving the search
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
//
|
||||
// just need to add a javacript to popup the window for printing
|
||||
//
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Print Participant List'),
|
||||
'js' => array('onclick' => 'window.print()'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'back',
|
||||
'name' => ts('Done'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
// redirect to the main search page after printing is over
|
||||
}
|
||||
|
||||
}
|
70
sites/all/modules/civicrm/CRM/Event/Form/Task/Result.php
Normal file
70
sites/all/modules/civicrm/CRM/Event/Form/Task/Result.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Used for displaying results
|
||||
*
|
||||
*
|
||||
*/
|
||||
class CRM_Event_Form_Task_Result extends CRM_Event_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
|
||||
//this is done to unset searchRows variable assign during AddToHousehold and AddToOrganization
|
||||
$this->set('searchRows', '');
|
||||
|
||||
$ssID = $this->get('ssID');
|
||||
|
||||
$path = 'force=1';
|
||||
if (isset($ssID)) {
|
||||
$path .= "&reset=1&ssID={$ssID}";
|
||||
}
|
||||
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
|
||||
if (CRM_Utils_Rule::qfKey($qfKey)) {
|
||||
$path .= "&qfKey=$qfKey";
|
||||
}
|
||||
|
||||
$url = CRM_Utils_System::url('civicrm/event/search', $path);
|
||||
$session->replaceUserContext($url);
|
||||
CRM_Utils_System::redirect($url);
|
||||
}
|
||||
|
||||
}
|
142
sites/all/modules/civicrm/CRM/Event/Form/Task/SaveSearch.php
Normal file
142
sites/all/modules/civicrm/CRM/Event/Form/Task/SaveSearch.php
Normal file
|
@ -0,0 +1,142 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to save a search
|
||||
* Saved Searches are used for saving frequently used queries
|
||||
* regarding the event participations
|
||||
*/
|
||||
class CRM_Event_Form_Task_SaveSearch extends CRM_Event_Form_Task {
|
||||
|
||||
/**
|
||||
* Saved search id if any.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
$this->_id = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object - it consists of
|
||||
* - displaying the QILL (query in local language)
|
||||
* - displaying elements for saving the search
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
CRM_Utils_System::setTitle(ts('Smart Group'));
|
||||
// get the qill
|
||||
$query = new CRM_Event_BAO_Query($this->get('formValues'));
|
||||
$qill = $query->qill();
|
||||
|
||||
// Values from the search form
|
||||
$formValues = $this->controller->exportValues();
|
||||
|
||||
// need to save qill for the smarty template
|
||||
$this->assign('qill', $qill);
|
||||
|
||||
// the name and description are actually stored with the group and not the saved search
|
||||
$this->add('text', 'title', ts('Name'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title'), TRUE
|
||||
);
|
||||
|
||||
$this->addElement('text', 'description', ts('Description'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'description')
|
||||
);
|
||||
|
||||
// get the group id for the saved search
|
||||
$groupId = NULL;
|
||||
if (isset($this->_id)) {
|
||||
$params = array('saved_search_id' => $this->_id);
|
||||
CRM_Contact_BAO_Group::retrieve($params, $values);
|
||||
$groupId = $values['id'];
|
||||
|
||||
$this->addDefaultButtons(ts('Update Smart Group'));
|
||||
}
|
||||
else {
|
||||
$this->addDefaultButtons(ts('Save Smart Group'));
|
||||
$this->assign('partiallySelected', $formValues['radio_ts'] != 'ts_all');
|
||||
}
|
||||
|
||||
$this->addRule('title', ts('Name already exists in Database.'),
|
||||
'objectExists', array('CRM_Contact_DAO_Group', $groupId, 'title')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
// saved search form values
|
||||
$formValues = $this->controller->exportValues();
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
|
||||
//save the search
|
||||
$savedSearch = new CRM_Contact_BAO_SavedSearch();
|
||||
$savedSearch->id = $this->_id;
|
||||
$savedSearch->form_values = serialize($this->get('formValues'));
|
||||
$savedSearch->save();
|
||||
$this->set('ssID', $savedSearch->id);
|
||||
CRM_Core_Session::setStatus(ts("Your smart group has been saved as '%1'.", array(1 => $formValues['title'])), ts('Saved'), 'success');
|
||||
|
||||
// also create a group that is associated with this saved search only if new saved search
|
||||
$params = array();
|
||||
$params['title'] = $formValues['title'];
|
||||
$params['description'] = $formValues['description'];
|
||||
$params['visibility'] = 'User and User Admin Only';
|
||||
$params['saved_search_id'] = $savedSearch->id;
|
||||
$params['is_active'] = 1;
|
||||
|
||||
if ($this->_id) {
|
||||
$params['id'] = CRM_Contact_BAO_SavedSearch::getName($this->_id, 'id');
|
||||
}
|
||||
$group = CRM_Contact_BAO_Group::create($params);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to update a saved search
|
||||
*
|
||||
*/
|
||||
class CRM_Event_Form_Task_SaveSearch_Update extends CRM_Event_Form_Task_SaveSearch {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
$this->_id = $this->get('ssID');
|
||||
if (!$this->_id) {
|
||||
// fetch the value from the group id gid
|
||||
$gid = $this->get('gid');
|
||||
$this->_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $gid, 'saved_search_id');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
|
||||
$defaults = array();
|
||||
$params = array();
|
||||
|
||||
$params = array('saved_search_id' => $this->_id);
|
||||
CRM_Contact_BAO_Group::retrieve($params, $defaults);
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to save a search
|
||||
* Saved Searches are used for saving frequently used queries
|
||||
*/
|
||||
class CRM_Event_Form_Task_SearchTaskHookSample extends CRM_Event_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
$rows = array();
|
||||
// display name and participation details of participants
|
||||
$participantIDs = implode(',', $this->_participantIds);
|
||||
|
||||
$query = "
|
||||
SELECT p.fee_amount as amount,
|
||||
p.register_date as register_date,
|
||||
p.source as source,
|
||||
ct.display_name as display_name
|
||||
FROM civicrm_participant p
|
||||
INNER JOIN civicrm_contact ct ON ( p.contact_id = ct.id )
|
||||
WHERE p.id IN ( $participantIDs )";
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
while ($dao->fetch()) {
|
||||
$rows[] = array(
|
||||
'display_name' => $dao->display_name,
|
||||
'amount' => $dao->amount,
|
||||
'register_date' => CRM_Utils_Date::customFormat($dao->register_date),
|
||||
'source' => $dao->source,
|
||||
);
|
||||
}
|
||||
$this->assign('rows', $rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'done',
|
||||
'name' => ts('Done'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue