24 require_once(
"Services/Table/classes/class.ilTableGUI.php");
44 public function __construct($a_parent_obj, $a_parent_cmd =
"")
49 $this->unique_id = md5(uniqid());
50 $this->parent_obj = $a_parent_obj;
51 $this->parent_cmd = $a_parent_cmd;
52 $this->buttons = array();
53 $this->header_commands = array();
54 $this->multi = array();
56 $this->tpl =
new ilTemplate(
"tpl.table2.html",
true,
true,
"Services/Table");
58 $this->
setLimit($ilUser->getPref(
"hits_per_page"));
68 return $this->parent_obj;
78 return $this->parent_cmd;
88 $this->noentriestext = $a_text;
98 return $this->noentriestext;
108 $this->enabled[
"title"] = $a_enabletitle;
118 return $this->enabled[
"title"];
128 $this->enabled[
"header"] = $a_enableheader;
138 return $this->enabled[
"header"];
141 final public function setTitle($a_title, $a_icon = 0, $a_icon_alt = 0)
153 $this->order_field = $a_order_field;
158 return $this->order_field;
163 $this->row_data = $a_data;
168 return $this->row_data;
173 if (is_array($this->row_data))
175 if (count($this->row_data) > 0)
185 $this->prefix = $a_prefix;
195 $this->form_action = $a_form_action;
205 return $this->form_action;
215 $this->formname = $a_formname;
225 return $this->formname;
265 $this->select_all_checkbox = $a_select_all_checkbox;
276 $this->row_template = $a_template;
277 $this->row_template_dir = $a_template_dir;
287 $this->defaultorderfield = $a_defaultorderfield;
297 return $this->defaultorderfield;
307 $this->defaultorderdirection = $a_defaultorderdirection;
317 return $this->defaultorderdirection;
328 $this->buttons[] = array(
"cmd" => $a_cmd,
"text" => $a_text);
339 $this->close_command = $a_link;
350 $this->multi[] = array(
"cmd" => $a_cmd,
"text" => $a_text);
361 $this->header_commands[] = array(
"href" => $a_href,
"text" => $a_text,
362 "target" => $a_target,
"img" => $a_img);
372 final public function addColumn($a_text, $a_sort_field =
"", $a_width =
"")
374 $this->column[] = array(
376 "sort_field" => $a_sort_field,
377 "width" => $a_width);
378 $this->column_count = count($this->column);
383 return $this->prefix.
"_table_nav";
393 $ilCtrl->setParameter($this->parent_obj,
395 $sort_field.
":".$order_dir.
":".$this->offset);
396 $this->tpl->setVariable(
"TBL_ORDER_LINK",
397 $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd));
400 $ilCtrl->setParameter($this->parent_obj,
406 foreach ($this->column as $column)
408 if (!$this->enabled[
"sort"] || $column[
"sort_field"] ==
"")
410 $this->tpl->setCurrentBlock(
"tbl_header_no_link");
411 if ($column[
"width"] !=
"")
413 $this->tpl->setVariable(
"TBL_COLUMN_WIDTH_NO_LINK",
" width=\"".$column[
"width"].
"\"");
415 $this->tpl->setVariable(
"TBL_HEADER_CELL_NO_LINK",
417 $this->tpl->parseCurrentBlock();
418 $this->tpl->touchBlock(
"tbl_header_th");
421 if (($column[
"sort_field"] == $this->order_field) && ($this->order_direction !=
""))
423 $this->tpl->setCurrentBlock(
"tbl_order_image");
424 $this->tpl->setVariable(
"IMG_ORDER_DIR",
ilUtil::getImagePath($this->order_direction.
"_order.gif"));
425 $this->tpl->parseCurrentBlock();
428 $this->tpl->setCurrentBlock(
"tbl_header_cell");
429 $this->tpl->setVariable(
"TBL_HEADER_CELL", $column[
"text"]);
432 if ($column[
"width"] !=
"")
434 $this->tpl->setVariable(
"TBL_COLUMN_WIDTH",
" width=\"".$column[
"width"].
"\"");
437 $lng_sort_column = $this->lng->txt(
"sort_by_this_column");
438 $this->tpl->setVariable(
"TBL_ORDER_ALT",$lng_sort_column);
442 if ($column[
"sort_field"] == $this->order_field)
444 $order_dir = $this->sort_order;
446 $lng_change_sort = $this->lng->txt(
"change_sort_direction");
447 $this->tpl->setVariable(
"TBL_ORDER_ALT",$lng_change_sort);
451 $this->tpl->parseCurrentBlock();
452 $this->tpl->touchBlock(
"tbl_header_th");
455 $this->tpl->setCurrentBlock(
"tbl_header");
456 $this->tpl->parseCurrentBlock();
466 if(!$this->enabled[
'content'])
486 $nav = explode(
":", $this->nav_value);
493 $this->
setFooter(
"tblfooter",$this->lng->txt(
"previous"),$this->lng->txt(
"next"));
506 $this->tpl->addBlockFile(
"TBL_CONTENT",
"tbl_content", $this->row_template,
507 $this->row_template_dir);
509 foreach($data as $set)
511 $this->tpl->setCurrentBlock(
"tbl_content");
512 $this->css_row = ($this->css_row !=
"tblrow1")
515 $this->tpl->setVariable(
"CSS_ROW", $this->css_row);
518 $this->tpl->setCurrentBlock(
"tbl_content");
519 $this->tpl->parseCurrentBlock();
527 : $lng->txt(
"no_items");
529 $this->css_row = ($this->css_row !=
"tblrow1")
533 $this->tpl->setCurrentBlock(
"tbl_no_entries");
534 $this->tpl->setVariable(
'TBL_NO_ENTRY_CSS_ROW', $this->css_row);
535 $this->tpl->setVariable(
'TBL_NO_ENTRY_COLUMN_COUNT', $this->column_count);
536 $this->tpl->setVariable(
'TBL_NO_ENTRY_TEXT', trim($no_items_text));
537 $this->tpl->parseCurrentBlock();
541 if ($this->form_action !=
"")
543 $this->tpl->setCurrentBlock(
"tbl_form_header");
544 $this->tpl->setVariable(
"FORMACTION", $this->
getFormAction());
545 $this->tpl->setVariable(
"FORMNAME", $this->
getFormName());
546 $this->tpl->parseCurrentBlock();
547 $this->tpl->touchBlock(
"tbl_form_footer");
575 $this->tpl->setVariable(
"CSS_TABLE",$this->
getStyle(
"table"));
576 if ($this->
getId() !=
"")
578 $this->tpl->setVariable(
"ID",
'id="'.$this->
getId().
'"');
582 if ($this->enabled[
"title"])
584 if ($this->enabled[
"icon"])
586 $this->tpl->setCurrentBlock(
"tbl_header_title_icon");
588 $this->tpl->setVariable(
"TBL_TITLE_IMG_ALT",$this->icon_alt);
589 $this->tpl->parseCurrentBlock();
592 foreach($this->header_commands as
$command)
594 if ($command[
"img"] !=
"")
596 $this->tpl->setCurrentBlock(
"tbl_header_img_link");
597 if ($command[
"target"] !=
"")
599 $this->tpl->setVariable(
"TARGET_IMG_LINK",
600 'target="'.$command[
"target"].
'"');
602 $this->tpl->setVariable(
"ALT_IMG_LINK", $command[
"text"]);
603 $this->tpl->setVariable(
"HREF_IMG_LINK", $command[
"href"]);
604 $this->tpl->setVariable(
"SRC_IMG_LINK",
606 $this->tpl->parseCurrentBlock();
610 $this->tpl->setCurrentBlock(
"head_cmd");
611 $this->tpl->setVariable(
"TXT_HEAD_CMD", $command[
"text"]);
612 $this->tpl->setVariable(
"HREF_HEAD_CMD", $command[
"href"]);
613 $this->tpl->parseCurrentBlock();
617 if (isset ($this->headerHTML)) {
618 $this->tpl->setCurrentBlock(
"tbl_header_html");
619 $this->tpl->setVariable (
"HEADER_HTML", $this->headerHTML);
620 $this->tpl->parseCurrentBlock();
624 if ($this->close_command !=
"")
626 $this->tpl->setCurrentBlock(
"tbl_header_img_link");
627 $this->tpl->setVariable(
"ALT_IMG_LINK",$lng->txt(
"close"));
628 $this->tpl->setVariable(
"HREF_IMG_LINK",$this->close_command);
630 $this->tpl->parseCurrentBlock();
633 $this->tpl->setCurrentBlock(
"tbl_header_title");
634 $this->tpl->setVariable(
"COLUMN_COUNT",$this->column_count);
635 $this->tpl->setVariable(
"TBL_TITLE",$this->title);
636 $this->tpl->parseCurrentBlock();
640 if ($this->enabled[
"header"])
645 $this->tpl->touchBlock(
"tbl_table_end");
647 return $this->tpl->get();
658 foreach ($a_set as $key => $value)
660 $this->tpl->setVariable(
"VAL_".strtoupper($key), $value);
677 $this->tpl->setCurrentBlock(
"select_all_checkbox");
678 $this->tpl->setVariable(
"SELECT_ALL_TXT_SELECT_ALL", $lng->txt(
"select_all"));
680 $this->tpl->setVariable(
"SELECT_ALL_FORM_NAME", $this->
getFormName());
681 $this->tpl->setVariable(
"CHECKBOXNAME",
"chb_select_all_" . $this->unique_id);
682 $this->tpl->parseCurrentBlock();
687 if ($this->enabled[
"numinfo"] && $this->enabled[
"footer"])
689 $start = $this->offset + 1;
696 if ($end > $this->max_count or $this->limit == 0)
701 if ($this->lang_support)
703 $numinfo =
"(".$start.
" - ".$end.
" ".strtolower($this->lng->txt(
"of")).
" ".$this->max_count.
")";
707 $numinfo =
"(".$start.
" - ".$end.
" of ".$this->max_count.
")";
709 if ($this->max_count > 0)
711 $this->tpl->setCurrentBlock(
"tbl_footer_numinfo");
712 $this->tpl->setVariable(
"NUMINFO", $numinfo);
713 $this->tpl->parseCurrentBlock();
719 if ($this->enabled[
"linkbar"] && $this->enabled[
"footer"] && $this->limit != 0
720 && $this->max_count > 0)
723 "link" => $this->footer_style,
724 "prev" => $this->footer_previous,
725 "next" => $this->footer_next,
728 $this->tpl->setCurrentBlock(
"tbl_footer_linkbar");
729 $this->tpl->setVariable(
"LINKBAR", $linkbar);
730 $this->tpl->parseCurrentBlock();
736 $this->tpl->setCurrentBlock(
"tbl_footer");
738 $this->tpl->parseCurrentBlock();
741 if ($numinfo !=
"" || $linkbar !=
"")
745 $this->tpl->setCurrentBlock(
"top_numinfo");
746 $this->tpl->setVariable(
"NUMINFO", $numinfo);
747 $this->tpl->parseCurrentBlock();
752 $this->tpl->setCurrentBlock(
"top_linkbar");
753 $this->tpl->setVariable(
"LINKBAR", $linkbar);
754 $this->tpl->parseCurrentBlock();
756 $this->tpl->setCurrentBlock(
"top_navigation");
758 $this->tpl->parseCurrentBlock();
774 $link = $ilCtrl->getLinkTargetByClass(get_class($this->parent_obj), $this->parent_cmd).
775 "&".$this->getNavParameter().
"=".
779 $layout_prev = $lng->txt(
"previous");
780 $layout_next = $lng->txt(
"next");
783 if ($this->max_count > $this->
getLimit())
789 $LinkBar .=
"<a class=\"small\" href=\"".$link.$prevoffset.
"\">".$layout_prev.
" </a>";
793 $LinkBar .=
'<span class="il_BlockInfo">'.$layout_prev.
" </span>";
799 $LinkBar .=
'<input type="hidden" name="'.$this->getNavParameter().
804 $pages = intval($this->max_count / $this->
getLimit());
807 if (($this->max_count % $this->
getLimit()))
811 $offset_arr = array();
812 for ($i = 1 ;$i <= $pages ; $i++)
814 $newoffset = $this->
getLimit() * ($i-1);
817 $offset_arr[$nav_value] = $i;
833 $LinkBar .=
"<span class=\"small\" > | </span>";
835 $LinkBar .=
"<a class=\"small\" href=\"".$link.$newoffset.
"\"> ".$layout_next.
"</a>";
840 $LinkBar .=
"<span class=\"small\" > | </span>";
841 $LinkBar .=
'<span class="il_BlockInfo"> '.$layout_next.
"</span>";
844 if (count($offset_arr))
846 $LinkBar .=
" ".ilUtil::formSelect($this->nav_value,
847 $this->
getNavParameter().$a_num, $offset_arr,
false,
true, 0,
"ilEditSelect").
848 ' <input class="ilEditSubmit" type="submit" name="cmd['.$this->parent_cmd.
']" value="'.
849 $lng->txt(
"select_page").
'"> ';
872 if (count($this->buttons) > 0)
874 foreach ($this->buttons as $button)
876 $this->tpl->setCurrentBlock(
"plain_button");
877 $this->tpl->setVariable(
"PBTN_NAME", $button[
"cmd"]);
878 $this->tpl->setVariable(
"PBTN_VALUE", $button[
"text"]);
879 $this->tpl->parseCurrentBlock();
881 $this->tpl->setCurrentBlock(
"plain_buttons");
882 $this->tpl->parseCurrentBlock();
888 if (count($this->multi) > 1 && $this->
dataExists())
890 $this->tpl->setCurrentBlock(
"tbl_cmd_select");
892 foreach ($this->multi as $mc)
894 $sel[$mc[
"cmd"]] = $mc[
"text"];
896 $this->tpl->setVariable(
"SELECT_CMDS",
898 $this->tpl->setVariable(
"TXT_EXECUTE", $lng->txt(
"execute"));
899 $this->tpl->setVariable(
'SELECT_CMD',
'select_cmd');
900 $this->tpl->parseCurrentBlock();
904 elseif(count($this->multi) == 1 && $this->
dataExists())
906 $this->tpl->setCurrentBlock(
"tbl_single_cmd");
908 foreach ($this->multi as $mc)
913 $this->tpl->setVariable(
"TXT_SINGLE_CMD",$txt);
914 $this->tpl->setVariable(
"SINGLE_CMD",
$cmd);
915 $this->tpl->parseCurrentBlock();
922 $this->tpl->setCurrentBlock(
"tbl_action_img_arrow");
924 $this->tpl->setVariable(
"ALT_ARROW", $lng->txt(
"action"));
925 $this->tpl->parseCurrentBlock();
930 $this->tpl->setCurrentBlock(
"tbl_action_row");
931 $this->tpl->setVariable(
"COLUMN_COUNTS", $this->
getColumnCount());
932 $this->tpl->parseCurrentBlock();
944 $this->headerHTML = $html;