ILIAS  eassessment Revision 61809
 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 
44  protected $export_formats;
45  protected $export_mode;
46  protected $print_mode;
47 
48  const FILTER_TEXT = 1;
49  const FILTER_SELECT = 2;
50  const FILTER_DATE = 3;
51  const FILTER_LANGUAGE = 4;
53  const FILTER_DATE_RANGE = 6;
55 
56  const EXPORT_EXCEL = 1;
57  const EXPORT_CSV = 2;
58 
63  public function __construct($a_parent_obj, $a_parent_cmd = "", $a_template_context = "")
64  {
65  global $lng;
66 
67  parent::__construct(0, false);
68  $this->unique_id = md5(uniqid());
69  $this->parent_obj = $a_parent_obj;
70  $this->parent_cmd = $a_parent_cmd;
71  $this->buttons = array();
72  $this->header_commands = array();
73  $this->multi = array();
74  $this->hidden_inputs = array();
75  $this->formname = "table_" . $this->unique_id;
76  $this->tpl = new ilTemplate("tpl.table2.html", true, true, "Services/Table");
77 
78  $lng->loadLanguageModule('tbl');
79 
80  if(!$a_template_context)
81  {
82  $a_template_context = $this->getId();
83  }
84  $this->setContext($a_template_context);
85 
86  // activate export mode
87  if(isset($_GET[$this->prefix."_xpt"]))
88  {
89  $this->export_mode = (int)$_GET[$this->prefix."_xpt"];
90  }
91 
92  // template handling
93  if(isset($_GET[$this->prefix."_tpl"]))
94  {
95  $this->restoreTemplate($_GET[$this->prefix."_tpl"]);
96  }
97 
98  $this->determineLimit();
99  $this->setIsDataTable(true);
100  $this->setEnableNumInfo(true);
101  $this->determineSelectedColumns();
102  }
103 
107  function determineLimit()
108  {
109  global $ilUser;
110 
111  if ($this->limit_determined)
112  {
113  return;
114  }
115 
116  $limit = 0;
117  if (isset($_GET[$this->prefix."_trows"]))
118  {
119  $this->storeProperty("rows", $_GET[$this->prefix."_trows"]);
120  $limit = $_GET[$this->prefix."_trows"];
121  $this->resetOffset();
122  }
123 
124  if ($limit == 0)
125  {
126  $rows = $this->loadProperty("rows");
127  if ($rows > 0)
128  {
129  $limit = $rows;
130  }
131  else
132  {
133  if (is_object($ilUser))
134  {
135  $limit = $ilUser->getPref("hits_per_page");
136  }
137  else
138  {
139  $limit = 40;
140  }
141  }
142  }
143 
144  $this->setLimit($limit);
145  $this->limit_determined = true;
146  }
147 
154  {
155  return array();
156  }
157 
162  {
163  if ($this->columns_determined)
164  {
165  return;
166  }
167 
168  $old_sel = $this->loadProperty("selfields");
169 
170  $stored = false;
171  if ($old_sel != "")
172  {
173  $sel_fields =
174  @unserialize($old_sel);
175  $stored = true;
176  }
177  if(!is_array($sel_fields))
178  {
179  $stored = false;
180  $sel_fields = array();
181  }
182 
183  $this->selected_columns = array();
184  $set = false;
185  foreach ($this->getSelectableColumns() as $k => $c)
186  {
187  $this->selected_column[$k] = false;
188 
189  if ($_POST["tblfsh".$this->getId()])
190  {
191  $set = true;
192  if (is_array($_POST["tblfs".$this->getId()]) && in_array($k, $_POST["tblfs".$this->getId()]))
193  {
194  $this->selected_column[$k] = true;
195  }
196  }
197  else if ($stored) // take stored values
198  {
199  $this->selected_column[$k] = $sel_fields[$k];
200  }
201  else // take default values
202  {
203  if ($c["default"])
204  {
205  $this->selected_column[$k] = true;
206  }
207  }
208  }
209 
210  if ($old_sel != serialize($this->selected_column) && $set)
211  {
212  $this->storeProperty("selfields", serialize($this->selected_column));
213  }
214 
215  $this->columns_determined = true;
216  }
217 
224  function isColumnSelected($a_col)
225  {
226  return $this->selected_column[$a_col];
227  }
228 
236  {
237  $scol = array();
238  foreach ($this->selected_column as $k => $v)
239  {
240  if ($v)
241  {
242  $scol[$k] = $k;
243  }
244  }
245  return $scol;
246  }
247 
251  function &executeCommand()
252  {
253  global $ilCtrl;
254 
255  $next_class = $ilCtrl->getNextClass($this);
256  $cmd = $ilCtrl->getCmd();
257 
258  switch($next_class)
259  {
260  case 'ilformpropertydispatchgui':
261  include_once './Services/Form/classes/class.ilFormPropertyDispatchGUI.php';
262  $form_prop_dispatch = new ilFormPropertyDispatchGUI();
263  $this->initFilter();
264  $item = $this->getFilterItemByPostVar($_GET["postvar"]);
265  $form_prop_dispatch->setItem($item);
266  return $ilCtrl->forwardCommand($form_prop_dispatch);
267  break;
268 
269  }
270  return false;
271  }
272 
276  function resetOffset($a_in_determination = false)
277  {
278  if (!$this->nav_determined && !$a_in_determination)
279  {
280  $this->determineOffsetAndOrder();
281  }
282  $this->nav_value = $this->getOrderField().":".$this->getOrderDirection().":0";
283  $_GET[$this->getNavParameter()] =
284  $_POST[$this->getNavParameter()."1"] =
285  $this->nav_value;
286 //echo $this->nav_value;
287  $this->setOffset(0);
288  }
289 
294  function initFilter()
295  {
296  }
297 
303  public function getParentObject()
304  {
305  return $this->parent_obj;
306  }
307 
313  public function getParentCmd()
314  {
315  return $this->parent_cmd;
316  }
317 
323  function setTopAnchor($a_val)
324  {
325  $this->top_anchor = $a_val;
326  }
327 
333  function getTopAnchor()
334  {
335  return $this->top_anchor;
336  }
337 
343  function setNoEntriesText($a_text)
344  {
345  $this->noentriestext = $a_text;
346  }
347 
353  function getNoEntriesText()
354  {
355  return $this->noentriestext;
356  }
357 
363  function setIsDataTable($a_val)
364  {
365  $this->datatable = $a_val;
366  }
367 
373  function getIsDataTable()
374  {
375  return $this->datatable;
376  }
377 
383  function setEnableTitle($a_enabletitle)
384  {
385  $this->enabled["title"] = $a_enabletitle;
386  }
387 
393  function getEnableTitle()
394  {
395  return $this->enabled["title"];
396  }
397 
403  function setEnableHeader($a_enableheader)
404  {
405  $this->enabled["header"] = $a_enableheader;
406  }
407 
413  function getEnableHeader()
414  {
415  return $this->enabled["header"];
416  }
417 
423  function setEnableNumInfo($a_val)
424  {
425  $this->num_info = $a_val;
426  }
427 
433  function getEnableNumInfo()
434  {
435  return $this->num_info;
436  }
437 
441  final public function setTitle($a_title, $a_icon = 0, $a_icon_alt = 0)
442  {
443  parent::setTitle($a_title, $a_icon, $a_icon_alt);
444  }
445 
451  function setDescription($a_val)
452  {
453  $this->description = $a_val;
454  }
455 
461  function getDescription()
462  {
463  return $this->description;
464  }
465 
471  function setOrderField($a_order_field)
472  {
473  $this->order_field = $a_order_field;
474  }
475 
476  function getOrderField()
477  {
478  return $this->order_field;
479  }
480 
481  final public function setData($a_data)
482  {
483  $this->row_data = $a_data;
484  }
485 
486  final public function getData()
487  {
488  return $this->row_data;
489  }
490 
491  final public function dataExists()
492  {
493  if (is_array($this->row_data))
494  {
495  if (count($this->row_data) > 0)
496  {
497  return true;
498  }
499  }
500  return false;
501  }
502 
503  final public function setPrefix($a_prefix)
504  {
505  $this->prefix = $a_prefix;
506  }
507 
508  final public function getPrefix()
509  {
510  return $this->prefix;
511  }
512 
517  final function addFilterItem($a_input_item, $a_optional = false)
518  {
519  $a_input_item->setParent($this);
520  if (!$a_optional)
521  {
522  $this->filters[] = $a_input_item;
523  }
524  else
525  {
526  $this->optional_filters[] = $a_input_item;
527  }
528 
529  // restore filter values (from stored view)
530  if($this->restore_filter_values &&
531  array_key_exists($a_input_item->getFieldId(), $this->restore_filter_values))
532  {
533  $this->setFilterValue($a_input_item, $this->restore_filter_values[$a_input_item->getFieldId()]);
534  }
535  }
536 
546  function addFilterItemByMetaType($id, $type = self::FILTER_TEXT, $a_optional = false, $caption = NULL)
547  {
548  global $lng;
549 
550  if(!$caption)
551  {
552  $caption = $lng->txt($id);
553  }
554 
555  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
556 
557  switch($type)
558  {
559  case self::FILTER_SELECT:
560  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
561  $item = new ilSelectInputGUI($caption, $id);
562  break;
563 
564  case self::FILTER_DATE:
565  include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
566  $item = new ilDateTimeInputGUI($caption, $id);
567  $item->setMode(ilDateTimeInputGUI::MODE_INPUT);
568  break;
569 
570  case self::FILTER_TEXT:
571  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
572  $item = new ilTextInputGUI($caption, $id);
573  $item->setMaxLength(64);
574  $item->setSize(20);
575  // $item->setSubmitFormOnEnter(true);
576  break;
577 
578  case self::FILTER_LANGUAGE:
579  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
580  $item = new ilSelectInputGUI($caption, $id);
581  $options = array("" => $lng->txt("trac_all"));
582  foreach ($lng->getInstalledLanguages() as $lang_key)
583  {
584  $options[$lang_key] = $lng->txt("lang_".$lang_key);
585  }
586  $item->setOptions($options);
587  break;
588 
589  case self::FILTER_NUMBER_RANGE:
590  include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
591  include_once("./Services/Form/classes/class.ilNumberInputGUI.php");
592  $item = new ilCombinationInputGUI($caption, $id);
593  $combi_item = new ilNumberInputGUI("", $id."_from");
594  $item->addCombinationItem("from", $combi_item, $lng->txt("from"));
595  $combi_item = new ilNumberInputGUI("", $id."_to");
596  $item->addCombinationItem("to", $combi_item, $lng->txt("to"));
597  $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
598  $item->setMaxLength(7);
599  $item->setSize(20);
600  break;
601 
602  case self::FILTER_DATE_RANGE:
603  include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
604  include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
605  $item = new ilCombinationInputGUI($caption, $id);
606  $combi_item = new ilDateTimeInputGUI("", $id."_from");
607  $item->addCombinationItem("from", $combi_item, $lng->txt("from"));
608  $combi_item = new ilDateTimeInputGUI("", $id."_to");
609  $item->addCombinationItem("to", $combi_item, $lng->txt("to"));
610  $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
611  $item->setMode(ilDateTimeInputGUI::MODE_INPUT);
612  break;
613 
614  case self::FILTER_DURATION_RANGE:
615  $lng->loadLanguageModule("form");
616  include_once("./Services/Form/classes/class.ilCombinationInputGUI.php");
617  include_once("./Services/Form/classes/class.ilDurationInputGUI.php");
618  $item = new ilCombinationInputGUI($caption, $id);
619  $combi_item = new ilDurationInputGUI("", $id."_from");
620  $combi_item->setShowMonths(false);
621  $combi_item->setShowDays(true);
622  $item->addCombinationItem("from", $combi_item, $lng->txt("from"));
623  $combi_item = new ilDurationInputGUI("", $id."_to");
624  $combi_item->setShowMonths(false);
625  $combi_item->setShowDays(true);
626  $item->addCombinationItem("to", $combi_item, $lng->txt("to"));
627  $item->setComparisonMode(ilCombinationInputGUI::COMPARISON_ASCENDING);
628  break;
629 
630  default:
631  return false;
632  }
633 
634  $this->addFilterItem($item, $a_optional);
635  $item->readFromSession();
636  return $item;
637  }
638 
642  final function getFilterItems($a_optionals = false)
643  {
644  if (!$a_optionals)
645  {
646  return $this->filters;
647  }
649  }
650 
651  final function getFilterItemByPostVar($a_post_var)
652  {
653  foreach ($this->getFilterItems() as $item)
654  {
655  if ($item->getPostVar() == $a_post_var)
656  {
657  return $item;
658  }
659  }
660  foreach ($this->getFilterItems(true) as $item)
661  {
662  if ($item->getPostVar() == $a_post_var)
663  {
664  return $item;
665  }
666  }
667  return false;
668  }
669 
675  function setFilterCols($a_val)
676  {
677  $this->filter_cols = $a_val;
678  }
679 
685  function getFilterCols()
686  {
687  return $this->filter_cols;
688  }
689 
695  function setDisableFilterHiding($a_val = true)
696  {
697  $this->disable_filter_hiding = $a_val;
698  }
699 
706  {
708  }
709 
716  function isFilterSelected($a_col)
717  {
718  return $this->selected_filter[$a_col];
719  }
720 
728  {
729  $sfil = array();
730  foreach ($this->selected_filter as $k => $v)
731  {
732  if ($v)
733  {
734  $sfil[$k] = $k;
735  }
736  }
737  return $sfil;
738  }
739 
747  {
748  if ($this->filters_determined)
749  {
750  return;
751  }
752 
753  $old_sel = $this->loadProperty("selfilters");
754  $stored = false;
755  if ($old_sel != "")
756  {
757  $sel_filters =
758  @unserialize($old_sel);
759  $stored = true;
760  }
761  if(!is_array($sel_filters))
762  {
763  $stored = false;
764  $sel_filters = array();
765  }
766 
767  $this->selected_filter = array();
768  $set = false;
769  foreach ($this->getFilterItems(true) as $item)
770  {
771  $k = $item->getPostVar();
772 
773  $this->selected_filter[$k] = false;
774 
775  if ($_POST["tblfsf".$this->getId()])
776  {
777  $set = true;
778  if (is_array($_POST["tblff".$this->getId()]) && in_array($k, $_POST["tblff".$this->getId()]))
779  {
780  $this->selected_filter[$k] = true;
781  }
782  else
783  {
784  $item->setValue(NULL);
785  $item->writeToSession();
786  }
787  }
788  else if ($stored) // take stored values
789  {
790  $this->selected_filter[$k] = $sel_filters[$k];
791  }
792  }
793 
794  if ($old_sel != serialize($this->selected_filter) && $set)
795  {
796  $this->storeProperty("selfilters", serialize($this->selected_filter));
797  }
798 
799  $this->filters_determined = true;
800  }
801 
805  function setCustomPreviousNext($a_prev_link, $a_next_link)
806  {
807  $this->custom_prev_next = true;
808  $this->custom_prev = $a_prev_link;
809  $this->custom_next = $a_next_link;
810  }
811 
817  final public function setFormAction($a_form_action)
818  {
819  $this->form_action = $a_form_action;
820  }
821 
827  final public function getFormAction()
828  {
829  return $this->form_action;
830  }
831 
837  function setFormName($a_formname)
838  {
839  $this->formname = $a_formname;
840  }
841 
847  function getFormName()
848  {
849  return $this->formname;
850  }
851 
857  function setId($a_val)
858  {
859  $this->id = $a_val;
860  if ($this->getPrefix() == "")
861  {
862  $this->setPrefix($a_val);
863  }
864  }
865 
871  function getId()
872  {
873  return $this->id;
874  }
875 
881  function setDisplayAsBlock($a_val)
882  {
883  $this->display_as_block = $a_val;
884  }
885 
891  function getDisplayAsBlock()
892  {
893  return $this->display_as_block;
894  }
895 
902  {
904  }
905 
911  function setSelectAllCheckbox($a_select_all_checkbox)
912  {
913  $this->select_all_checkbox = $a_select_all_checkbox;
914  }
915 
921  function setExternalSorting($a_val)
922  {
923  $this->ext_sort = $a_val;
924  }
925 
932  {
933  return $this->ext_sort;
934  }
935 
941  function setFilterCommand($a_val)
942  {
943  $this->filter_cmd = $a_val;
944  }
945 
951  function getFilterCommand()
952  {
953  return $this->filter_cmd;
954  }
955 
961  function setResetCommand($a_val)
962  {
963  $this->reset_cmd = $a_val;
964  }
965 
971  function getResetCommand()
972  {
973  return $this->reset_cmd;
974  }
975 
981  function setExternalSegmentation($a_val)
982  {
983  $this->ext_seg = $a_val;
984  }
985 
992  {
993  return $this->ext_seg;
994  }
995 
1002  final public function setRowTemplate($a_template, $a_template_dir = "")
1003  {
1004  $this->row_template = $a_template;
1005  $this->row_template_dir = $a_template_dir;
1006  }
1007 
1013  function setDefaultOrderField($a_defaultorderfield)
1014  {
1015  $this->defaultorderfield = $a_defaultorderfield;
1016  }
1017 
1024  {
1025  return $this->defaultorderfield;
1026  }
1027 
1033  function setDefaultOrderDirection($a_defaultorderdirection)
1034  {
1035  $this->defaultorderdirection = $a_defaultorderdirection;
1036  }
1037 
1044  {
1045  return $this->defaultorderdirection;
1046  }
1047 
1048  /*
1049  * Removes all command buttons from the table
1050  *
1051  * @access public
1052  */
1053  public function clearCommandButtons()
1054  {
1055  $this->buttons = array();
1056  }
1057 
1064  function addCommandButton($a_cmd, $a_text, $a_onclick = '')
1065  {
1066  $this->buttons[] = array("cmd" => $a_cmd, "text" => $a_text, 'onclick' => $a_onclick);
1067  }
1068 
1077  function addSelectionButton($a_sel_var, $a_options, $a_cmd, $a_text, $a_default_selection = '')
1078  {
1079  $this->sel_buttons[] = array("sel_var" => $a_sel_var, "options" => $a_options, "selected" => $a_default_selection, "cmd" => $a_cmd, "text" => $a_text);
1080  }
1081 
1091  public function addMultiItemSelectionButton($a_sel_var, $a_options, $a_cmd, $a_text, $a_default_selection = '')
1092  {
1093  $this->mi_sel_buttons[] = array("sel_var" => $a_sel_var, "options" => $a_options, "selected" => $a_default_selection, "cmd" => $a_cmd, "text" => $a_text);
1094  $this->addHiddenInput("cmd_sv[".$a_cmd."]", $a_sel_var);
1095  }
1096 
1097 
1098 
1104  function setCloseCommand($a_link)
1105  {
1106  $this->close_command = $a_link;
1107  }
1108 
1115  function addMultiCommand($a_cmd, $a_text)
1116  {
1117  $this->multi[] = array("cmd" => $a_cmd, "text" => $a_text);
1118  }
1119 
1126  public function addHiddenInput($a_name, $a_value)
1127  {
1128  $this->hidden_inputs[] = array("name" => $a_name, "value" => $a_value);
1129  }
1130 
1137  function addHeaderCommand($a_href, $a_text, $a_target = "", $a_img = "")
1138  {
1139  $this->header_commands[] = array("href" => $a_href, "text" => $a_text,
1140  "target" => $a_target, "img" => $a_img);
1141  }
1142 
1148  function setTopCommands($a_val)
1149  {
1150  $this->top_commands = $a_val;
1151  }
1152 
1158  function getTopCommands()
1159  {
1160  return $this->top_commands;
1161  }
1162 
1170  final public function addColumn($a_text, $a_sort_field = "", $a_width = "",
1171  $a_is_checkbox_action_column = false, $a_class = "", $a_tooltip = "")
1172  {
1173  $this->column[] = array(
1174  "text" => $a_text,
1175  "sort_field" => $a_sort_field,
1176  "width" => $a_width,
1177  "is_checkbox_action_column" => $a_is_checkbox_action_column,
1178  "class" => $a_class,
1179  "tooltip" => $a_tooltip
1180  );
1181  $this->column_count = count($this->column);
1182  }
1183 
1184 
1185  final public function getNavParameter()
1186  {
1187  return $this->prefix."_table_nav";
1188  }
1189 
1190  function setOrderLink($sort_field, $order_dir)
1191  {
1192  global $ilCtrl, $ilUser;
1193 
1194  $hash = "";
1195  if (is_object($ilUser) && $ilUser->getPref("screen_reader_optimization"))
1196  {
1197  $hash = "#".$this->getTopAnchor();
1198  }
1199 
1200  $old = $_GET[$this->getNavParameter()];
1201 
1202  // set order link
1203  $ilCtrl->setParameter($this->parent_obj,
1204  $this->getNavParameter(),
1205  $sort_field.":".$order_dir.":".$this->offset);
1206  $this->tpl->setVariable("TBL_ORDER_LINK",
1207  $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd).$hash);
1208 
1209  // set old value of nav variable
1210  $ilCtrl->setParameter($this->parent_obj,
1211  $this->getNavParameter(), $old);
1212  }
1213 
1214  function fillHeader()
1215  {
1216  global $lng;
1217 
1218  $allcolumnswithwidth = true;
1219  foreach ((array) $this->column as $column)
1220  {
1221  if (!strlen($column["width"])) $allcolumnswithwidth = false;
1222  }
1223  if ($allcolumnswithwidth)
1224  {
1225  foreach ((array) $this->column as $column)
1226  {
1227  $this->tpl->setCurrentBlock("tbl_colgroup_column");
1228  $this->tpl->setVariable("COLGROUP_COLUMN_WIDTH", $column["width"]);
1229  $this->tpl->parseCurrentBlock();
1230  }
1231  }
1232  $ccnt = 0;
1233  foreach ((array) $this->column as $column)
1234  {
1235  $ccnt++;
1236 
1237  //tooltip
1238  if ($column["tooltip"] != "")
1239  {
1240  include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
1241  ilTooltipGUI::addTooltip("thc_".$this->getId()."_".$ccnt, $column["tooltip"]);
1242  }
1243  if (!$this->enabled["sort"] || $column["sort_field"] == "" || $column["is_checkbox_action_column"])
1244  {
1245  $this->tpl->setCurrentBlock("tbl_header_no_link");
1246  if ($column["width"] != "")
1247  {
1248  $this->tpl->setVariable("TBL_COLUMN_WIDTH_NO_LINK"," width=\"".$column["width"]."\"");
1249  }
1250  if (!$column["is_checkbox_action_column"])
1251  {
1252  $this->tpl->setVariable("TBL_HEADER_CELL_NO_LINK",
1253  $column["text"]);
1254  }
1255  else
1256  {
1257  $this->tpl->setVariable("TBL_HEADER_CELL_NO_LINK",
1258  ilUtil::img(ilUtil::getImagePath("spacer.gif"), $lng->txt("action")));
1259  }
1260  $this->tpl->setVariable("HEAD_CELL_NL_ID", "thc_".$this->getId()."_".$ccnt);
1261 
1262  if ($column["class"] != "")
1263  {
1264  $this->tpl->setVariable("TBL_HEADER_CLASS"," " . $column["class"]);
1265  }
1266  $this->tpl->parseCurrentBlock();
1267  $this->tpl->touchBlock("tbl_header_th");
1268  continue;
1269  }
1270  if (($column["sort_field"] == $this->order_field) && ($this->order_direction != ""))
1271  {
1272  $this->tpl->setCurrentBlock("tbl_order_image");
1273  $this->tpl->setVariable("IMG_ORDER_DIR",ilUtil::getImagePath($this->order_direction."_order.gif"));
1274  $this->tpl->setVariable("IMG_ORDER_ALT", $this->lng->txt("change_sort_direction"));
1275  $this->tpl->parseCurrentBlock();
1276  }
1277 
1278  $this->tpl->setCurrentBlock("tbl_header_cell");
1279  $this->tpl->setVariable("TBL_HEADER_CELL", $column["text"]);
1280  $this->tpl->setVariable("HEAD_CELL_ID", "thc_".$this->getId()."_".$ccnt);
1281 
1282  // only set width if a value is given for that column
1283  if ($column["width"] != "")
1284  {
1285  $this->tpl->setVariable("TBL_COLUMN_WIDTH"," width=\"".$column["width"]."\"");
1286  }
1287 
1288  $lng_sort_column = $this->lng->txt("sort_by_this_column");
1289  $this->tpl->setVariable("TBL_ORDER_ALT",$lng_sort_column);
1290 
1291  $order_dir = "asc";
1292 
1293  if ($column["sort_field"] == $this->order_field)
1294  {
1295  $order_dir = $this->sort_order;
1296 
1297  $lng_change_sort = $this->lng->txt("change_sort_direction");
1298  $this->tpl->setVariable("TBL_ORDER_ALT",$lng_change_sort);
1299  }
1300 
1301  if ($column["class"] != "")
1302  {
1303  $this->tpl->setVariable("TBL_HEADER_CLASS"," " . $column["class"]);
1304  }
1305  $this->setOrderLink($column["sort_field"], $order_dir);
1306  $this->tpl->parseCurrentBlock();
1307  $this->tpl->touchBlock("tbl_header_th");
1308  }
1309 
1310  $this->tpl->setCurrentBlock("tbl_header");
1311  $this->tpl->parseCurrentBlock();
1312  }
1313 
1317  protected function prepareOutput()
1318  {
1319  }
1320 
1321 
1325  function determineOffsetAndOrder($a_omit_offset = false)
1326  {
1327  global $ilUser;
1328 
1329  if ($this->nav_determined)
1330  {
1331  return true;
1332  }
1333 
1334  if ($_POST[$this->getNavParameter()."1"] != "")
1335  {
1336  if ($_POST[$this->getNavParameter()."1"] != $_POST[$this->getNavParameter()])
1337  {
1338  $this->nav_value = $_POST[$this->getNavParameter()."1"];
1339  }
1340  else if ($_POST[$this->getNavParameter()."2"] != $_POST[$this->getNavParameter()])
1341  {
1342  $this->nav_value = $_POST[$this->getNavParameter()."2"];
1343  }
1344  }
1345  elseif($_GET[$this->getNavParameter()])
1346  {
1347  $this->nav_value = $_GET[$this->getNavParameter()];
1348  }
1349  elseif($_SESSION[$this->getNavParameter()] != "")
1350  {
1351  $this->nav_value = $_SESSION[$this->getNavParameter()];
1352  }
1353 
1354  if ($this->nav_value == "" && $this->getId() != "" && $ilUser->getId() != ANONYMOUS_USER_ID)
1355  {
1356  // get order and direction from db
1357  $this->nav_value =
1358  $this->loadProperty("order").":".
1359  $this->loadProperty("direction").":".
1360  $this->loadProperty("offset");
1361  }
1362  $nav = explode(":", $this->nav_value);
1363 
1364  // $nav[0] is order by
1365  $this->setOrderField(($nav[0] != "") ? $nav[0] : $this->getDefaultOrderField());
1366  $this->setOrderDirection(($nav[1] != "") ? $nav[1] : $this->getDefaultOrderDirection());
1367 
1368  if (!$a_omit_offset)
1369  {
1370  if (!$this->getExternalSegmentation() && $nav[2] >= $this->max_count)
1371  {
1372  $this->resetOffset(true);
1373  }
1374  else
1375  {
1376  $this->setOffset($nav[2]);
1377  }
1378  }
1379 
1380  if (!$a_omit_offset)
1381  {
1382  $this->nav_determined = true;
1383  }
1384  }
1385 
1387  {
1388  if ($this->getOrderField() != "")
1389  {
1390  $this->storeProperty("order", $this->getOrderField());
1391  }
1392  if ($this->getOrderDirection() != "")
1393  {
1394  $this->storeProperty("direction", $this->getOrderDirection());
1395  }
1396 //echo "-".$this->getOffset()."-";
1397  if ($this->getOffset() !== "")
1398  {
1399  $this->storeProperty("offset", $this->getOffset());
1400  }
1401  }
1402 
1403 
1407  final public function getHTML()
1408  {
1409  global $lng, $ilCtrl, $ilUser;
1410 
1411  if($this->getExportMode())
1412  {
1413  $this->exportData($this->getExportMode(), true);
1414  }
1415 
1416  $this->prepareOutput();
1417 
1418  if (is_object($ilCtrl) && $this->getId() == "")
1419  {
1420  $ilCtrl->saveParameter($this->getParentObject(), $this->getNavParameter());
1421  }
1422 
1423  if(!$this->enabled['content'])
1424  {
1425  return $this->render();
1426  }
1427 
1428  if (!$this->getExternalSegmentation())
1429  {
1430  $this->setMaxCount(count($this->row_data));
1431  }
1432 
1433  $this->determineOffsetAndOrder();
1434 
1435  $this->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
1436 
1437  $data = $this->getData();
1438  if($this->dataExists())
1439  {
1440  // sort
1441  if (!$this->getExternalSorting())
1442  {
1443  $data = ilUtil::sortArray($data, $this->getOrderField(),
1444  $this->getOrderDirection(), $this->numericOrdering($this->getOrderField()));
1445  }
1446 
1447  // slice
1448  if (!$this->getExternalSegmentation())
1449  {
1450  $data = array_slice($data, $this->getOffset(), $this->getLimit());
1451  }
1452  }
1453 
1454  // fill rows
1455  if($this->dataExists())
1456  {
1457  if($this->getPrintMode())
1458  {
1460  }
1461 
1462  $this->tpl->addBlockFile("TBL_CONTENT", "tbl_content", $this->row_template,
1463  $this->row_template_dir);
1464 
1465  foreach($data as $set)
1466  {
1467  $this->tpl->setCurrentBlock("tbl_content");
1468  $this->css_row = ($this->css_row != "tblrow1")
1469  ? "tblrow1"
1470  : "tblrow2";
1471  $this->tpl->setVariable("CSS_ROW", $this->css_row);
1472 
1473  $this->fillRow($set);
1474  $this->tpl->setCurrentBlock("tbl_content");
1475  $this->tpl->parseCurrentBlock();
1476  }
1477  }
1478  else
1479  {
1480  // add standard no items text (please tell me, if it messes something up, alex, 29.8.2008)
1481  $no_items_text = (trim($this->getNoEntriesText()) != '')
1482  ? $this->getNoEntriesText()
1483  : $lng->txt("no_items");
1484 
1485  $this->css_row = ($this->css_row != "tblrow1")
1486  ? "tblrow1"
1487  : "tblrow2";
1488 
1489  $this->tpl->setCurrentBlock("tbl_no_entries");
1490  $this->tpl->setVariable('TBL_NO_ENTRY_CSS_ROW', $this->css_row);
1491  $this->tpl->setVariable('TBL_NO_ENTRY_COLUMN_COUNT', $this->column_count);
1492  $this->tpl->setVariable('TBL_NO_ENTRY_TEXT', trim($no_items_text));
1493  $this->tpl->parseCurrentBlock();
1494  }
1495 
1496 
1497  if(!$this->getPrintMode())
1498  {
1499  // set form action
1500  if ($this->form_action != "")
1501  {
1502  $hash = "";
1503  if (is_object($ilUser) && $ilUser->getPref("screen_reader_optimization"))
1504  {
1505  $hash = "#".$this->getTopAnchor();
1506  }
1507 
1508  $this->tpl->setCurrentBlock("tbl_form_header");
1509  $this->tpl->setVariable("FORMACTION", $this->getFormAction().$hash);
1510  $this->tpl->setVariable("FORMNAME", $this->getFormName());
1511  $this->tpl->parseCurrentBlock();
1512  $this->tpl->touchBlock("tbl_form_footer");
1513  }
1514 
1515  $this->fillFooter();
1516 
1517  $this->fillHiddenRow();
1518 
1519  $this->fillActionRow();
1520 
1521  $this->storeNavParameter();
1522  }
1523 
1524  return $this->render();
1525  }
1526 
1532  function numericOrdering($a_field)
1533  {
1534  return false;
1535  }
1536 
1541  function render()
1542  {
1543  global $lng, $ilCtrl;
1544 
1545  $this->tpl->setVariable("CSS_TABLE",$this->getStyle("table"));
1546  $this->tpl->setVariable("DATA_TABLE", (int) $this->getIsDataTable());
1547  if ($this->getId() != "")
1548  {
1549  $this->tpl->setVariable("ID", 'id="'.$this->getId().'"');
1550  }
1551 
1552  // description
1553  if ($this->getDescription() != "")
1554  {
1555  $this->tpl->setCurrentBlock("tbl_header_description");
1556  $this->tpl->setVariable("TBL_DESCRIPTION", $this->getDescription());
1557  $this->tpl->parseCurrentBlock();
1558  }
1559 
1560  if(!$this->getPrintMode())
1561  {
1562  $this->renderFilter();
1563  }
1564 
1565  if ($this->getDisplayAsBlock())
1566  {
1567  $this->tpl->touchBlock("outer_start_1");
1568  $this->tpl->touchBlock("outer_end_1");
1569  }
1570  else
1571  {
1572  $this->tpl->touchBlock("outer_start_2");
1573  $this->tpl->touchBlock("outer_end_2");
1574  }
1575 
1576  // table title and icon
1577  if ($this->enabled["title"] && ($this->title != ""
1578  || $this->icon != "" || count($this->header_commands) > 0 ||
1579  $this->headerHTML != "" || $this->close_command != ""))
1580  {
1581  if ($this->enabled["icon"])
1582  {
1583  $this->tpl->setCurrentBlock("tbl_header_title_icon");
1584  $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath($this->icon));
1585  $this->tpl->setVariable("TBL_TITLE_IMG_ALT",$this->icon_alt);
1586  $this->tpl->parseCurrentBlock();
1587  }
1588 
1589  if(!$this->getPrintMode())
1590  {
1591  foreach($this->header_commands as $command)
1592  {
1593  if ($command["img"] != "")
1594  {
1595  $this->tpl->setCurrentBlock("tbl_header_img_link");
1596  if ($command["target"] != "")
1597  {
1598  $this->tpl->setVariable("TARGET_IMG_LINK",
1599  'target="'.$command["target"].'"');
1600  }
1601  $this->tpl->setVariable("ALT_IMG_LINK", $command["text"]);
1602  $this->tpl->setVariable("HREF_IMG_LINK", $command["href"]);
1603  $this->tpl->setVariable("SRC_IMG_LINK",
1604  $command["img"]);
1605  $this->tpl->parseCurrentBlock();
1606  }
1607  else
1608  {
1609  $this->tpl->setCurrentBlock("head_cmd");
1610  $this->tpl->setVariable("TXT_HEAD_CMD", $command["text"]);
1611  $this->tpl->setVariable("HREF_HEAD_CMD", $command["href"]);
1612  $this->tpl->parseCurrentBlock();
1613  }
1614  }
1615  }
1616 
1617  if (isset ($this->headerHTML)) {
1618  $this->tpl->setCurrentBlock("tbl_header_html");
1619  $this->tpl->setVariable ("HEADER_HTML", $this->headerHTML);
1620  $this->tpl->parseCurrentBlock();
1621  }
1622 
1623  // close command
1624  if ($this->close_command != "")
1625  {
1626  $this->tpl->setCurrentBlock("tbl_header_img_link");
1627  $this->tpl->setVariable("ALT_IMG_LINK",$lng->txt("close"));
1628  $this->tpl->setVariable("HREF_IMG_LINK",$this->close_command);
1629  $this->tpl->setVariable("SRC_IMG_LINK",ilUtil::getImagePath("icon_close2.gif"));
1630  $this->tpl->parseCurrentBlock();
1631  }
1632 
1633  $this->tpl->setCurrentBlock("tbl_header_title");
1634  $this->tpl->setVariable("TBL_TITLE",$this->title);
1635  $this->tpl->setVariable("TOP_ANCHOR",$this->getTopAnchor());
1636  if ($this->getDisplayAsBlock())
1637  {
1638  $this->tpl->setVariable("BLK_CLASS", "Block");
1639  }
1640  $this->tpl->parseCurrentBlock();
1641  }
1642 
1643  // table header
1644  if ($this->enabled["header"])
1645  {
1646  $this->fillHeader();
1647  }
1648 
1649  $this->tpl->touchBlock("tbl_table_end");
1650 
1651  return $this->tpl->get();
1652  }
1653 
1657  private function renderFilter()
1658  {
1659  global $lng, $tpl;
1660 
1661  $filter = $this->getFilterItems();
1662  $opt_filter = $this->getFilterItems(true);
1663 
1664  $tpl->addJavascript("./Services/Table/js/ServiceTable.js");
1665 
1666  if (count($filter) == 0 && count($opt_filter) == 0)
1667  {
1668  return;
1669  }
1670 
1671  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
1673 
1674  $ccnt = 0;
1675 
1676  // render standard filter
1677  if (count($filter) > 0)
1678  {
1679  foreach ($filter as $item)
1680  {
1681  if ($ccnt >= $this->getFilterCols())
1682  {
1683  $this->tpl->setCurrentBlock("filter_row");
1684  $this->tpl->parseCurrentBlock();
1685  $ccnt = 0;
1686  }
1687  $this->tpl->setCurrentBlock("filter_item");
1688  $this->tpl->setVariable("OPTION_NAME",
1689  $item->getTitle());
1690  $this->tpl->setVariable("F_INPUT_ID",
1691  $item->getFieldId());
1692  $this->tpl->setVariable("INPUT_HTML",
1693  $item->getTableFilterHTML());
1694  $this->tpl->parseCurrentBlock();
1695  $ccnt++;
1696  }
1697  }
1698 
1699  // render optional filter
1700  if (count($opt_filter) > 0)
1701  {
1702  $this->determineSelectedFilters();
1703 
1704  foreach ($opt_filter as $item)
1705  {
1706  if($this->isFilterSelected($item->getPostVar()))
1707  {
1708  if ($ccnt >= $this->getFilterCols())
1709  {
1710  $this->tpl->setCurrentBlock("filter_row");
1711  $this->tpl->parseCurrentBlock();
1712  $ccnt = 0;
1713  }
1714  $this->tpl->setCurrentBlock("filter_item");
1715  $this->tpl->setVariable("OPTION_NAME",
1716  $item->getTitle());
1717  $this->tpl->setVariable("F_INPUT_ID",
1718  $item->getFieldId());
1719  $this->tpl->setVariable("INPUT_HTML",
1720  $item->getTableFilterHTML());
1721  $this->tpl->parseCurrentBlock();
1722  $ccnt++;
1723  }
1724  }
1725 
1726  // filter selection
1727  $items = array();
1728  foreach ($opt_filter as $item)
1729  {
1730  $k = $item->getPostVar();
1731  $items[$k] = array("txt" => $item->getTitle(),
1732  "selected" => $this->isFilterSelected($k));
1733  }
1734 
1735  include_once("./Services/UIComponent/CheckboxListOverlay/classes/class.ilCheckboxListOverlayGUI.php");
1736  $cb_over = new ilCheckboxListOverlayGUI("tbl_filters_".$this->getId());
1737  $cb_over->setLinkTitle($lng->txt("optional_filters"));
1738  $cb_over->setItems($items);
1739 
1740  $cb_over->setFormCmd($this->getParentCmd());
1741  $cb_over->setFieldVar("tblff".$this->getId());
1742  $cb_over->setHiddenVar("tblfsf".$this->getId());
1743 
1744  $cb_over->setSelectionHeaderClass("ilTableMenuItem");
1745  $this->tpl->setCurrentBlock("filter_select");
1746 
1747  // apply should be the first submit because of enter/return, inserting hidden submit
1748  $this->tpl->setVariable("HIDDEN_CMD_APPLY", $this->filter_cmd);
1749 
1750  $this->tpl->setVariable("FILTER_SELECTOR", $cb_over->getHTML());
1751  $this->tpl->parseCurrentBlock();
1752  }
1753 
1754  // if any filter
1755  if($ccnt > 0 || count($opt_filter) > 0)
1756  {
1757  $this->tpl->setVariable("TXT_FILTER", $lng->txt("filter"));
1758 
1759  if($ccnt > 0)
1760  {
1761  if ($ccnt < $this->getFilterCols())
1762  {
1763  for($i = $ccnt; $i<=$this->getFilterCols(); $i++)
1764  {
1765  $this->tpl->touchBlock("filter_empty_cell");
1766  }
1767  }
1768  $this->tpl->setCurrentBlock("filter_row");
1769  $this->tpl->parseCurrentBlock();
1770 
1771  $this->tpl->setCurrentBlock("filter_buttons");
1772  $this->tpl->setVariable("CMD_APPLY", $this->filter_cmd);
1773  $this->tpl->setVariable("TXT_APPLY", $lng->txt("apply_filter"));
1774  $this->tpl->setVariable("CMD_RESET", $this->reset_cmd);
1775  $this->tpl->setVariable("TXT_RESET", $lng->txt("reset_filter"));
1776  }
1777  else if(count($opt_filter) > 0)
1778  {
1779  $this->tpl->setCurrentBlock("optional_filter_hint");
1780  $this->tpl->setVariable('TXT_OPT_HINT', $lng->txt('optional_filter_hint'));
1781  $this->tpl->parseCurrentBlock();
1782  }
1783 
1784  $this->tpl->setCurrentBlock("filter_section");
1785  $this->tpl->setVariable("FIL_ID", $this->getId());
1786  $this->tpl->parseCurrentBlock();
1787 
1788  // (keep) filter hidden?
1789  if ($this->loadProperty("filter") != 1)
1790  {
1791  if (!$this->getDisableFilterHiding())
1792  {
1793  $this->tpl->setCurrentBlock("filter_hidden");
1794  $this->tpl->setVariable("FI_ID", $this->getId());
1795  $this->tpl->parseCurrentBlock();
1796  }
1797  }
1798  }
1799  }
1800 
1804  public function writeFilterToSession()
1805  {
1806  global $lng;
1807 
1808  $filter = $this->getFilterItems();
1809  $opt_filter = $this->getFilterItems(true);
1810 
1811  foreach ($filter as $item)
1812  {
1813  if ($item->checkInput())
1814  {
1815  $item->setValueByArray($_POST);
1816  $item->writeToSession();
1817  }
1818  }
1819  foreach ($opt_filter as $item)
1820  {
1821  if ($item->checkInput())
1822  {
1823  $item->setValueByArray($_POST);
1824  $item->writeToSession();
1825  }
1826  }
1827  }
1828 
1832  public function resetFilter()
1833  {
1834  global $lng;
1835 
1836  $filter = $this->getFilterItems();
1837  $opt_filter = $this->getFilterItems(true);
1838 
1839  foreach ($filter as $item)
1840  {
1841  if ($item->checkInput())
1842  {
1843  $item->setValueByArray($_POST);
1844  $item->clearFromSession();
1845  }
1846  }
1847  foreach ($opt_filter as $item)
1848  {
1849  if ($item->checkInput())
1850  {
1851  $item->setValueByArray($_POST);
1852  $item->clearFromSession();
1853  }
1854  }
1855  }
1856 
1863  protected function fillRow($a_set)
1864  {
1865  foreach ($a_set as $key => $value)
1866  {
1867  $this->tpl->setVariable("VAL_".strtoupper($key), $value);
1868  }
1869  }
1870 
1874  function fillFooter()
1875  {
1876  global $lng, $ilCtrl, $ilUser;
1877 
1878  $footer = false;
1879 
1880  // select all checkbox
1881  if ((strlen($this->getFormName())) && (strlen($this->getSelectAllCheckbox())) && $this->dataExists())
1882  {
1883  $this->tpl->setCurrentBlock("select_all_checkbox");
1884  $this->tpl->setVariable("SELECT_ALL_TXT_SELECT_ALL", $lng->txt("select_all"));
1885  $this->tpl->setVariable("SELECT_ALL_CHECKBOX_NAME", $this->getSelectAllCheckbox());
1886  $this->tpl->setVariable("SELECT_ALL_FORM_NAME", $this->getFormName());
1887  $this->tpl->setVariable("CHECKBOXNAME", "chb_select_all_" . $this->unique_id);
1888  $this->tpl->parseCurrentBlock();
1889  }
1890 
1891  // table footer numinfo
1892  if ($this->enabled["numinfo"] && $this->enabled["footer"])
1893  {
1894  $start = $this->offset + 1; // compute num info
1895  if (!$this->dataExists())
1896  {
1897  $start = 0;
1898  }
1899  $end = $this->offset + $this->limit;
1900 
1901  if ($end > $this->max_count or $this->limit == 0)
1902  {
1903  $end = $this->max_count;
1904  }
1905 
1906  if ($this->max_count > 0)
1907  {
1908  if ($this->lang_support)
1909  {
1910  $numinfo = "(".$start." - ".$end." ".strtolower($this->lng->txt("of"))." ".$this->max_count.")";
1911  }
1912  else
1913  {
1914  $numinfo = "(".$start." - ".$end." of ".$this->max_count.")";
1915  }
1916  }
1917  if ($this->max_count > 0)
1918  {
1919  if ($this->getEnableNumInfo())
1920  {
1921  $this->tpl->setCurrentBlock("tbl_footer_numinfo");
1922  $this->tpl->setVariable("NUMINFO", $numinfo);
1923  $this->tpl->parseCurrentBlock();
1924  }
1925  }
1926  $footer = true;
1927  }
1928 
1929  // table footer linkbar
1930  if ($this->enabled["linkbar"] && $this->enabled["footer"] && $this->limit != 0
1931  && $this->max_count > 0)
1932  {
1933  $layout = array(
1934  "link" => $this->footer_style,
1935  "prev" => $this->footer_previous,
1936  "next" => $this->footer_next,
1937  );
1938  if (!$this->getDisplayAsBlock())
1939  {
1940  $linkbar = $this->getLinkbar("1");
1941  $this->tpl->setCurrentBlock("tbl_footer_linkbar");
1942  $this->tpl->setVariable("LINKBAR", $linkbar);
1943  $this->tpl->parseCurrentBlock();
1944  $linkbar = true;
1945  }
1946  $footer = true;
1947  }
1948 
1949  // column selector
1950  if (count($this->getSelectableColumns()) > 0)
1951  {
1952  $items = array();
1953  foreach ($this->getSelectableColumns() as $k => $c)
1954  {
1955  $items[$k] = array("txt" => $c["txt"],
1956  "selected" => $this->isColumnSelected($k));
1957  }
1958  include_once("./Services/UIComponent/CheckboxListOverlay/classes/class.ilCheckboxListOverlayGUI.php");
1959  $cb_over = new ilCheckboxListOverlayGUI("tbl_".$this->getId());
1960  $cb_over->setLinkTitle($lng->txt("columns"));
1961  $cb_over->setItems($items);
1962  //$cb_over->setUrl("./ilias.php?baseClass=ilTablePropertiesStorage&table_id=".
1963  // $this->getId()."&cmd=saveSelectedFields&user_id=".$ilUser->getId());
1964  $cb_over->setFormCmd($this->getParentCmd());
1965  $cb_over->setFieldVar("tblfs".$this->getId());
1966  $cb_over->setHiddenVar("tblfsh".$this->getId());
1967  $cb_over->setSelectionHeaderClass("ilTableMenuItem");
1968  $column_selector = $cb_over->getHTML();
1969  $footer = true;
1970  }
1971 
1972  if($this->getShowTemplates() && is_object($ilUser))
1973  {
1974  // template handling
1975  if(isset($_REQUEST["tbltplcrt"]) && $_REQUEST["tbltplcrt"])
1976  {
1977  if($this->saveTemplate($_REQUEST["tbltplcrt"]))
1978  {
1979  ilUtil::sendSuccess($lng->txt("tbl_template_created"));
1980  }
1981  }
1982  else if(isset($_REQUEST["tbltpldel"]) && $_REQUEST["tbltpldel"])
1983  {
1984  if($this->deleteTemplate($_REQUEST["tbltpldel"]))
1985  {
1986  ilUtil::sendSuccess($lng->txt("tbl_template_deleted"));
1987  }
1988  }
1989 
1990  $create_id = "template_create_overlay_".$this->getId();
1991  $delete_id = "template_delete_overlay_".$this->getId();
1992  $list_id = "template_stg_".$this->getId();
1993 
1994  include_once("./Services/Table/classes/class.ilTableTemplatesStorage.php");
1995  $storage = new ilTableTemplatesStorage();
1996  $templates = $storage->getNames($this->getContext(), $ilUser->getId());
1997 
1998  include_once("./Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php");
1999 
2000  // form to delete template
2001  if(sizeof($templates))
2002  {
2003  $overlay = new ilOverlayGUI($delete_id);
2004  $overlay->setTrigger($list_id."_delete");
2005  $overlay->setAnchor("ilAdvSelListAnchorElement_".$list_id);
2006  $overlay->setAutoHide(false);
2007  $overlay->add();
2008 
2009  $this->tpl->setCurrentBlock("template_editor_delete_item");
2010  $this->tpl->setVariable("TEMPLATE_DELETE_OPTION", "");
2011  $this->tpl->parseCurrentBlock();
2012  foreach($templates as $name)
2013  {
2014  $this->tpl->setVariable("TEMPLATE_DELETE_OPTION", $name);
2015  $this->tpl->parseCurrentBlock();
2016  }
2017 
2018  $this->tpl->setCurrentBlock("template_editor_delete");
2019  $this->tpl->setVariable("TEMPLATE_DELETE_ID", $delete_id);
2020  $this->tpl->setVariable("TXT_TEMPLATE_DELETE", $lng->txt("tbl_template_delete"));
2021  $this->tpl->setVariable("TXT_TEMPLATE_DELETE_SUBMIT", $lng->txt("delete"));
2022  $this->tpl->setVariable("TEMPLATE_DELETE_CMD", $this->parent_cmd);
2023  $this->tpl->parseCurrentBlock();
2024  }
2025 
2026 
2027  // form to save new template
2028  $overlay = new ilOverlayGUI($create_id);
2029  $overlay->setTrigger($list_id."_create");
2030  $overlay->setAnchor("ilAdvSelListAnchorElement_".$list_id);
2031  $overlay->setAutoHide(false);
2032  $overlay->add();
2033 
2034  $this->tpl->setCurrentBlock("template_editor");
2035  $this->tpl->setVariable("TEMPLATE_CREATE_ID", $create_id);
2036  $this->tpl->setVariable("TXT_TEMPLATE_CREATE", $lng->txt("tbl_template_create"));
2037  $this->tpl->setVariable("TXT_TEMPLATE_CREATE_SUBMIT", $lng->txt("save"));
2038  $this->tpl->setVariable("TEMPLATE_CREATE_CMD", $this->parent_cmd);
2039  $this->tpl->parseCurrentBlock();
2040 
2041  // load saved template
2042  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
2043  $alist = new ilAdvancedSelectionListGUI();
2044  $alist->setId($list_id);
2045  $alist->addItem($lng->txt("tbl_template_create"), "create", "#");
2046  if(sizeof($templates))
2047  {
2048  $alist->addItem($lng->txt("tbl_template_delete"), "delete", "#");
2049  foreach($templates as $name)
2050  {
2051  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_tpl", $name);
2052  $alist->addItem($name, $name, $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd));
2053  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_tpl", "");
2054  }
2055  }
2056  $alist->setListTitle($lng->txt("tbl_templates"));
2057  $this->tpl->setVariable("TEMPLATE_SELECTOR", "&nbsp;".$alist->getHTML());
2058  }
2059 
2060  if ($footer)
2061  {
2062  $this->tpl->setCurrentBlock("tbl_footer");
2063  $this->tpl->setVariable("COLUMN_COUNT", $this->getColumnCount());
2064  if ($this->getDisplayAsBlock())
2065  {
2066  $this->tpl->setVariable("BLK_CLASS", "Block");
2067  }
2068  $this->tpl->parseCurrentBlock();
2069 
2070  // top navigation, if number info or linkbar given
2071  if ($numinfo != "" || $linkbar != "" || $column_selector != "" ||
2072  count($this->filters) > 0 || count($this->optional_filters) > 0)
2073  {
2074  if (is_object($ilUser) && (count($this->filters) || count($this->optional_filters)))
2075  {
2076  $this->tpl->setCurrentBlock("filter_activation");
2077  $this->tpl->setVariable("TXT_ACTIVATE_FILTER", $lng->txt("show_filter"));
2078  $this->tpl->setVariable("FILA_ID", $this->getId());
2079  if ($this->getId() != "")
2080  {
2081  $this->tpl->setVariable("SAVE_URLA", "./ilias.php?baseClass=ilTablePropertiesStorage&table_id=".
2082  $this->getId()."&cmd=showFilter&user_id=".$ilUser->getId());
2083  }
2084  $this->tpl->parseCurrentBlock();
2085 
2086 
2087  if (!$this->getDisableFilterHiding())
2088  {
2089  $this->tpl->setCurrentBlock("filter_deactivation");
2090  $this->tpl->setVariable("TXT_HIDE", $lng->txt("hide_filter"));
2091  if ($this->getId() != "")
2092  {
2093  $this->tpl->setVariable("SAVE_URL", "./ilias.php?baseClass=ilTablePropertiesStorage&table_id=".
2094  $this->getId()."&cmd=hideFilter&user_id=".$ilUser->getId());
2095  $this->tpl->setVariable("FILD_ID", $this->getId());
2096  }
2097  $this->tpl->parseCurrentBlock();
2098  }
2099 
2100  }
2101 
2102  if ($numinfo != "" && $this->getEnableNumInfo())
2103  {
2104  $this->tpl->setCurrentBlock("top_numinfo");
2105  $this->tpl->setVariable("NUMINFO", $numinfo);
2106  $this->tpl->parseCurrentBlock();
2107  }
2108  if ($linkbar != "")
2109  {
2110  $linkbar = $this->getLinkbar("2");
2111  $this->tpl->setCurrentBlock("top_linkbar");
2112  $this->tpl->setVariable("LINKBAR", $linkbar);
2113  $this->tpl->parseCurrentBlock();
2114  }
2115 
2116  // column selector
2117  $this->tpl->setVariable("COLUMN_SELECTOR", $column_selector);
2118 
2119  // row selector
2120  if ($this->getShowRowsSelector() && is_object($ilUser))
2121  {
2122  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
2123  $alist = new ilAdvancedSelectionListGUI();
2124  $alist->setId("sellst_rows");
2125  $hpp = ($ilUser->getPref("hits_per_page") != 9999)
2126  ? $ilUser->getPref("hits_per_page")
2127  : $lng->txt("unlimited");
2128 
2129  $options = array(0 => $lng->txt("default")." (".$hpp.")",5 => 5, 10 => 10, 15 => 15, 20 => 20,
2130  30 => 30, 40 => 40, 50 => 50,
2131  100 => 100, 200 => 200, 400 => 400, 800 => 800);
2132  foreach ($options as $k => $v)
2133  {
2134  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_trows", $k);
2135  $alist->addItem($v, $k, $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd));
2136  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_trows", "");
2137  }
2138  $alist->setListTitle($lng->txt("rows"));
2139  $this->tpl->setVariable("ROW_SELECTOR", $alist->getHTML());
2140  }
2141 
2142  // export
2143  if(sizeof($this->export_formats))
2144  {
2145  $map = array(self::EXPORT_EXCEL => "tbl_export_excel",
2146  self::EXPORT_CSV => "tbl_export_csv");
2147  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
2148  $alist = new ilAdvancedSelectionListGUI();
2149  $alist->setId("sellst_xpt");
2150  foreach($this->export_formats as $format)
2151  {
2152  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_xpt", $format);
2153  $url = $ilCtrl->getLinkTarget($this->parent_obj, $this->parent_cmd);
2154  $ilCtrl->setParameter($this->parent_obj, $this->prefix."_xpt", "");
2155  $alist->addItem($lng->txt($map[$format]), $format, $url);
2156  }
2157  $alist->setListTitle($lng->txt("export"));
2158  $this->tpl->setVariable("EXPORT_SELECTOR", "&nbsp;".$alist->getHTML());
2159  }
2160 
2161  $this->tpl->setCurrentBlock("top_navigation");
2162  $this->tpl->setVariable("COLUMN_COUNT", $this->getColumnCount());
2163  if ($this->getDisplayAsBlock())
2164  {
2165  $this->tpl->setVariable("BLK_CLASS", "Block");
2166  }
2167  $this->tpl->parseCurrentBlock();
2168  }
2169  }
2170  }
2171 
2179  function getLinkbar($a_num)
2180  {
2181  global $ilCtrl, $lng, $ilUser;
2182 
2183  $hash = "";
2184  if (is_object($ilUser) && $ilUser->getPref("screen_reader_optimization"))
2185  {
2186  $hash = "#".$this->getTopAnchor();
2187  }
2188 
2189  $link = $ilCtrl->getLinkTargetByClass(get_class($this->parent_obj), $this->parent_cmd).
2190  "&".$this->getNavParameter()."=".
2191  $this->getOrderField().":".$this->getOrderDirection().":";
2192 
2193  $LinkBar = "";
2194  $layout_prev = $lng->txt("previous");
2195  $layout_next = $lng->txt("next");
2196 
2197  // if more entries then entries per page -> show link bar
2198  if ($this->max_count > $this->getLimit() || $this->custom_prev_next)
2199  {
2200  $sep = "<span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>";
2201 
2202  // calculate number of pages
2203  $pages = intval($this->max_count / $this->getLimit());
2204 
2205  // add a page if a rest remains
2206  if (($this->max_count % $this->getLimit()))
2207  $pages++;
2208 
2209  // links to other pages
2210  $offset_arr = array();
2211  for ($i = 1 ;$i <= $pages ; $i++)
2212  {
2213  $newoffset = $this->getLimit() * ($i-1);
2214 
2215  $nav_value = $this->getOrderField().":".$this->getOrderDirection().":".$newoffset;
2216  $offset_arr[$nav_value] = $i;
2217  }
2218 
2219  $sep = "<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
2220 
2221  // previous link
2222  if ($this->custom_prev_next && $this->custom_prev != "")
2223  {
2224  if ($LinkBar != "")
2225  $LinkBar .= $sep;
2226  $LinkBar .= "<a href=\"".$this->custom_prev.$hash."\">".$layout_prev."</a>";
2227  }
2228  else if ($this->getOffset() >= 1 && !$this->custom_prev_next)
2229  {
2230  if ($LinkBar != "")
2231  $LinkBar .= $sep;
2232  $prevoffset = $this->getOffset() - $this->getLimit();
2233  $LinkBar .= "<a href=\"".$link.$prevoffset.$hash."\">".$layout_prev."</a>";
2234  }
2235  else
2236  {
2237  if ($LinkBar != "")
2238  $LinkBar .= $sep;
2239  $LinkBar .= '<span class="ilTableFootLight">'.$layout_prev."</span>";
2240  }
2241 
2242  // current value
2243  if ($a_num == "1")
2244  {
2245  $LinkBar .= '<input type="hidden" name="'.$this->getNavParameter().
2246  '" value="'.$this->getOrderField().":".$this->getOrderDirection().":".$this->getOffset().'" />';
2247  }
2248 
2249  $sep = "<span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>";
2250 
2251  // show next link (if not last page)
2252  if ($this->custom_prev_next && $this->custom_next != "")
2253  {
2254  if ($LinkBar != "")
2255  $LinkBar .= $sep;
2256  $LinkBar .= "<a href=\"".$this->custom_next.$hash."\">".$layout_next."</a>";
2257  }
2258  else if (! ( ($this->getOffset() / $this->getLimit())==($pages-1) ) && ($pages!=1) &&
2259  !$this->custom_prev_next)
2260  {
2261  if ($LinkBar != "")
2262  $LinkBar .= $sep;
2263  $newoffset = $this->getOffset() + $this->getLimit();
2264  $LinkBar .= "<a href=\"".$link.$newoffset.$hash."\">".$layout_next."</a>";
2265  }
2266  else
2267  {
2268  if ($LinkBar != "")
2269  $LinkBar .= $sep;
2270  $LinkBar .= '<span class="ilTableFootLight">'.$layout_next."</span>";
2271  }
2272 
2273  $sep = "<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
2274 
2275  if (count($offset_arr) && !$this->getDisplayAsBlock() && !$this->custom_prev_next)
2276  {
2277  if ($LinkBar != "")
2278  $LinkBar .= $sep;
2279  $LinkBar .= "".
2280  '<label for="tab_page_sel_'.$a_num.'">'.$lng->txt("page").'</label> '.
2281  ilUtil::formSelect($this->nav_value,
2282  $this->getNavParameter().$a_num, $offset_arr, false, true, 0, "small",
2283  array("id" => "tab_page_sel_".$a_num,
2284  "onchange" => "ilTablePageSelection(this, 'cmd[".$this->parent_cmd."]')"));
2285  //' <input class="submit" type="submit" name="cmd['.$this->parent_cmd.']" value="'.
2286  //$lng->txt("ok").'" />';
2287  }
2288 
2289  return $LinkBar;
2290  }
2291  else
2292  {
2293  return false;
2294  }
2295  }
2296 
2297  function fillHiddenRow()
2298  {
2299  $hidden_row = false;
2300  if(count($this->hidden_inputs))
2301  {
2302  foreach ($this->hidden_inputs as $hidden_input)
2303  {
2304  $this->tpl->setCurrentBlock("tbl_hidden_field");
2305  $this->tpl->setVariable("FIELD_NAME", $hidden_input["name"]);
2306  $this->tpl->setVariable("FIELD_VALUE", $hidden_input["value"]);
2307  $this->tpl->parseCurrentBlock();
2308  }
2309 
2310  $this->tpl->setCurrentBlock("tbl_hidden_row");
2311  $this->tpl->parseCurrentBlock();
2312  }
2313  }
2314 
2318  function fillActionRow()
2319  {
2320  global $lng;
2321 
2322  // action row
2323  $action_row = false;
2324  $arrow = false;
2325 
2326  // add selection buttons
2327  if (count($this->sel_buttons) > 0)
2328  {
2329  foreach ($this->sel_buttons as $button)
2330  {
2331  $this->tpl->setCurrentBlock("sel_button");
2332  $this->tpl->setVariable("SBUTTON_SELECT",
2333  ilUtil::formSelect($button["selected"], $button["sel_var"],
2334  $button["options"], false, true));
2335  $this->tpl->setVariable("SBTN_NAME", $button["cmd"]);
2336  $this->tpl->setVariable("SBTN_VALUE", $button["text"]);
2337  $this->tpl->parseCurrentBlock();
2338 
2339  if ($this->getTopCommands())
2340  {
2341  $this->tpl->setCurrentBlock("sel_top_button");
2342  $this->tpl->setVariable("SBUTTON_SELECT",
2343  ilUtil::formSelect($button["selected"], $button["sel_var"],
2344  $button["options"], false, true));
2345  $this->tpl->setVariable("SBTN_NAME", $button["cmd"]);
2346  $this->tpl->setVariable("SBTN_VALUE", $button["text"]);
2347  $this->tpl->parseCurrentBlock();
2348  }
2349  }
2350  $buttons = true;
2351  $action_row = true;
2352  }
2353  $this->sel_buttons[] = array("options" => $a_options, "cmd" => $a_cmd, "text" => $a_text);
2354 
2355  // add buttons
2356  if (count($this->buttons) > 0)
2357  {
2358  foreach ($this->buttons as $button)
2359  {
2360  if (strlen($button['onclick']))
2361  {
2362  $this->tpl->setCurrentBlock('cmdonclick');
2363  $this->tpl->setVariable('CMD_ONCLICK', $button['onclick']);
2364  $this->tpl->parseCurrentBlock();
2365  }
2366  $this->tpl->setCurrentBlock("plain_button");
2367  $this->tpl->setVariable("PBTN_NAME", $button["cmd"]);
2368  $this->tpl->setVariable("PBTN_VALUE", $button["text"]);
2369  $this->tpl->parseCurrentBlock();
2370 
2371  if ($this->getTopCommands())
2372  {
2373  if (strlen($button['onclick']))
2374  {
2375  $this->tpl->setCurrentBlock('top_cmdonclick');
2376  $this->tpl->setVariable('CMD_ONCLICK', $button['onclick']);
2377  $this->tpl->parseCurrentBlock();
2378  }
2379  $this->tpl->setCurrentBlock("plain_top_button");
2380  $this->tpl->setVariable("PBTN_NAME", $button["cmd"]);
2381  $this->tpl->setVariable("PBTN_VALUE", $button["text"]);
2382  $this->tpl->parseCurrentBlock();
2383  }
2384  }
2385 
2386  $buttons = true;
2387  $action_row = true;
2388  }
2389 
2390  // multi selection
2391  if(count($this->mi_sel_buttons))
2392  {
2393  foreach ($this->mi_sel_buttons as $button)
2394  {
2395  $this->tpl->setCurrentBlock("mi_sel_button");
2396  $this->tpl->setVariable("MI_BUTTON_SELECT",
2397  ilUtil::formSelect($button["selected"], $button["sel_var"],
2398  $button["options"], false, true));
2399  $this->tpl->setVariable("MI_BTN_NAME", $button["cmd"]);
2400  $this->tpl->setVariable("MI_BTN_VALUE", $button["text"]);
2401  $this->tpl->parseCurrentBlock();
2402 
2403  if ($this->getTopCommands())
2404  {
2405  $this->tpl->setCurrentBlock("mi_top_sel_button");
2406  $this->tpl->setVariable("MI_BUTTON_SELECT",
2407  ilUtil::formSelect($button["selected"], $button["sel_var"]."_2",
2408  $button["options"], false, true));
2409  $this->tpl->setVariable("MI_BTN_NAME", $button["cmd"]);
2410  $this->tpl->setVariable("MI_BTN_VALUE", $button["text"]);
2411  $this->tpl->parseCurrentBlock();
2412  }
2413 
2414  }
2415  $arrow = true;
2416  $action_row = true;
2417  }
2418 
2419 
2420  if (count($this->multi) > 1 && $this->dataExists())
2421  {
2422  $this->tpl->setCurrentBlock("tbl_cmd_select");
2423  $sel = array();
2424  foreach ($this->multi as $mc)
2425  {
2426  $sel[$mc["cmd"]] = $mc["text"];
2427  }
2428  $this->tpl->setVariable("SELECT_CMDS",
2429  ilUtil::formSelect("", "selected_cmd", $sel, false, true));
2430  $this->tpl->setVariable("TXT_EXECUTE", $lng->txt("execute"));
2431  $this->tpl->parseCurrentBlock();
2432  $arrow = true;
2433  $action_row = true;
2434 
2435  if ($this->getTopCommands())
2436  {
2437  $this->tpl->setCurrentBlock("tbl_top_cmd_select");
2438  $sel = array();
2439  foreach ($this->multi as $mc)
2440  {
2441  $sel[$mc["cmd"]] = $mc["text"];
2442  }
2443  $this->tpl->setVariable("SELECT_CMDS",
2444  ilUtil::formSelect("", "selected_cmd2", $sel, false, true));
2445  $this->tpl->setVariable("TXT_EXECUTE", $lng->txt("execute"));
2446  $this->tpl->parseCurrentBlock();
2447  }
2448  }
2449  elseif(count($this->multi) == 1 && $this->dataExists())
2450  {
2451  $this->tpl->setCurrentBlock("tbl_single_cmd");
2452  $sel = array();
2453  foreach ($this->multi as $mc)
2454  {
2455  $cmd = $mc['cmd'];
2456  $txt = $mc['text'];
2457  }
2458  $this->tpl->setVariable("TXT_SINGLE_CMD",$txt);
2459  $this->tpl->setVariable("SINGLE_CMD",$cmd);
2460  $this->tpl->parseCurrentBlock();
2461  $arrow = true;
2462  $action_row = true;
2463 
2464  if ($this->getTopCommands())
2465  {
2466  $this->tpl->setCurrentBlock("tbl_top_single_cmd");
2467  $sel = array();
2468  foreach ($this->multi as $mc)
2469  {
2470  $cmd = $mc['cmd'];
2471  $txt = $mc['text'];
2472  }
2473  $this->tpl->setVariable("TXT_SINGLE_CMD",$txt);
2474  $this->tpl->setVariable("SINGLE_CMD",$cmd);
2475  $this->tpl->parseCurrentBlock();
2476  }
2477  }
2478 
2479  if ($arrow)
2480  {
2481  $this->tpl->setCurrentBlock("tbl_action_img_arrow");
2482  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
2483  $this->tpl->setVariable("ALT_ARROW", $lng->txt("action"));
2484  $this->tpl->parseCurrentBlock();
2485 
2486  if ($this->getTopCommands())
2487  {
2488  $this->tpl->setCurrentBlock("tbl_top_action_img_arrow");
2489  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_upright.gif"));
2490  $this->tpl->setVariable("ALT_ARROW", $lng->txt("action"));
2491  $this->tpl->parseCurrentBlock();
2492  }
2493  }
2494 
2495  if ($action_row)
2496  {
2497  $this->tpl->setCurrentBlock("tbl_action_row");
2498  $this->tpl->parseCurrentBlock();
2499  if ($this->getTopCommands())
2500  {
2501  $this->tpl->setCurrentBlock("tbl_top_action_row");
2502  $this->tpl->parseCurrentBlock();
2503  }
2504  }
2505  }
2506 
2512  public function setHeaderHTML($html)
2513  {
2514  $this->headerHTML = $html;
2515  }
2516 
2523  function storeProperty($type, $value)
2524  {
2525  global $ilUser;
2526 
2527  if(is_object($ilUser) && $this->getId() != "" && $ilUser->getId() != ANONYMOUS_USER_ID)
2528  {
2529  include_once("./Services/Table/classes/class.ilTablePropertiesStorage.php");
2530  $tab_prop = new ilTablePropertiesStorage();
2531 
2532  $tab_prop->storeProperty($this->getId(), $ilUser->getId(), $type, $value);
2533  }
2534  }
2535 
2543  {
2544  global $ilUser;
2545 
2546  if(is_object($ilUser) && $this->getId() != "" && $ilUser->getId() != ANONYMOUS_USER_ID)
2547  {
2548  include_once("./Services/Table/classes/class.ilTablePropertiesStorage.php");
2549  $tab_prop = new ilTablePropertiesStorage();
2550 
2551  return $tab_prop->getProperty($this->getId(), $ilUser->getId(), $type);
2552  }
2553  }
2554 
2560  public function getCurrentState()
2561  {
2562  $this->determineOffsetAndOrder();
2563  $this->determineLimit();
2564  $this->determineSelectedColumns();
2565  $this->determineSelectedFilters();
2566 
2567  // "filter" show/hide is not saved
2568 
2569  $result = array();
2570  $result["order"] = $this->getOrderField();
2571  $result["direction"] = $this->getOrderDirection();
2572  $result["offset"] = $this->getOffset();
2573  $result["rows"] = $this->getLimit();
2574  $result["selfields"] = $this->getSelectedColumns();
2575  $result["selfilters"] = $this->getSelectedFilters();
2576 
2577  // gather filter values
2578  if($this->filters)
2579  {
2580  foreach($this->filters as $item)
2581  {
2582  $result["filter_values"][$item->getFieldId()] = $this->getFilterValue($item);
2583  }
2584  }
2585  if($this->optional_filters && $result["selfilters"])
2586  {
2587  foreach($this->optional_filters as $item)
2588  {
2589  if(in_array($item->getFieldId(), $result["selfilters"]))
2590  {
2591  $result["filter_values"][$item->getFieldId()] = $this->getFilterValue($item);
2592  }
2593  }
2594  }
2595 
2596  return $result;
2597  }
2598 
2605  protected function getFilterValue(ilFormPropertyGUI $a_item)
2606  {
2607  if(method_exists($a_item, "getChecked"))
2608  {
2609  return $a_item->getChecked();
2610  }
2611  else if(method_exists($a_item, "getValue"))
2612  {
2613  return $a_item->getValue();
2614  }
2615  else if(method_exists($a_item, "getDate"))
2616  {
2617  return $a_item->getDate()->get(IL_CAL_DATE);
2618  }
2619  }
2620 
2627  protected function SetFilterValue(ilFormPropertyGUI $a_item, $a_value)
2628  {
2629  if(method_exists($a_item, "setChecked"))
2630  {
2631  $a_item->setChecked($a_value);
2632  }
2633  else if(method_exists($a_item, "setValue"))
2634  {
2635  $a_item->setValue($a_value);
2636  }
2637  else if(method_exists($a_item, "setDate"))
2638  {
2639  $a_item->setDate(new ilDate($a_value, IL_CAL_DATE));
2640  }
2641  $a_item->writeToSession();
2642  }
2643 
2649  public function setContext($id)
2650  {
2651  if(trim($id))
2652  {
2653  $this->context = $id;
2654  }
2655  }
2656 
2662  public function getContext()
2663  {
2664  return $this->context;
2665  }
2666 
2672  public function setShowRowsSelector($a_value)
2673  {
2674  $this->show_rows_selector = (bool)$a_value;
2675  }
2676 
2682  public function getShowRowsSelector()
2683  {
2685  }
2686 
2692  public function setShowTemplates($a_value)
2693  {
2694  $this->show_templates = (bool)$a_value;
2695  }
2696 
2702  public function getShowTemplates()
2703  {
2704  return $this->show_templates;
2705  }
2706 
2713  public function restoreTemplate($a_name)
2714  {
2715  global $ilUser;
2716 
2717  if(trim($a_name) && $this->getContext() != "" && is_object($ilUser) && $ilUser->getId() != ANONYMOUS_USER_ID)
2718  {
2719  include_once("./Services/Table/classes/class.ilTableTemplatesStorage.php");
2720  $storage = new ilTableTemplatesStorage();
2721 
2722  $data = $storage->load($this->getContext(), $ilUser->getId(), $a_name);
2723  if(is_array($data))
2724  {
2725  foreach($data as $property => $value)
2726  {
2727  $this->storeProperty($property, $value);
2728  }
2729  }
2730 
2731  $data["filter_values"] = unserialize($data["filter_values"]);
2732  if($data["filter_values"])
2733  {
2734  $this->restore_filter_values = $data["filter_values"];
2735  }
2736 
2737  return true;
2738  }
2739  return false;
2740  }
2741 
2748  public function saveTemplate($a_name)
2749  {
2750  global $ilUser;
2751 
2752  if(trim($a_name) && $this->getContext() != "" && is_object($ilUser) && $ilUser->getId() != ANONYMOUS_USER_ID)
2753  {
2754  include_once("./Services/Table/classes/class.ilTableTemplatesStorage.php");
2755  $storage = new ilTableTemplatesStorage();
2756 
2757  $state = $this->getCurrentState();
2758  $state["filter_values"] = serialize($state["filter_values"]);
2759  $state["selfields"] = serialize($state["selfields"]);
2760  $state["selfilters"] = serialize($state["selfilters"]);
2761 
2762  $storage->store($this->getContext(), $ilUser->getId(), $a_name, $state);
2763  return true;
2764  }
2765  return false;
2766  }
2767 
2774  public function deleteTemplate($a_name)
2775  {
2776  global $ilUser;
2777 
2778  if(trim($a_name) && $this->getContext() != "" && is_object($ilUser) && $ilUser->getId() != ANONYMOUS_USER_ID)
2779  {
2780  include_once("./Services/Table/classes/class.ilTableTemplatesStorage.php");
2781  $storage = new ilTableTemplatesStorage();
2782  $storage->delete($this->getContext(), $ilUser->getId(), $a_name);
2783  return true;
2784  }
2785  return false;
2786  }
2787 
2791  function getLimit()
2792  {
2793  if($this->getExportMode() || $this->getPrintMode())
2794  {
2795  return 9999;
2796  }
2797  return parent::getLimit();
2798  }
2799 
2803  function getOffset()
2804  {
2805  if($this->getExportMode() || $this->getPrintMode())
2806  {
2807  return 0;
2808  }
2809  return parent::getOffset();
2810  }
2811 
2817  public function setExportFormats(array $formats)
2818  {
2819  $this->export_formats = array();
2820  $valid = array(self::EXPORT_EXCEL, self::EXPORT_CSV);
2821  foreach($formats as $format)
2822  {
2823  if(in_array($format, $valid))
2824  {
2825  $this->export_formats[] = $format;
2826  }
2827  }
2828  }
2829 
2834  public function setPrintMode($a_value = false)
2835  {
2836  $this->print_mode = (bool)$a_value;
2837  }
2838 
2843  public function getPrintMode()
2844  {
2845  return $this->print_mode;
2846  }
2847 
2853  public function getExportMode()
2854  {
2855  return $this->export_mode;
2856  }
2857 
2863  public function exportData($format, $send = false)
2864  {
2865  if($this->dataExists())
2866  {
2867  $filename = "export";
2868 
2869  switch($format)
2870  {
2871  case self::EXPORT_EXCEL:
2872  include_once "./Services/Excel/classes/class.ilExcelUtils.php";
2873  include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php";
2874  $adapter = new ilExcelWriterAdapter($filename.".xls", $send);
2875  $workbook = $adapter->getWorkbook();
2876  $worksheet = $workbook->addWorksheet();
2877  $row = 0;
2878 
2879  ob_start();
2880  $this->fillMetaExcel($worksheet, $row);
2881  $this->fillHeaderExcel($worksheet, $row);
2882  foreach($this->row_data as $set)
2883  {
2884  $row++;
2885  $this->fillRowExcel($worksheet, $row, $set);
2886  }
2887  ob_end_clean();
2888 
2889  $workbook->close();
2890  break;
2891 
2892  case self::EXPORT_CSV:
2893  include_once "./Services/Utilities/classes/class.ilCSVWriter.php";
2894  $csv = new ilCSVWriter();
2895  $csv->setSeparator(";");
2896 
2897  ob_start();
2898  $this->fillMetaCSV($csv);
2899  $this->fillHeaderCSV($csv);
2900  foreach($this->row_data as $set)
2901  {
2902  $this->fillRowCSV($csv, $set);
2903  }
2904  ob_end_clean();
2905 
2906  if($send)
2907  {
2908  $filename .= ".csv";
2909  header("Content-type: text/comma-separated-values");
2910  header("Content-Disposition: attachment; filename=\"".$filename."\"");
2911  header("Expires: 0");
2912  header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
2913  header("Pragma: public");
2914  echo $csv->getCSVString();
2915 
2916  }
2917  else
2918  {
2919  file_put_contents($filename, $csv->getCSVString());
2920  }
2921  break;
2922  }
2923  }
2924 
2925  if($send)
2926  {
2927  exit();
2928  }
2929  }
2930 
2938  protected function fillMetaExcel($worksheet, &$a_row)
2939  {
2940 
2941  }
2942 
2950  protected function fillHeaderExcel($worksheet, &$a_row)
2951  {
2952  $col = 0;
2953  foreach ($this->column as $column)
2954  {
2955  $col++;
2956  $worksheet->write($a_row, $col, strip_tags($column["text"]));
2957  }
2958  $a_row++;
2959  }
2960 
2969  protected function fillRowExcel($a_worksheet, &$a_row, $a_set)
2970  {
2971  $col = 0;
2972  foreach ($a_set as $key => $value)
2973  {
2974  $col++;
2975  if(is_array($value))
2976  {
2977  $value = implode(', ', $value);
2978  }
2979  $a_worksheet->write($a_row, $col, strip_tags($value));
2980  }
2981  }
2982 
2989  protected function fillMetaCSV($a_csv)
2990  {
2991 
2992  }
2993 
3000  protected function fillHeaderCSV($a_csv)
3001  {
3002  foreach ($this->column as $column)
3003  {
3004  $a_csv->addColumn(strip_tags($column["text"]));
3005  }
3006  $a_csv->addRow();
3007  }
3008 
3016  protected function fillRowCSV($a_csv, $a_set)
3017  {
3018  foreach ($a_set as $key => $value)
3019  {
3020  if(is_array($value))
3021  {
3022  $value = implode(', ', $value);
3023  }
3024  $a_csv->addColumn(strip_tags($value));
3025  }
3026  $a_csv->addRow();
3027  }
3028 }
3029 
3030 ?>