copyright and version fixes
[civicrm-core.git] / CRM / Campaign / Form / Survey / 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_Campaign_Form_Survey_TabHeader {
40
41 static function build(&$form) {
42 $tabs = $form->get('tabHeader');
8cc574cf 43 if (!$tabs || empty($_GET['reset'])) {
6a488035
TO
44 $tabs = self::process($form);
45 $form->set('tabHeader', $tabs);
46 }
47 $form->assign_by_ref('tabHeader', $tabs);
4165b7e5
CW
48 CRM_Core_Resources::singleton()
49 ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js')
50 ->addSetting(array('tabSettings' => array(
51 'active' => self::getCurrentTab($tabs),
52 )));
6a488035
TO
53 return $tabs;
54 }
55
56 static function process(&$form) {
57 if ($form->getVar('_surveyId') <= 0) {
58 return NULL;
59 }
60
61 $tabs = array(
62 'main' => array('title' => ts('Main Information'),
63 'link' => NULL,
64 'valid' => FALSE,
65 'active' => FALSE,
66 'current' => FALSE,
67 ),
68 'questions' => array('title' => ts('Questions'),
69 'link' => NULL,
70 'valid' => FALSE,
71 'active' => FALSE,
72 'current' => FALSE,
73 ),
74 'results' => array('title' => ts('Results'),
75 'link' => NULL,
76 'valid' => FALSE,
77 'active' => FALSE,
78 'current' => FALSE,
79 ),
80 );
81
82 $surveyID = $form->getVar('_surveyId');
83 $class = $form->getVar('_name');
84 $class = CRM_Utils_String::getClassName($class);
85 $class = strtolower($class);
86
87 if (array_key_exists($class, $tabs)) {
88 $tabs[$class]['current'] = TRUE;
89 $qfKey = $form->get('qfKey');
90 if ($qfKey) {
91 $tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
92 }
93 }
94
95 if ($surveyID) {
0d8afee2 96 $reset = !empty($_GET['reset']) ? 'reset=1&' : '';
6a488035
TO
97
98 foreach ($tabs as $key => $value) {
99 if (!isset($tabs[$key]['qfKey'])) {
100 $tabs[$key]['qfKey'] = NULL;
101 }
102
103 $tabs[$key]['link'] = CRM_Utils_System::url("civicrm/survey/configure/{$key}",
8547369d 104 "{$reset}action=update&id={$surveyID}{$tabs[$key]['qfKey']}"
6a488035
TO
105 );
106 $tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE;
107 }
108 }
109 return $tabs;
110 }
111
112 static function reset(&$form) {
113 $tabs = self::process($form);
114 $form->set('tabHeader', $tabs);
115 }
116
117 static function getCurrentTab($tabs) {
118 static $current = FALSE;
119
120 if ($current) {
121 return $current;
122 }
123
124 if (is_array($tabs)) {
125 foreach ($tabs as $subPage => $pageVal) {
126 if ($pageVal['current'] === TRUE) {
127 $current = $subPage;
128 break;
129 }
130 }
131 }
132
133 $current = $current ? $current : 'main';
134 return $current;
135 }
136
137 static function getNextTab(&$form) {
138 static $next = FALSE;
139 if ($next)
140 return $next;
141
142 $tabs = $form->get('tabHeader');
143 if (is_array($tabs)) {
144 $current = false;
145 foreach ($tabs as $subPage => $pageVal) {
146 if ($current) {
147 $next = $subPage;
148 break;
149 }
150 if ($pageVal['current'] === TRUE) {
151 $current = $subPage;
152 }
153 }
154 }
155
156 $next = $next ? $next : 'main';
157 return $next;
158 }
159}