ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 require_once("./Services/COPage/classes/class.ilPCTable.php");
5 require_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;
86  $lng = $this->lng;
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;
115  $lng = $this->lng;
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  $lng = $this->lng;
161  $tpl = $this->tpl;
162 
163  $this->displayValidationError();
164  $this->setTabs();
165 
166  $this->initPropertiesForm();
167  $this->getPropertiesFormValues();
168  $html = $this->form->getHTML();
169  $html .= "<br />" . $this->renderTable("");
170  $tpl->setContent($html);
171  }
172 
176  public function initPropertiesForm($a_mode = "edit")
177  {
179  $lng = $this->lng;
180  $tpl = $this->tpl;
182 
183  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
184  $this->form = new ilPropertyFormGUI();
185  $this->form->setFormAction($ilCtrl->getFormAction($this));
186  if ($a_mode == "create") {
187  $this->form->setTitle($this->lng->txt("cont_insert_table"));
188  } else {
189  $this->form->setTitle($this->lng->txt("cont_table_properties"));
190  }
191 
192  if ($a_mode == "create") {
193  $nr = array();
194  for ($i = 1; $i <= 20; $i++) {
195  $nr[$i] = $i;
196  }
197 
198  // cols
199  $cols = new ilSelectInputGUI($this->lng->txt("cont_nr_cols"), "nr_cols");
200  $cols->setOptions($nr);
201  $cols->setValue(2);
202  $this->form->addItem($cols);
203 
204  // rows
205  $rows = new ilSelectInputGUI($this->lng->txt("cont_nr_rows"), "nr_rows");
206  $rows->setOptions($nr);
207  $rows->setValue(2);
208  $this->form->addItem($rows);
209  }
210 
211  // width
212  $width = new ilTextInputGUI($this->lng->txt("cont_table_width"), "width");
213  $width->setSize(6);
214  $width->setMaxLength(6);
215  $this->form->addItem($width);
216 
217  // border
218  $border = new ilTextInputGUI($this->lng->txt("cont_table_border"), "border");
219  $border->setInfo($this->lng->txt("cont_table_border_info"));
220  $border->setValue("1px");
221  $border->setSize(6);
222  $border->setMaxLength(6);
223  $this->form->addItem($border);
224 
225  // padding
226  $padding = new ilTextInputGUI($this->lng->txt("cont_table_cellpadding"), "padding");
227  $padding->setInfo($this->lng->txt("cont_table_cellpadding_info"));
228  $padding->setValue("2px");
229  $padding->setSize(6);
230  $padding->setMaxLength(6);
231  $this->form->addItem($padding);
232 
233  // spacing (deprecated, only hidden)
234  $spacing = new ilHiddenInputGUI("spacing");
235  $spacing->setValue("0px");
236  $this->form->addItem($spacing);
237  /*$spacing = new ilTextInputGUI($this->lng->txt("cont_table_cellspacing"), "spacing");
238  $spacing->setValue("0px");
239  $spacing->setSize(6);
240  $spacing->setMaxLength(6);
241  $this->form->addItem($spacing);*/
242 
243  // table templates and table classes
244  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
245  $char_prop = new ilAdvSelectInputGUI(
246  $this->lng->txt("cont_characteristic"),
247  "characteristic"
248  );
249  $chars = $this->getCharacteristics();
250  $templates = $this->getTemplateOptions();
251  $chars = array_merge($templates, $chars);
252  if (is_object($this->content_obj)) {
253  if ($chars[$a_seleted_value] == "" && ($this->content_obj->getClass() != "")) {
254  $chars = array_merge(
255  array($this->content_obj->getClass() => $this->content_obj->getClass()),
256  $chars
257  );
258  }
259  }
260  foreach ($chars as $k => $char) {
261  if (strpos($k, ":") > 0) {
262  $t = explode(":", $k);
263  $html = $this->style->lookupTemplatePreview($t[1]) . '<div style="clear:both;" class="small">' . $char . "</div>";
264  } else {
265  $html = '<table class="ilc_table_' . $k . '"><tr><td class="small">' .
266  $char . '</td></tr></table>';
267  }
268  $char_prop->addOption($k, $char, $html);
269  }
270  $char_prop->setValue("StandardTable");
271  $this->form->addItem($char_prop);
272 
273  $nr = array();
274  for ($i = 0; $i <= 3; $i++) {
275  $nr[$i] = $i;
276  }
277 
278  // row header
279  $rh = new ilSelectInputGUI($this->lng->txt("cont_nr_row_header"), "row_header");
280  $rh->setOptions($nr);
281  $rh->setValue(1);
282  $this->form->addItem($rh);
283 
284  // row footer
285  $rf = new ilSelectInputGUI($this->lng->txt("cont_nr_row_footer"), "row_footer");
286  $rf->setOptions($nr);
287  $rf->setValue(0);
288  $this->form->addItem($rf);
289 
290  // col header
291  $ch = new ilSelectInputGUI($this->lng->txt("cont_nr_col_header"), "col_header");
292  $ch->setOptions($nr);
293  $ch->setValue(0);
294  $this->form->addItem($ch);
295 
296  // col footer
297  $cf = new ilSelectInputGUI($this->lng->txt("cont_nr_col_footer"), "col_footer");
298  $cf->setOptions($nr);
299  $cf->setValue(0);
300  $this->form->addItem($cf);
301 
302  if ($a_mode == "create") {
303  // first row style
304  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
305  $fr_style = new ilAdvSelectInputGUI(
306  $this->lng->txt("cont_first_row_style"),
307  "first_row_style"
308  );
309  $this->setBasicTableCellStyles();
310  $this->getCharacteristicsOfCurrentStyle("table_cell");
311  $chars = $this->getCharacteristics();
312  $options = array_merge(array("" => $this->lng->txt("none")), $chars);
313  foreach ($options as $k => $option) {
314  $html = '<table border="0" cellspacing="0" cellpadding="0"><tr><td class="ilc_table_cell_' . $k . '">' .
315  $option . '</td></tr></table>';
316  $fr_style->addOption($k, $option, $html);
317  }
318 
319  $fr_style->setValue("");
320  $this->form->addItem($fr_style);
321  }
322 
323  // alignment
324  $align_opts = array("Left" => $lng->txt("cont_left"),
325  "Right" => $lng->txt("cont_right"), "Center" => $lng->txt("cont_center"),
326  "LeftFloat" => $lng->txt("cont_left_float"),
327  "RightFloat" => $lng->txt("cont_right_float"));
328  $align = new ilSelectInputGUI($this->lng->txt("cont_align"), "align");
329  $align->setOptions($align_opts);
330  $align->setValue("Center");
331  $this->form->addItem($align);
332 
333  // caption
334  $caption = new ilTextInputGUI($this->lng->txt("cont_caption"), "caption");
335  $caption->setSize(60);
336  $this->form->addItem($caption);
337 
338  // caption align
339  $ca_opts = array("top" => $lng->txt("cont_top"),
340  "bottom" => $lng->txt("cont_bottom"));
341  $ca = new ilSelectInputGUI(
342  $this->lng->txt("cont_align"),
343  "cap_align"
344  );
345  $ca->setOptions($ca_opts);
346  $caption->addSubItem($ca);
347 
348  // import
349  if ($a_mode == "create") {
350  // import table
351  $import = new ilRadioGroupInputGUI($this->lng->txt("cont_paste_table"), "import_type");
352  $op = new ilRadioOption($this->lng->txt("cont_html_table"), "html");
353  $import->addOption($op);
354  $op2 = new ilRadioOption($this->lng->txt("cont_spreadsheet_table"), "spreadsheet");
355 
356  $import_data = new ilTextAreaInputGUI("", "import_table");
357  $import_data->setRows(8);
358  $import_data->setCols(50);
359  $op2->addSubItem($import_data);
360 
361  $import->addOption($op2);
362  $import->setValue("html");
363  $this->form->addItem($import);
364  }
365 
366  // language
367  if ($_SESSION["il_text_lang_" . $_GET["ref_id"]] != "") {
368  $s_lang = $_SESSION["il_text_lang_" . $_GET["ref_id"]];
369  } else {
370  $s_lang = $ilUser->getLanguage();
371  }
372  require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
374  $language = new ilSelectInputGUI($this->lng->txt("language"), "language");
375  $language->setOptions($lang);
376  $language->setValue($s_lang);
377  $this->form->addItem($language);
378 
379  if ($a_mode == "create") {
380  $this->form->addCommandButton("create_tab", $lng->txt("save"));
381  $this->form->addCommandButton("cancelCreate", $lng->txt("cancel"));
382  } else {
383  $this->form->addCommandButton("saveProperties", $lng->txt("save"));
384  }
385  }
386 
390  public function getPropertiesFormValues()
391  {
392  $values = array();
393  $values["width"] = $this->content_obj->getWidth();
394  $values["border"] = $this->content_obj->getBorder();
395  $values["padding"] = $this->content_obj->getCellPadding();
396  $values["spacing"] = $this->content_obj->getCellSpacing();
397  $values["row_header"] = $this->content_obj->getHeaderRows();
398  $values["row_footer"] = $this->content_obj->getFooterRows();
399  $values["col_header"] = $this->content_obj->getHeaderCols();
400  $values["col_footer"] = $this->content_obj->getFooterCols();
401  if ($this->content_obj->getTemplate() != "") {
402  $values["characteristic"] = "t:" .
403  ilObjStyleSheet::_lookupTemplateIdByName($this->getStyleId(), $this->content_obj->getTemplate()) . ":" .
404  $this->content_obj->getTemplate();
405  } else {
406  $values["characteristic"] = $this->content_obj->getClass();
407  }
408  $values["align"] = $this->content_obj->getHorizontalAlign();
409  $values["caption"] = $this->content_obj->getCaption();
410  $values["cap_align"] = $this->content_obj->getCaptionAlign();
411  $values["language"] = $this->content_obj->getLanguage();
412 
413  $this->form->setValuesByArray($values);
414 
415  $ca = $this->form->getItemByPostVar("cap_align");
416  $ca->setValue($this->content_obj->getCaptionAlign());
417  }
418 
422  public function renderTable($a_mode = "table_edit", $a_submode = "")
423  {
424  $tab_node = $this->content_obj->getNode();
425  $tab_node->set_attribute("Enabled", "True");
426  $content = $this->dom->dump_node($tab_node);
427 
428  $trans = $this->pg_obj->getLanguageVariablesXML();
429  $mobs = $this->pg_obj->getMultimediaXML();
430  if ($this->getStyleId() > 0) {
431  if (ilObject::_lookupType($this->getStyleId()) == "sty") {
432  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
433  $style = new ilObjStyleSheet($this->getStyleId());
434  $template_xml = $style->getTemplateXML();
435  }
436  }
437 
438  $content = $content . $mobs . $trans . $template_xml;
439 
441  $content,
442  $a_mode,
443  $a_submode,
444  $this->content_obj,
445  !$this->pg_obj->getPageConfig()->getPreventHTMLUnmasking()
446  );
447  }
448 
452  public static function _renderTable(
453  $content,
454  $a_mode = "table_edit",
455  $a_submode = "",
456  $a_table_obj = null,
457  $unmask = true
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 
508  return '<div class="ilFloatLeft">' . $output . '</div>';
509  }
510 
514  public static function _addStyleCheckboxes($a_output, $a_table)
515  {
516  global $DIC;
517 
518  $lng = $DIC->language();
519 
520  $classes = $a_table->getAllCellClasses();
521 
522  foreach ($classes as $k => $v) {
523  if ($v == "") {
524  $v = $lng->txt("none");
525  }
526  if (substr($v, 0, 4) == "ilc_") {
527  $v = substr($v, 4);
528  }
529  $check = $lng->txt("cont_style") . ": " .
530  '<input type="checkbox" value="1"' .
531  ' name="target[' . $k . ']">' . '</input> ' . $v;
532 
533  $a_output = str_replace("{{{{{TableEdit;" . $k . "}}}}}", $check, $a_output);
534  }
535  return $a_output;
536  }
537 
541  public static function _addAlignmentCheckboxes($a_output, $a_table)
542  {
543  global $DIC;
544 
545  $lng = $DIC->language();
546 
547  $classes = $a_table->getAllCellAlignments();
548 
549  foreach ($classes as $k => $v) {
550  if ($v == "") {
551  $v = $lng->txt("default");
552  }
553  $check = $lng->txt("cont_alignment") . ": " .
554  '<input type="checkbox" value="1"' .
555  ' name="target[' . $k . ']">' . '</input> ' . $v;
556 
557  $a_output = str_replace("{{{{{TableEdit;" . $k . "}}}}}", $check, $a_output);
558  }
559  return $a_output;
560  }
561 
565  public static function _addWidthInputs($a_output, $a_table)
566  {
567  global $DIC;
568 
569  $lng = $DIC->language();
570 
571  $widths = $a_table->getAllCellWidths();
572 
573  foreach ($widths as $k => $v) {
574  $check = $lng->txt("cont_width") . ": " .
575  '<input class="small" type="text" size="5" maxlength="10"' .
576  ' name="width[' . $k . ']" value="' . $v . '">' . '</input>';
577 
578  $a_output = str_replace("{{{{{TableEdit;" . $k . "}}}}}", $check, $a_output);
579  }
580  return $a_output;
581  }
582 
586  public static function _addSpanInputs($a_output, $a_table)
587  {
588  global $DIC;
589 
590  $lng = $DIC->language();
591 
592  $spans = $a_table->getAllCellSpans();
593 
594  foreach ($spans as $k => $v) {
595  // colspans
596  $selects = '<div style="white-space:nowrap;">' . $lng->txt("cont_colspan") . ": " .
597  '<select class="small" name="colspan[' . $k . ']">';
598  for ($i = 1; $i <= $v["max_x"] - $v["x"] + 1; $i++) {
599  $sel_str = ($i == $v["colspan"])
600  ? 'selected="selected"'
601  : '';
602  $selects .= '<option value="' . $i . '" ' . $sel_str . '>' . $i . '</option>';
603  }
604  $selects .= "</select></div>";
605 
606  // rowspans
607  $selects .= '<div style="margin-top:3px; white-space:nowrap;">' . $lng->txt("cont_rowspan") . ": " .
608  '<select class="small" name="rowspan[' . $k . ']">';
609  for ($i = 1; $i <= $v["max_y"] - $v["y"] + 1; $i++) {
610  $sel_str = ($i == $v["rowspan"])
611  ? 'selected="selected"'
612  : '';
613  $selects .= '<option value="' . $i . '" ' . $sel_str . '>' . $i . '</option>';
614  }
615  $selects .= "</select></div>";
616 
617  $a_output = str_replace("{{{{{TableEdit;" . $k . "}}}}}", $selects, $a_output);
618  }
619  return $a_output;
620  }
621 
625  public function editCellStyle()
626  {
628  $tpl = $this->tpl;
629  $lng = $this->lng;
630  $ilTabs = $this->tabs;
631 
632  $this->displayValidationError();
633  $this->setTabs();
634  $this->setCellPropertiesSubTabs();
635  $ilTabs->setSubTabActive("cont_style");
636 
637  // edit form
638  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
639  $form = new ilPropertyFormGUI();
640  $form->setFormAction($ilCtrl->getFormAction($this));
641  $form->setTitle($this->lng->txt("cont_table_cell_properties"));
642 
643  // first row style
644  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
646  $this->lng->txt("cont_style"),
647  "style"
648  );
649  $this->setBasicTableCellStyles();
650  $this->getCharacteristicsOfCurrentStyle("table_cell"); // scorm-2004
651  $chars = $this->getCharacteristics(); // scorm-2004
652  $options = array_merge(array("" => $this->lng->txt("none")), $chars); // scorm-2004
653  foreach ($options as $k => $option) {
654  $html = '<table border="0" cellspacing="0" cellpadding="0"><tr><td class="ilc_table_cell_' . $k . '">' .
655  $option . '</td></tr></table>';
656  $style->addOption($k, $option, $html);
657  }
658 
659  $style->setValue("");
660  $style->setInfo($lng->txt("cont_set_tab_style_info"));
661  $form->addItem($style);
662  $form->setKeepOpen(true);
663 
664  $form->addCommandButton("setStyles", $lng->txt("cont_set_styles"));
665 
666  $html = $form->getHTML();
667  $html .= "<br />" . $this->renderTable("table_edit", "style") . "</form>";
668  $tpl->setContent($html);
669  }
670 
674  public function editCellWidth()
675  {
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 
700  public function editCellSpan()
701  {
703  $tpl = $this->tpl;
704  $lng = $this->lng;
705  $ilTabs = $this->tabs;
706 
707  $this->displayValidationError();
708  $this->setTabs();
709  $this->setCellPropertiesSubTabs();
710  $ilTabs->setSubTabActive("cont_span");
711  $ilTabs->setTabActive("cont_table_cell_properties");
712 
713  $ctpl = new ilTemplate("tpl.table_cell_properties.html", true, true, "Services/COPage");
714  $ctpl->setVariable("BTN_NAME", "setSpans");
715  $ctpl->setVariable("BTN_TEXT", $lng->txt("cont_save_spans"));
716  $ctpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
717 
718  $html = $ctpl->get();
719  $html .= "<br />" . $this->renderTable("table_edit", "span") . "</form>";
720  $tpl->setContent($html);
721  }
722 
726  public function setStyles()
727  {
728  $lng = $this->lng;
729 
730  if (is_array($_POST["target"])) {
731  foreach ($_POST["target"] as $k => $value) {
732  if ($value > 0) {
733  $cid = explode(":", $k);
734  $this->content_obj->setTDClass(
735  ilUtil::stripSlashes($cid[0]),
736  ilUtil::stripSlashes($_POST["style"]),
737  ilUtil::stripSlashes($cid[1])
738  );
739  }
740  }
741  }
742  $this->updated = $this->pg_obj->update();
743  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
744  $this->ctrl->redirect($this, "editCellStyle");
745  }
746 
750  public function setWidths()
751  {
752  $lng = $this->lng;
753 
754  if (is_array($_POST["width"])) {
755  foreach ($_POST["width"] as $k => $width) {
756  $cid = explode(":", $k);
757  $this->content_obj->setTDWidth(
758  ilUtil::stripSlashes($cid[0]),
759  ilUtil::stripSlashes($width),
760  ilUtil::stripSlashes($cid[1])
761  );
762  }
763  }
764  $this->updated = $this->pg_obj->update();
765  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
766  $this->ctrl->redirect($this, "editCellWidth");
767  }
768 
772  public function setSpans()
773  {
774  $lng = $this->lng;
775 
776  if (is_array($_POST["colspan"])) {
777  foreach ($_POST["colspan"] as $k => $span) {
778  $_POST["colspan"][$k] = ilUtil::stripSlashes($span);
779  $_POST["rowspan"][$k] = ilUtil::stripSlashes($_POST["rowspan"][$k]);
780  }
781  $this->content_obj->setTDSpans($_POST["colspan"], $_POST["rowspan"]);
782  }
783  $this->updated = $this->pg_obj->update();
784  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
785  $this->ctrl->redirect($this, "editCellSpan");
786  }
787 
791  public function setProperties()
792  {
793  // mask html
794  $caption = ilUtil::stripSlashes($_POST["caption"]);
795  $caption = str_replace("&", "&amp;", $caption);
796  $caption = str_replace("<", "&lt;", $caption);
797  $caption = str_replace(">", "&gt;", $caption);
798 
799  $this->content_obj->setLanguage(ilUtil::stripSlashes($_POST["language"]));
800  $this->content_obj->setWidth(ilUtil::stripSlashes($_POST["width"]));
801  $this->content_obj->setBorder(ilUtil::stripSlashes($_POST["border"]));
802  $this->content_obj->setCellSpacing(ilUtil::stripSlashes($_POST["spacing"]));
803  $this->content_obj->setCellPadding(ilUtil::stripSlashes($_POST["padding"]));
804  $this->content_obj->setHorizontalAlign(ilUtil::stripSlashes($_POST["align"]));
805  $this->content_obj->setHeaderRows(ilUtil::stripSlashes($_POST["row_header"]));
806  $this->content_obj->setHeaderCols(ilUtil::stripSlashes($_POST["col_header"]));
807  $this->content_obj->setFooterRows(ilUtil::stripSlashes($_POST["row_footer"]));
808  $this->content_obj->setFooterCols(ilUtil::stripSlashes($_POST["col_footer"]));
809  if (strpos($_POST["characteristic"], ":") > 0) {
810  $t = explode(":", $_POST["characteristic"]);
811  $this->content_obj->setTemplate(ilUtil::stripSlashes($t[2]));
812  $this->content_obj->setClass("");
813  } else {
814  $this->content_obj->setClass(ilUtil::stripSlashes($_POST["characteristic"]));
815  $this->content_obj->setTemplate("");
816  }
817  $this->content_obj->setCaption(
818  $caption,
819  ilUtil::stripSlashes($_POST["cap_align"])
820  );
821  }
822 
826  public function saveProperties()
827  {
828  $this->setProperties();
829  $this->updated = $this->pg_obj->update();
830  if ($this->updated === true) {
831  $this->ctrl->redirect($this, "edit");
832  //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
833  } else {
834  $this->pg_obj->addHierIDs();
835  $this->edit();
836  }
837  }
838 
842  public function rightAlign()
843  {
844  $this->content_obj->setHorizontalAlign("Right");
845  $_SESSION["il_pg_error"] = $this->pg_obj->update();
846  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
847  }
848 
852  public function leftAlign()
853  {
854  $this->content_obj->setHorizontalAlign("Left");
855  $_SESSION["il_pg_error"] = $this->pg_obj->update();
856  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
857  }
858 
862  public function centerAlign()
863  {
864  $this->content_obj->setHorizontalAlign("Center");
865  $_SESSION["il_pg_error"] = $this->pg_obj->update();
866  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
867  }
868 
872  public function leftFloatAlign()
873  {
874  $this->content_obj->setHorizontalAlign("LeftFloat");
875  $_SESSION["il_pg_error"] = $this->pg_obj->update();
876  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
877  }
878 
882  public function rightFloatAlign()
883  {
884  $this->content_obj->setHorizontalAlign("RightFloat");
885  $_SESSION["il_pg_error"] = $this->pg_obj->update();
886  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
887  }
888 
892  public function insert()
893  {
896  $tpl = $this->tpl;
897  $lng = $this->lng;
898 
899  $this->displayValidationError();
900 
901  $this->initPropertiesForm("create");
902  $html = $this->form->getHTML();
903  $tpl->setContent($html);
904  }
905 
909  public function getNewTableObject()
910  {
911  return new ilPCTable($this->getPage());
912  }
913 
917  public function create()
918  {
919  global $lng;
920 
921  $this->content_obj = $this->getNewTableObject();
922  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
923  $import_table = trim($_POST["import_table"]);
924 
925  // import xhtml or spreadsheet table
926  if (!empty($import_table)) {
927  switch ($_POST["import_type"]) {
928  // xhtml import
929  case "html":
930  if (!$this->content_obj->importHtml($_POST["language"], $import_table)) {
931  $this->insert();
932  return;
933  }
934  break;
935 
936  // spreadsheet
937  case "spreadsheet":
938  $this->content_obj->importSpreadsheet($_POST["language"], $import_table);
939  break;
940  }
941  } else {
942  $this->content_obj->addRows(
943  ilUtil::stripSlashes($_POST["nr_rows"]),
944  ilUtil::stripSlashes($_POST["nr_cols"])
945  );
946  }
947 
948  $this->setProperties();
949 
950  $frtype = ilUtil::stripSlashes($_POST["first_row_style"]);
951  if ($frtype != "") {
952  $this->content_obj->setFirstRowStyle($frtype);
953  }
954 
955  $this->updated = $this->pg_obj->update();
956 
957  if ($this->updated === true) {
958  $this->afterCreation();
959  } else {
960  $this->insert();
961  }
962  }
963 
967  public function afterCreation()
968  {
969  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
970  }
971 
972 
973  //
974  // Edit cell alignments
975  //
976 
980  public function editCellAlignment()
981  {
983  $tpl = $this->tpl;
984  $lng = $this->lng;
985  $ilTabs = $this->tabs;
986 
987  $this->displayValidationError();
988  $this->setTabs();
989  $this->setCellPropertiesSubTabs();
990  $ilTabs->setSubTabActive("cont_alignment");
991  $ilTabs->setTabActive("cont_table_cell_properties");
992 
993  // edit form
994  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
995  $form = new ilPropertyFormGUI();
996  $form->setFormAction($ilCtrl->getFormAction($this));
997  $form->setTitle($this->lng->txt("cont_table_cell_properties"));
998 
999  // alignment
1000  $options = array(
1001  "" => $lng->txt("default"),
1002  "Left" => $lng->txt("cont_left"),
1003  "Center" => $lng->txt("cont_center"),
1004  "Right" => $lng->txt("cont_right")
1005  );
1006  $si = new ilSelectInputGUI($lng->txt("cont_alignment"), "alignment");
1007  $si->setOptions($options);
1008  $si->setInfo($lng->txt(""));
1009  $form->addItem($si);
1010 
1011  $form->setKeepOpen(true);
1012 
1013  $form->addCommandButton("setAlignment", $lng->txt("cont_set_alignment"));
1014 
1015  $html = $form->getHTML();
1016  $html .= "<br />" . $this->renderTable("table_edit", "alignment") . "</form>";
1017  $tpl->setContent($html);
1018  }
1019 
1023  public function setAlignment()
1024  {
1025  $lng = $this->lng;
1026 
1027  if (is_array($_POST["target"])) {
1028  foreach ($_POST["target"] as $k => $value) {
1029  if ($value > 0) {
1030  $cid = explode(":", $k);
1031  $this->content_obj->setTDAlignment(
1032  ilUtil::stripSlashes($cid[0]),
1033  ilUtil::stripSlashes($_POST["alignment"]),
1034  ilUtil::stripSlashes($cid[1])
1035  );
1036  }
1037  }
1038  }
1039  $this->updated = $this->pg_obj->update();
1040  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1041 
1042  $this->ctrl->redirect($this, "editCellAlignment");
1043  }
1044 }
edit()
edit properties form
xslt_create()
executeCommand()
execute command
static _lookupTemplateIdByName($a_style_id, $a_name)
Lookup table template preview.
This class represents an option in a radio group.
getCharacteristicsOfCurrentStyle($a_type)
Get characteristics of current style.
getNewTableObject()
Get new table object.
initPropertiesForm($a_mode="edit")
Init properties form.
$style
Definition: example_012.php:70
setAlignment()
Set cell alignments.
leftFloatAlign()
align table to left float
$_SESSION["AccountId"]
This class represents a selection list property in a property form.
This class represents a property form user interface.
Class ilPCTable.
global $DIC
Definition: saml.php:7
$border
$_GET["client_id"]
static _addSpanInputs($a_output, $a_table)
Add span inputs.
setCellPropertiesSubTabs()
Set tabs.
xslt_free(&$proc)
static _addWidthInputs($a_output, $a_table)
Add width inputs.
__construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor public.
editCellSpan()
Edit cell spans.
"color:#CC0000 style
Definition: example_001.php:92
setStyles()
Set cell styles and.
editCellWidth()
Edit cell widths.
getTemplateOptions($a_type="")
Get table templates.
create()
create new table in dom and update page in db
user()
Definition: user.php:4
global $ilCtrl
Definition: ilias.php:18
setInfo($a_info)
Set Information Text.
setTabs()
Set tabs.
$a_type
Definition: workflow.php:92
xslt_error(&$proc)
setCharacteristics($a_chars)
Set Characteristics.
This class represents a hidden form property in a property form.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
This class represents a property in a property form.
if(isset($_POST['submit'])) $form
$mobs
addSubItem($a_item)
Add Subitem.
setBasicTableCellStyles()
Set basic table cell styles.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$values
special template class to simplify handling of ITX/PEAR
rightAlign()
align table to right
setSize($a_size)
Set Size.
displayValidationError()
display validation errors
This class represents a text property in a property form.
getStyleId()
Get Style Id.
$ilUser
Definition: imgupload.php:18
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Class ilPCTableGUI.
setOptions($a_options)
Set Options.
insert()
insert new table form
getCharacteristics()
Get characteristics.
static _lookupType($a_id, $a_reference=false)
lookup object type
saveProperties()
save table properties in db and return to page edit screen
static _addStyleCheckboxes($a_output, $a_table)
Add style checkboxes in edit mode.
$rows
Definition: xhr_table.php:10
renderTable($a_mode="table_edit", $a_submode="")
Render the table.
centerAlign()
align table to left
This class represents a text area property in a property form.
static _addAlignmentCheckboxes($a_output, $a_table)
Add alignment checkboxes in edit mode.
Class ilObjStyleSheet.
$ret
Definition: parser.php:6
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
$i
Definition: disco.tpl.php:19
rightFloatAlign()
align table to left
leftAlign()
align table to left
setProperties()
Set properties from input form.
editCellStyle()
Edit cell styles.
This class represents an advanced selection list property in a property form.
static getWebspaceDir($mode="filesystem")
get webspace directory
static _renderTable( $content, $a_mode="table_edit", $a_submode="", $a_table_obj=null, $unmask=true)
Static render table function.
afterCreation()
After creation processing.
$cols
Definition: xhr_table.php:11
$_POST["username"]
setWidths()
Set cell widths.
$html
Definition: example_001.php:87
getPropertiesFormValues()
Get properties form.
setSpans()
Set cell spans.
editCellAlignment()
Edit cell styles.