ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
440  return ilPCTableGUI::_renderTable($content, $a_mode, $a_submode, $this->content_obj,
441  !$this->pg_obj->getPageConfig()->getPreventHTMLUnmasking());
442  }
443 
447  public static function _renderTable($content, $a_mode = "table_edit", $a_submode = "", $a_table_obj = null,
448  $unmask = true)
449  {
450  global $DIC;
451 
452  $ilUser = $DIC->user();
453 
454  $content = "<dummy>" . $content . "</dummy>";
455 
456  $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
457  $args = array( '/_xml' => $content, '/_xsl' => $xsl );
458  $xh = xslt_create();
459  //echo "<b>XML</b>:".htmlentities($content).":<br>";
460  //echo "<b>XSLT</b>:".htmlentities($xsl).":<br>";
461  $wb_path = ilUtil::getWebspaceDir("output");
462  $enlarge_path = ilUtil::getImagePath("enlarge.svg");
463  $params = array('mode' => $a_mode,
464  'media_mode' => $ilUser->getPref("ilPageEditor_MediaMode"),
465  'media_mode' => 'disable',
466  'webspace_path' => $wb_path, 'enlarge_path' => $enlarge_path);
467  $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", null, $args, $params);
468  echo xslt_error($xh);
469  xslt_free($xh);
470 
471  // unmask user html
472  if ($unmask) {
473  $output = str_replace("&lt;", "<", $output);
474  $output = str_replace("&gt;", ">", $output);
475  $output = str_replace("&amp;", "&", $output);
476  }
477 
478  if ($a_mode == "table_edit" && !is_null($a_table_obj)) {
479  switch ($a_submode) {
480  case "style":
481  $output = ilPCTableGUI::_addStyleCheckboxes($output, $a_table_obj);
482  break;
483 
484  case "alignment":
485  $output = ilPCTableGUI::_addAlignmentCheckboxes($output, $a_table_obj);
486  break;
487 
488  case "width":
489  $output = ilPCTableGUI::_addWidthInputs($output, $a_table_obj);
490  break;
491 
492  case "span":
493  $output = ilPCTableGUI::_addSpanInputs($output, $a_table_obj);
494  break;
495  }
496  }
497 
498 
499  return '<div class="ilFloatLeft">' . $output . '</div>';
500  }
501 
505  public static function _addStyleCheckboxes($a_output, $a_table)
506  {
507  global $DIC;
508 
509  $lng = $DIC->language();
510 
511  $classes = $a_table->getAllCellClasses();
512 
513  foreach ($classes as $k => $v) {
514  if ($v == "") {
515  $v = $lng->txt("none");
516  }
517  if (substr($v, 0, 4) == "ilc_") {
518  $v = substr($v, 4);
519  }
520  $check = $lng->txt("cont_style") . ": " .
521  '<input type="checkbox" value="1"' .
522  ' name="target[' . $k . ']">' . '</input> ' . $v;
523 
524  $a_output = str_replace("{{{{{TableEdit;" . $k . "}}}}}", $check, $a_output);
525  }
526  return $a_output;
527  }
528 
532  public static function _addAlignmentCheckboxes($a_output, $a_table)
533  {
534  global $DIC;
535 
536  $lng = $DIC->language();
537 
538  $classes = $a_table->getAllCellAlignments();
539 
540  foreach ($classes as $k => $v) {
541  if ($v == "") {
542  $v = $lng->txt("default");
543  }
544  $check = $lng->txt("cont_alignment") . ": " .
545  '<input type="checkbox" value="1"' .
546  ' name="target[' . $k . ']">' . '</input> ' . $v;
547 
548  $a_output = str_replace("{{{{{TableEdit;" . $k . "}}}}}", $check, $a_output);
549  }
550  return $a_output;
551  }
552 
556  public static function _addWidthInputs($a_output, $a_table)
557  {
558  global $DIC;
559 
560  $lng = $DIC->language();
561 
562  $widths = $a_table->getAllCellWidths();
563 
564  foreach ($widths as $k => $v) {
565  $check = $lng->txt("cont_width") . ": " .
566  '<input class="small" type="text" size="5" maxlength="10"' .
567  ' name="width[' . $k . ']" value="' . $v . '">' . '</input>';
568 
569  $a_output = str_replace("{{{{{TableEdit;" . $k . "}}}}}", $check, $a_output);
570  }
571  return $a_output;
572  }
573 
577  public static function _addSpanInputs($a_output, $a_table)
578  {
579  global $DIC;
580 
581  $lng = $DIC->language();
582 
583  $spans = $a_table->getAllCellSpans();
584 
585  foreach ($spans as $k => $v) {
586  // colspans
587  $selects = '<div style="white-space:nowrap;">' . $lng->txt("cont_colspan") . ": " .
588  '<select class="small" name="colspan[' . $k . ']">';
589  for ($i = 1; $i <= $v["max_x"] - $v["x"] + 1; $i++) {
590  $sel_str = ($i == $v["colspan"])
591  ? 'selected="selected"'
592  : '';
593  $selects.= '<option value="' . $i . '" ' . $sel_str . '>' . $i . '</option>';
594  }
595  $selects.= "</select></div>";
596 
597  // rowspans
598  $selects.= '<div style="margin-top:3px; white-space:nowrap;">' . $lng->txt("cont_rowspan") . ": " .
599  '<select class="small" name="rowspan[' . $k . ']">';
600  for ($i = 1; $i <= $v["max_y"] - $v["y"] + 1; $i++) {
601  $sel_str = ($i == $v["rowspan"])
602  ? 'selected="selected"'
603  : '';
604  $selects.= '<option value="' . $i . '" ' . $sel_str . '>' . $i . '</option>';
605  }
606  $selects.= "</select></div>";
607 
608  $a_output = str_replace("{{{{{TableEdit;" . $k . "}}}}}", $selects, $a_output);
609  }
610  return $a_output;
611  }
612 
616  public function editCellStyle()
617  {
619  $tpl = $this->tpl;
620  $lng = $this->lng;
621  $ilTabs = $this->tabs;
622 
623  $this->displayValidationError();
624  $this->setTabs();
625  $this->setCellPropertiesSubTabs();
626  $ilTabs->setSubTabActive("cont_style");
627 
628  // edit form
629  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
630  $form = new ilPropertyFormGUI();
631  $form->setFormAction($ilCtrl->getFormAction($this));
632  $form->setTitle($this->lng->txt("cont_table_cell_properties"));
633 
634  // first row style
635  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
637  $this->lng->txt("cont_style"),
638  "style"
639  );
640  $this->setBasicTableCellStyles();
641  $this->getCharacteristicsOfCurrentStyle("table_cell"); // scorm-2004
642  $chars = $this->getCharacteristics(); // scorm-2004
643  $options = array_merge(array("" => $this->lng->txt("none")), $chars); // scorm-2004
644  foreach ($options as $k => $option) {
645  $html = '<table border="0" cellspacing="0" cellpadding="0"><tr><td class="ilc_table_cell_' . $k . '">' .
646  $option . '</td></tr></table>';
647  $style->addOption($k, $option, $html);
648  }
649 
650  $style->setValue("");
651  $style->setInfo($lng->txt("cont_set_tab_style_info"));
652  $form->addItem($style);
653  $form->setKeepOpen(true);
654 
655  $form->addCommandButton("setStyles", $lng->txt("cont_set_styles"));
656 
657  $html = $form->getHTML();
658  $html.= "<br />" . $this->renderTable("table_edit", "style") . "</form>";
659  $tpl->setContent($html);
660  }
661 
665  public function editCellWidth()
666  {
668  $tpl = $this->tpl;
669  $lng = $this->lng;
670  $ilTabs = $this->tabs;
671 
672  $this->displayValidationError();
673  $this->setTabs();
674  $this->setCellPropertiesSubTabs();
675  $ilTabs->setSubTabActive("cont_width");
676  $ilTabs->setTabActive("cont_table_cell_properties");
677 
678  $ctpl = new ilTemplate("tpl.table_cell_properties.html", true, true, "Services/COPage");
679  $ctpl->setVariable("BTN_NAME", "setWidths");
680  $ctpl->setVariable("BTN_TEXT", $lng->txt("cont_save_widths"));
681  $ctpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
682 
683  $html = $ctpl->get();
684  $html.= "<br />" . $this->renderTable("table_edit", "width") . "</form>";
685  $tpl->setContent($html);
686  }
687 
691  public function editCellSpan()
692  {
694  $tpl = $this->tpl;
695  $lng = $this->lng;
696  $ilTabs = $this->tabs;
697 
698  $this->displayValidationError();
699  $this->setTabs();
700  $this->setCellPropertiesSubTabs();
701  $ilTabs->setSubTabActive("cont_span");
702  $ilTabs->setTabActive("cont_table_cell_properties");
703 
704  $ctpl = new ilTemplate("tpl.table_cell_properties.html", true, true, "Services/COPage");
705  $ctpl->setVariable("BTN_NAME", "setSpans");
706  $ctpl->setVariable("BTN_TEXT", $lng->txt("cont_save_spans"));
707  $ctpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
708 
709  $html = $ctpl->get();
710  $html.= "<br />" . $this->renderTable("table_edit", "span") . "</form>";
711  $tpl->setContent($html);
712  }
713 
717  public function setStyles()
718  {
719  $lng = $this->lng;
720 
721  if (is_array($_POST["target"])) {
722  foreach ($_POST["target"] as $k => $value) {
723  if ($value > 0) {
724  $cid = explode(":", $k);
725  $this->content_obj->setTDClass(
726  ilUtil::stripSlashes($cid[0]),
727  ilUtil::stripSlashes($_POST["style"]),
728  ilUtil::stripSlashes($cid[1])
729  );
730  }
731  }
732  }
733  $this->updated = $this->pg_obj->update();
734  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
735  $this->ctrl->redirect($this, "editCellStyle");
736  }
737 
741  public function setWidths()
742  {
743  $lng = $this->lng;
744 
745  if (is_array($_POST["width"])) {
746  foreach ($_POST["width"] as $k => $width) {
747  $cid = explode(":", $k);
748  $this->content_obj->setTDWidth(
749  ilUtil::stripSlashes($cid[0]),
750  ilUtil::stripSlashes($width),
751  ilUtil::stripSlashes($cid[1])
752  );
753  }
754  }
755  $this->updated = $this->pg_obj->update();
756  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
757  $this->ctrl->redirect($this, "editCellWidth");
758  }
759 
763  public function setSpans()
764  {
765  $lng = $this->lng;
766 
767  if (is_array($_POST["colspan"])) {
768  foreach ($_POST["colspan"] as $k => $span) {
769  $_POST["colspan"][$k] = ilUtil::stripSlashes($span);
770  $_POST["rowspan"][$k] = ilUtil::stripSlashes($_POST["rowspan"][$k]);
771  }
772  $this->content_obj->setTDSpans($_POST["colspan"], $_POST["rowspan"]);
773  }
774  $this->updated = $this->pg_obj->update();
775  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
776  $this->ctrl->redirect($this, "editCellSpan");
777  }
778 
782  public function setProperties()
783  {
784  // mask html
785  $caption = ilUtil::stripSlashes($_POST["caption"]);
786  $caption = str_replace("&", "&amp;", $caption);
787  $caption = str_replace("<", "&lt;", $caption);
788  $caption = str_replace(">", "&gt;", $caption);
789 
790  $this->content_obj->setLanguage(ilUtil::stripSlashes($_POST["language"]));
791  $this->content_obj->setWidth(ilUtil::stripSlashes($_POST["width"]));
792  $this->content_obj->setBorder(ilUtil::stripSlashes($_POST["border"]));
793  $this->content_obj->setCellSpacing(ilUtil::stripSlashes($_POST["spacing"]));
794  $this->content_obj->setCellPadding(ilUtil::stripSlashes($_POST["padding"]));
795  $this->content_obj->setHorizontalAlign(ilUtil::stripSlashes($_POST["align"]));
796  $this->content_obj->setHeaderRows(ilUtil::stripSlashes($_POST["row_header"]));
797  $this->content_obj->setHeaderCols(ilUtil::stripSlashes($_POST["col_header"]));
798  $this->content_obj->setFooterRows(ilUtil::stripSlashes($_POST["row_footer"]));
799  $this->content_obj->setFooterCols(ilUtil::stripSlashes($_POST["col_footer"]));
800  if (strpos($_POST["characteristic"], ":") > 0) {
801  $t = explode(":", $_POST["characteristic"]);
802  $this->content_obj->setTemplate(ilUtil::stripSlashes($t[2]));
803  $this->content_obj->setClass("");
804  } else {
805  $this->content_obj->setClass(ilUtil::stripSlashes($_POST["characteristic"]));
806  $this->content_obj->setTemplate("");
807  }
808  $this->content_obj->setCaption(
809  $caption,
810  ilUtil::stripSlashes($_POST["cap_align"])
811  );
812  }
813 
817  public function saveProperties()
818  {
819  $this->setProperties();
820  $this->updated = $this->pg_obj->update();
821  if ($this->updated === true) {
822  $this->ctrl->redirect($this, "edit");
823  //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
824  } else {
825  $this->pg_obj->addHierIDs();
826  $this->edit();
827  }
828  }
829 
833  public function rightAlign()
834  {
835  $this->content_obj->setHorizontalAlign("Right");
836  $_SESSION["il_pg_error"] = $this->pg_obj->update();
837  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
838  }
839 
843  public function leftAlign()
844  {
845  $this->content_obj->setHorizontalAlign("Left");
846  $_SESSION["il_pg_error"] = $this->pg_obj->update();
847  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
848  }
849 
853  public function centerAlign()
854  {
855  $this->content_obj->setHorizontalAlign("Center");
856  $_SESSION["il_pg_error"] = $this->pg_obj->update();
857  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
858  }
859 
863  public function leftFloatAlign()
864  {
865  $this->content_obj->setHorizontalAlign("LeftFloat");
866  $_SESSION["il_pg_error"] = $this->pg_obj->update();
867  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
868  }
869 
873  public function rightFloatAlign()
874  {
875  $this->content_obj->setHorizontalAlign("RightFloat");
876  $_SESSION["il_pg_error"] = $this->pg_obj->update();
877  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
878  }
879 
883  public function insert()
884  {
887  $tpl = $this->tpl;
888  $lng = $this->lng;
889 
890  $this->displayValidationError();
891 
892  $this->initPropertiesForm("create");
893  $html = $this->form->getHTML();
894  $tpl->setContent($html);
895  }
896 
900  public function getNewTableObject()
901  {
902  return new ilPCTable($this->getPage());
903  }
904 
908  public function create()
909  {
910  global $lng;
911 
912  $this->content_obj = $this->getNewTableObject();
913  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
914  $import_table = trim($_POST["import_table"]);
915 
916  // import xhtml or spreadsheet table
917  if (!empty($import_table)) {
918  switch ($_POST["import_type"]) {
919  // xhtml import
920  case "html":
921  if (!$this->content_obj->importHtml($_POST["language"], $import_table)) {
922  $this->insert();
923  return;
924  }
925  break;
926 
927  // spreadsheet
928  case "spreadsheet":
929  $this->content_obj->importSpreadsheet($_POST["language"], $import_table);
930  break;
931  }
932  } else {
933  $this->content_obj->addRows(
934  ilUtil::stripSlashes($_POST["nr_rows"]),
935  ilUtil::stripSlashes($_POST["nr_cols"])
936  );
937  }
938 
939  $this->setProperties();
940 
941  $frtype = ilUtil::stripSlashes($_POST["first_row_style"]);
942  if ($frtype != "") {
943  $this->content_obj->setFirstRowStyle($frtype);
944  }
945 
946  $this->updated = $this->pg_obj->update();
947 
948  if ($this->updated === true) {
949  $this->afterCreation();
950  } else {
951  $this->insert();
952  }
953  }
954 
958  public function afterCreation()
959  {
960  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
961  }
962 
963 
964  //
965  // Edit cell alignments
966  //
967 
971  public function editCellAlignment()
972  {
974  $tpl = $this->tpl;
975  $lng = $this->lng;
976  $ilTabs = $this->tabs;
977 
978  $this->displayValidationError();
979  $this->setTabs();
980  $this->setCellPropertiesSubTabs();
981  $ilTabs->setSubTabActive("cont_alignment");
982  $ilTabs->setTabActive("cont_table_cell_properties");
983 
984  // edit form
985  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
986  $form = new ilPropertyFormGUI();
987  $form->setFormAction($ilCtrl->getFormAction($this));
988  $form->setTitle($this->lng->txt("cont_table_cell_properties"));
989 
990  // alignment
991  $options = array(
992  "" => $lng->txt("default"),
993  "Left" => $lng->txt("cont_left"),
994  "Center" => $lng->txt("cont_center"),
995  "Right" => $lng->txt("cont_right")
996  );
997  $si = new ilSelectInputGUI($lng->txt("cont_alignment"), "alignment");
998  $si->setOptions($options);
999  $si->setInfo($lng->txt(""));
1000  $form->addItem($si);
1001 
1002  $form->setKeepOpen(true);
1003 
1004  $form->addCommandButton("setAlignment", $lng->txt("cont_set_alignment"));
1005 
1006  $html = $form->getHTML();
1007  $html.= "<br />" . $this->renderTable("table_edit", "alignment") . "</form>";
1008  $tpl->setContent($html);
1009  }
1010 
1014  public function setAlignment()
1015  {
1016  $lng = $this->lng;
1017 
1018  if (is_array($_POST["target"])) {
1019  foreach ($_POST["target"] as $k => $value) {
1020  if ($value > 0) {
1021  $cid = explode(":", $k);
1022  $this->content_obj->setTDAlignment(
1023  ilUtil::stripSlashes($cid[0]),
1024  ilUtil::stripSlashes($_POST["alignment"]),
1025  ilUtil::stripSlashes($cid[1])
1026  );
1027  }
1028  }
1029  }
1030  $this->updated = $this->pg_obj->update();
1031  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1032 
1033  $this->ctrl->redirect($this, "editCellAlignment");
1034  }
1035 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
$params
Definition: disable.php:11
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.
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
This class represents a hidden form property in a property form.
static _renderTable($content, $a_mode="table_edit", $a_submode="", $a_table_obj=null, $unmask=true)
Static render table function.
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)
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.
Create styles array
The data for the language used.
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
$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
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.
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
editCellAlignment()
Edit cell styles.