ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPCTableGUI.php
Go to the documentation of this file.
1 <?php
2 
27 {
29  protected ilTabsGUI $tabs;
30  protected ilObjUser $user;
31  protected \ILIAS\GlobalScreen\ScreenContext\ContextServices $tool_context;
32 
33  public function __construct(
34  ilPageObject $a_pg_obj,
35  ?ilPageContent $a_content_obj,
36  string $a_hier_id,
37  string $a_pc_id = ""
38  ) {
39  global $DIC;
40 
41  $this->tabs = $DIC->tabs();
42  $this->ctrl = $DIC->ctrl();
43  $this->lng = $DIC->language();
44  $this->tpl = $DIC["tpl"];
45  $this->user = $DIC->user();
46  parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
47  $this->setCharacteristics(array("StandardTable" => $this->lng->txt("cont_StandardTable")));
48  $this->tool_context = $DIC->globalScreen()->tool()->context();
49  }
50 
51  public function setBasicTableCellStyles(): void
52  {
53  $this->setCharacteristics(array("Cell1" => "Cell1", "Cell2" => "Cell2",
54  "Cell3" => "Cell3", "Cell4" => "Cell4"));
55  }
56 
60  public function executeCommand()
61  {
62  $this->getCharacteristicsOfCurrentStyle(["table"]); // scorm-2004
63 
64  // get next class that processes or forwards current command
65  $next_class = $this->ctrl->getNextClass($this);
66 
67  // get current command
68  $cmd = $this->ctrl->getCmd();
69 
70  switch ($next_class) {
71  default:
72  $this->$cmd();
73  break;
74  }
75  return "";
76  }
77 
78  public function setTabs(
79  string $data_tab_txt_key = ""
80  ): void {
81  $ilTabs = $this->tabs;
82  $ilCtrl = $this->ctrl;
83  $lng = $this->lng;
84 
85  $ilTabs->setBackTarget(
86  $lng->txt("pg"),
87  (string) $this->ctrl->getParentReturn($this)
88  );
89 
90  if ($data_tab_txt_key == "") {
91  $data_tab_txt_key = "cont_table_edit_cells";
92  }
93 
94  $ilTabs->addTarget(
95  $data_tab_txt_key,
96  $ilCtrl->getLinkTarget($this, "editData"),
97  "editData",
98  get_class($this)
99  );
100 
101  $ilTabs->addTarget(
102  "cont_table_properties",
103  $ilCtrl->getLinkTarget($this, "editProperties"),
104  "editProperties",
105  get_class($this)
106  );
107 
108  $ilTabs->addTarget(
109  "cont_table_cell_properties",
110  $ilCtrl->getLinkTarget($this, "editCellStyle"),
111  "editCellStyle",
112  get_class($this)
113  );
114  }
115 
116  public function setCellPropertiesSubTabs(): void
117  {
118  $ilTabs = $this->tabs;
119  $ilCtrl = $this->ctrl;
120 
121  $ilTabs->addSubTabTarget(
122  "cont_style",
123  $ilCtrl->getLinkTarget($this, "editCellStyle"),
124  "editCellStyle",
125  get_class($this)
126  );
127 
128  $ilTabs->addSubTabTarget(
129  "cont_width",
130  $ilCtrl->getLinkTarget($this, "editCellWidth"),
131  "editCellWidth",
132  get_class($this)
133  );
134 
135  $ilTabs->addSubTabTarget(
136  "cont_alignment",
137  $ilCtrl->getLinkTarget($this, "editCellAlignment"),
138  "editCellAlignment",
139  get_class($this)
140  );
141 
142  $ilTabs->addSubTabTarget(
143  "cont_span",
144  $ilCtrl->getLinkTarget($this, "editCellSpan"),
145  "editCellSpan",
146  get_class($this)
147  );
148  }
149 
150  public function getTemplateOptions(string $a_type = ""): array
151  {
152  return parent::getTemplateOptions("table");
153  }
154 
155  public function edit(): void
156  {
157  $this->ctrl->redirect($this, "editData");
158  }
159 
160  public function editProperties(): void
161  {
162  $tpl = $this->tpl;
163 
164  $this->displayValidationError();
165  $this->setTabs();
166 
167  $this->initPropertiesForm();
168  $this->getPropertiesFormValues();
169  $html = $this->form->getHTML();
170  $html .= "<br />" . $this->renderTable("");
171  $tpl->setContent($html);
172  }
173 
174  protected function getFormTitle(string $a_mode = "edit"): string
175  {
176  if ($a_mode === "create") {
177  return $this->lng->txt("cont_insert_table");
178  }
179  return $this->lng->txt("cont_table_properties");
180  }
181 
182  public function initPropertiesForm(
183  string $a_mode = "edit"
184  ): void {
185  $a_seleted_value = "";
186  $ilCtrl = $this->ctrl;
187  $lng = $this->lng;
189 
190  $this->form = new ilPropertyFormGUI();
191  $this->form->setFormAction($ilCtrl->getFormAction($this));
192  $this->form->setTitle($this->getFormTitle($a_mode));
193 
194  if ($a_mode == "create") {
195  $nr = array();
196  for ($i = 1; $i <= 20; $i++) {
197  $nr[$i] = $i;
198  }
199 
200  // cols
201  $cols = new ilSelectInputGUI($this->lng->txt("cont_nr_cols"), "nr_cols");
202  $cols->setOptions($nr);
203  $cols->setValue(2);
204  $this->form->addItem($cols);
205 
206  // rows
207  $rows = new ilSelectInputGUI($this->lng->txt("cont_nr_rows"), "nr_rows");
208  $rows->setOptions($nr);
209  $rows->setValue(2);
210  $this->form->addItem($rows);
211  }
212 
213  // width
214  $width = new ilTextInputGUI($this->lng->txt("cont_table_width"), "width");
215  $width->setSize(6);
216  $width->setMaxLength(6);
217  $this->form->addItem($width);
218 
219  // border
220  $border = new ilTextInputGUI($this->lng->txt("cont_table_border"), "border");
221  $border->setInfo($this->lng->txt("cont_table_border_info"));
222  $border->setValue("1px");
223  $border->setSize(6);
224  $border->setMaxLength(6);
225  $this->form->addItem($border);
226 
227  // padding
228  $padding = new ilTextInputGUI($this->lng->txt("cont_table_cellpadding"), "padding");
229  $padding->setInfo($this->lng->txt("cont_table_cellpadding_info"));
230  $padding->setValue("2px");
231  $padding->setSize(6);
232  $padding->setMaxLength(6);
233  $this->form->addItem($padding);
234 
235  // spacing (deprecated, only hidden)
236  $spacing = new ilHiddenInputGUI("spacing");
237  $spacing->setValue("0px");
238  $this->form->addItem($spacing);
239 
240  // table templates and table classes
241  $char_prop = new ilAdvSelectInputGUI(
242  $this->lng->txt("cont_characteristic_table"),
243  "characteristic"
244  );
245  $chars = $this->getCharacteristics();
246  $templates = $this->getTemplateOptions();
247  $chars = array_merge($templates, $chars);
248  if (is_object($this->content_obj)) {
249  if (($chars[$a_seleted_value] ?? "") == "" && ($this->content_obj->getClass() != "")) {
250  $chars = array_merge(
251  array($this->content_obj->getClass() => $this->content_obj->getClass()),
252  $chars
253  );
254  }
255  }
256  foreach ($chars as $k => $char) {
257  if (strpos($k, ":") > 0) {
258  $t = explode(":", $k);
259  $html = $this->style->lookupTemplatePreview($t[1]) . '<div style="clear:both;" class="small">' . $char . "</div>";
260  } else {
261  $html = '<table class="ilc_table_' . $k . '"><tr><td class="small">' .
262  $char . '</td></tr></table>';
263  }
264  $char_prop->addOption($k, $char, $html);
265  }
266  $char_prop->setValue("StandardTable");
267  $this->form->addItem($char_prop);
268 
269  $nr = array();
270  for ($i = 0; $i <= 3; $i++) {
271  $nr[$i] = $i;
272  }
273 
274  // row header
275  $rh = new ilSelectInputGUI($this->lng->txt("cont_nr_row_header"), "row_header");
276  $rh->setOptions($nr);
277  $rh->setValue(1);
278  $this->form->addItem($rh);
279 
280  // row footer
281  $rf = new ilSelectInputGUI($this->lng->txt("cont_nr_row_footer"), "row_footer");
282  $rf->setOptions($nr);
283  $rf->setValue(0);
284  $this->form->addItem($rf);
285 
286  // col header
287  $ch = new ilSelectInputGUI($this->lng->txt("cont_nr_col_header"), "col_header");
288  $ch->setOptions($nr);
289  $ch->setValue(0);
290  $this->form->addItem($ch);
291 
292  // col footer
293  $cf = new ilSelectInputGUI($this->lng->txt("cont_nr_col_footer"), "col_footer");
294  $cf->setOptions($nr);
295  $cf->setValue(0);
296  $this->form->addItem($cf);
297 
298  if ($a_mode == "create") {
299  // first row style
300  $fr_style = new ilAdvSelectInputGUI(
301  $this->lng->txt("cont_first_row_style"),
302  "first_row_style"
303  );
304  $this->setBasicTableCellStyles();
305  $this->getCharacteristicsOfCurrentStyle(["table_cell"]);
306  $chars = $this->getCharacteristics();
307  $options = array_merge(array("" => $this->lng->txt("none")), $chars);
308  foreach ($options as $k => $option) {
309  $html = '<table border="0" cellspacing="0" cellpadding="0"><tr><td class="ilc_table_cell_' . $k . '">' .
310  $option . '</td></tr></table>';
311  $fr_style->addOption($k, $option, $html);
312  }
313 
314  $fr_style->setValue("");
315  $this->form->addItem($fr_style);
316  }
317 
318  // alignment
319  $align_opts = array("Left" => $lng->txt("cont_left"),
320  "Right" => $lng->txt("cont_right"), "Center" => $lng->txt("cont_center"),
321  "LeftFloat" => $lng->txt("cont_left_float"),
322  "RightFloat" => $lng->txt("cont_right_float"));
323  $align = new ilSelectInputGUI($this->lng->txt("cont_align"), "align");
324  $align->setOptions($align_opts);
325  $align->setValue("Center");
326  $this->form->addItem($align);
327 
328  // caption
329  $caption = new ilTextInputGUI($this->lng->txt("cont_caption"), "caption");
330  $caption->setSize(60);
331  $this->form->addItem($caption);
332 
333  // caption align
334  $ca_opts = array("top" => $lng->txt("cont_top"),
335  "bottom" => $lng->txt("cont_bottom"));
336  $ca = new ilSelectInputGUI(
337  $this->lng->txt("cont_align"),
338  "cap_align"
339  );
340  $ca->setOptions($ca_opts);
341  $caption->addSubItem($ca);
342 
343  // import
344  if ($a_mode == "create") {
345  // import table
346  $import = new ilRadioGroupInputGUI($this->lng->txt("cont_paste_table"), "import_type");
347  $op = new ilRadioOption($this->lng->txt("cont_html_table"), "html");
348  $import->addOption($op);
349  $op2 = new ilRadioOption($this->lng->txt("cont_spreadsheet_table"), "spreadsheet");
350 
351  $import_data = new ilTextAreaInputGUI("", "import_table");
352  $import_data->setRows(8);
353  $import_data->setCols(50);
354  $op2->addSubItem($import_data);
355 
356  $import->addOption($op2);
357  $import->setValue("html");
358  $this->form->addItem($import);
359  }
360 
361  // language
362  if ($this->getCurrentTextLang() != "") {
363  $s_lang = $this->getCurrentTextLang();
364  } else {
365  $s_lang = $ilUser->getLanguage();
366  }
368  $language = new ilSelectInputGUI($this->lng->txt("language"), "language");
369  $language->setOptions($lang);
370  $language->setValue($s_lang);
371  $this->form->addItem($language);
372 
373  if ($a_mode == "create") {
374  $this->form->addCommandButton("create_tab", $lng->txt("save"));
375  $this->form->addCommandButton("cancelCreate", $lng->txt("cancel"));
376  } else {
377  $this->form->addCommandButton("saveProperties", $lng->txt("save"));
378  }
379  }
380 
381  public function getPropertiesFormValues(): void
382  {
383  $values = array();
384  $values["width"] = $this->content_obj->getWidth();
385  $values["border"] = $this->content_obj->getBorder();
386  $values["padding"] = $this->content_obj->getCellPadding();
387  $values["spacing"] = $this->content_obj->getCellSpacing();
388  $values["row_header"] = $this->content_obj->getHeaderRows();
389  $values["row_footer"] = $this->content_obj->getFooterRows();
390  $values["col_header"] = $this->content_obj->getHeaderCols();
391  $values["col_footer"] = $this->content_obj->getFooterCols();
392  if ($this->content_obj->getTemplate() != "") {
393  $values["characteristic"] = "t:" .
394  ilObjStyleSheet::_lookupTemplateIdByName($this->getStyleId(), $this->content_obj->getTemplate()) . ":" .
395  $this->content_obj->getTemplate();
396  } else {
397  $values["characteristic"] = $this->content_obj->getClass();
398  }
399  $values["align"] = $this->content_obj->getHorizontalAlign();
400  $values["caption"] = $this->content_obj->getCaption();
401  $values["cap_align"] = $this->content_obj->getCaptionAlign();
402  $values["language"] = $this->content_obj->getLanguage();
403 
404  $this->form->setValuesByArray($values);
405 
406  $ca = $this->form->getItemByPostVar("cap_align");
407  $ca->setValue($this->content_obj->getCaptionAlign());
408  }
409 
410  public function renderTable(
411  string $a_mode = "table_edit",
412  string $a_submode = ""
413  ): string {
414  $template_xml = "";
415  $tab_node = $this->content_obj->getNode();
416  $tab_node->set_attribute("Enabled", "True");
417  $content = $this->dom->dump_node($tab_node);
418 
419  $trans = $this->pg_obj->getLanguageVariablesXML();
420  $mobs = $this->pg_obj->getMultimediaXML();
421  if ($this->getStyleId() > 0) {
422  if (ilObject::_lookupType($this->getStyleId()) == "sty") {
423  $style = new ilObjStyleSheet($this->getStyleId());
424  $template_xml = $style->getTemplateXML();
425  }
426  }
427 
428  $content = $content . $mobs . $trans . $template_xml;
429 
431  $tab = $this->content_obj;
433  $content,
434  $a_mode,
435  $a_submode,
436  $tab,
437  !$this->pg_obj->getPageConfig()->getPreventHTMLUnmasking(),
438  $this->getPage()
439  );
440  }
441 
442  public static function _renderTable(
443  string $content,
444  string $a_mode = "table_edit",
445  string $a_submode = "",
446  ilPCTable $a_table_obj = null,
447  bool $unmask = true,
448  ilPageObject $page_object = null
449  ): string {
450  global $DIC;
451 
452  $ilUser = $DIC->user();
453 
454  $content = "<dummy>" . $content . "</dummy>";
455 
456  $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
457  $args = array( '/_xml' => $content, '/_xsl' => $xsl );
458  $xh = xslt_create();
459  //echo "<b>XML</b>:".htmlentities($content).":<br>";
460  //echo "<b>XSLT</b>:".htmlentities($xsl).":<br>";
461  $wb_path = ilFileUtils::getWebspaceDir("output") . "/";
462  $enlarge_path = ilUtil::getImagePath("enlarge.svg");
463  $params = array('mode' => $a_mode,
464  'webspace_path' => $wb_path, 'enlarge_path' => $enlarge_path);
465  $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", null, $args, $params);
466  xslt_error($xh);
467  xslt_free($xh);
468 
469  // unmask user html
470  if ($unmask) {
471  $output = str_replace("&lt;", "<", $output);
472  $output = str_replace("&gt;", ">", $output);
473  $output = str_replace("&amp;", "&", $output);
474  }
475 
476  if ($a_mode == "table_edit" && !is_null($a_table_obj)) {
477  switch ($a_submode) {
478  case "style":
479  $output = ilPCTableGUI::_addStyleCheckboxes($output, $a_table_obj);
480  break;
481 
482  case "alignment":
483  $output = ilPCTableGUI::_addAlignmentCheckboxes($output, $a_table_obj);
484  break;
485 
486  case "width":
487  $output = ilPCTableGUI::_addWidthInputs($output, $a_table_obj);
488  break;
489 
490  case "span":
491  $output = ilPCTableGUI::_addSpanInputs($output, $a_table_obj);
492  break;
493  }
494  }
495 
496  // for all page components...
497  if (isset($page_object)) {
499  foreach ($defs as $def) {
500  $pc_class = $def["pc_class"];
501  $pc_obj = new $pc_class($page_object);
502 
503  // post xsl page content modification by pc elements
504  $output = $pc_obj->modifyPageContentPostXsl($output, "presentation", false);
505  }
506  }
507 
508  return $output;
509  }
510 
514  public static function _addStyleCheckboxes(
515  string $a_output,
516  ilPCTable $a_table
517  ): string {
518  global $DIC;
519 
520  $lng = $DIC->language();
521 
522  $classes = $a_table->getAllCellClasses();
523 
524  foreach ($classes as $k => $v) {
525  if ($v == "") {
526  $v = $lng->txt("none");
527  }
528  if (substr($v, 0, 4) == "ilc_") {
529  $v = substr($v, 4);
530  }
531  $check = $lng->txt("cont_style") . ": " .
532  '<input type="checkbox" value="1"' .
533  ' name="target[' . $k . ']">' . '</input> ' . $v;
534 
535  $a_output = str_replace("{{{{{TableEdit;" . $k . "}}}}}", $check, $a_output);
536  }
537  return $a_output;
538  }
539 
543  public static function _addAlignmentCheckboxes(
544  string $a_output,
545  ilPCTable $a_table
546  ): string {
547  global $DIC;
548 
549  $lng = $DIC->language();
550 
551  $classes = $a_table->getAllCellAlignments();
552 
553  foreach ($classes as $k => $v) {
554  if ($v == "") {
555  $v = $lng->txt("default");
556  }
557  $check = $lng->txt("cont_alignment") . ": " .
558  '<input type="checkbox" value="1"' .
559  ' name="target[' . $k . ']">' . '</input> ' . $v;
560 
561  $a_output = str_replace("{{{{{TableEdit;" . $k . "}}}}}", $check, $a_output);
562  }
563  return $a_output;
564  }
565 
569  public static function _addWidthInputs(
570  string $a_output,
571  ilPCTable $a_table
572  ): string {
573  global $DIC;
574 
575  $lng = $DIC->language();
576 
577  $widths = $a_table->getAllCellWidths();
578 
579  foreach ($widths as $k => $v) {
580  $check = $lng->txt("cont_width") . ": " .
581  '<input class="small" type="text" size="5" maxlength="10"' .
582  ' name="width[' . $k . ']" value="' . $v . '">' . '</input>';
583 
584  $a_output = str_replace("{{{{{TableEdit;" . $k . "}}}}}", $check, $a_output);
585  }
586  return $a_output;
587  }
588 
592  public static function _addSpanInputs(
593  string $a_output,
594  ilPCTable $a_table
595  ): string {
596  global $DIC;
597 
598  $lng = $DIC->language();
599 
600  $spans = $a_table->getAllCellSpans();
601 
602  foreach ($spans as $k => $v) {
603  // colspans
604  $selects = '<div style="white-space:nowrap;">' . $lng->txt("cont_colspan") . ": " .
605  '<select class="small" name="colspan[' . $k . ']">';
606  for ($i = 1; $i <= $v["max_x"] - $v["x"] + 1; $i++) {
607  $sel_str = ($i == $v["colspan"])
608  ? 'selected="selected"'
609  : '';
610  $selects .= '<option value="' . $i . '" ' . $sel_str . '>' . $i . '</option>';
611  }
612  $selects .= "</select></div>";
613 
614  // rowspans
615  $selects .= '<div style="margin-top:3px; white-space:nowrap;">' . $lng->txt("cont_rowspan") . ": " .
616  '<select class="small" name="rowspan[' . $k . ']">';
617  for ($i = 1; $i <= $v["max_y"] - $v["y"] + 1; $i++) {
618  $sel_str = ($i == $v["rowspan"])
619  ? 'selected="selected"'
620  : '';
621  $selects .= '<option value="' . $i . '" ' . $sel_str . '>' . $i . '</option>';
622  }
623  $selects .= "</select></div>";
624 
625  $a_output = str_replace("{{{{{TableEdit;" . $k . "}}}}}", $selects, $a_output);
626  }
627  return $a_output;
628  }
629 
630  public function editCellStyle(): void
631  {
632  $ilCtrl = $this->ctrl;
633  $tpl = $this->tpl;
634  $lng = $this->lng;
635  $ilTabs = $this->tabs;
636 
637  $this->displayValidationError();
638  $this->setTabs();
639  $this->setCellPropertiesSubTabs();
640  $ilTabs->setSubTabActive("cont_style");
641 
642  // edit form
643  $form = new ilPropertyFormGUI();
644  $form->setFormAction($ilCtrl->getFormAction($this));
645  $form->setTitle($this->lng->txt("cont_table_cell_properties"));
646 
647  // first row style
649  $this->lng->txt("cont_style"),
650  "style"
651  );
652  $this->setBasicTableCellStyles();
653  $this->getCharacteristicsOfCurrentStyle(["table_cell"]); // scorm-2004
654  $chars = $this->getCharacteristics(); // scorm-2004
655  $options = array_merge(array("" => $this->lng->txt("none")), $chars); // scorm-2004
656  foreach ($options as $k => $option) {
657  $html = '<table border="0" cellspacing="0" cellpadding="0"><tr><td class="ilc_table_cell_' . $k . '">' .
658  $option . '</td></tr></table>';
659  $style->addOption($k, $option, $html);
660  }
661 
662  $style->setValue("");
663  $style->setInfo($lng->txt("cont_set_tab_style_info"));
664  $form->addItem($style);
665  $form->setKeepOpen(true);
666 
667  $form->addCommandButton("setStyles", $lng->txt("cont_set_styles"));
668 
669  $html = $form->getHTML();
670  $html .= "<br />" . $this->renderTable("table_edit", "style") . "</form>";
671  $tpl->setContent($html);
672  }
673 
674  public function editCellWidth(): void
675  {
676  $ilCtrl = $this->ctrl;
677  $tpl = $this->tpl;
678  $lng = $this->lng;
679  $ilTabs = $this->tabs;
680 
681  $this->displayValidationError();
682  $this->setTabs();
683  $this->setCellPropertiesSubTabs();
684  $ilTabs->setSubTabActive("cont_width");
685  $ilTabs->setTabActive("cont_table_cell_properties");
686 
687  $ctpl = new ilTemplate("tpl.table_cell_properties.html", true, true, "Services/COPage");
688  $ctpl->setVariable("BTN_NAME", "setWidths");
689  $ctpl->setVariable("BTN_TEXT", $lng->txt("cont_save_widths"));
690  $ctpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
691 
692  $html = $ctpl->get();
693  $html .= "<br />" . $this->renderTable("table_edit", "width") . "</form>";
694  $tpl->setContent($html);
695  }
696 
697  public function editCellSpan(): void
698  {
699  $ilCtrl = $this->ctrl;
700  $tpl = $this->tpl;
701  $lng = $this->lng;
702  $ilTabs = $this->tabs;
703 
704  $this->displayValidationError();
705  $this->setTabs();
706  $this->setCellPropertiesSubTabs();
707  $ilTabs->setSubTabActive("cont_span");
708  $ilTabs->setTabActive("cont_table_cell_properties");
709 
710  $ctpl = new ilTemplate("tpl.table_cell_properties.html", true, true, "Services/COPage");
711  $ctpl->setVariable("BTN_NAME", "setSpans");
712  $ctpl->setVariable("BTN_TEXT", $lng->txt("cont_save_spans"));
713  $ctpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
714 
715  $html = $ctpl->get();
716  $html .= "<br />" . $this->renderTable("table_edit", "span") . "</form>";
717  $tpl->setContent($html);
718  }
719 
723  public function setStyles(): void
724  {
725  $lng = $this->lng;
726 
727  $target = $this->request->getStringArray("target");
728  if (count($target)) {
729  foreach ($target as $k => $value) {
730  if ($value > 0) {
731  $cid = explode(":", $k);
732  $this->content_obj->setTDClass(
733  ilUtil::stripSlashes($cid[0]),
734  $this->request->getString("style"),
735  ilUtil::stripSlashes($cid[1])
736  );
737  }
738  }
739  }
740  $this->updated = $this->pg_obj->update();
741  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
742  $this->ctrl->redirect($this, "editCellStyle");
743  }
744 
748  public function setWidths(): void
749  {
750  $lng = $this->lng;
751 
752  $widths = $this->request->getStringArray("width");
753  if (count($widths) > 0) {
754  foreach ($widths as $k => $width) {
755  $cid = explode(":", $k);
756  $this->content_obj->setTDWidth(
757  ilUtil::stripSlashes($cid[0]),
758  ilUtil::stripSlashes($width),
759  ilUtil::stripSlashes($cid[1])
760  );
761  }
762  }
763  $this->updated = $this->pg_obj->update();
764  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
765  $this->ctrl->redirect($this, "editCellWidth");
766  }
767 
771  public function setSpans(): void
772  {
773  $lng = $this->lng;
774 
775  $colspans = $this->request->getStringArray("colspan");
776  $rowspans = $this->request->getStringArray("rowspan");
777  $cs = [];
778  $rs = [];
779  if (count($colspans) > 0) {
780  foreach ($colspans as $k => $span) {
781  $cs[$k] = $span;
782  $rs[$k] = $rowspans[$k];
783  }
784  $this->content_obj->setTDSpans($cs, $rs);
785  }
786  $this->updated = $this->pg_obj->update();
787  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
788  $this->ctrl->redirect($this, "editCellSpan");
789  }
790 
794  public function setProperties(): void
795  {
796  $this->initPropertiesForm();
797  $this->form->checkInput();
798 
799  // mask html
800  $caption = $this->form->getInput("caption");
801  $caption = str_replace("&", "&amp;", $caption);
802  $caption = str_replace("<", "&lt;", $caption);
803  $caption = str_replace(">", "&gt;", $caption);
804 
805  $this->content_obj->setLanguage($this->form->getInput("language"));
806  $this->content_obj->setWidth($this->form->getInput("width"));
807  $this->content_obj->setBorder($this->form->getInput("border"));
808  $this->content_obj->setCellSpacing($this->form->getInput("spacing"));
809  $this->content_obj->setCellPadding($this->form->getInput("padding"));
810  $this->content_obj->setHorizontalAlign($this->form->getInput("align"));
811  $this->content_obj->setHeaderRows($this->form->getInput("row_header"));
812  $this->content_obj->setHeaderCols($this->form->getInput("col_header"));
813  $this->content_obj->setFooterRows($this->form->getInput("row_footer"));
814  $this->content_obj->setFooterCols($this->form->getInput("col_footer"));
815  if (strpos($this->form->getInput("characteristic"), ":") > 0) {
816  $t = explode(":", $this->form->getInput("characteristic"));
817  $this->content_obj->setTemplate($t[2]);
818  $this->content_obj->setClass("");
819  } else {
820  $this->content_obj->setClass($this->form->getInput("characteristic"));
821  $this->content_obj->setTemplate("");
822  }
823  $this->content_obj->setCaption(
824  $caption,
825  $this->form->getInput("cap_align")
826  );
827  }
828 
832  public function saveProperties(): void
833  {
834  $this->setProperties();
835  $this->updated = $this->pg_obj->update();
836  if ($this->updated === true) {
837  $this->ctrl->redirect($this, "editProperties");
838  //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
839  } else {
840  $this->pg_obj->addHierIDs();
841  $this->edit();
842  }
843  }
844 
845  public function rightAlign(): void
846  {
847  $this->content_obj->setHorizontalAlign("Right");
848  $this->updateAndReturn();
849  }
850 
851  public function leftAlign(): void
852  {
853  $this->content_obj->setHorizontalAlign("Left");
854  $this->updateAndReturn();
855  }
856 
857  public function centerAlign(): void
858  {
859  $this->content_obj->setHorizontalAlign("Center");
860  $this->updateAndReturn();
861  }
862 
863  public function leftFloatAlign(): void
864  {
865  $this->content_obj->setHorizontalAlign("LeftFloat");
866  $this->updateAndReturn();
867  }
868 
869  public function rightFloatAlign(): void
870  {
871  $this->content_obj->setHorizontalAlign("RightFloat");
872  $this->updateAndReturn();
873  }
874 
875  public function insert(): void
876  {
877  $tpl = $this->tpl;
878 
879  $this->displayValidationError();
880  $this->initPropertiesForm("create");
881  $html = $this->form->getHTML();
882  $tpl->setContent($html);
883  }
884 
885  public function getNewTableObject(): ilPCTable
886  {
887  return new ilPCTable($this->getPage());
888  }
889 
893  public function create(): void
894  {
895  $this->content_obj = $this->getNewTableObject();
896  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
897 
898  $this->initPropertiesForm("create");
899  $this->form->checkInput();
900 
901  $import_table = trim($this->form->getInput("import_table"));
902 
903  // import xhtml or spreadsheet table
904  if (!empty($import_table)) {
905  switch ($this->form->getInput("import_type")) {
906  // xhtml import
907  case "html":
908  $res = $this->content_obj->importHtml(
909  $this->form->getInput("language"),
910  $import_table
911  );
912  if ($res !== true) {
913  $this->tpl->setOnScreenMessage('failure', $res);
914  $this->insert();
915  return;
916  }
917  break;
918 
919  // spreadsheet
920  case "spreadsheet":
921  $this->content_obj->importSpreadsheet($this->form->getInput("language"), $import_table);
922  break;
923  }
924  } else {
925  $this->content_obj->addRows(
926  $this->form->getInput("nr_rows"),
927  $this->form->getInput("nr_cols")
928  );
929  }
930 
931  $this->setProperties();
932 
933  $frtype = $this->form->getInput("first_row_style");
934  if ($frtype != "") {
935  $this->content_obj->setFirstRowStyle($frtype);
936  }
937 
938  $this->updated = $this->pg_obj->update();
939 
940  if ($this->updated === true) {
941  $this->afterCreation();
942  } else {
943  $this->insert();
944  }
945  }
946 
947  public function afterCreation(): void
948  {
949  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
950  }
951 
952 
953  //
954  // Edit cell alignments
955  //
956 
957  public function editCellAlignment(): void
958  {
959  $ilCtrl = $this->ctrl;
960  $tpl = $this->tpl;
961  $lng = $this->lng;
962  $ilTabs = $this->tabs;
963 
964  $this->displayValidationError();
965  $this->setTabs();
966  $this->setCellPropertiesSubTabs();
967  $ilTabs->setSubTabActive("cont_alignment");
968  $ilTabs->setTabActive("cont_table_cell_properties");
969 
970  // edit form
971  $form = new ilPropertyFormGUI();
972  $form->setFormAction($ilCtrl->getFormAction($this));
973  $form->setTitle($this->lng->txt("cont_table_cell_properties"));
974 
975  // alignment
976  $options = array(
977  "" => $lng->txt("default"),
978  "Left" => $lng->txt("cont_left"),
979  "Center" => $lng->txt("cont_center"),
980  "Right" => $lng->txt("cont_right")
981  );
982  $si = new ilSelectInputGUI($lng->txt("cont_alignment"), "alignment");
983  $si->setOptions($options);
984  $si->setInfo($lng->txt(""));
985  $form->addItem($si);
986 
987  $form->setKeepOpen(true);
988 
989  $form->addCommandButton("setAlignment", $lng->txt("cont_set_alignment"));
990 
991  $html = $form->getHTML();
992  $html .= "<br />" . $this->renderTable("table_edit", "alignment") . "</form>";
993  $tpl->setContent($html);
994  }
995 
999  public function setAlignment(): void
1000  {
1001  $lng = $this->lng;
1002 
1003  $targets = $this->request->getStringArray("target");
1004  if (count($targets) > 0) {
1005  foreach ($targets as $k => $value) {
1006  if ($value > 0) {
1007  $cid = explode(":", $k);
1008  $this->content_obj->setTDAlignment(
1009  ilUtil::stripSlashes($cid[0]),
1010  $this->request->getString("alignment"),
1011  ilUtil::stripSlashes($cid[1])
1012  );
1013  }
1014  }
1015  }
1016  $this->updated = $this->pg_obj->update();
1017  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
1018 
1019  $this->ctrl->redirect($this, "editCellAlignment");
1020  }
1021 
1025  protected function setEditorToolContext(): void
1026  {
1027  $collection = $this->tool_context->current()->getAdditionalData();
1028  if ($collection->exists(ilCOPageEditGSToolProvider::SHOW_EDITOR)) {
1029  $collection->replace(ilCOPageEditGSToolProvider::SHOW_EDITOR, true);
1030  } else {
1031  $collection->add(ilCOPageEditGSToolProvider::SHOW_EDITOR, true);
1032  }
1033  }
1034 
1038  public function editData(): void
1039  {
1040  $this->setEditorToolContext();
1041 
1042  $this->setTabs();
1043 
1044  $this->displayValidationError();
1045 
1046  $editor_init = new \ILIAS\COPage\Editor\UI\Init();
1047  $editor_init->initUI($this->tpl);
1048 
1049  $this->tpl->setContent($this->getEditDataTable(true));
1050  }
1051 
1052  public function getEditDataTable(bool $initial = false): string
1053  {
1054  $ilCtrl = $this->ctrl;
1055 
1056  $dtpl = new ilTemplate("tpl.tabledata2.html", true, true, "Services/COPage");
1057  $dtpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "tableAction"));
1058  $dtpl->setVariable("HIERID", $this->hier_id);
1059  $dtpl->setVariable("PCID", $this->pc_id);
1060 
1061  $dtpl->setVariable(
1062  "WYSIWYG_ACTION",
1063  $ilCtrl->getFormAction($this, "updateJS")
1064  );
1065 
1066  // get all rows
1067  $xpc = xpath_new_context($this->dom);
1068  $path = "//PageContent[@HierId='" . $this->getHierId() . "']" .
1069  "/Table/TableRow";
1070  $res = xpath_eval($xpc, $path);
1071 
1072  for ($i = 0; $i < count($res->nodeset); $i++) {
1073  $xpc2 = xpath_new_context($this->dom);
1074  $path2 = "//PageContent[@HierId='" . $this->getHierId() . "']" .
1075  "/Table/TableRow[$i+1]/TableData";
1076  $res2 = xpath_eval($xpc2, $path2);
1077 
1078  // if this is the first row -> col icons
1079  if ($i == 0) {
1080  for ($j = 0; $j < count($res2->nodeset); $j++) {
1081  if ($j == 0) {
1082  $dtpl->touchBlock("empty_td");
1083  }
1084 
1085  $move_forward = false;
1086  $move_backward = false;
1087  if ($j == 0) {
1088  if (count($res2->nodeset) == 1) {
1089  //
1090  } else {
1091  $move_forward = true;
1092  }
1093  } elseif ($j == (count($res2->nodeset) - 1)) {
1094  $move_backward = true;
1095  } else {
1096  $move_forward = true;
1097  $move_backward = true;
1098  }
1099  $dtpl->setCurrentBlock("col_icon");
1100  $dtpl->setVariable("NR_COLUMN", $j + 1);
1101  $dtpl->setVariable("PCID_COLUMN", $res2->nodeset[$j]->get_attribute("PCID"));
1102  $dtpl->setVariable("COLUMN_CAPTION", $this->getColumnCaption($j + 1));
1103  $dtpl->parseCurrentBlock();
1104  }
1105  $dtpl->setCurrentBlock("row");
1106  $dtpl->parseCurrentBlock();
1107  }
1108 
1109  for ($j = 0; $j < count($res2->nodeset); $j++) {
1110  // first col: row icons
1111  if ($j == 0) {
1112  if ($i == 0) {
1113  if (count($res->nodeset) == 1) {
1114  $move_type = "none";
1115  } else {
1116  $move_type = "forward";
1117  }
1118  } elseif ($i == (count($res->nodeset) - 1)) {
1119  $move_type = "backward";
1120  } else {
1121  $move_type = "both";
1122  }
1123  $dtpl->setCurrentBlock("row_icon");
1124  $dtpl->setVariable("NR_ROW", $i + 1);
1125  $dtpl->setVariable("PCID_ROW", $res2->nodeset[$j]->get_attribute("PCID"));
1126  $dtpl->setVariable("ROW_CAPTION", $i + 1);
1127  $dtpl->parseCurrentBlock();
1128  }
1129 
1130  // cell
1131  if ($res2->nodeset[$j]->get_attribute("Hidden") != "Y") {
1132  if ($this->content_obj->getType() == "dtab") {
1133  $dtpl->touchBlock("cell_type");
1134  //$dtpl->setCurrentBlock("cell_type");
1135  //$dtpl->parseCurrentBlock();
1136  }
1137 
1138  $dtpl->setCurrentBlock("cell");
1139 
1140  $dtpl->setVariable("PAR_TA_NAME", "cell[" . $i . "][" . $j . "]");
1141  $dtpl->setVariable("PAR_TA_ID", "cell_" . $i . "_" . $j);
1142  $dtpl->setVariable("PAR_ROW", (string) $i);
1143  $dtpl->setVariable("PAR_COLUMN", (string) $j);
1144 
1145  $dtpl->setVariable(
1146  "PAR_TA_CONTENT",
1147  $this->getCellContent($i, $j)
1148  );
1149 
1150  $cs = $res2->nodeset[$j]->get_attribute("ColSpan");
1151  $rs = $res2->nodeset[$j]->get_attribute("RowSpan");
1152  $dtpl->setVariable("WIDTH", "140");
1153  $dtpl->setVariable("HEIGHT", "80");
1154  if ($cs > 1) {
1155  $dtpl->setVariable("COLSPAN", 'colspan="' . $cs . '"');
1156  $dtpl->setVariable("WIDTH", (140 + ($cs - 1) * 146));
1157  }
1158  if ($rs > 1) {
1159  $dtpl->setVariable("ROWSPAN", 'rowspan="' . $rs . '"');
1160  $dtpl->setVariable("HEIGHT", (80 + ($rs - 1) * 86));
1161  }
1162  $dtpl->parseCurrentBlock();
1163  }
1164  }
1165  $dtpl->setCurrentBlock("row");
1166  $dtpl->parseCurrentBlock();
1167  }
1168 
1169  $dtpl->setVariable("TXT_ACTION", $this->lng->txt("cont_table"));
1170 
1171  // add int link parts
1172  $dtpl->setCurrentBlock("int_link_prep");
1173  $dtpl->setVariable(
1174  "INT_LINK_PREP",
1176  $ilCtrl->getLinkTargetByClass(
1177  array("ilpageeditorgui", "ilinternallinkgui"),
1178  "",
1179  false,
1180  true,
1181  false
1182  )
1183  )
1184  );
1185  $dtpl->parseCurrentBlock();
1186 
1187  if ($initial) {
1188  $dtpl->touchBlock("script");
1189  }
1190 
1191  return $dtpl->get();
1192  }
1193 
1194  protected function getColumnCaption(int $nr): string
1195  {
1196  $cap = "";
1197  $base = 26;
1198  while ($nr > 0) {
1199  $chr = ($nr - 1) % $base;
1200  $cap = chr($chr + 65) . $cap;
1201  $nr = ($nr - 1 - $chr) / $base;
1202  }
1203  return $cap;
1204  }
1205 
1206  protected function getCellContent(int $i, int $j): string
1207  {
1208  $tab_node = $this->content_obj->getNode();
1209  $cnt_i = 0;
1210  $content = "";
1211  $template_xml = "";
1212  // get correct cell and dump content of all its childrem
1213  foreach ($tab_node->first_child()->child_nodes() as $child) {
1214  if ($i == $cnt_i) {
1215  $cnt_j = 0;
1216  foreach ($child->child_nodes() as $child2) {
1217  if ($j == $cnt_j) {
1218  foreach ($child2->child_nodes() as $cell_content_node) {
1219  $content .= $this->dom->dump_node($cell_content_node);
1220  }
1221  }
1222  $cnt_j++;
1223  }
1224  }
1225  $cnt_i++;
1226  }
1227  $trans = $this->pg_obj->getLanguageVariablesXML();
1228  $mobs = $this->pg_obj->getMultimediaXML();
1229  if ($this->getStyleId() > 0) {
1230  if (ilObject::_lookupType($this->getStyleId()) == "sty") {
1231  $style = new ilObjStyleSheet($this->getStyleId());
1232  $template_xml = $style->getTemplateXML();
1233  }
1234  }
1235 
1236  $content = $content . $mobs . $trans . $template_xml;
1237 
1238  return $this->renderCell(
1239  $content,
1240  !$this->pg_obj->getPageConfig()->getPreventHTMLUnmasking(),
1241  $this->getPage()
1242  );
1243  }
1244 
1248  protected function renderCell(
1249  $content,
1250  $unmask = true,
1251  $page_object = null
1252  ): string {
1253  global $DIC;
1254 
1255  $ilUser = $DIC->user();
1256  $content = "<dummy>" . $content . "</dummy>";
1257 
1258  $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
1259  $args = array( '/_xml' => $content, '/_xsl' => $xsl );
1260  $xh = xslt_create();
1261  $wb_path = ilFileUtils::getWebspaceDir("output") . "/";
1262  $enlarge_path = ilUtil::getImagePath("enlarge.svg");
1263  $params = array('webspace_path' => $wb_path, 'enlarge_path' => $enlarge_path);
1264  $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", null, $args, $params);
1265  xslt_free($xh);
1266 
1267  // unmask user html
1268  if ($unmask) {
1269  $output = str_replace("&lt;", "<", $output);
1270  $output = str_replace("&gt;", ">", $output);
1271  $output = str_replace("&amp;", "&", $output);
1272  }
1273 
1274  // for all page components...
1275  if (isset($page_object)) {
1277  foreach ($defs as $def) {
1278  //ilCOPagePCDef::requirePCClassByName($def["name"]);
1279  $pc_class = $def["pc_class"];
1280  $pc_obj = new $pc_class($page_object);
1281 
1282  // post xsl page content modification by pc elements
1283  $output = $pc_obj->modifyPageContentPostXsl((string) $output, "presentation", false);
1284  }
1285  }
1286 
1287 
1288  return $output;
1289  }
1290 }
xpath_eval(php4DOMXPath $xpath_context, string $eval_str, $contextnode=null)
static getWebspaceDir(string $mode="filesystem")
get webspace directory
xslt_create()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69
editData()
Edit data of table.
renderCell( $content, $unmask=true, $page_object=null)
Static render table function.
static getInitHTML(string $a_url)
Get initialisation HTML to use internal link editing.
getCharacteristicsOfCurrentStyle(array $a_type)
Get characteristics of current style and call setCharacteristics, if style is given.
static _renderTable(string $content, string $a_mode="table_edit", string $a_submode="", ilPCTable $a_table_obj=null, bool $unmask=true, ilPageObject $page_object=null)
setAlignment()
Set cell alignments.
initPropertiesForm(string $a_mode="edit")
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
static _lookupTemplateIdByName(int $a_style_id, string $a_name)
Lookup table template preview.
$mobs
Definition: imgupload.php:70
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
ilPropertyFormGUI $form
xslt_free(&$proc)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
setStyles()
Set cell styles.
static _addStyleCheckboxes(string $a_output, ilPCTable $a_table)
Add style checkboxes in edit mode.
setCharacteristics(array $a_chars)
create()
create new table in dom and update page in db
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$path
Definition: ltiservices.php:32
global $DIC
Definition: feed.php:28
ILIAS GlobalScreen ScreenContext ContextServices $tool_context
xslt_error(&$proc)
xpath_new_context($dom_document)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _addSpanInputs(string $a_output, ilPCTable $a_table)
Add span inputs.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
This class represents a property in a property form.
setContent(string $a_html)
Sets content for standard template.
setFormAction(string $a_formaction)
getTemplateXML()
Get table template xml.
static _addAlignmentCheckboxes(string $a_output, ilPCTable $a_table)
Add alignment checkboxes in edit mode.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
getFormTitle(string $a_mode="edit")
ilGlobalTemplateInterface $tpl
setEditorToolContext()
Set editor tool context.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
form( $class_path, string $cmd)
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
getAllCellWidths()
Get all cell widths.
saveProperties()
save table properties in db and return to page edit screen
$rows
Definition: xhr_table.php:10
$lang
Definition: xapiexit.php:26
getEditDataTable(bool $initial=false)
getAllCellSpans()
Get all cell spans.
setKeepOpen(bool $a_keepopen)
setTabs(string $data_tab_txt_key="")
__construct(Container $dic, ilPlugin $plugin)
getTemplateOptions(string $a_type="")
This class represents a text area property in a property form.
$ilUser
Definition: imgupload.php:34
$check
Definition: buildRTE.php:81
setProperties()
Set properties from input form.
static _addWidthInputs(string $a_output, ilPCTable $a_table)
Add width inputs.
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$cols
Definition: xhr_table.php:11
getAllCellClasses()
Get all cell classes.
setWidths()
Set cell widths.
setSpans()
Set cell spans.
getCellContent(int $i, int $j)
$i
Definition: metadata.php:41
$base
Definition: index.php:4