5 require_once(
"./Services/COPage/classes/class.ilPageContent.php");
33 parent::setNode($a_node);
34 $this->tab_node = $a_node->first_child();
37 function create(&$a_pg_obj, $a_hier_id, $a_pc_id =
"")
41 $this->tab_node = $this->dom->create_element(
"Table");
42 $this->tab_node = $this->node->append_child($this->tab_node);
43 $this->tab_node->set_attribute(
"Language",
"");
47 $new_tr = $this->dom->create_element(
"TableRow");
48 $new_tr = &$this->tab_node->append_child($new_tr);
52 function &
addCell (&$aRow, $a_data =
"", $a_lang =
"")
54 $new_td = $this->dom->create_element(
"TableData");
55 $new_td = $aRow->append_child($new_td);
61 $new_par = $this->dom->create_element(
"Paragraph");
62 $new_par = $new_pg->append_child($new_par);
63 $new_par->set_attribute(
"Language", $a_lang);
64 $new_par->set_attribute(
"Characteristic",
"TableContent");
65 $new_par->set_content($a_data);
66 $new_td->append_child ($new_pg);
77 for ($i=1; $i<=$a_nr_rows; $i++)
80 for ($j=1; $j<=$a_nr_cols; $j++)
92 str_replace($a_data,
"\r",
"\n");
93 str_replace($a_data,
"\n\n",
"\n");
94 $target_rows =
array();
95 $rows = explode(
"\n", $a_data);
99 foreach($rows as
$row)
101 $cells = explode(
"\t", $row);
102 $max_cols = ($max_cols > count($cells))
105 $target_rows[] = $cells;
109 foreach($target_rows as $row)
112 for ($j=0; $j<$max_cols; $j++)
115 $data = str_replace(
"&",
"&", $row[$j]);
222 $this->tab_node->set_attribute(
"HorizontalAlign", $a_halign);
242 $path =
"//TableData[@HierId = '".$a_hier_id.
"']";
246 $path =
"//TableData[@PCID = '".$a_pc_id.
"']";
250 if (count(
$res->nodeset) == 1)
254 $res->nodeset[0]->set_attribute(
"Width", $a_width);
258 if (
$res->nodeset[0]->has_attribute(
"Width"))
260 $res->nodeset[0]->remove_attribute(
"Width");
272 $rows = $this->tab_node->child_nodes();
273 foreach($rows as
$row)
275 if ($row->node_name() ==
"TableRow")
278 $cells = $row->child_nodes();
279 foreach($cells as $cell)
281 if ($cell->node_name() ==
"TableData")
283 $ckey = $cell->get_attribute(
"HierId").
":".$cell->get_attribute(
"PCID");
284 if((
int) $a_colspans[$ckey] > 1)
286 $cell->set_attribute(
"ColSpan", (
int) $a_colspans[$ckey]);
290 if ($cell->has_attribute(
"ColSpan"))
292 $cell->remove_attribute(
"ColSpan");
295 if((
int) $a_rowspans[$ckey] > 1)
297 $cell->set_attribute(
"RowSpan", (
int) $a_rowspans[$ckey]);
301 if ($cell->has_attribute(
"RowSpan"))
303 $cell->remove_attribute(
"RowSpan");
326 $rows = $this->tab_node->child_nodes();
328 foreach($rows as
$row)
330 if ($row->node_name() ==
"TableRow")
333 $cells = $row->child_nodes();
334 foreach($cells as $cell)
336 if ($cell->node_name() ==
"TableData")
338 $max_x = max ($max_x,
$x);
339 $max_y = max ($max_y,
$y);
349 $rows = $this->tab_node->child_nodes();
350 foreach($rows as $row)
352 if ($row->node_name() ==
"TableRow")
355 $cells = $row->child_nodes();
356 foreach($cells as $cell)
358 if ($cell->node_name() ==
"TableData")
360 $cspan = max(1, (
int) $cell->get_attribute(
"ColSpan"));
361 $rspan = max(1, (
int) $cell->get_attribute(
"RowSpan"));
364 if ($cspan > $max_x -
$x + 1)
366 $cell->set_attribute(
"ColSpan", $max_x -
$x + 1);
367 $cspan = $max_x -
$x + 1;
369 if ($rspan > $max_y -
$y + 1)
371 $cell->set_attribute(
"RowSpan", $max_y -
$y + 1);
372 $rspan = $max_y -
$y + 1;
379 $cell->set_attribute(
"Hidden",
"Y");
382 if ($cell->has_attribute(
"ColSpan"))
384 $cell->remove_attribute(
"ColSpan");
386 if ($cell->has_attribute(
"RowSpan"))
388 $cell->remove_attribute(
"RowSpan");
395 if ($cell->has_attribute(
"Hidden"))
397 $cell->remove_attribute(
"Hidden");
401 $colspans[
$x][
$y] = $cspan;
402 $rowspans[
$x][
$y] = $rspan;
419 $children = $td_node->child_nodes();
420 for($i=0; $i<count($children); $i++)
422 $td_node->remove_child($children[$i]);
431 for ($i = 0; $i<=
$x; $i++)
433 for ($j = 0; $j<=
$y; $j++)
435 if ($i !=
$x || $j !=
$y)
437 if ((($i + $colspans[$i][$j] >
$x) &&
438 ($j + $rowspans[$i][$j] >
$y)))
456 $rows = $this->tab_node->child_nodes();
457 foreach($rows as
$row)
459 if ($row->node_name() ==
"TableRow")
461 $cells = $row->child_nodes();
462 foreach($cells as $cell)
464 if ($cell->node_name() ==
"TableData")
466 $classes[$cell->get_attribute(
"HierId").
":".$cell->get_attribute(
"PCID")]
467 = $cell->get_attribute(
"Class");
484 $rows = $this->tab_node->child_nodes();
485 foreach($rows as
$row)
487 if ($row->node_name() ==
"TableRow")
489 $cells = $row->child_nodes();
490 foreach($cells as $cell)
492 if ($cell->node_name() ==
"TableData")
494 $classes[$cell->get_attribute(
"HierId").
":".$cell->get_attribute(
"PCID")]
495 = $cell->get_attribute(
"HorizontalAlign");
512 $rows = $this->tab_node->child_nodes();
516 foreach($rows as
$row)
518 if ($row->node_name() ==
"TableRow")
521 $cells = $row->child_nodes();
522 foreach($cells as $cell)
524 if ($cell->node_name() ==
"TableData")
526 $spans[$cell->get_attribute(
"HierId").
":".$cell->get_attribute(
"PCID")]
527 =
array(
"x" =>
$x,
"y" =>
$y,
"colspan" => $cell->get_attribute(
"ColSpan"),
528 "rowspan" => $cell->get_attribute(
"RowSpan"));
529 $max_x = max($max_x,
$x);
530 $max_y = max($max_y,
$y);
537 foreach ($spans as $k => $v)
539 $spans[$k][
"max_x"] = $max_x;
540 $spans[$k][
"max_y"] = $max_y;
554 $rows = $this->tab_node->child_nodes();
555 foreach($rows as
$row)
557 if ($row->node_name() ==
"TableRow")
559 $cells = $row->child_nodes();
560 foreach($cells as $cell)
562 if ($cell->node_name() ==
"TableData")
564 $widths[$cell->get_attribute(
"HierId").
":".$cell->get_attribute(
"PCID")]
565 = $cell->get_attribute(
"Width");
582 $path =
"//TableData[@HierId = '".$a_hier_id.
"']";
586 $path =
"//TableData[@PCID = '".$a_pc_id.
"']";
589 if (count(
$res->nodeset) == 1)
593 $res->nodeset[0]->set_attribute(
"Class", $a_class);
597 if (
$res->nodeset[0]->has_attribute(
"Class"))
599 $res->nodeset[0]->remove_attribute(
"Class");
613 $path =
"//TableData[@HierId = '".$a_hier_id.
"']";
617 $path =
"//TableData[@PCID = '".$a_pc_id.
"']";
620 if (count(
$res->nodeset) == 1)
624 $res->nodeset[0]->set_attribute(
"HorizontalAlign", $a_class);
628 if (
$res->nodeset[0]->has_attribute(
"HorizontalAlign"))
630 $res->nodeset[0]->remove_attribute(
"HorizontalAlign");
645 $path =
"//PageContent[@HierId = '".$hier_id.
"']/Table/Caption";
648 if (count(
$res->nodeset) == 1)
650 return $res->nodeset[0]->get_content();
664 $path =
"//PageContent[@HierId = '".$hier_id.
"']/Table/Caption";
666 if (count(
$res->nodeset) == 1)
668 return $res->nodeset[0]->get_attribute(
"Align");
682 array(
"Align" => $a_align));
694 if (
$node->has_attributes ())
696 foreach(
$node->attributes() as
$n)
699 switch (strtolower(
$n->node_name ())) {
726 if (
$node->has_attributes ())
728 foreach(
$node->attributes() as
$n)
731 switch (strtolower(
$n->node_name ())) {
751 if (
$node->has_child_nodes())
753 foreach(
$node->child_nodes() as
$n)
755 if (
$n->node_type() == XML_ELEMENT_NODE &&
756 strcasecmp(
$n->node_name (),
"td") == 0)
767 $aCell = $this->
addCell($aRow);
769 $par->createAtNode($aCell);
770 $par->setText($par->input2xml($this->extractText($cellNode)));
771 $par->setCharacteristic(
"TableContent");
772 $par->setLanguage(
$lng);
777 $owner_document =
$node->owner_document ();
778 $children =
$node->child_nodes();
779 $total_children = count($children);
780 for ($i = 0; $i < $total_children; $i++){
781 $cur_child_node = $children[$i];
782 $output .= $owner_document->dump_node($cur_child_node);
796 $path =
"//table[1] | //Table[1]";
799 if (count(
$res->nodeset) == 0)
801 $error =
"Could not find a table root node";
806 for($i = 0; $i < count(
$res->nodeset); $i++)
812 if (
$node->has_child_nodes())
814 foreach(
$node->child_nodes() as
$n)
816 if (
$n->node_type() == XML_ELEMENT_NODE &&
817 strcasecmp(
$n->node_name (),
"tr") == 0)
830 foreach (
$error as $errorline) { # Loop through all errors
831 $errmsg .=
"[" . $errorline[
'line'] .
", " . $errorline[
'col'] .
"]: ".$errorline[
'errormessage'].
" at Node '". $errorline[
'nodename'] .
"'<br />";
838 if (empty ($errmsg)) {
851 $childs = $this->tab_node->child_nodes();
852 foreach($childs as $child)
854 if ($child->node_name() ==
"TableRow")
856 $gchilds = $child->child_nodes();
857 foreach($gchilds as $gchild)
859 if ($gchild->node_name() ==
"TableData")
861 $gchild->set_attribute(
"Class", $a_class);
997 if (!empty($a_value))
999 $this->tab_node->set_attribute($a_attr, $a_value);
1003 if ($this->tab_node->has_attribute($a_attr))
1005 $this->tab_node->remove_attribute($a_attr);
1017 if (is_object($this->tab_node))
1019 return $this->tab_node->get_attribute($a_attr);
1029 return array(
"ed_insert_dtable",
"ed_insert_atable",
"ed_new_row_after",
"ed_new_row_before",
1030 "ed_new_col_after",
"ed_new_col_before",
"ed_delete_col",
1031 "ed_delete_row",
"ed_edit_data",
"ed_row_up",
"ed_row_down",
1032 "ed_col_left",
"ed_col_right");
1044 $xpath =
new DOMXPath($a_domdoc);
1045 $nodes = $xpath->query(
"//Table");
1046 foreach($nodes as
$node)
1048 $node->removeAttribute(
"Id");
getFooterRows()
Get footer rows.
setTDSpans($a_colspans, $a_rowspans)
Set TDSpans.
static getLangVars()
Get lang vars needed for editing.
getTableAttribute($a_attr)
Get table tag attribute.
setHeaderRows($a_nr)
Set header rows.
create(&$a_pg_obj, $a_hier_id, $a_pc_id="")
getWidth()
get table width
xpath_new_context($dom_document)
setTDWidth($a_hier_id, $a_width, $a_pc_id="")
set width of table data cell
setHeaderCols($a_nr)
Set header cols.
xpath_eval($xpath_context, $eval_str, $contextnode=null)
static deleteAllChildsByName($a_parent, $a_node_names)
delete all childs of a node by names in $a_node_names
importCell($lng, &$cellNode, &$aRow)
static handleCopiedContent(DOMDocument $a_domdoc, $a_self_ass=true, $a_clone_mobs=false)
Handle copied content.
setType($a_type)
Set Type.
setLanguage($a_lang)
set table language
setCaption($a_content, $a_align)
set table caption
importCellAttributes(&$node, &$par)
init()
Init page content component.
& addCell(&$aRow, $a_data="", $a_lang="")
getTemplate()
Get template.
getClass()
Get characteristic of section.
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
addRows($a_nr_rows, $a_nr_cols)
add rows to table
importHtml($lng, $htmlTable)
setTableAttribute($a_attr, $a_value)
Set attribute of table tag.
setHorizontalAlign($a_halign)
set horizontal align
setTemplate($a_template)
Set template.
setCellSpacing($a_spacing)
set table cell spacing
setFirstRowStyle($a_class)
Set first row td style.
static setFirstOptionalElement($doc, $parent_node, $a_node_name, $a_successors, $a_content, $a_attributes, $a_remove_childs=true)
searches for an element $a_node_name within the childs of $parent_node if no node is found...
setWidth($a_width)
set table width
getHorizontalAlign()
get table cell padding
setTDAlignment($a_hier_id, $a_class, $a_pc_id="")
set alignment of table data cell
getFooterCols()
Get footer cols.
importSpreadsheet($a_lang, $a_data)
import from table
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
checkCellHidden($colspans, $rowspans, $x, $y)
Check hidden status.
getHeaderCols()
Get header cols.
getHierId()
Get hierarchical id.
setBorder($a_border)
set table border
makeEmptyCell($td_node)
Make cell empty.
Create styles array
The data for the language used.
getAllCellWidths()
Get all cell widhts.
getCellPadding()
get table cell padding
getCaptionAlign()
get caption alignment (Top | Bottom)
importTableAttributes(&$node)
getBorder()
get table border width
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element) ...
getAllCellSpans()
Get all cell spans.
setFooterRows($a_nr)
Set footer rows.
setCellPadding($a_padding)
set table cell padding
getAllCellAlignments()
Get all cell alignments.
domxml_open_mem($str, $mode=0, &$error=NULL)
getCellSpacing()
get table cell spacing
setFooterCols($a_nr)
Set footer cols.
getHeaderRows()
Get header rows.
getAllCellClasses()
Get all cell classes.
setClass($a_class)
Set Style Class of table.
getLanguage()
get table language
setTDClass($a_hier_id, $a_class, $a_pc_id="")
set class of table data cell
fixHideAndSpans()
Fix Hide and Spans.