[go: up one dir, main page]

Menu

[r2]: / trunk / lib / lib.tab.php  Maximize  Restore  History

Download this file

267 lines (227 with data), 7.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?php defined("IN_DOCEBO") or die('Direct access is forbidden.');
/* ======================================================================== \
| DOCEBO - The E-Learning Suite |
| |
| Copyright (c) 2008 (Docebo) |
| http://www.docebo.com |
| License http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt |
\ ======================================================================== */
/**
* Define class TabView
* @package admin-library
* @subpackage interaction
* @author Emanuele Sandri (esandri@tiscali.it)
* @version $Id: lib.tab.php 113 2006-03-08 18:08:42Z ema $
**/
/*
* NOTE: Require style_tabview.css
*/
/**
* The class TabItem describe an element of TabView
**/
class TabElem {
/** @var string $id the id of the tab element */
var $id;
/** @var bool $active state of the tab active=TRUE not active=FALSE */
var $active = FALSE;
/** return the name of the data used to store status
* @return string the name of the data used to store status
**/
function _getStateId() { return 'tabelem_'.$this->id.'_status'; }
/** Activate the TabElem */
function activate() { $this->active = TRUE; }
/** Deactivate the TabElem */
function deactivate() { $this->active = FALSE; }
/** Return the active state of the tab
* @return bool active state of the tab
**/
function isActive() { return $this->active; }
/** if the tab element is visible
* @return TRUE if the tab element is visible, FALSE otherwise
**/
function isVisible() { return FALSE; }
/** This funciton return HTML code to print out tab clickable label.
* @return HTML code for tab label UI or FALSE
**/
function printLabel() { return FALSE; }
/** This function extract from input (POST) the state of the tab
* @param array &$data input data (POST)
* @param array &$extra_data extra input data
**/
function parseInput( &$data, &$extra_data ) {
// $extra_data are ingored in this context
//$flip = array_flip($data);
if( isset( $data[$this->_getStateId()] ) ) {
$this->activate();
}
}
/** Return the state array of the TabView
* @return array state array of the TabView
**/
function getState() {
return NULL;
}
}
class TabElemDefault extends TabElem {
/** @var string $label */
var $label;
/** @var string $imgsrc */
var $imgsrc = FALSE;
/** @var string $className */
var $className = FALSE;
/** Constructor
* @param string $id
* @param string $label
* @param string $imgsrc
* @param string $className
**/
function TabElemDefault( $id, $label, $imgsrc = FALSE, $className = FALSE) {
$this->id = $id;
$this->label = $label;
$this->imgsrc = $imgsrc;
}
function isVisible() { return TRUE; }
function printLabel() {
$lout = '<li class="';
if( $this->isActive() )
$lout .= 'TabElemDefault_active';
else
$lout .= 'TabElemDefault_inactive';
if( $this->className !== FALSE )
$lout .= ' '.$this->className.'">';
else
$lout .= '">';
/*if( $this->imgsrc !== FALSE ) {
$lout .= '<img src="'.$this->imgsrc.'" alt="'
.$this->label.'" title="'
.$this->label.( $this->isActive() ? ' '. Lang::t('_ACTIVE_TAB', 'standard') : '' ).'" />';
}*/
$lout .= '<div><input type="submit" value="'
.$this->label.'" name="'
.$this->_getStateId().'" class="TabView_hotspot" />'
.'</div></li>';
//$lout .= $this->label.'</div>';
return $lout;
}
}
/**
* The class TabView represent a tabbed UI
**/
class TabView {
/** @var string $id the id of the TabView */
var $id;
/** @var array $arrTab array of tab elements*/
var $arrTab = array();
/** @var int $activeId id of the active tab in the array */
var $activeId = NULL;
/** @var string $url for post tab click requests */
var $post_url = FALSE;
var $method = 'post';
/** return the name of the data used to store status
* @return string the name of the data used to store status
**/
function _getStateId() { return 'tabview_'.$this->id.'_status'; }
/** Constructor
* @param string $id the unique id of the TabView object
**/
function TabView( $id, $post_url ) {
$this->id = $id;
$this->post_url = $post_url;
}
/** This function add a tab to list of managed tab
* @param TabElem $tab tab element to add
**/
function addTab( $tab ) {
$this->arrTab[$tab->id] = $tab;
}
/** Set the active tab.
* Set all other tabs to inactive
* @param $tabId the id of the tab to acivate
**/
function setActiveTab( $tabId ) {
while( ($key = key($this->arrTab)) != "" ) {
if( $key == $tabId ) {
$this->activeId = $tabId;
$this->arrTab[$key]->activate();
} else
$this->arrTab[$key]->deactivate();
next( $this->arrTab );
}
reset( $this->arrTab );
}
/** Get the active tab element.
* @return string the id of the active tab
**/
function getActiveTab() {
return $this->activeId;
}
/** This function extract from input (POST) the state of the tab
* @param array &$data input data (POST)
* @param array &$extra_data extra input data (SESSION)
**/
function parseInput( &$data, &$extra_data ) {
// $extra_data are ingored in this context
while( ($key = key($this->arrTab)) != "" ) {
$this->arrTab[$key]->parseInput( $data, $extra_data );
if( $this->arrTab[$key]->isActive() )
$this->activeId = $key;
next( $this->arrTab );
}
reset( $this->arrTab );
if( $this->activeId === NULL ) {
if( isset( $data[$this->_getStateId()] ) ) {
$this->setActiveTab( $data[$this->_getStateId()] );
} elseif ( isset( $extra_data[$this->_getStateId()] ) ) {
$this->setActiveTab( $extra_data[$this->_getStateId()] );
}
}
}
/** Return the state array of the TabView
* @return array state array of the TabView
**/
function getState() {
return array( $this->_getStateId() => $this->getActiveTab() );
}
/* ********************************** PRINT OUT FUNCTIONS ************************/
/** This function return a string with start output for print
* tabview and related content
* @return string the output of the TabView
**/
function printTabView_Begin( $url_param = "", $print_form = TRUE ) {
$tvout = '<div class="TabView_container">';
//open form
if($print_form)
$tvout .= '<form action="'.$this->post_url.( $url_param != "" ? '&amp;'.$url_param : '' ).'" method="'.$this->method.'">'
.'<input type="hidden" id="authentic_request_tv" name="authentic_request" value="'.Util::getSignature().'" />';
// print tab
$tvout .= '<ul class="TabView_tabspace">';
while(($tab = current($this->arrTab)) !== FALSE) {
$tvout .= $tab->printLabel();
next( $this->arrTab );
}
reset($this->arrTab);
$tvout .= '</ul>';
// close form
if($print_form)
$tvout .= '</form>';
$tvout .= '<div class="TabView_content"><br />'."\n";
return $tvout;
}
/** This function return a string with all output for print
* tabview and related content
* @param stirng $content the content of the tab
* @return string the output of the TabView
**/
function printTabView( $content ) {
return $this->printTabView_Begin().$content.$this->printTabView_End();
}
/** This function return a string with end output for print
* tabview and related content
* @return string the output of the TabView
**/
function printTabView_End( ) {
return "</div>\n"
."</div>\n";
}
}
?>