noalyss Version-9
output_html_tab.class.php
Go to the documentation of this file.
1<?php
2
3
4/*
5 * Copyright (C) 2018 Dany De Bontridder <dany@alchimerys.be>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22
23/**
24 * @file
25 * @brief Display the tabs
26 *
27 */
28
29/**
30 * @brief Display the tabs
31 * @see Html_Tab
32 *
33 */
34
36{
37
38 private $a_tabs; //!< array of html tabs
39 private $class_tab; //!< for normal tab
40 private $class_tab_selected; //!< for class_tab_selected
41 private $mode; //!< mode default tabs
42 private $class_tab_main; //! CSS class for the UL tag
43 private $class_anchor; //! CSS class for the A tag (anchor) default empty
44 private $class_div; //! CSS class for the DIV containing the UL default empty
45 private $class_content_div; //! CSS class for the DIV with content, default empty
46 private $class_comment ; //! CSS class for the comment default "tabs"
47
48 /**
49 *@example html_tab.test.php
50 */
51 function __construct()
52 {
53 $this->a_tabs=[];
54 $this->class_tab="tabs";
55 $this->class_tab_main="tabs";
56 $this->class_tab_selected="tabs_selected";
57 $this->set_mode("tab");
58 $this->class_anchor="";
59 $this->class_div="";
60 $this->class_content_div="";
61 $this->class_comment="tabs";
62 }
63 /**
64 * @brief CSS class for the comment default "tabs"
65 * @return type
66 */
67 public function get_class_comment()
68 {
70 }
71 /**
72 * @brief CSS class for the comment default "tabs"
73 * @return type
74 */
75
77 {
78 $this->class_comment=$class_comment;
79 return $this;
80 }
81
82 /**
83 * @brief CSS class for the DIV with content (default empty)
84 */
85 public function get_class_content_div()
86 {
88 }
89 /**
90 *@brief CSS class for the DIV with content (default empty)
91 *
92 * @param string $class_content_div
93 */
95 {
96 $this->class_content_div=$class_content_div;
97 return $this;
98 }
99
100 /**
101 * @brief CSS class for the DIV containing the UL
102 * @return string
103 */
104 public function get_class_div()
105 {
106 return $this->class_div;
107 }
108
109 /**
110 * @brief CSS class for the DIV containing the UL
111 * @return string
112 */
113
114 public function set_class_div($class_div)
115 {
116 $this->class_div=$class_div;
117 return $this;
118 }
119
120 /**
121 * @brief CSS class for the A tag (anchor)
122 * @return type
123 */
124 public function get_class_anchor()
125 {
126 return $this->class_anchor;
127 }
128 /**
129 * @brief CSS class for the A tag (anchor)
130 * @param type $anchor_class
131 */
132 public function set_class_anchor($anchor_class)
133 {
134 $this->class_anchor=$anchor_class;
135 $this;
136 }
137
138 /**
139 * @brief get the CSS class for the UL element
140 * @return type
141 */
142 public function get_class_tab_main()
143 {
145 }
146
147 /**
148 * @brief set the CSS class for the UL element
149 * @return this
150 */
151
153 {
154 $this->class_tab_main=$class_tab_main;
155 return $this;
156 }
157
158 /**
159 * @brief get the mode , possible value are row or tabs , with mode = row , the
160 * class_content_div is set to row
161 * @return mixed
162 */
163 public function get_mode()
164 {
165 return $this->mode;
166 }
167
168 /**
169 * @brief set the mode , possible values : row , tabs or accordeon
170 * @param string $mode possible values : row , tabs or accordeon
171 */
172 public function set_mode($mode)
173 {
174 if (! in_array($mode,['tab','row','accordeon'] )) {
175 throw new Exception(_("OUTPUTHTML070 Mode invalide"));
176 }
177 $this->mode = $mode;
178 if ($mode == "row") {
179 $this->set_class_tab_selected("tab_row_selected");
180 $this->set_class_tab("tab_row");
181
182 }elseif ( $mode == "tab") {
183 $this->set_class_tab_selected("tabs_selected");
184 $this->set_class_tab("tabs");
185
186 }elseif ($mode == "accordeon") {
187 $this->set_class_tab_selected("");
188 $this->set_class_tab("tab_row");
189 } else {
190 throw new \Exception("OH186.unknow mode [$mode]");
191 }
192 return $this;
193 }
194
195 /**
196 * Add Html_Tab
197 * @param Html_Tab $p_html_tab
198 */
199 function add(Html_Tab $p_html_tab)
200 {
201 $this->a_tabs[]=clone $p_html_tab;
202
203 }
204
205 /**
206 * get the CSS class of tabs
207 * @return mixed
208 */
209 public function get_class_tab()
210 {
211 return $this->class_tab;
212 }
213
214 /**
215 * set the CSS class of tabs, default is tabs
216 * @param mixed $class_tab
217 */
218 public function set_class_tab($class_tab)
219 {
220 $this->class_tab = $class_tab;
221 return $this;
222 }
223
224 /**
225 * get the CSS class of tabs_selected
226 * @return mixed
227 */
228 public function get_class_tab_selected()
229 {
231 }
232
233 /**
234 * set the CSS class of tabs, default is tabs_selected
235 * @param mixed $class_tab_selected
236 */
238 {
239 $this->class_tab_selected = $class_tab_selected;
240 return $this;
241 }
242
243 /**
244 * Build the javascript to change the class name of the selected tab, hide other div and show the selected one
245 * @param string $p_not_hidden id of the showed tab
246 * @return javascript string
247 */
248 function build_js ($p_not_hidden)
249 {
250 $r="";
251 $nb=count($this->a_tabs);
252 $mode=$this->get_mode();
253 if ($mode=="accordeon") {
254 $r .= \Icon_Action::toggle_hide(uniqid(), sprintf("div%s", $p_not_hidden));
255
256 return $r;
257 }
258 for ($i =0 ; $i < $nb;$i++)
259 {
260 if ($mode=="tab") {
261
262 if ( $this->a_tabs[$i]->get_id() != $p_not_hidden) {
263 $r .= sprintf("$('div%s').hide();",$this->a_tabs[$i]->get_id() );
264 $r .= sprintf("$('tab%s').className='%s';",$this->a_tabs[$i]->get_id(),$this->class_tab );
265 } else {
266 $r .= sprintf("$('div%s').show();",$p_not_hidden );
267 $r .= sprintf("$('tab%s').className='%s';",$p_not_hidden ,$this->class_tab_selected);
268
269 }
270 } elseif ($mode=="row") {
271 if ( $this->a_tabs[$i]->get_id() != $p_not_hidden) {
272 $r .= sprintf("Effect.BlindUp('div%s',{duration : 0.7});",$this->a_tabs[$i]->get_id() );
273 $r .= sprintf("$('tab%s').className='%s';",$this->a_tabs[$i]->get_id(),$this->class_tab );
274 } else {
275 $r .= sprintf("Effect.SlideDown('div%s',{duration : 0.7});",$p_not_hidden );
276 $r .= sprintf("$('tab%s').className='%s';",$p_not_hidden ,$this->class_tab_selected);
277
278 }
279 } else {
280 throw new \Exception("OH283.unknow mode [$mode]");
281 }
282 }
283 return $r;
284 }
285
286 /**
287 * When printing row , a comment is written if not empty,
288 * @param $p_index
289 */
290 protected function print_comment($p_index) {
291 printf ('<span class="%s"> %s </span>',
292 $this->get_class_comment(),
293 $this->a_tabs[$p_index]->get_comment()
294 );
295
296 }
297 /**
298 * @brief print the html + javascript code of the tabs and the div
299 *
300 */
301 function output()
302 {
303 $nb=count($this->a_tabs);
304 if ($nb==0)
305 {
306 return;
307 }
308 printf('<div class="%s">',$this->class_div);
309 printf ( '<ul class="%s">',$this->class_tab_main);
310 $mode=$this->get_mode();
311 for ($i=0; $i<$nb; $i++)
312 {
313 printf ('<li id="tab%s" class="%s">',
314 $this->a_tabs[$i]->get_id(),$this->class_tab);
315 switch ($this->a_tabs[$i]->get_mode())
316 {
317 case 'link':
318 printf ('<a class="%s" id="%s" href="%s">',
319 $this->class_anchor,
320 $this->a_tabs[$i]->get_id(),
321 $this->a_tabs[$i]->get_link());
322 printf ('<span class="title_%s"> %s </span>',
323 $this->get_class_tab(),
324 $this->a_tabs[$i]->get_title()
325 );
326 echo '</a>';
327
328 break;
329 case 'ajax':
330 printf('<a class="%s" id="%s" onclick="%s">',
331 $this->class_anchor,
332 $this->a_tabs[$i]->get_id(),
333 $this->a_tabs[$i]->get_link());
334 printf ('<span class="title_%s"> %s </span>',
335 $this->get_class_tab(),
336 $this->a_tabs[$i]->get_title()
337 );
338
339 echo $this->a_tabs[$i]->get_title();
340 echo '</a>';
341 break;
342 case 'static':
343 // show one , hide other except for accordeon
344 $script=$this->build_js($this->a_tabs[$i]->get_id());
345 if ($mode != 'accordeon') {
346 printf('<a class="%s" onclick="%s">', $this->class_anchor,$script);
347 } else {
349 }
350
351 printf ('<span class="title_%s"> %s </span>',
352 $this->get_class_tab(),
353 $this->a_tabs[$i]->get_title()
354 );
355
356 echo '</a>';
357 $script=$this->build_js($this->a_tabs[$i]->get_id());
358
359 break;
360 default:
361 throw new Exception('OUTPUTHTMLTAB01');
362 break;
363 }
364 if ( $mode =="row" || $mode == "accordeon") {
365 $this->print_comment($i);
366 }
367 echo '</li>';
368 if ( $mode =="row" || $mode == "accordeon") {
369 $this->print_div($i);
370 }
371 }
372 echo '</ul>';
373 echo '</div>';
374
375 if ( $mode=="tab" ) {
376 for ($i=0;$i<$nb;$i++)
377 {
378 $this->print_div($i);
379 }
380
381 }
382 }
383 private function print_div($p_index)
384 {
385 $class="";
386 if ( $this->get_mode() == "row" ) {
387 $class="tab_row";
388 } elseif ( $this->get_mode() == 'accordeon') {
389 $class="";
390 }
391
392
393 printf('<div id="div%s" style="display:none;clear:both" class="%s">',
394 $this->a_tabs[$p_index]->get_id(),
395 $class);
396 echo $this->a_tabs[$p_index]->get_content();
397 echo '</div>';
398
399 }
400}
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$class
Tab Element.
static toggle_hide($p_id, $p_id_to_hide)
hide or display an element, to be used for an accordon
Display the tabs.
get_class_div()
CSS class for the DIV containing the UL.
set_class_tab($class_tab)
set the CSS class of tabs, default is tabs
add(Html_Tab $p_html_tab)
Add Html_Tab.
$class_content_div
CSS class for the DIV containing the UL default empty.
$class_tab_selected
for class_tab_selected
get_class_tab_selected()
get the CSS class of tabs_selected
get_mode()
get the mode , possible value are row or tabs , with mode = row , the class_content_div is set to row
set_class_tab_main($class_tab_main)
set the CSS class for the UL element
$class_tab
for normal tab
set_class_comment($class_comment)
CSS class for the comment default "tabs".
get_class_anchor()
CSS class for the A tag (anchor)
get_class_tab_main()
get the CSS class for the UL element
set_class_anchor($anchor_class)
CSS class for the A tag (anchor)
$mode
mode default tabs
get_class_comment()
CSS class for the comment default "tabs".
set_class_tab_selected($class_tab_selected)
set the CSS class of tabs, default is tabs_selected
$a_tabs
array of html tabs
print_comment($p_index)
When printing row , a comment is written if not empty,.
build_js($p_not_hidden)
Build the javascript to change the class name of the selected tab, hide other div and show the select...
$class_div
CSS class for the A tag (anchor) default empty.
get_class_tab()
get the CSS class of tabs
$class_anchor
CSS class for the UL tag.
set_class_div($class_div)
CSS class for the DIV containing the UL.
output()
print the html + javascript code of the tabs and the div
set_mode($mode)
set the mode , possible values : row , tabs or accordeon
set_class_content_div($class_content_div)
CSS class for the DIV with content (default empty)
$class_comment
CSS class for the DIV with content, default empty.
get_class_content_div()
CSS class for the DIV with content (default empty)
print
Type of printing.
if( $delta< 0) elseif( $delta==0)
$script
Definition: popup.php:125