24 require_once(
"./Services/COPage/classes/class.ilPageContent.php");
53 $this->tab_node =& $a_node->first_child();
56 function create(&$a_pg_obj, $a_hier_id, $a_pc_id =
"")
60 $this->tab_node =& $this->dom->create_element(
"Table");
61 $this->tab_node =& $this->node->append_child($this->tab_node);
62 $this->tab_node->set_attribute(
"Language",
"");
66 $new_tr =& $this->dom->create_element(
"TableRow");
67 $new_tr = &$this->tab_node->append_child($new_tr);
71 function &
addCell (&$aRow, $a_data =
"", $a_lang =
"")
73 $new_td =& $this->dom->create_element(
"TableData");
74 $new_td =& $aRow->append_child($new_td);
80 $new_par =& $this->dom->create_element(
"Paragraph");
81 $new_par =& $new_pg->append_child($new_par);
82 $new_par->set_attribute(
"Language", $a_lang);
83 $new_par->set_attribute(
"Characteristic",
"TableContent");
84 $new_par->set_content($a_data);
85 $new_td->append_child ($new_pg);
96 for ($i=1; $i<=$a_nr_rows; $i++)
99 for ($j=1; $j<=$a_nr_cols; $j++)
111 str_replace($a_data,
"\r",
"\n");
112 str_replace($a_data,
"\n\n",
"\n");
113 $target_rows = array();
114 $rows = explode(
"\n", $a_data);
118 foreach($rows as
$row)
120 $cells = explode(
"\t", $row);
121 $max_cols = ($max_cols > count($cells))
124 $target_rows[] = $cells;
128 foreach($target_rows as $row)
131 for ($j=0; $j<$max_cols; $j++)
134 $data = str_replace(
"&",
"&", $row[$j]);
241 $this->tab_node->set_attribute(
"HorizontalAlign", $a_halign);
261 $path =
"//TableData[@HierId = '".$a_hier_id.
"']";
265 $path =
"//TableData[@PCID = '".$a_pc_id.
"']";
269 if (count(
$res->nodeset) == 1)
273 $res->nodeset[0]->set_attribute(
"Width", $a_width);
277 if (
$res->nodeset[0]->has_attribute(
"Width"))
279 $res->nodeset[0]->remove_attribute(
"Width");
291 $rows = $this->tab_node->child_nodes();
292 foreach($rows as
$row)
294 if ($row->node_name() ==
"TableRow")
297 $cells = $row->child_nodes();
298 foreach($cells as $cell)
300 if ($cell->node_name() ==
"TableData")
302 $ckey = $cell->get_attribute(
"HierId").
":".$cell->get_attribute(
"PCID");
303 if((
int) $a_colspans[$ckey] > 1)
305 $cell->set_attribute(
"ColSpan", (
int) $a_colspans[$ckey]);
309 if ($cell->has_attribute(
"ColSpan"))
311 $cell->remove_attribute(
"ColSpan");
314 if((
int) $a_rowspans[$ckey] > 1)
316 $cell->set_attribute(
"RowSpan", (
int) $a_rowspans[$ckey]);
320 if ($cell->has_attribute(
"RowSpan"))
322 $cell->remove_attribute(
"RowSpan");
345 $rows = $this->tab_node->child_nodes();
347 foreach($rows as
$row)
349 if ($row->node_name() ==
"TableRow")
352 $cells = $row->child_nodes();
353 foreach($cells as $cell)
355 if ($cell->node_name() ==
"TableData")
357 $max_x = max ($max_x,
$x);
358 $max_y = max ($max_y,
$y);
368 $rows = $this->tab_node->child_nodes();
369 foreach($rows as $row)
371 if ($row->node_name() ==
"TableRow")
374 $cells = $row->child_nodes();
375 foreach($cells as $cell)
377 if ($cell->node_name() ==
"TableData")
379 $cspan = max(1, (
int) $cell->get_attribute(
"ColSpan"));
380 $rspan = max(1, (
int) $cell->get_attribute(
"RowSpan"));
383 if ($cspan > $max_x -
$x + 1)
385 $cell->set_attribute(
"ColSpan", $max_x -
$x + 1);
386 $cspan = $max_x -
$x + 1;
388 if ($rspan > $max_y -
$y + 1)
390 $cell->set_attribute(
"RowSpan", $max_y -
$y + 1);
391 $rspan = $max_y -
$y + 1;
398 $cell->set_attribute(
"Hidden",
"Y");
401 if ($cell->has_attribute(
"ColSpan"))
403 $cell->remove_attribute(
"ColSpan");
405 if ($cell->has_attribute(
"RowSpan"))
407 $cell->remove_attribute(
"RowSpan");
414 if ($cell->has_attribute(
"Hidden"))
416 $cell->remove_attribute(
"Hidden");
420 $colspans[
$x][
$y] = $cspan;
421 $rowspans[
$x][
$y] = $rspan;
438 $children = $td_node->child_nodes();
439 for($i=0; $i<count($children); $i++)
441 $td_node->remove_child($children[$i]);
450 for ($i = 0; $i<=
$x; $i++)
452 for ($j = 0; $j<=
$y; $j++)
454 if ($i !=
$x || $j !=
$y)
456 if ((($i + $colspans[$i][$j] >
$x) &&
457 ($j + $rowspans[$i][$j] >
$y)))
475 $rows = $this->tab_node->child_nodes();
476 foreach($rows as
$row)
478 if ($row->node_name() ==
"TableRow")
480 $cells = $row->child_nodes();
481 foreach($cells as $cell)
483 if ($cell->node_name() ==
"TableData")
485 $classes[$cell->get_attribute(
"HierId").
":".$cell->get_attribute(
"PCID")]
486 = $cell->get_attribute(
"Class");
504 $rows = $this->tab_node->child_nodes();
508 foreach($rows as
$row)
510 if ($row->node_name() ==
"TableRow")
513 $cells = $row->child_nodes();
514 foreach($cells as $cell)
516 if ($cell->node_name() ==
"TableData")
518 $spans[$cell->get_attribute(
"HierId").
":".$cell->get_attribute(
"PCID")]
519 = array(
"x" =>
$x,
"y" =>
$y,
"colspan" => $cell->get_attribute(
"ColSpan"),
520 "rowspan" => $cell->get_attribute(
"RowSpan"));
521 $max_x = max($max_x,
$x);
522 $max_y = max($max_y,
$y);
529 foreach ($spans as $k => $v)
531 $spans[$k][
"max_x"] = $max_x;
532 $spans[$k][
"max_y"] = $max_y;
546 $rows = $this->tab_node->child_nodes();
547 foreach($rows as
$row)
549 if ($row->node_name() ==
"TableRow")
551 $cells = $row->child_nodes();
552 foreach($cells as $cell)
554 if ($cell->node_name() ==
"TableData")
556 $widths[$cell->get_attribute(
"HierId").
":".$cell->get_attribute(
"PCID")]
557 = $cell->get_attribute(
"Width");
574 $path =
"//TableData[@HierId = '".$a_hier_id.
"']";
578 $path =
"//TableData[@PCID = '".$a_pc_id.
"']";
581 if (count(
$res->nodeset) == 1)
585 $res->nodeset[0]->set_attribute(
"Class", $a_class);
589 if (
$res->nodeset[0]->has_attribute(
"Class"))
591 $res->nodeset[0]->remove_attribute(
"Class");
606 $path =
"//PageContent[@HierId = '".$hier_id.
"']/Table/Caption";
609 if (count(
$res->nodeset) == 1)
611 return $res->nodeset[0]->get_content();
625 $path =
"//PageContent[@HierId = '".$hier_id.
"']/Table/Caption";
627 if (count(
$res->nodeset) == 1)
629 return $res->nodeset[0]->get_attribute(
"Align");
639 if ($a_content !=
"")
642 array(
"Summary",
"TableRow"), $a_content,
643 array(
"Align" => $a_align));
655 if (
$node->has_attributes ())
657 foreach(
$node->attributes() as
$n)
660 switch (strtolower(
$n->node_name ())) {
687 if (
$node->has_attributes ())
689 foreach(
$node->attributes() as
$n)
692 switch (strtolower(
$n->node_name ())) {
712 if (
$node->has_child_nodes())
714 foreach(
$node->child_nodes() as
$n)
716 if (
$n->node_type() == XML_ELEMENT_NODE &&
717 strcasecmp(
$n->node_name (),
"td") == 0)
728 $aCell = $this->
addCell($aRow);
730 $par->createAtNode($aCell);
731 $par->setText($par->input2xml($this->extractText ($cellNode)));
732 $par->setCharacteristic(
"TableContent");
733 $par->setLanguage(
$lng);
738 $owner_document =
$node->owner_document ();
739 $children =
$node->child_nodes();
740 $total_children = count($children);
741 for ($i = 0; $i < $total_children; $i++){
742 $cur_child_node = $children[$i];
743 $output .= $owner_document->dump_node($cur_child_node);
757 $path =
"//table[1] | //Table[1]";
760 if (count(
$res->nodeset) == 0)
762 $error =
"Could not find a table root node";
767 for($i = 0; $i < count(
$res->nodeset); $i++)
773 if (
$node->has_child_nodes())
775 foreach(
$node->child_nodes() as
$n)
777 if (
$n->node_type() == XML_ELEMENT_NODE &&
778 strcasecmp(
$n->node_name (),
"tr") == 0)
791 foreach (
$error as $errorline) { # Loop through all errors
792 $errmsg .=
"[" . $errorline[
'line'] .
", " . $errorline[
'col'] .
"]: ".$errorline[
'errormessage'].
" at Node '". $errorline[
'nodename'] .
"'<br />";
799 if (empty ($errmsg)) {
812 $childs = $this->tab_node->child_nodes();
813 foreach($childs as $child)
815 if ($child->node_name() ==
"TableRow")
817 $gchilds = $child->child_nodes();
818 foreach($gchilds as $gchild)
820 if ($gchild->node_name() ==
"TableData")
822 $gchild->set_attribute(
"Class", $a_class);
958 if (!empty($a_value))
960 $this->tab_node->set_attribute($a_attr, $a_value);
964 if ($this->tab_node->has_attribute($a_attr))
966 $this->tab_node->remove_attribute($a_attr);
978 if (is_object($this->tab_node))
980 return $this->tab_node->get_attribute($a_attr);