ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
18{
22 protected $tabs;
23
27 protected $user;
28
29
34 public function __construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
35 {
36 global $DIC;
37
38 $this->tabs = $DIC->tabs();
39 $this->ctrl = $DIC->ctrl();
40 $this->lng = $DIC->language();
41 $this->tpl = $DIC["tpl"];
42 $this->user = $DIC->user();
43 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
44 $this->setCharacteristics(array("StandardTable" => $this->lng->txt("cont_StandardTable")));
45 }
46
50 public function setBasicTableCellStyles()
51 {
52 $this->setCharacteristics(array("Cell1" => "Cell1", "Cell2" => "Cell2",
53 "Cell3" => "Cell3", "Cell4" => "Cell4"));
54 }
55
59 public function executeCommand()
60 {
61 $this->getCharacteristicsOfCurrentStyle("table"); // scorm-2004
62
63 // get next class that processes or forwards current command
64 $next_class = $this->ctrl->getNextClass($this);
65
66 // get current command
67 $cmd = $this->ctrl->getCmd();
68
69 switch ($next_class) {
70 default:
71 $ret = $this->$cmd();
72 break;
73 }
74
75 return $ret;
76 }
77
78
82 public function setTabs()
83 {
84 $ilTabs = $this->tabs;
87
88 $ilTabs->setBackTarget(
89 $lng->txt("pg"),
90 $this->ctrl->getParentReturn($this)
91 );
92
93 $ilTabs->addTarget(
94 "cont_table_properties",
95 $ilCtrl->getLinkTarget($this, "edit"),
96 "edit",
97 get_class($this)
98 );
99
100 $ilTabs->addTarget(
101 "cont_table_cell_properties",
102 $ilCtrl->getLinkTarget($this, "editCellStyle"),
103 "editCellStyle",
104 get_class($this)
105 );
106 }
107
111 public function setCellPropertiesSubTabs()
112 {
113 $ilTabs = $this->tabs;
116
117 $ilTabs->addSubTabTarget(
118 "cont_style",
119 $ilCtrl->getLinkTarget($this, "editCellStyle"),
120 "editCellStyle",
121 get_class($this)
122 );
123
124 $ilTabs->addSubTabTarget(
125 "cont_width",
126 $ilCtrl->getLinkTarget($this, "editCellWidth"),
127 "editCellWidth",
128 get_class($this)
129 );
130
131 $ilTabs->addSubTabTarget(
132 "cont_alignment",
133 $ilCtrl->getLinkTarget($this, "editCellAlignment"),
134 "editCellAlignment",
135 get_class($this)
136 );
137
138 $ilTabs->addSubTabTarget(
139 "cont_span",
140 $ilCtrl->getLinkTarget($this, "editCellSpan"),
141 "editCellSpan",
142 get_class($this)
143 );
144 }
145
149 public function getTemplateOptions($a_type = "")
150 {
151 return parent::getTemplateOptions("table");
152 }
153
157 public function edit()
158 {
160
161 $this->displayValidationError();
162 $this->setTabs();
163
164 $this->initPropertiesForm();
166 $html = $this->form->getHTML();
167 $html .= "<br />" . $this->renderTable("");
168 $tpl->setContent($html);
169 }
170
174 public function initPropertiesForm($a_mode = "edit")
175 {
180
181 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
182 $this->form = new ilPropertyFormGUI();
183 $this->form->setFormAction($ilCtrl->getFormAction($this));
184 if ($a_mode == "create") {
185 $this->form->setTitle($this->lng->txt("cont_insert_table"));
186 } else {
187 $this->form->setTitle($this->lng->txt("cont_table_properties"));
188 }
189
190 if ($a_mode == "create") {
191 $nr = array();
192 for ($i = 1; $i <= 20; $i++) {
193 $nr[$i] = $i;
194 }
195
196 // cols
197 $cols = new ilSelectInputGUI($this->lng->txt("cont_nr_cols"), "nr_cols");
198 $cols->setOptions($nr);
199 $cols->setValue(2);
200 $this->form->addItem($cols);
201
202 // rows
203 $rows = new ilSelectInputGUI($this->lng->txt("cont_nr_rows"), "nr_rows");
204 $rows->setOptions($nr);
205 $rows->setValue(2);
206 $this->form->addItem($rows);
207 }
208
209 // width
210 $width = new ilTextInputGUI($this->lng->txt("cont_table_width"), "width");
211 $width->setSize(6);
212 $width->setMaxLength(6);
213 $this->form->addItem($width);
214
215 // border
216 $border = new ilTextInputGUI($this->lng->txt("cont_table_border"), "border");
217 $border->setInfo($this->lng->txt("cont_table_border_info"));
218 $border->setValue("1px");
219 $border->setSize(6);
220 $border->setMaxLength(6);
221 $this->form->addItem($border);
222
223 // padding
224 $padding = new ilTextInputGUI($this->lng->txt("cont_table_cellpadding"), "padding");
225 $padding->setInfo($this->lng->txt("cont_table_cellpadding_info"));
226 $padding->setValue("2px");
227 $padding->setSize(6);
228 $padding->setMaxLength(6);
229 $this->form->addItem($padding);
230
231 // spacing (deprecated, only hidden)
232 $spacing = new ilHiddenInputGUI("spacing");
233 $spacing->setValue("0px");
234 $this->form->addItem($spacing);
235 /*$spacing = new ilTextInputGUI($this->lng->txt("cont_table_cellspacing"), "spacing");
236 $spacing->setValue("0px");
237 $spacing->setSize(6);
238 $spacing->setMaxLength(6);
239 $this->form->addItem($spacing);*/
240
241 // table templates and table classes
242 require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
243 $char_prop = new ilAdvSelectInputGUI(
244 $this->lng->txt("cont_characteristic"),
245 "characteristic"
246 );
247 $chars = $this->getCharacteristics();
248 $templates = $this->getTemplateOptions();
249 $chars = array_merge($templates, $chars);
250 if (is_object($this->content_obj)) {
251 if ($chars[$a_seleted_value] == "" && ($this->content_obj->getClass() != "")) {
252 $chars = array_merge(
253 array($this->content_obj->getClass() => $this->content_obj->getClass()),
254 $chars
255 );
256 }
257 }
258 foreach ($chars as $k => $char) {
259 if (strpos($k, ":") > 0) {
260 $t = explode(":", $k);
261 $html = $this->style->lookupTemplatePreview($t[1]) . '<div style="clear:both;" class="small">' . $char . "</div>";
262 } else {
263 $html = '<table class="ilc_table_' . $k . '"><tr><td class="small">' .
264 $char . '</td></tr></table>';
265 }
266 $char_prop->addOption($k, $char, $html);
267 }
268 $char_prop->setValue("StandardTable");
269 $this->form->addItem($char_prop);
270
271 $nr = array();
272 for ($i = 0; $i <= 3; $i++) {
273 $nr[$i] = $i;
274 }
275
276 // row header
277 $rh = new ilSelectInputGUI($this->lng->txt("cont_nr_row_header"), "row_header");
278 $rh->setOptions($nr);
279 $rh->setValue(1);
280 $this->form->addItem($rh);
281
282 // row footer
283 $rf = new ilSelectInputGUI($this->lng->txt("cont_nr_row_footer"), "row_footer");
284 $rf->setOptions($nr);
285 $rf->setValue(0);
286 $this->form->addItem($rf);
287
288 // col header
289 $ch = new ilSelectInputGUI($this->lng->txt("cont_nr_col_header"), "col_header");
290 $ch->setOptions($nr);
291 $ch->setValue(0);
292 $this->form->addItem($ch);
293
294 // col footer
295 $cf = new ilSelectInputGUI($this->lng->txt("cont_nr_col_footer"), "col_footer");
296 $cf->setOptions($nr);
297 $cf->setValue(0);
298 $this->form->addItem($cf);
299
300 if ($a_mode == "create") {
301 // first row style
302 require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
303 $fr_style = new ilAdvSelectInputGUI(
304 $this->lng->txt("cont_first_row_style"),
305 "first_row_style"
306 );
308 $this->getCharacteristicsOfCurrentStyle("table_cell");
309 $chars = $this->getCharacteristics();
310 $options = array_merge(array("" => $this->lng->txt("none")), $chars);
311 foreach ($options as $k => $option) {
312 $html = '<table border="0" cellspacing="0" cellpadding="0"><tr><td class="ilc_table_cell_' . $k . '">' .
313 $option . '</td></tr></table>';
314 $fr_style->addOption($k, $option, $html);
315 }
316
317 $fr_style->setValue("");
318 $this->form->addItem($fr_style);
319 }
320
321 // alignment
322 $align_opts = array("Left" => $lng->txt("cont_left"),
323 "Right" => $lng->txt("cont_right"), "Center" => $lng->txt("cont_center"),
324 "LeftFloat" => $lng->txt("cont_left_float"),
325 "RightFloat" => $lng->txt("cont_right_float"));
326 $align = new ilSelectInputGUI($this->lng->txt("cont_align"), "align");
327 $align->setOptions($align_opts);
328 $align->setValue("Center");
329 $this->form->addItem($align);
330
331 // caption
332 $caption = new ilTextInputGUI($this->lng->txt("cont_caption"), "caption");
333 $caption->setSize(60);
334 $this->form->addItem($caption);
335
336 // caption align
337 $ca_opts = array("top" => $lng->txt("cont_top"),
338 "bottom" => $lng->txt("cont_bottom"));
339 $ca = new ilSelectInputGUI(
340 $this->lng->txt("cont_align"),
341 "cap_align"
342 );
343 $ca->setOptions($ca_opts);
344 $caption->addSubItem($ca);
345
346 // import
347 if ($a_mode == "create") {
348 // import table
349 $import = new ilRadioGroupInputGUI($this->lng->txt("cont_paste_table"), "import_type");
350 $op = new ilRadioOption($this->lng->txt("cont_html_table"), "html");
351 $import->addOption($op);
352 $op2 = new ilRadioOption($this->lng->txt("cont_spreadsheet_table"), "spreadsheet");
353
354 $import_data = new ilTextAreaInputGUI("", "import_table");
355 $import_data->setRows(8);
356 $import_data->setCols(50);
357 $op2->addSubItem($import_data);
358
359 $import->addOption($op2);
360 $import->setValue("html");
361 $this->form->addItem($import);
362 }
363
364 // language
365 if ($_SESSION["il_text_lang_" . $_GET["ref_id"]] != "") {
366 $s_lang = $_SESSION["il_text_lang_" . $_GET["ref_id"]];
367 } else {
368 $s_lang = $ilUser->getLanguage();
369 }
370 require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
372 $language = new ilSelectInputGUI($this->lng->txt("language"), "language");
373 $language->setOptions($lang);
374 $language->setValue($s_lang);
375 $this->form->addItem($language);
376
377 if ($a_mode == "create") {
378 $this->form->addCommandButton("create_tab", $lng->txt("save"));
379 $this->form->addCommandButton("cancelCreate", $lng->txt("cancel"));
380 } else {
381 $this->form->addCommandButton("saveProperties", $lng->txt("save"));
382 }
383 }
384
388 public function getPropertiesFormValues()
389 {
390 $values = array();
391 $values["width"] = $this->content_obj->getWidth();
392 $values["border"] = $this->content_obj->getBorder();
393 $values["padding"] = $this->content_obj->getCellPadding();
394 $values["spacing"] = $this->content_obj->getCellSpacing();
395 $values["row_header"] = $this->content_obj->getHeaderRows();
396 $values["row_footer"] = $this->content_obj->getFooterRows();
397 $values["col_header"] = $this->content_obj->getHeaderCols();
398 $values["col_footer"] = $this->content_obj->getFooterCols();
399 if ($this->content_obj->getTemplate() != "") {
400 $values["characteristic"] = "t:" .
401 ilObjStyleSheet::_lookupTemplateIdByName($this->getStyleId(), $this->content_obj->getTemplate()) . ":" .
402 $this->content_obj->getTemplate();
403 } else {
404 $values["characteristic"] = $this->content_obj->getClass();
405 }
406 $values["align"] = $this->content_obj->getHorizontalAlign();
407 $values["caption"] = $this->content_obj->getCaption();
408 $values["cap_align"] = $this->content_obj->getCaptionAlign();
409 $values["language"] = $this->content_obj->getLanguage();
410
411 $this->form->setValuesByArray($values);
412
413 $ca = $this->form->getItemByPostVar("cap_align");
414 $ca->setValue($this->content_obj->getCaptionAlign());
415 }
416
420 public function renderTable($a_mode = "table_edit", $a_submode = "")
421 {
422 $tab_node = $this->content_obj->getNode();
423 $tab_node->set_attribute("Enabled", "True");
424 $content = $this->dom->dump_node($tab_node);
425
426 $trans = $this->pg_obj->getLanguageVariablesXML();
427 $mobs = $this->pg_obj->getMultimediaXML();
428 if ($this->getStyleId() > 0) {
429 if (ilObject::_lookupType($this->getStyleId()) == "sty") {
430 include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
431 $style = new ilObjStyleSheet($this->getStyleId());
432 $template_xml = $style->getTemplateXML();
433 }
434 }
435
436 $content = $content . $mobs . $trans . $template_xml;
437
439 $content,
440 $a_mode,
441 $a_submode,
442 $this->content_obj,
443 !$this->pg_obj->getPageConfig()->getPreventHTMLUnmasking(),
444 $this->getPage()
445 );
446 }
447
451 public static function _renderTable(
452 $content,
453 $a_mode = "table_edit",
454 $a_submode = "",
455 $a_table_obj = null,
456 $unmask = true,
457 $page_object = null
458 ) {
459 global $DIC;
460
461 $ilUser = $DIC->user();
462
463 $content = "<dummy>" . $content . "</dummy>";
464
465 $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
466 $args = array( '/_xml' => $content, '/_xsl' => $xsl );
467 $xh = xslt_create();
468 //echo "<b>XML</b>:".htmlentities($content).":<br>";
469 //echo "<b>XSLT</b>:".htmlentities($xsl).":<br>";
470 $wb_path = ilUtil::getWebspaceDir("output");
471 $enlarge_path = ilUtil::getImagePath("enlarge.svg");
472 $params = array('mode' => $a_mode,
473 'media_mode' => $ilUser->getPref("ilPageEditor_MediaMode"),
474 'media_mode' => 'disable',
475 'webspace_path' => $wb_path, 'enlarge_path' => $enlarge_path);
476 $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", null, $args, $params);
477 echo xslt_error($xh);
478 xslt_free($xh);
479
480 // unmask user html
481 if ($unmask) {
482 $output = str_replace("&lt;", "<", $output);
483 $output = str_replace("&gt;", ">", $output);
484 $output = str_replace("&amp;", "&", $output);
485 }
486
487 if ($a_mode == "table_edit" && !is_null($a_table_obj)) {
488 switch ($a_submode) {
489 case "style":
490 $output = ilPCTableGUI::_addStyleCheckboxes($output, $a_table_obj);
491 break;
492
493 case "alignment":
494 $output = ilPCTableGUI::_addAlignmentCheckboxes($output, $a_table_obj);
495 break;
496
497 case "width":
498 $output = ilPCTableGUI::_addWidthInputs($output, $a_table_obj);
499 break;
500
501 case "span":
502 $output = ilPCTableGUI::_addSpanInputs($output, $a_table_obj);
503 break;
504 }
505 }
506
507 // for all page components...
508 if (isset($page_object)) {
510 foreach ($defs as $def) {
512 $pc_class = $def["pc_class"];
513 $pc_obj = new $pc_class($page_object);
514
515 // post xsl page content modification by pc elements
516 $output = $pc_obj->modifyPageContentPostXsl($output, "presentation", false);
517 }
518 }
519
520
521 return $output;
522 }
523
527 public static function _addStyleCheckboxes($a_output, $a_table)
528 {
529 global $DIC;
530
531 $lng = $DIC->language();
532
533 $classes = $a_table->getAllCellClasses();
534
535 foreach ($classes as $k => $v) {
536 if ($v == "") {
537 $v = $lng->txt("none");
538 }
539 if (substr($v, 0, 4) == "ilc_") {
540 $v = substr($v, 4);
541 }
542 $check = $lng->txt("cont_style") . ": " .
543 '<input type="checkbox" value="1"' .
544 ' name="target[' . $k . ']">' . '</input> ' . $v;
545
546 $a_output = str_replace("{{{{{TableEdit;" . $k . "}}}}}", $check, $a_output);
547 }
548 return $a_output;
549 }
550
554 public static function _addAlignmentCheckboxes($a_output, $a_table)
555 {
556 global $DIC;
557
558 $lng = $DIC->language();
559
560 $classes = $a_table->getAllCellAlignments();
561
562 foreach ($classes as $k => $v) {
563 if ($v == "") {
564 $v = $lng->txt("default");
565 }
566 $check = $lng->txt("cont_alignment") . ": " .
567 '<input type="checkbox" value="1"' .
568 ' name="target[' . $k . ']">' . '</input> ' . $v;
569
570 $a_output = str_replace("{{{{{TableEdit;" . $k . "}}}}}", $check, $a_output);
571 }
572 return $a_output;
573 }
574
578 public static function _addWidthInputs($a_output, $a_table)
579 {
580 global $DIC;
581
582 $lng = $DIC->language();
583
584 $widths = $a_table->getAllCellWidths();
585
586 foreach ($widths as $k => $v) {
587 $check = $lng->txt("cont_width") . ": " .
588 '<input class="small" type="text" size="5" maxlength="10"' .
589 ' name="width[' . $k . ']" value="' . $v . '">' . '</input>';
590
591 $a_output = str_replace("{{{{{TableEdit;" . $k . "}}}}}", $check, $a_output);
592 }
593 return $a_output;
594 }
595
599 public static function _addSpanInputs($a_output, $a_table)
600 {
601 global $DIC;
602
603 $lng = $DIC->language();
604
605 $spans = $a_table->getAllCellSpans();
606
607 foreach ($spans as $k => $v) {
608 // colspans
609 $selects = '<div style="white-space:nowrap;">' . $lng->txt("cont_colspan") . ": " .
610 '<select class="small" name="colspan[' . $k . ']">';
611 for ($i = 1; $i <= $v["max_x"] - $v["x"] + 1; $i++) {
612 $sel_str = ($i == $v["colspan"])
613 ? 'selected="selected"'
614 : '';
615 $selects .= '<option value="' . $i . '" ' . $sel_str . '>' . $i . '</option>';
616 }
617 $selects .= "</select></div>";
618
619 // rowspans
620 $selects .= '<div style="margin-top:3px; white-space:nowrap;">' . $lng->txt("cont_rowspan") . ": " .
621 '<select class="small" name="rowspan[' . $k . ']">';
622 for ($i = 1; $i <= $v["max_y"] - $v["y"] + 1; $i++) {
623 $sel_str = ($i == $v["rowspan"])
624 ? 'selected="selected"'
625 : '';
626 $selects .= '<option value="' . $i . '" ' . $sel_str . '>' . $i . '</option>';
627 }
628 $selects .= "</select></div>";
629
630 $a_output = str_replace("{{{{{TableEdit;" . $k . "}}}}}", $selects, $a_output);
631 }
632 return $a_output;
633 }
634
638 public function editCellStyle()
639 {
643 $ilTabs = $this->tabs;
644
645 $this->displayValidationError();
646 $this->setTabs();
648 $ilTabs->setSubTabActive("cont_style");
649
650 // edit form
651 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
652 $form = new ilPropertyFormGUI();
653 $form->setFormAction($ilCtrl->getFormAction($this));
654 $form->setTitle($this->lng->txt("cont_table_cell_properties"));
655
656 // first row style
657 require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
658 $style = new ilAdvSelectInputGUI(
659 $this->lng->txt("cont_style"),
660 "style"
661 );
663 $this->getCharacteristicsOfCurrentStyle("table_cell"); // scorm-2004
664 $chars = $this->getCharacteristics(); // scorm-2004
665 $options = array_merge(array("" => $this->lng->txt("none")), $chars); // scorm-2004
666 foreach ($options as $k => $option) {
667 $html = '<table border="0" cellspacing="0" cellpadding="0"><tr><td class="ilc_table_cell_' . $k . '">' .
668 $option . '</td></tr></table>';
669 $style->addOption($k, $option, $html);
670 }
671
672 $style->setValue("");
673 $style->setInfo($lng->txt("cont_set_tab_style_info"));
674 $form->addItem($style);
675 $form->setKeepOpen(true);
676
677 $form->addCommandButton("setStyles", $lng->txt("cont_set_styles"));
678
679 $html = $form->getHTML();
680 $html .= "<br />" . $this->renderTable("table_edit", "style") . "</form>";
681 $tpl->setContent($html);
682 }
683
687 public function editCellWidth()
688 {
692 $ilTabs = $this->tabs;
693
694 $this->displayValidationError();
695 $this->setTabs();
697 $ilTabs->setSubTabActive("cont_width");
698 $ilTabs->setTabActive("cont_table_cell_properties");
699
700 $ctpl = new ilTemplate("tpl.table_cell_properties.html", true, true, "Services/COPage");
701 $ctpl->setVariable("BTN_NAME", "setWidths");
702 $ctpl->setVariable("BTN_TEXT", $lng->txt("cont_save_widths"));
703 $ctpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
704
705 $html = $ctpl->get();
706 $html .= "<br />" . $this->renderTable("table_edit", "width") . "</form>";
707 $tpl->setContent($html);
708 }
709
713 public function editCellSpan()
714 {
718 $ilTabs = $this->tabs;
719
720 $this->displayValidationError();
721 $this->setTabs();
723 $ilTabs->setSubTabActive("cont_span");
724 $ilTabs->setTabActive("cont_table_cell_properties");
725
726 $ctpl = new ilTemplate("tpl.table_cell_properties.html", true, true, "Services/COPage");
727 $ctpl->setVariable("BTN_NAME", "setSpans");
728 $ctpl->setVariable("BTN_TEXT", $lng->txt("cont_save_spans"));
729 $ctpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
730
731 $html = $ctpl->get();
732 $html .= "<br />" . $this->renderTable("table_edit", "span") . "</form>";
733 $tpl->setContent($html);
734 }
735
739 public function setStyles()
740 {
742
743 if (is_array($_POST["target"])) {
744 foreach ($_POST["target"] as $k => $value) {
745 if ($value > 0) {
746 $cid = explode(":", $k);
747 $this->content_obj->setTDClass(
748 ilUtil::stripSlashes($cid[0]),
750 ilUtil::stripSlashes($cid[1])
751 );
752 }
753 }
754 }
755 $this->updated = $this->pg_obj->update();
756 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
757 $this->ctrl->redirect($this, "editCellStyle");
758 }
759
763 public function setWidths()
764 {
766
767 if (is_array($_POST["width"])) {
768 foreach ($_POST["width"] as $k => $width) {
769 $cid = explode(":", $k);
770 $this->content_obj->setTDWidth(
771 ilUtil::stripSlashes($cid[0]),
772 ilUtil::stripSlashes($width),
773 ilUtil::stripSlashes($cid[1])
774 );
775 }
776 }
777 $this->updated = $this->pg_obj->update();
778 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
779 $this->ctrl->redirect($this, "editCellWidth");
780 }
781
785 public function setSpans()
786 {
788
789 if (is_array($_POST["colspan"])) {
790 foreach ($_POST["colspan"] as $k => $span) {
791 $_POST["colspan"][$k] = ilUtil::stripSlashes($span);
792 $_POST["rowspan"][$k] = ilUtil::stripSlashes($_POST["rowspan"][$k]);
793 }
794 $this->content_obj->setTDSpans($_POST["colspan"], $_POST["rowspan"]);
795 }
796 $this->updated = $this->pg_obj->update();
797 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
798 $this->ctrl->redirect($this, "editCellSpan");
799 }
800
804 public function setProperties()
805 {
806 // mask html
807 $caption = ilUtil::stripSlashes($_POST["caption"]);
808 $caption = str_replace("&", "&amp;", $caption);
809 $caption = str_replace("<", "&lt;", $caption);
810 $caption = str_replace(">", "&gt;", $caption);
811
812 $this->content_obj->setLanguage(ilUtil::stripSlashes($_POST["language"]));
813 $this->content_obj->setWidth(ilUtil::stripSlashes($_POST["width"]));
814 $this->content_obj->setBorder(ilUtil::stripSlashes($_POST["border"]));
815 $this->content_obj->setCellSpacing(ilUtil::stripSlashes($_POST["spacing"]));
816 $this->content_obj->setCellPadding(ilUtil::stripSlashes($_POST["padding"]));
817 $this->content_obj->setHorizontalAlign(ilUtil::stripSlashes($_POST["align"]));
818 $this->content_obj->setHeaderRows(ilUtil::stripSlashes($_POST["row_header"]));
819 $this->content_obj->setHeaderCols(ilUtil::stripSlashes($_POST["col_header"]));
820 $this->content_obj->setFooterRows(ilUtil::stripSlashes($_POST["row_footer"]));
821 $this->content_obj->setFooterCols(ilUtil::stripSlashes($_POST["col_footer"]));
822 if (strpos($_POST["characteristic"], ":") > 0) {
823 $t = explode(":", $_POST["characteristic"]);
824 $this->content_obj->setTemplate(ilUtil::stripSlashes($t[2]));
825 $this->content_obj->setClass("");
826 } else {
827 $this->content_obj->setClass(ilUtil::stripSlashes($_POST["characteristic"]));
828 $this->content_obj->setTemplate("");
829 }
830 $this->content_obj->setCaption(
831 $caption,
832 ilUtil::stripSlashes($_POST["cap_align"])
833 );
834 }
835
839 public function saveProperties()
840 {
841 $this->setProperties();
842 $this->updated = $this->pg_obj->update();
843 if ($this->updated === true) {
844 $this->ctrl->redirect($this, "edit");
845 //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
846 } else {
847 $this->pg_obj->addHierIDs();
848 $this->edit();
849 }
850 }
851
855 public function rightAlign()
856 {
857 $this->content_obj->setHorizontalAlign("Right");
858 $_SESSION["il_pg_error"] = $this->pg_obj->update();
859 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
860 }
861
865 public function leftAlign()
866 {
867 $this->content_obj->setHorizontalAlign("Left");
868 $_SESSION["il_pg_error"] = $this->pg_obj->update();
869 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
870 }
871
875 public function centerAlign()
876 {
877 $this->content_obj->setHorizontalAlign("Center");
878 $_SESSION["il_pg_error"] = $this->pg_obj->update();
879 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
880 }
881
885 public function leftFloatAlign()
886 {
887 $this->content_obj->setHorizontalAlign("LeftFloat");
888 $_SESSION["il_pg_error"] = $this->pg_obj->update();
889 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
890 }
891
895 public function rightFloatAlign()
896 {
897 $this->content_obj->setHorizontalAlign("RightFloat");
898 $_SESSION["il_pg_error"] = $this->pg_obj->update();
899 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
900 }
901
905 public function insert()
906 {
911
912 $this->displayValidationError();
913
914 $this->initPropertiesForm("create");
915 $html = $this->form->getHTML();
916 $tpl->setContent($html);
917 }
918
922 public function getNewTableObject()
923 {
924 return new ilPCTable($this->getPage());
925 }
926
930 public function create()
931 {
932 global $lng;
933
934 $this->content_obj = $this->getNewTableObject();
935 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
936 $import_table = trim($_POST["import_table"]);
937
938 // import xhtml or spreadsheet table
939 if (!empty($import_table)) {
940 switch ($_POST["import_type"]) {
941 // xhtml import
942 case "html":
943 if (!$this->content_obj->importHtml($_POST["language"], $import_table)) {
944 $this->insert();
945 return;
946 }
947 break;
948
949 // spreadsheet
950 case "spreadsheet":
951 $this->content_obj->importSpreadsheet($_POST["language"], $import_table);
952 break;
953 }
954 } else {
955 $this->content_obj->addRows(
956 ilUtil::stripSlashes($_POST["nr_rows"]),
957 ilUtil::stripSlashes($_POST["nr_cols"])
958 );
959 }
960
961 $this->setProperties();
962
963 $frtype = ilUtil::stripSlashes($_POST["first_row_style"]);
964 if ($frtype != "") {
965 $this->content_obj->setFirstRowStyle($frtype);
966 }
967
968 $this->updated = $this->pg_obj->update();
969
970 if ($this->updated === true) {
971 $this->afterCreation();
972 } else {
973 $this->insert();
974 }
975 }
976
980 public function afterCreation()
981 {
982 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
983 }
984
985
986 //
987 // Edit cell alignments
988 //
989
993 public function editCellAlignment()
994 {
998 $ilTabs = $this->tabs;
999
1000 $this->displayValidationError();
1001 $this->setTabs();
1002 $this->setCellPropertiesSubTabs();
1003 $ilTabs->setSubTabActive("cont_alignment");
1004 $ilTabs->setTabActive("cont_table_cell_properties");
1005
1006 // edit form
1007 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1008 $form = new ilPropertyFormGUI();
1009 $form->setFormAction($ilCtrl->getFormAction($this));
1010 $form->setTitle($this->lng->txt("cont_table_cell_properties"));
1011
1012 // alignment
1013 $options = array(
1014 "" => $lng->txt("default"),
1015 "Left" => $lng->txt("cont_left"),
1016 "Center" => $lng->txt("cont_center"),
1017 "Right" => $lng->txt("cont_right")
1018 );
1019 $si = new ilSelectInputGUI($lng->txt("cont_alignment"), "alignment");
1020 $si->setOptions($options);
1021 $si->setInfo($lng->txt(""));
1022 $form->addItem($si);
1023
1024 $form->setKeepOpen(true);
1025
1026 $form->addCommandButton("setAlignment", $lng->txt("cont_set_alignment"));
1027
1028 $html = $form->getHTML();
1029 $html .= "<br />" . $this->renderTable("table_edit", "alignment") . "</form>";
1030 $tpl->setContent($html);
1031 }
1032
1036 public function setAlignment()
1037 {
1038 $lng = $this->lng;
1039
1040 if (is_array($_POST["target"])) {
1041 foreach ($_POST["target"] as $k => $value) {
1042 if ($value > 0) {
1043 $cid = explode(":", $k);
1044 $this->content_obj->setTDAlignment(
1045 ilUtil::stripSlashes($cid[0]),
1046 ilUtil::stripSlashes($_POST["alignment"]),
1047 ilUtil::stripSlashes($cid[1])
1048 );
1049 }
1050 }
1051 }
1052 $this->updated = $this->pg_obj->update();
1053 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1054
1055 $this->ctrl->redirect($this, "editCellAlignment");
1056 }
1057}
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.
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.
create()
create new table in dom and update page in db
setStyles()
Set cell styles and.
setTabs()
Set tabs.
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.
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.
edit()
edit properties form
afterCreation()
After creation processing.
getNewTableObject()
Get new table object.
setAlignment()
Set cell alignments.
Class ilPCTable.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
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 $ilCtrl
Definition: ilias.php:18
xslt_error(&$proc)
xslt_free(&$proc)
xslt_create()
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6
$mobs
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:92
$lang
Definition: xapiexit.php:8
$DIC
Definition: xapitoken.php:46
$cols
Definition: xhr_table.php:11
$rows
Definition: xhr_table.php:10