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