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