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
21 * Helper class to build navigation links
23 class CRM_Event_Form_ManageEvent_TabHeader
{
26 * @param CRM_Event_Form_ManageEvent $form
29 * @throws \CRM_Core_Exception
31 public static function build(&$form) {
32 $tabs = $form->get('tabHeader');
33 if (!$tabs ||
empty($_GET['reset'])) {
34 $tabs = self
::process($form);
35 $form->set('tabHeader', $tabs);
37 $form->assign_by_ref('tabHeader', $tabs);
38 CRM_Core_Resources
::singleton()
39 ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
42 'active' => self
::getCurrentTab($tabs),
45 CRM_Event_Form_ManageEvent
::addProfileEditScripts();
50 * @param CRM_Event_Form_ManageEvent $form
55 public static function process(&$form) {
56 if ($form->getVar('_id') <= 0) {
65 'class' => 'ajaxForm',
69 $tabs['settings'] = ['title' => ts('Info and Settings'), 'class' => 'ajaxForm livePage'] +
$default;
70 $tabs['location'] = ['title' => ts('Event Location')] +
$default;
71 $tabs['fee'] = ['title' => ts('Fees')] +
$default;
72 $tabs['registration'] = ['title' => ts('Online Registration')] +
$default;
73 // @fixme I don't understand the event permissions check here - can we just get rid of it?
74 $permissions = CRM_Event_BAO_Event
::getAllPermissions();
75 if (CRM_Core_Permission
::check('administer CiviCRM') ||
!empty($permissions[CRM_Core_Permission
::EDIT
])) {
76 $tabs['reminder'] = ['title' => ts('Schedule Reminders'), 'class' => 'livePage'] +
$default;
78 $tabs['conference'] = ['title' => ts('Conference Slots')] +
$default;
79 $tabs['friend'] = ['title' => ts('Tell a Friend')] +
$default;
80 $tabs['pcp'] = ['title' => ts('Personal Campaigns')] +
$default;
81 $tabs['repeat'] = ['title' => ts('Repeat')] +
$default;
83 // Repeat tab must refresh page when switching repeat mode so js & vars will get set-up
84 if (!$form->_isRepeatingEvent
) {
85 unset($tabs['repeat']['class']);
88 // check if we're in shopping cart mode for events
89 $enableCart = Civi
::settings()->get('enable_cart');
91 unset($tabs['conference']);
94 $eventID = $form->getVar('_id');
96 // disable tabs based on their configuration status
97 $eventNameMapping = CRM_Utils_Array
::first(CRM_Core_BAO_ActionSchedule
::getMappings([
98 'id' => CRM_Event_ActionMapping
::EVENT_NAME_MAPPING_ID
,
101 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
103 LEFT JOIN civicrm_tell_friend taf ON ( taf.entity_table = 'civicrm_event' AND taf.entity_id = e.id )
104 LEFT JOIN civicrm_pcp_block pcp ON ( pcp.entity_table = 'civicrm_event' AND pcp.entity_id = e.id )
105 LEFT JOIN civicrm_action_schedule sch ON ( sch.mapping_id = %2 AND sch.entity_value = %1 )
106 LEFT JOIN civicrm_recurring_entity re ON ( e.id = re.entity_id AND re.entity_table = 'civicrm_event' )
109 //Check if repeat is configured
110 $eventHasParent = CRM_Core_BAO_RecurringEntity
::getParentFor($eventID, 'civicrm_event');
112 1 => [$eventID, 'Integer'],
113 2 => [$eventNameMapping->getId(), 'Integer'],
115 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
116 if (!$dao->fetch()) {
117 CRM_Core_Error
::fatal();
119 if (!$dao->is_location
) {
120 $tabs['location']['valid'] = FALSE;
122 if (!$dao->is_online_registration
) {
123 $tabs['registration']['valid'] = FALSE;
125 if (!$dao->is_monetary
) {
126 $tabs['fee']['valid'] = FALSE;
128 if (!$dao->is_active
) {
129 $tabs['friend']['valid'] = FALSE;
132 $tabs['pcp']['valid'] = FALSE;
134 if (!$dao->is_reminder
) {
135 $tabs['reminder']['valid'] = FALSE;
137 if (!$dao->is_repeating_event
) {
138 $tabs['repeat']['valid'] = FALSE;
142 // see if any other modules want to add any tabs
143 // note: status of 'valid' flag of any injected tab, needs to be taken care in the hook implementation.
144 CRM_Utils_Hook
::tabset('civicrm/event/manage', $tabs,
145 ['event_id' => $eventID]);
147 $fullName = $form->getVar('_name');
148 $className = CRM_Utils_String
::getClassName($fullName);
151 // hack for special cases.
152 switch ($className) {
154 $attributes = $form->getVar('_attributes');
155 $class = CRM_Utils_Request
::retrieveComponent($attributes);
162 case 'ScheduleReminders':
167 $class = strtolower($className);
171 if (array_key_exists($class, $tabs)) {
172 $tabs[$class]['current'] = TRUE;
173 $qfKey = $form->get('qfKey');
175 $tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
180 $reset = !empty($_GET['reset']) ?
'reset=1&' : '';
182 foreach ($tabs as $key => $value) {
183 if (!isset($tabs[$key]['qfKey'])) {
184 $tabs[$key]['qfKey'] = NULL;
188 if ($key == 'reminder') {
192 $link = "civicrm/event/manage/{$key}";
193 $query = "{$reset}action={$action}&id={$eventID}&component=event{$tabs[$key]['qfKey']}";
195 $tabs[$key]['link'] = (isset($value['link']) ?
$value['link'] :
196 CRM_Utils_System
::url($link, $query));
204 * @param CRM_Event_Form_ManageEvent $form
206 public static function reset(&$form) {
207 $tabs = self
::process($form);
208 $form->set('tabHeader', $tabs);
216 public static function getCurrentTab($tabs) {
217 static $current = FALSE;
223 if (is_array($tabs)) {
224 foreach ($tabs as $subPage => $pageVal) {
225 if (CRM_Utils_Array
::value('current', $pageVal) === TRUE) {
232 $current = $current ?
$current : 'settings';