ILIAS  release_4-3 Revision
 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 
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))
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  if(sizeof($invalid))
557  {
558  trigger_error("The following columns are defined as sortable but".
559  " cannot be found in the given data: ".implode(", ", $invalid).
560  ". Sorting will not work properly.", E_USER_WARNING);
561  }
562  }
563 
564  $this->row_data = $a_data;
565  }
566 
567  final public function getData()
568  {
569  return $this->row_data;
570  }
571 
572  final public function dataExists()
573  {
574  if (is_array($this->row_data))
575  {
576  if (count($this->row_data) > 0)
577  {
578  return true;
579  }
580  }
581  return false;
582  }
583 
584  final public function setPrefix($a_prefix)
585  {
586  $this->prefix = $a_prefix;
587  }
588 
589  final public function getPrefix()
590  {
591  return $this->prefix;
592  }
593 
598  final function addFilterItem($a_input_item, $a_optional = false)
599  {
600  $a_input_item->setParent($this);
601  if (!$a_optional)
602  {
603  $this->filters[] = $a_input_item;
604  }
605  else
606  {
607  $this->optional_filters[] = $a_input_item;
608  }
609 
610  // restore filter values (from stored view)
611  if($this->restore_filter_values &&
612  array_key_exists($a_input_item->getFieldId(), $this->restore_filter_values))
613  {
614  $this->setFilterValue($a_input_item, $this->restore_filter_values[$a_input_item->getFieldId()]);
615  }
616  }
617 
627  function addFilterItemByMetaType($id, $type = self::FILTER_TEXT, $a_optional = false, $caption = NULL)
628  {
629  global $lng;
630 
631  if(!$caption)
632  {
633  $caption = $lng->txt($id);
634  }
635 
636  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
637 
638  switch($type)
639  {
640  case self::FILTER_SELECT:
641  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
642  $item = new ilSelectInputGUI($caption, $id);
643  break;
644 
645  case self::FILTER_DATE:
646  include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
647  $item = new ilDateTimeInputGUI($caption, $id);
648  $item->setMode(ilDateTimeInputGUI::MODE_INPUT);
649  break;
650 
651  case self::FILTER_TEXT:
652  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
653  $item = new ilTextInputGUI($caption, $id);
654  $item->setMaxLength(64);
655  $item->setSize(20);
656  // $item->setSubmitFormOnEnter(true);
657  break;
658 
659  case self::FILTER_LANGUAGE:
660  $lng->loadLanguageModule("meta");
661  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
662  $item = new ilSelectInputGUI($caption, $id);
663  $options = array("" => $lng->txt("trac_all"));
664  foreach ($lng->getInstalledLanguages() as $lang_key)
665  {
666  $options[$lang_key] = $lng->txt("meta_l_".$lang_key);
667  }
668  $item->setOptions($options);
669  break;
670 
671  case self::FILTER_NUMBER_RANGE:
672  include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
673  include_once("./Services/Form/classes/class.ilNumberInputGUI.php");
674  $item = new ilCombinationInputGUI($caption, $id);
675  $combi_item = new ilNumberInputGUI("", $id."_from");
676  $item->addCombinationItem("from", $combi_item, $lng->txt("from"));
677  $combi_item = new ilNumberInputGUI("", $id."_to");
678  $item->addCombinationItem("to", $combi_item, $lng->txt("to"));
679  $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
680  $item->setMaxLength(7);
681  $item->setSize(20);
682  break;
683 
684  case self::FILTER_DATE_RANGE:
685  include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
686  include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
687  $item = new ilCombinationInputGUI($caption, $id);
688  $combi_item = new ilDateTimeInputGUI("", $id."_from");
689  $item->addCombinationItem("from", $combi_item, $lng->txt("from"));
690  $combi_item = new ilDateTimeInputGUI("", $id."_to");
691  $item->addCombinationItem("to", $combi_item, $lng->txt("to"));
692  $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
693  $item->setMode(ilDateTimeInputGUI::MODE_INPUT);
694  break;
695 
696  case self::FILTER_DATETIME_RANGE:
697  include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
698  include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
699  $item = new ilCombinationInputGUI($caption, $id);
700  $combi_item = new ilDateTimeInputGUI("", $id."_from");
701  $combi_item->setShowTime(true);
702  $item->addCombinationItem("from", $combi_item, $lng->txt("from"));
703  $combi_item = new ilDateTimeInputGUI("", $id."_to");
704  $combi_item->setShowTime(true);
705  $item->addCombinationItem("to", $combi_item, $lng->txt("to"));
706  $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
707  $item->setMode(ilDateTimeInputGUI::MODE_INPUT);
708  break;
709 
710  case self::FILTER_DURATION_RANGE:
711  $lng->loadLanguageModule("form");
712  include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
713  include_once("./Services/Form/classes/class.ilDurationInputGUI.php");
714  $item = new ilCombinationInputGUI($caption, $id);
715  $combi_item = new ilDurationInputGUI("", $id."_from");
716  $combi_item->setShowMonths(false);
717  $combi_item->setShowDays(true);
718  $combi_item->setShowSeconds(true);
719  $item->addCombinationItem("from", $combi_item, $lng->txt("from"));
720  $combi_item = new ilDurationInputGUI("", $id."_to");
721  $combi_item->setShowMonths(false);
722  $combi_item->setShowDays(true);
723  $combi_item->setShowSeconds(true);
724  $item->addCombinationItem("to", $combi_item, $lng->txt("to"));
725  $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
726  break;
727 
728  default:
729  return false;
730  }
731 
732  $this->addFilterItem($item, $a_optional);
733  $item->readFromSession();
734  return $item;
735  }
736 
740  final function getFilterItems($a_optionals = false)
741  {
742  if (!$a_optionals)
743  {
744  return $this->filters;
745  }
747  }
748 
749  final function getFilterItemByPostVar($a_post_var)
750  {
751  foreach ($this->getFilterItems() as $item)
752  {
753  if ($item->getPostVar() == $a_post_var)
754  {
755  return $item;
756  }
757  }
758  foreach ($this->getFilterItems(true) as $item)
759  {
760  if ($item->getPostVar() == $a_post_var)
761  {
762  return $item;
763  }
764  }
765  return false;
766  }
767 
773  function setFilterCols($a_val)
774  {
775  $this->filter_cols = $a_val;
776  }
777 
783  function getFilterCols()
784  {
785  return $this->filter_cols;
786  }
787 
793  function setDisableFilterHiding($a_val = true)
794  {
795  $this->disable_filter_hiding = $a_val;
796  }
797 
804  {
806  }
807 
814  function isFilterSelected($a_col)
815  {
816  return $this->selected_filter[$a_col];
817  }
818 
826  {
827  $sfil = array();
828  foreach ($this->selected_filter as $k => $v)
829  {
830  if ($v)
831  {
832  $sfil[$k] = $k;
833  }
834  }
835  return $sfil;
836  }
837 
845  {
846  if ($this->filters_determined)
847  {
848  return;
849  }
850 
851  $old_sel = $this->loadProperty("selfilters");
852  $stored = false;
853  if ($old_sel != "")
854  {
855  $sel_filters =
856  @unserialize($old_sel);
857  $stored = true;
858  }
859  if(!is_array($sel_filters))
860  {
861  $stored = false;
862  $sel_filters = array();
863  }
864 
865  $this->selected_filter = array();
866  $set = false;
867  foreach ($this->getFilterItems(true) as $item)
868  {
869  $k = $item->getPostVar();
870 
871  $this->selected_filter[$k] = false;
872 
873  if ($_POST["tblfsf".$this->getId()])
874  {
875  $set = true;
876  if (is_array($_POST["tblff".$this->getId()]) && in_array($k, $_POST["tblff".$this->getId()]))
877  {
878  $this->selected_filter[$k] = true;
879  }
880  else
881  {
882  $item->setValue(NULL);
883  $item->writeToSession();
884  }
885  }
886  else if ($stored) // take stored values
887  {
888  $this->selected_filter[$k] = $sel_filters[$k];
889  }
890  }
891 
892  if ($old_sel != serialize($this->selected_filter) && $set)
893  {
894  $this->storeProperty("selfilters", serialize($this->selected_filter));
895  }
896 
897  $this->filters_determined = true;
898  }
899 
903  function setCustomPreviousNext($a_prev_link, $a_next_link)
904  {
905  $this->custom_prev_next = true;
906  $this->custom_prev = $a_prev_link;
907  $this->custom_next = $a_next_link;
908  }
909 
915  final public function setFormAction($a_form_action)
916  {
917  $this->form_action = $a_form_action;
918  }
919 
925  final public function getFormAction()
926  {
927  return $this->form_action;
928  }
929 
935  function setFormName($a_formname)
936  {
937  $this->formname = $a_formname;
938  }
939 
945  function getFormName()
946  {
947  return $this->formname;
948  }
949 
955  function setId($a_val)
956  {
957  $this->id = $a_val;
958  if ($this->getPrefix() == "")
959  {
960  $this->setPrefix($a_val);
961  }
962  }
963 
969  function getId()
970  {
971  return $this->id;
972  }
973 
979  function setDisplayAsBlock($a_val)
980  {
981  $this->display_as_block = $a_val;
982  }
983 
989  function getDisplayAsBlock()
990  {
991  return $this->display_as_block;
992  }
993 
1000  {
1002  }
1003 
1009  function setSelectAllCheckbox($a_select_all_checkbox)
1010  {
1011  $this->select_all_checkbox = $a_select_all_checkbox;
1012  }
1013 
1019  function setExternalSorting($a_val)
1020  {
1021  $this->ext_sort = $a_val;
1022  }
1023 
1030  {
1031  return $this->ext_sort;
1032  }
1033 
1039  function setFilterCommand($a_val)
1040  {
1041  $this->filter_cmd = $a_val;
1042  }
1043 
1049  function getFilterCommand()
1050  {
1051  return $this->filter_cmd;
1052  }
1053 
1059  function setResetCommand($a_val)
1060  {
1061  $this->reset_cmd = $a_val;
1062  }
1063 
1069  function getResetCommand()
1070  {
1071  return $this->reset_cmd;
1072  }
1073 
1079  function setExternalSegmentation($a_val)
1080  {
1081  $this->ext_seg = $a_val;
1082  }
1083 
1090  {
1091  return $this->ext_seg;
1092  }
1093 
1100  final public function setRowTemplate($a_template, $a_template_dir = "")
1101  {
1102  $this->row_template = $a_template;
1103  $this->row_template_dir = $a_template_dir;
1104  }
1105 
1111  function setDefaultOrderField($a_defaultorderfield)
1112  {
1113  $this->defaultorderfield = $a_defaultorderfield;
1114  }
1115 
1122  {
1123  return $this->defaultorderfield;
1124  }
1125 
1131  function setDefaultOrderDirection($a_defaultorderdirection)
1132  {
1133  $this->defaultorderdirection = $a_defaultorderdirection;
1134  }
1135 
1142  {
1143  return $this->defaultorderdirection;
1144  }
1145 
1146  /*
1147  * Removes all command buttons from the table
1148  *
1149  * @access public
1150  */
1151  public function clearCommandButtons()
1152  {
1153  $this->buttons = array();
1154  }
1155 
1162  function addCommandButton($a_cmd, $a_text, $a_onclick = '', $a_id = "")
1163  {
1164  $this->buttons[] = array("cmd" => $a_cmd, "text" => $a_text, 'onclick' => $a_onclick,
1165  "id" => $a_id);
1166  }
1167 
1178  function addSelectionButton($a_sel_var, $a_options, $a_cmd, $a_text, $a_default_selection = '')
1179  {
1180 echo "ilTabl2GUI->addSelectionButton() has been deprecated with 4.2. Please try to move the drop-down to ilToolbarGUI.";
1181 // $this->sel_buttons[] = array("sel_var" => $a_sel_var, "options" => $a_options, "selected" => $a_default_selection, "cmd" => $a_cmd, "text" => $a_text);
1182  }
1183 
1193  public function addMultiItemSelectionButton($a_sel_var, $a_options, $a_cmd, $a_text, $a_default_selection = '')
1194  {
1195  $this->mi_sel_buttons[] = array("sel_var" => $a_sel_var, "options" => $a_options, "selected" => $a_default_selection, "cmd" => $a_cmd, "text" => $a_text);
1196  $this->addHiddenInput("cmd_sv[".$a_cmd."]", $a_sel_var);
1197  }
1198 
1199 
1200 
1206  function setCloseCommand($a_link)
1207  {
1208  $this->close_command = $a_link;
1209  }
1210 
1217  function addMultiCommand($a_cmd, $a_text)
1218  {
1219  $this->multi[] = array("cmd" => $a_cmd, "text" => $a_text);
1220  }
1221 
1228  public function addHiddenInput($a_name, $a_value)
1229  {
1230  $this->hidden_inputs[] = array("name" => $a_name, "value" => $a_value);
1231  }
1232 
1239  function addHeaderCommand($a_href, $a_text, $a_target = "", $a_img = "")
1240  {
1241  $this->header_commands[] = array("href" => $a_href, "text" => $a_text,
1242  "target" => $a_target, "img" => $a_img);
1243  }
1244 
1250  function setTopCommands($a_val)
1251  {
1252  $this->top_commands = $a_val;
1253  }
1254 
1260  function getTopCommands()
1261  {
1262  return $this->top_commands;
1263  }
1264 
1272  final public function addColumn($a_text, $a_sort_field = "", $a_width = "",
1273  $a_is_checkbox_action_column = false, $a_class = "", $a_tooltip = "")
1274  {
1275  $this->column[] = array(
1276  "text" => $a_text,
1277  "sort_field" => $a_sort_field,
1278  "width" => $a_width,
1279  "is_checkbox_action_column" => $a_is_checkbox_action_column,
1280  "class" => $a_class,
1281  "tooltip" => $a_tooltip
1282  );
1283  $this->column_count = count($this->column);
1284  }
1285 
1286 
1287  final public function getNavParameter()
1288  {
1289  return $this->prefix."_table_nav";
1290  }
1291 
1292  function setOrderLink($sort_field, $order_dir)
1293  {
1294  global $ilCtrl, $ilUser;
1295 
1296  $hash = "";
1297  if (is_object($ilUser) && $ilUser->getPref("screen_reader_optimization"))
1298  {
1299  $hash = "#".$this->getTopAnchor();
1300  }
1301 
1302  $old = $_GET[$this->getNavParameter()];
1303 
1304  // set order link
1305  $ilCtrl->setParameter($this->parent_obj,
1306  $this->getNavParameter(),
1307  $sort_field.":".$order_dir.":".$this->offset);
1308  $this->tpl->setVariable("TBL_ORDER_LINK",
1309  $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd).$hash);
1310 
1311  // set old value of nav variable
1312  $ilCtrl->setParameter($this->parent_obj,
1313  $this->getNavParameter(), $old);
1314  }
1315 
1316  function fillHeader()
1317  {
1318  global $lng;
1319 
1320  $allcolumnswithwidth = true;
1321  foreach ((array) $this->column as $idx => $column)
1322  {
1323  if (!strlen($column["width"]))
1324  {
1325  $allcolumnswithwidth = false;
1326  }
1327  else if($column["width"] == "1")
1328  {
1329  // IE does not like 1 but seems to work with 1%
1330  $this->column[$idx]["width"] = "1%";
1331  }
1332  }
1333  if ($allcolumnswithwidth)
1334  {
1335  foreach ((array) $this->column as $column)
1336  {
1337  $this->tpl->setCurrentBlock("tbl_colgroup_column");
1338  $this->tpl->setVariable("COLGROUP_COLUMN_WIDTH", $column["width"]);
1339  $this->tpl->parseCurrentBlock();
1340  }
1341  }
1342  $ccnt = 0;
1343  foreach ((array) $this->column as $column)
1344  {
1345  $ccnt++;
1346 
1347  //tooltip
1348  if ($column["tooltip"] != "")
1349  {
1350  include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
1351  ilTooltipGUI::addTooltip("thc_".$this->getId()."_".$ccnt, $column["tooltip"]);
1352  }
1353  if (!$this->enabled["sort"] || $column["sort_field"] == "" || $column["is_checkbox_action_column"])
1354  {
1355  $this->tpl->setCurrentBlock("tbl_header_no_link");
1356  if ($column["width"] != "")
1357  {
1358  $this->tpl->setVariable("TBL_COLUMN_WIDTH_NO_LINK"," width=\"".$column["width"]."\"");
1359  }
1360  if (!$column["is_checkbox_action_column"])
1361  {
1362  $this->tpl->setVariable("TBL_HEADER_CELL_NO_LINK",
1363  $column["text"]);
1364  }
1365  else
1366  {
1367  $this->tpl->setVariable("TBL_HEADER_CELL_NO_LINK",
1368  ilUtil::img(ilUtil::getImagePath("spacer.png"), $lng->txt("action")));
1369  }
1370  $this->tpl->setVariable("HEAD_CELL_NL_ID", "thc_".$this->getId()."_".$ccnt);
1371 
1372  if ($column["class"] != "")
1373  {
1374  $this->tpl->setVariable("TBL_HEADER_CLASS"," " . $column["class"]);
1375  }
1376  $this->tpl->parseCurrentBlock();
1377  $this->tpl->touchBlock("tbl_header_th");
1378  continue;
1379  }
1380  if (($column["sort_field"] == $this->order_field) && ($this->order_direction != ""))
1381  {
1382  $this->tpl->setCurrentBlock("tbl_order_image");
1383  $this->tpl->setVariable("IMG_ORDER_DIR",ilUtil::getImagePath($this->order_direction."_order.png"));
1384  $this->tpl->setVariable("IMG_ORDER_ALT", $this->lng->txt("change_sort_direction"));
1385  $this->tpl->parseCurrentBlock();
1386  }
1387 
1388  $this->tpl->setCurrentBlock("tbl_header_cell");
1389  $this->tpl->setVariable("TBL_HEADER_CELL", $column["text"]);
1390  $this->tpl->setVariable("HEAD_CELL_ID", "thc_".$this->getId()."_".$ccnt);
1391 
1392  // only set width if a value is given for that column
1393  if ($column["width"] != "")
1394  {
1395  $this->tpl->setVariable("TBL_COLUMN_WIDTH"," width=\"".$column["width"]."\"");
1396  }
1397 
1398  $lng_sort_column = $this->lng->txt("sort_by_this_column");
1399  $this->tpl->setVariable("TBL_ORDER_ALT",$lng_sort_column);
1400 
1401  $order_dir = "asc";
1402 
1403  if ($column["sort_field"] == $this->order_field)
1404  {
1405  $order_dir = $this->sort_order;
1406 
1407  $lng_change_sort = $this->lng->txt("change_sort_direction");
1408  $this->tpl->setVariable("TBL_ORDER_ALT",$lng_change_sort);
1409  }
1410 
1411  if ($column["class"] != "")
1412  {
1413  $this->tpl->setVariable("TBL_HEADER_CLASS"," " . $column["class"]);
1414  }
1415  $this->setOrderLink($column["sort_field"], $order_dir);
1416  $this->tpl->parseCurrentBlock();
1417  $this->tpl->touchBlock("tbl_header_th");
1418  }
1419 
1420  $this->tpl->setCurrentBlock("tbl_header");
1421  $this->tpl->parseCurrentBlock();
1422  }
1423 
1427  protected function prepareOutput()
1428  {
1429  }
1430 
1431 
1435  function determineOffsetAndOrder($a_omit_offset = false)
1436  {
1437  global $ilUser;
1438 
1439  if ($this->nav_determined)
1440  {
1441  return true;
1442  }
1443 
1444  if ($_POST[$this->getNavParameter()."1"] != "")
1445  {
1446  if ($_POST[$this->getNavParameter()."1"] != $_POST[$this->getNavParameter()])
1447  {
1448  $this->nav_value = $_POST[$this->getNavParameter()."1"];
1449  }
1450  else if ($_POST[$this->getNavParameter()."2"] != $_POST[$this->getNavParameter()])
1451  {
1452  $this->nav_value = $_POST[$this->getNavParameter()."2"];
1453  }
1454  }
1455  elseif($_GET[$this->getNavParameter()])
1456  {
1457  $this->nav_value = $_GET[$this->getNavParameter()];
1458  }
1459  elseif($_SESSION[$this->getNavParameter()] != "")
1460  {
1461  $this->nav_value = $_SESSION[$this->getNavParameter()];
1462  }
1463 
1464  if ($this->nav_value == "" && $this->getId() != "" && $ilUser->getId() != ANONYMOUS_USER_ID)
1465  {
1466  // get order and direction from db
1467  $this->nav_value =
1468  $this->loadProperty("order").":".
1469  $this->loadProperty("direction").":".
1470  $this->loadProperty("offset");
1471  }
1472  $nav = explode(":", $this->nav_value);
1473 
1474  // $nav[0] is order by
1475  $this->setOrderField(($nav[0] != "") ? $nav[0] : $this->getDefaultOrderField());
1476  $this->setOrderDirection(($nav[1] != "") ? $nav[1] : $this->getDefaultOrderDirection());
1477 
1478  if (!$a_omit_offset)
1479  {
1480  // #8904: offset must be discarded when no limit is given
1481  if(!$this->getExternalSegmentation() && $this->limit_determined && $this->limit == 9999)
1482  {
1483  $this->resetOffset(true);
1484  }
1485  else if (!$this->getExternalSegmentation() && $nav[2] >= $this->max_count)
1486  {
1487  $this->resetOffset(true);
1488  }
1489  else
1490  {
1491  $this->setOffset($nav[2]);
1492  }
1493  }
1494 
1495  if (!$a_omit_offset)
1496  {
1497  $this->nav_determined = true;
1498  }
1499  }
1500 
1502  {
1503  if ($this->getOrderField() != "")
1504  {
1505  $this->storeProperty("order", $this->getOrderField());
1506  }
1507  if ($this->getOrderDirection() != "")
1508  {
1509  $this->storeProperty("direction", $this->getOrderDirection());
1510  }
1511 //echo "-".$this->getOffset()."-";
1512  if ($this->getOffset() !== "")
1513  {
1514  $this->storeProperty("offset", $this->getOffset());
1515  }
1516  }
1517 
1518 
1522  final public function getHTML()
1523  {
1524  global $lng, $ilCtrl, $ilUser;
1525 
1526  if($this->getExportMode())
1527  {
1528  $this->exportData($this->getExportMode(), true);
1529  }
1530 
1531  $this->prepareOutput();
1532 
1533  if (is_object($ilCtrl) && $this->getId() == "")
1534  {
1535  $ilCtrl->saveParameter($this->getParentObject(), $this->getNavParameter());
1536  }
1537 
1538  if(!$this->getPrintMode())
1539  {
1540  // set form action
1541  if ($this->form_action != "" && $this->getOpenFormTag())
1542  {
1543  $hash = "";
1544  if (is_object($ilUser) && $ilUser->getPref("screen_reader_optimization"))
1545  {
1546  $hash = "#".$this->getTopAnchor();
1547  }
1548 
1549  $this->tpl->setCurrentBlock("tbl_form_header");
1550  $this->tpl->setVariable("FORMACTION", $this->getFormAction().$hash);
1551  $this->tpl->setVariable("FORMNAME", $this->getFormName());
1552  $this->tpl->parseCurrentBlock();
1553  }
1554 
1555  if ($this->form_action != "" && $this->getCloseFormTag())
1556  {
1557  $this->tpl->touchBlock("tbl_form_footer");
1558  }
1559  }
1560 
1561  if(!$this->enabled['content'])
1562  {
1563  return $this->render();
1564  }
1565 
1566  if (!$this->getExternalSegmentation())
1567  {
1568  $this->setMaxCount(count($this->row_data));
1569  }
1570 
1571  $this->determineOffsetAndOrder();
1572 
1573  $this->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
1574 
1575  $data = $this->getData();
1576  if($this->dataExists())
1577  {
1578  // sort
1579  if (!$this->getExternalSorting())
1580  {
1581  $data = ilUtil::sortArray($data, $this->getOrderField(),
1582  $this->getOrderDirection(), $this->numericOrdering($this->getOrderField()));
1583  }
1584 
1585  // slice
1586  if (!$this->getExternalSegmentation())
1587  {
1588  $data = array_slice($data, $this->getOffset(), $this->getLimit());
1589  }
1590  }
1591 
1592  // fill rows
1593  if($this->dataExists())
1594  {
1595  if($this->getPrintMode())
1596  {
1598  }
1599 
1600  $this->tpl->addBlockFile("TBL_CONTENT", "tbl_content", $this->row_template,
1601  $this->row_template_dir);
1602 
1603  foreach($data as $set)
1604  {
1605  $this->tpl->setCurrentBlock("tbl_content");
1606  $this->css_row = ($this->css_row != "tblrow1")
1607  ? "tblrow1"
1608  : "tblrow2";
1609  $this->tpl->setVariable("CSS_ROW", $this->css_row);
1610 
1611  $this->fillRow($set);
1612  $this->tpl->setCurrentBlock("tbl_content");
1613  $this->tpl->parseCurrentBlock();
1614  }
1615  }
1616  else
1617  {
1618  // add standard no items text (please tell me, if it messes something up, alex, 29.8.2008)
1619  $no_items_text = (trim($this->getNoEntriesText()) != '')
1620  ? $this->getNoEntriesText()
1621  : $lng->txt("no_items");
1622 
1623  $this->css_row = ($this->css_row != "tblrow1")
1624  ? "tblrow1"
1625  : "tblrow2";
1626 
1627  $this->tpl->setCurrentBlock("tbl_no_entries");
1628  $this->tpl->setVariable('TBL_NO_ENTRY_CSS_ROW', $this->css_row);
1629  $this->tpl->setVariable('TBL_NO_ENTRY_COLUMN_COUNT', $this->column_count);
1630  $this->tpl->setVariable('TBL_NO_ENTRY_TEXT', trim($no_items_text));
1631  $this->tpl->parseCurrentBlock();
1632  }
1633 
1634 
1635  if(!$this->getPrintMode())
1636  {
1637  $this->fillFooter();
1638 
1639  $this->fillHiddenRow();
1640 
1641  $this->fillActionRow();
1642 
1643  $this->storeNavParameter();
1644  }
1645 
1646  return $this->render();
1647  }
1648 
1654  function numericOrdering($a_field)
1655  {
1656  return false;
1657  }
1658 
1663  function render()
1664  {
1665  global $lng, $ilCtrl;
1666 
1667  $this->tpl->setVariable("CSS_TABLE",$this->getStyle("table"));
1668  $this->tpl->setVariable("DATA_TABLE", (int) $this->getIsDataTable());
1669  if ($this->getId() != "")
1670  {
1671  $this->tpl->setVariable("ID", 'id="'.$this->getId().'"');
1672  }
1673 
1674  // description
1675  if ($this->getDescription() != "")
1676  {
1677  $this->tpl->setCurrentBlock("tbl_header_description");
1678  $this->tpl->setVariable("TBL_DESCRIPTION", $this->getDescription());
1679  $this->tpl->parseCurrentBlock();
1680  }
1681 
1682  if(!$this->getPrintMode())
1683  {
1684  $this->renderFilter();
1685  }
1686 
1687  if ($this->getDisplayAsBlock())
1688  {
1689  $this->tpl->touchBlock("outer_start_1");
1690  $this->tpl->touchBlock("outer_end_1");
1691  }
1692  else
1693  {
1694  $this->tpl->touchBlock("outer_start_2");
1695  $this->tpl->touchBlock("outer_end_2");
1696  }
1697 
1698  // table title and icon
1699  if ($this->enabled["title"] && ($this->title != ""
1700  || $this->icon != "" || count($this->header_commands) > 0 ||
1701  $this->headerHTML != "" || $this->close_command != ""))
1702  {
1703  if ($this->enabled["icon"])
1704  {
1705  $this->tpl->setCurrentBlock("tbl_header_title_icon");
1706  $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath($this->icon));
1707  $this->tpl->setVariable("TBL_TITLE_IMG_ALT",$this->icon_alt);
1708  $this->tpl->parseCurrentBlock();
1709  }
1710 
1711  if(!$this->getPrintMode())
1712  {
1713  foreach($this->header_commands as $command)
1714  {
1715  if ($command["img"] != "")
1716  {
1717  $this->tpl->setCurrentBlock("tbl_header_img_link");
1718  if ($command["target"] != "")
1719  {
1720  $this->tpl->setVariable("TARGET_IMG_LINK",
1721  'target="'.$command["target"].'"');
1722  }
1723  $this->tpl->setVariable("ALT_IMG_LINK", $command["text"]);
1724  $this->tpl->setVariable("HREF_IMG_LINK", $command["href"]);
1725  $this->tpl->setVariable("SRC_IMG_LINK",
1726  $command["img"]);
1727  $this->tpl->parseCurrentBlock();
1728  }
1729  else
1730  {
1731  $this->tpl->setCurrentBlock("head_cmd");
1732  $this->tpl->setVariable("TXT_HEAD_CMD", $command["text"]);
1733  $this->tpl->setVariable("HREF_HEAD_CMD", $command["href"]);
1734  $this->tpl->parseCurrentBlock();
1735  }
1736  }
1737  }
1738 
1739  if (isset ($this->headerHTML)) {
1740  $this->tpl->setCurrentBlock("tbl_header_html");
1741  $this->tpl->setVariable ("HEADER_HTML", $this->headerHTML);
1742  $this->tpl->parseCurrentBlock();
1743  }
1744 
1745  // close command
1746  if ($this->close_command != "")
1747  {
1748  $this->tpl->setCurrentBlock("tbl_header_img_link");
1749  $this->tpl->setVariable("ALT_IMG_LINK",$lng->txt("close"));
1750  $this->tpl->setVariable("HREF_IMG_LINK",$this->close_command);
1751  $this->tpl->setVariable("SRC_IMG_LINK",ilUtil::getImagePath("icon_close2.png"));
1752  $this->tpl->parseCurrentBlock();
1753  }
1754 
1755  $this->tpl->setCurrentBlock("tbl_header_title");
1756  $this->tpl->setVariable("TBL_TITLE",$this->title);
1757  $this->tpl->setVariable("TOP_ANCHOR",$this->getTopAnchor());
1758  if ($this->getDisplayAsBlock())
1759  {
1760  $this->tpl->setVariable("BLK_CLASS", "Block");
1761  }
1762  $this->tpl->parseCurrentBlock();
1763  }
1764 
1765  // table header
1766  if ($this->enabled["header"])
1767  {
1768  $this->fillHeader();
1769  }
1770 
1771  $this->tpl->touchBlock("tbl_table_end");
1772 
1773  return $this->tpl->get();
1774  }
1775 
1779  private function renderFilter()
1780  {
1781  global $lng, $tpl;
1782 
1783  $filter = $this->getFilterItems();
1784  $opt_filter = $this->getFilterItems(true);
1785 
1786  $tpl->addJavascript("./Services/Table/js/ServiceTable.js");
1787 
1788  if (count($filter) == 0 && count($opt_filter) == 0)
1789  {
1790  return;
1791  }
1792 
1793  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
1795 
1796  $ccnt = 0;
1797 
1798  // render standard filter
1799  if (count($filter) > 0)
1800  {
1801  foreach ($filter as $item)
1802  {
1803  if ($ccnt >= $this->getFilterCols())
1804  {
1805  $this->tpl->setCurrentBlock("filter_row");
1806  $this->tpl->parseCurrentBlock();
1807  $ccnt = 0;
1808  }
1809  $this->tpl->setCurrentBlock("filter_item");
1810  $this->tpl->setVariable("OPTION_NAME",
1811  $item->getTitle());
1812  $this->tpl->setVariable("F_INPUT_ID",
1813  $item->getFieldId());
1814  $this->tpl->setVariable("INPUT_HTML",
1815  $item->getTableFilterHTML());
1816  $this->tpl->parseCurrentBlock();
1817  $ccnt++;
1818  }
1819  }
1820 
1821  // render optional filter
1822  if (count($opt_filter) > 0)
1823  {
1824  $this->determineSelectedFilters();
1825 
1826  foreach ($opt_filter as $item)
1827  {
1828  if($this->isFilterSelected($item->getPostVar()))
1829  {
1830  if ($ccnt >= $this->getFilterCols())
1831  {
1832  $this->tpl->setCurrentBlock("filter_row");
1833  $this->tpl->parseCurrentBlock();
1834  $ccnt = 0;
1835  }
1836  $this->tpl->setCurrentBlock("filter_item");
1837  $this->tpl->setVariable("OPTION_NAME",
1838  $item->getTitle());
1839  $this->tpl->setVariable("F_INPUT_ID",
1840  $item->getFieldId());
1841  $this->tpl->setVariable("INPUT_HTML",
1842  $item->getTableFilterHTML());
1843  $this->tpl->parseCurrentBlock();
1844  $ccnt++;
1845  }
1846  }
1847 
1848  // filter selection
1849  $items = array();
1850  foreach ($opt_filter as $item)
1851  {
1852  $k = $item->getPostVar();
1853  $items[$k] = array("txt" => $item->getTitle(),
1854  "selected" => $this->isFilterSelected($k));
1855  }
1856 
1857  include_once("./Services/UIComponent/CheckboxListOverlay/classes/class.ilCheckboxListOverlayGUI.php");
1858  $cb_over = new ilCheckboxListOverlayGUI("tbl_filters_".$this->getId());
1859  $cb_over->setLinkTitle($lng->txt("optional_filters"));
1860  $cb_over->setItems($items);
1861 
1862  $cb_over->setFormCmd($this->getParentCmd());
1863  $cb_over->setFieldVar("tblff".$this->getId());
1864  $cb_over->setHiddenVar("tblfsf".$this->getId());
1865 
1866  $cb_over->setSelectionHeaderClass("ilTableMenuItem");
1867  $this->tpl->setCurrentBlock("filter_select");
1868 
1869  // apply should be the first submit because of enter/return, inserting hidden submit
1870  $this->tpl->setVariable("HIDDEN_CMD_APPLY", $this->filter_cmd);
1871 
1872  $this->tpl->setVariable("FILTER_SELECTOR", $cb_over->getHTML());
1873  $this->tpl->parseCurrentBlock();
1874  }
1875 
1876  // if any filter
1877  if($ccnt > 0 || count($opt_filter) > 0)
1878  {
1879  $this->tpl->setVariable("TXT_FILTER", $lng->txt("filter"));
1880 
1881  if($ccnt > 0)
1882  {
1883  if ($ccnt < $this->getFilterCols())
1884  {
1885  for($i = $ccnt; $i<=$this->getFilterCols(); $i++)
1886  {
1887  $this->tpl->touchBlock("filter_empty_cell");
1888  }
1889  }
1890  $this->tpl->setCurrentBlock("filter_row");
1891  $this->tpl->parseCurrentBlock();
1892 
1893  $this->tpl->setCurrentBlock("filter_buttons");
1894  $this->tpl->setVariable("CMD_APPLY", $this->filter_cmd);
1895  $this->tpl->setVariable("TXT_APPLY", $lng->txt("apply_filter"));
1896  $this->tpl->setVariable("CMD_RESET", $this->reset_cmd);
1897  $this->tpl->setVariable("TXT_RESET", $lng->txt("reset_filter"));
1898  }
1899  else if(count($opt_filter) > 0)
1900  {
1901  $this->tpl->setCurrentBlock("optional_filter_hint");
1902  $this->tpl->setVariable('TXT_OPT_HINT', $lng->txt('optional_filter_hint'));
1903  $this->tpl->parseCurrentBlock();
1904  }
1905 
1906  $this->tpl->setCurrentBlock("filter_section");
1907  $this->tpl->setVariable("FIL_ID", $this->getId());
1908  $this->tpl->parseCurrentBlock();
1909 
1910  // (keep) filter hidden?
1911  if ($this->loadProperty("filter") != 1)
1912  {
1913  if (!$this->getDisableFilterHiding())
1914  {
1915  $this->tpl->setCurrentBlock("filter_hidden");
1916  $this->tpl->setVariable("FI_ID", $this->getId());
1917  $this->tpl->parseCurrentBlock();
1918  }
1919  }
1920  }
1921  }
1922 
1926  public function writeFilterToSession()
1927  {
1928  global $lng;
1929 
1930  $filter = $this->getFilterItems();
1931  $opt_filter = $this->getFilterItems(true);
1932 
1933  foreach ($filter as $item)
1934  {
1935  if ($item->checkInput())
1936  {
1937  $item->setValueByArray($_POST);
1938  $item->writeToSession();
1939  }
1940  }
1941  foreach ($opt_filter as $item)
1942  {
1943  if ($item->checkInput())
1944  {
1945  $item->setValueByArray($_POST);
1946  $item->writeToSession();
1947  }
1948  }
1949 
1950  // #13209
1951  unset($_REQUEST["tbltplcrt"]);
1952  unset($_REQUEST["tbltpldel"]);
1953 
1954  }
1955 
1959  public function resetFilter()
1960  {
1961  global $lng;
1962 
1963  $filter = $this->getFilterItems();
1964  $opt_filter = $this->getFilterItems(true);
1965 
1966  foreach ($filter as $item)
1967  {
1968  if ($item->checkInput())
1969  {
1970  $item->setValueByArray($_POST);
1971  $item->clearFromSession();
1972  }
1973  }
1974  foreach ($opt_filter as $item)
1975  {
1976  if ($item->checkInput())
1977  {
1978  $item->setValueByArray($_POST);
1979  $item->clearFromSession();
1980  }
1981  }
1982 
1983  // #13209
1984  unset($_REQUEST["tbltplcrt"]);
1985  unset($_REQUEST["tbltpldel"]);
1986  }
1987 
1994  protected function fillRow($a_set)
1995  {
1996  foreach ($a_set as $key => $value)
1997  {
1998  $this->tpl->setVariable("VAL_".strtoupper($key), $value);
1999  }
2000  }
2001 
2005  function fillFooter()
2006  {
2007  global $lng, $ilCtrl, $ilUser;
2008 
2009  $footer = false;
2010 
2011  // select all checkbox
2012  if ((strlen($this->getFormName())) && (strlen($this->getSelectAllCheckbox())) && $this->dataExists())
2013  {
2014  $this->tpl->setCurrentBlock("select_all_checkbox");
2015  $this->tpl->setVariable("SELECT_ALL_TXT_SELECT_ALL", $lng->txt("select_all"));
2016  $this->tpl->setVariable("SELECT_ALL_CHECKBOX_NAME", $this->getSelectAllCheckbox());
2017  $this->tpl->setVariable("SELECT_ALL_FORM_NAME", $this->getFormName());
2018  $this->tpl->setVariable("CHECKBOXNAME", "chb_select_all_" . $this->unique_id);
2019  $this->tpl->parseCurrentBlock();
2020  }
2021 
2022  // table footer numinfo
2023  if ($this->enabled["numinfo"] && $this->enabled["footer"])
2024  {
2025  $start = $this->offset + 1; // compute num info
2026  if (!$this->dataExists())
2027  {
2028  $start = 0;
2029  }
2030  $end = $this->offset + $this->limit;
2031 
2032  if ($end > $this->max_count or $this->limit == 0)
2033  {
2034  $end = $this->max_count;
2035  }
2036 
2037  if ($this->max_count > 0)
2038  {
2039  if ($this->lang_support)
2040  {
2041  $numinfo = "(".$start." - ".$end." ".strtolower($this->lng->txt("of"))." ".$this->max_count.")";
2042  }
2043  else
2044  {
2045  $numinfo = "(".$start." - ".$end." of ".$this->max_count.")";
2046  }
2047  }
2048  if ($this->max_count > 0)
2049  {
2050  if ($this->getEnableNumInfo())
2051  {
2052  $this->tpl->setCurrentBlock("tbl_footer_numinfo");
2053  $this->tpl->setVariable("NUMINFO", $numinfo);
2054  $this->tpl->parseCurrentBlock();
2055  }
2056  }
2057  $footer = true;
2058  }
2059 
2060  // table footer linkbar
2061  if ($this->enabled["linkbar"] && $this->enabled["footer"] && $this->limit != 0
2062  && $this->max_count > 0)
2063  {
2064  $layout = array(
2065  "link" => $this->footer_style,
2066  "prev" => $this->footer_previous,
2067  "next" => $this->footer_next,
2068  );
2069  //if (!$this->getDisplayAsBlock())
2070  //{
2071  $linkbar = $this->getLinkbar("1");
2072  $this->tpl->setCurrentBlock("tbl_footer_linkbar");
2073  $this->tpl->setVariable("LINKBAR", $linkbar);
2074  $this->tpl->parseCurrentBlock();
2075  $linkbar = true;
2076  //}
2077  $footer = true;
2078  }
2079 
2080  // column selector
2081  if (count($this->getSelectableColumns()) > 0)
2082  {
2083  $items = array();
2084  foreach ($this->getSelectableColumns() as $k => $c)
2085  {
2086  $items[$k] = array("txt" => $c["txt"],
2087  "selected" => $this->isColumnSelected($k));
2088  }
2089  include_once("./Services/UIComponent/CheckboxListOverlay/classes/class.ilCheckboxListOverlayGUI.php");
2090  $cb_over = new ilCheckboxListOverlayGUI("tbl_".$this->getId());
2091  $cb_over->setLinkTitle($lng->txt("columns"));
2092  $cb_over->setItems($items);
2093  //$cb_over->setUrl("./ilias.php?baseClass=ilTablePropertiesStorage&table_id=".
2094  // $this->getId()."&cmd=saveSelectedFields&user_id=".$ilUser->getId());
2095  $cb_over->setFormCmd($this->getParentCmd());
2096  $cb_over->setFieldVar("tblfs".$this->getId());
2097  $cb_over->setHiddenVar("tblfsh".$this->getId());
2098  $cb_over->setSelectionHeaderClass("ilTableMenuItem");
2099  $column_selector = $cb_over->getHTML();
2100  $footer = true;
2101  }
2102 
2103  if($this->getShowTemplates() && is_object($ilUser))
2104  {
2105  // template handling
2106  if(isset($_REQUEST["tbltplcrt"]) && $_REQUEST["tbltplcrt"])
2107  {
2108  if($this->saveTemplate($_REQUEST["tbltplcrt"]))
2109  {
2110  ilUtil::sendSuccess($lng->txt("tbl_template_created"));
2111  }
2112  }
2113  else if(isset($_REQUEST["tbltpldel"]) && $_REQUEST["tbltpldel"])
2114  {
2115  if($this->deleteTemplate($_REQUEST["tbltpldel"]))
2116  {
2117  ilUtil::sendSuccess($lng->txt("tbl_template_deleted"));
2118  }
2119  }
2120 
2121  $create_id = "template_create_overlay_".$this->getId();
2122  $delete_id = "template_delete_overlay_".$this->getId();
2123  $list_id = "template_stg_".$this->getId();
2124 
2125  include_once("./Services/Table/classes/class.ilTableTemplatesStorage.php");
2126  $storage = new ilTableTemplatesStorage();
2127  $templates = $storage->getNames($this->getContext(), $ilUser->getId());
2128 
2129  include_once("./Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php");
2130 
2131  // form to delete template
2132  if(sizeof($templates))
2133  {
2134  $overlay = new ilOverlayGUI($delete_id);
2135  $overlay->setTrigger($list_id."_delete");
2136  $overlay->setAnchor("ilAdvSelListAnchorElement_".$list_id);
2137  $overlay->setAutoHide(false);
2138  $overlay->add();
2139 
2140  $lng->loadLanguageModule("form");
2141  $this->tpl->setCurrentBlock("template_editor_delete_item");
2142  $this->tpl->setVariable("TEMPLATE_DELETE_OPTION_VALUE", "");
2143  $this->tpl->setVariable("TEMPLATE_DELETE_OPTION", "- ".$lng->txt("form_please_select")." -");
2144  $this->tpl->parseCurrentBlock();
2145  foreach($templates as $name)
2146  {
2147  $this->tpl->setVariable("TEMPLATE_DELETE_OPTION_VALUE", $name);
2148  $this->tpl->setVariable("TEMPLATE_DELETE_OPTION", $name);
2149  $this->tpl->parseCurrentBlock();
2150  }
2151 
2152  $this->tpl->setCurrentBlock("template_editor_delete");
2153  $this->tpl->setVariable("TEMPLATE_DELETE_ID", $delete_id);
2154  $this->tpl->setVariable("TXT_TEMPLATE_DELETE", $lng->txt("tbl_template_delete"));
2155  $this->tpl->setVariable("TXT_TEMPLATE_DELETE_SUBMIT", $lng->txt("delete"));
2156  $this->tpl->setVariable("TEMPLATE_DELETE_CMD", $this->parent_cmd);
2157  $this->tpl->parseCurrentBlock();
2158  }
2159 
2160 
2161  // form to save new template
2162  $overlay = new ilOverlayGUI($create_id);
2163  $overlay->setTrigger($list_id."_create");
2164  $overlay->setAnchor("ilAdvSelListAnchorElement_".$list_id);
2165  $overlay->setAutoHide(false);
2166  $overlay->add();
2167 
2168  $this->tpl->setCurrentBlock("template_editor");
2169  $this->tpl->setVariable("TEMPLATE_CREATE_ID", $create_id);
2170  $this->tpl->setVariable("TXT_TEMPLATE_CREATE", $lng->txt("tbl_template_create"));
2171  $this->tpl->setVariable("TXT_TEMPLATE_CREATE_SUBMIT", $lng->txt("save"));
2172  $this->tpl->setVariable("TEMPLATE_CREATE_CMD", $this->parent_cmd);
2173  $this->tpl->parseCurrentBlock();
2174 
2175  // load saved template
2176  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
2177  $alist = new ilAdvancedSelectionListGUI();
2178  $alist->setId($list_id);
2179  $alist->addItem($lng->txt("tbl_template_create"), "create", "#");
2180  if(sizeof($templates))
2181  {
2182  $alist->addItem($lng->txt("tbl_template_delete"), "delete", "#");
2183  foreach($templates as $name)
2184  {
2185  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_tpl", urlencode($name));
2186  $alist->addItem($name, $name, $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd));
2187  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_tpl", "");
2188  }
2189  }
2190  $alist->setListTitle($lng->txt("tbl_templates"));
2191  $this->tpl->setVariable("TEMPLATE_SELECTOR", "&nbsp;".$alist->getHTML());
2192  }
2193 
2194  if ($footer)
2195  {
2196  $this->tpl->setCurrentBlock("tbl_footer");
2197  $this->tpl->setVariable("COLUMN_COUNT", $this->getColumnCount());
2198  if ($this->getDisplayAsBlock())
2199  {
2200  $this->tpl->setVariable("BLK_CLASS", "Block");
2201  }
2202  $this->tpl->parseCurrentBlock();
2203 
2204  // top navigation, if number info or linkbar given
2205  if ($numinfo != "" || $linkbar != "" || $column_selector != "" ||
2206  count($this->filters) > 0 || count($this->optional_filters) > 0)
2207  {
2208  if (is_object($ilUser) && (count($this->filters) || count($this->optional_filters)))
2209  {
2210  $this->tpl->setCurrentBlock("filter_activation");
2211  $this->tpl->setVariable("TXT_ACTIVATE_FILTER", $lng->txt("show_filter"));
2212  $this->tpl->setVariable("FILA_ID", $this->getId());
2213  if ($this->getId() != "")
2214  {
2215  $this->tpl->setVariable("SAVE_URLA", "./ilias.php?baseClass=ilTablePropertiesStorage&table_id=".
2216  $this->getId()."&cmd=showFilter&user_id=".$ilUser->getId());
2217  }
2218  $this->tpl->parseCurrentBlock();
2219 
2220 
2221  if (!$this->getDisableFilterHiding())
2222  {
2223  $this->tpl->setCurrentBlock("filter_deactivation");
2224  $this->tpl->setVariable("TXT_HIDE", $lng->txt("hide_filter"));
2225  if ($this->getId() != "")
2226  {
2227  $this->tpl->setVariable("SAVE_URL", "./ilias.php?baseClass=ilTablePropertiesStorage&table_id=".
2228  $this->getId()."&cmd=hideFilter&user_id=".$ilUser->getId());
2229  $this->tpl->setVariable("FILD_ID", $this->getId());
2230  }
2231  $this->tpl->parseCurrentBlock();
2232  }
2233 
2234  }
2235 
2236  if ($numinfo != "" && $this->getEnableNumInfo())
2237  {
2238  $this->tpl->setCurrentBlock("top_numinfo");
2239  $this->tpl->setVariable("NUMINFO", $numinfo);
2240  $this->tpl->parseCurrentBlock();
2241  }
2242  if ($linkbar != "" && !$this->getDisplayAsBlock())
2243  {
2244  $linkbar = $this->getLinkbar("2");
2245  $this->tpl->setCurrentBlock("top_linkbar");
2246  $this->tpl->setVariable("LINKBAR", $linkbar);
2247  $this->tpl->parseCurrentBlock();
2248  }
2249 
2250  // column selector
2251  $this->tpl->setVariable("COLUMN_SELECTOR", $column_selector);
2252 
2253  // row selector
2254  if ($this->getShowRowsSelector() && is_object($ilUser))
2255  {
2256  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
2257  $alist = new ilAdvancedSelectionListGUI();
2258  $alist->setId("sellst_rows");
2259  $hpp = ($ilUser->getPref("hits_per_page") != 9999)
2260  ? $ilUser->getPref("hits_per_page")
2261  : $lng->txt("unlimited");
2262 
2263  $options = array(0 => $lng->txt("default")." (".$hpp.")",5 => 5, 10 => 10, 15 => 15, 20 => 20,
2264  30 => 30, 40 => 40, 50 => 50,
2265  100 => 100, 200 => 200, 400 => 400, 800 => 800);
2266  foreach ($options as $k => $v)
2267  {
2268  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_trows", $k);
2269  $alist->addItem($v, $k, $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd));
2270  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_trows", "");
2271  }
2272  $alist->setListTitle($this->getRowSelectorLabel() ? $this->getRowSelectorLabel() : $lng->txt("rows"));
2273  $this->tpl->setVariable("ROW_SELECTOR", $alist->getHTML());
2274  }
2275 
2276  // export
2277  if(sizeof($this->export_formats) && $this->dataExists())
2278  {
2279  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
2280  $alist = new ilAdvancedSelectionListGUI();
2281  $alist->setId("sellst_xpt");
2282  foreach($this->export_formats as $format => $caption_lng_id)
2283  {
2284  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_xpt", $format);
2285  $url = $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd);
2286  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_xpt", "");
2287  $alist->addItem($lng->txt($caption_lng_id), $format, $url);
2288  }
2289  $alist->setListTitle($lng->txt("export"));
2290  $this->tpl->setVariable("EXPORT_SELECTOR", "&nbsp;".$alist->getHTML());
2291  }
2292 
2293  $this->tpl->setCurrentBlock("top_navigation");
2294  $this->tpl->setVariable("COLUMN_COUNT", $this->getColumnCount());
2295  if ($this->getDisplayAsBlock())
2296  {
2297  $this->tpl->setVariable("BLK_CLASS", "Block");
2298  }
2299  $this->tpl->parseCurrentBlock();
2300  }
2301  }
2302  }
2303 
2311  function getLinkbar($a_num)
2312  {
2313  global $ilCtrl, $lng, $ilUser;
2314 
2315  $hash = "";
2316  if (is_object($ilUser) && $ilUser->getPref("screen_reader_optimization"))
2317  {
2318  $hash = "#".$this->getTopAnchor();
2319  }
2320 
2321  $link = $ilCtrl->getLinkTargetByClass(get_class($this->parent_obj), $this->parent_cmd).
2322  "&".$this->getNavParameter()."=".
2323  $this->getOrderField().":".$this->getOrderDirection().":";
2324 
2325  $LinkBar = "";
2326  $layout_prev = $lng->txt("previous");
2327  $layout_next = $lng->txt("next");
2328 
2329  // if more entries then entries per page -> show link bar
2330  if ($this->max_count > $this->getLimit() || $this->custom_prev_next)
2331  {
2332  $sep = "<span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>";
2333 
2334  // calculate number of pages
2335  $pages = intval($this->max_count / $this->getLimit());
2336 
2337  // add a page if a rest remains
2338  if (($this->max_count % $this->getLimit()))
2339  $pages++;
2340 
2341  // links to other pages
2342  $offset_arr = array();
2343  for ($i = 1 ;$i <= $pages ; $i++)
2344  {
2345  $newoffset = $this->getLimit() * ($i-1);
2346 
2347  $nav_value = $this->getOrderField().":".$this->getOrderDirection().":".$newoffset;
2348  $offset_arr[$nav_value] = $i;
2349  }
2350 
2351  $sep = "<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
2352 
2353  // previous link
2354  if ($this->custom_prev_next && $this->custom_prev != "")
2355  {
2356  if ($LinkBar != "")
2357  $LinkBar .= $sep;
2358  $LinkBar .= "<a href=\"".$this->custom_prev.$hash."\">".$layout_prev."</a>";
2359  }
2360  else if ($this->getOffset() >= 1 && !$this->custom_prev_next)
2361  {
2362  if ($LinkBar != "")
2363  $LinkBar .= $sep;
2364  $prevoffset = $this->getOffset() - $this->getLimit();
2365  $LinkBar .= "<a href=\"".$link.$prevoffset.$hash."\">".$layout_prev."</a>";
2366  }
2367  else
2368  {
2369  if ($LinkBar != "")
2370  $LinkBar .= $sep;
2371  $LinkBar .= '<span class="ilTableFootLight">'.$layout_prev."</span>";
2372  }
2373 
2374  // current value
2375  if ($a_num == "1")
2376  {
2377  $LinkBar .= '<input type="hidden" name="'.$this->getNavParameter().
2378  '" value="'.$this->getOrderField().":".$this->getOrderDirection().":".$this->getOffset().'" />';
2379  }
2380 
2381  $sep = "<span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>";
2382 
2383  // show next link (if not last page)
2384  if ($this->custom_prev_next && $this->custom_next != "")
2385  {
2386  if ($LinkBar != "")
2387  $LinkBar .= $sep;
2388  $LinkBar .= "<a href=\"".$this->custom_next.$hash."\">".$layout_next."</a>";
2389  }
2390  else if (! ( ($this->getOffset() / $this->getLimit())==($pages-1) ) && ($pages!=1) &&
2391  !$this->custom_prev_next)
2392  {
2393  if ($LinkBar != "")
2394  $LinkBar .= $sep;
2395  $newoffset = $this->getOffset() + $this->getLimit();
2396  $LinkBar .= "<a href=\"".$link.$newoffset.$hash."\">".$layout_next."</a>";
2397  }
2398  else
2399  {
2400  if ($LinkBar != "")
2401  $LinkBar .= $sep;
2402  $LinkBar .= '<span class="ilTableFootLight">'.$layout_next."</span>";
2403  }
2404 
2405  $sep = "<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
2406 
2407  if (count($offset_arr) && !$this->getDisplayAsBlock() && !$this->custom_prev_next)
2408  {
2409  if ($LinkBar != "")
2410  $LinkBar .= $sep;
2411  $LinkBar .= "".
2412  '<label for="tab_page_sel_'.$a_num.'">'.$lng->txt("page").'</label> '.
2413  ilUtil::formSelect($this->nav_value,
2414  $this->getNavParameter().$a_num, $offset_arr, false, true, 0, "small",
2415  array("id" => "tab_page_sel_".$a_num,
2416  "onchange" => "ilTablePageSelection(this, 'cmd[".$this->parent_cmd."]')"));
2417  //' <input class="submit" type="submit" name="cmd['.$this->parent_cmd.']" value="'.
2418  //$lng->txt("ok").'" />';
2419  }
2420 
2421  return $LinkBar;
2422  }
2423  else
2424  {
2425  return false;
2426  }
2427  }
2428 
2429  function fillHiddenRow()
2430  {
2431  $hidden_row = false;
2432  if(count($this->hidden_inputs))
2433  {
2434  foreach ($this->hidden_inputs as $hidden_input)
2435  {
2436  $this->tpl->setCurrentBlock("tbl_hidden_field");
2437  $this->tpl->setVariable("FIELD_NAME", $hidden_input["name"]);
2438  $this->tpl->setVariable("FIELD_VALUE", $hidden_input["value"]);
2439  $this->tpl->parseCurrentBlock();
2440  }
2441 
2442  $this->tpl->setCurrentBlock("tbl_hidden_row");
2443  $this->tpl->parseCurrentBlock();
2444  }
2445  }
2446 
2450  function fillActionRow()
2451  {
2452  global $lng;
2453 
2454  // action row
2455  $action_row = false;
2456  $arrow = false;
2457 
2458  // add selection buttons
2459  if (count($this->sel_buttons) > 0)
2460  {
2461  foreach ($this->sel_buttons as $button)
2462  {
2463  $this->tpl->setCurrentBlock("sel_button");
2464  $this->tpl->setVariable("SBUTTON_SELECT",
2465  ilUtil::formSelect($button["selected"], $button["sel_var"],
2466  $button["options"], false, true));
2467  $this->tpl->setVariable("SBTN_NAME", $button["cmd"]);
2468  $this->tpl->setVariable("SBTN_VALUE", $button["text"]);
2469  $this->tpl->parseCurrentBlock();
2470 
2471  if ($this->getTopCommands())
2472  {
2473  $this->tpl->setCurrentBlock("sel_top_button");
2474  $this->tpl->setVariable("SBUTTON_SELECT",
2475  ilUtil::formSelect($button["selected"], $button["sel_var"],
2476  $button["options"], false, true));
2477  $this->tpl->setVariable("SBTN_NAME", $button["cmd"]);
2478  $this->tpl->setVariable("SBTN_VALUE", $button["text"]);
2479  $this->tpl->parseCurrentBlock();
2480  }
2481  }
2482  $buttons = true;
2483  $action_row = true;
2484  }
2485  $this->sel_buttons[] = array("options" => $a_options, "cmd" => $a_cmd, "text" => $a_text);
2486 
2487  // add buttons
2488  if (count($this->buttons) > 0)
2489  {
2490  foreach ($this->buttons as $button)
2491  {
2492  if (strlen($button['onclick']))
2493  {
2494  $this->tpl->setCurrentBlock('cmdonclick');
2495  $this->tpl->setVariable('CMD_ONCLICK', $button['onclick']);
2496  $this->tpl->parseCurrentBlock();
2497  }
2498  $this->tpl->setCurrentBlock("plain_button");
2499  if ($button["id"] != "")
2500  {
2501  $this->tpl->setVariable("PBID", ' id="'.$button["id"].'" ');
2502  }
2503  $this->tpl->setVariable("PBTN_NAME", $button["cmd"]);
2504  $this->tpl->setVariable("PBTN_VALUE", $button["text"]);
2505  $this->tpl->parseCurrentBlock();
2506 
2507  if ($this->getTopCommands())
2508  {
2509  if (strlen($button['onclick']))
2510  {
2511  $this->tpl->setCurrentBlock('top_cmdonclick');
2512  $this->tpl->setVariable('CMD_ONCLICK', $button['onclick']);
2513  $this->tpl->parseCurrentBlock();
2514  }
2515  $this->tpl->setCurrentBlock("plain_top_button");
2516  $this->tpl->setVariable("PBTN_NAME", $button["cmd"]);
2517  $this->tpl->setVariable("PBTN_VALUE", $button["text"]);
2518  $this->tpl->parseCurrentBlock();
2519  }
2520  }
2521 
2522  $buttons = true;
2523  $action_row = true;
2524  }
2525 
2526  // multi selection
2527  if(count($this->mi_sel_buttons))
2528  {
2529  foreach ($this->mi_sel_buttons as $button)
2530  {
2531  $this->tpl->setCurrentBlock("mi_sel_button");
2532  $this->tpl->setVariable("MI_BUTTON_SELECT",
2533  ilUtil::formSelect($button["selected"], $button["sel_var"],
2534  $button["options"], false, true));
2535  $this->tpl->setVariable("MI_BTN_NAME", $button["cmd"]);
2536  $this->tpl->setVariable("MI_BTN_VALUE", $button["text"]);
2537  $this->tpl->parseCurrentBlock();
2538 
2539  if ($this->getTopCommands())
2540  {
2541  $this->tpl->setCurrentBlock("mi_top_sel_button");
2542  $this->tpl->setVariable("MI_BUTTON_SELECT",
2543  ilUtil::formSelect($button["selected"], $button["sel_var"]."_2",
2544  $button["options"], false, true));
2545  $this->tpl->setVariable("MI_BTN_NAME", $button["cmd"]);
2546  $this->tpl->setVariable("MI_BTN_VALUE", $button["text"]);
2547  $this->tpl->parseCurrentBlock();
2548  }
2549 
2550  }
2551  $arrow = true;
2552  $action_row = true;
2553  }
2554 
2555 
2556  if (count($this->multi) > 1 && $this->dataExists())
2557  {
2558  if($this->enable_command_for_all && $this->max_count <= self::getAllCommandLimit())
2559  {
2560  $this->tpl->setCurrentBlock("tbl_cmd_select_all");
2561  $this->tpl->setVariable("TXT_SELECT_CMD_ALL", $lng->txt("all_objects"));
2562  $this->tpl->parseCurrentBlock();
2563  }
2564 
2565  $this->tpl->setCurrentBlock("tbl_cmd_select");
2566  $sel = array();
2567  foreach ($this->multi as $mc)
2568  {
2569  $sel[$mc["cmd"]] = $mc["text"];
2570  }
2571  $this->tpl->setVariable("SELECT_CMDS",
2572  ilUtil::formSelect("", "selected_cmd", $sel, false, true));
2573  $this->tpl->setVariable("TXT_EXECUTE", $lng->txt("execute"));
2574  $this->tpl->parseCurrentBlock();
2575  $arrow = true;
2576  $action_row = true;
2577 
2578  if ($this->getTopCommands())
2579  {
2580  if($this->enable_command_for_all && $this->max_count <= self::getAllCommandLimit())
2581  {
2582  $this->tpl->setCurrentBlock("tbl_top_cmd_select_all");
2583  $this->tpl->setVariable("TXT_SELECT_CMD_ALL", $lng->txt("all_objects"));
2584  $this->tpl->parseCurrentBlock();
2585  }
2586 
2587  $this->tpl->setCurrentBlock("tbl_top_cmd_select");
2588  $sel = array();
2589  foreach ($this->multi as $mc)
2590  {
2591  $sel[$mc["cmd"]] = $mc["text"];
2592  }
2593  $this->tpl->setVariable("SELECT_CMDS",
2594  ilUtil::formSelect("", "selected_cmd2", $sel, false, true));
2595  $this->tpl->setVariable("TXT_EXECUTE", $lng->txt("execute"));
2596  $this->tpl->parseCurrentBlock();
2597  }
2598  }
2599  elseif(count($this->multi) == 1 && $this->dataExists())
2600  {
2601  $this->tpl->setCurrentBlock("tbl_single_cmd");
2602  $sel = array();
2603  foreach ($this->multi as $mc)
2604  {
2605  $cmd = $mc['cmd'];
2606  $txt = $mc['text'];
2607  }
2608  $this->tpl->setVariable("TXT_SINGLE_CMD",$txt);
2609  $this->tpl->setVariable("SINGLE_CMD",$cmd);
2610  $this->tpl->parseCurrentBlock();
2611  $arrow = true;
2612  $action_row = true;
2613 
2614  if ($this->getTopCommands())
2615  {
2616  $this->tpl->setCurrentBlock("tbl_top_single_cmd");
2617  $sel = array();
2618  foreach ($this->multi as $mc)
2619  {
2620  $cmd = $mc['cmd'];
2621  $txt = $mc['text'];
2622  }
2623  $this->tpl->setVariable("TXT_SINGLE_CMD",$txt);
2624  $this->tpl->setVariable("SINGLE_CMD",$cmd);
2625  $this->tpl->parseCurrentBlock();
2626  }
2627  }
2628 
2629  if ($arrow)
2630  {
2631  $this->tpl->setCurrentBlock("tbl_action_img_arrow");
2632  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.png"));
2633  $this->tpl->setVariable("ALT_ARROW", $lng->txt("action"));
2634  $this->tpl->parseCurrentBlock();
2635 
2636  if ($this->getTopCommands())
2637  {
2638  $this->tpl->setCurrentBlock("tbl_top_action_img_arrow");
2639  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_upright.png"));
2640  $this->tpl->setVariable("ALT_ARROW", $lng->txt("action"));
2641  $this->tpl->parseCurrentBlock();
2642  }
2643  }
2644 
2645  if ($action_row)
2646  {
2647  $this->tpl->setCurrentBlock("tbl_action_row");
2648  $this->tpl->parseCurrentBlock();
2649  if ($this->getTopCommands())
2650  {
2651  $this->tpl->setCurrentBlock("tbl_top_action_row");
2652  $this->tpl->parseCurrentBlock();
2653  }
2654  }
2655  }
2656 
2662  public function setHeaderHTML($html)
2663  {
2664  $this->headerHTML = $html;
2665  }
2666 
2673  function storeProperty($type, $value)
2674  {
2675  global $ilUser;
2676 
2677  if(is_object($ilUser) && $this->getId() != "" && $ilUser->getId() != ANONYMOUS_USER_ID)
2678  {
2679  include_once("./Services/Table/classes/class.ilTablePropertiesStorage.php");
2680  $tab_prop = new ilTablePropertiesStorage();
2681 
2682  $tab_prop->storeProperty($this->getId(), $ilUser->getId(), $type, $value);
2683  }
2684  }
2685 
2692  function loadProperty($type)
2693  {
2694  global $ilUser;
2695 
2696  if(is_object($ilUser) && $this->getId() != "" && $ilUser->getId() != ANONYMOUS_USER_ID)
2697  {
2698  include_once("./Services/Table/classes/class.ilTablePropertiesStorage.php");
2699  $tab_prop = new ilTablePropertiesStorage();
2700 
2701  return $tab_prop->getProperty($this->getId(), $ilUser->getId(), $type);
2702  }
2703  }
2704 
2710  public function getCurrentState()
2711  {
2712  $this->determineOffsetAndOrder();
2713  $this->determineLimit();
2714  $this->determineSelectedColumns();
2715  $this->determineSelectedFilters();
2716 
2717  // "filter" show/hide is not saved
2718 
2719  $result = array();
2720  $result["order"] = $this->getOrderField();
2721  $result["direction"] = $this->getOrderDirection();
2722  $result["offset"] = $this->getOffset();
2723  $result["rows"] = $this->getLimit();
2724  $result["selfilters"] = $this->getSelectedFilters();
2725 
2726  // #9514 - $this->getSelectedColumns() will omit deselected, leading to
2727  // confusion on restoring template
2728  $result["selfields"] = $this->selected_column;
2729 
2730  // gather filter values
2731  if($this->filters)
2732  {
2733  foreach($this->filters as $item)
2734  {
2735  $result["filter_values"][$item->getFieldId()] = $this->getFilterValue($item);
2736  }
2737  }
2738  if($this->optional_filters && $result["selfilters"])
2739  {
2740  foreach($this->optional_filters as $item)
2741  {
2742  if(in_array($item->getFieldId(), $result["selfilters"]))
2743  {
2744  $result["filter_values"][$item->getFieldId()] = $this->getFilterValue($item);
2745  }
2746  }
2747  }
2748 
2749  return $result;
2750  }
2751 
2758  protected function getFilterValue(ilFormPropertyGUI $a_item)
2759  {
2760  if(method_exists($a_item, "getChecked"))
2761  {
2762  return $a_item->getChecked();
2763  }
2764  else if(method_exists($a_item, "getValue"))
2765  {
2766  return $a_item->getValue();
2767  }
2768  else if(method_exists($a_item, "getDate"))
2769  {
2770  return $a_item->getDate()->get(IL_CAL_DATE);
2771  }
2772  }
2773 
2780  protected function SetFilterValue(ilFormPropertyGUI $a_item, $a_value)
2781  {
2782  if(method_exists($a_item, "setChecked"))
2783  {
2784  $a_item->setChecked($a_value);
2785  }
2786  else if(method_exists($a_item, "setValue"))
2787  {
2788  $a_item->setValue($a_value);
2789  }
2790  else if(method_exists($a_item, "setDate"))
2791  {
2792  $a_item->setDate(new ilDate($a_value, IL_CAL_DATE));
2793  }
2794  $a_item->writeToSession();
2795  }
2796 
2802  public function setContext($id)
2803  {
2804  if(trim($id))
2805  {
2806  $this->context = $id;
2807  }
2808  }
2809 
2815  public function getContext()
2816  {
2817  return $this->context;
2818  }
2819 
2825  public function setShowRowsSelector($a_value)
2826  {
2827  $this->show_rows_selector = (bool)$a_value;
2828  }
2829 
2835  public function getShowRowsSelector()
2836  {
2838  }
2839 
2845  public function setShowTemplates($a_value)
2846  {
2847  $this->show_templates = (bool)$a_value;
2848  }
2849 
2855  public function getShowTemplates()
2856  {
2857  return $this->show_templates;
2858  }
2859 
2866  public function restoreTemplate($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 
2877  $data = $storage->load($this->getContext(), $ilUser->getId(), $a_name);
2878  if(is_array($data))
2879  {
2880  foreach($data as $property => $value)
2881  {
2882  $this->storeProperty($property, $value);
2883  }
2884  }
2885 
2886  $data["filter_values"] = unserialize($data["filter_values"]);
2887  if($data["filter_values"])
2888  {
2889  $this->restore_filter_values = $data["filter_values"];
2890  }
2891 
2892  return true;
2893  }
2894  return false;
2895  }
2896 
2903  public function saveTemplate($a_name)
2904  {
2905  global $ilUser;
2906 
2907  $a_name = ilUtil::prepareFormOutput($a_name, true);
2908 
2909  if(trim($a_name) && $this->getContext() != "" && is_object($ilUser) && $ilUser->getId() != ANONYMOUS_USER_ID)
2910  {
2911  include_once("./Services/Table/classes/class.ilTableTemplatesStorage.php");
2912  $storage = new ilTableTemplatesStorage();
2913 
2914  $state = $this->getCurrentState();
2915  $state["filter_values"] = serialize($state["filter_values"]);
2916  $state["selfields"] = serialize($state["selfields"]);
2917  $state["selfilters"] = serialize($state["selfilters"]);
2918 
2919  $storage->store($this->getContext(), $ilUser->getId(), $a_name, $state);
2920  return true;
2921  }
2922  return false;
2923  }
2924 
2931  public function deleteTemplate($a_name)
2932  {
2933  global $ilUser;
2934 
2935  $a_name = ilUtil::prepareFormOutput($a_name, true);
2936 
2937  if(trim($a_name) && $this->getContext() != "" && is_object($ilUser) && $ilUser->getId() != ANONYMOUS_USER_ID)
2938  {
2939  include_once("./Services/Table/classes/class.ilTableTemplatesStorage.php");
2940  $storage = new ilTableTemplatesStorage();
2941  $storage->delete($this->getContext(), $ilUser->getId(), $a_name);
2942  return true;
2943  }
2944  return false;
2945  }
2946 
2950  function getLimit()
2951  {
2952  if($this->getExportMode() || $this->getPrintMode())
2953  {
2954  return 9999;
2955  }
2956  return parent::getLimit();
2957  }
2958 
2962  function getOffset()
2963  {
2964  if($this->getExportMode() || $this->getPrintMode())
2965  {
2966  return 0;
2967  }
2968  return parent::getOffset();
2969  }
2970 
2976  public function setExportFormats(array $formats)
2977  {
2978  $this->export_formats = array();
2979 
2980  // #11339
2981  $valid = array(self::EXPORT_EXCEL => "tbl_export_excel",
2982  self::EXPORT_CSV => "tbl_export_csv");
2983 
2984  foreach($formats as $format)
2985  {
2986  if(array_key_exists($format, $valid))
2987  {
2988  $this->export_formats[$format] = $valid[$format];
2989  }
2990  }
2991  }
2992 
2997  public function setPrintMode($a_value = false)
2998  {
2999  $this->print_mode = (bool)$a_value;
3000  }
3001 
3006  public function getPrintMode()
3007  {
3008  return $this->print_mode;
3009  }
3010 
3016  public function getExportMode()
3017  {
3018  return $this->export_mode;
3019  }
3020 
3026  public function exportData($format, $send = false)
3027  {
3028  if($this->dataExists())
3029  {
3030  // #9640: sort
3031  if (!$this->getExternalSorting())
3032  {
3033  $this->determineOffsetAndOrder(true);
3034 
3035  $this->row_data = ilUtil::sortArray($this->row_data, $this->getOrderField(),
3036  $this->getOrderDirection(), $this->numericOrdering($this->getOrderField()));
3037  }
3038 
3039  $filename = "export";
3040 
3041  switch($format)
3042  {
3043  case self::EXPORT_EXCEL:
3044  include_once "./Services/Excel/classes/class.ilExcelUtils.php";
3045  include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php";
3046  $adapter = new ilExcelWriterAdapter($filename.".xls", $send);
3047  $workbook = $adapter->getWorkbook();
3048  $worksheet = $workbook->addWorksheet();
3049  $row = 0;
3050 
3051  ob_start();
3052  $this->fillMetaExcel($worksheet, $row);
3053  $this->fillHeaderExcel($worksheet, $row);
3054  foreach($this->row_data as $set)
3055  {
3056  $row++;
3057  $this->fillRowExcel($worksheet, $row, $set);
3058  }
3059  ob_end_clean();
3060 
3061  $workbook->close();
3062  break;
3063 
3064  case self::EXPORT_CSV:
3065  include_once "./Services/Utilities/classes/class.ilCSVWriter.php";
3066  $csv = new ilCSVWriter();
3067  $csv->setSeparator(";");
3068 
3069  ob_start();
3070  $this->fillMetaCSV($csv);
3071  $this->fillHeaderCSV($csv);
3072  foreach($this->row_data as $set)
3073  {
3074  $this->fillRowCSV($csv, $set);
3075  }
3076  ob_end_clean();
3077 
3078  if($send)
3079  {
3080  $filename .= ".csv";
3081  header("Content-type: text/comma-separated-values");
3082  header("Content-Disposition: attachment; filename=\"".$filename."\"");
3083  header("Expires: 0");
3084  header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
3085  header("Pragma: public");
3086  echo $csv->getCSVString();
3087 
3088  }
3089  else
3090  {
3091  file_put_contents($filename, $csv->getCSVString());
3092  }
3093  break;
3094  }
3095 
3096  if($send)
3097  {
3098  exit();
3099  }
3100  }
3101  }
3102 
3110  protected function fillMetaExcel($worksheet, &$a_row)
3111  {
3112 
3113  }
3114 
3122  protected function fillHeaderExcel($worksheet, &$a_row)
3123  {
3124  $col = 0;
3125  foreach ($this->column as $column)
3126  {
3127  $title = strip_tags($column["text"]);
3128  if($title)
3129  {
3130  $worksheet->write($a_row, $col, $title);
3131  $col++;
3132  }
3133  }
3134  $a_row++;
3135  }
3136 
3145  protected function fillRowExcel($a_worksheet, &$a_row, $a_set)
3146  {
3147  $col = 0;
3148  foreach ($a_set as $key => $value)
3149  {
3150  if(is_array($value))
3151  {
3152  $value = implode(', ', $value);
3153  }
3154  $a_worksheet->write($a_row, $col, strip_tags($value));
3155  $col++;
3156  }
3157  }
3158 
3165  protected function fillMetaCSV($a_csv)
3166  {
3167 
3168  }
3169 
3176  protected function fillHeaderCSV($a_csv)
3177  {
3178  foreach ($this->column as $column)
3179  {
3180  $title = strip_tags($column["text"]);
3181  if($title)
3182  {
3183  $a_csv->addColumn($title);
3184  }
3185  }
3186  $a_csv->addRow();
3187  }
3188 
3196  protected function fillRowCSV($a_csv, $a_set)
3197  {
3198  foreach ($a_set as $key => $value)
3199  {
3200  if(is_array($value))
3201  {
3202  $value = implode(', ', $value);
3203  }
3204  $a_csv->addColumn(strip_tags($value));
3205  }
3206  $a_csv->addRow();
3207  }
3208 
3214  public function setEnableAllCommand($a_value)
3215  {
3216  $this->enable_command_for_all = (bool)$a_value;
3217  }
3218 
3224  public static function getAllCommandLimit()
3225  {
3226  global $ilClientIniFile;
3227 
3228  $limit = $ilClientIniFile->readVariable("system", "TABLE_ACTION_ALL_LIMIT");
3229  if(!$limit)
3230  {
3232  }
3233 
3234  return $limit;
3235  }
3236 
3241  {
3242  $this->row_selector_label = $row_selector_label;
3243  return $this;
3244  }
3245 
3249  public function getRowSelectorLabel()
3250  {
3252  }
3253 }
3254 
3255 ?>