Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
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 | */ | |
6a488035 TO |
45 | static function build(&$form) { |
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') |
4165b7e5 CW |
54 | ->addSetting(array('tabSettings' => array( |
55 | 'active' => self::getCurrentTab($tabs), | |
56 | ))); | |
6a488035 TO |
57 | return $tabs; |
58 | } | |
59 | ||
186c9c17 | 60 | /** |
c490a46a | 61 | * @param CRM_Core_Form $form |
186c9c17 EM |
62 | * |
63 | * @return array | |
64 | */ | |
6a488035 TO |
65 | static function process(&$form) { |
66 | if ($form->getVar('_id') <= 0) { | |
67 | return NULL; | |
68 | } | |
69 | ||
70 | $tabs = array( | |
71 | 'settings' => array('title' => ts('Title'), | |
72 | 'link' => NULL, | |
73 | 'valid' => FALSE, | |
74 | 'active' => FALSE, | |
75 | 'current' => FALSE, | |
76 | ), | |
77 | 'amount' => array('title' => ts('Amounts'), | |
78 | 'link' => NULL, | |
79 | 'valid' => FALSE, | |
80 | 'active' => FALSE, | |
81 | 'current' => FALSE, | |
82 | ), | |
83 | 'membership' => array('title' => ts('Memberships'), | |
84 | 'link' => NULL, | |
85 | 'valid' => FALSE, | |
86 | 'active' => FALSE, | |
87 | 'current' => FALSE, | |
88 | ), | |
89 | 'thankyou' => array('title' => ts('Receipt'), | |
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 | 'custom' => array('title' => ts('Profiles'), | |
102 | 'link' => NULL, | |
103 | 'valid' => FALSE, | |
104 | 'active' => FALSE, | |
105 | 'current' => FALSE, | |
106 | ), | |
107 | 'premium' => array('title' => ts('Premiums'), | |
108 | 'link' => NULL, | |
109 | 'valid' => FALSE, | |
110 | 'active' => FALSE, | |
111 | 'current' => FALSE, | |
112 | ), | |
113 | 'widget' => array('title' => ts('Widgets'), | |
114 | 'link' => NULL, | |
115 | 'valid' => FALSE, | |
116 | 'active' => FALSE, | |
117 | 'current' => FALSE, | |
118 | ), | |
119 | 'pcp' => array('title' => ts('Personal Campaigns'), | |
120 | 'link' => NULL, | |
121 | 'valid' => FALSE, | |
122 | 'active' => FALSE, | |
123 | 'current' => FALSE, | |
124 | ), | |
125 | ); | |
126 | ||
127 | $contribPageId = $form->getVar('_id'); | |
128 | $fullName = $form->getVar('_name'); | |
129 | $className = CRM_Utils_String::getClassName($fullName); | |
130 | ||
131 | // Hack for special cases. | |
132 | switch ($className) { | |
133 | case 'Contribute': | |
134 | $attributes = $form->getVar('_attributes'); | |
135 | $class = strtolower(basename(CRM_Utils_Array::value('action', $attributes))); | |
136 | break; | |
137 | ||
138 | case 'MembershipBlock': | |
139 | $class = 'membership'; | |
140 | break; | |
141 | ||
142 | default: | |
143 | $class = strtolower($className); | |
144 | break; | |
145 | } | |
146 | ||
147 | if (array_key_exists($class, $tabs)) { | |
148 | $tabs[$class]['current'] = TRUE; | |
149 | $qfKey = $form->get('qfKey'); | |
150 | if ($qfKey) { | |
151 | $tabs[$class]['qfKey'] = "&qfKey={$qfKey}"; | |
152 | } | |
153 | } | |
154 | ||
155 | if ($contribPageId) { | |
0d8afee2 | 156 | $reset = !empty($_GET['reset']) ? 'reset=1&' : ''; |
6a488035 TO |
157 | |
158 | foreach ($tabs as $key => $value) { | |
159 | if (!isset($tabs[$key]['qfKey'])) { | |
160 | $tabs[$key]['qfKey'] = NULL; | |
161 | } | |
162 | ||
163 | $tabs[$key]['link'] = | |
164 | CRM_Utils_System::url( | |
165 | "civicrm/admin/contribute/{$key}", | |
8547369d | 166 | "{$reset}action=update&id={$contribPageId}{$tabs[$key]['qfKey']}" |
6a488035 TO |
167 | ); |
168 | $tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE; | |
169 | } | |
170 | //get all section info. | |
171 | $contriPageInfo = CRM_Contribute_BAO_ContributionPage::getSectionInfo(array($contribPageId)); | |
172 | ||
173 | foreach ($contriPageInfo[$contribPageId] as $section => $info) { | |
174 | if (!$info) { | |
175 | $tabs[$section]['valid'] = FALSE; | |
176 | } | |
177 | } | |
178 | } | |
179 | return $tabs; | |
180 | } | |
181 | ||
186c9c17 EM |
182 | /** |
183 | * @param $form | |
184 | */ | |
6a488035 TO |
185 | static function reset(&$form) { |
186 | $tabs = self::process($form); | |
187 | $form->set('tabHeader', $tabs); | |
188 | } | |
189 | ||
186c9c17 EM |
190 | /** |
191 | * @param $tabs | |
192 | * | |
193 | * @return int|string | |
194 | */ | |
6a488035 TO |
195 | static function getCurrentTab($tabs) { |
196 | static $current = FALSE; | |
197 | ||
198 | if ($current) { | |
199 | return $current; | |
200 | } | |
201 | ||
202 | if (is_array($tabs)) { | |
203 | foreach ($tabs as $subPage => $pageVal) { | |
204 | if ($pageVal['current'] === TRUE) { | |
205 | $current = $subPage; | |
206 | break; | |
207 | } | |
208 | } | |
209 | } | |
210 | ||
211 | $current = $current ? $current : 'settings'; | |
212 | return $current; | |
213 | } | |
214 | } | |
215 |