noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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 * @code
27 * // create TAQ , with a url
28 $tab = new Html_Tab('tab1',_("Titre 1"));
29 $tab->set_mode('link');
30 $tab->set_link("test.php?".
31 http_build_query([ "gDossier"=>Dossier::id(),
32 "script"=>"html_tab.test.php",
33 "a"=>1,
34 "b"=>2]));
35 *
36 // create a TAB and give the content
37 $tab2 = new Html_Tab('tab2',_("Titre 2"));
38 $tab2->set_content(""
39 . "<br> Très longue chaine HTML pour 2"
40 . "<br> Très longue chaine HTML pour 2"
41 . "<br> Très longue chaine HTML pour 2"
42 . "<br> Très longue chaine HTML pour 2"
43 . "<br> Très longue chaine HTML pour 2"
44 . "<br> Très longue chaine HTML pour 2"
45 . "<br> Très longue chaine HTML pour 2"
46 . "<br> Très longue chaine HTML pour 2"
47 . "<br> Très longue chaine HTML pour 2"
48 . "<br> Très longue chaine HTML pour 2"
49 . "<br> Très longue chaine HTML pour 2"
50 . "<br> Très longue chaine HTML pour 2");
51
52 $tab3 = new Html_Tab('tab3',_("Titre 3"));
53 $tab3->set_content('<p >'
54 . "<br> Très longue chaine HTML pour 3"
55 . "<br> Très longue chaine HTML pour 3"
56 . "<br> Très longue chaine HTML pour 3"
57 . "<br> Très longue chaine HTML pour 3"
58 . "<br> Très longue chaine HTML pour 3"
59 . "<br> Très longue chaine HTML pour 3"
60 . "<br> Très longue chaine HTML pour 3"
61 . "<br> Très longue chaine HTML pour 3"
62 . "<br> Très longue chaine HTML pour 3"
63 . "<br> Très longue chaine HTML pour 3"
64 . "<br> Très longue chaine HTML pour 3"
65 . "<br> Très longue chaine HTML pour 3"
66 . "<br> Très longue chaine HTML pour 3"
67 . "<br> Très longue chaine HTML pour 3"
68 .'</p>'
69 );
70
71 $output = new Output_Html_Tab;
72
73 $output->add($tab);
74 $output->add($tab2);
75 $output->add($tab3);
76
77 // show all the TABS
78$output->output();
79 *
80 * @endcode
81 */
82
83/**
84 * @brief Display the tabs
85 * @see Html_Tab
86 *
87 */
88
90{
91
92 private $a_tabs; //!< array of html tabs
93 private $class_tab; //!< for normal tab
94 private $class_tab_selected; //!< for class_tab_selected
95 private $mode; //!< mode default tabs
96 private $class_tab_main; //! CSS class for the UL tag
97 private $class_anchor; //! CSS class for the A tag (anchor) default empty
98 private $class_div; //! CSS class for the DIV containing the UL default empty
99 private $class_content_div; //! CSS class for the DIV with content, default empty
100 private $class_comment ; //! CSS class for the comment default "tabs"
101
102 /**
103 *@example html_tab.test.php
104 */
105 function __construct()
106 {
107 $this->a_tabs=[];
108 $this->class_tab="tabs";
109 $this->class_tab_main="tabs";
110 $this->class_tab_selected="tabs_selected";
111 $this->set_mode("tab");
112 $this->class_anchor="";
113 $this->class_div="";
114 $this->class_content_div="";
115 $this->class_comment="tabs";
116 }
117 /**
118 * @brief CSS class for the comment default "tabs"
119 * @return type
120 */
121 public function get_class_comment()
122 {
124 }
125 /**
126 * @brief CSS class for the comment default "tabs"
127 * @return type
128 */
129
131 {
132 $this->class_comment=$class_comment;
133 return $this;
134 }
135
136 /**
137 * @brief CSS class for the DIV with content (default empty)
138 */
139 public function get_class_content_div()
140 {
142 }
143 /**
144 *@brief CSS class for the DIV with content (default empty)
145 *
146 * @param string $class_content_div
147 */
149 {
150 $this->class_content_div=$class_content_div;
151 return $this;
152 }
153
154 /**
155 * @brief CSS class for the DIV containing the UL
156 * @return string
157 */
158 public function get_class_div()
159 {
160 return $this->class_div;
161 }
162
163 /**
164 * @brief CSS class for the DIV containing the UL
165 * @return string
166 */
167
168 public function set_class_div($class_div)
169 {
170 $this->class_div=$class_div;
171 return $this;
172 }
173
174 /**
175 * @brief CSS class for the A tag (anchor)
176 * @return type
177 */
178 public function get_class_anchor()
179 {
180 return $this->class_anchor;
181 }
182 /**
183 * @brief CSS class for the A tag (anchor)
184 * @param type $anchor_class
185 */
186 public function set_class_anchor($anchor_class)
187 {
188 $this->class_anchor=$anchor_class;
189 $this;
190 }
191
192 /**
193 * @brief get the CSS class for the UL element
194 * @return type
195 */
196 public function get_class_tab_main()
197 {
199 }
200
201 /**
202 * @brief set the CSS class for the UL element
203 * @return this
204 */
205
207 {
208 $this->class_tab_main=$class_tab_main;
209 return $this;
210 }
211
212 /**
213 * @brief get the mode , possible value are row or tabs , with mode = row , the
214 * class_content_div is set to row
215 * @return mixed
216 */
217 public function get_mode()
218 {
219 return $this->mode;
220 }
221
222 /**
223 * @brief set the mode , possible values : row , tabs or accordeon
224 * @param string $mode possible values : row , tabs or accordeon
225 */
226 public function set_mode($mode)
227 {
228 if (! in_array($mode,['tab','row','accordeon'] )) {
229 throw new Exception(_("OUTPUTHTML070 Mode invalide"));
230 }
231 $this->mode = $mode;
232 if ($mode == "row") {
233 $this->set_class_tab_selected("tab_row_selected");
234 $this->set_class_tab("tab_row");
235
236 }elseif ( $mode == "tab") {
237 $this->set_class_tab_selected("tabs_selected");
238 $this->set_class_tab("tabs");
239
240 }elseif ($mode == "accordeon") {
241 $this->set_class_tab_selected("");
242 $this->set_class_tab("tab_row");
243 } else {
244 throw new \Exception("OH186.unknow mode [$mode]");
245 }
246 return $this;
247 }
248
249 /**
250 * Add Html_Tab
251 * @param Html_Tab $p_html_tab
252 */
253 function add(Html_Tab $p_html_tab)
254 {
255 $this->a_tabs[]=clone $p_html_tab;
256
257 }
258
259 /**
260 * get the CSS class of tabs
261 * @return mixed
262 */
263 public function get_class_tab()
264 {
265 return $this->class_tab;
266 }
267
268 /**
269 * set the CSS class of tabs, default is tabs
270 * @param mixed $class_tab
271 */
272 public function set_class_tab($class_tab)
273 {
274 $this->class_tab = $class_tab;
275 return $this;
276 }
277
278 /**
279 * get the CSS class of tabs_selected
280 * @return mixed
281 */
282 public function get_class_tab_selected()
283 {
285 }
286
287 /**
288 * set the CSS class of tabs, default is tabs_selected
289 * @param mixed $class_tab_selected
290 */
292 {
293 $this->class_tab_selected = $class_tab_selected;
294 return $this;
295 }
296
297 /**
298 * Build the javascript to change the class name of the selected tab, hide other div and show the selected one
299 * @param string $p_not_hidden id of the showed tab
300 * @return javascript string
301 */
302 function build_js ($p_not_hidden)
303 {
304 $r="";
305 $nb=count($this->a_tabs);
306 $mode=$this->get_mode();
307 if ($mode=="accordeon") {
308 $r .= \Icon_Action::toggle_hide(uniqid(), sprintf("div%s", $p_not_hidden));
309
310 return $r;
311 }
312 for ($i =0 ; $i < $nb;$i++)
313 {
314 if ($mode=="tab") {
315
316 if ( $this->a_tabs[$i]->get_id() != $p_not_hidden) {
317 $r .= sprintf("$('div%s').hide();",$this->a_tabs[$i]->get_id() );
318 $r .= sprintf("$('tab%s').className='%s';",$this->a_tabs[$i]->get_id(),$this->class_tab );
319 } else {
320 $r .= sprintf("$('div%s').show();",$p_not_hidden );
321 $r .= sprintf("$('tab%s').className='%s';",$p_not_hidden ,$this->class_tab_selected);
322
323 }
324 } elseif ($mode=="row") {
325 if ( $this->a_tabs[$i]->get_id() != $p_not_hidden) {
326 $r .= sprintf("Effect.BlindUp('div%s',{duration : 0.7});",$this->a_tabs[$i]->get_id() );
327 $r .= sprintf("$('tab%s').className='%s';",$this->a_tabs[$i]->get_id(),$this->class_tab );
328 } else {
329 $r .= sprintf("Effect.SlideDown('div%s',{duration : 0.7});",$p_not_hidden );
330 $r .= sprintf("$('tab%s').className='%s';",$p_not_hidden ,$this->class_tab_selected);
331
332 }
333 } else {
334 throw new \Exception("OH283.unknow mode [$mode]");
335 }
336 }
337 return $r;
338 }
339
340 /**
341 * When printing row , a comment is written if not empty,
342 * @param $p_index
343 */
344 protected function print_comment($p_index) {
345 printf ('<span class="%s"> %s </span>',
346 $this->get_class_comment(),
347 $this->a_tabs[$p_index]->get_comment()
348 );
349
350 }
351 /**
352 * @brief print the html + javascript code of the tabs and the div
353 *
354 */
355 function output()
356 {
357 $nb=count($this->a_tabs);
358 if ($nb==0)
359 {
360 return;
361 }
362 printf('<div class="%s">',$this->class_div);
363 printf ( '<ul class="%s">',$this->class_tab_main);
364 $mode=$this->get_mode();
365 for ($i=0; $i<$nb; $i++)
366 {
367 printf ('<li id="tab%s" class="%s">',
368 $this->a_tabs[$i]->get_id(),$this->class_tab);
369 switch ($this->a_tabs[$i]->get_mode())
370 {
371 case 'link':
372 printf ('<a class="%s" id="%s" href="%s">',
373 $this->class_anchor,
374 $this->a_tabs[$i]->get_id(),
375 $this->a_tabs[$i]->get_link());
376 printf ('<span class="title_%s"> %s </span>',
377 $this->get_class_tab(),
378 $this->a_tabs[$i]->get_title()
379 );
380 echo '</a>';
381
382 break;
383 case 'ajax':
384 printf('<a class="%s" id="%s" onclick="%s">',
385 $this->class_anchor,
386 $this->a_tabs[$i]->get_id(),
387 $this->a_tabs[$i]->get_link());
388 printf ('<span class="title_%s"> %s </span>',
389 $this->get_class_tab(),
390 $this->a_tabs[$i]->get_title()
391 );
392
393 echo $this->a_tabs[$i]->get_title();
394 echo '</a>';
395 break;
396 case 'static':
397 // show one , hide other except for accordeon
398 $script=$this->build_js($this->a_tabs[$i]->get_id());
399 if ($mode != 'accordeon') {
400 printf('<a class="%s" onclick="%s">', $this->class_anchor,$script);
401 } else {
403 }
404
405 printf ('<span class="title_%s"> %s </span>',
406 $this->get_class_tab(),
407 $this->a_tabs[$i]->get_title()
408 );
409
410 echo '</a>';
411 $script=$this->build_js($this->a_tabs[$i]->get_id());
412
413 break;
414 default:
415 throw new Exception('OUTPUTHTMLTAB01');
416 break;
417 }
418 if ( $mode =="row" || $mode == "accordeon") {
419 $this->print_comment($i);
420 }
421 echo '</li>';
422 if ( $mode =="row" || $mode == "accordeon") {
423 $this->print_div($i);
424 }
425 }
426 echo '</ul>';
427 echo '</div>';
428
429 if ( $mode=="tab" ) {
430 for ($i=0;$i<$nb;$i++)
431 {
432 $this->print_div($i);
433 }
434
435 }
436 }
437 private function print_div($p_index)
438 {
439 $class="";
440 if ( $this->get_mode() == "row" ) {
441 $class="tab_row";
442 } elseif ( $this->get_mode() == 'accordeon') {
443 $class="";
444 }
445
446
447 printf('<div id="div%s" style="display:none;clear:both" class="%s">',
448 $this->a_tabs[$p_index]->get_id(),
449 $class);
450 echo $this->a_tabs[$p_index]->get_content();
451 echo '</div>';
452
453 }
454}
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
_("actif, passif,charge,...")
Tab Element.
static toggle_hide($p_id, $p_id_to_hide)
hide or display an element, to be used for an accordon
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
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