CRM-13244 - RecipientBuilder::prepareStartDateClauses - Less stringiness
[civicrm-core.git] / CRM / Event / Form / ManageEvent / TabHeader.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * Helper class to build navigation links
38 */
39class CRM_Event_Form_ManageEvent_TabHeader {
40
0cf587a7 41 /**
c65ce939 42 * @param CRM_Event_Form_ManageEvent $form
0cf587a7
EM
43 *
44 * @return array
45 */
00be9182 46 public static function build(&$form) {
6a488035 47 $tabs = $form->get('tabHeader');
8cc574cf 48 if (!$tabs || empty($_GET['reset'])) {
6a488035
TO
49 $tabs = self::process($form);
50 $form->set('tabHeader', $tabs);
51 }
52 $form->assign_by_ref('tabHeader', $tabs);
4165b7e5 53 CRM_Core_Resources::singleton()
96ed17aa 54 ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
0479b4c8 55 ->addSetting(array(
353ffa53
TO
56 'tabSettings' => array(
57 'active' => self::getCurrentTab($tabs),
389bcebf 58 ),
353ffa53 59 ));
bfd83a87 60 CRM_Event_Form_ManageEvent::addProfileEditScripts();
6a488035
TO
61 return $tabs;
62 }
63
0cf587a7 64 /**
c65ce939 65 * @param CRM_Event_Form_ManageEvent $form
0cf587a7
EM
66 *
67 * @return array
68 * @throws Exception
69 */
00be9182 70 public static function process(&$form) {
6a488035
TO
71 if ($form->getVar('_id') <= 0) {
72 return NULL;
73 }
74
4b628e67
CW
75 $default = array(
76 'link' => NULL,
77 'valid' => TRUE,
78 'active' => TRUE,
79 'current' => FALSE,
80 'class' => 'ajaxForm',
81 );
82
209989e3 83 $tabs = array();
84 $tabs['settings'] = array('title' => ts('Info and Settings'), 'class' => 'ajaxForm livePage') + $default;
85 $tabs['location'] = array('title' => ts('Event Location')) + $default;
86 $tabs['fee'] = array('title' => ts('Fees')) + $default;
87 $tabs['registration'] = array('title' => ts('Online Registration')) + $default;
17bf0840 88 if (CRM_Core_Permission::check('administer CiviCRM') || CRM_Event_BAO_Event::checkPermission(NULL, CRM_Core_Permission::EDIT)) {
209989e3 89 $tabs['reminder'] = array('title' => ts('Schedule Reminders'), 'class' => 'livePage') + $default;
90 }
91 $tabs['conference'] = array('title' => ts('Conference Slots')) + $default;
92 $tabs['friend'] = array('title' => ts('Tell a Friend')) + $default;
93 $tabs['pcp'] = array('title' => ts('Personal Campaigns')) + $default;
62933949 94 $tabs['repeat'] = array('title' => ts('Repeat')) + $default;
209989e3 95
c65ce939
CW
96 // Repeat tab must refresh page when switching repeat mode so js & vars will get set-up
97 if (!$form->_isRepeatingEvent) {
98 unset($tabs['repeat']['class']);
99 }
100
6a488035
TO
101 // check if we're in shopping cart mode for events
102 $enableCart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME,
103 'enable_cart'
104 );
6a488035
TO
105 if (!$enableCart) {
106 unset($tabs['conference']);
107 }
108
109 $eventID = $form->getVar('_id');
a215a5b0 110 if ($eventID) {
0cf587a7 111 // disable tabs based on their configuration status
50a23755 112 $eventNameMapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings(array(
77e16391 113 'id' => CRM_Core_ActionScheduleTmp::EVENT_NAME_MAPPING_ID,
50a23755 114 )));
a215a5b0 115 $sql = "
6063a2f1 116SELECT 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
a215a5b0
DS
117FROM civicrm_event e
118LEFT JOIN civicrm_tell_friend taf ON ( taf.entity_table = 'civicrm_event' AND taf.entity_id = e.id )
119LEFT JOIN civicrm_pcp_block pcp ON ( pcp.entity_table = 'civicrm_event' AND pcp.entity_id = e.id )
50a23755 120LEFT JOIN civicrm_action_schedule sch ON ( sch.mapping_id = %2 AND sch.entity_value = %1 )
6063a2f1 121LEFT JOIN civicrm_recurring_entity re ON ( e.id = re.entity_id AND re.entity_table = 'civicrm_event' )
a215a5b0
DS
122WHERE e.id = %1
123";
62933949 124 //Check if repeat is configured
125 $eventHasParent = CRM_Core_BAO_RecurringEntity::getParentFor($eventID, 'civicrm_event');
50a23755
TO
126 $params = array(
127 1 => array($eventID, 'Integer'),
9e1bf145 128 2 => array($eventNameMapping->getId(), 'Integer'),
50a23755 129 );
a215a5b0
DS
130 $dao = CRM_Core_DAO::executeQuery($sql, $params);
131 if (!$dao->fetch()) {
132 CRM_Core_Error::fatal();
133 }
134 if (!$dao->is_location) {
135 $tabs['location']['valid'] = FALSE;
136 }
137 if (!$dao->is_online_registration) {
138 $tabs['registration']['valid'] = FALSE;
139 }
140 if (!$dao->is_monetary) {
141 $tabs['fee']['valid'] = FALSE;
142 }
143 if (!$dao->is_active) {
144 $tabs['friend']['valid'] = FALSE;
145 }
146 if (!$dao->is_pcp) {
147 $tabs['pcp']['valid'] = FALSE;
148 }
149 if (!$dao->is_reminder) {
150 $tabs['reminder']['valid'] = FALSE;
151 }
a50a97b8 152 if (!$dao->is_repeating_event) {
62933949 153 $tabs['repeat']['valid'] = FALSE;
154 }
a215a5b0 155 }
6a488035 156
c1ad592f 157 // see if any other modules want to add any tabs
a215a5b0 158 // note: status of 'valid' flag of any injected tab, needs to be taken care in the hook implementation.
c1ad592f 159 CRM_Utils_Hook::tabset('civicrm/event/manage', $tabs,
160 array('event_id' => $eventID));
161
353ffa53 162 $fullName = $form->getVar('_name');
6a488035 163 $className = CRM_Utils_String::getClassName($fullName);
353ffa53 164 $new = '';
4d3e4dbe 165
6a488035
TO
166 // hack for special cases.
167 switch ($className) {
168 case 'Event':
169 $attributes = $form->getVar('_attributes');
170 $class = strtolower(basename(CRM_Utils_Array::value('action', $attributes)));
171 break;
172
c13a1cff
AN
173 case 'EventInfo':
174 $class = 'settings';
175 break;
176
6a488035
TO
177 case 'ScheduleReminders':
178 $class = 'reminder';
6a488035
TO
179 break;
180
181 default:
182 $class = strtolower($className);
183 break;
184 }
185
186 if (array_key_exists($class, $tabs)) {
187 $tabs[$class]['current'] = TRUE;
188 $qfKey = $form->get('qfKey');
189 if ($qfKey) {
190 $tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
191 }
192 }
193
194 if ($eventID) {
0d8afee2 195 $reset = !empty($_GET['reset']) ? 'reset=1&' : '';
6a488035
TO
196
197 foreach ($tabs as $key => $value) {
198 if (!isset($tabs[$key]['qfKey'])) {
199 $tabs[$key]['qfKey'] = NULL;
200 }
201
e8e90f7e 202 $action = 'update';
4d3e4dbe 203 if ($key == 'reminder') {
204 $action = 'browse';
205 }
206
2f3732a9
FG
207 $link = "civicrm/event/manage/{$key}";
208 $query = "{$reset}action={$action}&id={$eventID}&component=event{$tabs[$key]['qfKey']}";
e84a94d2 209
32f93260 210 $tabs[$key]['link'] = (isset($value['link']) ? $value['link'] :
2f3732a9 211 CRM_Utils_System::url($link, $query));
74affe5c 212 }
6a488035 213 }
fa3dbfbd 214
6a488035
TO
215 return $tabs;
216 }
217
0cf587a7 218 /**
c65ce939 219 * @param CRM_Event_Form_ManageEvent $form
0cf587a7 220 */
00be9182 221 public static function reset(&$form) {
6a488035
TO
222 $tabs = self::process($form);
223 $form->set('tabHeader', $tabs);
224 }
225
0cf587a7
EM
226 /**
227 * @param $tabs
228 *
229 * @return int|string
230 */
00be9182 231 public static function getCurrentTab($tabs) {
6a488035
TO
232 static $current = FALSE;
233
234 if ($current) {
235 return $current;
236 }
237
238 if (is_array($tabs)) {
239 foreach ($tabs as $subPage => $pageVal) {
240 if ($pageVal['current'] === TRUE) {
241 $current = $subPage;
242 break;
243 }
244 }
245 }
246
247 $current = $current ? $current : 'settings';
248 return $current;
249 }
96025800 250
6a488035 251}