ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
19 
24  function ilPCTableGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
25  {
26  parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
27  $this->setCharacteristics(array("StandardTable" => $this->lng->txt("cont_StandardTable")));
28 
29  }
30 
35  {
36  $this->setCharacteristics(array("Cell1" => "Cell1", "Cell2" => "Cell2",
37  "Cell3" => "Cell3", "Cell4" => "Cell4"));
38  }
39 
43  function &executeCommand()
44  {
45  $this->getCharacteristicsOfCurrentStyle("table"); // scorm-2004
46 
47  // get next class that processes or forwards current command
48  $next_class = $this->ctrl->getNextClass($this);
49 
50  // get current command
51  $cmd = $this->ctrl->getCmd();
52 
53  switch($next_class)
54  {
55  default:
56  $ret =& $this->$cmd();
57  break;
58  }
59 
60  return $ret;
61  }
62 
63 
67  function setTabs()
68  {
69  global $ilTabs, $ilCtrl, $lng;
70 
71  $ilTabs->setBackTarget($lng->txt("pg"),
72  $this->ctrl->getParentReturn($this));
73 
74  $ilTabs->addTarget("cont_table_properties",
75  $ilCtrl->getLinkTarget($this, "edit"), "edit",
76  get_class($this));
77 
78  $ilTabs->addTarget("cont_table_cell_properties",
79  $ilCtrl->getLinkTarget($this, "editCellStyle"), "editCellStyle",
80  get_class($this));
81 
82  }
83 
88  {
89  global $ilTabs, $ilCtrl, $lng;
90 
91  $ilTabs->addSubTabTarget("cont_style",
92  $ilCtrl->getLinkTarget($this, "editCellStyle"), "editCellStyle",
93  get_class($this));
94 
95  $ilTabs->addSubTabTarget("cont_width",
96  $ilCtrl->getLinkTarget($this, "editCellWidth"), "editCellWidth",
97  get_class($this));
98 
99  $ilTabs->addSubTabTarget("cont_alignment",
100  $ilCtrl->getLinkTarget($this, "editCellAlignment"), "editCellAlignment",
101  get_class($this));
102 
103  $ilTabs->addSubTabTarget("cont_span",
104  $ilCtrl->getLinkTarget($this, "editCellSpan"), "editCellSpan",
105  get_class($this));
106 
107  }
108 
113  {
114  return parent::getTemplateOptions("table");
115  }
116 
120  function edit()
121  {
122  global $ilCtrl, $lng, $tpl;
123 
124  $this->displayValidationError();
125  $this->setTabs();
126 
127  $this->initPropertiesForm();
128  $this->getPropertiesFormValues();
129  $html = $this->form->getHTML();
130  $html.= "<br />".$this->renderTable("");
131  $tpl->setContent($html);
132  }
133 
137  function initPropertiesForm($a_mode = "edit")
138  {
139  global $ilCtrl, $lng, $tpl, $ilUser;
140 
141  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
142  $this->form = new ilPropertyFormGUI();
143  $this->form->setFormAction($ilCtrl->getFormAction($this));
144  if ($a_mode == "create")
145  {
146  $this->form->setTitle($this->lng->txt("cont_insert_table"));
147  }
148  else
149  {
150  $this->form->setTitle($this->lng->txt("cont_table_properties"));
151  }
152 
153  if ($a_mode == "create")
154  {
155  $nr = array();
156  for($i=1; $i<=20; $i++)
157  {
158  $nr[$i] = $i;
159  }
160 
161  // cols
162  $cols = new ilSelectInputGUI($this->lng->txt("cont_nr_cols"), "nr_cols");
163  $cols->setOptions($nr);
164  $cols->setValue(2);
165  $this->form->addItem($cols);
166 
167  // rows
168  $rows = new ilSelectInputGUI($this->lng->txt("cont_nr_rows"), "nr_rows");
169  $rows->setOptions($nr);
170  $rows->setValue(2);
171  $this->form->addItem($rows);
172  }
173 
174  // width
175  $width = new ilTextInputGUI($this->lng->txt("cont_table_width"), "width");
176  $width->setSize(6);
177  $width->setMaxLength(6);
178  $this->form->addItem($width);
179 
180  // border
181  $border = new ilTextInputGUI($this->lng->txt("cont_table_border"), "border");
182  $border->setValue("1px");
183  $border->setSize(6);
184  $border->setMaxLength(6);
185  $this->form->addItem($border);
186 
187  // padding
188  $padding = new ilTextInputGUI($this->lng->txt("cont_table_cellpadding"), "padding");
189  $padding->setValue("2px");
190  $padding->setSize(6);
191  $padding->setMaxLength(6);
192  $this->form->addItem($padding);
193 
194  // spacing (deprecated, only hidden)
195  $spacing = new ilHiddenInputGUI("spacing");
196  $spacing->setValue("0px");
197  $this->form->addItem($spacing);
198  /*$spacing = new ilTextInputGUI($this->lng->txt("cont_table_cellspacing"), "spacing");
199  $spacing->setValue("0px");
200  $spacing->setSize(6);
201  $spacing->setMaxLength(6);
202  $this->form->addItem($spacing);*/
203 
204  // table templates and table classes
205  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
206  $char_prop = new ilAdvSelectInputGUI($this->lng->txt("cont_characteristic"),
207  "characteristic");
208  $chars = $this->getCharacteristics();
209  $templates = $this->getTemplateOptions();
210  $chars = array_merge($templates, $chars);
211  if (is_object($this->content_obj))
212  {
213  if ($chars[$a_seleted_value] == "" && ($this->content_obj->getClass() != ""))
214  {
215  $chars = array_merge(
216  array($this->content_obj->getClass() => $this->content_obj->getClass()),
217  $chars);
218  }
219  }
220  foreach($chars as $k => $char)
221  {
222  if (strpos($k, ":") > 0)
223  {
224  $t = explode(":", $k);
225  $html = $this->style->lookupTemplatePreview($t[1]).'<div style="clear:both;" class="small">'.$char."</div>";
226  }
227  else
228  {
229  $html = '<table class="ilc_table_'.$k.'"><tr><td class="small">'.
230  $char.'</td></tr></table>';
231  }
232  $char_prop->addOption($k, $char, $html);
233  }
234  $char_prop->setValue("StandardTable");
235  $this->form->addItem($char_prop);
236 
237  $nr = array();
238  for($i=0; $i<=3; $i++)
239  {
240  $nr[$i] = $i;
241  }
242 
243  // row header
244  $rh = new ilSelectInputGUI($this->lng->txt("cont_nr_row_header"), "row_header");
245  $rh->setOptions($nr);
246  $rh->setValue(1);
247  $this->form->addItem($rh);
248 
249  // row footer
250  $rf = new ilSelectInputGUI($this->lng->txt("cont_nr_row_footer"), "row_footer");
251  $rf->setOptions($nr);
252  $rf->setValue(0);
253  $this->form->addItem($rf);
254 
255  // col header
256  $ch = new ilSelectInputGUI($this->lng->txt("cont_nr_col_header"), "col_header");
257  $ch->setOptions($nr);
258  $ch->setValue(0);
259  $this->form->addItem($ch);
260 
261  // col footer
262  $cf = new ilSelectInputGUI($this->lng->txt("cont_nr_col_footer"), "col_footer");
263  $cf->setOptions($nr);
264  $cf->setValue(0);
265  $this->form->addItem($cf);
266 
267  if ($a_mode == "create")
268  {
269  // first row style
270  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
271  $fr_style = new ilAdvSelectInputGUI($this->lng->txt("cont_first_row_style"),
272  "first_row_style");
273  $this->setBasicTableCellStyles();
274  $this->getCharacteristicsOfCurrentStyle("table_cell");
275  $chars = $this->getCharacteristics();
276  $options = array_merge(array("" => $this->lng->txt("none")), $chars);
277  foreach($options as $k => $option)
278  {
279  $html = '<table border="0" cellspacing="0" cellpadding="0"><tr><td class="ilc_table_cell_'.$k.'">'.
280  $option.'</td></tr></table>';
281  $fr_style->addOption($k, $option, $html);
282  }
283 
284  $fr_style->setValue("");
285  $this->form->addItem($fr_style);
286  }
287 
288  // alignment
289  $align_opts = array("Left" => $lng->txt("cont_left"),
290  "Right" => $lng->txt("cont_right"), "Center" => $lng->txt("cont_center"),
291  "LeftFloat" => $lng->txt("cont_left_float"),
292  "RightFloat" => $lng->txt("cont_right_float"));
293  $align = new ilSelectInputGUI($this->lng->txt("cont_align"), "align");
294  $align->setOptions($align_opts);
295  $align->setValue("Center");
296  $this->form->addItem($align);
297 
298  // caption
299  $caption = new ilTextInputGUI($this->lng->txt("cont_caption"), "caption");
300  $caption->setSize(60);
301  $this->form->addItem($caption);
302 
303  // caption align
304  $ca_opts = array("top" => $lng->txt("cont_top"),
305  "bottom" => $lng->txt("cont_bottom"));
306  $ca = new ilSelectInputGUI($this->lng->txt("cont_align"),
307  "cap_align");
308  $ca->setOptions($ca_opts);
309  $caption->addSubItem($ca);
310 
311  // import
312  if ($a_mode == "create")
313  {
314  // import table
315  $import = new ilRadioGroupInputGUI($this->lng->txt("cont_paste_table"), "import_type");
316  $op = new ilRadioOption($this->lng->txt("cont_html_table"), "html");
317  $import->addOption($op);
318  $op2 = new ilRadioOption($this->lng->txt("cont_spreadsheet_table"), "spreadsheet");
319 
320  $import_data = new ilTextAreaInputGUI("", "import_table");
321  $import_data->setRows(8);
322  $import_data->setCols(50);
323  $op2->addSubItem($import_data);
324 
325  $import->addOption($op2);
326  $import->setValue("html");
327  $this->form->addItem($import);
328  }
329 
330  // language
331  if ($_SESSION["il_text_lang_".$_GET["ref_id"]] != "")
332  {
333  $s_lang = $_SESSION["il_text_lang_".$_GET["ref_id"]];
334  }
335  else
336  {
337  $s_lang = $ilUser->getLanguage();
338  }
339  require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
341  $language = new ilSelectInputGUI($this->lng->txt("language"), "language");
342  $language->setOptions($lang);
343  $language->setValue($s_lang);
344  $this->form->addItem($language);
345 
346  if ($a_mode == "create")
347  {
348  $this->form->addCommandButton("create_tab", $lng->txt("save"));
349  $this->form->addCommandButton("cancelCreate", $lng->txt("cancel"));
350  }
351  else
352  {
353  $this->form->addCommandButton("saveProperties", $lng->txt("save"));
354  }
355  }
356 
361  {
362  $values = array();
363  $values["width"] = $this->content_obj->getWidth();
364  $values["border"] = $this->content_obj->getBorder();
365  $values["padding"] = $this->content_obj->getCellPadding();
366  $values["spacing"] = $this->content_obj->getCellSpacing();
367  $values["row_header"] = $this->content_obj->getHeaderRows();
368  $values["row_footer"] = $this->content_obj->getFooterRows();
369  $values["col_header"] = $this->content_obj->getHeaderCols();
370  $values["col_footer"] = $this->content_obj->getFooterCols();
371  if ($this->content_obj->getTemplate() != "")
372  {
373  $values["characteristic"] = "t:".
374  ilObjStyleSheet::_lookupTemplateIdByName($this->getStyleId(), $this->content_obj->getTemplate()).":".
375  $this->content_obj->getTemplate();
376  }
377  else
378  {
379  $values["characteristic"] = $this->content_obj->getClass();
380  }
381  $values["align"] = $this->content_obj->getHorizontalAlign();
382  $values["caption"] = $this->content_obj->getCaption();
383  $values["cap_align"] = $this->content_obj->getCaptionAlign();
384  $values["language"] = $this->content_obj->getLanguage();
385 
386  $this->form->setValuesByArray($values);
387 
388  $ca = $this->form->getItemByPostVar("cap_align");
389  $ca->setValue($this->content_obj->getCaptionAlign());
390  }
391 
395  function renderTable($a_mode = "table_edit", $a_submode = "")
396  {
397  $tab_node = $this->content_obj->getNode();
398  $tab_node->set_attribute("Enabled", "True");
399  $content = $this->dom->dump_node($tab_node);
400 
401  $trans = $this->pg_obj->getLanguageVariablesXML();
402  $mobs = $this->pg_obj->getMultimediaXML();
403  if ($this->getStyleId() > 0)
404  {
405  if (ilObject::_lookupType($this->getStyleId()) == "sty")
406  {
407  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
408  $style = new ilObjStyleSheet($this->getStyleId());
409  $template_xml = $style->getTemplateXML();
410  }
411  }
412 
413  $content = $content.$mobs.$trans.$template_xml;
414 
415  return ilPCTableGUI::_renderTable($content, $a_mode, $a_submode, $this->content_obj);
416  }
417 
421  static function _renderTable($content, $a_mode = "table_edit", $a_submode = "", $a_table_obj = null)
422  {
423  global $ilUser;
424 
425  $content = "<dummy>".$content."</dummy>";
426 
427  $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
428  $args = array( '/_xml' => $content, '/_xsl' => $xsl );
429  $xh = xslt_create();
430 //echo "<b>XML</b>:".htmlentities($content).":<br>";
431 //echo "<b>XSLT</b>:".htmlentities($xsl).":<br>";
432  $med_disabled_path = ilUtil::getImagePath("media_disabled.png");
433  $wb_path = ilUtil::getWebspaceDir("output");
434  $enlarge_path = ilUtil::getImagePath("enlarge.png");
435  $params = array ('mode' => $a_mode,
436  'med_disabled_path' => $med_disabled_path,
437  'media_mode' => $ilUser->getPref("ilPageEditor_MediaMode"),
438  'media_mode' => 'disable',
439  'webspace_path' => $wb_path, 'enlarge_path' => $enlarge_path);
440  $output = xslt_process($xh,"arg:/_xml","arg:/_xsl",NULL,$args, $params);
441  echo xslt_error($xh);
442  xslt_free($xh);
443 
444  // unmask user html
445  $output = str_replace("&lt;","<",$output);
446  $output = str_replace("&gt;",">",$output);
447  $output = str_replace("&amp;","&",$output);
448 
449  if ($a_mode == "table_edit" && !is_null($a_table_obj))
450  {
451  switch ($a_submode)
452  {
453  case "style":
454  $output = ilPCTableGUI::_addStyleCheckboxes($output, $a_table_obj);
455  break;
456 
457  case "alignment":
458  $output = ilPCTableGUI::_addAlignmentCheckboxes($output, $a_table_obj);
459  break;
460 
461  case "width":
462  $output = ilPCTableGUI::_addWidthInputs($output, $a_table_obj);
463  break;
464 
465  case "span":
466  $output = ilPCTableGUI::_addSpanInputs($output, $a_table_obj);
467  break;
468  }
469  }
470 
471 
472  return '<div style="float:left;">'.$output.'</div>';
473  }
474 
478  static function _addStyleCheckboxes($a_output, $a_table)
479  {
480  global $lng;
481 
482  $classes = $a_table->getAllCellClasses();
483 
484  foreach ($classes as $k => $v)
485  {
486  if ($v == "")
487  {
488  $v = $lng->txt("none");
489  }
490  if (substr($v, 0, 4) == "ilc_")
491  {
492  $v = substr($v, 4);
493  }
494  $check = $lng->txt("cont_style").": ".
495  '<input type="checkbox" value="1"'.
496  ' name="target['.$k.']">'.'</input> '.$v;
497 
498  $a_output = str_replace("{{{{{TableEdit;".$k."}}}}}", $check, $a_output);
499  }
500  return $a_output;
501  }
502 
506  static function _addAlignmentCheckboxes($a_output, $a_table)
507  {
508  global $lng;
509 
510  $classes = $a_table->getAllCellAlignments();
511 
512  foreach ($classes as $k => $v)
513  {
514  if ($v == "")
515  {
516  $v = $lng->txt("default");
517  }
518  $check = $lng->txt("cont_alignment").": ".
519  '<input type="checkbox" value="1"'.
520  ' name="target['.$k.']">'.'</input> '.$v;
521 
522  $a_output = str_replace("{{{{{TableEdit;".$k."}}}}}", $check, $a_output);
523  }
524  return $a_output;
525  }
526 
530  static function _addWidthInputs($a_output, $a_table)
531  {
532  global $lng;
533 
534  $widths = $a_table->getAllCellWidths();
535 
536  foreach ($widths as $k => $v)
537  {
538  $check = $lng->txt("cont_width").": ".
539  '<input class="small" type="text" size="5" maxlength="10"'.
540  ' name="width['.$k.']" value="'.$v.'">'.'</input>';
541 
542  $a_output = str_replace("{{{{{TableEdit;".$k."}}}}}", $check, $a_output);
543  }
544  return $a_output;
545  }
546 
550  static function _addSpanInputs($a_output, $a_table)
551  {
552  global $lng;
553 
554  $spans = $a_table->getAllCellSpans();
555 
556  foreach ($spans as $k => $v)
557  {
558  // colspans
559  $selects = '<div style="white-space:nowrap;">'.$lng->txt("cont_colspan").": ".
560  '<select class="small" name="colspan['.$k.']">';
561  for ($i = 1; $i <= $v["max_x"] - $v["x"] + 1; $i++)
562  {
563  $sel_str = ($i == $v["colspan"])
564  ? 'selected="selected"'
565  : '';
566  $selects.= '<option value="'.$i.'" '.$sel_str.'>'.$i.'</option>';
567  }
568  $selects.= "</select></div>";
569 
570  // rowspans
571  $selects.= '<div style="margin-top:3px; white-space:nowrap;">'.$lng->txt("cont_rowspan").": ".
572  '<select class="small" name="rowspan['.$k.']">';
573  for ($i = 1; $i <= $v["max_y"] - $v["y"] + 1; $i++)
574  {
575  $sel_str = ($i == $v["rowspan"])
576  ? 'selected="selected"'
577  : '';
578  $selects.= '<option value="'.$i.'" '.$sel_str.'>'.$i.'</option>';
579  }
580  $selects.= "</select></div>";
581 
582  $a_output = str_replace("{{{{{TableEdit;".$k."}}}}}", $selects, $a_output);
583  }
584  return $a_output;
585  }
586 
590  function editCellStyle()
591  {
592  global $ilCtrl, $tpl, $lng, $ilTabs;
593 
594  $this->displayValidationError();
595  $this->setTabs();
596  $this->setCellPropertiesSubTabs();
597  $ilTabs->setSubTabActive("cont_style");
598 
599  // edit form
600  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
601  $form = new ilPropertyFormGUI();
602  $form->setFormAction($ilCtrl->getFormAction($this));
603  $form->setTitle($this->lng->txt("cont_table_cell_properties"));
604 
605  // first row style
606  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
607  $style = new ilAdvSelectInputGUI($this->lng->txt("cont_style"),
608  "style");
609  $this->setBasicTableCellStyles();
610  $this->getCharacteristicsOfCurrentStyle("table_cell"); // scorm-2004
611  $chars = $this->getCharacteristics(); // scorm-2004
612  $options = array_merge(array("" => $this->lng->txt("none")), $chars); // scorm-2004
613  foreach($options as $k => $option)
614  {
615  $html = '<table border="0" cellspacing="0" cellpadding="0"><tr><td class="ilc_table_cell_'.$k.'">'.
616  $option.'</td></tr></table>';
617  $style->addOption($k, $option, $html);
618  }
619 
620  $style->setValue("");
621  $style->setInfo($lng->txt("cont_set_tab_style_info"));
622  $form->addItem($style);
623  $form->setKeepOpen(true);
624 
625  $form->addCommandButton("setStyles", $lng->txt("cont_set_styles"));
626 
627  $html = $form->getHTML();
628  $html.= "<br />".$this->renderTable("table_edit", "style")."</form>";
629  $tpl->setContent($html);
630 
631  }
632 
636  function editCellWidth()
637  {
638  global $ilCtrl, $tpl, $lng, $ilTabs;
639 
640  $this->displayValidationError();
641  $this->setTabs();
642  $this->setCellPropertiesSubTabs();
643  $ilTabs->setSubTabActive("cont_width");
644  $ilTabs->setTabActive("cont_table_cell_properties");
645 
646  $ctpl = new ilTemplate("tpl.table_cell_properties.html", true, true, "Services/COPage");
647  $ctpl->setVariable("BTN_NAME", "setWidths");
648  $ctpl->setVariable("BTN_TEXT", $lng->txt("cont_save_widths"));
649  $ctpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
650 
651  $html = $ctpl->get();
652  $html.= "<br />".$this->renderTable("table_edit", "width")."</form>";
653  $tpl->setContent($html);
654 
655  }
656 
660  function editCellSpan()
661  {
662  global $ilCtrl, $tpl, $lng, $ilTabs;
663 
664  $this->displayValidationError();
665  $this->setTabs();
666  $this->setCellPropertiesSubTabs();
667  $ilTabs->setSubTabActive("cont_span");
668  $ilTabs->setTabActive("cont_table_cell_properties");
669 
670  $ctpl = new ilTemplate("tpl.table_cell_properties.html", true, true, "Services/COPage");
671  $ctpl->setVariable("BTN_NAME", "setSpans");
672  $ctpl->setVariable("BTN_TEXT", $lng->txt("cont_save_spans"));
673  $ctpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
674 
675  $html = $ctpl->get();
676  $html.= "<br />".$this->renderTable("table_edit", "span")."</form>";
677  $tpl->setContent($html);
678 
679  }
680 
684  function setStyles()
685  {
686  global $lng;
687 
688  if (is_array($_POST["target"]))
689  {
690  foreach ($_POST["target"] as $k => $value)
691  {
692  if ($value > 0)
693  {
694  $cid = explode(":", $k);
695  $this->content_obj->setTDClass(ilUtil::stripSlashes($cid[0]),
696  ilUtil::stripSlashes($_POST["style"]), ilUtil::stripSlashes($cid[1]));
697  }
698  }
699  }
700  $this->updated = $this->pg_obj->update();
701  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
702  $this->ctrl->redirect($this, "editCellStyle");
703  }
704 
708  function setWidths()
709  {
710  global $lng;
711 
712  if (is_array($_POST["width"]))
713  {
714  foreach ($_POST["width"] as $k => $width)
715  {
716  $cid = explode(":", $k);
717  $this->content_obj->setTDWidth(ilUtil::stripSlashes($cid[0]),
718  ilUtil::stripSlashes($width), ilUtil::stripSlashes($cid[1]));
719  }
720  }
721  $this->updated = $this->pg_obj->update();
722  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
723  $this->ctrl->redirect($this, "editCellWidth");
724  }
725 
729  function setSpans()
730  {
731  global $lng;
732 
733  if (is_array($_POST["colspan"]))
734  {
735  foreach ($_POST["colspan"] as $k => $span)
736  {
737  $_POST["colspan"][$k] = ilUtil::stripSlashes($span);
738  $_POST["rowspan"][$k] = ilUtil::stripSlashes($_POST["rowspan"][$k]);
739  }
740  $this->content_obj->setTDSpans($_POST["colspan"], $_POST["rowspan"]);
741  }
742  $this->updated = $this->pg_obj->update();
743  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
744  $this->ctrl->redirect($this, "editCellSpan");
745  }
746 
750  function setProperties()
751  {
752  // mask html
753  $caption = ilUtil::stripSlashes($_POST["caption"]);
754  $caption = str_replace("&","&amp;", $caption);
755  $caption = str_replace("<","&lt;", $caption);
756  $caption = str_replace(">","&gt;", $caption);
757 
758  $this->content_obj->setLanguage(ilUtil::stripSlashes($_POST["language"]));
759  $this->content_obj->setWidth(ilUtil::stripSlashes($_POST["width"]));
760  $this->content_obj->setBorder(ilUtil::stripSlashes($_POST["border"]));
761  $this->content_obj->setCellSpacing(ilUtil::stripSlashes($_POST["spacing"]));
762  $this->content_obj->setCellPadding(ilUtil::stripSlashes($_POST["padding"]));
763  $this->content_obj->setHorizontalAlign(ilUtil::stripSlashes($_POST["align"]));
764  $this->content_obj->setHeaderRows(ilUtil::stripSlashes($_POST["row_header"]));
765  $this->content_obj->setHeaderCols(ilUtil::stripSlashes($_POST["col_header"]));
766  $this->content_obj->setFooterRows(ilUtil::stripSlashes($_POST["row_footer"]));
767  $this->content_obj->setFooterCols(ilUtil::stripSlashes($_POST["col_footer"]));
768  if (strpos($_POST["characteristic"], ":") > 0)
769  {
770  $t = explode(":", $_POST["characteristic"]);
771  $this->content_obj->setTemplate(ilUtil::stripSlashes($t[2]));
772  $this->content_obj->setClass("");
773  }
774  else
775  {
776  $this->content_obj->setClass(ilUtil::stripSlashes($_POST["characteristic"]));
777  $this->content_obj->setTemplate("");
778  }
779  $this->content_obj->setCaption($caption,
780  ilUtil::stripSlashes($_POST["cap_align"]));
781  }
782 
786  function saveProperties()
787  {
788  $this->setProperties();
789  $this->updated = $this->pg_obj->update();
790  if ($this->updated === true)
791  {
792  $this->ctrl->redirect($this, "edit");
793  //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
794  }
795  else
796  {
797  $this->pg_obj->addHierIDs();
798  $this->edit();
799  }
800  }
801 
805  function rightAlign()
806  {
807  $this->content_obj->setHorizontalAlign("Right");
808  $_SESSION["il_pg_error"] = $this->pg_obj->update();
809  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
810  }
811 
815  function leftAlign()
816  {
817  $this->content_obj->setHorizontalAlign("Left");
818  $_SESSION["il_pg_error"] = $this->pg_obj->update();
819  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
820  }
821 
825  function centerAlign()
826  {
827  $this->content_obj->setHorizontalAlign("Center");
828  $_SESSION["il_pg_error"] = $this->pg_obj->update();
829  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
830  }
831 
835  function leftFloatAlign()
836  {
837  $this->content_obj->setHorizontalAlign("LeftFloat");
838  $_SESSION["il_pg_error"] = $this->pg_obj->update();
839  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
840  }
841 
845  function rightFloatAlign()
846  {
847  $this->content_obj->setHorizontalAlign("RightFloat");
848  $_SESSION["il_pg_error"] = $this->pg_obj->update();
849  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
850  }
851 
855  function insert()
856  {
857  global $ilUser, $ilCtrl, $tpl, $lng;
858 
859  $this->displayValidationError();
860 
861  $this->initPropertiesForm("create");
862  $html = $this->form->getHTML();
863  $tpl->setContent($html);
864  }
865 
869  function getNewTableObject()
870  {
871  return new ilPCTable($this->dom);
872  }
873 
877  function create()
878  {
879  global $lng;
880 
881  $this->content_obj = $this->getNewTableObject();
882  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
883  $import_table = trim($_POST["import_table"]);
884 
885  // import xhtml or spreadsheet table
886  if (!empty ($import_table))
887  {
888  switch($_POST["import_type"])
889  {
890  // xhtml import
891  case "html":
892  if (!$this->content_obj->importHtml ($_POST["language"], $import_table))
893  {
894  $this->insert();
895  return;
896  }
897  break;
898 
899  // spreadsheet
900  case "spreadsheet":
901  $this->content_obj->importSpreadsheet($_POST["language"], $import_table);
902  break;
903  }
904  }
905  else
906  {
907  $this->content_obj->addRows(ilUtil::stripSlashes($_POST["nr_rows"]),
908  ilUtil::stripSlashes($_POST["nr_cols"]));
909  }
910 
911  $this->setProperties();
912 
913  $frtype = ilUtil::stripSlashes($_POST["first_row_style"]);
914  if ($frtype != "")
915  {
916  $this->content_obj->setFirstRowStyle($frtype);
917  }
918 
919  $this->updated = $this->pg_obj->update();
920 
921  if ($this->updated === true)
922  {
923  $this->afterCreation();
924  }
925  else
926  {
927  $this->insert();
928  }
929  }
930 
934  function afterCreation()
935  {
936  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
937  }
938 
939 
940  //
941  // Edit cell alignments
942  //
943 
947  function editCellAlignment()
948  {
949  global $ilCtrl, $tpl, $lng, $ilTabs;
950 
951  $this->displayValidationError();
952  $this->setTabs();
953  $this->setCellPropertiesSubTabs();
954  $ilTabs->setSubTabActive("cont_alignment");
955  $ilTabs->setTabActive("cont_table_cell_properties");
956 
957  // edit form
958  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
959  $form = new ilPropertyFormGUI();
960  $form->setFormAction($ilCtrl->getFormAction($this));
961  $form->setTitle($this->lng->txt("cont_table_cell_properties"));
962 
963  // alignment
964  $options = array(
965  "" => $lng->txt("default"),
966  "Left" => $lng->txt("cont_left"),
967  "Center" => $lng->txt("cont_center"),
968  "Right" => $lng->txt("cont_right")
969  );
970  $si = new ilSelectInputGUI($lng->txt("cont_alignment"), "alignment");
971  $si->setOptions($options);
972  $si->setInfo($lng->txt(""));
973  $form->addItem($si);
974 
975  $form->setKeepOpen(true);
976 
977  $form->addCommandButton("setAlignment", $lng->txt("cont_set_alignment"));
978 
979  $html = $form->getHTML();
980  $html.= "<br />".$this->renderTable("table_edit", "alignment")."</form>";
981  $tpl->setContent($html);
982 
983  }
984 
988  function setAlignment()
989  {
990  global $lng;
991 
992  if (is_array($_POST["target"]))
993  {
994  foreach ($_POST["target"] as $k => $value)
995  {
996  if ($value > 0)
997  {
998  $cid = explode(":", $k);
999  $this->content_obj->setTDAlignment(ilUtil::stripSlashes($cid[0]),
1000  ilUtil::stripSlashes($_POST["alignment"]), ilUtil::stripSlashes($cid[1]));
1001  }
1002  }
1003  }
1004  $this->updated = $this->pg_obj->update();
1005  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1006 
1007  $this->ctrl->redirect($this, "editCellAlignment");
1008  }
1009 
1010 
1011 }
1012 ?>