Commit | Line | Data |
---|---|---|
6a488035 TO |
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_Campaign_Form_Survey_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('_surveyId') <= 0) { | |
55 | return NULL; | |
56 | } | |
57 | ||
58 | $tabs = array( | |
59 | 'main' => array('title' => ts('Main Information'), | |
60 | 'link' => NULL, | |
61 | 'valid' => FALSE, | |
62 | 'active' => FALSE, | |
63 | 'current' => FALSE, | |
64 | ), | |
65 | 'questions' => array('title' => ts('Questions'), | |
66 | 'link' => NULL, | |
67 | 'valid' => FALSE, | |
68 | 'active' => FALSE, | |
69 | 'current' => FALSE, | |
70 | ), | |
71 | 'results' => array('title' => ts('Results'), | |
72 | 'link' => NULL, | |
73 | 'valid' => FALSE, | |
74 | 'active' => FALSE, | |
75 | 'current' => FALSE, | |
76 | ), | |
77 | ); | |
78 | ||
79 | $surveyID = $form->getVar('_surveyId'); | |
80 | $class = $form->getVar('_name'); | |
81 | $class = CRM_Utils_String::getClassName($class); | |
82 | $class = strtolower($class); | |
83 | ||
84 | if (array_key_exists($class, $tabs)) { | |
85 | $tabs[$class]['current'] = TRUE; | |
86 | $qfKey = $form->get('qfKey'); | |
87 | if ($qfKey) { | |
88 | $tabs[$class]['qfKey'] = "&qfKey={$qfKey}"; | |
89 | } | |
90 | } | |
91 | ||
92 | if ($surveyID) { | |
93 | $reset = CRM_Utils_Array::value('reset', $_GET) ? 'reset=1&' : ''; | |
94 | ||
95 | foreach ($tabs as $key => $value) { | |
96 | if (!isset($tabs[$key]['qfKey'])) { | |
97 | $tabs[$key]['qfKey'] = NULL; | |
98 | } | |
99 | ||
100 | $tabs[$key]['link'] = CRM_Utils_System::url("civicrm/survey/configure/{$key}", | |
101 | "{$reset}action=update&snippet=5&id={$surveyID}{$tabs[$key]['qfKey']}" | |
102 | ); | |
103 | $tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE; | |
104 | } | |
105 | } | |
106 | return $tabs; | |
107 | } | |
108 | ||
109 | static function reset(&$form) { | |
110 | $tabs = self::process($form); | |
111 | $form->set('tabHeader', $tabs); | |
112 | } | |
113 | ||
114 | static function getCurrentTab($tabs) { | |
115 | static $current = FALSE; | |
116 | ||
117 | if ($current) { | |
118 | return $current; | |
119 | } | |
120 | ||
121 | if (is_array($tabs)) { | |
122 | foreach ($tabs as $subPage => $pageVal) { | |
123 | if ($pageVal['current'] === TRUE) { | |
124 | $current = $subPage; | |
125 | break; | |
126 | } | |
127 | } | |
128 | } | |
129 | ||
130 | $current = $current ? $current : 'main'; | |
131 | return $current; | |
132 | } | |
133 | ||
134 | static function getNextTab(&$form) { | |
135 | static $next = FALSE; | |
136 | if ($next) | |
137 | return $next; | |
138 | ||
139 | $tabs = $form->get('tabHeader'); | |
140 | if (is_array($tabs)) { | |
141 | $current = false; | |
142 | foreach ($tabs as $subPage => $pageVal) { | |
143 | if ($current) { | |
144 | $next = $subPage; | |
145 | break; | |
146 | } | |
147 | if ($pageVal['current'] === TRUE) { | |
148 | $current = $subPage; | |
149 | } | |
150 | } | |
151 | } | |
152 | ||
153 | $next = $next ? $next : 'main'; | |
154 | return $next; | |
155 | } | |
156 | } |