68 "numinfo_header" =>
false,
77 "table" =>
"fullwidth"
91 $this->global_tpl = $a_global_tpl;
92 $this->ilias =& $ilias;
93 $this->header_vars = array();
94 $this->header_params = array();
95 $this->enabled[
"form"] =
true;
96 $this->action_buttons = array();
97 if ($this->global_tpl)
103 $this->tpl =
new ilTemplate(
"tpl.table.html",
true,
true,
"Services/Table");
110 $this->lang_support =
false;
124 $this->tpl =& $a_tpl;
139 if (is_array($a_data))
141 $this->data = $a_data;
157 function setTitle($a_title,$a_icon = 0,$a_icon_alt = 0)
159 $this->title = $a_title;
160 $this->icon = $a_icon;
161 $this->icon_alt = $a_icon_alt;
165 $this->enabled[
"icon"] =
false;
170 if (!$this->icon_alt)
174 $this->enabled[
"icon"] =
true;
184 function setHelp($a_help_page,$a_help_icon,$a_help_icon_alt = 0)
186 $this->help_page = $a_help_page;
187 $this->help_icon = $a_help_icon;
188 $this->help_icon_alt = $a_help_icon_alt;
190 if (!$this->help_icon_alt)
203 $this->header_names = $a_header_names;
204 $this->column_count = count($this->header_names);
225 $this->header_vars = $a_header_vars;
227 if ($a_header_params == 0 or !is_array($a_header_params))
229 $this->link_params =
"";
233 $this->header_params = $a_header_params;
235 foreach ($a_header_params as $key => $val)
237 $this->link_params .= $key.
"=".$val.
"&";
249 $this->column_width = $a_column_width;
260 $this->column_width[$a_column_number] = $a_column_width;
272 $this->max_count = $a_max_count;
274 if ($this->max_limit)
286 function setLimit($a_limit = 0, $a_default_limit = 0)
288 $this->limit = ($a_limit) ? $a_limit : $a_default_limit;
290 if ($this->limit == 0)
292 $this->max_limit =
true;
312 $this->prefix = ($a_prefix) ? $a_prefix :
"";
322 $this->offset = ($a_offset) ? $a_offset : 0;
342 if (empty($a_order_column))
344 if (!empty($a_default_column))
346 $this->order_column = array_search($a_default_column,$this->header_vars);
350 $this->order_column = 0;
356 $this->order_column = array_search($a_order_column,$this->header_vars);
359 if ($this->order_column ===
false)
362 $this->order_column = 0;
381 if ($a_order_direction ==
"desc")
383 $this->order_direction =
"desc";
384 $this->sort_order =
"asc";
388 $this->order_direction =
"asc";
389 $this->sort_order =
"desc";
408 function setFooter($a_style,$a_previous = 0,$a_next = 0)
410 $this->footer_style = $a_style;
412 $this->footer_previous = ($a_previous) ? $a_previous :
"<<<";
413 $this->footer_next = ($a_next) ? $a_next :
">>>";
426 if (!in_array($a_module_name,array_keys($this->enabled)))
431 $this->enabled[$a_module_name] =
true;
444 if (!in_array($a_module_name,array_keys($this->enabled)))
449 $this->enabled[$a_module_name] =
false;
455 if($this->enabled[
"sort"])
457 $this->data =
ilUtil::sortArray($this->data,$this->order_column,$this->order_direction);
459 $this->data = array_slice($this->data,$this->offset,$this->limit);
468 if($this->enabled[
'table'])
470 $this->tpl->setVariable(
"CSS_TABLE",$this->
getStyle(
"table"));
474 if ($this->enabled[
"icon"] && $this->enabled[
"title"])
476 $this->tpl->setCurrentBlock(
"tbl_header_title_icon");
478 $this->tpl->setVariable(
"TBL_TITLE_IMG_ALT",$this->icon_alt);
479 $this->tpl->parseCurrentBlock();
482 if ($this->enabled[
"help"] && $this->enabled[
"title"])
484 $this->tpl->setCurrentBlock(
"tbl_header_title_help");
486 $this->tpl->setVariable(
"TBL_HELP_LINK",$this->help_page);
487 $this->tpl->setVariable(
"TBL_HELP_IMG_ALT",$this->help_icon_alt);
488 $this->tpl->parseCurrentBlock();
492 if ($this->enabled[
"hits"] && $this->enabled[
"title"])
494 $this->tpl->setCurrentBlock(
"tbl_header_hits_page");
495 $this->tpl->setVariable(
"LIMIT",
$_SESSION[
"tbl_limit"]);
496 $this->tpl->setVariable(
"HITS_PER_PAGE",$this->lng->txt(
"hits_per_page"));
497 $this->tpl->parseCurrentBlock();
501 if ($this->enabled[
"title"])
503 $this->tpl->setCurrentBlock(
"tbl_header_title");
504 $this->tpl->setVariable(
"COLUMN_COUNT",$this->column_count);
505 $this->tpl->setVariable(
"TBL_TITLE",$this->title);
506 $this->tpl->parseCurrentBlock();
510 if ($this->enabled[
"header"])
520 if ($this->enabled[
"content"] && is_array($this->data))
522 if($this->enabled[
'auto_sort'])
529 foreach ($this->data as $tbl_content_row)
531 foreach ($tbl_content_row as $key => $tbl_content_cell)
533 if (is_array($tbl_content_cell))
535 $this->tpl->setCurrentBlock(
"tbl_cell_subtitle");
536 $this->tpl->setVariable(
"TBL_CELL_SUBTITLE",$tbl_content_cell[1]);
537 $this->tpl->parseCurrentBlock();
538 $tbl_content_cell =
"<b>".$tbl_content_cell[0].
"</b>";
541 $this->tpl->setCurrentBlock(
"tbl_content_cell");
542 $this->tpl->setVariable(
"TBL_CONTENT_CELL",$tbl_content_cell);
543 $this->tpl->parseCurrentBlock();
546 $this->tpl->setCurrentBlock(
"tbl_content_row");
548 $this->tpl->setVariable(
"ROWCOLOR", $rowcolor);
549 $this->tpl->parseCurrentBlock();
555 if ($this->enabled[
"select_all"])
559 $this->tpl->setVariable(
'SELECT_PREFIX',$this->prefix);
560 $this->tpl->setVariable(
"SELECT_ALL_TXT_SELECT_ALL", $this->lng->txt(
"select_all"));
562 $this->tpl->setVariable(
"SELECT_ALL_FORM_NAME", $this->
getFormName());
563 if (!($this->enabled[
"numinfo"] && $this->enabled[
"footer"]))
571 if ($this->enabled[
"numinfo_header"])
573 $start = $this->offset + 1;
576 if ($end > $this->max_count or $this->limit == 0)
581 if ($this->lang_support)
583 $numinfo =
"(".$this->lng->txt(
"dataset").
" ".$start.
" - ".$end.
" ".strtolower($this->lng->txt(
"of")).
" ".$this->max_count.
")";
587 $numinfo =
"(Dataset ".$start.
" - ".$end.
" of ".$this->max_count.
")";
589 if ($this->max_count > 0)
592 $this->tpl->setCurrentBlock(
"tbl_header_numinfo");
593 $this->tpl->setVariable(
"NUMINFO_HEADER", $numinfo);
594 $this->tpl->setVariable(
"COLUMN_COUNT_HEADER", $this->
getColumnCount());
595 $this->tpl->parseCurrentBlock();
599 if ($this->enabled[
"numinfo"] && $this->enabled[
"footer"])
601 $start = $this->offset + 1;
604 if ($end > $this->max_count or $this->limit == 0)
609 if ($this->lang_support)
611 $numinfo =
"(".$this->lng->txt(
"dataset").
" ".$start.
" - ".$end.
" ".strtolower($this->lng->txt(
"of")).
" ".$this->max_count.
")";
615 $numinfo =
"(Dataset ".$start.
" - ".$end.
" of ".$this->max_count.
")";
617 if ($this->max_count > 0)
620 $this->tpl->setCurrentBlock(
"tbl_footer_numinfo");
621 $this->tpl->setVariable(
"NUMINFO", $numinfo);
622 $this->tpl->parseCurrentBlock();
626 if ($this->enabled[
"linkbar"] && $this->enabled[
"footer"] && $this->limit != 0
627 && $this->max_count > 0)
630 $this->prefix.
"sort_by" => $this->header_vars[$this->order_column],
631 $this->prefix.
"sort_order" => $this->order_direction
633 $params = array_merge($this->header_params,$params);
636 "link" => $this->footer_style,
637 "prev" => $this->footer_previous,
638 "next" => $this->footer_next,
642 ? basename($_SERVER[
"PHP_SELF"])
645 $linkbar =
ilUtil::Linkbar(
$base,$this->max_count,$this->limit,$this->offset,$params,$layout, $this->prefix);
646 $this->tpl->setCurrentBlock(
"tbl_footer_linkbar");
647 $this->tpl->setVariable(
"LINKBAR", $linkbar);
648 $this->tpl->parseCurrentBlock();
652 if ($this->enabled[
"footer"] && $this->max_count > 0)
654 $this->tpl->setCurrentBlock(
"tbl_footer");
655 $this->tpl->setVariable(
"COLUMN_COUNT",$this->column_count);
656 $this->tpl->parseCurrentBlock();
660 if ($this->enabled[
"action"])
662 foreach ($this->action_buttons as $button)
664 $this->tpl->setCurrentBlock(
"tbl_action_btn");
665 $this->tpl->setVariable(
"BTN_NAME", $button[
"name"]);
666 $this->tpl->setVariable(
"BTN_VALUE", $button[
"value"]);
667 $this->tpl->parseCurrentBlock();
669 $this->tpl->setCurrentBlock(
"tbl_action_row");
671 $this->tpl->setVariable(
"ALT_ARROW", $this->lng->txt(
"arrow_downright.gif"));
672 $this->tpl->setVariable(
"COLUMN_COUNTS", $this->
getColumnCount());
673 $this->tpl->parseCurrentBlock();
676 if ($this->enabled[
"form"])
678 $this->tpl->touchBlock(
"tbl_form_footer");
681 if($this->enabled[
'table'])
683 $this->tpl->touchBlock(
"tbl_table_end");
686 if (!$this->global_tpl)
688 return $this->tpl->get();
694 foreach ($this->header_names as $key => $tbl_header_cell)
696 if (!$this->enabled[
"sort"])
698 $this->tpl->setCurrentBlock(
"tbl_header_no_link");
699 if ($this->column_width[$key])
701 $this->tpl->setVariable(
"TBL_COLUMN_WIDTH_NO_LINK",
" width=\"".$this->column_width[$key].
"\"");
703 $this->tpl->setVariable(
"TBL_HEADER_CELL_NO_LINK",$tbl_header_cell);
704 $this->tpl->parseCurrentBlock();
707 if (($key == $this->order_column) && ($this->order_direction !=
""))
709 if (strcmp($this->header_vars[$key],
"") != 0)
711 $this->tpl->setCurrentBlock(
"tbl_order_image");
712 $this->tpl->setVariable(
"IMG_ORDER_DIR",
ilUtil::getImagePath($this->order_direction.
"_order.gif"));
713 $this->tpl->parseCurrentBlock();
717 $this->tpl->setCurrentBlock(
"tbl_header_cell");
718 $this->tpl->setVariable(
"TBL_HEADER_CELL",$tbl_header_cell);
721 if ($this->column_width[$key])
723 $this->tpl->setVariable(
"TBL_COLUMN_WIDTH",
" width=\"".$this->column_width[$key].
"\"");
726 $lng_sort_column = (
$this->lang_support) ? $this->lng->txt(
"sort_by_this_column") :
"Sort by this column";
727 $this->tpl->setVariable(
"TBL_ORDER_ALT",$lng_sort_column);
731 if ($key == $this->order_column)
733 $order_dir = $this->sort_order;
735 $lng_change_sort = (
$this->lang_support) ? $this->lng->txt(
"change_sort_direction") :
"Change sort direction";
736 $this->tpl->setVariable(
"TBL_ORDER_ALT",$lng_change_sort);
740 $this->tpl->parseCurrentBlock();
743 $this->tpl->setCurrentBlock(
"tbl_header");
744 $this->tpl->parseCurrentBlock();
749 $this->tpl->setVariable(
"TBL_ORDER_LINK",basename($_SERVER[
"PHP_SELF"]).
"?".$this->link_params.$this->prefix.
"sort_by=".$this->header_vars[$key].
"&".$this->prefix.
"sort_order=".$order_dir.
"&".$this->prefix.
"offset=".$this->offset);
760 $this->styles[$a_element] = $a_style;
770 return $this->styles[$a_element];
780 $this->base = $a_base;
810 $this->form_name = $a_name;
830 $this->select_all_checkbox = $a_select_all_checkbox;
840 $this->action_buttons = array();
852 array_push($this->action_buttons,
855 "value" => $btn_value