Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * Helper class to build navigation links | |
38 | */ | |
39 | class CRM_Event_Form_ManageEvent_TabHeader { | |
40 | ||
41 | static function build(&$form) { | |
42 | $tabs = $form->get('tabHeader'); | |
43 | if (!$tabs || !CRM_Utils_Array::value('reset', $_GET)) { | |
44 | $tabs = self::process($form); | |
45 | $form->set('tabHeader', $tabs); | |
46 | } | |
47 | $form->assign_by_ref('tabHeader', $tabs); | |
4165b7e5 CW |
48 | CRM_Core_Resources::singleton() |
49 | ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js') | |
50 | ->addSetting(array('tabSettings' => array( | |
51 | 'active' => self::getCurrentTab($tabs), | |
52 | ))); | |
6a488035 TO |
53 | return $tabs; |
54 | } | |
55 | ||
56 | static function process(&$form) { | |
57 | if ($form->getVar('_id') <= 0) { | |
58 | return NULL; | |
59 | } | |
60 | ||
4b628e67 CW |
61 | $default = array( |
62 | 'link' => NULL, | |
63 | 'valid' => TRUE, | |
64 | 'active' => TRUE, | |
65 | 'current' => FALSE, | |
66 | 'class' => 'ajaxForm', | |
67 | ); | |
68 | ||
6a488035 | 69 | $tabs = array( |
4b628e67 CW |
70 | 'settings' => array('title' => ts('Info and Settings')) + $default, |
71 | 'location' => array('title' => ts('Event Location')) + $default, | |
72 | 'fee' => array('title' => ts('Fees')) + $default, | |
73 | 'registration' => array('title' => ts('Online Registration')) + $default, | |
74 | 'reminder' => array('title' => ts('Schedule Reminders'), 'class' => 'livePage') + $default, | |
75 | 'conference' => array('title' => ts('Conference Slots')) + $default, | |
76 | 'friend' => array('title' => ts('Tell a Friend')) + $default, | |
77 | 'pcp' => array('title' => ts('Personal Campaigns')) + $default, | |
6a488035 TO |
78 | ); |
79 | ||
80 | // check if we're in shopping cart mode for events | |
81 | $enableCart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME, | |
82 | 'enable_cart' | |
83 | ); | |
6a488035 TO |
84 | if (!$enableCart) { |
85 | unset($tabs['conference']); | |
86 | } | |
87 | ||
88 | $eventID = $form->getVar('_id'); | |
a215a5b0 DS |
89 | if ($eventID) { |
90 | // disable tabs based on their configuration status | |
91 | $sql = " | |
92 | SELECT e.loc_block_id as is_location, e.is_online_registration, e.is_monetary, taf.is_active, pcp.id as is_pcp, sch.id as is_reminder | |
93 | FROM civicrm_event e | |
94 | LEFT JOIN civicrm_tell_friend taf ON ( taf.entity_table = 'civicrm_event' AND taf.entity_id = e.id ) | |
95 | LEFT JOIN civicrm_pcp_block pcp ON ( pcp.entity_table = 'civicrm_event' AND pcp.entity_id = e.id ) | |
96 | LEFT JOIN civicrm_action_mapping map ON ( map.entity_value = 'civicrm_event' ) | |
97 | LEFT JOIN civicrm_action_schedule sch ON ( sch.mapping_id = map.id AND sch.entity_value = %1 ) | |
98 | WHERE e.id = %1 | |
99 | "; | |
100 | $params = array(1 => array($eventID, 'Integer')); | |
101 | $dao = CRM_Core_DAO::executeQuery($sql, $params); | |
102 | if (!$dao->fetch()) { | |
103 | CRM_Core_Error::fatal(); | |
104 | } | |
105 | if (!$dao->is_location) { | |
106 | $tabs['location']['valid'] = FALSE; | |
107 | } | |
108 | if (!$dao->is_online_registration) { | |
109 | $tabs['registration']['valid'] = FALSE; | |
110 | } | |
111 | if (!$dao->is_monetary) { | |
112 | $tabs['fee']['valid'] = FALSE; | |
113 | } | |
114 | if (!$dao->is_active) { | |
115 | $tabs['friend']['valid'] = FALSE; | |
116 | } | |
117 | if (!$dao->is_pcp) { | |
118 | $tabs['pcp']['valid'] = FALSE; | |
119 | } | |
120 | if (!$dao->is_reminder) { | |
121 | $tabs['reminder']['valid'] = FALSE; | |
122 | } | |
123 | } | |
6a488035 | 124 | |
c1ad592f | 125 | // see if any other modules want to add any tabs |
a215a5b0 | 126 | // note: status of 'valid' flag of any injected tab, needs to be taken care in the hook implementation. |
c1ad592f | 127 | CRM_Utils_Hook::tabset('civicrm/event/manage', $tabs, |
128 | array('event_id' => $eventID)); | |
129 | ||
6a488035 TO |
130 | $fullName = $form->getVar('_name'); |
131 | $className = CRM_Utils_String::getClassName($fullName); | |
132 | $new = ''; | |
133 | // hack for special cases. | |
134 | switch ($className) { | |
135 | case 'Event': | |
136 | $attributes = $form->getVar('_attributes'); | |
137 | $class = strtolower(basename(CRM_Utils_Array::value('action', $attributes))); | |
138 | break; | |
139 | ||
140 | case 'ScheduleReminders': | |
141 | $class = 'reminder'; | |
142 | $new = CRM_Utils_Array::value('new', $_GET) ? '&new=1' : ''; | |
143 | break; | |
144 | ||
145 | default: | |
146 | $class = strtolower($className); | |
147 | break; | |
148 | } | |
149 | ||
150 | if (array_key_exists($class, $tabs)) { | |
151 | $tabs[$class]['current'] = TRUE; | |
152 | $qfKey = $form->get('qfKey'); | |
153 | if ($qfKey) { | |
154 | $tabs[$class]['qfKey'] = "&qfKey={$qfKey}"; | |
155 | } | |
156 | } | |
157 | ||
158 | if ($eventID) { | |
159 | $reset = CRM_Utils_Array::value('reset', $_GET) ? 'reset=1&' : ''; | |
160 | ||
161 | foreach ($tabs as $key => $value) { | |
162 | if (!isset($tabs[$key]['qfKey'])) { | |
163 | $tabs[$key]['qfKey'] = NULL; | |
164 | } | |
165 | ||
166 | $tabs[$key]['link'] = CRM_Utils_System::url("civicrm/event/manage/{$key}", | |
8547369d | 167 | "{$reset}action=update&id={$eventID}&component=event{$new}{$tabs[$key]['qfKey']}" |
6a488035 | 168 | ); |
74affe5c | 169 | } |
6a488035 | 170 | } |
fa3dbfbd | 171 | |
6a488035 TO |
172 | return $tabs; |
173 | } | |
174 | ||
175 | static function reset(&$form) { | |
176 | $tabs = self::process($form); | |
177 | $form->set('tabHeader', $tabs); | |
178 | } | |
179 | ||
180 | static function getCurrentTab($tabs) { | |
181 | static $current = FALSE; | |
182 | ||
183 | if ($current) { | |
184 | return $current; | |
185 | } | |
186 | ||
187 | if (is_array($tabs)) { | |
188 | foreach ($tabs as $subPage => $pageVal) { | |
189 | if ($pageVal['current'] === TRUE) { | |
190 | $current = $subPage; | |
191 | break; | |
192 | } | |
193 | } | |
194 | } | |
195 | ||
196 | $current = $current ? $current : 'settings'; | |
197 | return $current; | |
198 | } | |
199 | } | |
200 |