ILIAS  Release_4_2_x_branch Revision 61807
 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
195  $spacing = new ilTextInputGUI($this->lng->txt("cont_table_cellspacing"), "spacing");
196  $spacing->setValue("0px");
197  $spacing->setSize(6);
198  $spacing->setMaxLength(6);
199  $this->form->addItem($spacing);
200 
201  // table templates and table classes
202  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
203  $char_prop = new ilAdvSelectInputGUI($this->lng->txt("cont_characteristic"),
204  "characteristic");
205  $chars = $this->getCharacteristics();
206  $templates = $this->getTemplateOptions();
207  $chars = array_merge($templates, $chars);
208  if (is_object($this->content_obj))
209  {
210  if ($chars[$a_seleted_value] == "" && ($this->content_obj->getClass() != ""))
211  {
212  $chars = array_merge(
213  array($this->content_obj->getClass() => $this->content_obj->getClass()),
214  $chars);
215  }
216  }
217  foreach($chars as $k => $char)
218  {
219  if (strpos($k, ":") > 0)
220  {
221  $t = explode(":", $k);
222  $html = $this->style->lookupTemplatePreview($t[1]).'<div style="clear:both;" class="small">'.$char."</div>";
223  }
224  else
225  {
226  $html = '<table class="ilc_table_'.$k.'"><tr><td class="small">'.
227  $char.'</td></tr></table>';
228  }
229  $char_prop->addOption($k, $char, $html);
230  }
231  $char_prop->setValue("StandardTable");
232  $this->form->addItem($char_prop);
233 
234  $nr = array();
235  for($i=0; $i<=3; $i++)
236  {
237  $nr[$i] = $i;
238  }
239 
240  // row header
241  $rh = new ilSelectInputGUI($this->lng->txt("cont_nr_row_header"), "row_header");
242  $rh->setOptions($nr);
243  $rh->setValue(1);
244  $this->form->addItem($rh);
245 
246  // row footer
247  $rf = new ilSelectInputGUI($this->lng->txt("cont_nr_row_footer"), "row_footer");
248  $rf->setOptions($nr);
249  $rf->setValue(0);
250  $this->form->addItem($rf);
251 
252  // col header
253  $ch = new ilSelectInputGUI($this->lng->txt("cont_nr_col_header"), "col_header");
254  $ch->setOptions($nr);
255  $ch->setValue(0);
256  $this->form->addItem($ch);
257 
258  // col footer
259  $cf = new ilSelectInputGUI($this->lng->txt("cont_nr_col_footer"), "col_footer");
260  $cf->setOptions($nr);
261  $cf->setValue(0);
262  $this->form->addItem($cf);
263 
264  if ($a_mode == "create")
265  {
266  // first row style
267  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
268  $fr_style = new ilAdvSelectInputGUI($this->lng->txt("cont_first_row_style"),
269  "first_row_style");
270  $this->setBasicTableCellStyles();
271  $this->getCharacteristicsOfCurrentStyle("table_cell");
272  $chars = $this->getCharacteristics();
273  $options = array_merge(array("" => $this->lng->txt("none")), $chars);
274  foreach($options as $k => $option)
275  {
276  $html = '<table border="0" cellspacing="0" cellpadding="0"><tr><td class="ilc_table_cell_'.$k.'">'.
277  $option.'</td></tr></table>';
278  $fr_style->addOption($k, $option, $html);
279  }
280 
281  $fr_style->setValue("");
282  $this->form->addItem($fr_style);
283  }
284 
285  // alignment
286  $align_opts = array("Left" => $lng->txt("cont_left"),
287  "Right" => $lng->txt("cont_right"), "Center" => $lng->txt("cont_center"),
288  "LeftFloat" => $lng->txt("cont_left_float"),
289  "RightFloat" => $lng->txt("cont_right_float"));
290  $align = new ilSelectInputGUI($this->lng->txt("cont_align"), "align");
291  $align->setOptions($align_opts);
292  $align->setValue("Center");
293  $this->form->addItem($align);
294 
295  // caption
296  $caption = new ilTextInputGUI($this->lng->txt("cont_caption"), "caption");
297  $caption->setSize(60);
298  $this->form->addItem($caption);
299 
300  // caption align
301  $ca_opts = array("top" => $lng->txt("cont_top"),
302  "bottom" => $lng->txt("cont_bottom"));
303  $ca = new ilSelectInputGUI($this->lng->txt("cont_align"),
304  "cap_align");
305  $ca->setOptions($ca_opts);
306  $caption->addSubItem($ca);
307 
308  // import
309  if ($a_mode == "create")
310  {
311  // import table
312  $import = new ilRadioGroupInputGUI($this->lng->txt("cont_paste_table"), "import_type");
313  $op = new ilRadioOption($this->lng->txt("cont_html_table"), "html");
314  $import->addOption($op);
315  $op2 = new ilRadioOption($this->lng->txt("cont_spreadsheet_table"), "spreadsheet");
316 
317  $import_data = new ilTextAreaInputGUI("", "import_table");
318  $import_data->setRows(8);
319  $import_data->setCols(50);
320  $op2->addSubItem($import_data);
321 
322  $import->addOption($op2);
323  $import->setValue("html");
324  $this->form->addItem($import);
325  }
326 
327  // language
328  if ($_SESSION["il_text_lang_".$_GET["ref_id"]] != "")
329  {
330  $s_lang = $_SESSION["il_text_lang_".$_GET["ref_id"]];
331  }
332  else
333  {
334  $s_lang = $ilUser->getLanguage();
335  }
336  require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
338  $language = new ilSelectInputGUI($this->lng->txt("language"), "language");
339  $language->setOptions($lang);
340  $language->setValue($s_lang);
341  $this->form->addItem($language);
342 
343  if ($a_mode == "create")
344  {
345  $this->form->addCommandButton("create_tab", $lng->txt("save"));
346  $this->form->addCommandButton("cancelCreate", $lng->txt("cancel"));
347  }
348  else
349  {
350  $this->form->addCommandButton("saveProperties", $lng->txt("save"));
351  }
352  }
353 
358  {
359  $values = array();
360  $values["width"] = $this->content_obj->getWidth();
361  $values["border"] = $this->content_obj->getBorder();
362  $values["padding"] = $this->content_obj->getCellPadding();
363  $values["spacing"] = $this->content_obj->getCellSpacing();
364  $values["row_header"] = $this->content_obj->getHeaderRows();
365  $values["row_footer"] = $this->content_obj->getFooterRows();
366  $values["col_header"] = $this->content_obj->getHeaderCols();
367  $values["col_footer"] = $this->content_obj->getFooterCols();
368  if ($this->content_obj->getTemplate() != "")
369  {
370  $values["characteristic"] = "t:".
371  ilObjStyleSheet::_lookupTemplateIdByName($this->getStyleId(), $this->content_obj->getTemplate()).":".
372  $this->content_obj->getTemplate();
373  }
374  else
375  {
376  $values["characteristic"] = $this->content_obj->getClass();
377  }
378  $values["align"] = $this->content_obj->getHorizontalAlign();
379  $values["caption"] = $this->content_obj->getCaption();
380  $values["cap_align"] = $this->content_obj->getCaptionAlign();
381  $values["language"] = $this->content_obj->getLanguage();
382 
383  $this->form->setValuesByArray($values);
384 
385  $ca = $this->form->getItemByPostVar("cap_align");
386  $ca->setValue($this->content_obj->getCaptionAlign());
387  }
388 
392  function renderTable($a_mode = "table_edit", $a_submode = "")
393  {
394  $tab_node = $this->content_obj->getNode();
395  $tab_node->set_attribute("Enabled", "True");
396  $content = $this->dom->dump_node($tab_node);
397 
398  $trans = $this->pg_obj->getLanguageVariablesXML();
399  $mobs = $this->pg_obj->getMultimediaXML();
400  if ($this->getStyleId() > 0)
401  {
402  if (ilObject::_lookupType($this->getStyleId()) == "sty")
403  {
404  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
405  $style = new ilObjStyleSheet($this->getStyleId());
406  $template_xml = $style->getTemplateXML();
407  }
408  }
409 
410  $content = $content.$mobs.$trans.$template_xml;
411 
412  return ilPCTableGUI::_renderTable($content, $a_mode, $a_submode, $this->content_obj);
413  }
414 
418  static function _renderTable($content, $a_mode = "table_edit", $a_submode = "", $a_table_obj = null)
419  {
420  global $ilUser;
421 
422  $content = "<dummy>".$content."</dummy>";
423 
424  $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
425  $args = array( '/_xml' => $content, '/_xsl' => $xsl );
426  $xh = xslt_create();
427 //echo "<b>XML</b>:".htmlentities($content).":<br>";
428 //echo "<b>XSLT</b>:".htmlentities($xsl).":<br>";
429  $med_disabled_path = ilUtil::getImagePath("media_disabled.gif");
430  $wb_path = ilUtil::getWebspaceDir("output");
431  $enlarge_path = ilUtil::getImagePath("enlarge.gif");
432  $params = array ('mode' => $a_mode,
433  'med_disabled_path' => $med_disabled_path,
434  'media_mode' => $ilUser->getPref("ilPageEditor_MediaMode"),
435  'media_mode' => 'disable',
436  'webspace_path' => $wb_path, 'enlarge_path' => $enlarge_path);
437  $output = xslt_process($xh,"arg:/_xml","arg:/_xsl",NULL,$args, $params);
438  echo xslt_error($xh);
439  xslt_free($xh);
440 
441  // unmask user html
442  $output = str_replace("&lt;","<",$output);
443  $output = str_replace("&gt;",">",$output);
444  $output = str_replace("&amp;","&",$output);
445 
446  if ($a_mode == "table_edit" && !is_null($a_table_obj))
447  {
448  switch ($a_submode)
449  {
450  case "style":
451  $output = ilPCTableGUI::_addStyleCheckboxes($output, $a_table_obj);
452  break;
453 
454  case "alignment":
455  $output = ilPCTableGUI::_addAlignmentCheckboxes($output, $a_table_obj);
456  break;
457 
458  case "width":
459  $output = ilPCTableGUI::_addWidthInputs($output, $a_table_obj);
460  break;
461 
462  case "span":
463  $output = ilPCTableGUI::_addSpanInputs($output, $a_table_obj);
464  break;
465  }
466  }
467 
468 
469  return '<div style="float:left;">'.$output.'</div>';
470  }
471 
475  static function _addStyleCheckboxes($a_output, $a_table)
476  {
477  global $lng;
478 
479  $classes = $a_table->getAllCellClasses();
480 
481  foreach ($classes as $k => $v)
482  {
483  if ($v == "")
484  {
485  $v = $lng->txt("none");
486  }
487  if (substr($v, 0, 4) == "ilc_")
488  {
489  $v = substr($v, 4);
490  }
491  $check = $lng->txt("cont_style").": ".
492  '<input type="checkbox" value="1"'.
493  ' name="target['.$k.']">'.'</input> '.$v;
494 
495  $a_output = str_replace("{{{{{TableEdit;".$k."}}}}}", $check, $a_output);
496  }
497  return $a_output;
498  }
499 
503  static function _addAlignmentCheckboxes($a_output, $a_table)
504  {
505  global $lng;
506 
507  $classes = $a_table->getAllCellAlignments();
508 
509  foreach ($classes as $k => $v)
510  {
511  if ($v == "")
512  {
513  $v = $lng->txt("default");
514  }
515  $check = $lng->txt("cont_alignment").": ".
516  '<input type="checkbox" value="1"'.
517  ' name="target['.$k.']">'.'</input> '.$v;
518 
519  $a_output = str_replace("{{{{{TableEdit;".$k."}}}}}", $check, $a_output);
520  }
521  return $a_output;
522  }
523 
527  static function _addWidthInputs($a_output, $a_table)
528  {
529  global $lng;
530 
531  $widths = $a_table->getAllCellWidths();
532 
533  foreach ($widths as $k => $v)
534  {
535  $check = $lng->txt("cont_width").": ".
536  '<input class="small" type="text" size="5" maxlength="10"'.
537  ' name="width['.$k.']" value="'.$v.'">'.'</input>';
538 
539  $a_output = str_replace("{{{{{TableEdit;".$k."}}}}}", $check, $a_output);
540  }
541  return $a_output;
542  }
543 
547  static function _addSpanInputs($a_output, $a_table)
548  {
549  global $lng;
550 
551  $spans = $a_table->getAllCellSpans();
552 
553  foreach ($spans as $k => $v)
554  {
555  // colspans
556  $selects = '<div style="white-space:nowrap;">'.$lng->txt("cont_colspan").": ".
557  '<select class="small" name="colspan['.$k.']">';
558  for ($i = 1; $i <= $v["max_x"] - $v["x"] + 1; $i++)
559  {
560  $sel_str = ($i == $v["colspan"])
561  ? 'selected="selected"'
562  : '';
563  $selects.= '<option value="'.$i.'" '.$sel_str.'>'.$i.'</option>';
564  }
565  $selects.= "</select></div>";
566 
567  // rowspans
568  $selects.= '<div style="margin-top:3px; white-space:nowrap;">'.$lng->txt("cont_rowspan").": ".
569  '<select class="small" name="rowspan['.$k.']">';
570  for ($i = 1; $i <= $v["max_y"] - $v["y"] + 1; $i++)
571  {
572  $sel_str = ($i == $v["rowspan"])
573  ? 'selected="selected"'
574  : '';
575  $selects.= '<option value="'.$i.'" '.$sel_str.'>'.$i.'</option>';
576  }
577  $selects.= "</select></div>";
578 
579  $a_output = str_replace("{{{{{TableEdit;".$k."}}}}}", $selects, $a_output);
580  }
581  return $a_output;
582  }
583 
587  function editCellStyle()
588  {
589  global $ilCtrl, $tpl, $lng, $ilTabs;
590 
591  $this->displayValidationError();
592  $this->setTabs();
593  $this->setCellPropertiesSubTabs();
594  $ilTabs->setSubTabActive("cont_style");
595 
596  // edit form
597  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
598  $form = new ilPropertyFormGUI();
599  $form->setFormAction($ilCtrl->getFormAction($this));
600  $form->setTitle($this->lng->txt("cont_table_cell_properties"));
601 
602  // first row style
603  require_once("./Services/Form/classes/class.ilAdvSelectInputGUI.php");
604  $style = new ilAdvSelectInputGUI($this->lng->txt("cont_style"),
605  "style");
606  $this->setBasicTableCellStyles();
607  $this->getCharacteristicsOfCurrentStyle("table_cell"); // scorm-2004
608  $chars = $this->getCharacteristics(); // scorm-2004
609  $options = array_merge(array("" => $this->lng->txt("none")), $chars); // scorm-2004
610  foreach($options as $k => $option)
611  {
612  $html = '<table border="0" cellspacing="0" cellpadding="0"><tr><td class="ilc_table_cell_'.$k.'">'.
613  $option.'</td></tr></table>';
614  $style->addOption($k, $option, $html);
615  }
616 
617  $style->setValue("");
618  $style->setInfo($lng->txt("cont_set_tab_style_info"));
619  $form->addItem($style);
620  $form->setKeepOpen(true);
621 
622  $form->addCommandButton("setStyles", $lng->txt("cont_set_styles"));
623 
624  $html = $form->getHTML();
625  $html.= "<br />".$this->renderTable("table_edit", "style")."</form>";
626  $tpl->setContent($html);
627 
628  }
629 
633  function editCellWidth()
634  {
635  global $ilCtrl, $tpl, $lng, $ilTabs;
636 
637  $this->displayValidationError();
638  $this->setTabs();
639  $this->setCellPropertiesSubTabs();
640  $ilTabs->setSubTabActive("cont_width");
641  $ilTabs->setTabActive("cont_table_cell_properties");
642 
643  $ctpl = new ilTemplate("tpl.table_cell_properties.html", true, true, "Services/COPage");
644  $ctpl->setVariable("BTN_NAME", "setWidths");
645  $ctpl->setVariable("BTN_TEXT", $lng->txt("cont_save_widths"));
646  $ctpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
647 
648  $html = $ctpl->get();
649  $html.= "<br />".$this->renderTable("table_edit", "width")."</form>";
650  $tpl->setContent($html);
651 
652  }
653 
657  function editCellSpan()
658  {
659  global $ilCtrl, $tpl, $lng, $ilTabs;
660 
661  $this->displayValidationError();
662  $this->setTabs();
663  $this->setCellPropertiesSubTabs();
664  $ilTabs->setSubTabActive("cont_span");
665  $ilTabs->setTabActive("cont_table_cell_properties");
666 
667  $ctpl = new ilTemplate("tpl.table_cell_properties.html", true, true, "Services/COPage");
668  $ctpl->setVariable("BTN_NAME", "setSpans");
669  $ctpl->setVariable("BTN_TEXT", $lng->txt("cont_save_spans"));
670  $ctpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
671 
672  $html = $ctpl->get();
673  $html.= "<br />".$this->renderTable("table_edit", "span")."</form>";
674  $tpl->setContent($html);
675 
676  }
677 
681  function setStyles()
682  {
683  global $lng;
684 
685  if (is_array($_POST["target"]))
686  {
687  foreach ($_POST["target"] as $k => $value)
688  {
689  if ($value > 0)
690  {
691  $cid = explode(":", $k);
692  $this->content_obj->setTDClass(ilUtil::stripSlashes($cid[0]),
693  ilUtil::stripSlashes($_POST["style"]), ilUtil::stripSlashes($cid[1]));
694  }
695  }
696  }
697  $this->updated = $this->pg_obj->update();
698  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
699  $this->ctrl->redirect($this, "editCellStyle");
700  }
701 
705  function setWidths()
706  {
707  global $lng;
708 
709  if (is_array($_POST["width"]))
710  {
711  foreach ($_POST["width"] as $k => $width)
712  {
713  $cid = explode(":", $k);
714  $this->content_obj->setTDWidth(ilUtil::stripSlashes($cid[0]),
715  ilUtil::stripSlashes($width), ilUtil::stripSlashes($cid[1]));
716  }
717  }
718  $this->updated = $this->pg_obj->update();
719  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
720  $this->ctrl->redirect($this, "editCellWidth");
721  }
722 
726  function setSpans()
727  {
728  global $lng;
729 
730  if (is_array($_POST["colspan"]))
731  {
732  foreach ($_POST["colspan"] as $k => $span)
733  {
734  $_POST["colspan"][$k] = ilUtil::stripSlashes($span);
735  $_POST["rowspan"][$k] = ilUtil::stripSlashes($_POST["rowspan"][$k]);
736  }
737  $this->content_obj->setTDSpans($_POST["colspan"], $_POST["rowspan"]);
738  }
739  $this->updated = $this->pg_obj->update();
740  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
741  $this->ctrl->redirect($this, "editCellSpan");
742  }
743 
747  function setProperties()
748  {
749  // mask html
750  $caption = ilUtil::stripSlashes($_POST["caption"]);
751  $caption = str_replace("&","&amp;", $caption);
752  $caption = str_replace("<","&lt;", $caption);
753  $caption = str_replace(">","&gt;", $caption);
754 
755  $this->content_obj->setLanguage(ilUtil::stripSlashes($_POST["language"]));
756  $this->content_obj->setWidth(ilUtil::stripSlashes($_POST["width"]));
757  $this->content_obj->setBorder(ilUtil::stripSlashes($_POST["border"]));
758  $this->content_obj->setCellSpacing(ilUtil::stripSlashes($_POST["spacing"]));
759  $this->content_obj->setCellPadding(ilUtil::stripSlashes($_POST["padding"]));
760  $this->content_obj->setHorizontalAlign(ilUtil::stripSlashes($_POST["align"]));
761  $this->content_obj->setHeaderRows(ilUtil::stripSlashes($_POST["row_header"]));
762  $this->content_obj->setHeaderCols(ilUtil::stripSlashes($_POST["col_header"]));
763  $this->content_obj->setFooterRows(ilUtil::stripSlashes($_POST["row_footer"]));
764  $this->content_obj->setFooterCols(ilUtil::stripSlashes($_POST["col_footer"]));
765  if (strpos($_POST["characteristic"], ":") > 0)
766  {
767  $t = explode(":", $_POST["characteristic"]);
768  $this->content_obj->setTemplate(ilUtil::stripSlashes($t[2]));
769  $this->content_obj->setClass("");
770  }
771  else
772  {
773  $this->content_obj->setClass(ilUtil::stripSlashes($_POST["characteristic"]));
774  $this->content_obj->setTemplate("");
775  }
776  $this->content_obj->setCaption($caption,
777  ilUtil::stripSlashes($_POST["cap_align"]));
778  }
779 
783  function saveProperties()
784  {
785  $this->setProperties();
786  $this->updated = $this->pg_obj->update();
787  if ($this->updated === true)
788  {
789  $this->ctrl->redirect($this, "edit");
790  //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
791  }
792  else
793  {
794  $this->pg_obj->addHierIDs();
795  $this->edit();
796  }
797  }
798 
802  function rightAlign()
803  {
804  $this->content_obj->setHorizontalAlign("Right");
805  $_SESSION["il_pg_error"] = $this->pg_obj->update();
806  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
807  }
808 
812  function leftAlign()
813  {
814  $this->content_obj->setHorizontalAlign("Left");
815  $_SESSION["il_pg_error"] = $this->pg_obj->update();
816  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
817  }
818 
822  function centerAlign()
823  {
824  $this->content_obj->setHorizontalAlign("Center");
825  $_SESSION["il_pg_error"] = $this->pg_obj->update();
826  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
827  }
828 
832  function leftFloatAlign()
833  {
834  $this->content_obj->setHorizontalAlign("LeftFloat");
835  $_SESSION["il_pg_error"] = $this->pg_obj->update();
836  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
837  }
838 
842  function rightFloatAlign()
843  {
844  $this->content_obj->setHorizontalAlign("RightFloat");
845  $_SESSION["il_pg_error"] = $this->pg_obj->update();
846  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
847  }
848 
852  function insert()
853  {
854  global $ilUser, $ilCtrl, $tpl, $lng;
855 
856  $this->displayValidationError();
857 
858  $this->initPropertiesForm("create");
859  $html = $this->form->getHTML();
860  $tpl->setContent($html);
861  }
862 
866  function getNewTableObject()
867  {
868  return new ilPCTable($this->dom);
869  }
870 
874  function create()
875  {
876  global $lng;
877 
878  $this->content_obj = $this->getNewTableObject();
879  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
880  $import_table = trim($_POST["import_table"]);
881 
882  // import xhtml or spreadsheet table
883  if (!empty ($import_table))
884  {
885  switch($_POST["import_type"])
886  {
887  // xhtml import
888  case "html":
889  if (!$this->content_obj->importHtml ($_POST["language"], $import_table))
890  {
891  $this->insert();
892  return;
893  }
894  break;
895 
896  // spreadsheet
897  case "spreadsheet":
898  $this->content_obj->importSpreadsheet($_POST["language"], $import_table);
899  break;
900  }
901  }
902  else
903  {
904  $this->content_obj->addRows(ilUtil::stripSlashes($_POST["nr_rows"]),
905  ilUtil::stripSlashes($_POST["nr_cols"]));
906  }
907 
908  $this->setProperties();
909 
910  $frtype = ilUtil::stripSlashes($_POST["first_row_style"]);
911  if ($frtype != "")
912  {
913  $this->content_obj->setFirstRowStyle($frtype);
914  }
915 
916  $this->updated = $this->pg_obj->update();
917 
918  if ($this->updated === true)
919  {
920  $this->afterCreation();
921  }
922  else
923  {
924  $this->insert();
925  }
926  }
927 
931  function afterCreation()
932  {
933  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
934  }
935 
936 
937  //
938  // Edit cell alignments
939  //
940 
944  function editCellAlignment()
945  {
946  global $ilCtrl, $tpl, $lng, $ilTabs;
947 
948  $this->displayValidationError();
949  $this->setTabs();
950  $this->setCellPropertiesSubTabs();
951  $ilTabs->setSubTabActive("cont_alignment");
952  $ilTabs->setTabActive("cont_table_cell_properties");
953 
954  // edit form
955  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
956  $form = new ilPropertyFormGUI();
957  $form->setFormAction($ilCtrl->getFormAction($this));
958  $form->setTitle($this->lng->txt("cont_table_cell_properties"));
959 
960  // alignment
961  $options = array(
962  "" => $lng->txt("default"),
963  "Left" => $lng->txt("cont_left"),
964  "Center" => $lng->txt("cont_center"),
965  "Right" => $lng->txt("cont_right")
966  );
967  $si = new ilSelectInputGUI($lng->txt("cont_alignment"), "alignment");
968  $si->setOptions($options);
969  $si->setInfo($lng->txt(""));
970  $form->addItem($si);
971 
972  $form->setKeepOpen(true);
973 
974  $form->addCommandButton("setAlignment", $lng->txt("cont_set_alignment"));
975 
976  $html = $form->getHTML();
977  $html.= "<br />".$this->renderTable("table_edit", "alignment")."</form>";
978  $tpl->setContent($html);
979 
980  }
981 
985  function setAlignment()
986  {
987  global $lng;
988 
989  if (is_array($_POST["target"]))
990  {
991  foreach ($_POST["target"] as $k => $value)
992  {
993  if ($value > 0)
994  {
995  $cid = explode(":", $k);
996  $this->content_obj->setTDAlignment(ilUtil::stripSlashes($cid[0]),
997  ilUtil::stripSlashes($_POST["alignment"]), ilUtil::stripSlashes($cid[1]));
998  }
999  }
1000  }
1001  $this->updated = $this->pg_obj->update();
1002  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1003 
1004  $this->ctrl->redirect($this, "editCellAlignment");
1005  }
1006 
1007 
1008 }
1009 ?>