Import from SVN (r45945, r596)
[civicrm-core.git] / CRM / Event / Form / ManageEvent / TabHeader.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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);
48 $selectedTab = self::getCurrentTab($tabs);
49 $form->assign_by_ref('selectedTab', $selectedTab);
50 return $tabs;
51 }
52
53 static function process(&$form) {
54 if ($form->getVar('_id') <= 0) {
55 return NULL;
56 }
57
58 $tabs = array(
59 'settings' => array('title' => ts('Info and Settings'),
60 'link' => NULL,
61 'valid' => FALSE,
62 'active' => FALSE,
63 'current' => FALSE,
64 ),
65 'location' => array('title' => ts('Event Location'),
66 'link' => NULL,
67 'valid' => FALSE,
68 'active' => FALSE,
69 'current' => FALSE,
70 ),
71 'fee' => array('title' => ts('Fees'),
72 'link' => NULL,
73 'valid' => FALSE,
74 'active' => FALSE,
75 'current' => FALSE,
76 ),
77 'registration' => array('title' => ts('Online Registration'),
78 'link' => NULL,
79 'valid' => FALSE,
80 'active' => FALSE,
81 'current' => FALSE,
82 ),
83 'reminder' => array('title' => ts('Schedule Reminders'),
84 'link' => NULL,
85 'valid' => FALSE,
86 'active' => FALSE,
87 'current' => FALSE,
88 ),
89 'conference' => array('title' => ts('Conference Slots'),
90 'link' => NULL,
91 'valid' => FALSE,
92 'active' => FALSE,
93 'current' => FALSE,
94 ),
95 'friend' => array('title' => ts('Tell a Friend'),
96 'link' => NULL,
97 'valid' => FALSE,
98 'active' => FALSE,
99 'current' => FALSE,
100 ),
101 'pcp' => array('title' => ts('Personal Campaigns'),
102 'link' => NULL,
103 'valid' => FALSE,
104 'active' => FALSE,
105 'current' => FALSE,
106 )
107 );
108
109 // check if we're in shopping cart mode for events
110 $enableCart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME,
111 'enable_cart'
112 );
113
114 if (!$enableCart) {
115 unset($tabs['conference']);
116 }
117
118 $eventID = $form->getVar('_id');
119
120 $fullName = $form->getVar('_name');
121 $className = CRM_Utils_String::getClassName($fullName);
122 $new = '';
123 // hack for special cases.
124 switch ($className) {
125 case 'Event':
126 $attributes = $form->getVar('_attributes');
127 $class = strtolower(basename(CRM_Utils_Array::value('action', $attributes)));
128 break;
129
130 case 'ScheduleReminders':
131 $class = 'reminder';
132 $new = CRM_Utils_Array::value('new', $_GET) ? '&new=1' : '';
133 break;
134
135 default:
136 $class = strtolower($className);
137 break;
138 }
139
140 if (array_key_exists($class, $tabs)) {
141 $tabs[$class]['current'] = TRUE;
142 $qfKey = $form->get('qfKey');
143 if ($qfKey) {
144 $tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
145 }
146 }
147
148 if ($eventID) {
149 $reset = CRM_Utils_Array::value('reset', $_GET) ? 'reset=1&' : '';
150
151 foreach ($tabs as $key => $value) {
152 if (!isset($tabs[$key]['qfKey'])) {
153 $tabs[$key]['qfKey'] = NULL;
154 }
155
156 $tabs[$key]['link'] = CRM_Utils_System::url("civicrm/event/manage/{$key}",
157 "{$reset}action=update&snippet=5&id={$eventID}&component=event{$new}{$tabs[$key]['qfKey']}"
158 );
159 $tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE;
160 }
161
162 // retrieve info about paid event, tell a friend and online reg
163 $sql = "
164 SELECT e.is_online_registration, e.is_monetary, taf.is_active
165 FROM civicrm_event e
166 LEFT JOIN civicrm_tell_friend taf ON ( taf.entity_table = 'civicrm_event' AND taf.entity_id = e.id )
167 WHERE e.id = %1
168 ";
169 $params = array(1 => array($eventID, 'Integer'));
170 $dao = CRM_Core_DAO::executeQuery($sql, $params);
171 if (!$dao->fetch()) {
172 CRM_Core_Error::fatal();
173 }
174
175 if (!$dao->is_online_registration) {
176 $tabs['registration']['valid'] = FALSE;
177 }
178
179 if (!$dao->is_monetary) {
180 $tabs['fee']['valid'] = FALSE;
181 }
182
183 if (!$dao->is_active) {
184 $tabs['friend']['valid'] = FALSE;
185 }
186
187 //calculate if the reminder has been configured for this event
188 }
189 return $tabs;
190 }
191
192 static function reset(&$form) {
193 $tabs = self::process($form);
194 $form->set('tabHeader', $tabs);
195 }
196
197 static function getCurrentTab($tabs) {
198 static $current = FALSE;
199
200 if ($current) {
201 return $current;
202 }
203
204 if (is_array($tabs)) {
205 foreach ($tabs as $subPage => $pageVal) {
206 if ($pageVal['current'] === TRUE) {
207 $current = $subPage;
208 break;
209 }
210 }
211 }
212
213 $current = $current ? $current : 'settings';
214 return $current;
215 }
216 }
217