ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTable2GUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once("Services/Table/classes/class.ilTableGUI.php");
5 
15 class ilTable2GUI extends ilTableGUI
16 {
17  protected $close_command = "";
18  private $unique_id;
19  private $headerHTML;
20  protected $top_anchor = "il_table_top";
21  protected $filters = array();
22  protected $optional_filters = array();
23  protected $filter_cmd = 'applyFilter';
24  protected $reset_cmd = 'resetFilter';
25  protected $filter_cols = 5;
26  protected $ext_sort = false;
27  protected $ext_seg = false;
28  protected $context = "";
29 
30  protected $mi_sel_buttons = null;
31  protected $disable_filter_hiding = false;
32  protected $selected_filter = false;
33  protected $top_commands = true;
34  protected $selectable_columns = array();
35  protected $selected_column = array();
36  protected $show_templates = false;
37  protected $show_rows_selector = false;
38 
39  protected $nav_determined= false;
40  protected $limit_determined = false;
41  protected $filters_determined = false;
42  protected $columns_determined = false;
43  protected $open_form_tag = true;
44  protected $close_form_tag = true;
45 
46  protected $export_formats;
47  protected $export_mode;
48  protected $print_mode;
49 
51 
56 
57  const FILTER_TEXT = 1;
58  const FILTER_SELECT = 2;
59  const FILTER_DATE = 3;
60  const FILTER_LANGUAGE = 4;
62  const FILTER_DATE_RANGE = 6;
65 
66  const EXPORT_EXCEL = 1;
67  const EXPORT_CSV = 2;
68 
69  const ACTION_ALL_LIMIT = 1000;
70 
75  public function __construct($a_parent_obj, $a_parent_cmd = "", $a_template_context = "")
76  {
77  global $lng;
78 
79  parent::__construct(0, false);
80  $this->unique_id = md5(uniqid());
81  $this->parent_obj = $a_parent_obj;
82  $this->parent_cmd = $a_parent_cmd;
83  $this->buttons = array();
84  $this->header_commands = array();
85  $this->multi = array();
86  $this->hidden_inputs = array();
87  $this->formname = "table_" . $this->unique_id;
88  $this->tpl = new ilTemplate("tpl.table2.html", true, true, "Services/Table");
89 
90  $lng->loadLanguageModule('tbl');
91 
92  if(!$a_template_context)
93  {
94  $a_template_context = $this->getId();
95  }
96  $this->setContext($a_template_context);
97 
98  // activate export mode
99  if(isset($_GET[$this->prefix."_xpt"]))
100  {
101  $this->export_mode = (int)$_GET[$this->prefix."_xpt"];
102  }
103 
104  // template handling
105  if(isset($_GET[$this->prefix."_tpl"]))
106  {
107  $this->restoreTemplate($_GET[$this->prefix."_tpl"]);
108  }
109 
110  $this->determineLimit();
111  $this->setIsDataTable(true);
112  $this->setEnableNumInfo(true);
113  $this->determineSelectedColumns();
114  }
115 
121  function setOpenFormTag($a_val)
122  {
123  $this->open_form_tag = $a_val;
124  }
125 
131  function getOpenFormTag()
132  {
133  return $this->open_form_tag;
134  }
135 
141  function setCloseFormTag($a_val)
142  {
143  $this->close_form_tag = $a_val;
144  }
145 
151  function getCloseFormTag()
152  {
153  return $this->close_form_tag;
154  }
155 
159  function determineLimit()
160  {
161  global $ilUser;
162 
163  if ($this->limit_determined)
164  {
165  return;
166  }
167 
168  $limit = 0;
169  if (isset($_GET[$this->prefix."_trows"]))
170  {
171  $this->storeProperty("rows", $_GET[$this->prefix."_trows"]);
172  $limit = $_GET[$this->prefix."_trows"];
173  $this->resetOffset();
174  }
175 
176  if ($limit == 0)
177  {
178  $rows = $this->loadProperty("rows");
179  if ($rows > 0)
180  {
181  $limit = $rows;
182  }
183  else
184  {
185  if (is_object($ilUser))
186  {
187  $limit = $ilUser->getPref("hits_per_page");
188  }
189  else
190  {
191  $limit = 40;
192  }
193  }
194  }
195 
196  $this->setLimit($limit);
197  $this->limit_determined = true;
198  }
199 
206  {
207  return array();
208  }
209 
214  {
215  if ($this->columns_determined)
216  {
217  return;
218  }
219 
220  $old_sel = $this->loadProperty("selfields");
221 
222  $stored = false;
223  if ($old_sel != "")
224  {
225  $sel_fields =
226  @unserialize($old_sel);
227  $stored = true;
228  }
229  if(!is_array($sel_fields))
230  {
231  $stored = false;
232  $sel_fields = array();
233  }
234 
235  $this->selected_columns = array();
236  $set = false;
237  foreach ($this->getSelectableColumns() as $k => $c)
238  {
239  $this->selected_column[$k] = false;
240 
241  $new_column = ($sel_fields[$k] === NULL);
242 
243  if ($_POST["tblfsh".$this->getId()])
244  {
245  $set = true;
246  if (is_array($_POST["tblfs".$this->getId()]) && in_array($k, $_POST["tblfs".$this->getId()]))
247  {
248  $this->selected_column[$k] = true;
249  }
250  }
251  else if ($stored && !$new_column) // take stored values
252  {
253  $this->selected_column[$k] = $sel_fields[$k];
254  }
255  else // take default values
256  {
257  if ($new_column)
258  {
259  $set = true;
260  }
261  if ($c["default"])
262  {
263  $this->selected_column[$k] = true;
264  }
265  }
266  }
267 
268  if ($old_sel != serialize($this->selected_column) && $set)
269  {
270  $this->storeProperty("selfields", serialize($this->selected_column));
271  }
272 
273  $this->columns_determined = true;
274  }
275 
282  function isColumnSelected($a_col)
283  {
284  return $this->selected_column[$a_col];
285  }
286 
294  {
295  $scol = array();
296  foreach ($this->selected_column as $k => $v)
297  {
298  if ($v)
299  {
300  $scol[$k] = $k;
301  }
302  }
303  return $scol;
304  }
305 
309  function &executeCommand()
310  {
311  global $ilCtrl;
312 
313  $next_class = $ilCtrl->getNextClass($this);
314  $cmd = $ilCtrl->getCmd();
315 
316  switch($next_class)
317  {
318  case 'ilformpropertydispatchgui':
319  include_once './Services/Form/classes/class.ilFormPropertyDispatchGUI.php';
320  $form_prop_dispatch = new ilFormPropertyDispatchGUI();
321  $this->initFilter();
322  $item = $this->getFilterItemByPostVar($_GET["postvar"]);
323  $form_prop_dispatch->setItem($item);
324  return $ilCtrl->forwardCommand($form_prop_dispatch);
325  break;
326 
327  }
328  return false;
329  }
330 
334  function resetOffset($a_in_determination = false)
335  {
336  if (!$this->nav_determined && !$a_in_determination)
337  {
338  $this->determineOffsetAndOrder();
339  }
340  $this->nav_value = $this->getOrderField().":".$this->getOrderDirection().":0";
341  $_GET[$this->getNavParameter()] =
342  $_POST[$this->getNavParameter()."1"] =
343  $this->nav_value;
344 //echo $this->nav_value;
345  $this->setOffset(0);
346  }
347 
352  function initFilter()
353  {
354  }
355 
361  public function getParentObject()
362  {
363  return $this->parent_obj;
364  }
365 
371  public function getParentCmd()
372  {
373  return $this->parent_cmd;
374  }
375 
381  function setTopAnchor($a_val)
382  {
383  $this->top_anchor = $a_val;
384  }
385 
391  function getTopAnchor()
392  {
393  return $this->top_anchor;
394  }
395 
401  function setNoEntriesText($a_text)
402  {
403  $this->noentriestext = $a_text;
404  }
405 
411  function getNoEntriesText()
412  {
413  return $this->noentriestext;
414  }
415 
421  function setIsDataTable($a_val)
422  {
423  $this->datatable = $a_val;
424  }
425 
431  function getIsDataTable()
432  {
433  return $this->datatable;
434  }
435 
441  function setEnableTitle($a_enabletitle)
442  {
443  $this->enabled["title"] = $a_enabletitle;
444  }
445 
451  function getEnableTitle()
452  {
453  return $this->enabled["title"];
454  }
455 
461  function setEnableHeader($a_enableheader)
462  {
463  $this->enabled["header"] = $a_enableheader;
464  }
465 
471  function getEnableHeader()
472  {
473  return $this->enabled["header"];
474  }
475 
481  function setEnableNumInfo($a_val)
482  {
483  $this->num_info = $a_val;
484  }
485 
491  function getEnableNumInfo()
492  {
493  return $this->num_info;
494  }
495 
499  final public function setTitle($a_title, $a_icon = 0, $a_icon_alt = 0)
500  {
501  parent::setTitle($a_title, $a_icon, $a_icon_alt);
502  }
503 
509  function setDescription($a_val)
510  {
511  $this->description = $a_val;
512  }
513 
519  function getDescription()
520  {
521  return $this->description;
522  }
523 
529  function setOrderField($a_order_field)
530  {
531  $this->order_field = $a_order_field;
532  }
533 
534  function getOrderField()
535  {
536  return $this->order_field;
537  }
538 
539  final public function setData($a_data)
540  {
541  // check column names against given data (to ensure proper sorting)
542  if(DEVMODE &&
543  $this->enabled["header"] && $this->enabled["sort"] &&
544  $this->columns_determined && is_array($this->column) &&
545  is_array($a_data) && sizeof($a_data) && !$this->getExternalSorting())
546  {
547  $check = $a_data;
548  $check = array_keys(array_shift($check));
549  foreach($this->column as $col)
550  {
551  if($col["sort_field"] && !in_array($col["sort_field"], $check))
552  {
553  $invalid[] = $col["sort_field"];
554  }
555  }
556 
557  // this triggers an error, if some columns are not set for some rows
558  // which may just be a representation of "null" values, e.g.
559  // ilAdvancedMDValues:queryForRecords works that way.
560 /* if(sizeof($invalid))
561  {
562  trigger_error("The following columns are defined as sortable but".
563  " cannot be found in the given data: ".implode(", ", $invalid).
564  ". Sorting will not work properly.", E_USER_WARNING);
565  }*/
566  }
567 
568  $this->row_data = $a_data;
569  }
570 
571  final public function getData()
572  {
573  return $this->row_data;
574  }
575 
576  final public function dataExists()
577  {
578  if (is_array($this->row_data))
579  {
580  if (count($this->row_data) > 0)
581  {
582  return true;
583  }
584  }
585  return false;
586  }
587 
588  final public function setPrefix($a_prefix)
589  {
590  $this->prefix = $a_prefix;
591  }
592 
593  final public function getPrefix()
594  {
595  return $this->prefix;
596  }
597 
602  final function addFilterItem($a_input_item, $a_optional = false)
603  {
604  $a_input_item->setParent($this);
605  if (!$a_optional)
606  {
607  $this->filters[] = $a_input_item;
608  }
609  else
610  {
611  $this->optional_filters[] = $a_input_item;
612  }
613 
614  // restore filter values (from stored view)
615  if($this->restore_filter_values &&
616  array_key_exists($a_input_item->getFieldId(), $this->restore_filter_values))
617  {
618  $this->setFilterValue($a_input_item, $this->restore_filter_values[$a_input_item->getFieldId()]);
619  }
620  }
621 
631  function addFilterItemByMetaType($id, $type = self::FILTER_TEXT, $a_optional = false, $caption = NULL)
632  {
633  global $lng;
634 
635  if(!$caption)
636  {
637  $caption = $lng->txt($id);
638  }
639 
640  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
641 
642  switch($type)
643  {
644  case self::FILTER_SELECT:
645  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
646  $item = new ilSelectInputGUI($caption, $id);
647  break;
648 
649  case self::FILTER_DATE:
650  include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
651  $item = new ilDateTimeInputGUI($caption, $id);
652  $item->setMode(ilDateTimeInputGUI::MODE_INPUT);
653  break;
654 
655  case self::FILTER_TEXT:
656  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
657  $item = new ilTextInputGUI($caption, $id);
658  $item->setMaxLength(64);
659  $item->setSize(20);
660  // $item->setSubmitFormOnEnter(true);
661  break;
662 
663  case self::FILTER_LANGUAGE:
664  $lng->loadLanguageModule("meta");
665  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
666  $item = new ilSelectInputGUI($caption, $id);
667  $options = array("" => $lng->txt("trac_all"));
668  foreach ($lng->getInstalledLanguages() as $lang_key)
669  {
670  $options[$lang_key] = $lng->txt("meta_l_".$lang_key);
671  }
672  $item->setOptions($options);
673  break;
674 
675  case self::FILTER_NUMBER_RANGE:
676  include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
677  include_once("./Services/Form/classes/class.ilNumberInputGUI.php");
678  $item = new ilCombinationInputGUI($caption, $id);
679  $combi_item = new ilNumberInputGUI("", $id."_from");
680  $item->addCombinationItem("from", $combi_item, $lng->txt("from"));
681  $combi_item = new ilNumberInputGUI("", $id."_to");
682  $item->addCombinationItem("to", $combi_item, $lng->txt("to"));
683  $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
684  $item->setMaxLength(7);
685  $item->setSize(20);
686  break;
687 
688  case self::FILTER_DATE_RANGE:
689  include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
690  include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
691  $item = new ilCombinationInputGUI($caption, $id);
692  $combi_item = new ilDateTimeInputGUI("", $id."_from");
693  $item->addCombinationItem("from", $combi_item, $lng->txt("from"));
694  $combi_item = new ilDateTimeInputGUI("", $id."_to");
695  $item->addCombinationItem("to", $combi_item, $lng->txt("to"));
696  $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
697  $item->setMode(ilDateTimeInputGUI::MODE_INPUT);
698  break;
699 
700  case self::FILTER_DATETIME_RANGE:
701  include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
702  include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
703  $item = new ilCombinationInputGUI($caption, $id);
704  $combi_item = new ilDateTimeInputGUI("", $id."_from");
705  $combi_item->setShowTime(true);
706  $item->addCombinationItem("from", $combi_item, $lng->txt("from"));
707  $combi_item = new ilDateTimeInputGUI("", $id."_to");
708  $combi_item->setShowTime(true);
709  $item->addCombinationItem("to", $combi_item, $lng->txt("to"));
710  $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
711  $item->setMode(ilDateTimeInputGUI::MODE_INPUT);
712  break;
713 
714  case self::FILTER_DURATION_RANGE:
715  $lng->loadLanguageModule("form");
716  include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
717  include_once("./Services/Form/classes/class.ilDurationInputGUI.php");
718  $item = new ilCombinationInputGUI($caption, $id);
719  $combi_item = new ilDurationInputGUI("", $id."_from");
720  $combi_item->setShowMonths(false);
721  $combi_item->setShowDays(true);
722  $combi_item->setShowSeconds(true);
723  $item->addCombinationItem("from", $combi_item, $lng->txt("from"));
724  $combi_item = new ilDurationInputGUI("", $id."_to");
725  $combi_item->setShowMonths(false);
726  $combi_item->setShowDays(true);
727  $combi_item->setShowSeconds(true);
728  $item->addCombinationItem("to", $combi_item, $lng->txt("to"));
729  $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
730  break;
731 
732  default:
733  return false;
734  }
735 
736  $this->addFilterItem($item, $a_optional);
737  $item->readFromSession();
738  return $item;
739  }
740 
744  final function getFilterItems($a_optionals = false)
745  {
746  if (!$a_optionals)
747  {
748  return $this->filters;
749  }
751  }
752 
753  final function getFilterItemByPostVar($a_post_var)
754  {
755  foreach ($this->getFilterItems() as $item)
756  {
757  if ($item->getPostVar() == $a_post_var)
758  {
759  return $item;
760  }
761  }
762  foreach ($this->getFilterItems(true) as $item)
763  {
764  if ($item->getPostVar() == $a_post_var)
765  {
766  return $item;
767  }
768  }
769  return false;
770  }
771 
777  function setFilterCols($a_val)
778  {
779  $this->filter_cols = $a_val;
780  }
781 
787  function getFilterCols()
788  {
789  return $this->filter_cols;
790  }
791 
797  function setDisableFilterHiding($a_val = true)
798  {
799  $this->disable_filter_hiding = $a_val;
800  }
801 
808  {
810  }
811 
818  function isFilterSelected($a_col)
819  {
820  return $this->selected_filter[$a_col];
821  }
822 
830  {
831  $sfil = array();
832  foreach ($this->selected_filter as $k => $v)
833  {
834  if ($v)
835  {
836  $sfil[$k] = $k;
837  }
838  }
839  return $sfil;
840  }
841 
849  {
850  if ($this->filters_determined)
851  {
852  return;
853  }
854 
855  $old_sel = $this->loadProperty("selfilters");
856  $stored = false;
857  if ($old_sel != "")
858  {
859  $sel_filters =
860  @unserialize($old_sel);
861  $stored = true;
862  }
863  if(!is_array($sel_filters))
864  {
865  $stored = false;
866  $sel_filters = array();
867  }
868 
869  $this->selected_filter = array();
870  $set = false;
871  foreach ($this->getFilterItems(true) as $item)
872  {
873  $k = $item->getPostVar();
874 
875  $this->selected_filter[$k] = false;
876 
877  if ($_POST["tblfsf".$this->getId()])
878  {
879  $set = true;
880  if (is_array($_POST["tblff".$this->getId()]) && in_array($k, $_POST["tblff".$this->getId()]))
881  {
882  $this->selected_filter[$k] = true;
883  }
884  else
885  {
886  $item->setValue(NULL);
887  $item->writeToSession();
888  }
889  }
890  else if ($stored) // take stored values
891  {
892  $this->selected_filter[$k] = $sel_filters[$k];
893  }
894  }
895 
896  if ($old_sel != serialize($this->selected_filter) && $set)
897  {
898  $this->storeProperty("selfilters", serialize($this->selected_filter));
899  }
900 
901  $this->filters_determined = true;
902  }
903 
907  function setCustomPreviousNext($a_prev_link, $a_next_link)
908  {
909  $this->custom_prev_next = true;
910  $this->custom_prev = $a_prev_link;
911  $this->custom_next = $a_next_link;
912  }
913 
919  final public function setFormAction($a_form_action)
920  {
921  $this->form_action = $a_form_action;
922  }
923 
929  final public function getFormAction()
930  {
931  return $this->form_action;
932  }
933 
939  function setFormName($a_formname)
940  {
941  $this->formname = $a_formname;
942  }
943 
949  function getFormName()
950  {
951  return $this->formname;
952  }
953 
959  function setId($a_val)
960  {
961  $this->id = $a_val;
962  if ($this->getPrefix() == "")
963  {
964  $this->setPrefix($a_val);
965  }
966  }
967 
973  function getId()
974  {
975  return $this->id;
976  }
977 
983  function setDisplayAsBlock($a_val)
984  {
985  $this->display_as_block = $a_val;
986  }
987 
993  function getDisplayAsBlock()
994  {
995  return $this->display_as_block;
996  }
997 
1004  {
1006  }
1007 
1013  function setSelectAllCheckbox($a_select_all_checkbox)
1014  {
1015  $this->select_all_checkbox = $a_select_all_checkbox;
1016  }
1017 
1023  function setExternalSorting($a_val)
1024  {
1025  $this->ext_sort = $a_val;
1026  }
1027 
1034  {
1035  return $this->ext_sort;
1036  }
1037 
1043  function setFilterCommand($a_val)
1044  {
1045  $this->filter_cmd = $a_val;
1046  }
1047 
1053  function getFilterCommand()
1054  {
1055  return $this->filter_cmd;
1056  }
1057 
1063  function setResetCommand($a_val)
1064  {
1065  $this->reset_cmd = $a_val;
1066  }
1067 
1073  function getResetCommand()
1074  {
1075  return $this->reset_cmd;
1076  }
1077 
1083  function setExternalSegmentation($a_val)
1084  {
1085  $this->ext_seg = $a_val;
1086  }
1087 
1094  {
1095  return $this->ext_seg;
1096  }
1097 
1104  final public function setRowTemplate($a_template, $a_template_dir = "")
1105  {
1106  $this->row_template = $a_template;
1107  $this->row_template_dir = $a_template_dir;
1108  }
1109 
1115  function setDefaultOrderField($a_defaultorderfield)
1116  {
1117  $this->defaultorderfield = $a_defaultorderfield;
1118  }
1119 
1126  {
1127  return $this->defaultorderfield;
1128  }
1129 
1135  function setDefaultOrderDirection($a_defaultorderdirection)
1136  {
1137  $this->defaultorderdirection = $a_defaultorderdirection;
1138  }
1139 
1146  {
1147  return $this->defaultorderdirection;
1148  }
1149 
1150  /*
1151  * Removes all command buttons from the table
1152  *
1153  * @access public
1154  */
1155  public function clearCommandButtons()
1156  {
1157  $this->buttons = array();
1158  }
1159 
1166  function addCommandButton($a_cmd, $a_text, $a_onclick = '', $a_id = "")
1167  {
1168  $this->buttons[] = array("cmd" => $a_cmd, "text" => $a_text, 'onclick' => $a_onclick,
1169  "id" => $a_id);
1170  }
1171 
1182  function addSelectionButton($a_sel_var, $a_options, $a_cmd, $a_text, $a_default_selection = '')
1183  {
1184 echo "ilTabl2GUI->addSelectionButton() has been deprecated with 4.2. Please try to move the drop-down to ilToolbarGUI.";
1185 // $this->sel_buttons[] = array("sel_var" => $a_sel_var, "options" => $a_options, "selected" => $a_default_selection, "cmd" => $a_cmd, "text" => $a_text);
1186  }
1187 
1197  public function addMultiItemSelectionButton($a_sel_var, $a_options, $a_cmd, $a_text, $a_default_selection = '')
1198  {
1199  $this->mi_sel_buttons[] = array("sel_var" => $a_sel_var, "options" => $a_options, "selected" => $a_default_selection, "cmd" => $a_cmd, "text" => $a_text);
1200  $this->addHiddenInput("cmd_sv[".$a_cmd."]", $a_sel_var);
1201  }
1202 
1203 
1204 
1210  function setCloseCommand($a_link)
1211  {
1212  $this->close_command = $a_link;
1213  }
1214 
1221  function addMultiCommand($a_cmd, $a_text)
1222  {
1223  $this->multi[] = array("cmd" => $a_cmd, "text" => $a_text);
1224  }
1225 
1232  public function addHiddenInput($a_name, $a_value)
1233  {
1234  $this->hidden_inputs[] = array("name" => $a_name, "value" => $a_value);
1235  }
1236 
1243  function addHeaderCommand($a_href, $a_text, $a_target = "", $a_img = "")
1244  {
1245  $this->header_commands[] = array("href" => $a_href, "text" => $a_text,
1246  "target" => $a_target, "img" => $a_img);
1247  }
1248 
1254  function setTopCommands($a_val)
1255  {
1256  $this->top_commands = $a_val;
1257  }
1258 
1264  function getTopCommands()
1265  {
1266  return $this->top_commands;
1267  }
1268 
1276  final public function addColumn($a_text, $a_sort_field = "", $a_width = "",
1277  $a_is_checkbox_action_column = false, $a_class = "", $a_tooltip = "")
1278  {
1279  $this->column[] = array(
1280  "text" => $a_text,
1281  "sort_field" => $a_sort_field,
1282  "width" => $a_width,
1283  "is_checkbox_action_column" => $a_is_checkbox_action_column,
1284  "class" => $a_class,
1285  "tooltip" => $a_tooltip
1286  );
1287  $this->column_count = count($this->column);
1288  }
1289 
1290 
1291  final public function getNavParameter()
1292  {
1293  return $this->prefix."_table_nav";
1294  }
1295 
1296  function setOrderLink($sort_field, $order_dir)
1297  {
1298  global $ilCtrl, $ilUser;
1299 
1300  $hash = "";
1301  if (is_object($ilUser) && $ilUser->getPref("screen_reader_optimization"))
1302  {
1303  $hash = "#".$this->getTopAnchor();
1304  }
1305 
1306  $old = $_GET[$this->getNavParameter()];
1307 
1308  // set order link
1309  $ilCtrl->setParameter($this->parent_obj,
1310  $this->getNavParameter(),
1311  $sort_field.":".$order_dir.":".$this->offset);
1312  $this->tpl->setVariable("TBL_ORDER_LINK",
1313  $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd).$hash);
1314 
1315  // set old value of nav variable
1316  $ilCtrl->setParameter($this->parent_obj,
1317  $this->getNavParameter(), $old);
1318  }
1319 
1320  function fillHeader()
1321  {
1322  global $lng;
1323 
1324  $allcolumnswithwidth = true;
1325  foreach ((array) $this->column as $idx => $column)
1326  {
1327  if (!strlen($column["width"]))
1328  {
1329  $allcolumnswithwidth = false;
1330  }
1331  else if($column["width"] == "1")
1332  {
1333  // IE does not like 1 but seems to work with 1%
1334  $this->column[$idx]["width"] = "1%";
1335  }
1336  }
1337  if ($allcolumnswithwidth)
1338  {
1339  foreach ((array) $this->column as $column)
1340  {
1341  $this->tpl->setCurrentBlock("tbl_colgroup_column");
1342  $this->tpl->setVariable("COLGROUP_COLUMN_WIDTH", $column["width"]);
1343  $this->tpl->parseCurrentBlock();
1344  }
1345  }
1346  $ccnt = 0;
1347  foreach ((array) $this->column as $column)
1348  {
1349  $ccnt++;
1350 
1351  //tooltip
1352  if ($column["tooltip"] != "")
1353  {
1354  include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
1355  ilTooltipGUI::addTooltip("thc_".$this->getId()."_".$ccnt, $column["tooltip"]);
1356  }
1357  if (!$this->enabled["sort"] || $column["sort_field"] == "" || $column["is_checkbox_action_column"])
1358  {
1359  $this->tpl->setCurrentBlock("tbl_header_no_link");
1360  if ($column["width"] != "")
1361  {
1362  $this->tpl->setVariable("TBL_COLUMN_WIDTH_NO_LINK"," width=\"".$column["width"]."\"");
1363  }
1364  if (!$column["is_checkbox_action_column"])
1365  {
1366  $this->tpl->setVariable("TBL_HEADER_CELL_NO_LINK",
1367  $column["text"]);
1368  }
1369  else
1370  {
1371  $this->tpl->setVariable("TBL_HEADER_CELL_NO_LINK",
1372  ilUtil::img(ilUtil::getImagePath("spacer.png"), $lng->txt("action")));
1373  }
1374  $this->tpl->setVariable("HEAD_CELL_NL_ID", "thc_".$this->getId()."_".$ccnt);
1375 
1376  if ($column["class"] != "")
1377  {
1378  $this->tpl->setVariable("TBL_HEADER_CLASS"," " . $column["class"]);
1379  }
1380  $this->tpl->parseCurrentBlock();
1381  $this->tpl->touchBlock("tbl_header_th");
1382  continue;
1383  }
1384  if (($column["sort_field"] == $this->order_field) && ($this->order_direction != ""))
1385  {
1386  $this->tpl->setCurrentBlock("tbl_order_image");
1387  $this->tpl->setVariable("IMG_ORDER_DIR",ilUtil::getImagePath($this->order_direction."_order.png"));
1388  $this->tpl->setVariable("IMG_ORDER_ALT", $this->lng->txt("change_sort_direction"));
1389  $this->tpl->parseCurrentBlock();
1390  }
1391 
1392  $this->tpl->setCurrentBlock("tbl_header_cell");
1393  $this->tpl->setVariable("TBL_HEADER_CELL", $column["text"]);
1394  $this->tpl->setVariable("HEAD_CELL_ID", "thc_".$this->getId()."_".$ccnt);
1395 
1396  // only set width if a value is given for that column
1397  if ($column["width"] != "")
1398  {
1399  $this->tpl->setVariable("TBL_COLUMN_WIDTH"," width=\"".$column["width"]."\"");
1400  }
1401 
1402  $lng_sort_column = $this->lng->txt("sort_by_this_column");
1403  $this->tpl->setVariable("TBL_ORDER_ALT",$lng_sort_column);
1404 
1405  $order_dir = "asc";
1406 
1407  if ($column["sort_field"] == $this->order_field)
1408  {
1409  $order_dir = $this->sort_order;
1410 
1411  $lng_change_sort = $this->lng->txt("change_sort_direction");
1412  $this->tpl->setVariable("TBL_ORDER_ALT",$lng_change_sort);
1413  }
1414 
1415  if ($column["class"] != "")
1416  {
1417  $this->tpl->setVariable("TBL_HEADER_CLASS"," " . $column["class"]);
1418  }
1419  $this->setOrderLink($column["sort_field"], $order_dir);
1420  $this->tpl->parseCurrentBlock();
1421  $this->tpl->touchBlock("tbl_header_th");
1422  }
1423 
1424  $this->tpl->setCurrentBlock("tbl_header");
1425  $this->tpl->parseCurrentBlock();
1426  }
1427 
1431  protected function prepareOutput()
1432  {
1433  }
1434 
1435 
1439  function determineOffsetAndOrder($a_omit_offset = false)
1440  {
1441  global $ilUser;
1442 
1443  if ($this->nav_determined)
1444  {
1445  return true;
1446  }
1447 
1448  if ($_POST[$this->getNavParameter()."1"] != "")
1449  {
1450  if ($_POST[$this->getNavParameter()."1"] != $_POST[$this->getNavParameter()])
1451  {
1452  $this->nav_value = $_POST[$this->getNavParameter()."1"];
1453  }
1454  else if ($_POST[$this->getNavParameter()."2"] != $_POST[$this->getNavParameter()])
1455  {
1456  $this->nav_value = $_POST[$this->getNavParameter()."2"];
1457  }
1458  }
1459  elseif($_GET[$this->getNavParameter()])
1460  {
1461  $this->nav_value = $_GET[$this->getNavParameter()];
1462  }
1463  elseif($_SESSION[$this->getNavParameter()] != "")
1464  {
1465  $this->nav_value = $_SESSION[$this->getNavParameter()];
1466  }
1467 
1468  if ($this->nav_value == "" && $this->getId() != "" && $ilUser->getId() != ANONYMOUS_USER_ID)
1469  {
1470  // get order and direction from db
1471  $this->nav_value =
1472  $this->loadProperty("order").":".
1473  $this->loadProperty("direction").":".
1474  $this->loadProperty("offset");
1475  }
1476  $nav = explode(":", $this->nav_value);
1477 
1478  // $nav[0] is order by
1479  $this->setOrderField(($nav[0] != "") ? $nav[0] : $this->getDefaultOrderField());
1480  $this->setOrderDirection(($nav[1] != "") ? $nav[1] : $this->getDefaultOrderDirection());
1481 
1482  if (!$a_omit_offset)
1483  {
1484  // #8904: offset must be discarded when no limit is given
1485  if(!$this->getExternalSegmentation() && $this->limit_determined && $this->limit == 9999)
1486  {
1487  $this->resetOffset(true);
1488  }
1489  else if (!$this->getExternalSegmentation() && $nav[2] >= $this->max_count)
1490  {
1491  $this->resetOffset(true);
1492  }
1493  else
1494  {
1495  $this->setOffset($nav[2]);
1496  }
1497  }
1498 
1499  if (!$a_omit_offset)
1500  {
1501  $this->nav_determined = true;
1502  }
1503  }
1504 
1506  {
1507  if ($this->getOrderField() != "")
1508  {
1509  $this->storeProperty("order", $this->getOrderField());
1510  }
1511  if ($this->getOrderDirection() != "")
1512  {
1513  $this->storeProperty("direction", $this->getOrderDirection());
1514  }
1515 //echo "-".$this->getOffset()."-";
1516  if ($this->getOffset() !== "")
1517  {
1518  $this->storeProperty("offset", $this->getOffset());
1519  }
1520  }
1521 
1522 
1526  final public function getHTML()
1527  {
1528  global $lng, $ilCtrl, $ilUser;
1529 
1530  if($this->getExportMode())
1531  {
1532  $this->exportData($this->getExportMode(), true);
1533  }
1534 
1535  $this->prepareOutput();
1536 
1537  if (is_object($ilCtrl) && $this->getId() == "")
1538  {
1539  $ilCtrl->saveParameter($this->getParentObject(), $this->getNavParameter());
1540  }
1541 
1542  if(!$this->getPrintMode())
1543  {
1544  // set form action
1545  if ($this->form_action != "" && $this->getOpenFormTag())
1546  {
1547  $hash = "";
1548  if (is_object($ilUser) && $ilUser->getPref("screen_reader_optimization"))
1549  {
1550  $hash = "#".$this->getTopAnchor();
1551  }
1552 
1553  $this->tpl->setCurrentBlock("tbl_form_header");
1554  $this->tpl->setVariable("FORMACTION", $this->getFormAction().$hash);
1555  $this->tpl->setVariable("FORMNAME", $this->getFormName());
1556  $this->tpl->parseCurrentBlock();
1557  }
1558 
1559  if ($this->form_action != "" && $this->getCloseFormTag())
1560  {
1561  $this->tpl->touchBlock("tbl_form_footer");
1562  }
1563  }
1564 
1565  if(!$this->enabled['content'])
1566  {
1567  return $this->render();
1568  }
1569 
1570  if (!$this->getExternalSegmentation())
1571  {
1572  $this->setMaxCount(count($this->row_data));
1573  }
1574 
1575  $this->determineOffsetAndOrder();
1576 
1577  $this->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
1578 
1579  $data = $this->getData();
1580  if($this->dataExists())
1581  {
1582  // sort
1583  if (!$this->getExternalSorting() && $this->enabled["sort"])
1584  {
1585  $data = ilUtil::sortArray($data, $this->getOrderField(),
1586  $this->getOrderDirection(), $this->numericOrdering($this->getOrderField()));
1587  }
1588 
1589  // slice
1590  if (!$this->getExternalSegmentation())
1591  {
1592  $data = array_slice($data, $this->getOffset(), $this->getLimit());
1593  }
1594  }
1595 
1596  // fill rows
1597  if($this->dataExists())
1598  {
1599  if($this->getPrintMode())
1600  {
1602  }
1603 
1604  $this->tpl->addBlockFile("TBL_CONTENT", "tbl_content", $this->row_template,
1605  $this->row_template_dir);
1606 
1607  foreach($data as $set)
1608  {
1609  $this->tpl->setCurrentBlock("tbl_content");
1610  $this->css_row = ($this->css_row != "tblrow1")
1611  ? "tblrow1"
1612  : "tblrow2";
1613  $this->tpl->setVariable("CSS_ROW", $this->css_row);
1614 
1615  $this->fillRow($set);
1616  $this->tpl->setCurrentBlock("tbl_content");
1617  $this->tpl->parseCurrentBlock();
1618  }
1619  }
1620  else
1621  {
1622  // add standard no items text (please tell me, if it messes something up, alex, 29.8.2008)
1623  $no_items_text = (trim($this->getNoEntriesText()) != '')
1624  ? $this->getNoEntriesText()
1625  : $lng->txt("no_items");
1626 
1627  $this->css_row = ($this->css_row != "tblrow1")
1628  ? "tblrow1"
1629  : "tblrow2";
1630 
1631  $this->tpl->setCurrentBlock("tbl_no_entries");
1632  $this->tpl->setVariable('TBL_NO_ENTRY_CSS_ROW', $this->css_row);
1633  $this->tpl->setVariable('TBL_NO_ENTRY_COLUMN_COUNT', $this->column_count);
1634  $this->tpl->setVariable('TBL_NO_ENTRY_TEXT', trim($no_items_text));
1635  $this->tpl->parseCurrentBlock();
1636  }
1637 
1638 
1639  if(!$this->getPrintMode())
1640  {
1641  $this->fillFooter();
1642 
1643  $this->fillHiddenRow();
1644 
1645  $this->fillActionRow();
1646 
1647  $this->storeNavParameter();
1648  }
1649 
1650  return $this->render();
1651  }
1652 
1658  function numericOrdering($a_field)
1659  {
1660  return false;
1661  }
1662 
1667  function render()
1668  {
1669  global $lng, $ilCtrl;
1670 
1671  $this->tpl->setVariable("CSS_TABLE",$this->getStyle("table"));
1672  $this->tpl->setVariable("DATA_TABLE", (int) $this->getIsDataTable());
1673  if ($this->getId() != "")
1674  {
1675  $this->tpl->setVariable("ID", 'id="'.$this->getId().'"');
1676  }
1677 
1678  // description
1679  if ($this->getDescription() != "")
1680  {
1681  $this->tpl->setCurrentBlock("tbl_header_description");
1682  $this->tpl->setVariable("TBL_DESCRIPTION", $this->getDescription());
1683  $this->tpl->parseCurrentBlock();
1684  }
1685 
1686  if(!$this->getPrintMode())
1687  {
1688  $this->renderFilter();
1689  }
1690 
1691  if ($this->getDisplayAsBlock())
1692  {
1693  $this->tpl->touchBlock("outer_start_1");
1694  $this->tpl->touchBlock("outer_end_1");
1695  }
1696  else
1697  {
1698  $this->tpl->touchBlock("outer_start_2");
1699  $this->tpl->touchBlock("outer_end_2");
1700  }
1701 
1702  // table title and icon
1703  if ($this->enabled["title"] && ($this->title != ""
1704  || $this->icon != "" || count($this->header_commands) > 0 ||
1705  $this->headerHTML != "" || $this->close_command != ""))
1706  {
1707  if ($this->enabled["icon"])
1708  {
1709  $this->tpl->setCurrentBlock("tbl_header_title_icon");
1710  $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath($this->icon));
1711  $this->tpl->setVariable("TBL_TITLE_IMG_ALT",$this->icon_alt);
1712  $this->tpl->parseCurrentBlock();
1713  }
1714 
1715  if(!$this->getPrintMode())
1716  {
1717  foreach($this->header_commands as $command)
1718  {
1719  if ($command["img"] != "")
1720  {
1721  $this->tpl->setCurrentBlock("tbl_header_img_link");
1722  if ($command["target"] != "")
1723  {
1724  $this->tpl->setVariable("TARGET_IMG_LINK",
1725  'target="'.$command["target"].'"');
1726  }
1727  $this->tpl->setVariable("ALT_IMG_LINK", $command["text"]);
1728  $this->tpl->setVariable("HREF_IMG_LINK", $command["href"]);
1729  $this->tpl->setVariable("SRC_IMG_LINK",
1730  $command["img"]);
1731  $this->tpl->parseCurrentBlock();
1732  }
1733  else
1734  {
1735  $this->tpl->setCurrentBlock("head_cmd");
1736  $this->tpl->setVariable("TXT_HEAD_CMD", $command["text"]);
1737  $this->tpl->setVariable("HREF_HEAD_CMD", $command["href"]);
1738  $this->tpl->parseCurrentBlock();
1739  }
1740  }
1741  }
1742 
1743  if (isset ($this->headerHTML)) {
1744  $this->tpl->setCurrentBlock("tbl_header_html");
1745  $this->tpl->setVariable ("HEADER_HTML", $this->headerHTML);
1746  $this->tpl->parseCurrentBlock();
1747  }
1748 
1749  // close command
1750  if ($this->close_command != "")
1751  {
1752  $this->tpl->setCurrentBlock("tbl_header_img_link");
1753  $this->tpl->setVariable("ALT_IMG_LINK",$lng->txt("close"));
1754  $this->tpl->setVariable("HREF_IMG_LINK",$this->close_command);
1755  $this->tpl->setVariable("SRC_IMG_LINK",ilUtil::getImagePath("icon_close2.png"));
1756  $this->tpl->parseCurrentBlock();
1757  }
1758 
1759  $this->tpl->setCurrentBlock("tbl_header_title");
1760  $this->tpl->setVariable("TBL_TITLE",$this->title);
1761  $this->tpl->setVariable("TOP_ANCHOR",$this->getTopAnchor());
1762  if ($this->getDisplayAsBlock())
1763  {
1764  $this->tpl->setVariable("BLK_CLASS", "Block");
1765  }
1766  $this->tpl->parseCurrentBlock();
1767  }
1768 
1769  // table header
1770  if ($this->enabled["header"])
1771  {
1772  $this->fillHeader();
1773  }
1774 
1775  $this->tpl->touchBlock("tbl_table_end");
1776 
1777  return $this->tpl->get();
1778  }
1779 
1783  private function renderFilter()
1784  {
1785  global $lng, $tpl;
1786 
1787  $filter = $this->getFilterItems();
1788  $opt_filter = $this->getFilterItems(true);
1789 
1790  $tpl->addJavascript("./Services/Table/js/ServiceTable.js");
1791 
1792  if (count($filter) == 0 && count($opt_filter) == 0)
1793  {
1794  return;
1795  }
1796 
1797  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
1799 
1800  $ccnt = 0;
1801 
1802  // render standard filter
1803  if (count($filter) > 0)
1804  {
1805  foreach ($filter as $item)
1806  {
1807  if ($ccnt >= $this->getFilterCols())
1808  {
1809  $this->tpl->setCurrentBlock("filter_row");
1810  $this->tpl->parseCurrentBlock();
1811  $ccnt = 0;
1812  }
1813  $this->tpl->setCurrentBlock("filter_item");
1814  $this->tpl->setVariable("OPTION_NAME",
1815  $item->getTitle());
1816  $this->tpl->setVariable("F_INPUT_ID",
1817  $item->getFieldId());
1818  $this->tpl->setVariable("INPUT_HTML",
1819  $item->getTableFilterHTML());
1820  $this->tpl->parseCurrentBlock();
1821  $ccnt++;
1822  }
1823  }
1824 
1825  // render optional filter
1826  if (count($opt_filter) > 0)
1827  {
1828  $this->determineSelectedFilters();
1829 
1830  foreach ($opt_filter as $item)
1831  {
1832  if($this->isFilterSelected($item->getPostVar()))
1833  {
1834  if ($ccnt >= $this->getFilterCols())
1835  {
1836  $this->tpl->setCurrentBlock("filter_row");
1837  $this->tpl->parseCurrentBlock();
1838  $ccnt = 0;
1839  }
1840  $this->tpl->setCurrentBlock("filter_item");
1841  $this->tpl->setVariable("OPTION_NAME",
1842  $item->getTitle());
1843  $this->tpl->setVariable("F_INPUT_ID",
1844  $item->getFieldId());
1845  $this->tpl->setVariable("INPUT_HTML",
1846  $item->getTableFilterHTML());
1847  $this->tpl->parseCurrentBlock();
1848  $ccnt++;
1849  }
1850  }
1851 
1852  // filter selection
1853  $items = array();
1854  foreach ($opt_filter as $item)
1855  {
1856  $k = $item->getPostVar();
1857  $items[$k] = array("txt" => $item->getTitle(),
1858  "selected" => $this->isFilterSelected($k));
1859  }
1860 
1861  include_once("./Services/UIComponent/CheckboxListOverlay/classes/class.ilCheckboxListOverlayGUI.php");
1862  $cb_over = new ilCheckboxListOverlayGUI("tbl_filters_".$this->getId());
1863  $cb_over->setLinkTitle($lng->txt("optional_filters"));
1864  $cb_over->setItems($items);
1865 
1866  $cb_over->setFormCmd($this->getParentCmd());
1867  $cb_over->setFieldVar("tblff".$this->getId());
1868  $cb_over->setHiddenVar("tblfsf".$this->getId());
1869 
1870  $cb_over->setSelectionHeaderClass("ilTableMenuItem");
1871  $this->tpl->setCurrentBlock("filter_select");
1872 
1873  // apply should be the first submit because of enter/return, inserting hidden submit
1874  $this->tpl->setVariable("HIDDEN_CMD_APPLY", $this->filter_cmd);
1875 
1876  $this->tpl->setVariable("FILTER_SELECTOR", $cb_over->getHTML());
1877  $this->tpl->parseCurrentBlock();
1878  }
1879 
1880  // if any filter
1881  if($ccnt > 0 || count($opt_filter) > 0)
1882  {
1883  $this->tpl->setVariable("TXT_FILTER", $lng->txt("filter"));
1884 
1885  if($ccnt > 0)
1886  {
1887  if ($ccnt < $this->getFilterCols())
1888  {
1889  for($i = $ccnt; $i<=$this->getFilterCols(); $i++)
1890  {
1891  $this->tpl->touchBlock("filter_empty_cell");
1892  }
1893  }
1894  $this->tpl->setCurrentBlock("filter_row");
1895  $this->tpl->parseCurrentBlock();
1896 
1897  $this->tpl->setCurrentBlock("filter_buttons");
1898  $this->tpl->setVariable("CMD_APPLY", $this->filter_cmd);
1899  $this->tpl->setVariable("TXT_APPLY", $lng->txt("apply_filter"));
1900  $this->tpl->setVariable("CMD_RESET", $this->reset_cmd);
1901  $this->tpl->setVariable("TXT_RESET", $lng->txt("reset_filter"));
1902  }
1903  else if(count($opt_filter) > 0)
1904  {
1905  $this->tpl->setCurrentBlock("optional_filter_hint");
1906  $this->tpl->setVariable('TXT_OPT_HINT', $lng->txt('optional_filter_hint'));
1907  $this->tpl->parseCurrentBlock();
1908  }
1909 
1910  $this->tpl->setCurrentBlock("filter_section");
1911  $this->tpl->setVariable("FIL_ID", $this->getId());
1912  $this->tpl->parseCurrentBlock();
1913 
1914  // (keep) filter hidden?
1915  if ($this->loadProperty("filter") != 1)
1916  {
1917  if (!$this->getDisableFilterHiding())
1918  {
1919  $this->tpl->setCurrentBlock("filter_hidden");
1920  $this->tpl->setVariable("FI_ID", $this->getId());
1921  $this->tpl->parseCurrentBlock();
1922  }
1923  }
1924  }
1925  }
1926 
1930  public function writeFilterToSession()
1931  {
1932  global $lng;
1933 
1934  $filter = $this->getFilterItems();
1935  $opt_filter = $this->getFilterItems(true);
1936 
1937  foreach ($filter as $item)
1938  {
1939  if ($item->checkInput())
1940  {
1941  $item->setValueByArray($_POST);
1942  $item->writeToSession();
1943  }
1944  }
1945  foreach ($opt_filter as $item)
1946  {
1947  if ($item->checkInput())
1948  {
1949  $item->setValueByArray($_POST);
1950  $item->writeToSession();
1951  }
1952  }
1953 
1954  // #13209
1955  unset($_REQUEST["tbltplcrt"]);
1956  unset($_REQUEST["tbltpldel"]);
1957  }
1958 
1962  public function resetFilter()
1963  {
1964  global $lng;
1965 
1966  $filter = $this->getFilterItems();
1967  $opt_filter = $this->getFilterItems(true);
1968 
1969  foreach ($filter as $item)
1970  {
1971  if ($item->checkInput())
1972  {
1973  $item->setValueByArray($_POST);
1974  $item->clearFromSession();
1975  }
1976  }
1977  foreach ($opt_filter as $item)
1978  {
1979  if ($item->checkInput())
1980  {
1981  $item->setValueByArray($_POST);
1982  $item->clearFromSession();
1983  }
1984  }
1985 
1986  // #13209
1987  unset($_REQUEST["tbltplcrt"]);
1988  unset($_REQUEST["tbltpldel"]);
1989  }
1990 
1997  protected function fillRow($a_set)
1998  {
1999  foreach ($a_set as $key => $value)
2000  {
2001  $this->tpl->setVariable("VAL_".strtoupper($key), $value);
2002  }
2003  }
2004 
2008  function fillFooter()
2009  {
2010  global $lng, $ilCtrl, $ilUser;
2011 
2012  $footer = false;
2013 
2014  // select all checkbox
2015  if ((strlen($this->getFormName())) && (strlen($this->getSelectAllCheckbox())) && $this->dataExists())
2016  {
2017  $this->tpl->setCurrentBlock("select_all_checkbox");
2018  $this->tpl->setVariable("SELECT_ALL_TXT_SELECT_ALL", $lng->txt("select_all"));
2019  $this->tpl->setVariable("SELECT_ALL_CHECKBOX_NAME", $this->getSelectAllCheckbox());
2020  $this->tpl->setVariable("SELECT_ALL_FORM_NAME", $this->getFormName());
2021  $this->tpl->setVariable("CHECKBOXNAME", "chb_select_all_" . $this->unique_id);
2022  $this->tpl->parseCurrentBlock();
2023  }
2024 
2025  // table footer numinfo
2026  if ($this->enabled["numinfo"] && $this->enabled["footer"])
2027  {
2028  $start = $this->offset + 1; // compute num info
2029  if (!$this->dataExists())
2030  {
2031  $start = 0;
2032  }
2033  $end = $this->offset + $this->limit;
2034 
2035  if ($end > $this->max_count or $this->limit == 0)
2036  {
2037  $end = $this->max_count;
2038  }
2039 
2040  if ($this->max_count > 0)
2041  {
2042  if ($this->lang_support)
2043  {
2044  $numinfo = "(".$start." - ".$end." ".strtolower($this->lng->txt("of"))." ".$this->max_count.")";
2045  }
2046  else
2047  {
2048  $numinfo = "(".$start." - ".$end." of ".$this->max_count.")";
2049  }
2050  }
2051  if ($this->max_count > 0)
2052  {
2053  if ($this->getEnableNumInfo())
2054  {
2055  $this->tpl->setCurrentBlock("tbl_footer_numinfo");
2056  $this->tpl->setVariable("NUMINFO", $numinfo);
2057  $this->tpl->parseCurrentBlock();
2058  }
2059  }
2060  $footer = true;
2061  }
2062 
2063  // table footer linkbar
2064  if ($this->enabled["linkbar"] && $this->enabled["footer"] && $this->limit != 0
2065  && $this->max_count > 0)
2066  {
2067  $layout = array(
2068  "link" => $this->footer_style,
2069  "prev" => $this->footer_previous,
2070  "next" => $this->footer_next,
2071  );
2072  //if (!$this->getDisplayAsBlock())
2073  //{
2074  $linkbar = $this->getLinkbar("1");
2075  $this->tpl->setCurrentBlock("tbl_footer_linkbar");
2076  $this->tpl->setVariable("LINKBAR", $linkbar);
2077  $this->tpl->parseCurrentBlock();
2078  $linkbar = true;
2079  //}
2080  $footer = true;
2081  }
2082 
2083  // column selector
2084  if (count($this->getSelectableColumns()) > 0)
2085  {
2086  $items = array();
2087  foreach ($this->getSelectableColumns() as $k => $c)
2088  {
2089  $items[$k] = array("txt" => $c["txt"],
2090  "selected" => $this->isColumnSelected($k));
2091  }
2092  include_once("./Services/UIComponent/CheckboxListOverlay/classes/class.ilCheckboxListOverlayGUI.php");
2093  $cb_over = new ilCheckboxListOverlayGUI("tbl_".$this->getId());
2094  $cb_over->setLinkTitle($lng->txt("columns"));
2095  $cb_over->setItems($items);
2096  //$cb_over->setUrl("./ilias.php?baseClass=ilTablePropertiesStorage&table_id=".
2097  // $this->getId()."&cmd=saveSelectedFields&user_id=".$ilUser->getId());
2098  $cb_over->setFormCmd($this->getParentCmd());
2099  $cb_over->setFieldVar("tblfs".$this->getId());
2100  $cb_over->setHiddenVar("tblfsh".$this->getId());
2101  $cb_over->setSelectionHeaderClass("ilTableMenuItem");
2102  $column_selector = $cb_over->getHTML();
2103  $footer = true;
2104  }
2105 
2106  if($this->getShowTemplates() && is_object($ilUser))
2107  {
2108  // template handling
2109  if(isset($_REQUEST["tbltplcrt"]) && $_REQUEST["tbltplcrt"])
2110  {
2111  if($this->saveTemplate($_REQUEST["tbltplcrt"]))
2112  {
2113  ilUtil::sendSuccess($lng->txt("tbl_template_created"));
2114  }
2115  }
2116  else if(isset($_REQUEST["tbltpldel"]) && $_REQUEST["tbltpldel"])
2117  {
2118  if($this->deleteTemplate($_REQUEST["tbltpldel"]))
2119  {
2120  ilUtil::sendSuccess($lng->txt("tbl_template_deleted"));
2121  }
2122  }
2123 
2124  $create_id = "template_create_overlay_".$this->getId();
2125  $delete_id = "template_delete_overlay_".$this->getId();
2126  $list_id = "template_stg_".$this->getId();
2127 
2128  include_once("./Services/Table/classes/class.ilTableTemplatesStorage.php");
2129  $storage = new ilTableTemplatesStorage();
2130  $templates = $storage->getNames($this->getContext(), $ilUser->getId());
2131 
2132  include_once("./Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php");
2133 
2134  // form to delete template
2135  if(sizeof($templates))
2136  {
2137  $overlay = new ilOverlayGUI($delete_id);
2138  $overlay->setTrigger($list_id."_delete");
2139  $overlay->setAnchor("ilAdvSelListAnchorElement_".$list_id);
2140  $overlay->setAutoHide(false);
2141  $overlay->add();
2142 
2143  $lng->loadLanguageModule("form");
2144  $this->tpl->setCurrentBlock("template_editor_delete_item");
2145  $this->tpl->setVariable("TEMPLATE_DELETE_OPTION_VALUE", "");
2146  $this->tpl->setVariable("TEMPLATE_DELETE_OPTION", "- ".$lng->txt("form_please_select")." -");
2147  $this->tpl->parseCurrentBlock();
2148  foreach($templates as $name)
2149  {
2150  $this->tpl->setVariable("TEMPLATE_DELETE_OPTION_VALUE", $name);
2151  $this->tpl->setVariable("TEMPLATE_DELETE_OPTION", $name);
2152  $this->tpl->parseCurrentBlock();
2153  }
2154 
2155  $this->tpl->setCurrentBlock("template_editor_delete");
2156  $this->tpl->setVariable("TEMPLATE_DELETE_ID", $delete_id);
2157  $this->tpl->setVariable("TXT_TEMPLATE_DELETE", $lng->txt("tbl_template_delete"));
2158  $this->tpl->setVariable("TXT_TEMPLATE_DELETE_SUBMIT", $lng->txt("delete"));
2159  $this->tpl->setVariable("TEMPLATE_DELETE_CMD", $this->parent_cmd);
2160  $this->tpl->parseCurrentBlock();
2161  }
2162 
2163 
2164  // form to save new template
2165  $overlay = new ilOverlayGUI($create_id);
2166  $overlay->setTrigger($list_id."_create");
2167  $overlay->setAnchor("ilAdvSelListAnchorElement_".$list_id);
2168  $overlay->setAutoHide(false);
2169  $overlay->add();
2170 
2171  $this->tpl->setCurrentBlock("template_editor");
2172  $this->tpl->setVariable("TEMPLATE_CREATE_ID", $create_id);
2173  $this->tpl->setVariable("TXT_TEMPLATE_CREATE", $lng->txt("tbl_template_create"));
2174  $this->tpl->setVariable("TXT_TEMPLATE_CREATE_SUBMIT", $lng->txt("save"));
2175  $this->tpl->setVariable("TEMPLATE_CREATE_CMD", $this->parent_cmd);
2176  $this->tpl->parseCurrentBlock();
2177 
2178  // load saved template
2179  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
2180  $alist = new ilAdvancedSelectionListGUI();
2181  $alist->setId($list_id);
2182  $alist->addItem($lng->txt("tbl_template_create"), "create", "#");
2183  if(sizeof($templates))
2184  {
2185  $alist->addItem($lng->txt("tbl_template_delete"), "delete", "#");
2186  foreach($templates as $name)
2187  {
2188  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_tpl", urlencode($name));
2189  $alist->addItem($name, $name, $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd));
2190  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_tpl", "");
2191  }
2192  }
2193  $alist->setListTitle($lng->txt("tbl_templates"));
2194  $this->tpl->setVariable("TEMPLATE_SELECTOR", "&nbsp;".$alist->getHTML());
2195  }
2196 
2197  if ($footer)
2198  {
2199  $this->tpl->setCurrentBlock("tbl_footer");
2200  $this->tpl->setVariable("COLUMN_COUNT", $this->getColumnCount());
2201  if ($this->getDisplayAsBlock())
2202  {
2203  $this->tpl->setVariable("BLK_CLASS", "Block");
2204  }
2205  $this->tpl->parseCurrentBlock();
2206 
2207  // top navigation, if number info or linkbar given
2208  if ($numinfo != "" || $linkbar != "" || $column_selector != "" ||
2209  count($this->filters) > 0 || count($this->optional_filters) > 0)
2210  {
2211  if (is_object($ilUser) && (count($this->filters) || count($this->optional_filters)))
2212  {
2213  $this->tpl->setCurrentBlock("filter_activation");
2214  $this->tpl->setVariable("TXT_ACTIVATE_FILTER", $lng->txt("show_filter"));
2215  $this->tpl->setVariable("FILA_ID", $this->getId());
2216  if ($this->getId() != "")
2217  {
2218  $this->tpl->setVariable("SAVE_URLA", "./ilias.php?baseClass=ilTablePropertiesStorage&table_id=".
2219  $this->getId()."&cmd=showFilter&user_id=".$ilUser->getId());
2220  }
2221  $this->tpl->parseCurrentBlock();
2222 
2223 
2224  if (!$this->getDisableFilterHiding())
2225  {
2226  $this->tpl->setCurrentBlock("filter_deactivation");
2227  $this->tpl->setVariable("TXT_HIDE", $lng->txt("hide_filter"));
2228  if ($this->getId() != "")
2229  {
2230  $this->tpl->setVariable("SAVE_URL", "./ilias.php?baseClass=ilTablePropertiesStorage&table_id=".
2231  $this->getId()."&cmd=hideFilter&user_id=".$ilUser->getId());
2232  $this->tpl->setVariable("FILD_ID", $this->getId());
2233  }
2234  $this->tpl->parseCurrentBlock();
2235  }
2236 
2237  }
2238 
2239  if ($numinfo != "" && $this->getEnableNumInfo())
2240  {
2241  $this->tpl->setCurrentBlock("top_numinfo");
2242  $this->tpl->setVariable("NUMINFO", $numinfo);
2243  $this->tpl->parseCurrentBlock();
2244  }
2245  if ($linkbar != "" && !$this->getDisplayAsBlock())
2246  {
2247  $linkbar = $this->getLinkbar("2");
2248  $this->tpl->setCurrentBlock("top_linkbar");
2249  $this->tpl->setVariable("LINKBAR", $linkbar);
2250  $this->tpl->parseCurrentBlock();
2251  }
2252 
2253  // column selector
2254  $this->tpl->setVariable("COLUMN_SELECTOR", $column_selector);
2255 
2256  // row selector
2257  if ($this->getShowRowsSelector() && is_object($ilUser))
2258  {
2259  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
2260  $alist = new ilAdvancedSelectionListGUI();
2261  $alist->setId("sellst_rows_".$this->getId());
2262  $hpp = ($ilUser->getPref("hits_per_page") != 9999)
2263  ? $ilUser->getPref("hits_per_page")
2264  : $lng->txt("unlimited");
2265 
2266  $options = array(0 => $lng->txt("default")." (".$hpp.")",5 => 5, 10 => 10, 15 => 15, 20 => 20,
2267  30 => 30, 40 => 40, 50 => 50,
2268  100 => 100, 200 => 200, 400 => 400, 800 => 800);
2269  foreach ($options as $k => $v)
2270  {
2271  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_trows", $k);
2272  $alist->addItem($v, $k, $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd));
2273  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_trows", "");
2274  }
2275  $alist->setListTitle($this->getRowSelectorLabel() ? $this->getRowSelectorLabel() : $lng->txt("rows"));
2276  $this->tpl->setVariable("ROW_SELECTOR", $alist->getHTML());
2277  }
2278 
2279  // export
2280  if(sizeof($this->export_formats) && $this->dataExists())
2281  {
2282  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
2283  $alist = new ilAdvancedSelectionListGUI();
2284  $alist->setId("sellst_xpt");
2285  foreach($this->export_formats as $format => $caption_lng_id)
2286  {
2287  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_xpt", $format);
2288  $url = $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd);
2289  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_xpt", "");
2290  $alist->addItem($lng->txt($caption_lng_id), $format, $url);
2291  }
2292  $alist->setListTitle($lng->txt("export"));
2293  $this->tpl->setVariable("EXPORT_SELECTOR", "&nbsp;".$alist->getHTML());
2294  }
2295 
2296  $this->tpl->setCurrentBlock("top_navigation");
2297  $this->tpl->setVariable("COLUMN_COUNT", $this->getColumnCount());
2298  if ($this->getDisplayAsBlock())
2299  {
2300  $this->tpl->setVariable("BLK_CLASS", "Block");
2301  }
2302  $this->tpl->parseCurrentBlock();
2303  }
2304  }
2305  }
2306 
2314  function getLinkbar($a_num)
2315  {
2316  global $ilCtrl, $lng, $ilUser;
2317 
2318  $hash = "";
2319  if (is_object($ilUser) && $ilUser->getPref("screen_reader_optimization"))
2320  {
2321  $hash = "#".$this->getTopAnchor();
2322  }
2323 
2324  $link = $ilCtrl->getLinkTargetByClass(get_class($this->parent_obj), $this->parent_cmd).
2325  "&".$this->getNavParameter()."=".
2326  $this->getOrderField().":".$this->getOrderDirection().":";
2327 
2328  $LinkBar = "";
2329  $layout_prev = $lng->txt("previous");
2330  $layout_next = $lng->txt("next");
2331 
2332  // if more entries then entries per page -> show link bar
2333  if ($this->max_count > $this->getLimit() || $this->custom_prev_next)
2334  {
2335  $sep = "<span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>";
2336 
2337  // calculate number of pages
2338  $pages = intval($this->max_count / $this->getLimit());
2339 
2340  // add a page if a rest remains
2341  if (($this->max_count % $this->getLimit()))
2342  $pages++;
2343 
2344  // links to other pages
2345  $offset_arr = array();
2346  for ($i = 1 ;$i <= $pages ; $i++)
2347  {
2348  $newoffset = $this->getLimit() * ($i-1);
2349 
2350  $nav_value = $this->getOrderField().":".$this->getOrderDirection().":".$newoffset;
2351  $offset_arr[$nav_value] = $i;
2352  }
2353 
2354  $sep = "<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
2355 
2356  // previous link
2357  if ($this->custom_prev_next && $this->custom_prev != "")
2358  {
2359  if ($LinkBar != "")
2360  $LinkBar .= $sep;
2361  $LinkBar .= "<a href=\"".$this->custom_prev.$hash."\">".$layout_prev."</a>";
2362  }
2363  else if ($this->getOffset() >= 1 && !$this->custom_prev_next)
2364  {
2365  if ($LinkBar != "")
2366  $LinkBar .= $sep;
2367  $prevoffset = $this->getOffset() - $this->getLimit();
2368  $LinkBar .= "<a href=\"".$link.$prevoffset.$hash."\">".$layout_prev."</a>";
2369  }
2370  else
2371  {
2372  if ($LinkBar != "")
2373  $LinkBar .= $sep;
2374  $LinkBar .= '<span class="ilTableFootLight">'.$layout_prev."</span>";
2375  }
2376 
2377  // current value
2378  if ($a_num == "1")
2379  {
2380  $LinkBar .= '<input type="hidden" name="'.$this->getNavParameter().
2381  '" value="'.$this->getOrderField().":".$this->getOrderDirection().":".$this->getOffset().'" />';
2382  }
2383 
2384  $sep = "<span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>";
2385 
2386  // show next link (if not last page)
2387  if ($this->custom_prev_next && $this->custom_next != "")
2388  {
2389  if ($LinkBar != "")
2390  $LinkBar .= $sep;
2391  $LinkBar .= "<a href=\"".$this->custom_next.$hash."\">".$layout_next."</a>";
2392  }
2393  else if (! ( ($this->getOffset() / $this->getLimit())==($pages-1) ) && ($pages!=1) &&
2394  !$this->custom_prev_next)
2395  {
2396  if ($LinkBar != "")
2397  $LinkBar .= $sep;
2398  $newoffset = $this->getOffset() + $this->getLimit();
2399  $LinkBar .= "<a href=\"".$link.$newoffset.$hash."\">".$layout_next."</a>";
2400  }
2401  else
2402  {
2403  if ($LinkBar != "")
2404  $LinkBar .= $sep;
2405  $LinkBar .= '<span class="ilTableFootLight">'.$layout_next."</span>";
2406  }
2407 
2408  $sep = "<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
2409 
2410  if (count($offset_arr) && !$this->getDisplayAsBlock() && !$this->custom_prev_next)
2411  {
2412  if ($LinkBar != "")
2413  $LinkBar .= $sep;
2414  $LinkBar .= "".
2415  '<label for="tab_page_sel_'.$a_num.'">'.$lng->txt("page").'</label> '.
2416  ilUtil::formSelect($this->nav_value,
2417  $this->getNavParameter().$a_num, $offset_arr, false, true, 0, "small",
2418  array("id" => "tab_page_sel_".$a_num,
2419  "onchange" => "ilTablePageSelection(this, 'cmd[".$this->parent_cmd."]')"));
2420  //' <input class="submit" type="submit" name="cmd['.$this->parent_cmd.']" value="'.
2421  //$lng->txt("ok").'" />';
2422  }
2423 
2424  return $LinkBar;
2425  }
2426  else
2427  {
2428  return false;
2429  }
2430  }
2431 
2432  function fillHiddenRow()
2433  {
2434  $hidden_row = false;
2435  if(count($this->hidden_inputs))
2436  {
2437  foreach ($this->hidden_inputs as $hidden_input)
2438  {
2439  $this->tpl->setCurrentBlock("tbl_hidden_field");
2440  $this->tpl->setVariable("FIELD_NAME", $hidden_input["name"]);
2441  $this->tpl->setVariable("FIELD_VALUE", $hidden_input["value"]);
2442  $this->tpl->parseCurrentBlock();
2443  }
2444 
2445  $this->tpl->setCurrentBlock("tbl_hidden_row");
2446  $this->tpl->parseCurrentBlock();
2447  }
2448  }
2449 
2453  function fillActionRow()
2454  {
2455  global $lng;
2456 
2457  // action row
2458  $action_row = false;
2459  $arrow = false;
2460 
2461  // add selection buttons
2462  if (count($this->sel_buttons) > 0)
2463  {
2464  foreach ($this->sel_buttons as $button)
2465  {
2466  $this->tpl->setCurrentBlock("sel_button");
2467  $this->tpl->setVariable("SBUTTON_SELECT",
2468  ilUtil::formSelect($button["selected"], $button["sel_var"],
2469  $button["options"], false, true));
2470  $this->tpl->setVariable("SBTN_NAME", $button["cmd"]);
2471  $this->tpl->setVariable("SBTN_VALUE", $button["text"]);
2472  $this->tpl->parseCurrentBlock();
2473 
2474  if ($this->getTopCommands())
2475  {
2476  $this->tpl->setCurrentBlock("sel_top_button");
2477  $this->tpl->setVariable("SBUTTON_SELECT",
2478  ilUtil::formSelect($button["selected"], $button["sel_var"],
2479  $button["options"], false, true));
2480  $this->tpl->setVariable("SBTN_NAME", $button["cmd"]);
2481  $this->tpl->setVariable("SBTN_VALUE", $button["text"]);
2482  $this->tpl->parseCurrentBlock();
2483  }
2484  }
2485  $buttons = true;
2486  $action_row = true;
2487  }
2488  $this->sel_buttons[] = array("options" => $a_options, "cmd" => $a_cmd, "text" => $a_text);
2489 
2490  // add buttons
2491  if (count($this->buttons) > 0)
2492  {
2493  foreach ($this->buttons as $button)
2494  {
2495  if (strlen($button['onclick']))
2496  {
2497  $this->tpl->setCurrentBlock('cmdonclick');
2498  $this->tpl->setVariable('CMD_ONCLICK', $button['onclick']);
2499  $this->tpl->parseCurrentBlock();
2500  }
2501  $this->tpl->setCurrentBlock("plain_button");
2502  if ($button["id"] != "")
2503  {
2504  $this->tpl->setVariable("PBID", ' id="'.$button["id"].'" ');
2505  }
2506  $this->tpl->setVariable("PBTN_NAME", $button["cmd"]);
2507  $this->tpl->setVariable("PBTN_VALUE", $button["text"]);
2508  $this->tpl->parseCurrentBlock();
2509 
2510  if ($this->getTopCommands())
2511  {
2512  if (strlen($button['onclick']))
2513  {
2514  $this->tpl->setCurrentBlock('top_cmdonclick');
2515  $this->tpl->setVariable('CMD_ONCLICK', $button['onclick']);
2516  $this->tpl->parseCurrentBlock();
2517  }
2518  $this->tpl->setCurrentBlock("plain_top_button");
2519  $this->tpl->setVariable("PBTN_NAME", $button["cmd"]);
2520  $this->tpl->setVariable("PBTN_VALUE", $button["text"]);
2521  $this->tpl->parseCurrentBlock();
2522  }
2523  }
2524 
2525  $buttons = true;
2526  $action_row = true;
2527  }
2528 
2529  // multi selection
2530  if(count($this->mi_sel_buttons))
2531  {
2532  foreach ($this->mi_sel_buttons as $button)
2533  {
2534  $this->tpl->setCurrentBlock("mi_sel_button");
2535  $this->tpl->setVariable("MI_BUTTON_SELECT",
2536  ilUtil::formSelect($button["selected"], $button["sel_var"],
2537  $button["options"], false, true));
2538  $this->tpl->setVariable("MI_BTN_NAME", $button["cmd"]);
2539  $this->tpl->setVariable("MI_BTN_VALUE", $button["text"]);
2540  $this->tpl->parseCurrentBlock();
2541 
2542  if ($this->getTopCommands())
2543  {
2544  $this->tpl->setCurrentBlock("mi_top_sel_button");
2545  $this->tpl->setVariable("MI_BUTTON_SELECT",
2546  ilUtil::formSelect($button["selected"], $button["sel_var"]."_2",
2547  $button["options"], false, true));
2548  $this->tpl->setVariable("MI_BTN_NAME", $button["cmd"]);
2549  $this->tpl->setVariable("MI_BTN_VALUE", $button["text"]);
2550  $this->tpl->parseCurrentBlock();
2551  }
2552 
2553  }
2554  $arrow = true;
2555  $action_row = true;
2556  }
2557 
2558 
2559  if (count($this->multi) > 1 && $this->dataExists())
2560  {
2561  if($this->enable_command_for_all && $this->max_count <= self::getAllCommandLimit())
2562  {
2563  $this->tpl->setCurrentBlock("tbl_cmd_select_all");
2564  $this->tpl->setVariable("TXT_SELECT_CMD_ALL", $lng->txt("all_objects"));
2565  $this->tpl->parseCurrentBlock();
2566  }
2567 
2568  $this->tpl->setCurrentBlock("tbl_cmd_select");
2569  $sel = array();
2570  foreach ($this->multi as $mc)
2571  {
2572  $sel[$mc["cmd"]] = $mc["text"];
2573  }
2574  $this->tpl->setVariable("SELECT_CMDS",
2575  ilUtil::formSelect("", "selected_cmd", $sel, false, true));
2576  $this->tpl->setVariable("TXT_EXECUTE", $lng->txt("execute"));
2577  $this->tpl->parseCurrentBlock();
2578  $arrow = true;
2579  $action_row = true;
2580 
2581  if ($this->getTopCommands())
2582  {
2583  if($this->enable_command_for_all && $this->max_count <= self::getAllCommandLimit())
2584  {
2585  $this->tpl->setCurrentBlock("tbl_top_cmd_select_all");
2586  $this->tpl->setVariable("TXT_SELECT_CMD_ALL", $lng->txt("all_objects"));
2587  $this->tpl->parseCurrentBlock();
2588  }
2589 
2590  $this->tpl->setCurrentBlock("tbl_top_cmd_select");
2591  $sel = array();
2592  foreach ($this->multi as $mc)
2593  {
2594  $sel[$mc["cmd"]] = $mc["text"];
2595  }
2596  $this->tpl->setVariable("SELECT_CMDS",
2597  ilUtil::formSelect("", "selected_cmd2", $sel, false, true));
2598  $this->tpl->setVariable("TXT_EXECUTE", $lng->txt("execute"));
2599  $this->tpl->parseCurrentBlock();
2600  }
2601  }
2602  elseif(count($this->multi) == 1 && $this->dataExists())
2603  {
2604  $this->tpl->setCurrentBlock("tbl_single_cmd");
2605  $sel = array();
2606  foreach ($this->multi as $mc)
2607  {
2608  $cmd = $mc['cmd'];
2609  $txt = $mc['text'];
2610  }
2611  $this->tpl->setVariable("TXT_SINGLE_CMD",$txt);
2612  $this->tpl->setVariable("SINGLE_CMD",$cmd);
2613  $this->tpl->parseCurrentBlock();
2614  $arrow = true;
2615  $action_row = true;
2616 
2617  if ($this->getTopCommands())
2618  {
2619  $this->tpl->setCurrentBlock("tbl_top_single_cmd");
2620  $sel = array();
2621  foreach ($this->multi as $mc)
2622  {
2623  $cmd = $mc['cmd'];
2624  $txt = $mc['text'];
2625  }
2626  $this->tpl->setVariable("TXT_SINGLE_CMD",$txt);
2627  $this->tpl->setVariable("SINGLE_CMD",$cmd);
2628  $this->tpl->parseCurrentBlock();
2629  }
2630  }
2631 
2632  if ($arrow)
2633  {
2634  $this->tpl->setCurrentBlock("tbl_action_img_arrow");
2635  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.png"));
2636  $this->tpl->setVariable("ALT_ARROW", $lng->txt("action"));
2637  $this->tpl->parseCurrentBlock();
2638 
2639  if ($this->getTopCommands())
2640  {
2641  $this->tpl->setCurrentBlock("tbl_top_action_img_arrow");
2642  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_upright.png"));
2643  $this->tpl->setVariable("ALT_ARROW", $lng->txt("action"));
2644  $this->tpl->parseCurrentBlock();
2645  }
2646  }
2647 
2648  if ($action_row)
2649  {
2650  $this->tpl->setCurrentBlock("tbl_action_row");
2651  $this->tpl->parseCurrentBlock();
2652  if ($this->getTopCommands())
2653  {
2654  $this->tpl->setCurrentBlock("tbl_top_action_row");
2655  $this->tpl->parseCurrentBlock();
2656  }
2657  }
2658  }
2659 
2665  public function setHeaderHTML($html)
2666  {
2667  $this->headerHTML = $html;
2668  }
2669 
2676  function storeProperty($type, $value)
2677  {
2678  global $ilUser;
2679 
2680  if(is_object($ilUser) && $this->getId() != "" && $ilUser->getId() != ANONYMOUS_USER_ID)
2681  {
2682  include_once("./Services/Table/classes/class.ilTablePropertiesStorage.php");
2683  $tab_prop = new ilTablePropertiesStorage();
2684 
2685  $tab_prop->storeProperty($this->getId(), $ilUser->getId(), $type, $value);
2686  }
2687  }
2688 
2695  function loadProperty($type)
2696  {
2697  global $ilUser;
2698 
2699  if(is_object($ilUser) && $this->getId() != "" && $ilUser->getId() != ANONYMOUS_USER_ID)
2700  {
2701  include_once("./Services/Table/classes/class.ilTablePropertiesStorage.php");
2702  $tab_prop = new ilTablePropertiesStorage();
2703 
2704  return $tab_prop->getProperty($this->getId(), $ilUser->getId(), $type);
2705  }
2706  }
2707 
2713  public function getCurrentState()
2714  {
2715  $this->determineOffsetAndOrder();
2716  $this->determineLimit();
2717  $this->determineSelectedColumns();
2718  $this->determineSelectedFilters();
2719 
2720  // "filter" show/hide is not saved
2721 
2722  $result = array();
2723  $result["order"] = $this->getOrderField();
2724  $result["direction"] = $this->getOrderDirection();
2725  $result["offset"] = $this->getOffset();
2726  $result["rows"] = $this->getLimit();
2727  $result["selfilters"] = $this->getSelectedFilters();
2728 
2729  // #9514 - $this->getSelectedColumns() will omit deselected, leading to
2730  // confusion on restoring template
2731  $result["selfields"] = $this->selected_column;
2732 
2733  // gather filter values
2734  if($this->filters)
2735  {
2736  foreach($this->filters as $item)
2737  {
2738  $result["filter_values"][$item->getFieldId()] = $this->getFilterValue($item);
2739  }
2740  }
2741  if($this->optional_filters && $result["selfilters"])
2742  {
2743  foreach($this->optional_filters as $item)
2744  {
2745  if(in_array($item->getFieldId(), $result["selfilters"]))
2746  {
2747  $result["filter_values"][$item->getFieldId()] = $this->getFilterValue($item);
2748  }
2749  }
2750  }
2751 
2752  return $result;
2753  }
2754 
2761  protected function getFilterValue(ilFormPropertyGUI $a_item)
2762  {
2763  if(method_exists($a_item, "getChecked"))
2764  {
2765  return $a_item->getChecked();
2766  }
2767  else if(method_exists($a_item, "getValue"))
2768  {
2769  return $a_item->getValue();
2770  }
2771  else if(method_exists($a_item, "getDate"))
2772  {
2773  return $a_item->getDate()->get(IL_CAL_DATE);
2774  }
2775  }
2776 
2783  protected function SetFilterValue(ilFormPropertyGUI $a_item, $a_value)
2784  {
2785  if(method_exists($a_item, "setChecked"))
2786  {
2787  $a_item->setChecked($a_value);
2788  }
2789  else if(method_exists($a_item, "setValue"))
2790  {
2791  $a_item->setValue($a_value);
2792  }
2793  else if(method_exists($a_item, "setDate"))
2794  {
2795  $a_item->setDate(new ilDate($a_value, IL_CAL_DATE));
2796  }
2797  $a_item->writeToSession();
2798  }
2799 
2805  public function setContext($id)
2806  {
2807  if(trim($id))
2808  {
2809  $this->context = $id;
2810  }
2811  }
2812 
2818  public function getContext()
2819  {
2820  return $this->context;
2821  }
2822 
2828  public function setShowRowsSelector($a_value)
2829  {
2830  $this->show_rows_selector = (bool)$a_value;
2831  }
2832 
2838  public function getShowRowsSelector()
2839  {
2841  }
2842 
2848  public function setShowTemplates($a_value)
2849  {
2850  $this->show_templates = (bool)$a_value;
2851  }
2852 
2858  public function getShowTemplates()
2859  {
2860  return $this->show_templates;
2861  }
2862 
2869  public function restoreTemplate($a_name)
2870  {
2871  global $ilUser;
2872 
2873  $a_name = ilUtil::stripSlashes($a_name);
2874 
2875  if(trim($a_name) && $this->getContext() != "" && is_object($ilUser) && $ilUser->getId() != ANONYMOUS_USER_ID)
2876  {
2877  include_once("./Services/Table/classes/class.ilTableTemplatesStorage.php");
2878  $storage = new ilTableTemplatesStorage();
2879 
2880  $data = $storage->load($this->getContext(), $ilUser->getId(), $a_name);
2881  if(is_array($data))
2882  {
2883  foreach($data as $property => $value)
2884  {
2885  $this->storeProperty($property, $value);
2886  }
2887  }
2888 
2889  $data["filter_values"] = unserialize($data["filter_values"]);
2890  if($data["filter_values"])
2891  {
2892  $this->restore_filter_values = $data["filter_values"];
2893  }
2894 
2895  return true;
2896  }
2897  return false;
2898  }
2899 
2906  public function saveTemplate($a_name)
2907  {
2908  global $ilUser;
2909 
2910  $a_name = ilUtil::prepareFormOutput($a_name, true);
2911 
2912  if(trim($a_name) && $this->getContext() != "" && is_object($ilUser) && $ilUser->getId() != ANONYMOUS_USER_ID)
2913  {
2914  include_once("./Services/Table/classes/class.ilTableTemplatesStorage.php");
2915  $storage = new ilTableTemplatesStorage();
2916 
2917  $state = $this->getCurrentState();
2918  $state["filter_values"] = serialize($state["filter_values"]);
2919  $state["selfields"] = serialize($state["selfields"]);
2920  $state["selfilters"] = serialize($state["selfilters"]);
2921 
2922  $storage->store($this->getContext(), $ilUser->getId(), $a_name, $state);
2923  return true;
2924  }
2925  return false;
2926  }
2927 
2934  public function deleteTemplate($a_name)
2935  {
2936  global $ilUser;
2937 
2938  $a_name = ilUtil::prepareFormOutput($a_name, true);
2939 
2940  if(trim($a_name) && $this->getContext() != "" && is_object($ilUser) && $ilUser->getId() != ANONYMOUS_USER_ID)
2941  {
2942  include_once("./Services/Table/classes/class.ilTableTemplatesStorage.php");
2943  $storage = new ilTableTemplatesStorage();
2944  $storage->delete($this->getContext(), $ilUser->getId(), $a_name);
2945  return true;
2946  }
2947  return false;
2948  }
2949 
2953  function getLimit()
2954  {
2955  if($this->getExportMode() || $this->getPrintMode())
2956  {
2957  return 9999;
2958  }
2959  return parent::getLimit();
2960  }
2961 
2965  function getOffset()
2966  {
2967  if($this->getExportMode() || $this->getPrintMode())
2968  {
2969  return 0;
2970  }
2971  return parent::getOffset();
2972  }
2973 
2979  public function setExportFormats(array $formats)
2980  {
2981  $this->export_formats = array();
2982 
2983  // #11339
2984  $valid = array(self::EXPORT_EXCEL => "tbl_export_excel",
2985  self::EXPORT_CSV => "tbl_export_csv");
2986 
2987  foreach($formats as $format)
2988  {
2989  if(array_key_exists($format, $valid))
2990  {
2991  $this->export_formats[$format] = $valid[$format];
2992  }
2993  }
2994  }
2995 
3000  public function setPrintMode($a_value = false)
3001  {
3002  $this->print_mode = (bool)$a_value;
3003  }
3004 
3009  public function getPrintMode()
3010  {
3011  return $this->print_mode;
3012  }
3013 
3019  public function getExportMode()
3020  {
3021  return $this->export_mode;
3022  }
3023 
3029  public function exportData($format, $send = false)
3030  {
3031  if($this->dataExists())
3032  {
3033  // #9640: sort
3034  if (!$this->getExternalSorting() && $this->enabled["sort"])
3035  {
3036  $this->determineOffsetAndOrder(true);
3037 
3038  $this->row_data = ilUtil::sortArray($this->row_data, $this->getOrderField(),
3039  $this->getOrderDirection(), $this->numericOrdering($this->getOrderField()));
3040  }
3041 
3042  $filename = "export";
3043 
3044  switch($format)
3045  {
3046  case self::EXPORT_EXCEL:
3047  include_once "./Services/Excel/classes/class.ilExcelUtils.php";
3048  include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php";
3049  $adapter = new ilExcelWriterAdapter($filename.".xls", $send);
3050  $workbook = $adapter->getWorkbook();
3051  $worksheet = $workbook->addWorksheet();
3052  $row = 0;
3053 
3054  ob_start();
3055  $this->fillMetaExcel($worksheet, $row);
3056 
3057  // #14142
3058  $pre = $row;
3059  $this->fillHeaderExcel($worksheet, $row);
3060  if($pre == $row)
3061  {
3062  $row++;
3063  }
3064 
3065  foreach($this->row_data as $set)
3066  {
3067  $this->fillRowExcel($worksheet, $row, $set);
3068  $row++;
3069  }
3070  ob_end_clean();
3071 
3072  $workbook->close();
3073  break;
3074 
3075  case self::EXPORT_CSV:
3076  include_once "./Services/Utilities/classes/class.ilCSVWriter.php";
3077  $csv = new ilCSVWriter();
3078  $csv->setSeparator(";");
3079 
3080  ob_start();
3081  $this->fillMetaCSV($csv);
3082  $this->fillHeaderCSV($csv);
3083  foreach($this->row_data as $set)
3084  {
3085  $this->fillRowCSV($csv, $set);
3086  }
3087  ob_end_clean();
3088 
3089  if($send)
3090  {
3091  $filename .= ".csv";
3092  header("Content-type: text/comma-separated-values");
3093  header("Content-Disposition: attachment; filename=\"".$filename."\"");
3094  header("Expires: 0");
3095  header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
3096  header("Pragma: public");
3097  echo $csv->getCSVString();
3098 
3099  }
3100  else
3101  {
3102  file_put_contents($filename, $csv->getCSVString());
3103  }
3104  break;
3105  }
3106 
3107  if($send)
3108  {
3109  exit();
3110  }
3111  }
3112  }
3113 
3121  protected function fillMetaExcel($worksheet, &$a_row)
3122  {
3123 
3124  }
3125 
3133  protected function fillHeaderExcel($worksheet, &$a_row)
3134  {
3135  $col = 0;
3136  foreach ($this->column as $column)
3137  {
3138  $title = strip_tags($column["text"]);
3139  if($title)
3140  {
3141  $worksheet->write($a_row, $col, $title);
3142  $col++;
3143  }
3144  }
3145  $a_row++;
3146  }
3147 
3156  protected function fillRowExcel($a_worksheet, &$a_row, $a_set)
3157  {
3158  $col = 0;
3159  foreach ($a_set as $key => $value)
3160  {
3161  if(is_array($value))
3162  {
3163  $value = implode(', ', $value);
3164  }
3165  $a_worksheet->write($a_row, $col, strip_tags($value));
3166  $col++;
3167  }
3168  }
3169 
3176  protected function fillMetaCSV($a_csv)
3177  {
3178 
3179  }
3180 
3187  protected function fillHeaderCSV($a_csv)
3188  {
3189  foreach ($this->column as $column)
3190  {
3191  $title = strip_tags($column["text"]);
3192  if($title)
3193  {
3194  $a_csv->addColumn($title);
3195  }
3196  }
3197  $a_csv->addRow();
3198  }
3199 
3207  protected function fillRowCSV($a_csv, $a_set)
3208  {
3209  foreach ($a_set as $key => $value)
3210  {
3211  if(is_array($value))
3212  {
3213  $value = implode(', ', $value);
3214  }
3215  $a_csv->addColumn(strip_tags($value));
3216  }
3217  $a_csv->addRow();
3218  }
3219 
3225  public function setEnableAllCommand($a_value)
3226  {
3227  $this->enable_command_for_all = (bool)$a_value;
3228  }
3229 
3235  public static function getAllCommandLimit()
3236  {
3237  global $ilClientIniFile;
3238 
3239  $limit = $ilClientIniFile->readVariable("system", "TABLE_ACTION_ALL_LIMIT");
3240  if(!$limit)
3241  {
3243  }
3244 
3245  return $limit;
3246  }
3247 
3252  {
3253  $this->row_selector_label = $row_selector_label;
3254  return $this;
3255  }
3256 
3260  public function getRowSelectorLabel()
3261  {
3263  }
3264 }
3265 
3266 ?>