Merge pull request #1652 from vivekarora/CRM-13368
[civicrm-core.git] / CRM / Contribute / Form / ContributionPage / TabHeader.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
232624b1 4 | CiviCRM version 4.4 |
6a488035
TO
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 */
39class CRM_Contribute_Form_ContributionPage_TabHeader {
40 static function build(&$form) {
41 $tabs = $form->get('tabHeader');
42 if (!$tabs || !CRM_Utils_Array::value('reset', $_GET)) {
43 $tabs = self::process($form);
44 $form->set('tabHeader', $tabs);
45 }
46 $form->assign_by_ref('tabHeader', $tabs);
47 $form->assign('selectedTab', self::getCurrentTab($tabs));
48 return $tabs;
49 }
50
51 static function process(&$form) {
52 if ($form->getVar('_id') <= 0) {
53 return NULL;
54 }
55
56 $tabs = array(
57 'settings' => array('title' => ts('Title'),
58 'link' => NULL,
59 'valid' => FALSE,
60 'active' => FALSE,
61 'current' => FALSE,
62 ),
63 'amount' => array('title' => ts('Amounts'),
64 'link' => NULL,
65 'valid' => FALSE,
66 'active' => FALSE,
67 'current' => FALSE,
68 ),
69 'membership' => array('title' => ts('Memberships'),
70 'link' => NULL,
71 'valid' => FALSE,
72 'active' => FALSE,
73 'current' => FALSE,
74 ),
75 'thankyou' => array('title' => ts('Receipt'),
76 'link' => NULL,
77 'valid' => FALSE,
78 'active' => FALSE,
79 'current' => FALSE,
80 ),
81 'friend' => array('title' => ts('Tell a Friend'),
82 'link' => NULL,
83 'valid' => FALSE,
84 'active' => FALSE,
85 'current' => FALSE,
86 ),
87 'custom' => array('title' => ts('Profiles'),
88 'link' => NULL,
89 'valid' => FALSE,
90 'active' => FALSE,
91 'current' => FALSE,
92 ),
93 'premium' => array('title' => ts('Premiums'),
94 'link' => NULL,
95 'valid' => FALSE,
96 'active' => FALSE,
97 'current' => FALSE,
98 ),
99 'widget' => array('title' => ts('Widgets'),
100 'link' => NULL,
101 'valid' => FALSE,
102 'active' => FALSE,
103 'current' => FALSE,
104 ),
105 'pcp' => array('title' => ts('Personal Campaigns'),
106 'link' => NULL,
107 'valid' => FALSE,
108 'active' => FALSE,
109 'current' => FALSE,
110 ),
111 );
112
113 $contribPageId = $form->getVar('_id');
114 $fullName = $form->getVar('_name');
115 $className = CRM_Utils_String::getClassName($fullName);
116
117 // Hack for special cases.
118 switch ($className) {
119 case 'Contribute':
120 $attributes = $form->getVar('_attributes');
121 $class = strtolower(basename(CRM_Utils_Array::value('action', $attributes)));
122 break;
123
124 case 'MembershipBlock':
125 $class = 'membership';
126 break;
127
128 default:
129 $class = strtolower($className);
130 break;
131 }
132
133 if (array_key_exists($class, $tabs)) {
134 $tabs[$class]['current'] = TRUE;
135 $qfKey = $form->get('qfKey');
136 if ($qfKey) {
137 $tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
138 }
139 }
140
141 if ($contribPageId) {
142 $reset = CRM_Utils_Array::value('reset', $_GET) ? 'reset=1&' : '';
143
144 foreach ($tabs as $key => $value) {
145 if (!isset($tabs[$key]['qfKey'])) {
146 $tabs[$key]['qfKey'] = NULL;
147 }
148
149 $tabs[$key]['link'] =
150 CRM_Utils_System::url(
151 "civicrm/admin/contribute/{$key}",
152 "{$reset}action=update&snippet=5&id={$contribPageId}{$tabs[$key]['qfKey']}"
153 );
154 $tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE;
155 }
156 //get all section info.
157 $contriPageInfo = CRM_Contribute_BAO_ContributionPage::getSectionInfo(array($contribPageId));
158
159 foreach ($contriPageInfo[$contribPageId] as $section => $info) {
160 if (!$info) {
161 $tabs[$section]['valid'] = FALSE;
162 }
163 }
164 }
165 return $tabs;
166 }
167
168 static function reset(&$form) {
169 $tabs = self::process($form);
170 $form->set('tabHeader', $tabs);
171 }
172
173 static function getCurrentTab($tabs) {
174 static $current = FALSE;
175
176 if ($current) {
177 return $current;
178 }
179
180 if (is_array($tabs)) {
181 foreach ($tabs as $subPage => $pageVal) {
182 if ($pageVal['current'] === TRUE) {
183 $current = $subPage;
184 break;
185 }
186 }
187 }
188
189 $current = $current ? $current : 'settings';
190 return $current;
191 }
192}
193