Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * Helper class to build navigation links | |
38 | */ | |
39 | class CRM_Contribute_Form_ContributionPage_TabHeader { | |
186c9c17 | 40 | /** |
c490a46a | 41 | * @param CRM_Core_Form $form |
186c9c17 EM |
42 | * |
43 | * @return array | |
44 | */ | |
00be9182 | 45 | public static function build(&$form) { |
6a488035 | 46 | $tabs = $form->get('tabHeader'); |
8cc574cf | 47 | if (!$tabs || empty($_GET['reset'])) { |
6a488035 TO |
48 | $tabs = self::process($form); |
49 | $form->set('tabHeader', $tabs); | |
50 | } | |
51 | $form->assign_by_ref('tabHeader', $tabs); | |
4165b7e5 | 52 | CRM_Core_Resources::singleton() |
96ed17aa | 53 | ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header') |
874c9be7 | 54 | ->addSetting(array( |
353ffa53 TO |
55 | 'tabSettings' => array( |
56 | 'active' => self::getCurrentTab($tabs), | |
389bcebf | 57 | ), |
353ffa53 | 58 | )); |
6a488035 TO |
59 | return $tabs; |
60 | } | |
61 | ||
186c9c17 | 62 | /** |
c490a46a | 63 | * @param CRM_Core_Form $form |
186c9c17 EM |
64 | * |
65 | * @return array | |
66 | */ | |
00be9182 | 67 | public static function process(&$form) { |
6a488035 TO |
68 | if ($form->getVar('_id') <= 0) { |
69 | return NULL; | |
70 | } | |
71 | ||
72 | $tabs = array( | |
874c9be7 | 73 | 'settings' => array( |
353ffa53 | 74 | 'title' => ts('Title'), |
6a488035 TO |
75 | 'link' => NULL, |
76 | 'valid' => FALSE, | |
77 | 'active' => FALSE, | |
78 | 'current' => FALSE, | |
79 | ), | |
874c9be7 | 80 | 'amount' => array( |
353ffa53 | 81 | 'title' => ts('Amounts'), |
6a488035 TO |
82 | 'link' => NULL, |
83 | 'valid' => FALSE, | |
84 | 'active' => FALSE, | |
85 | 'current' => FALSE, | |
86 | ), | |
874c9be7 | 87 | 'membership' => array( |
353ffa53 | 88 | 'title' => ts('Memberships'), |
6a488035 TO |
89 | 'link' => NULL, |
90 | 'valid' => FALSE, | |
91 | 'active' => FALSE, | |
92 | 'current' => FALSE, | |
93 | ), | |
874c9be7 | 94 | 'thankyou' => array( |
353ffa53 | 95 | 'title' => ts('Receipt'), |
6a488035 TO |
96 | 'link' => NULL, |
97 | 'valid' => FALSE, | |
98 | 'active' => FALSE, | |
99 | 'current' => FALSE, | |
100 | ), | |
874c9be7 | 101 | 'friend' => array( |
353ffa53 | 102 | 'title' => ts('Tell a Friend'), |
6a488035 TO |
103 | 'link' => NULL, |
104 | 'valid' => FALSE, | |
105 | 'active' => FALSE, | |
106 | 'current' => FALSE, | |
107 | ), | |
874c9be7 | 108 | 'custom' => array( |
353ffa53 | 109 | 'title' => ts('Profiles'), |
6a488035 TO |
110 | 'link' => NULL, |
111 | 'valid' => FALSE, | |
112 | 'active' => FALSE, | |
113 | 'current' => FALSE, | |
114 | ), | |
874c9be7 | 115 | 'premium' => array( |
353ffa53 | 116 | 'title' => ts('Premiums'), |
6a488035 TO |
117 | 'link' => NULL, |
118 | 'valid' => FALSE, | |
119 | 'active' => FALSE, | |
120 | 'current' => FALSE, | |
121 | ), | |
874c9be7 | 122 | 'widget' => array( |
353ffa53 | 123 | 'title' => ts('Widgets'), |
6a488035 TO |
124 | 'link' => NULL, |
125 | 'valid' => FALSE, | |
126 | 'active' => FALSE, | |
127 | 'current' => FALSE, | |
128 | ), | |
874c9be7 | 129 | 'pcp' => array( |
353ffa53 | 130 | 'title' => ts('Personal Campaigns'), |
6a488035 TO |
131 | 'link' => NULL, |
132 | 'valid' => FALSE, | |
133 | 'active' => FALSE, | |
134 | 'current' => FALSE, | |
135 | ), | |
136 | ); | |
137 | ||
138 | $contribPageId = $form->getVar('_id'); | |
353ffa53 TO |
139 | $fullName = $form->getVar('_name'); |
140 | $className = CRM_Utils_String::getClassName($fullName); | |
6a488035 TO |
141 | |
142 | // Hack for special cases. | |
143 | switch ($className) { | |
144 | case 'Contribute': | |
145 | $attributes = $form->getVar('_attributes'); | |
146 | $class = strtolower(basename(CRM_Utils_Array::value('action', $attributes))); | |
147 | break; | |
148 | ||
149 | case 'MembershipBlock': | |
150 | $class = 'membership'; | |
151 | break; | |
152 | ||
153 | default: | |
154 | $class = strtolower($className); | |
155 | break; | |
156 | } | |
157 | ||
158 | if (array_key_exists($class, $tabs)) { | |
159 | $tabs[$class]['current'] = TRUE; | |
160 | $qfKey = $form->get('qfKey'); | |
161 | if ($qfKey) { | |
162 | $tabs[$class]['qfKey'] = "&qfKey={$qfKey}"; | |
163 | } | |
164 | } | |
165 | ||
166 | if ($contribPageId) { | |
0d8afee2 | 167 | $reset = !empty($_GET['reset']) ? 'reset=1&' : ''; |
6a488035 TO |
168 | |
169 | foreach ($tabs as $key => $value) { | |
170 | if (!isset($tabs[$key]['qfKey'])) { | |
171 | $tabs[$key]['qfKey'] = NULL; | |
172 | } | |
173 | ||
389bcebf | 174 | $tabs[$key]['link'] = CRM_Utils_System::url( |
6a488035 | 175 | "civicrm/admin/contribute/{$key}", |
353ffa53 TO |
176 | "{$reset}action=update&id={$contribPageId}{$tabs[$key]['qfKey']}" |
177 | ); | |
6a488035 TO |
178 | $tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE; |
179 | } | |
180 | //get all section info. | |
181 | $contriPageInfo = CRM_Contribute_BAO_ContributionPage::getSectionInfo(array($contribPageId)); | |
182 | ||
183 | foreach ($contriPageInfo[$contribPageId] as $section => $info) { | |
184 | if (!$info) { | |
185 | $tabs[$section]['valid'] = FALSE; | |
186 | } | |
187 | } | |
188 | } | |
189 | return $tabs; | |
190 | } | |
191 | ||
186c9c17 EM |
192 | /** |
193 | * @param $form | |
194 | */ | |
00be9182 | 195 | public static function reset(&$form) { |
6a488035 TO |
196 | $tabs = self::process($form); |
197 | $form->set('tabHeader', $tabs); | |
198 | } | |
199 | ||
186c9c17 EM |
200 | /** |
201 | * @param $tabs | |
202 | * | |
203 | * @return int|string | |
204 | */ | |
00be9182 | 205 | public static function getCurrentTab($tabs) { |
6a488035 TO |
206 | static $current = FALSE; |
207 | ||
208 | if ($current) { | |
209 | return $current; | |
210 | } | |
211 | ||
212 | if (is_array($tabs)) { | |
213 | foreach ($tabs as $subPage => $pageVal) { | |
214 | if ($pageVal['current'] === TRUE) { | |
215 | $current = $subPage; | |
216 | break; | |
217 | } | |
218 | } | |
219 | } | |
220 | ||
221 | $current = $current ? $current : 'settings'; | |
222 | return $current; | |
223 | } | |
96025800 | 224 | |
6a488035 | 225 | } |