Source for file LVU_DOMDOCUMENT.phpclass
Documentation is available at LVU_DOMDOCUMENT.phpclass
* Class file LVU_DOMDOCUMENT.phpclass
* @project Open CSP-Management
* @author Christian Gaisberger (cg) <c.gaisberger@lvus.at>
* @author Peter Krebs (pk)<p.krebs@lvus.at>
* @copyright (c) 2002-2003 by Landesverlag Unternehmensservice
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
require_once $GLOBALS['DEFAULTCONFPATH'].
"xml.conf.phpinc";
* @project Open CSP-Management
* @author Christian Gaisberger <c.gaisberger@lvus.at>
* @copyright (c) 2004 by Landesverlag Unternehmensservice
* @var string $xmlFile dateiname zum öffnen
* @var string $xmlWorkdir datei pfad
* @var object $myDom zum öffnen des xml files
* @var object $myDtd ausgabe des dtd namen
* @var object $myTag ausgabe des tagnamen
* @var string $gDBIDX key of $GLOBALS[] to the db object
if ($debug) echo
"\n<p><b>LVU_DOMDOCUMENT::LVU_DOMDOCUMENT($xmlFile)</b> (".
get_class($this).
")</p>\n";
$this->myDom->load($xmlFile);
echo
"\n\t<blockquote><!-- -------------------------------------- -->\n<pre>\n".
print_r($this->myDom,TRUE).
"\n</pre>\n</blockquote><!-- -------------------------------------- -->\n";
* returns the root node of myDom
* @returns DOMElement NULL in case of error
return $this->myDom->documentElement;
* gibt einen array mit dem ersten wurzel elemt zurück
if ($debug) echo
"\n\n<p><b>LVU_DOMDOCUMENT::getRoottag()</b> (".
get_class($this).
")</p>\n\n\t<blockquote><!-- -------------------------------------- -->\n";
if ($this->myDom->documentElement->childNodes->length) {
foreach($this->myDom->documentElement->childNodes as $n) {
if ($debug) echo
"\t\n</blockquote><!-- -------------------------------------- -->\n";
* returns an array of tag descriptions
* use $reqNOC = 2 (require number of children) to get only nodes which are
* parent of a complex element
* @param int $maxLevels (999 = unlimited)
* @param string $parentName
* @param string $pPath path to root (exmpl TBL>ROW>COL)
* @todo $reqNOC may fail for complex nodes which consists of only on complex parent
function populateAllTagsArr(&$tagArr,$maxLevels=
999,$reqNOC=
0,$node=
NULL,$parentName=
"ROOT",$pPath=
"",$debug=
FALSE) {
if (!$node) $node=
$this->getRoot();
echo
"\n\n<p><b>LVU_DOMDOCUMENT::populateAllTagsArr(\$tagArr,$maxLevels,$reqNOC,\$node,$parentName,$pPath ...)</b> (".
get_class($this).
")</p>\n";
if (!$maxLevels) return TRUE;
if (($node->nodeType !=
XML_TEXT_NODE) &&
($node->childNodes->length >=
$reqNOC)) {
$nodeDesc =
"NAME:".
$node->nodeName;
$nodeDesc.=
"/TYPE:".
$node->nodeType;
$nodeDesc.=
"/PARENT:".
$parentName;
$nodeDesc.=
"/PATH:".
$pPath;
if (!empty($pPath)) $pPath .=
">";
$pPath .=
$node->nodeName;
if ($maxLevels <
999) $maxLevels--
;
if ($node->childNodes->length) {
foreach($node->childNodes as $child) {
$this->populateAllTagsArr($tagArr,$maxLevels,$reqNOC,$child,$node->nodeName,$pPath,$debug);
* returns an array with xml tag desc array
* @param int $maxLevels (999 = unlimited)
* @param int $reqNOC see THIS::populateAllTagsArr
if ($debug) echo
"\n<p><b>LVU_DOMDOCUMENT::getTagDescArr($maxLevels,...)</b> (".
get_class($this).
")</p>\n";
$keyArr=
array(); // tmporary used to store keys
foreach($tagArr as $tagDescStr) {
if ($tmpArr1 =
explode("/",$tagDescStr)) {
foreach($tmpArr1 as $tmpStr) {
$tagDesc[$tmpArr2[0]]=
$tmpArr2[1];
$retArr[$idx++
]=
$tagDesc;
/**********************************************************************************/
/******************** DATA FUNCTIONS ********************************************/
/**********************************************************************************/
* populates a tmpImpArr element
if ($debug) echo
"\n<p><b>LVU_DOMDOCUMENT::populate_tmpImpArr($tblTag,$rowTag..)</b> (".
get_class($this).
")</p>\n";
$key=
$tblTag.
">".
$rowTag;
$query =
"SELECT * FROM T_SYS_XMLROOTS ";
$query.=
" WHERE XRS_TBLTG='".
$tblTag.
"'";
$query.=
" AND XRS_ROWTG='".
$rowTag.
"'";
//if ($debug) echo "\n\t<blockquote><!-- -------------------------------------- -->\n<pre>$query</pre>\n</blockquote><!-- -------------------------------------- -->\n";
if ($this->tmpImpArr[$key]=
$GLOBALS[$this->gDBIDX]->quickQuery($query)) {
$query =
"SELECT XMD_COLTG AS ARRKEY, d.* FROM T_SYS_XMLDESC d WHERE XRS_ID=".
$this->tmpImpArr[$key]['XRS_ID'];
//if ($debug) echo "\n\t<blockquote><!-- -------------------------------------- -->\n<pre>$query</pre>\n</blockquote><!-- -------------------------------------- -->\n";
$this->tmpImpArr[$key]['COLS']=
$GLOBALS[$this->gDBIDX]->queryArray($query,0,-
1);
$this->tmpImpArr[$key]=
FALSE;
* inserts single multivalue tag
* for each child a db replace statement is executed
* returns the number of rows processed
if ($debug) echo
"\n<p><b>LVU_DOMDOCUMENT::getDataArray($smvkey,\$node...)</b> (".
get_class($this).
")</p>\n";
foreach($node->childNodes as $child) {
if (is_array($this->tmpImpArr[$smvkey]['COLS'][$child->nodeName])) {
$tblKey=
$this->tmpImpArr[$smvkey]['COLS'][$child->nodeName]['XMD_TABLE'];
$colKey=
$this->tmpImpArr[$smvkey]['COLS'][$child->nodeName]['XMD_COL'];
$GLOBALS['USRDB']->replaceArray($tblKey,$row[$tblKey],$debug);
* gets a data array out of a node child list
* each child not found in $this->tmpImpArr[$key]['COLS']
if ($debug) echo
"\n<p><b>LVU_DOMDOCUMENT::getDataArray($key,\$node...)</b> (".
get_class($this).
")</p>\n";
if (!is_array($this->tmpImpArr[$key]['COLS'])) return FALSE;
if ($debug) echo
"\n\t<blockquote><!-- -------------------------------------- -->\n<ul>";
$singleMultiValChildren=
array();
foreach($node->childNodes as $child) {
if (is_array($this->tmpImpArr[$key]['COLS'][$child->nodeName])) {
$tblKey=
$this->tmpImpArr[$key]['COLS'][$child->nodeName]['XMD_TABLE'];
$colKey=
$this->tmpImpArr[$key]['COLS'][$child->nodeName]['XMD_COL'];
if ($debug) echo
"<li>\$row[".
$tblKey.
"][".
$colKey.
"]:\n\t<blockquote><!-- -------------------------------------- -->\n<pre>".
htmlspecialchars(utf8_decode($child->nodeValue)).
"</pre>\n</blockquote><!-- -------------------------------------- -->\n</li>";
} else if (is_array($this->tmpImpArr[$key]['COLS']["<".
$child->nodeName.
">"])) {
if ($debug) echo
"\t\t<li>SubNode ".
$child->nodeName.
" </li>\n";
$smvkey=
$node->nodeName.
">".
$child->nodeName;
if (!isset
($this->tmpImpArr[$smvkey])) {
if ($this->tmpImpArr[$smvkey]['XRS_SINGLEVALMULTI']) {
$singleMultiValChildren[$smvkey]=
$child;
if ($child->nodeType !=
XML_TEXT_NODE) {
if ($debug) echo
"\t\t<li>".
$child->nodeName.
" NOT USED </li>\n";
foreach($singleMultiValChildren as $smvkey =>
$child) {
if ($debug) echo
"</ul>\n\n<p>Done LVU_DOMDOCUMENT::getDataArray()</p>\n<hr></blockquote><!-- -------------------------------------- -->\n";
if ($debug) echo
"\n<p><b>LVU_DOMDOCUMENT::importSubTreeData(\$parData (".
sizeof($parData).
",$tblTag,$rowTag,\$node...)</b> (".
get_class($this).
")</p>\n\n\t<blockquote><!-- -------------------------------------- -->\n";
$key=
$tblTag.
">".
$rowTag;
if (!isset
($this->tmpImpArr[$key])) {
if (is_array($this->tmpImpArr[$key]['COLS'])) {
// echo "<pre>ROW: ".print_r($row,TRUE)."</pre>\n";
foreach($row as $impTbl =>
$impRow) {
foreach($parData as $parTbl =>
$parRow) {
foreach($parRow as $col =>
$val) {
if (!isset
($impRow[$col])) {
$GLOBALS[$this->gDBIDX]->replaceArray($impTbl,$impRow,$debug);
foreach($childNodes as $cchild) {
if ($cchild->nodeType !=
XML_TEXT_NODE) {
if ($debug) echo
"</blockquote><!-- -------------------------------------- -->\n";
* imports the data of the xml file
function importData($node=
NULL,$delTab=
NULL,$debug=
FALSE) {
echo
"\n<p><b>LVU_DOMDOCUMENT::importData(\$node,$delTab,...)</b> (".
get_class($this).
")</p>\n";
$this->tmpImpArr=
array();
if ($node->childNodes->length) {
foreach($node->childNodes as $child) {
if (($node->nodeType !=
XML_TEXT_NODE) &&
($child->nodeType !=
XML_TEXT_NODE)) { // we have a subtree
$key=
$node->nodeName.
">".
$child->nodeName; // generate a node key
if (!isset
($this->tmpImpArr[$key])) { // not yet checked
if ($this->populate_tmpImpArr($node->nodeName,$child->nodeName,$debug)) { // check if we have a definition for the subtree
if ($delTab ==
1) { // truncate table
$cmd =
"TRUNCATE ".
$this->tmpImpArr[$key]['XRS_TABLE'];
if ($debug) echo
"\n<p>$cmd</p>";
$GLOBALS['USRDB']->executeCmd($cmd,$GLOBALS['DEBUGMODE']);
if (is_array($this->tmpImpArr[$key]['COLS'])) { //
// echo "<pre>ROW: ".print_r($row,TRUE)."</pre>\n";
if ($this->tmpImpArr[$key]['XRS_DOINSERT']) {
foreach($row as $impTbl =>
$impRow) {
$GLOBALS[$this->gDBIDX]->replaceArray($impTbl,$impRow,$debug);
foreach($chChildNodes as $cchild) {
if ($cchild->nodeType !=
XML_TEXT_NODE) {
foreach($childNodes as $child) {
if ($child->nodeType !=
XML_TEXT_NODE) {
* echos a node used for debuging
function print_node($node=
NULL,$fullDebug=
FALSE) {
if (!$node) $node=
$this->myDom;
echo
"\n<p>Node Info: (file: ".
$this->xmlFile.
")</p>\n";
print
"\n\t<blockquote><!-- -------------------------------------- -->\n<pre>Node Name: " .
$node->nodeName;
print
"\nNode Type: " .
$node->nodeType;
$child_count =
$node->childNodes->length;
print
"\nNum Children: " .
$child_count;
print
"\nNode Content: " .
$node->nodeValue;
echo
"\n-----------------------------\n\tNODETYPE: ";
switch($node->nodeType) {
echo
"UNKNOWN ".
$node->nodeType.
"\n";
print
"</pre>\n</blockquote><!-- -------------------------------------- -->\n";
Documentation generated on Thu, 08 Jan 2009 17:44:35 +0100 by phpDocumentor 1.4.0a2