ILIAS  Release_4_2_x_branch Revision 61807
 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 = 4;
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 
50  const FILTER_TEXT = 1;
51  const FILTER_SELECT = 2;
52  const FILTER_DATE = 3;
53  const FILTER_LANGUAGE = 4;
55  const FILTER_DATE_RANGE = 6;
57 
58  const EXPORT_EXCEL = 1;
59  const EXPORT_CSV = 2;
60 
65  public function __construct($a_parent_obj, $a_parent_cmd = "", $a_template_context = "")
66  {
67  global $lng;
68 
69  parent::__construct(0, false);
70  $this->unique_id = md5(uniqid());
71  $this->parent_obj = $a_parent_obj;
72  $this->parent_cmd = $a_parent_cmd;
73  $this->buttons = array();
74  $this->header_commands = array();
75  $this->multi = array();
76  $this->hidden_inputs = array();
77  $this->formname = "table_" . $this->unique_id;
78  $this->tpl = new ilTemplate("tpl.table2.html", true, true, "Services/Table");
79 
80  $lng->loadLanguageModule('tbl');
81 
82  if(!$a_template_context)
83  {
84  $a_template_context = $this->getId();
85  }
86  $this->setContext($a_template_context);
87 
88  // activate export mode
89  if(isset($_GET[$this->prefix."_xpt"]))
90  {
91  $this->export_mode = (int)$_GET[$this->prefix."_xpt"];
92  }
93 
94  // template handling
95  if(isset($_GET[$this->prefix."_tpl"]))
96  {
97  $this->restoreTemplate($_GET[$this->prefix."_tpl"]);
98  }
99 
100  $this->determineLimit();
101  $this->setIsDataTable(true);
102  $this->setEnableNumInfo(true);
103  $this->determineSelectedColumns();
104  }
105 
111  function setOpenFormTag($a_val)
112  {
113  $this->open_form_tag = $a_val;
114  }
115 
121  function getOpenFormTag()
122  {
123  return $this->open_form_tag;
124  }
125 
131  function setCloseFormTag($a_val)
132  {
133  $this->close_form_tag = $a_val;
134  }
135 
141  function getCloseFormTag()
142  {
143  return $this->close_form_tag;
144  }
145 
149  function determineLimit()
150  {
151  global $ilUser;
152 
153  if ($this->limit_determined)
154  {
155  return;
156  }
157 
158  $limit = 0;
159  if (isset($_GET[$this->prefix."_trows"]))
160  {
161  $this->storeProperty("rows", $_GET[$this->prefix."_trows"]);
162  $limit = $_GET[$this->prefix."_trows"];
163  $this->resetOffset();
164  }
165 
166  if ($limit == 0)
167  {
168  $rows = $this->loadProperty("rows");
169  if ($rows > 0)
170  {
171  $limit = $rows;
172  }
173  else
174  {
175  if (is_object($ilUser))
176  {
177  $limit = $ilUser->getPref("hits_per_page");
178  }
179  else
180  {
181  $limit = 40;
182  }
183  }
184  }
185 
186  $this->setLimit($limit);
187  $this->limit_determined = true;
188  }
189 
196  {
197  return array();
198  }
199 
204  {
205  if ($this->columns_determined)
206  {
207  return;
208  }
209 
210  $old_sel = $this->loadProperty("selfields");
211 
212  $stored = false;
213  if ($old_sel != "")
214  {
215  $sel_fields =
216  @unserialize($old_sel);
217  $stored = true;
218  }
219  if(!is_array($sel_fields))
220  {
221  $stored = false;
222  $sel_fields = array();
223  }
224 
225  $this->selected_columns = array();
226  $set = false;
227  foreach ($this->getSelectableColumns() as $k => $c)
228  {
229  $this->selected_column[$k] = false;
230 
231  if ($_POST["tblfsh".$this->getId()])
232  {
233  $set = true;
234  if (is_array($_POST["tblfs".$this->getId()]) && in_array($k, $_POST["tblfs".$this->getId()]))
235  {
236  $this->selected_column[$k] = true;
237  }
238  }
239  else if ($stored) // take stored values
240  {
241  $this->selected_column[$k] = $sel_fields[$k];
242  }
243  else // take default values
244  {
245  if ($c["default"])
246  {
247  $this->selected_column[$k] = true;
248  }
249  }
250  }
251 
252  if ($old_sel != serialize($this->selected_column) && $set)
253  {
254  $this->storeProperty("selfields", serialize($this->selected_column));
255  }
256 
257  $this->columns_determined = true;
258  }
259 
266  function isColumnSelected($a_col)
267  {
268  return $this->selected_column[$a_col];
269  }
270 
278  {
279  $scol = array();
280  foreach ($this->selected_column as $k => $v)
281  {
282  if ($v)
283  {
284  $scol[$k] = $k;
285  }
286  }
287  return $scol;
288  }
289 
293  function &executeCommand()
294  {
295  global $ilCtrl;
296 
297  $next_class = $ilCtrl->getNextClass($this);
298  $cmd = $ilCtrl->getCmd();
299 
300  switch($next_class)
301  {
302  case 'ilformpropertydispatchgui':
303  include_once './Services/Form/classes/class.ilFormPropertyDispatchGUI.php';
304  $form_prop_dispatch = new ilFormPropertyDispatchGUI();
305  $this->initFilter();
306  $item = $this->getFilterItemByPostVar($_GET["postvar"]);
307  $form_prop_dispatch->setItem($item);
308  return $ilCtrl->forwardCommand($form_prop_dispatch);
309  break;
310 
311  }
312  return false;
313  }
314 
318  function resetOffset($a_in_determination = false)
319  {
320  if (!$this->nav_determined && !$a_in_determination)
321  {
322  $this->determineOffsetAndOrder();
323  }
324  $this->nav_value = $this->getOrderField().":".$this->getOrderDirection().":0";
325  $_GET[$this->getNavParameter()] =
326  $_POST[$this->getNavParameter()."1"] =
327  $this->nav_value;
328 //echo $this->nav_value;
329  $this->setOffset(0);
330  }
331 
336  function initFilter()
337  {
338  }
339 
345  public function getParentObject()
346  {
347  return $this->parent_obj;
348  }
349 
355  public function getParentCmd()
356  {
357  return $this->parent_cmd;
358  }
359 
365  function setTopAnchor($a_val)
366  {
367  $this->top_anchor = $a_val;
368  }
369 
375  function getTopAnchor()
376  {
377  return $this->top_anchor;
378  }
379 
385  function setNoEntriesText($a_text)
386  {
387  $this->noentriestext = $a_text;
388  }
389 
395  function getNoEntriesText()
396  {
397  return $this->noentriestext;
398  }
399 
405  function setIsDataTable($a_val)
406  {
407  $this->datatable = $a_val;
408  }
409 
415  function getIsDataTable()
416  {
417  return $this->datatable;
418  }
419 
425  function setEnableTitle($a_enabletitle)
426  {
427  $this->enabled["title"] = $a_enabletitle;
428  }
429 
435  function getEnableTitle()
436  {
437  return $this->enabled["title"];
438  }
439 
445  function setEnableHeader($a_enableheader)
446  {
447  $this->enabled["header"] = $a_enableheader;
448  }
449 
455  function getEnableHeader()
456  {
457  return $this->enabled["header"];
458  }
459 
465  function setEnableNumInfo($a_val)
466  {
467  $this->num_info = $a_val;
468  }
469 
475  function getEnableNumInfo()
476  {
477  return $this->num_info;
478  }
479 
483  final public function setTitle($a_title, $a_icon = 0, $a_icon_alt = 0)
484  {
485  parent::setTitle($a_title, $a_icon, $a_icon_alt);
486  }
487 
493  function setDescription($a_val)
494  {
495  $this->description = $a_val;
496  }
497 
503  function getDescription()
504  {
505  return $this->description;
506  }
507 
513  function setOrderField($a_order_field)
514  {
515  $this->order_field = $a_order_field;
516  }
517 
518  function getOrderField()
519  {
520  return $this->order_field;
521  }
522 
523  final public function setData($a_data)
524  {
525  // check column names against given data (to ensure proper sorting)
526  if(DEVMODE &&
527  $this->enabled["header"] && $this->enabled["sort"] &&
528  $this->columns_determined && is_array($this->column) &&
529  is_array($a_data) && sizeof($a_data))
530  {
531  $check = $a_data;
532  $check = array_keys(array_shift($check));
533  foreach($this->column as $col)
534  {
535  if($col["sort_field"] && !in_array($col["sort_field"], $check))
536  {
537  $invalid[] = $col["sort_field"];
538  }
539  }
540  if(sizeof($invalid))
541  {
542  trigger_error("The following columns are defined as sortable but".
543  " cannot be found in the given data: ".implode(", ", $invalid).
544  ". Sorting will not work properly.", E_USER_WARNING);
545  }
546  }
547 
548  $this->row_data = $a_data;
549  }
550 
551  final public function getData()
552  {
553  return $this->row_data;
554  }
555 
556  final public function dataExists()
557  {
558  if (is_array($this->row_data))
559  {
560  if (count($this->row_data) > 0)
561  {
562  return true;
563  }
564  }
565  return false;
566  }
567 
568  final public function setPrefix($a_prefix)
569  {
570  $this->prefix = $a_prefix;
571  }
572 
573  final public function getPrefix()
574  {
575  return $this->prefix;
576  }
577 
582  final function addFilterItem($a_input_item, $a_optional = false)
583  {
584  $a_input_item->setParent($this);
585  if (!$a_optional)
586  {
587  $this->filters[] = $a_input_item;
588  }
589  else
590  {
591  $this->optional_filters[] = $a_input_item;
592  }
593 
594  // restore filter values (from stored view)
595  if($this->restore_filter_values &&
596  array_key_exists($a_input_item->getFieldId(), $this->restore_filter_values))
597  {
598  $this->setFilterValue($a_input_item, $this->restore_filter_values[$a_input_item->getFieldId()]);
599  }
600  }
601 
611  function addFilterItemByMetaType($id, $type = self::FILTER_TEXT, $a_optional = false, $caption = NULL)
612  {
613  global $lng;
614 
615  if(!$caption)
616  {
617  $caption = $lng->txt($id);
618  }
619 
620  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
621 
622  switch($type)
623  {
624  case self::FILTER_SELECT:
625  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
626  $item = new ilSelectInputGUI($caption, $id);
627  break;
628 
629  case self::FILTER_DATE:
630  include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
631  $item = new ilDateTimeInputGUI($caption, $id);
632  $item->setMode(ilDateTimeInputGUI::MODE_INPUT);
633  break;
634 
635  case self::FILTER_TEXT:
636  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
637  $item = new ilTextInputGUI($caption, $id);
638  $item->setMaxLength(64);
639  $item->setSize(20);
640  // $item->setSubmitFormOnEnter(true);
641  break;
642 
643  case self::FILTER_LANGUAGE:
644  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
645  $item = new ilSelectInputGUI($caption, $id);
646  $options = array("" => $lng->txt("trac_all"));
647  foreach ($lng->getInstalledLanguages() as $lang_key)
648  {
649  $options[$lang_key] = $lng->txt("lang_".$lang_key);
650  }
651  $item->setOptions($options);
652  break;
653 
654  case self::FILTER_NUMBER_RANGE:
655  include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
656  include_once("./Services/Form/classes/class.ilNumberInputGUI.php");
657  $item = new ilCombinationInputGUI($caption, $id);
658  $combi_item = new ilNumberInputGUI("", $id."_from");
659  $item->addCombinationItem("from", $combi_item, $lng->txt("from"));
660  $combi_item = new ilNumberInputGUI("", $id."_to");
661  $item->addCombinationItem("to", $combi_item, $lng->txt("to"));
662  $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
663  $item->setMaxLength(7);
664  $item->setSize(20);
665  break;
666 
667  case self::FILTER_DATE_RANGE:
668  include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
669  include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
670  $item = new ilCombinationInputGUI($caption, $id);
671  $combi_item = new ilDateTimeInputGUI("", $id."_from");
672  $item->addCombinationItem("from", $combi_item, $lng->txt("from"));
673  $combi_item = new ilDateTimeInputGUI("", $id."_to");
674  $item->addCombinationItem("to", $combi_item, $lng->txt("to"));
675  $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
676  $item->setMode(ilDateTimeInputGUI::MODE_INPUT);
677  break;
678 
679  case self::FILTER_DURATION_RANGE:
680  $lng->loadLanguageModule("form");
681  include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
682  include_once("./Services/Form/classes/class.ilDurationInputGUI.php");
683  $item = new ilCombinationInputGUI($caption, $id);
684  $combi_item = new ilDurationInputGUI("", $id."_from");
685  $combi_item->setShowMonths(false);
686  $combi_item->setShowDays(true);
687  $item->addCombinationItem("from", $combi_item, $lng->txt("from"));
688  $combi_item = new ilDurationInputGUI("", $id."_to");
689  $combi_item->setShowMonths(false);
690  $combi_item->setShowDays(true);
691  $item->addCombinationItem("to", $combi_item, $lng->txt("to"));
692  $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
693  break;
694 
695  default:
696  return false;
697  }
698 
699  $this->addFilterItem($item, $a_optional);
700  $item->readFromSession();
701  return $item;
702  }
703 
707  final function getFilterItems($a_optionals = false)
708  {
709  if (!$a_optionals)
710  {
711  return $this->filters;
712  }
714  }
715 
716  final function getFilterItemByPostVar($a_post_var)
717  {
718  foreach ($this->getFilterItems() as $item)
719  {
720  if ($item->getPostVar() == $a_post_var)
721  {
722  return $item;
723  }
724  }
725  foreach ($this->getFilterItems(true) as $item)
726  {
727  if ($item->getPostVar() == $a_post_var)
728  {
729  return $item;
730  }
731  }
732  return false;
733  }
734 
740  function setFilterCols($a_val)
741  {
742  $this->filter_cols = $a_val;
743  }
744 
750  function getFilterCols()
751  {
752  return $this->filter_cols;
753  }
754 
760  function setDisableFilterHiding($a_val = true)
761  {
762  $this->disable_filter_hiding = $a_val;
763  }
764 
771  {
773  }
774 
781  function isFilterSelected($a_col)
782  {
783  return $this->selected_filter[$a_col];
784  }
785 
793  {
794  $sfil = array();
795  foreach ($this->selected_filter as $k => $v)
796  {
797  if ($v)
798  {
799  $sfil[$k] = $k;
800  }
801  }
802  return $sfil;
803  }
804 
812  {
813  if ($this->filters_determined)
814  {
815  return;
816  }
817 
818  $old_sel = $this->loadProperty("selfilters");
819  $stored = false;
820  if ($old_sel != "")
821  {
822  $sel_filters =
823  @unserialize($old_sel);
824  $stored = true;
825  }
826  if(!is_array($sel_filters))
827  {
828  $stored = false;
829  $sel_filters = array();
830  }
831 
832  $this->selected_filter = array();
833  $set = false;
834  foreach ($this->getFilterItems(true) as $item)
835  {
836  $k = $item->getPostVar();
837 
838  $this->selected_filter[$k] = false;
839 
840  if ($_POST["tblfsf".$this->getId()])
841  {
842  $set = true;
843  if (is_array($_POST["tblff".$this->getId()]) && in_array($k, $_POST["tblff".$this->getId()]))
844  {
845  $this->selected_filter[$k] = true;
846  }
847  else
848  {
849  $item->setValue(NULL);
850  $item->writeToSession();
851  }
852  }
853  else if ($stored) // take stored values
854  {
855  $this->selected_filter[$k] = $sel_filters[$k];
856  }
857  }
858 
859  if ($old_sel != serialize($this->selected_filter) && $set)
860  {
861  $this->storeProperty("selfilters", serialize($this->selected_filter));
862  }
863 
864  $this->filters_determined = true;
865  }
866 
870  function setCustomPreviousNext($a_prev_link, $a_next_link)
871  {
872  $this->custom_prev_next = true;
873  $this->custom_prev = $a_prev_link;
874  $this->custom_next = $a_next_link;
875  }
876 
882  final public function setFormAction($a_form_action)
883  {
884  $this->form_action = $a_form_action;
885  }
886 
892  final public function getFormAction()
893  {
894  return $this->form_action;
895  }
896 
902  function setFormName($a_formname)
903  {
904  $this->formname = $a_formname;
905  }
906 
912  function getFormName()
913  {
914  return $this->formname;
915  }
916 
922  function setId($a_val)
923  {
924  $this->id = $a_val;
925  if ($this->getPrefix() == "")
926  {
927  $this->setPrefix($a_val);
928  }
929  }
930 
936  function getId()
937  {
938  return $this->id;
939  }
940 
946  function setDisplayAsBlock($a_val)
947  {
948  $this->display_as_block = $a_val;
949  }
950 
956  function getDisplayAsBlock()
957  {
958  return $this->display_as_block;
959  }
960 
967  {
969  }
970 
976  function setSelectAllCheckbox($a_select_all_checkbox)
977  {
978  $this->select_all_checkbox = $a_select_all_checkbox;
979  }
980 
986  function setExternalSorting($a_val)
987  {
988  $this->ext_sort = $a_val;
989  }
990 
997  {
998  return $this->ext_sort;
999  }
1000 
1006  function setFilterCommand($a_val)
1007  {
1008  $this->filter_cmd = $a_val;
1009  }
1010 
1016  function getFilterCommand()
1017  {
1018  return $this->filter_cmd;
1019  }
1020 
1026  function setResetCommand($a_val)
1027  {
1028  $this->reset_cmd = $a_val;
1029  }
1030 
1036  function getResetCommand()
1037  {
1038  return $this->reset_cmd;
1039  }
1040 
1046  function setExternalSegmentation($a_val)
1047  {
1048  $this->ext_seg = $a_val;
1049  }
1050 
1057  {
1058  return $this->ext_seg;
1059  }
1060 
1067  final public function setRowTemplate($a_template, $a_template_dir = "")
1068  {
1069  $this->row_template = $a_template;
1070  $this->row_template_dir = $a_template_dir;
1071  }
1072 
1078  function setDefaultOrderField($a_defaultorderfield)
1079  {
1080  $this->defaultorderfield = $a_defaultorderfield;
1081  }
1082 
1089  {
1090  return $this->defaultorderfield;
1091  }
1092 
1098  function setDefaultOrderDirection($a_defaultorderdirection)
1099  {
1100  $this->defaultorderdirection = $a_defaultorderdirection;
1101  }
1102 
1109  {
1110  return $this->defaultorderdirection;
1111  }
1112 
1113  /*
1114  * Removes all command buttons from the table
1115  *
1116  * @access public
1117  */
1118  public function clearCommandButtons()
1119  {
1120  $this->buttons = array();
1121  }
1122 
1129  function addCommandButton($a_cmd, $a_text, $a_onclick = '', $a_id = "")
1130  {
1131  $this->buttons[] = array("cmd" => $a_cmd, "text" => $a_text, 'onclick' => $a_onclick,
1132  "id" => $a_id);
1133  }
1134 
1143  function addSelectionButton($a_sel_var, $a_options, $a_cmd, $a_text, $a_default_selection = '')
1144  {
1145 echo "ilTabl2GUI->addSelectionButton() has been deprecated with 4.2. Please try to move the drop-down to ilToolbarGUI.";
1146 // $this->sel_buttons[] = array("sel_var" => $a_sel_var, "options" => $a_options, "selected" => $a_default_selection, "cmd" => $a_cmd, "text" => $a_text);
1147  }
1148 
1158  public function addMultiItemSelectionButton($a_sel_var, $a_options, $a_cmd, $a_text, $a_default_selection = '')
1159  {
1160  $this->mi_sel_buttons[] = array("sel_var" => $a_sel_var, "options" => $a_options, "selected" => $a_default_selection, "cmd" => $a_cmd, "text" => $a_text);
1161  $this->addHiddenInput("cmd_sv[".$a_cmd."]", $a_sel_var);
1162  }
1163 
1164 
1165 
1171  function setCloseCommand($a_link)
1172  {
1173  $this->close_command = $a_link;
1174  }
1175 
1182  function addMultiCommand($a_cmd, $a_text)
1183  {
1184  $this->multi[] = array("cmd" => $a_cmd, "text" => $a_text);
1185  }
1186 
1193  public function addHiddenInput($a_name, $a_value)
1194  {
1195  $this->hidden_inputs[] = array("name" => $a_name, "value" => $a_value);
1196  }
1197 
1204  function addHeaderCommand($a_href, $a_text, $a_target = "", $a_img = "")
1205  {
1206  $this->header_commands[] = array("href" => $a_href, "text" => $a_text,
1207  "target" => $a_target, "img" => $a_img);
1208  }
1209 
1215  function setTopCommands($a_val)
1216  {
1217  $this->top_commands = $a_val;
1218  }
1219 
1225  function getTopCommands()
1226  {
1227  return $this->top_commands;
1228  }
1229 
1237  final public function addColumn($a_text, $a_sort_field = "", $a_width = "",
1238  $a_is_checkbox_action_column = false, $a_class = "", $a_tooltip = "")
1239  {
1240  $this->column[] = array(
1241  "text" => $a_text,
1242  "sort_field" => $a_sort_field,
1243  "width" => $a_width,
1244  "is_checkbox_action_column" => $a_is_checkbox_action_column,
1245  "class" => $a_class,
1246  "tooltip" => $a_tooltip
1247  );
1248  $this->column_count = count($this->column);
1249  }
1250 
1251 
1252  final public function getNavParameter()
1253  {
1254  return $this->prefix."_table_nav";
1255  }
1256 
1257  function setOrderLink($sort_field, $order_dir)
1258  {
1259  global $ilCtrl, $ilUser;
1260 
1261  $hash = "";
1262  if (is_object($ilUser) && $ilUser->getPref("screen_reader_optimization"))
1263  {
1264  $hash = "#".$this->getTopAnchor();
1265  }
1266 
1267  $old = $_GET[$this->getNavParameter()];
1268 
1269  // set order link
1270  $ilCtrl->setParameter($this->parent_obj,
1271  $this->getNavParameter(),
1272  $sort_field.":".$order_dir.":".$this->offset);
1273  $this->tpl->setVariable("TBL_ORDER_LINK",
1274  $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd).$hash);
1275 
1276  // set old value of nav variable
1277  $ilCtrl->setParameter($this->parent_obj,
1278  $this->getNavParameter(), $old);
1279  }
1280 
1281  function fillHeader()
1282  {
1283  global $lng;
1284 
1285  $allcolumnswithwidth = true;
1286  foreach ((array) $this->column as $idx => $column)
1287  {
1288  if (!strlen($column["width"]))
1289  {
1290  $allcolumnswithwidth = false;
1291  }
1292  else if($column["width"] == "1")
1293  {
1294  // IE does not like 1 but seems to work with 1%
1295  $this->column[$idx]["width"] = "1%";
1296  }
1297  }
1298  if ($allcolumnswithwidth)
1299  {
1300  foreach ((array) $this->column as $column)
1301  {
1302  $this->tpl->setCurrentBlock("tbl_colgroup_column");
1303  $this->tpl->setVariable("COLGROUP_COLUMN_WIDTH", $column["width"]);
1304  $this->tpl->parseCurrentBlock();
1305  }
1306  }
1307  $ccnt = 0;
1308  foreach ((array) $this->column as $column)
1309  {
1310  $ccnt++;
1311 
1312  //tooltip
1313  if ($column["tooltip"] != "")
1314  {
1315  include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
1316  ilTooltipGUI::addTooltip("thc_".$this->getId()."_".$ccnt, $column["tooltip"]);
1317  }
1318  if (!$this->enabled["sort"] || $column["sort_field"] == "" || $column["is_checkbox_action_column"])
1319  {
1320  $this->tpl->setCurrentBlock("tbl_header_no_link");
1321  if ($column["width"] != "")
1322  {
1323  $this->tpl->setVariable("TBL_COLUMN_WIDTH_NO_LINK"," width=\"".$column["width"]."\"");
1324  }
1325  if (!$column["is_checkbox_action_column"])
1326  {
1327  $this->tpl->setVariable("TBL_HEADER_CELL_NO_LINK",
1328  $column["text"]);
1329  }
1330  else
1331  {
1332  $this->tpl->setVariable("TBL_HEADER_CELL_NO_LINK",
1333  ilUtil::img(ilUtil::getImagePath("spacer.gif"), $lng->txt("action")));
1334  }
1335  $this->tpl->setVariable("HEAD_CELL_NL_ID", "thc_".$this->getId()."_".$ccnt);
1336 
1337  if ($column["class"] != "")
1338  {
1339  $this->tpl->setVariable("TBL_HEADER_CLASS"," " . $column["class"]);
1340  }
1341  $this->tpl->parseCurrentBlock();
1342  $this->tpl->touchBlock("tbl_header_th");
1343  continue;
1344  }
1345  if (($column["sort_field"] == $this->order_field) && ($this->order_direction != ""))
1346  {
1347  $this->tpl->setCurrentBlock("tbl_order_image");
1348  $this->tpl->setVariable("IMG_ORDER_DIR",ilUtil::getImagePath($this->order_direction."_order.gif"));
1349  $this->tpl->setVariable("IMG_ORDER_ALT", $this->lng->txt("change_sort_direction"));
1350  $this->tpl->parseCurrentBlock();
1351  }
1352 
1353  $this->tpl->setCurrentBlock("tbl_header_cell");
1354  $this->tpl->setVariable("TBL_HEADER_CELL", $column["text"]);
1355  $this->tpl->setVariable("HEAD_CELL_ID", "thc_".$this->getId()."_".$ccnt);
1356 
1357  // only set width if a value is given for that column
1358  if ($column["width"] != "")
1359  {
1360  $this->tpl->setVariable("TBL_COLUMN_WIDTH"," width=\"".$column["width"]."\"");
1361  }
1362 
1363  $lng_sort_column = $this->lng->txt("sort_by_this_column");
1364  $this->tpl->setVariable("TBL_ORDER_ALT",$lng_sort_column);
1365 
1366  $order_dir = "asc";
1367 
1368  if ($column["sort_field"] == $this->order_field)
1369  {
1370  $order_dir = $this->sort_order;
1371 
1372  $lng_change_sort = $this->lng->txt("change_sort_direction");
1373  $this->tpl->setVariable("TBL_ORDER_ALT",$lng_change_sort);
1374  }
1375 
1376  if ($column["class"] != "")
1377  {
1378  $this->tpl->setVariable("TBL_HEADER_CLASS"," " . $column["class"]);
1379  }
1380  $this->setOrderLink($column["sort_field"], $order_dir);
1381  $this->tpl->parseCurrentBlock();
1382  $this->tpl->touchBlock("tbl_header_th");
1383  }
1384 
1385  $this->tpl->setCurrentBlock("tbl_header");
1386  $this->tpl->parseCurrentBlock();
1387  }
1388 
1392  protected function prepareOutput()
1393  {
1394  }
1395 
1396 
1400  function determineOffsetAndOrder($a_omit_offset = false)
1401  {
1402  global $ilUser;
1403 
1404  if ($this->nav_determined)
1405  {
1406  return true;
1407  }
1408 
1409  if ($_POST[$this->getNavParameter()."1"] != "")
1410  {
1411  if ($_POST[$this->getNavParameter()."1"] != $_POST[$this->getNavParameter()])
1412  {
1413  $this->nav_value = $_POST[$this->getNavParameter()."1"];
1414  }
1415  else if ($_POST[$this->getNavParameter()."2"] != $_POST[$this->getNavParameter()])
1416  {
1417  $this->nav_value = $_POST[$this->getNavParameter()."2"];
1418  }
1419  }
1420  elseif($_GET[$this->getNavParameter()])
1421  {
1422  $this->nav_value = $_GET[$this->getNavParameter()];
1423  }
1424  elseif($_SESSION[$this->getNavParameter()] != "")
1425  {
1426  $this->nav_value = $_SESSION[$this->getNavParameter()];
1427  }
1428 
1429  if ($this->nav_value == "" && $this->getId() != "" && $ilUser->getId() != ANONYMOUS_USER_ID)
1430  {
1431  // get order and direction from db
1432  $this->nav_value =
1433  $this->loadProperty("order").":".
1434  $this->loadProperty("direction").":".
1435  $this->loadProperty("offset");
1436  }
1437  $nav = explode(":", $this->nav_value);
1438 
1439  // $nav[0] is order by
1440  $this->setOrderField(($nav[0] != "") ? $nav[0] : $this->getDefaultOrderField());
1441  $this->setOrderDirection(($nav[1] != "") ? $nav[1] : $this->getDefaultOrderDirection());
1442 
1443  if (!$a_omit_offset)
1444  {
1445  // #8904: offset must be discarded when no limit is given
1446  if(!$this->getExternalSegmentation() && $this->limit_determined && $this->limit == 9999)
1447  {
1448  $this->resetOffset(true);
1449  }
1450  else if (!$this->getExternalSegmentation() && $nav[2] >= $this->max_count)
1451  {
1452  $this->resetOffset(true);
1453  }
1454  else
1455  {
1456  $this->setOffset($nav[2]);
1457  }
1458  }
1459 
1460  if (!$a_omit_offset)
1461  {
1462  $this->nav_determined = true;
1463  }
1464  }
1465 
1467  {
1468  if ($this->getOrderField() != "")
1469  {
1470  $this->storeProperty("order", $this->getOrderField());
1471  }
1472  if ($this->getOrderDirection() != "")
1473  {
1474  $this->storeProperty("direction", $this->getOrderDirection());
1475  }
1476 //echo "-".$this->getOffset()."-";
1477  if ($this->getOffset() !== "")
1478  {
1479  $this->storeProperty("offset", $this->getOffset());
1480  }
1481  }
1482 
1483 
1487  final public function getHTML()
1488  {
1489  global $lng, $ilCtrl, $ilUser;
1490 
1491  if($this->getExportMode())
1492  {
1493  $this->exportData($this->getExportMode(), true);
1494  }
1495 
1496  $this->prepareOutput();
1497 
1498  if (is_object($ilCtrl) && $this->getId() == "")
1499  {
1500  $ilCtrl->saveParameter($this->getParentObject(), $this->getNavParameter());
1501  }
1502 
1503  if(!$this->enabled['content'])
1504  {
1505  return $this->render();
1506  }
1507 
1508  if (!$this->getExternalSegmentation())
1509  {
1510  $this->setMaxCount(count($this->row_data));
1511  }
1512 
1513  $this->determineOffsetAndOrder();
1514 
1515  $this->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
1516 
1517  $data = $this->getData();
1518  if($this->dataExists())
1519  {
1520  // sort
1521  if (!$this->getExternalSorting())
1522  {
1523  $data = ilUtil::sortArray($data, $this->getOrderField(),
1524  $this->getOrderDirection(), $this->numericOrdering($this->getOrderField()));
1525  }
1526 
1527  // slice
1528  if (!$this->getExternalSegmentation())
1529  {
1530  $data = array_slice($data, $this->getOffset(), $this->getLimit());
1531  }
1532  }
1533 
1534  // fill rows
1535  if($this->dataExists())
1536  {
1537  if($this->getPrintMode())
1538  {
1540  }
1541 
1542  $this->tpl->addBlockFile("TBL_CONTENT", "tbl_content", $this->row_template,
1543  $this->row_template_dir);
1544 
1545  foreach($data as $set)
1546  {
1547  $this->tpl->setCurrentBlock("tbl_content");
1548  $this->css_row = ($this->css_row != "tblrow1")
1549  ? "tblrow1"
1550  : "tblrow2";
1551  $this->tpl->setVariable("CSS_ROW", $this->css_row);
1552 
1553  $this->fillRow($set);
1554  $this->tpl->setCurrentBlock("tbl_content");
1555  $this->tpl->parseCurrentBlock();
1556  }
1557  }
1558  else
1559  {
1560  // add standard no items text (please tell me, if it messes something up, alex, 29.8.2008)
1561  $no_items_text = (trim($this->getNoEntriesText()) != '')
1562  ? $this->getNoEntriesText()
1563  : $lng->txt("no_items");
1564 
1565  $this->css_row = ($this->css_row != "tblrow1")
1566  ? "tblrow1"
1567  : "tblrow2";
1568 
1569  $this->tpl->setCurrentBlock("tbl_no_entries");
1570  $this->tpl->setVariable('TBL_NO_ENTRY_CSS_ROW', $this->css_row);
1571  $this->tpl->setVariable('TBL_NO_ENTRY_COLUMN_COUNT', $this->column_count);
1572  $this->tpl->setVariable('TBL_NO_ENTRY_TEXT', trim($no_items_text));
1573  $this->tpl->parseCurrentBlock();
1574  }
1575 
1576 
1577  if(!$this->getPrintMode())
1578  {
1579  // set form action
1580  if ($this->form_action != "" && $this->getOpenFormTag())
1581  {
1582  $hash = "";
1583  if (is_object($ilUser) && $ilUser->getPref("screen_reader_optimization"))
1584  {
1585  $hash = "#".$this->getTopAnchor();
1586  }
1587 
1588  $this->tpl->setCurrentBlock("tbl_form_header");
1589  $this->tpl->setVariable("FORMACTION", $this->getFormAction().$hash);
1590  $this->tpl->setVariable("FORMNAME", $this->getFormName());
1591  $this->tpl->parseCurrentBlock();
1592  }
1593 
1594  if ($this->form_action != "" && $this->getCloseFormTag())
1595  {
1596  $this->tpl->touchBlock("tbl_form_footer");
1597  }
1598 
1599  $this->fillFooter();
1600 
1601  $this->fillHiddenRow();
1602 
1603  $this->fillActionRow();
1604 
1605  $this->storeNavParameter();
1606  }
1607 
1608  return $this->render();
1609  }
1610 
1616  function numericOrdering($a_field)
1617  {
1618  return false;
1619  }
1620 
1625  function render()
1626  {
1627  global $lng, $ilCtrl;
1628 
1629  $this->tpl->setVariable("CSS_TABLE",$this->getStyle("table"));
1630  $this->tpl->setVariable("DATA_TABLE", (int) $this->getIsDataTable());
1631  if ($this->getId() != "")
1632  {
1633  $this->tpl->setVariable("ID", 'id="'.$this->getId().'"');
1634  }
1635 
1636  // description
1637  if ($this->getDescription() != "")
1638  {
1639  $this->tpl->setCurrentBlock("tbl_header_description");
1640  $this->tpl->setVariable("TBL_DESCRIPTION", $this->getDescription());
1641  $this->tpl->parseCurrentBlock();
1642  }
1643 
1644  if(!$this->getPrintMode())
1645  {
1646  $this->renderFilter();
1647  }
1648 
1649  if ($this->getDisplayAsBlock())
1650  {
1651  $this->tpl->touchBlock("outer_start_1");
1652  $this->tpl->touchBlock("outer_end_1");
1653  }
1654  else
1655  {
1656  $this->tpl->touchBlock("outer_start_2");
1657  $this->tpl->touchBlock("outer_end_2");
1658  }
1659 
1660  // table title and icon
1661  if ($this->enabled["title"] && ($this->title != ""
1662  || $this->icon != "" || count($this->header_commands) > 0 ||
1663  $this->headerHTML != "" || $this->close_command != ""))
1664  {
1665  if ($this->enabled["icon"])
1666  {
1667  $this->tpl->setCurrentBlock("tbl_header_title_icon");
1668  $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath($this->icon));
1669  $this->tpl->setVariable("TBL_TITLE_IMG_ALT",$this->icon_alt);
1670  $this->tpl->parseCurrentBlock();
1671  }
1672 
1673  if(!$this->getPrintMode())
1674  {
1675  foreach($this->header_commands as $command)
1676  {
1677  if ($command["img"] != "")
1678  {
1679  $this->tpl->setCurrentBlock("tbl_header_img_link");
1680  if ($command["target"] != "")
1681  {
1682  $this->tpl->setVariable("TARGET_IMG_LINK",
1683  'target="'.$command["target"].'"');
1684  }
1685  $this->tpl->setVariable("ALT_IMG_LINK", $command["text"]);
1686  $this->tpl->setVariable("HREF_IMG_LINK", $command["href"]);
1687  $this->tpl->setVariable("SRC_IMG_LINK",
1688  $command["img"]);
1689  $this->tpl->parseCurrentBlock();
1690  }
1691  else
1692  {
1693  $this->tpl->setCurrentBlock("head_cmd");
1694  $this->tpl->setVariable("TXT_HEAD_CMD", $command["text"]);
1695  $this->tpl->setVariable("HREF_HEAD_CMD", $command["href"]);
1696  $this->tpl->parseCurrentBlock();
1697  }
1698  }
1699  }
1700 
1701  if (isset ($this->headerHTML)) {
1702  $this->tpl->setCurrentBlock("tbl_header_html");
1703  $this->tpl->setVariable ("HEADER_HTML", $this->headerHTML);
1704  $this->tpl->parseCurrentBlock();
1705  }
1706 
1707  // close command
1708  if ($this->close_command != "")
1709  {
1710  $this->tpl->setCurrentBlock("tbl_header_img_link");
1711  $this->tpl->setVariable("ALT_IMG_LINK",$lng->txt("close"));
1712  $this->tpl->setVariable("HREF_IMG_LINK",$this->close_command);
1713  $this->tpl->setVariable("SRC_IMG_LINK",ilUtil::getImagePath("icon_close2.gif"));
1714  $this->tpl->parseCurrentBlock();
1715  }
1716 
1717  $this->tpl->setCurrentBlock("tbl_header_title");
1718  $this->tpl->setVariable("TBL_TITLE",$this->title);
1719  $this->tpl->setVariable("TOP_ANCHOR",$this->getTopAnchor());
1720  if ($this->getDisplayAsBlock())
1721  {
1722  $this->tpl->setVariable("BLK_CLASS", "Block");
1723  }
1724  $this->tpl->parseCurrentBlock();
1725  }
1726 
1727  // table header
1728  if ($this->enabled["header"])
1729  {
1730  $this->fillHeader();
1731  }
1732 
1733  $this->tpl->touchBlock("tbl_table_end");
1734 
1735  return $this->tpl->get();
1736  }
1737 
1741  private function renderFilter()
1742  {
1743  global $lng, $tpl;
1744 
1745  $filter = $this->getFilterItems();
1746  $opt_filter = $this->getFilterItems(true);
1747 
1748  $tpl->addJavascript("./Services/Table/js/ServiceTable.js");
1749 
1750  if (count($filter) == 0 && count($opt_filter) == 0)
1751  {
1752  return;
1753  }
1754 
1755  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
1757 
1758  $ccnt = 0;
1759 
1760  // render standard filter
1761  if (count($filter) > 0)
1762  {
1763  foreach ($filter as $item)
1764  {
1765  if ($ccnt >= $this->getFilterCols())
1766  {
1767  $this->tpl->setCurrentBlock("filter_row");
1768  $this->tpl->parseCurrentBlock();
1769  $ccnt = 0;
1770  }
1771  $this->tpl->setCurrentBlock("filter_item");
1772  $this->tpl->setVariable("OPTION_NAME",
1773  $item->getTitle());
1774  $this->tpl->setVariable("F_INPUT_ID",
1775  $item->getFieldId());
1776  $this->tpl->setVariable("INPUT_HTML",
1777  $item->getTableFilterHTML());
1778  $this->tpl->parseCurrentBlock();
1779  $ccnt++;
1780  }
1781  }
1782 
1783  // render optional filter
1784  if (count($opt_filter) > 0)
1785  {
1786  $this->determineSelectedFilters();
1787 
1788  foreach ($opt_filter as $item)
1789  {
1790  if($this->isFilterSelected($item->getPostVar()))
1791  {
1792  if ($ccnt >= $this->getFilterCols())
1793  {
1794  $this->tpl->setCurrentBlock("filter_row");
1795  $this->tpl->parseCurrentBlock();
1796  $ccnt = 0;
1797  }
1798  $this->tpl->setCurrentBlock("filter_item");
1799  $this->tpl->setVariable("OPTION_NAME",
1800  $item->getTitle());
1801  $this->tpl->setVariable("F_INPUT_ID",
1802  $item->getFieldId());
1803  $this->tpl->setVariable("INPUT_HTML",
1804  $item->getTableFilterHTML());
1805  $this->tpl->parseCurrentBlock();
1806  $ccnt++;
1807  }
1808  }
1809 
1810  // filter selection
1811  $items = array();
1812  foreach ($opt_filter as $item)
1813  {
1814  $k = $item->getPostVar();
1815  $items[$k] = array("txt" => $item->getTitle(),
1816  "selected" => $this->isFilterSelected($k));
1817  }
1818 
1819  include_once("./Services/UIComponent/CheckboxListOverlay/classes/class.ilCheckboxListOverlayGUI.php");
1820  $cb_over = new ilCheckboxListOverlayGUI("tbl_filters_".$this->getId());
1821  $cb_over->setLinkTitle($lng->txt("optional_filters"));
1822  $cb_over->setItems($items);
1823 
1824  $cb_over->setFormCmd($this->getParentCmd());
1825  $cb_over->setFieldVar("tblff".$this->getId());
1826  $cb_over->setHiddenVar("tblfsf".$this->getId());
1827 
1828  $cb_over->setSelectionHeaderClass("ilTableMenuItem");
1829  $this->tpl->setCurrentBlock("filter_select");
1830 
1831  // apply should be the first submit because of enter/return, inserting hidden submit
1832  $this->tpl->setVariable("HIDDEN_CMD_APPLY", $this->filter_cmd);
1833 
1834  $this->tpl->setVariable("FILTER_SELECTOR", $cb_over->getHTML());
1835  $this->tpl->parseCurrentBlock();
1836  }
1837 
1838  // if any filter
1839  if($ccnt > 0 || count($opt_filter) > 0)
1840  {
1841  $this->tpl->setVariable("TXT_FILTER", $lng->txt("filter"));
1842 
1843  if($ccnt > 0)
1844  {
1845  if ($ccnt < $this->getFilterCols())
1846  {
1847  for($i = $ccnt; $i<=$this->getFilterCols(); $i++)
1848  {
1849  $this->tpl->touchBlock("filter_empty_cell");
1850  }
1851  }
1852  $this->tpl->setCurrentBlock("filter_row");
1853  $this->tpl->parseCurrentBlock();
1854 
1855  $this->tpl->setCurrentBlock("filter_buttons");
1856  $this->tpl->setVariable("CMD_APPLY", $this->filter_cmd);
1857  $this->tpl->setVariable("TXT_APPLY", $lng->txt("apply_filter"));
1858  $this->tpl->setVariable("CMD_RESET", $this->reset_cmd);
1859  $this->tpl->setVariable("TXT_RESET", $lng->txt("reset_filter"));
1860  }
1861  else if(count($opt_filter) > 0)
1862  {
1863  $this->tpl->setCurrentBlock("optional_filter_hint");
1864  $this->tpl->setVariable('TXT_OPT_HINT', $lng->txt('optional_filter_hint'));
1865  $this->tpl->parseCurrentBlock();
1866  }
1867 
1868  $this->tpl->setCurrentBlock("filter_section");
1869  $this->tpl->setVariable("FIL_ID", $this->getId());
1870  $this->tpl->parseCurrentBlock();
1871 
1872  // (keep) filter hidden?
1873  if ($this->loadProperty("filter") != 1)
1874  {
1875  if (!$this->getDisableFilterHiding())
1876  {
1877  $this->tpl->setCurrentBlock("filter_hidden");
1878  $this->tpl->setVariable("FI_ID", $this->getId());
1879  $this->tpl->parseCurrentBlock();
1880  }
1881  }
1882  }
1883  }
1884 
1888  public function writeFilterToSession()
1889  {
1890  global $lng;
1891 
1892  $filter = $this->getFilterItems();
1893  $opt_filter = $this->getFilterItems(true);
1894 
1895  foreach ($filter as $item)
1896  {
1897  if ($item->checkInput())
1898  {
1899  $item->setValueByArray($_POST);
1900  $item->writeToSession();
1901  }
1902  }
1903  foreach ($opt_filter as $item)
1904  {
1905  if ($item->checkInput())
1906  {
1907  $item->setValueByArray($_POST);
1908  $item->writeToSession();
1909  }
1910  }
1911  }
1912 
1916  public function resetFilter()
1917  {
1918  global $lng;
1919 
1920  $filter = $this->getFilterItems();
1921  $opt_filter = $this->getFilterItems(true);
1922 
1923  foreach ($filter as $item)
1924  {
1925  if ($item->checkInput())
1926  {
1927  $item->setValueByArray($_POST);
1928  $item->clearFromSession();
1929  }
1930  }
1931  foreach ($opt_filter as $item)
1932  {
1933  if ($item->checkInput())
1934  {
1935  $item->setValueByArray($_POST);
1936  $item->clearFromSession();
1937  }
1938  }
1939  }
1940 
1947  protected function fillRow($a_set)
1948  {
1949  foreach ($a_set as $key => $value)
1950  {
1951  $this->tpl->setVariable("VAL_".strtoupper($key), $value);
1952  }
1953  }
1954 
1958  function fillFooter()
1959  {
1960  global $lng, $ilCtrl, $ilUser;
1961 
1962  $footer = false;
1963 
1964  // select all checkbox
1965  if ((strlen($this->getFormName())) && (strlen($this->getSelectAllCheckbox())) && $this->dataExists())
1966  {
1967  $this->tpl->setCurrentBlock("select_all_checkbox");
1968  $this->tpl->setVariable("SELECT_ALL_TXT_SELECT_ALL", $lng->txt("select_all"));
1969  $this->tpl->setVariable("SELECT_ALL_CHECKBOX_NAME", $this->getSelectAllCheckbox());
1970  $this->tpl->setVariable("SELECT_ALL_FORM_NAME", $this->getFormName());
1971  $this->tpl->setVariable("CHECKBOXNAME", "chb_select_all_" . $this->unique_id);
1972  $this->tpl->parseCurrentBlock();
1973  }
1974 
1975  // table footer numinfo
1976  if ($this->enabled["numinfo"] && $this->enabled["footer"])
1977  {
1978  $start = $this->offset + 1; // compute num info
1979  if (!$this->dataExists())
1980  {
1981  $start = 0;
1982  }
1983  $end = $this->offset + $this->limit;
1984 
1985  if ($end > $this->max_count or $this->limit == 0)
1986  {
1987  $end = $this->max_count;
1988  }
1989 
1990  if ($this->max_count > 0)
1991  {
1992  if ($this->lang_support)
1993  {
1994  $numinfo = "(".$start." - ".$end." ".strtolower($this->lng->txt("of"))." ".$this->max_count.")";
1995  }
1996  else
1997  {
1998  $numinfo = "(".$start." - ".$end." of ".$this->max_count.")";
1999  }
2000  }
2001  if ($this->max_count > 0)
2002  {
2003  if ($this->getEnableNumInfo())
2004  {
2005  $this->tpl->setCurrentBlock("tbl_footer_numinfo");
2006  $this->tpl->setVariable("NUMINFO", $numinfo);
2007  $this->tpl->parseCurrentBlock();
2008  }
2009  }
2010  $footer = true;
2011  }
2012 
2013  // table footer linkbar
2014  if ($this->enabled["linkbar"] && $this->enabled["footer"] && $this->limit != 0
2015  && $this->max_count > 0)
2016  {
2017  $layout = array(
2018  "link" => $this->footer_style,
2019  "prev" => $this->footer_previous,
2020  "next" => $this->footer_next,
2021  );
2022  //if (!$this->getDisplayAsBlock())
2023  //{
2024  $linkbar = $this->getLinkbar("1");
2025  $this->tpl->setCurrentBlock("tbl_footer_linkbar");
2026  $this->tpl->setVariable("LINKBAR", $linkbar);
2027  $this->tpl->parseCurrentBlock();
2028  $linkbar = true;
2029  //}
2030  $footer = true;
2031  }
2032 
2033  // column selector
2034  if (count($this->getSelectableColumns()) > 0)
2035  {
2036  $items = array();
2037  foreach ($this->getSelectableColumns() as $k => $c)
2038  {
2039  $items[$k] = array("txt" => $c["txt"],
2040  "selected" => $this->isColumnSelected($k));
2041  }
2042  include_once("./Services/UIComponent/CheckboxListOverlay/classes/class.ilCheckboxListOverlayGUI.php");
2043  $cb_over = new ilCheckboxListOverlayGUI("tbl_".$this->getId());
2044  $cb_over->setLinkTitle($lng->txt("columns"));
2045  $cb_over->setItems($items);
2046  //$cb_over->setUrl("./ilias.php?baseClass=ilTablePropertiesStorage&table_id=".
2047  // $this->getId()."&cmd=saveSelectedFields&user_id=".$ilUser->getId());
2048  $cb_over->setFormCmd($this->getParentCmd());
2049  $cb_over->setFieldVar("tblfs".$this->getId());
2050  $cb_over->setHiddenVar("tblfsh".$this->getId());
2051  $cb_over->setSelectionHeaderClass("ilTableMenuItem");
2052  $column_selector = $cb_over->getHTML();
2053  $footer = true;
2054  }
2055 
2056  if($this->getShowTemplates() && is_object($ilUser))
2057  {
2058  // template handling
2059  if(isset($_REQUEST["tbltplcrt"]) && $_REQUEST["tbltplcrt"])
2060  {
2061  if($this->saveTemplate($_REQUEST["tbltplcrt"]))
2062  {
2063  ilUtil::sendSuccess($lng->txt("tbl_template_created"));
2064  }
2065  }
2066  else if(isset($_REQUEST["tbltpldel"]) && $_REQUEST["tbltpldel"])
2067  {
2068  if($this->deleteTemplate($_REQUEST["tbltpldel"]))
2069  {
2070  ilUtil::sendSuccess($lng->txt("tbl_template_deleted"));
2071  }
2072  }
2073 
2074  $create_id = "template_create_overlay_".$this->getId();
2075  $delete_id = "template_delete_overlay_".$this->getId();
2076  $list_id = "template_stg_".$this->getId();
2077 
2078  include_once("./Services/Table/classes/class.ilTableTemplatesStorage.php");
2079  $storage = new ilTableTemplatesStorage();
2080  $templates = $storage->getNames($this->getContext(), $ilUser->getId());
2081 
2082  include_once("./Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php");
2083 
2084  // form to delete template
2085  if(sizeof($templates))
2086  {
2087  $overlay = new ilOverlayGUI($delete_id);
2088  $overlay->setTrigger($list_id."_delete");
2089  $overlay->setAnchor("ilAdvSelListAnchorElement_".$list_id);
2090  $overlay->setAutoHide(false);
2091  $overlay->add();
2092 
2093  $this->tpl->setCurrentBlock("template_editor_delete_item");
2094  $this->tpl->setVariable("TEMPLATE_DELETE_OPTION", "");
2095  $this->tpl->parseCurrentBlock();
2096  foreach($templates as $name)
2097  {
2098  $this->tpl->setVariable("TEMPLATE_DELETE_OPTION", $name);
2099  $this->tpl->parseCurrentBlock();
2100  }
2101 
2102  $this->tpl->setCurrentBlock("template_editor_delete");
2103  $this->tpl->setVariable("TEMPLATE_DELETE_ID", $delete_id);
2104  $this->tpl->setVariable("TXT_TEMPLATE_DELETE", $lng->txt("tbl_template_delete"));
2105  $this->tpl->setVariable("TXT_TEMPLATE_DELETE_SUBMIT", $lng->txt("delete"));
2106  $this->tpl->setVariable("TEMPLATE_DELETE_CMD", $this->parent_cmd);
2107  $this->tpl->parseCurrentBlock();
2108  }
2109 
2110 
2111  // form to save new template
2112  $overlay = new ilOverlayGUI($create_id);
2113  $overlay->setTrigger($list_id."_create");
2114  $overlay->setAnchor("ilAdvSelListAnchorElement_".$list_id);
2115  $overlay->setAutoHide(false);
2116  $overlay->add();
2117 
2118  $this->tpl->setCurrentBlock("template_editor");
2119  $this->tpl->setVariable("TEMPLATE_CREATE_ID", $create_id);
2120  $this->tpl->setVariable("TXT_TEMPLATE_CREATE", $lng->txt("tbl_template_create"));
2121  $this->tpl->setVariable("TXT_TEMPLATE_CREATE_SUBMIT", $lng->txt("save"));
2122  $this->tpl->setVariable("TEMPLATE_CREATE_CMD", $this->parent_cmd);
2123  $this->tpl->parseCurrentBlock();
2124 
2125  // load saved template
2126  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
2127  $alist = new ilAdvancedSelectionListGUI();
2128  $alist->setId($list_id);
2129  $alist->addItem($lng->txt("tbl_template_create"), "create", "#");
2130  if(sizeof($templates))
2131  {
2132  $alist->addItem($lng->txt("tbl_template_delete"), "delete", "#");
2133  foreach($templates as $name)
2134  {
2135  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_tpl", urlencode($name));
2136  $alist->addItem($name, $name, $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd));
2137  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_tpl", "");
2138  }
2139  }
2140  $alist->setListTitle($lng->txt("tbl_templates"));
2141  $this->tpl->setVariable("TEMPLATE_SELECTOR", "&nbsp;".$alist->getHTML());
2142  }
2143 
2144  if ($footer)
2145  {
2146  $this->tpl->setCurrentBlock("tbl_footer");
2147  $this->tpl->setVariable("COLUMN_COUNT", $this->getColumnCount());
2148  if ($this->getDisplayAsBlock())
2149  {
2150  $this->tpl->setVariable("BLK_CLASS", "Block");
2151  }
2152  $this->tpl->parseCurrentBlock();
2153 
2154  // top navigation, if number info or linkbar given
2155  if ($numinfo != "" || $linkbar != "" || $column_selector != "" ||
2156  count($this->filters) > 0 || count($this->optional_filters) > 0)
2157  {
2158  if (is_object($ilUser) && (count($this->filters) || count($this->optional_filters)))
2159  {
2160  $this->tpl->setCurrentBlock("filter_activation");
2161  $this->tpl->setVariable("TXT_ACTIVATE_FILTER", $lng->txt("show_filter"));
2162  $this->tpl->setVariable("FILA_ID", $this->getId());
2163  if ($this->getId() != "")
2164  {
2165  $this->tpl->setVariable("SAVE_URLA", "./ilias.php?baseClass=ilTablePropertiesStorage&table_id=".
2166  $this->getId()."&cmd=showFilter&user_id=".$ilUser->getId());
2167  }
2168  $this->tpl->parseCurrentBlock();
2169 
2170 
2171  if (!$this->getDisableFilterHiding())
2172  {
2173  $this->tpl->setCurrentBlock("filter_deactivation");
2174  $this->tpl->setVariable("TXT_HIDE", $lng->txt("hide_filter"));
2175  if ($this->getId() != "")
2176  {
2177  $this->tpl->setVariable("SAVE_URL", "./ilias.php?baseClass=ilTablePropertiesStorage&table_id=".
2178  $this->getId()."&cmd=hideFilter&user_id=".$ilUser->getId());
2179  $this->tpl->setVariable("FILD_ID", $this->getId());
2180  }
2181  $this->tpl->parseCurrentBlock();
2182  }
2183 
2184  }
2185 
2186  if ($numinfo != "" && $this->getEnableNumInfo())
2187  {
2188  $this->tpl->setCurrentBlock("top_numinfo");
2189  $this->tpl->setVariable("NUMINFO", $numinfo);
2190  $this->tpl->parseCurrentBlock();
2191  }
2192  if ($linkbar != "" && !$this->getDisplayAsBlock())
2193  {
2194  $linkbar = $this->getLinkbar("2");
2195  $this->tpl->setCurrentBlock("top_linkbar");
2196  $this->tpl->setVariable("LINKBAR", $linkbar);
2197  $this->tpl->parseCurrentBlock();
2198  }
2199 
2200  // column selector
2201  $this->tpl->setVariable("COLUMN_SELECTOR", $column_selector);
2202 
2203  // row selector
2204  if ($this->getShowRowsSelector() && is_object($ilUser))
2205  {
2206  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
2207  $alist = new ilAdvancedSelectionListGUI();
2208  $alist->setId("sellst_rows");
2209  $hpp = ($ilUser->getPref("hits_per_page") != 9999)
2210  ? $ilUser->getPref("hits_per_page")
2211  : $lng->txt("unlimited");
2212 
2213  $options = array(0 => $lng->txt("default")." (".$hpp.")",5 => 5, 10 => 10, 15 => 15, 20 => 20,
2214  30 => 30, 40 => 40, 50 => 50,
2215  100 => 100, 200 => 200, 400 => 400, 800 => 800);
2216  foreach ($options as $k => $v)
2217  {
2218  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_trows", $k);
2219  $alist->addItem($v, $k, $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd));
2220  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_trows", "");
2221  }
2222  $alist->setListTitle($lng->txt("rows"));
2223  $this->tpl->setVariable("ROW_SELECTOR", $alist->getHTML());
2224  }
2225 
2226  // export
2227  if(sizeof($this->export_formats) && $this->dataExists())
2228  {
2229  $map = array(self::EXPORT_EXCEL => "tbl_export_excel",
2230  self::EXPORT_CSV => "tbl_export_csv");
2231  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
2232  $alist = new ilAdvancedSelectionListGUI();
2233  $alist->setId("sellst_xpt");
2234  foreach($this->export_formats as $format)
2235  {
2236  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_xpt", $format);
2237  $url = $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd);
2238  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_xpt", "");
2239  $alist->addItem($lng->txt($map[$format]), $format, $url);
2240  }
2241  $alist->setListTitle($lng->txt("export"));
2242  $this->tpl->setVariable("EXPORT_SELECTOR", "&nbsp;".$alist->getHTML());
2243  }
2244 
2245  $this->tpl->setCurrentBlock("top_navigation");
2246  $this->tpl->setVariable("COLUMN_COUNT", $this->getColumnCount());
2247  if ($this->getDisplayAsBlock())
2248  {
2249  $this->tpl->setVariable("BLK_CLASS", "Block");
2250  }
2251  $this->tpl->parseCurrentBlock();
2252  }
2253  }
2254  }
2255 
2263  function getLinkbar($a_num)
2264  {
2265  global $ilCtrl, $lng, $ilUser;
2266 
2267  $hash = "";
2268  if (is_object($ilUser) && $ilUser->getPref("screen_reader_optimization"))
2269  {
2270  $hash = "#".$this->getTopAnchor();
2271  }
2272 
2273  $link = $ilCtrl->getLinkTargetByClass(get_class($this->parent_obj), $this->parent_cmd).
2274  "&".$this->getNavParameter()."=".
2275  $this->getOrderField().":".$this->getOrderDirection().":";
2276 
2277  $LinkBar = "";
2278  $layout_prev = $lng->txt("previous");
2279  $layout_next = $lng->txt("next");
2280 
2281  // if more entries then entries per page -> show link bar
2282  if ($this->max_count > $this->getLimit() || $this->custom_prev_next)
2283  {
2284  $sep = "<span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>";
2285 
2286  // calculate number of pages
2287  $pages = intval($this->max_count / $this->getLimit());
2288 
2289  // add a page if a rest remains
2290  if (($this->max_count % $this->getLimit()))
2291  $pages++;
2292 
2293  // links to other pages
2294  $offset_arr = array();
2295  for ($i = 1 ;$i <= $pages ; $i++)
2296  {
2297  $newoffset = $this->getLimit() * ($i-1);
2298 
2299  $nav_value = $this->getOrderField().":".$this->getOrderDirection().":".$newoffset;
2300  $offset_arr[$nav_value] = $i;
2301  }
2302 
2303  $sep = "<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
2304 
2305  // previous link
2306  if ($this->custom_prev_next && $this->custom_prev != "")
2307  {
2308  if ($LinkBar != "")
2309  $LinkBar .= $sep;
2310  $LinkBar .= "<a href=\"".$this->custom_prev.$hash."\">".$layout_prev."</a>";
2311  }
2312  else if ($this->getOffset() >= 1 && !$this->custom_prev_next)
2313  {
2314  if ($LinkBar != "")
2315  $LinkBar .= $sep;
2316  $prevoffset = $this->getOffset() - $this->getLimit();
2317  $LinkBar .= "<a href=\"".$link.$prevoffset.$hash."\">".$layout_prev."</a>";
2318  }
2319  else
2320  {
2321  if ($LinkBar != "")
2322  $LinkBar .= $sep;
2323  $LinkBar .= '<span class="ilTableFootLight">'.$layout_prev."</span>";
2324  }
2325 
2326  // current value
2327  if ($a_num == "1")
2328  {
2329  $LinkBar .= '<input type="hidden" name="'.$this->getNavParameter().
2330  '" value="'.$this->getOrderField().":".$this->getOrderDirection().":".$this->getOffset().'" />';
2331  }
2332 
2333  $sep = "<span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>";
2334 
2335  // show next link (if not last page)
2336  if ($this->custom_prev_next && $this->custom_next != "")
2337  {
2338  if ($LinkBar != "")
2339  $LinkBar .= $sep;
2340  $LinkBar .= "<a href=\"".$this->custom_next.$hash."\">".$layout_next."</a>";
2341  }
2342  else if (! ( ($this->getOffset() / $this->getLimit())==($pages-1) ) && ($pages!=1) &&
2343  !$this->custom_prev_next)
2344  {
2345  if ($LinkBar != "")
2346  $LinkBar .= $sep;
2347  $newoffset = $this->getOffset() + $this->getLimit();
2348  $LinkBar .= "<a href=\"".$link.$newoffset.$hash."\">".$layout_next."</a>";
2349  }
2350  else
2351  {
2352  if ($LinkBar != "")
2353  $LinkBar .= $sep;
2354  $LinkBar .= '<span class="ilTableFootLight">'.$layout_next."</span>";
2355  }
2356 
2357  $sep = "<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
2358 
2359  if (count($offset_arr) && !$this->getDisplayAsBlock() && !$this->custom_prev_next)
2360  {
2361  if ($LinkBar != "")
2362  $LinkBar .= $sep;
2363  $LinkBar .= "".
2364  '<label for="tab_page_sel_'.$a_num.'">'.$lng->txt("page").'</label> '.
2365  ilUtil::formSelect($this->nav_value,
2366  $this->getNavParameter().$a_num, $offset_arr, false, true, 0, "small",
2367  array("id" => "tab_page_sel_".$a_num,
2368  "onchange" => "ilTablePageSelection(this, 'cmd[".$this->parent_cmd."]')"));
2369  //' <input class="submit" type="submit" name="cmd['.$this->parent_cmd.']" value="'.
2370  //$lng->txt("ok").'" />';
2371  }
2372 
2373  return $LinkBar;
2374  }
2375  else
2376  {
2377  return false;
2378  }
2379  }
2380 
2381  function fillHiddenRow()
2382  {
2383  $hidden_row = false;
2384  if(count($this->hidden_inputs))
2385  {
2386  foreach ($this->hidden_inputs as $hidden_input)
2387  {
2388  $this->tpl->setCurrentBlock("tbl_hidden_field");
2389  $this->tpl->setVariable("FIELD_NAME", $hidden_input["name"]);
2390  $this->tpl->setVariable("FIELD_VALUE", $hidden_input["value"]);
2391  $this->tpl->parseCurrentBlock();
2392  }
2393 
2394  $this->tpl->setCurrentBlock("tbl_hidden_row");
2395  $this->tpl->parseCurrentBlock();
2396  }
2397  }
2398 
2402  function fillActionRow()
2403  {
2404  global $lng;
2405 
2406  // action row
2407  $action_row = false;
2408  $arrow = false;
2409 
2410  // add selection buttons
2411  if (count($this->sel_buttons) > 0)
2412  {
2413  foreach ($this->sel_buttons as $button)
2414  {
2415  $this->tpl->setCurrentBlock("sel_button");
2416  $this->tpl->setVariable("SBUTTON_SELECT",
2417  ilUtil::formSelect($button["selected"], $button["sel_var"],
2418  $button["options"], false, true));
2419  $this->tpl->setVariable("SBTN_NAME", $button["cmd"]);
2420  $this->tpl->setVariable("SBTN_VALUE", $button["text"]);
2421  $this->tpl->parseCurrentBlock();
2422 
2423  if ($this->getTopCommands())
2424  {
2425  $this->tpl->setCurrentBlock("sel_top_button");
2426  $this->tpl->setVariable("SBUTTON_SELECT",
2427  ilUtil::formSelect($button["selected"], $button["sel_var"],
2428  $button["options"], false, true));
2429  $this->tpl->setVariable("SBTN_NAME", $button["cmd"]);
2430  $this->tpl->setVariable("SBTN_VALUE", $button["text"]);
2431  $this->tpl->parseCurrentBlock();
2432  }
2433  }
2434  $buttons = true;
2435  $action_row = true;
2436  }
2437  $this->sel_buttons[] = array("options" => $a_options, "cmd" => $a_cmd, "text" => $a_text);
2438 
2439  // add buttons
2440  if (count($this->buttons) > 0)
2441  {
2442  foreach ($this->buttons as $button)
2443  {
2444  if (strlen($button['onclick']))
2445  {
2446  $this->tpl->setCurrentBlock('cmdonclick');
2447  $this->tpl->setVariable('CMD_ONCLICK', $button['onclick']);
2448  $this->tpl->parseCurrentBlock();
2449  }
2450  $this->tpl->setCurrentBlock("plain_button");
2451  if ($button["id"] != "")
2452  {
2453  $this->tpl->setVariable("PBID", ' id="'.$button["id"].'" ');
2454  }
2455  $this->tpl->setVariable("PBTN_NAME", $button["cmd"]);
2456  $this->tpl->setVariable("PBTN_VALUE", $button["text"]);
2457  $this->tpl->parseCurrentBlock();
2458 
2459  if ($this->getTopCommands())
2460  {
2461  if (strlen($button['onclick']))
2462  {
2463  $this->tpl->setCurrentBlock('top_cmdonclick');
2464  $this->tpl->setVariable('CMD_ONCLICK', $button['onclick']);
2465  $this->tpl->parseCurrentBlock();
2466  }
2467  $this->tpl->setCurrentBlock("plain_top_button");
2468  $this->tpl->setVariable("PBTN_NAME", $button["cmd"]);
2469  $this->tpl->setVariable("PBTN_VALUE", $button["text"]);
2470  $this->tpl->parseCurrentBlock();
2471  }
2472  }
2473 
2474  $buttons = true;
2475  $action_row = true;
2476  }
2477 
2478  // multi selection
2479  if(count($this->mi_sel_buttons))
2480  {
2481  foreach ($this->mi_sel_buttons as $button)
2482  {
2483  $this->tpl->setCurrentBlock("mi_sel_button");
2484  $this->tpl->setVariable("MI_BUTTON_SELECT",
2485  ilUtil::formSelect($button["selected"], $button["sel_var"],
2486  $button["options"], false, true));
2487  $this->tpl->setVariable("MI_BTN_NAME", $button["cmd"]);
2488  $this->tpl->setVariable("MI_BTN_VALUE", $button["text"]);
2489  $this->tpl->parseCurrentBlock();
2490 
2491  if ($this->getTopCommands())
2492  {
2493  $this->tpl->setCurrentBlock("mi_top_sel_button");
2494  $this->tpl->setVariable("MI_BUTTON_SELECT",
2495  ilUtil::formSelect($button["selected"], $button["sel_var"]."_2",
2496  $button["options"], false, true));
2497  $this->tpl->setVariable("MI_BTN_NAME", $button["cmd"]);
2498  $this->tpl->setVariable("MI_BTN_VALUE", $button["text"]);
2499  $this->tpl->parseCurrentBlock();
2500  }
2501 
2502  }
2503  $arrow = true;
2504  $action_row = true;
2505  }
2506 
2507 
2508  if (count($this->multi) > 1 && $this->dataExists())
2509  {
2510  $this->tpl->setCurrentBlock("tbl_cmd_select");
2511  $sel = array();
2512  foreach ($this->multi as $mc)
2513  {
2514  $sel[$mc["cmd"]] = $mc["text"];
2515  }
2516  $this->tpl->setVariable("SELECT_CMDS",
2517  ilUtil::formSelect("", "selected_cmd", $sel, false, true));
2518  $this->tpl->setVariable("TXT_EXECUTE", $lng->txt("execute"));
2519  $this->tpl->parseCurrentBlock();
2520  $arrow = true;
2521  $action_row = true;
2522 
2523  if ($this->getTopCommands())
2524  {
2525  $this->tpl->setCurrentBlock("tbl_top_cmd_select");
2526  $sel = array();
2527  foreach ($this->multi as $mc)
2528  {
2529  $sel[$mc["cmd"]] = $mc["text"];
2530  }
2531  $this->tpl->setVariable("SELECT_CMDS",
2532  ilUtil::formSelect("", "selected_cmd2", $sel, false, true));
2533  $this->tpl->setVariable("TXT_EXECUTE", $lng->txt("execute"));
2534  $this->tpl->parseCurrentBlock();
2535  }
2536  }
2537  elseif(count($this->multi) == 1 && $this->dataExists())
2538  {
2539  $this->tpl->setCurrentBlock("tbl_single_cmd");
2540  $sel = array();
2541  foreach ($this->multi as $mc)
2542  {
2543  $cmd = $mc['cmd'];
2544  $txt = $mc['text'];
2545  }
2546  $this->tpl->setVariable("TXT_SINGLE_CMD",$txt);
2547  $this->tpl->setVariable("SINGLE_CMD",$cmd);
2548  $this->tpl->parseCurrentBlock();
2549  $arrow = true;
2550  $action_row = true;
2551 
2552  if ($this->getTopCommands())
2553  {
2554  $this->tpl->setCurrentBlock("tbl_top_single_cmd");
2555  $sel = array();
2556  foreach ($this->multi as $mc)
2557  {
2558  $cmd = $mc['cmd'];
2559  $txt = $mc['text'];
2560  }
2561  $this->tpl->setVariable("TXT_SINGLE_CMD",$txt);
2562  $this->tpl->setVariable("SINGLE_CMD",$cmd);
2563  $this->tpl->parseCurrentBlock();
2564  }
2565  }
2566 
2567  if ($arrow)
2568  {
2569  $this->tpl->setCurrentBlock("tbl_action_img_arrow");
2570  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
2571  $this->tpl->setVariable("ALT_ARROW", $lng->txt("action"));
2572  $this->tpl->parseCurrentBlock();
2573 
2574  if ($this->getTopCommands())
2575  {
2576  $this->tpl->setCurrentBlock("tbl_top_action_img_arrow");
2577  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_upright.gif"));
2578  $this->tpl->setVariable("ALT_ARROW", $lng->txt("action"));
2579  $this->tpl->parseCurrentBlock();
2580  }
2581  }
2582 
2583  if ($action_row)
2584  {
2585  $this->tpl->setCurrentBlock("tbl_action_row");
2586  $this->tpl->parseCurrentBlock();
2587  if ($this->getTopCommands())
2588  {
2589  $this->tpl->setCurrentBlock("tbl_top_action_row");
2590  $this->tpl->parseCurrentBlock();
2591  }
2592  }
2593  }
2594 
2600  public function setHeaderHTML($html)
2601  {
2602  $this->headerHTML = $html;
2603  }
2604 
2611  function storeProperty($type, $value)
2612  {
2613  global $ilUser;
2614 
2615  if(is_object($ilUser) && $this->getId() != "" && $ilUser->getId() != ANONYMOUS_USER_ID)
2616  {
2617  include_once("./Services/Table/classes/class.ilTablePropertiesStorage.php");
2618  $tab_prop = new ilTablePropertiesStorage();
2619 
2620  $tab_prop->storeProperty($this->getId(), $ilUser->getId(), $type, $value);
2621  }
2622  }
2623 
2630  function loadProperty($type)
2631  {
2632  global $ilUser;
2633 
2634  if(is_object($ilUser) && $this->getId() != "" && $ilUser->getId() != ANONYMOUS_USER_ID)
2635  {
2636  include_once("./Services/Table/classes/class.ilTablePropertiesStorage.php");
2637  $tab_prop = new ilTablePropertiesStorage();
2638 
2639  return $tab_prop->getProperty($this->getId(), $ilUser->getId(), $type);
2640  }
2641  }
2642 
2648  public function getCurrentState()
2649  {
2650  $this->determineOffsetAndOrder();
2651  $this->determineLimit();
2652  $this->determineSelectedColumns();
2653  $this->determineSelectedFilters();
2654 
2655  // "filter" show/hide is not saved
2656 
2657  $result = array();
2658  $result["order"] = $this->getOrderField();
2659  $result["direction"] = $this->getOrderDirection();
2660  $result["offset"] = $this->getOffset();
2661  $result["rows"] = $this->getLimit();
2662  $result["selfields"] = $this->getSelectedColumns();
2663  $result["selfilters"] = $this->getSelectedFilters();
2664 
2665  // gather filter values
2666  if($this->filters)
2667  {
2668  foreach($this->filters as $item)
2669  {
2670  $result["filter_values"][$item->getFieldId()] = $this->getFilterValue($item);
2671  }
2672  }
2673  if($this->optional_filters && $result["selfilters"])
2674  {
2675  foreach($this->optional_filters as $item)
2676  {
2677  if(in_array($item->getFieldId(), $result["selfilters"]))
2678  {
2679  $result["filter_values"][$item->getFieldId()] = $this->getFilterValue($item);
2680  }
2681  }
2682  }
2683 
2684  return $result;
2685  }
2686 
2693  protected function getFilterValue(ilFormPropertyGUI $a_item)
2694  {
2695  if(method_exists($a_item, "getChecked"))
2696  {
2697  return $a_item->getChecked();
2698  }
2699  else if(method_exists($a_item, "getValue"))
2700  {
2701  return $a_item->getValue();
2702  }
2703  else if(method_exists($a_item, "getDate"))
2704  {
2705  return $a_item->getDate()->get(IL_CAL_DATE);
2706  }
2707  }
2708 
2715  protected function SetFilterValue(ilFormPropertyGUI $a_item, $a_value)
2716  {
2717  if(method_exists($a_item, "setChecked"))
2718  {
2719  $a_item->setChecked($a_value);
2720  }
2721  else if(method_exists($a_item, "setValue"))
2722  {
2723  $a_item->setValue($a_value);
2724  }
2725  else if(method_exists($a_item, "setDate"))
2726  {
2727  $a_item->setDate(new ilDate($a_value, IL_CAL_DATE));
2728  }
2729  $a_item->writeToSession();
2730  }
2731 
2737  public function setContext($id)
2738  {
2739  if(trim($id))
2740  {
2741  $this->context = $id;
2742  }
2743  }
2744 
2750  public function getContext()
2751  {
2752  return $this->context;
2753  }
2754 
2760  public function setShowRowsSelector($a_value)
2761  {
2762  $this->show_rows_selector = (bool)$a_value;
2763  }
2764 
2770  public function getShowRowsSelector()
2771  {
2773  }
2774 
2780  public function setShowTemplates($a_value)
2781  {
2782  $this->show_templates = (bool)$a_value;
2783  }
2784 
2790  public function getShowTemplates()
2791  {
2792  return $this->show_templates;
2793  }
2794 
2801  public function restoreTemplate($a_name)
2802  {
2803  global $ilUser;
2804 
2805  $a_name = ilUtil::stripSlashes($a_name);
2806 
2807  if(trim($a_name) && $this->getContext() != "" && is_object($ilUser) && $ilUser->getId() != ANONYMOUS_USER_ID)
2808  {
2809  include_once("./Services/Table/classes/class.ilTableTemplatesStorage.php");
2810  $storage = new ilTableTemplatesStorage();
2811 
2812  $data = $storage->load($this->getContext(), $ilUser->getId(), $a_name);
2813  if(is_array($data))
2814  {
2815  foreach($data as $property => $value)
2816  {
2817  $this->storeProperty($property, $value);
2818  }
2819  }
2820 
2821  $data["filter_values"] = unserialize($data["filter_values"]);
2822  if($data["filter_values"])
2823  {
2824  $this->restore_filter_values = $data["filter_values"];
2825  }
2826 
2827  return true;
2828  }
2829  return false;
2830  }
2831 
2838  public function saveTemplate($a_name)
2839  {
2840  global $ilUser;
2841 
2842  $a_name = ilUtil::stripSlashes($a_name);
2843 
2844  if(trim($a_name) && $this->getContext() != "" && is_object($ilUser) && $ilUser->getId() != ANONYMOUS_USER_ID)
2845  {
2846  include_once("./Services/Table/classes/class.ilTableTemplatesStorage.php");
2847  $storage = new ilTableTemplatesStorage();
2848 
2849  $state = $this->getCurrentState();
2850  $state["filter_values"] = serialize($state["filter_values"]);
2851  $state["selfields"] = serialize($state["selfields"]);
2852  $state["selfilters"] = serialize($state["selfilters"]);
2853 
2854  $storage->store($this->getContext(), $ilUser->getId(), $a_name, $state);
2855  return true;
2856  }
2857  return false;
2858  }
2859 
2866  public function deleteTemplate($a_name)
2867  {
2868  global $ilUser;
2869 
2870  $a_name = ilUtil::stripSlashes($a_name);
2871 
2872  if(trim($a_name) && $this->getContext() != "" && is_object($ilUser) && $ilUser->getId() != ANONYMOUS_USER_ID)
2873  {
2874  include_once("./Services/Table/classes/class.ilTableTemplatesStorage.php");
2875  $storage = new ilTableTemplatesStorage();
2876  $storage->delete($this->getContext(), $ilUser->getId(), $a_name);
2877  return true;
2878  }
2879  return false;
2880  }
2881 
2885  function getLimit()
2886  {
2887  if($this->getExportMode() || $this->getPrintMode())
2888  {
2889  return 9999;
2890  }
2891  return parent::getLimit();
2892  }
2893 
2897  function getOffset()
2898  {
2899  if($this->getExportMode() || $this->getPrintMode())
2900  {
2901  return 0;
2902  }
2903  return parent::getOffset();
2904  }
2905 
2911  public function setExportFormats(array $formats)
2912  {
2913  $this->export_formats = array();
2914  $valid = array(self::EXPORT_EXCEL, self::EXPORT_CSV);
2915  foreach($formats as $format)
2916  {
2917  if(in_array($format, $valid))
2918  {
2919  $this->export_formats[] = $format;
2920  }
2921  }
2922  }
2923 
2928  public function setPrintMode($a_value = false)
2929  {
2930  $this->print_mode = (bool)$a_value;
2931  }
2932 
2937  public function getPrintMode()
2938  {
2939  return $this->print_mode;
2940  }
2941 
2947  public function getExportMode()
2948  {
2949  return $this->export_mode;
2950  }
2951 
2957  public function exportData($format, $send = false)
2958  {
2959  if($this->dataExists())
2960  {
2961  $filename = "export";
2962 
2963  switch($format)
2964  {
2965  case self::EXPORT_EXCEL:
2966  include_once "./Services/Excel/classes/class.ilExcelUtils.php";
2967  include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php";
2968  $adapter = new ilExcelWriterAdapter($filename.".xls", $send);
2969  $workbook = $adapter->getWorkbook();
2970  $worksheet = $workbook->addWorksheet();
2971  $row = 0;
2972 
2973  ob_start();
2974  $this->fillMetaExcel($worksheet, $row);
2975  $this->fillHeaderExcel($worksheet, $row);
2976  foreach($this->row_data as $set)
2977  {
2978  $row++;
2979  $this->fillRowExcel($worksheet, $row, $set);
2980  }
2981  ob_end_clean();
2982 
2983  $workbook->close();
2984  break;
2985 
2986  case self::EXPORT_CSV:
2987  include_once "./Services/Utilities/classes/class.ilCSVWriter.php";
2988  $csv = new ilCSVWriter();
2989  $csv->setSeparator(";");
2990 
2991  ob_start();
2992  $this->fillMetaCSV($csv);
2993  $this->fillHeaderCSV($csv);
2994  foreach($this->row_data as $set)
2995  {
2996  $this->fillRowCSV($csv, $set);
2997  }
2998  ob_end_clean();
2999 
3000  if($send)
3001  {
3002  $filename .= ".csv";
3003  header("Content-type: text/comma-separated-values");
3004  header("Content-Disposition: attachment; filename=\"".$filename."\"");
3005  header("Expires: 0");
3006  header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
3007  header("Pragma: public");
3008  echo $csv->getCSVString();
3009 
3010  }
3011  else
3012  {
3013  file_put_contents($filename, $csv->getCSVString());
3014  }
3015  break;
3016  }
3017 
3018  if($send)
3019  {
3020  exit();
3021  }
3022  }
3023  }
3024 
3032  protected function fillMetaExcel($worksheet, &$a_row)
3033  {
3034 
3035  }
3036 
3044  protected function fillHeaderExcel($worksheet, &$a_row)
3045  {
3046  $col = 0;
3047  foreach ($this->column as $column)
3048  {
3049  $title = strip_tags($column["text"]);
3050  if($title)
3051  {
3052  $worksheet->write($a_row, $col, $title);
3053  $col++;
3054  }
3055  }
3056  $a_row++;
3057  }
3058 
3067  protected function fillRowExcel($a_worksheet, &$a_row, $a_set)
3068  {
3069  $col = 0;
3070  foreach ($a_set as $key => $value)
3071  {
3072  if(is_array($value))
3073  {
3074  $value = implode(', ', $value);
3075  }
3076  $a_worksheet->write($a_row, $col, strip_tags($value));
3077  $col++;
3078  }
3079  }
3080 
3087  protected function fillMetaCSV($a_csv)
3088  {
3089 
3090  }
3091 
3098  protected function fillHeaderCSV($a_csv)
3099  {
3100  foreach ($this->column as $column)
3101  {
3102  $title = strip_tags($column["text"]);
3103  if($title)
3104  {
3105  $a_csv->addColumn($title);
3106  }
3107  }
3108  $a_csv->addRow();
3109  }
3110 
3118  protected function fillRowCSV($a_csv, $a_set)
3119  {
3120  foreach ($a_set as $key => $value)
3121  {
3122  if(is_array($value))
3123  {
3124  $value = implode(', ', $value);
3125  }
3126  $a_csv->addColumn(strip_tags($value));
3127  }
3128  $a_csv->addRow();
3129  }
3130 }
3131 
3132 ?>