First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View 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
*/
/**
* 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');
}
}

View 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');
}
}
}

View file

@ -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 events 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');
}
}

View 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('&nbsp;&nbsp;', '&nbsp;&nbsp;', '&nbsp;&nbsp;', '<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');
}
}

View file

@ -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

View 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;
}
}

View file

@ -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';
}
}

View file

@ -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;
}
}