3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Helper class to build navigation links
21 class CRM_Event_Form_ManageEvent_TabHeader
{
24 * @param CRM_Event_Form_ManageEvent $form
27 * @throws \CRM_Core_Exception
29 public static function build(&$form) {
30 $tabs = $form->get('tabHeader');
31 if (!$tabs ||
empty($_GET['reset'])) {
32 $tabs = self
::process($form);
33 $form->set('tabHeader', $tabs);
35 $form->assign_by_ref('tabHeader', $tabs);
36 CRM_Core_Resources
::singleton()
37 ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
40 'active' => self
::getCurrentTab($tabs),
43 CRM_Event_Form_ManageEvent
::addProfileEditScripts();
48 * @param CRM_Event_Form_ManageEvent $form
53 public static function process(&$form) {
54 if ($form->getVar('_id') <= 0) {
63 'class' => 'ajaxForm',
67 $tabs['settings'] = ['title' => ts('Info and Settings'), 'class' => 'ajaxForm livePage'] +
$default;
68 $tabs['location'] = ['title' => ts('Event Location')] +
$default;
69 $tabs['fee'] = ['title' => ts('Fees')] +
$default;
70 $tabs['registration'] = ['title' => ts('Online Registration')] +
$default;
71 // @fixme I don't understand the event permissions check here - can we just get rid of it?
72 $permissions = CRM_Event_BAO_Event
::getAllPermissions();
73 if (CRM_Core_Permission
::check('administer CiviCRM data') ||
!empty($permissions[CRM_Core_Permission
::EDIT
])) {
74 $tabs['reminder'] = ['title' => ts('Schedule Reminders'), 'class' => 'livePage'] +
$default;
76 $tabs['conference'] = ['title' => ts('Conference Slots')] +
$default;
77 $tabs['friend'] = ['title' => ts('Tell a Friend')] +
$default;
78 $tabs['pcp'] = ['title' => ts('Personal Campaigns')] +
$default;
79 $tabs['repeat'] = ['title' => ts('Repeat')] +
$default;
81 // Repeat tab must refresh page when switching repeat mode so js & vars will get set-up
82 if (!$form->_isRepeatingEvent
) {
83 unset($tabs['repeat']['class']);
86 // @todo Move to eventcart extension
87 // check if we're in shopping cart mode for events
88 if (!(bool) Civi
::settings()->get('enable_cart')) {
89 unset($tabs['conference']);
92 $eventID = $form->getVar('_id');
94 // disable tabs based on their configuration status
95 $eventNameMapping = CRM_Utils_Array
::first(CRM_Core_BAO_ActionSchedule
::getMappings([
96 'id' => CRM_Event_ActionMapping
::EVENT_NAME_MAPPING_ID
,
99 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
101 LEFT JOIN civicrm_tell_friend taf ON ( taf.entity_table = 'civicrm_event' AND taf.entity_id = e.id )
102 LEFT JOIN civicrm_pcp_block pcp ON ( pcp.entity_table = 'civicrm_event' AND pcp.entity_id = e.id )
103 LEFT JOIN civicrm_action_schedule sch ON ( sch.mapping_id = %2 AND sch.entity_value = %1 )
104 LEFT JOIN civicrm_recurring_entity re ON ( e.id = re.entity_id AND re.entity_table = 'civicrm_event' )
107 //Check if repeat is configured
108 CRM_Core_BAO_RecurringEntity
::getParentFor($eventID, 'civicrm_event');
110 1 => [$eventID, 'Integer'],
111 2 => [$eventNameMapping->getId(), 'Integer'],
113 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
114 if (!$dao->fetch()) {
115 throw new CRM_Core_Exception('Unable to determine Event information');;
117 if (!$dao->is_location
) {
118 $tabs['location']['valid'] = FALSE;
120 if (!$dao->is_online_registration
) {
121 $tabs['registration']['valid'] = FALSE;
123 if (!$dao->is_monetary
) {
124 $tabs['fee']['valid'] = FALSE;
126 if (!$dao->is_active
) {
127 $tabs['friend']['valid'] = FALSE;
130 $tabs['pcp']['valid'] = FALSE;
132 if (!$dao->is_reminder
) {
133 $tabs['reminder']['valid'] = FALSE;
135 if (!$dao->is_repeating_event
) {
136 $tabs['repeat']['valid'] = FALSE;
140 // see if any other modules want to add any tabs
141 // note: status of 'valid' flag of any injected tab, needs to be taken care in the hook implementation.
142 CRM_Utils_Hook
::tabset('civicrm/event/manage', $tabs,
143 ['event_id' => $eventID]);
145 $fullName = $form->getVar('_name');
146 $className = CRM_Utils_String
::getClassName($fullName);
149 // hack for special cases.
150 switch ($className) {
152 $attributes = $form->getVar('_attributes');
153 $class = CRM_Utils_Request
::retrieveComponent($attributes);
160 case 'ScheduleReminders':
165 $class = strtolower($className);
169 if (array_key_exists($class, $tabs)) {
170 $tabs[$class]['current'] = TRUE;
171 $qfKey = $form->get('qfKey');
173 $tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
178 $reset = !empty($_GET['reset']) ?
'reset=1&' : '';
180 foreach ($tabs as $key => $value) {
181 if (!isset($tabs[$key]['qfKey'])) {
182 $tabs[$key]['qfKey'] = NULL;
186 if ($key == 'reminder') {
190 $link = "civicrm/event/manage/{$key}";
191 $query = "{$reset}action={$action}&id={$eventID}&component=event{$tabs[$key]['qfKey']}";
193 $tabs[$key]['link'] = (isset($value['link']) ?
$value['link'] :
194 CRM_Utils_System
::url($link, $query));
202 * @param CRM_Event_Form_ManageEvent $form
204 public static function reset(&$form) {
205 $tabs = self
::process($form);
206 $form->set('tabHeader', $tabs);
214 public static function getCurrentTab($tabs) {
215 static $current = FALSE;
221 if (is_array($tabs)) {
222 foreach ($tabs as $subPage => $pageVal) {
223 if (CRM_Utils_Array
::value('current', $pageVal) === TRUE) {
230 $current = $current ?
$current : 'settings';