diff --git a/.gitignore b/.gitignore index a0aca91..872d054 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,9 @@ generic_data/newKernelDDBase/ generic_data/ParamInfo/*.xml js/lib/ext help/simu/simu* +desktop.php +php/my_config.php +DD.res +logs/* *~ - +generic_data/EpnTapData/services.json diff --git a/cron_scripts/get_services.php b/cron_scripts/get_services.php new file mode 100755 index 0000000..d871992 --- /dev/null +++ b/cron_scripts/get_services.php @@ -0,0 +1,42 @@ +request($s["accessurl"], $query); + if($rows == NULL) + continue; + + foreach ($rows as $r) { + $r['dp_type'] = $r['dp_type']; + $r['t_class'] = $r['t_class']; + $r['t_name'] = $r['t_name']; + + if(!isset($services_content[$r['dp_type']])) + $services_content[$r['dp_type']] = Array(); + + if(!isset($services_content[$r['dp_type']][$r['t_class']])) + $services_content[$r['dp_type']][$r['t_class']] = Array(); + + if(!isset($services_content[$r['dp_type']][$r['t_class']][$r['t_name']])) + $services_content[$r['dp_type']][$r['t_class']][$r['t_name']] = Array(); + + $services_content[$r['dp_type']][$r['t_class']][$r['t_name']][$s["schema"]] = [$r['nb_res'], $r['time_min'], $r['time_max']]; + } +} + +fwrite(fopen(EpnTapDataPath . "services.json", "w+"), json_encode($services_content, JSON_PRETTY_PRINT)); +?> diff --git a/php/classes/AmdaAction.php b/php/classes/AmdaAction.php index bf59747..e58a422 100644 --- a/php/classes/AmdaAction.php +++ b/php/classes/AmdaAction.php @@ -8,17 +8,17 @@ class AmdaAction { - private $xmlFiles = array('localParam' => 'LocalParams.xml', 'remoteParam' => 'RemoteParams.xml', + private $xmlFiles = array('localParam' => 'LocalParams.xml', 'remoteParam' => 'RemoteParams.xml', 'remoteSimuParam' => 'RemoteParams.xml', 'derivedParam' => 'WsParams.xml', 'myDataParam' => 'WsParams.xml', - 'timeTable' => 'Tt.xml', 'catalog' => 'Tt.xml', 'alias' => 'Alias.xml', - 'myData' => 'Files.xml', + 'timeTable' => 'Tt.xml', 'catalog' => 'Tt.xml', 'alias' => 'Alias.xml', + 'myData' => 'Files.xml', 'request' => 'Request.xml', 'condition' => 'Request.xml', 'bkgWorks' => 'jobs.xml'); private $user, $amdaStat; - public function __construct() - { + public function __construct() + { $dd = new UserMgr(); $this->user = $dd->user; if (!defined('NEWKERNEL_DEBUG') || !NEWKERNEL_DEBUG) @@ -28,38 +28,38 @@ class AmdaAction { private function getUrlDirs($url) { //TODO replace by ftp php class methods: ftp_nlist() etc require_once "simple_html_dom.php"; - - $url = html_entity_decode($url); + + $url = html_entity_decode($url); $trimmed_url = trim($url); if (strrpos($trimmed_url, "/") == strlen($trimmed_url) - 1) { - if (file_exists("temp.html")) unlink("temp.html"); + if (file_exists("temp.html")) unlink("temp.html"); exec("wget -O temp.html ".$url); - + $html = file_get_html('temp.html'); $dirs = $html->find('a[href]'); foreach ($dirs as $dir) { $name = $dir->innertext; //$dir->href; $isLeaf = strrpos($name, "/") !== strlen($name) - 1; $childrenToReturn[] = array('text' => $name, 'id' => $trimmed_url.$name, - 'nodeType' => 'url', 'leaf' => $isLeaf); + 'nodeType' => 'url', 'leaf' => $isLeaf); } - + } - return $childrenToReturn; + return $childrenToReturn; } - + /***************************************************************** * PUBLIC FUNCTIONS -*****************************************************************/ - +*****************************************************************/ + /* * $obj = { id: node.id, nodeType: node.nodeType } */ public function getTree($obj) { - + $node = $obj->node; - - // to correct 'restricted' parameters + + // to correct 'restricted' parameters if (strpos($node, restricted) !== false) { $node = str_replace(restricted,"",$node); } @@ -68,9 +68,9 @@ class AmdaAction { $remoteBase = false; $isRemoteDataSet = false; - if ($nodeType == 'url') + if ($nodeType == 'url') { - $url = $node == 'root' ? $obj->baseId : $node; + $url = $node == 'root' ? $obj->baseId : $node; return $this->getUrlDirs($url); } @@ -78,63 +78,63 @@ class AmdaAction { if ($node == 'root' && $remoteBase) $node = $obj->baseId; - if ($node == 'root' && !$remoteBase) - { + if ($node == 'root' && !$remoteBase) + { $json_o = json_decode(file_get_contents(DATAPATH.$nodeType.'.json')); - $childrenToReturn = $json_o->nodes; - } - else + $childrenToReturn = $json_o->nodes; + } + else { $Dom = new DomDocument("1.0"); - switch ($nodeType) + switch ($nodeType) { case 'sharedtimeTable': case 'sharedcatalog': $xmlName = SHAREDPATH.'/SharedObjectTree.xml'; break; - case 'bkgWorks': + case 'bkgWorks': $xmlName = USERJOBDIR.$this->xmlFiles[$nodeType]; break; case 'source': - $xmlName = DATAPATH.'RemoteData/'.$obj->baseId.'/base.xml'; + $xmlName = DATAPATH.'RemoteData/'.$obj->baseId.'/base.xml'; + break; + case 'destination': + $xmlName = USERWSDIR.'RemoteParams.xml'; break; - case 'destination': - $xmlName = USERWSDIR.'RemoteParams.xml'; - break; default: $xmlName = USERWSDIR.$this->xmlFiles[$nodeType]; } - if ($remoteBase) - { + if ($remoteBase) + { $nodeType = 'remoteParam'; - } - + } + $Dom->load($xmlName); - - if ($node == "myRemoteSimuData-treeRootNode") + + if ($node == "myRemoteSimuData-treeRootNode") $node = "myRemoteData-treeRootNode"; - + $nodeToOpen = $Dom->getElementById($node); $children = $nodeToOpen->childNodes; - foreach ($children as $child) + foreach ($children as $child) if ($child->nodeType == XML_ELEMENT_NODE) { $isLeaf = true; - + if ($child->hasChildNodes()) - foreach ($child->childNodes as $grandChild) + foreach ($child->childNodes as $grandChild) if ($grandChild -> nodeType == XML_ELEMENT_NODE) { $isLeaf = false; break; } if ($child->tagName == 'folder') $isLeaf = false; - //TODO MAKE PROPERLY as function of nodetype !!!! - $info = ''; + //TODO MAKE PROPERLY as function of nodetype !!!! + $info = ''; $id = $child->getAttribute('xml:id'); - $name = $child->getAttribute('name'); + $name = $child->getAttribute('name'); $help = $child->getAttribute('att'); if ($child->hasAttribute('dataStart')) $dataStart = $child->getAttribute('dataStart'); if ($child->hasAttribute('dataStop')) $dataStop = $child->getAttribute('dataStop'); @@ -146,42 +146,42 @@ class AmdaAction { $isSimulation = false; $rank = null; - switch ($nodeType) + switch ($nodeType) { - case 'bkgWorks': + case 'bkgWorks': $specialNode = true; $status = $child->getAttribute('status'); - // if ($status == 'done') continue; + // if ($status == 'done') continue; $childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType, 'leaf' => $isLeaf, - 'pid' => $child->getAttribute('pid'), 'status' => $status, + 'pid' => $child->getAttribute('pid'), 'status' => $status, 'jobType' => $child->getAttribute('jobType'), 'info' => $child->getAttribute('info')); break; case 'condition': $objectMgr = new RequestMgr(); - $info = $objectMgr->getObject($id)->expression; - break; + $info = $objectMgr->getObject($id)->expression; + break; case 'request': - + $objectMgr = new RequestMgr(); - $objplot = $objectMgr->getObject($id); - for ($i=0; $i < count($objplot->children); $i++) { + $objplot = $objectMgr->getObject($id); + for ($i=0; $i < count($objplot->children); $i++) { for ($j=0; $j < count($objplot->children[$i]->children); $j++) { $info = $info.' '.$objplot->children[$i]->children[$j]->name; } } - - break; - case 'alias': + break; + + case 'alias': $info = $id; $id = 'alias_'.$id; - if ($isLeaf) $isParameter = true; + if ($isLeaf) $isParameter = true; break; case 'timeTable': - case 'catalog': + case 'catalog': if ($isLeaf) $info = $child->getAttribute('intervals').' intervals'; break; case 'sharedtimeTable': @@ -205,34 +205,34 @@ class AmdaAction { $specialNode = true; $isParameter = false; $needsArgs = false; - $isSpectra = false; + $isSpectra = false; $isStack = false; if ($child->hasAttribute('desc')) $info = $child->getAttribute('desc'); - if ($child->hasAttribute('sampling')) + if ($child->hasAttribute('sampling')) { $info = "Sampling: ".$child->getAttribute('sampling')."
"; if ($child->getAttribute('dataStart') == 'depending on mission') { $info .= "Time Range: ".$child->getAttribute('dataStart')."
"; - } - else - { - $info .= "Time Range: ".$child->getAttribute('dataStart')."-".$child->getAttribute('dataStop')."
"; - } - + } + else + { + $info .= "Time Range: ".$child->getAttribute('dataStart')."-".$child->getAttribute('dataStop')."
"; + } + if ($child->getAttribute('restricted') > 1) { $restricted = $child->getAttribute('restricted'); $info .= "Time Restriction: -$restricted days
"; } - + $info .= "Source: ".$child->getAttribute('dataSource'); } - + if ($child->hasAttribute('units')) $info = $child->getAttribute('units'); - if ($child->tagName == 'parameter') + if ($child->tagName == 'parameter') { $isParameter = true; $isScatter = true; @@ -240,24 +240,24 @@ class AmdaAction { if ($child->parentNode->hasAttribute('dataStart')) { $globalStart = $child->parentNode->getAttribute('dataStart'); - $globalStop = $child->parentNode->getAttribute('dataStop'); + $globalStop = $child->parentNode->getAttribute('dataStop'); } if ($child->parentNode->getAttribute('restricted') > 1 ) { $timeRestriction = true; - + } - - /*------------------- to show not tested parameters ------*/ - + + /*------------------- to show not tested parameters ------*/ + if ($child->getAttribute('tbd')) $info .= "
Not tested yet"; - - /*------------------- --------------------------------------*/ - + + /*------------------- --------------------------------------*/ + } - + $component_info = array(); if ($child->tagName == 'component') @@ -268,78 +268,78 @@ class AmdaAction { if ($child->parentNode->parentNode->hasAttribute('dataStart')) { $globalStart = $child->parentNode->parentNode->getAttribute('dataStart'); - $globalStop = $child->parentNode->parentNode->getAttribute('dataStop'); - } + $globalStop = $child->parentNode->parentNode->getAttribute('dataStop'); + } if ($child->parentNode->parentNode->getAttribute('restricted') > 1) { $timeRestriction = true; - - } + + } if ($child->hasAttribute("index1")) $component_info["index1"] = $child->getAttribute('index1'); if ($child->hasAttribute("index2")) $component_info["index2"] = $child->getAttribute('index2'); - + $component_info["parentId"] = $child->parentNode->getAttribute('xml:id'); } - + if ($child->tagName == 'parameter' && $child->hasChildNodes()) $isScatter = false; - + if ($child->tagName == 'parameter' && $child->hasAttribute('display_type')) { if ($child->getAttribute('display_type') == 'spectrogram') { - $needsArgs = true; - $isSpectra = true; + $needsArgs = true; + $isSpectra = true; $isScatter = false; } - else if ($child->getAttribute('display_type') == 'stackplot') { + else if ($child->getAttribute('display_type') == 'stackplot') { $isStack = true; $isScatter = false; } - } - - if ($isParameter) + } + + if ($isParameter) { if ($child->tagName == 'parameter' && $child->childNodes->length == 1) - { - $needsArgs = true; - } - if (substr($id,0,4) == 'bt96' || substr($id,0,6) == 'ba2000'|| substr($id,0,5) == 'bcain' || substr($id,0,7) == 'bmorsch' ) - { + { + $needsArgs = true; + } + if (substr($id,0,4) == 'bt96' || substr($id,0,6) == 'ba2000'|| substr($id,0,5) == 'bcain' || substr($id,0,7) == 'bmorsch' ) + { $needsArgs = true; } - - if ($id == 'mex_n_sw' || $id == 'mex_v_sw') + + if ($id == 'mex_n_sw' || $id == 'mex_v_sw') { $not_yet = true; - + } //TODO proper conditions - if (substr($id,0,3) == 'ros') + if (substr($id,0,3) == 'ros') { if ( !(strpos($id,'_r_') || strpos($id,'_xyz_') || strpos($id,'_cg_') - || strpos($id,'_sc_') || strpos($id,'_aux_') || strpos($id,'_sw_') - || strpos($id,'_tao_') )) - { + || strpos($id,'_sc_') || strpos($id,'_aux_') || strpos($id,'_sw_') + || strpos($id,'_tao_') )) + { $not_yet = true; - } + } } $objectMgr = new AliasMgr(); $alias = $objectMgr->getAlias($id); - - $childrenToReturn[] = array('text' => $name,'alias' => $alias, + + $childrenToReturn[] = array('text' => $name,'alias' => $alias, 'id' => $id,'nodeType' => $nodeType, 'info' => $info, "component_info" => $component_info, 'globalStart' => $globalStart, 'globalStop' => $globalStop, 'timeRestriction' => $timeRestriction, 'leaf' => $isLeaf, 'isParameter' => $isParameter, 'isScatter' => $isScatter, 'isSpectra' => $isSpectra,'isStack' => $isStack, 'needsArgs' => $needsArgs, 'help' => $help, 'notyet' => $not_yet); } - else + else { - if ($child->tagName == 'mission') + if ($child->tagName == 'mission') { $disable = ($child->getAttribute('available') != "1"); $rank = $child->getAttribute('rank'); @@ -348,19 +348,19 @@ class AmdaAction { { $disable = $child->getAttribute('restricted'); } - + if ($disable) { if ($disable == 1) { $info .= "
Restricted access"; } - else { - $disable = false; + else { + $disable = false; } } - $childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType, 'info' => $info, - 'leaf' => false, 'help' => $help, 'disable' => $disable, 'rank' => $rank); + $childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType, 'info' => $info, + 'leaf' => false, 'help' => $help, 'disable' => $disable, 'rank' => $rank); } break; @@ -378,12 +378,12 @@ class AmdaAction { break; } } - if ($child->tagName == 'simulationRegion') + if ($child->tagName == 'simulationRegion') { $rank = $child->getAttribute('rank'); } case 'remoteParam' : - + if ($child->getAttribute('isSimulation') && $child->tagName == 'dataCenter') { $skip = true; break; @@ -391,13 +391,13 @@ class AmdaAction { $isDeletable = $child->hasAttribute('isDeletable'); $specialNode = true; - $isParameter = false; - $isSpectra = false; - - switch ($id) + $isParameter = false; + $isSpectra = false; + + switch ($id) { - case 'CDAWEB' : - case 'OMNIWEB' : + case 'CDAWEB' : + case 'OMNIWEB' : $isLeaf = false; break; case 'THEMIS' : @@ -411,64 +411,64 @@ class AmdaAction { break; default: } - + $info = $child->getAttribute('desc'); -// if ($info && !$isSimulation) { +// if ($info && !$isSimulation) { $info = str_replace(';', "
Time Range: ", $info); // } if ($child->tagName == 'dataset') { - /*if ($child->hasAttribute('dataStart') && $child->hasAttribute('dataStop')) - $info .= "Time Range: ".$child->getAttribute('dataStart')."-".$child->getAttribute('dataStop')."
"; */ + /*if ($child->hasAttribute('dataStart') && $child->hasAttribute('dataStop')) + $info .= "Time Range: ".$child->getAttribute('dataStart')."-".$child->getAttribute('dataStop')."
"; */ // $info .= "Time Range: ".$dataStart"-".$dataStop."
"; } if (($child->tagName == 'parameter') || ($child->tagName == 'component')) { $isParameter = true; - $isScatter = true; + $isScatter = true; } - + $needsArgs = $child->hasAttribute('needsArgs'); if (($child->tagName == 'parameter' && $child->hasChildNodes()) || $needsArgs) $isScatter = false; - + if ($remoteBase) { - if ($child->tagName == 'dataset') $isRemoteDataSet = true; + if ($child->tagName == 'dataset') $isRemoteDataSet = true; } if ($isParameter) { - $disable = $child->parentNode->getAttribute('disabled'); + $disable = $child->parentNode->getAttribute('disabled'); $objectMgr = new AliasMgr(); $alias = $objectMgr->getAlias($id); - if ($child->hasAttribute('display_type') + if ($child->hasAttribute('display_type') && $child->getAttribute('display_type') == 'spectrogram'){ - $needsArgs = true; + $needsArgs = true; $isScatter = false; $isSpectra = true; - } + } - $childrenToReturn[] = array('text' => $name,'alias' => $alias, + $childrenToReturn[] = array('text' => $name,'alias' => $alias, 'id' => $id,'nodeType' => $nodeType, 'info' => $info, 'help' => $help, - 'leaf' => $isLeaf, 'disable' => $disable, 'isParameter' => $isParameter, + 'leaf' => $isLeaf, 'disable' => $disable, 'isParameter' => $isParameter, 'isScatter' => $isScatter, 'isSpectra' => $isSpectra, 'needsArgs' => $needsArgs, "component_info" => $component_info); } - else { - if ($child->tagName == 'dataCenter') - $restricted = ($child->getAttribute('available') != "1"); + else { + if ($child->tagName == 'dataCenter') + $restricted = ($child->getAttribute('available') != "1"); else $restricted = false; - - if ($id == 'CDAWEB' || $id == 'THEMIS'|| $id == 'MAPSKP' || $id == 'VEXGRAZ') + + if ($id == 'CDAWEB' || $id == 'THEMIS'|| $id == 'MAPSKP' || $id == 'VEXGRAZ') $restricted = FALSE; if ($restricted) - $info .= "
Open soon !"; - + $info .= "
Open soon !"; + if ($child->tagName == 'dataset') $nonavailable = ($child->getAttribute('disabled')); else $nonavailable = false; - + if ($nonavailable) $info .= "
Not available yet"; @@ -484,12 +484,12 @@ class AmdaAction { $disable = $restricted || $nonavailable || $obsolete; $childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType, 'isAddable' => $isAddable, - 'info' => $info, 'leaf' => false, 'isRemoteDataSet' => $isRemoteDataSet, 'disable' => $disable, - 'isSimulation' => $isSimulation, 'rank' => $rank, 'isDeletable' => $isDeletable, 'help' => $help); + 'info' => $info, 'leaf' => false, 'isRemoteDataSet' => $isRemoteDataSet, 'disable' => $disable, + 'isSimulation' => $isSimulation, 'rank' => $rank, 'isDeletable' => $isDeletable, 'help' => $help); } - + break; - case 'myData' : + case 'myData' : $info = $child->hasAttribute('info') ? $child->getAttribute('info') : $child->nodeValue; // $info = str_replace("\n","
",$info); break; @@ -504,7 +504,7 @@ class AmdaAction { $mask = $child->getAttribute('mask'); $isSpectra = false; - + if ($isLeaf) { $isParameter = true; $info = "Size: ".$size."
".$child->getAttribute('desc')."
Mask: ".$mask; @@ -516,24 +516,24 @@ class AmdaAction { $globalStop = substr(str_replace( '-','/',$child->getAttribute('desc')), 17, 22); } - $childrenToReturn[] = array('text' => $name, 'size' => $size, 'id' => $id, + $childrenToReturn[] = array('text' => $name, 'size' => $size, 'id' => $id, 'globalStart' => $globalStart, 'globalStop' => $globalStop, - 'nodeType' => $nodeType, 'info' => $info, 'isScatter' => $isScatter, 'leaf' => $isLeaf, + 'nodeType' => $nodeType, 'info' => $info, 'isScatter' => $isScatter, 'leaf' => $isLeaf, 'isParameter' => $isParameter, 'linkedMask' => $mask, 'isSpectra' => $isSpectra); break; - default: + default: } - + if (!$specialNode && !$skip) { - if ($child->hasAttribute('desc')) + if ($child->hasAttribute('desc')) $info = $child->getAttribute('desc'); - $childrenToReturn[] = array('text' => $name, 'id' => $id, 'nodeType' => $nodeType, 'info' => $info, + $childrenToReturn[] = array('text' => $name, 'id' => $id, 'nodeType' => $nodeType, 'info' => $info, 'help' => $help, 'leaf' => $isLeaf, 'isParameter' => $isParameter); } } // if $childrenToReturn we have to return [] - if ($childrenToReturn == null) { + if ($childrenToReturn == null) { $childrenToReturn = array('nodeType' => $nodeType, 'text' => null); } } @@ -541,106 +541,106 @@ class AmdaAction { return $childrenToReturn; } - public function saveTree($obj) + public function saveTree($obj) { $paramMgr = new ParamMgr(); - return $paramMgr->saveTree($obj); + return $paramMgr->saveTree($obj); } - public function doNothing($obj) - { + public function doNothing($obj) + { return array("res" => 'ok'); - + } - public function deleteFromTree($obj) - { + public function deleteFromTree($obj) + { $paramMgr = new ParamMgr(); return $paramMgr->deleteFromTree($obj); - + } /* * temporary object fromUpload -*/ +*/ public function getUploadedObject($name, $format, $nodeType) - { - switch ($nodeType) + { + switch ($nodeType) { - case 'timeTable' : - $objectMgr = new TimeTableMgr(); + case 'timeTable' : + $objectMgr = new TimeTableMgr(); break; - case 'myDataParam' : - $objectMgr = new FilesMgr(); + case 'myDataParam' : + $objectMgr = new FilesMgr(); break; default: return array("error" => $nodeType." NOT_IMPLEMENTED_YET"); } return $objectMgr -> getUploadedObject($name, $format, true); - } + } /* -* fill ascii file into grid -*/ - public function getAsciiFile($obj) - { - $objectMgr = new FilesMgr(); +* fill ascii file into grid +*/ + public function getAsciiFile($obj) + { + $objectMgr = new FilesMgr(); return $objectMgr -> getAsciiFile($obj->fileName); } - - public function getMyParamInfo($object) - { - $objectMgr = new FilesMgr(); + + public function getMyParamInfo($object) + { + $objectMgr = new FilesMgr(); return $objectMgr -> getParamInfo($object); - } + } /* -* temporary object from Search -*/ - public function getTmpObject($folderId, $name, $nodeType) { +* temporary object from Search +*/ + public function getTmpObject($folderId, $name, $nodeType) { + - switch ($nodeType) { - case 'timeTable' : - $objectMgr = new TimeTableMgr(); - break; + case 'timeTable' : + $objectMgr = new TimeTableMgr(); + break; case 'catalog' : - $objectMgr = new CatalogMgr(); - break; + $objectMgr = new CatalogMgr(); + break; default: return array("error" => $nodeType." NOT_IMPLEMENTED_YET"); } return $objectMgr -> getTmpObject($folderId, $name, true); } - - public function getObject($id, $nodeType) { - + + public function getObject($id, $nodeType) { + switch ($nodeType) { case 'myDataParam': - case 'derivedParam' : - $objectMgr = new DerivedParamMgr($nodeType); + case 'derivedParam' : + $objectMgr = new DerivedParamMgr($nodeType); break; - case 'timeTable' : + case 'timeTable' : case 'sharedtimeTable' : - $objectMgr = new TimeTableMgr(); - break; + $objectMgr = new TimeTableMgr(); + break; case 'catalog' : case 'sharedcatalog' : - $objectMgr = new CatalogMgr(); - break; - case 'condition' : + $objectMgr = new CatalogMgr(); + break; + case 'condition' : case 'request' : - $objectMgr = new RequestMgr($nodeType); - break; + $objectMgr = new RequestMgr($nodeType); + break; case 'bkgWorks' : require_once(INTEGRATION_SRC_DIR."RequestManager.php"); return $this->executeRequest($id, FunctionTypeEnumClass::PROCESSGETINFO); break; case 'myData' : - $objectMgr = new FilesMgr(); + $objectMgr = new FilesMgr(); break; default: return array("error" => $nodeType." NOT_IMPLEMENTED_YET"); @@ -651,28 +651,28 @@ class AmdaAction { /* * $obj = { id: node.id, leaf: node.leaf, nodeType: node.nodeType } */ - public function deleteObject($obj) { - - switch ($obj->nodeType) { - - case 'myDataParam' : - case 'derivedParam' : - $objectMgr = new DerivedParamMgr($obj->nodeType); + public function deleteObject($obj) { + + switch ($obj->nodeType) { + + case 'myDataParam' : + case 'derivedParam' : + $objectMgr = new DerivedParamMgr($obj->nodeType); break; - case 'timeTable' : - $objectMgr = new TimeTableMgr(); - break; - case 'catalog' : - $objectMgr = new CatalogMgr(); + case 'timeTable' : + $objectMgr = new TimeTableMgr(); break; - case 'condition' : + case 'catalog' : + $objectMgr = new CatalogMgr(); + break; + case 'condition' : case 'request' : - $objectMgr = new RequestMgr($obj->nodeType); + $objectMgr = new RequestMgr($obj->nodeType); break; case 'alias' : $objectMgr = new AliasMgr(); $obj->id = substr($obj->id,strlen('alias_')); - break; + break; case 'bkgWorks' : require_once(INTEGRATION_SRC_DIR."RequestManager.php"); return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSDELETE); @@ -690,27 +690,27 @@ class AmdaAction { /* * $obj = { id: node.id, old_name: node.text, name: value, parent : node.parentNode.id, leaf: node.leaf, nodeType: node.nodeType } */ - public function renameObject($obj) { - + public function renameObject($obj) { + switch ($obj->nodeType) { - + case 'myDataParam' : - case 'derivedParam' : - $objectMgr = new DerivedParamMgr($obj->nodeType); + case 'derivedParam' : + $objectMgr = new DerivedParamMgr($obj->nodeType); break; - case 'timeTable' : - $objectMgr = new TimeTableMgr(); + case 'timeTable' : + $objectMgr = new TimeTableMgr(); break; - case 'catalog' : - $objectMgr = new CatalogMgr(); - break; - case 'condition' : - case 'request' : - $objectMgr = new RequestMgr($obj->nodeType); + case 'catalog' : + $objectMgr = new CatalogMgr(); + break; + case 'condition' : + case 'request' : + $objectMgr = new RequestMgr($obj->nodeType); break; case 'alias' : - $objectMgr = new AliasMgr(); - break; + $objectMgr = new AliasMgr(); + break; default: return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET"); } @@ -718,33 +718,33 @@ class AmdaAction { return $objectMgr -> renameObject($obj); } -/* +/* * $obj = { name: obj.name, obj.nodeType, obj.leaf (??), OBJ DEPENDENT ATTRIBUTES } */ - public function createObject($obj, $folder) { - + public function createObject($obj, $folder) { + switch ($obj->nodeType) { - case 'myDataParam' : + case 'myDataParam' : case 'derivedParam' : - if ($obj->nodeType == 'derivedParam' && $this->amdaStat->success) + if ($obj->nodeType == 'derivedParam' && $this->amdaStat->success) $this->amdaStat->addTask('create', $this->user, null); - $objectMgr = new DerivedParamMgr($obj->nodeType); - break; - case 'timeTable' : - $objectMgr = new TimeTableMgr(); - break; - case 'catalog' : - $objectMgr = new CatalogMgr(); + $objectMgr = new DerivedParamMgr($obj->nodeType); + break; + case 'timeTable' : + $objectMgr = new TimeTableMgr(); + break; + case 'catalog' : + $objectMgr = new CatalogMgr(); break; case 'condition' : - case 'request' : - $objectMgr = new RequestMgr($obj->nodeType); - break; + case 'request' : + $objectMgr = new RequestMgr($obj->nodeType); + break; case 'alias' : - $objectMgr = new AliasMgr(); - break; + $objectMgr = new AliasMgr(); + break; default: return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET"); } @@ -752,33 +752,33 @@ class AmdaAction { return $objectMgr -> createObject($obj, $folder); } -/* +/* * $obj = { id:obj.id, name: obj.name, obj.nodeType, obj.leaf (??), OBJ DEPENDENT ATTRIBUTES } */ public function modifyObject($obj) { - - switch ($obj->nodeType) { - case 'myDataParam' : - case 'derivedParam' : - $objectMgr = new DerivedParamMgr($obj->nodeType); + switch ($obj->nodeType) { + + case 'myDataParam' : + case 'derivedParam' : + $objectMgr = new DerivedParamMgr($obj->nodeType); + break; + case 'timeTable' : + $objectMgr = new TimeTableMgr(); break; - case 'timeTable' : - $objectMgr = new TimeTableMgr(); + case 'catalog' : + $objectMgr = new CatalogMgr(); break; - case 'catalog' : - $objectMgr = new CatalogMgr(); - break; - case 'condition' : + case 'condition' : case 'request' : - $objectMgr = new RequestMgr($obj->nodeType); + $objectMgr = new RequestMgr($obj->nodeType); break; default: return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET"); } return $objectMgr -> modifyObject($obj); - } + } /* * {obj.name, obj.nodeType, obj.leaf} */ @@ -814,7 +814,7 @@ class AmdaAction { public function getJobs() { require_once(INTEGRATION_SRC_DIR."RequestManager.php"); - return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSRUNNINGINFO); + return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSRUNNINGINFO); } @@ -828,8 +828,8 @@ class AmdaAction { $this->user = NEWKERNEL_DEBUG_USER; return array('success' => true); } - - + + if (isset($obj->username) && isset($obj->password) && isset($obj->sessionID)) { //$dd = new WSUserMgr(); @@ -838,11 +838,11 @@ class AmdaAction { } else $dd = new UserMgr(); - - //TODO error handling + + //TODO error handling if (($res = $dd -> ddCheckUser()) != 0) { - if ($res == 156) + if ($res == 156) return array('success' => false, 'message' => 'Your AMDA session is expired.
Login please!'); return array('success' => false, 'message' => 'ddLogin error: '.$res); @@ -860,42 +860,42 @@ class AmdaAction { if ($dd->getWsSize() > DISK_QUOTA) return array('success' => false, 'message' => 'Please clean up your workspace.
No more space is available'); } - + $this->user = $dd->user; - + return array('success' => true, 'userHost' => $dd -> getIPclient()); } - + private function executeRequest($obj, $function) { $res = $this->checkUser($obj); - + if (!$res['success']) return $res; - + $requestManager = new RequestManagerClass(); - + try { $res = $requestManager->runIHMRequest($this->user, $res['userHost'], $function, $obj); } catch (Exception $e) { return array('success' => false, 'message' => 'Exception detected : '.$e->getMessage()); } - + return $res; } - -/* -* Main EXECUTE PROCEDURE + +/* +* Main EXECUTE PROCEDURE */ public function execute($node, $obj) - { + { require_once(INTEGRATION_SRC_DIR."RequestManager.php"); if (isset($obj->action)) return $this->executeRequest($obj, FunctionTypeEnumClass::ACTION); else return $this->executeRequest($obj, FunctionTypeEnumClass::PARAMS); } - + /* * Generate derived parameter compilation */ @@ -912,23 +912,23 @@ class AmdaAction { { require_once(INTEGRATION_SRC_DIR."RequestManager.php"); $res = $this->checkUser($obj); - + if (!$res['success']) return $res; - + IHMConfigClass::setUserName($this->user); $libParamPath = IHMConfigClass::getCompilationPath()."lib/".$obj->paramId.".so"; if (file_exists($libParamPath)) unlink($libParamPath); return array("success" => true); } - + /* * kill plot process */ - + public function killPlotRequest() - { + { require_once(INTEGRATION_SRC_DIR."RequestManager.php"); return $this->executeRequest((object) array('nodeType' => 'killplot'), FunctionTypeEnumClass::PARAMS); } @@ -940,14 +940,14 @@ class AmdaAction { if ($this->amdaStat->success) $this->amdaStat->addTask('ttoper', $this->user, null); - + $objectMgr = new TimeTableMgr(); return $objectMgr -> merge($obj); } - + /* * intersect time tables */ @@ -961,117 +961,117 @@ class AmdaAction { return $result; } - + public function initTTCache($isCatalog = false, $nparams) { if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr(); else $cacheMgr = new CatalogCacheMgr(); - + return $cacheMgr->initTTCache($nparams); } - - + + public function initTTCacheFromTT($id, $type) { if ($type == 'catalog' || $type == 'sharedcatalog') $cacheMgr = new CatalogCacheMgr(); else $cacheMgr = new TimeTableCacheMgr(); - + return $cacheMgr->initFromTT($id, $type); } - + public function initForChart($id, $name, $isTmpObject, $type) { if ($type == 'catalog' || $type == 'sharedcatalog') $objMgr = new CatalogMgr(); - + return $objMgr->initForChart($id, $name, $isTmpObject, $type); } - + public function initTTCacheFromTmpObject($folderId, $name, $isCatalog = false) { if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr(); - + else $cacheMgr = new CatalogCacheMgr(); - - - + + + return $cacheMgr->initFromTmpObject($folderId, $name); } - + public function initTTCacheFromUploadedFile($name, $format) { $cacheMgr = new TimeTableCacheMgr(); return $cacheMgr->initFromUploadedFile($name, $format); } - + public function readTTCacheIntervals($o) { if ($o->typeTT == 'catalog' || $type == 'sharedcatalog') $cacheMgr = new CatalogCacheMgr(); else $cacheMgr = new TimeTableCacheMgr(); - + return $cacheMgr->getIntervals($o->start,$o->limit,$o->sort,$o->filter); } - + public function readIntervalsForChart($o) { if ($o->typeTT == 'catalog' || $type == 'sharedcatalog') $objMgr = new CatalogMgr(); - - + + return $objMgr->getIntervalsForChart($o->id, $o->name, $o->fromPlugin, $o->typeTT); } - + public function saveTTCacheIntervalsInTT($o) { $cacheMgr = new TimeTableCacheMgr(); return $cacheMgr->saveInTT($o->ttId,$o->action,$o->cacheToken); } - + public function addTTCacheInterval($o) { if ($o->isCatalog) $cacheMgr = new CatalogCacheMgr(); else $cacheMgr = new TimeTableCacheMgr(); - + return $cacheMgr->addInterval($o->index, $o->start, $o->stop); } - + public function removeTTCacheIntervalFromId($id, $isCatalog = false) { if ($isCatalog) $cacheMgr = new CatalogCacheMgr(); else $cacheMgr = new TimeTableCacheMgr(); - + return $cacheMgr->removeIntervalFromId($id); } - + public function modifyTTCacheInterval($o) { if ($o->isCatalog) { - + $cacheMgr = new CatalogCacheMgr(); return $cacheMgr->modifyIntervalFromId($o); - + } else $cacheMgr = new TimeTableCacheMgr(); - + return $cacheMgr->modifyIntervalFromId($o->cacheId, $o->start, $o->stop); } - + public function operationTTCacheIntervals($extendTime, $shiftTime) { $cacheMgr = new TimeTableCacheMgr(); return $cacheMgr->operationIntervals($extendTime, $shiftTime); } - + public function mergeTTCacheIntervals() { $cacheMgr = new TimeTableCacheMgr(); return $cacheMgr->mergeIntervals(); } - + public function getTTCacheStatistics() { $cacheMgr = new TimeTableCacheMgr(); return $cacheMgr->getStatistics(); } - + public function getTTCacheStatus() { $cacheMgr = new TimeTableCacheMgr(); @@ -1080,39 +1080,39 @@ class AmdaAction { /* * Send a feedback - * + * */ public function sendFeedback($feed) { $feedMgr = new FeedbackMgr(); return $feedMgr->addFeedback($feed->user, $feed->interface, $feed->subject, $feed->userText, $feed->userAgent, $feed->attach); } - + /* * Save state - * + * */ public function saveState($datas) { $myStateMgr = new StateMgr(); return $myStateMgr->saveState($datas); } - + /* * Load state - * - */ + * + */ public function loadState($o) - { + { $myStateMgr = new StateMgr(); return $myStateMgr->loadState(); } - -/* + +/* * SAMP */ public function sendToSAMP($o) - { + { if ($this->amdaStat->success) $this->amdaStat->addTask('samp', $this->user, null); @@ -1125,7 +1125,7 @@ class AmdaAction { } return $res; } - + /* * HST Images */ @@ -1133,30 +1133,30 @@ class AmdaAction { { if ($this->amdaStat->success) $this->amdaStat->addTask('images', $this->user, null); - + $myHstMgr = new HstMgr(); $res = $myHstMgr->getImagesUrl($o->startTime, $o->stopTime, $o->planet); //if ($domRes->length <= 0) // return array('success' => false, 'message' => 'Cannot find HST Images for this request.'); return array('success' => true, 'result' => $res); } - + public function getAPISImagesUrl($o) { - if ($this->amdaStat->success) + if ($this->amdaStat->success) $this->amdaStat->addTask('images', $this->user, null); - + $apisMgr = new APISMgr(); $res = $apisMgr->get($o->target, $o->startTime, $o->stopTime, $o->datasets); return $res; - } + } /* * Filters */ public function loadFilterList($o) { - $filtersMgr = new FiltersMgr(); + $filtersMgr = new FiltersMgr(); $res = $filtersMgr->loadList(); return $res; } @@ -1170,52 +1170,52 @@ class AmdaAction { $res = $filtersMgr->loadAll(); return $res; } - + public function saveFilter($o) { - $filtersMgr = new FiltersMgr(); + $filtersMgr = new FiltersMgr(); return $filtersMgr->save($o); } - + public function createFilter($o) { - $filtersMgr = new FiltersMgr(); + $filtersMgr = new FiltersMgr(); return $filtersMgr->create($o); } - + public function destroyFilter($o) { $filtersMgr = new FiltersMgr(); $res = $filtersMgr->delete($o); return; } - + public function getCrtFilterId() { $filtersMgr = new FiltersMgr(); $res = $filtersMgr->getCrtId(); return $res; } - + public function getCrtFilterResult() { - $filtersMgr = new FiltersMgr(); + $filtersMgr = new FiltersMgr(); return $filtersMgr->getCrtResult(); } - + public function setCrtFilterId($o) { - $filtersMgr = new FiltersMgr(); + $filtersMgr = new FiltersMgr(); return $filtersMgr->setCrtId($o->id); } - + public function resetFilter() { $filtersMgr = new FiltersMgr(); $res = $filtersMgr->reset(); return $res; } - + public function logout($isGuest) { if ($isGuest) { @@ -1224,25 +1224,25 @@ class AmdaAction { } else { $myBaseMgr = new BaseManager(); - $myBaseMgr->delSimuFiles('mysimudata'); - $myBaseMgr->delSimuFiles('mywsrdata'); - + $myBaseMgr->delSimuFiles('mysimudata'); + $myBaseMgr->delSimuFiles('mywsrdata'); + $this->cleanUserWS(); - } + } return; - } + } public function getInfo($obj) { - if (file_exists(HELPPATH.$obj->name)) + if (file_exists(HELPPATH.$obj->name)) { - $content = file_get_contents(HELPPATH.$obj->name); + $content = file_get_contents(HELPPATH.$obj->name); return array('success' => true, 'result' => $content); } return array('success' => false); - - } - + + } + public function getUserInfo() { $dd = new UserMgr(); @@ -1262,11 +1262,11 @@ class AmdaAction { $myBestRunsMgr = new BestRunsMgr(); $res = $myBestRunsMgr->getRun($obj); - - return $res; + + return $res; } - - //$obj = array of IDs + + //$obj = array of IDs public function addRun($obj) { $myBestRunsMgr = new BestRunsMgr(); @@ -1275,7 +1275,7 @@ class AmdaAction { $res = array('success' => true,'addedRuns' => $obj); return $res; - } + } //AKKA - New action to clean user WS public function cleanUserWS() { @@ -1285,11 +1285,11 @@ class AmdaAction { public function deleteSpecialInfo($name) { - if (file_exists(USERDIR.$name)) + if (file_exists(USERDIR.$name)) unlink(USERDIR.$name); return array('success' => true); } - + public function interactivePlot($obj, $multiPlotState) { require_once(INTEGRATION_SRC_DIR."RequestManager.php"); @@ -1299,7 +1299,7 @@ class AmdaAction { ); return $this->executeRequest($inputobj, FunctionTypeEnumClass::ACTION); } - + public function getParamPlotInit($obj) { require_once(INTEGRATION_SRC_DIR."RequestManager.php"); @@ -1309,7 +1309,7 @@ class AmdaAction { ); return $this->executeRequest($inputobj, FunctionTypeEnumClass::PARAMINFO); } - + public function getParamInfo($obj) { require_once(INTEGRATION_SRC_DIR."RequestManager.php"); @@ -1319,14 +1319,14 @@ class AmdaAction { ); return $this->executeRequest($inputobj, FunctionTypeEnumClass::PARAMINFO); } - + public function getSharedObjectFolders($obj) { $mgr = new SharedObjectsMgr(); $folders = $mgr->getFolders($obj->type); return array('success' => true, 'folders' => $folders); } - + public function shareObjects($obj) { $mgr = new SharedObjectsMgr(); @@ -1335,19 +1335,19 @@ class AmdaAction { case 'catalog' : $src_object_path = USERTTDIR.$obj->object->id.".xml"; break; - + default: return array('success' => false, 'message' => 'Unknown object type'); } - + $result = $mgr->add($obj->type, $obj->name, $obj->folder, $src_object_path, $obj->description, $this->user); if (!$result['success']) return $result; - + $mgr->updateTree(); return $result; } - + public function isSharedObjectNameAlreadyUsed($obj) { $mgr = new SharedObjectsMgr(); @@ -1360,4 +1360,3 @@ class AmdaAction { } } ?> - diff --git a/php/classes/EpnTapMgr.php b/php/classes/EpnTapMgr.php index ab158c9..2bbcbca 100644 --- a/php/classes/EpnTapMgr.php +++ b/php/classes/EpnTapMgr.php @@ -8,13 +8,13 @@ class EpnTapMgr { function __construct() { - $this->logEpnTap = fopen(USERDATADIR."logEpnTap", "a"); + $this->logEpnTap = fopen(LOG_DIR . "epnTap.log", "a"); $this->addLog("\n---\n"); } function addLog($msg) { - fwrite($this->logEpnTap, date("h:i:s A") . $msg . "\n"); + fwrite($this->logEpnTap, date("h:i:s A") . ": " . $msg . "\n"); } public function call($function_name, $args) { @@ -45,8 +45,7 @@ class EpnTapMgr { $monthp = $month; } - # this checks where we are in relation to October 15, 1582, the beginning - # of the Gregorian calendar. + # this checks where we are in relation to October 15, 1582, the beginning of the Gregorian calendar. if (($year < 1582) || ($year == 1582 && $month < 10) || ($year == 1582 && $month == 10 && $day < 15)) @@ -60,53 +59,34 @@ class EpnTapMgr { return $j_day; } - private function getServiceNbResults($table_name, $access_url, $target_name, $dataproduct_type, $time_min, $time_max) { - // $this->addLog("getServiceNbResults(" . $table_name .", ". $access_url .", ". $target_name .", ". $dataproduct_type .", ". $time_min .", ". $time_max . ")"); + public function createFilter($target_name, $dataproduct_type, $time_min, $time_max) { $filter = array(); if($target_name) array_push($filter, "target_name = '$target_name'"); if($dataproduct_type) array_push($filter, "dataproduct_type = '$dataproduct_type'"); if($time_min) - array_push($filter, "time_min >= " . $this->date2JD($time_min)); + array_push($filter, "time_min <= " . $this->date2JD($time_min)); if($time_max) array_push($filter, "time_max >= " . $this->date2JD($time_max)); - $query = "SELECT COUNT(granule_uid) AS nb_results FROM $table_name.epn_core" - . (count($filter) > 0 ? ' WHERE '.join(' AND ', $filter) : ''); - - $this->addLog("query: " . $query); + return (count($filter) > 0 ? ' WHERE '.join(' AND ', $filter) : ''); + } + public function request($access_url, $query) { $votMgr = new VOTableMgr; $params = 'FORMAT=votable&LANG=ADQL&REQUEST=doQuery'; $url = $access_url . '/sync?' . $params . '&QUERY=' . urlencode($query); - $this->addLog("URL: " . $url); + $this->addLog("Query URL: " . $url); $votMgr->load($url); - $res = $votMgr->isValidSchema() ? $votMgr->getStream() : "-"; - return $res["nb_results"]; + $result = $votMgr->isValidSchema() ? $votMgr->parseStream() : NULL; + return $result; } private function getGranules($table_name, $access_url, $target_name, $dataproduct_type, $time_min, $time_max) { - $this->addLog("getGranules(" . $table_name .", ". $access_url .", ". $target_name .", ". $dataproduct_type .", ". $time_min .", ". $time_max . ")"); - $filter = array(); - if($target_name) - array_push($filter, "target_name = '$target_name'"); - if($dataproduct_type) - array_push($filter, "dataproduct_type = '$dataproduct_type'"); - if($time_min) - array_push($filter, "time_min >= " . $this->date2JD($time_min)); - if($time_max) - array_push($filter, "time_max >= " . $this->date2JD($time_max)); - - $query = "SELECT dataproduct_type, target_name, time_min, time_max FROM $table_name.epn_core" - . ($filter.length > 0 ? ' WHERE ' . join(' AND ', $filter) : ''); - - $votMgr = new VOTableMgr; - $params = 'FORMAT=votable&LANG=ADQL&REQUEST=doQuery'; - $url = $access_url . '/sync?' . $params . '&QUERY=' . urlencode($query); - $votMgr->load($url); - $res = $votMgr->isValidSchema() ? $votMgr->getStream() : "-"; - return $res; + $filter = $this->createFilter($target_name, $dataproduct_type, $time_min, $time_max); + $query = "SELECT dataproduct_type, target_name, time_min, time_max FROM $table_name.epn_core" . $filter; + return $this->request($access_url, $query); } } ?> diff --git a/php/classes/VOTableMgr.php b/php/classes/VOTableMgr.php index 26f6baa..53d1091 100644 --- a/php/classes/VOTableMgr.php +++ b/php/classes/VOTableMgr.php @@ -9,20 +9,22 @@ define("DEBUG_MODE", TRUE); class VOTableMgr { - private $xml, $xp; - private $log; - - function __construct() - { - if (DEBUG_MODE) - $this->log = fopen(USERDATADIR."logVOTable", "a"); - } + private $xml, $xp; + private $logVotable; // The log file. + private $stream; // The stream in the VOTable + private $c; // Current character position on the stream + + function __construct() + { + if (DEBUG_MODE) + $this->logVotable = fopen(LOG_DIR . "VOTable.log", "a"); + } - function addLog($msg) - { - if (DEBUG_MODE) - fprintf($this->log, $msg."\n"); - } + function addLog($msg) + { + if (DEBUG_MODE) + fwrite($this->logVotable, date("h:i:s A") . ": " . $msg . "\n"); + } function load($fileName) { $this->addLog("File name" . $fileName); @@ -35,10 +37,11 @@ class VOTableMgr { libxml_set_streams_context($context); $this->xml = new DomDocument(); - if (!$this->xml->load($fileName)) - { - $this->xml = false; - return FALSE; + $res = $this->xml->load($fileName); + + if(!$res) { + $this->addLog("Can not load VOTAble."); + return false; } $this->checkIDAttribute(); @@ -58,113 +61,125 @@ class VOTableMgr { return true; } - function isValidSchema() - { - if (!$this->xml) - return FALSE; - - - //ToDo - BRE - add validation!! - return TRUE; - - if (DEBUG_MODE) - libxml_use_internal_errors(true); - - $vers = $this->getVersion(); - - $this->addLog("VOTable version : ".$vers."\n"); - - $result = FALSE; - - switch ($vers) - { - case '1.2' : - $result = $this->xml->schemaValidate(XMLPATH.'VOTable-1.2.xsd'); - case '1.0' : - $result = $this->xml->schemaValidate(XMLPATH.'VOTable-1.0.xsd'); - default : - $result = $this->xml->schemaValidate(XMLPATH.'VOTable-1.1.xsd'); - } - - if (DEBUG_MODE) - { - $errors = libxml_get_errors(); - - foreach ($errors as $error) - { - $msg = ''; - - switch ($error->level) - { - case LIBXML_ERR_WARNING: - $msg .= ("WARNING ".$error->code.": "); - break; - case LIBXML_ERR_ERROR: - $msg .= ("ERROR ".$error->code.": "); - break; - case LIBXML_ERR_FATAL: - $msg .= ("FATAL ".$error->code.": "); - break; - } - $msg .= ($error->message." - In line : ".$error->line." - Of file : ".$error->file."\n"); - - $this->addLog($msg); - } - - libxml_use_internal_errors(false); - } - - return $result; - } - - protected function queryResource() - { - return "//x:RESOURCE"; - } - - protected function queryTable() - { - return $this->queryResource()."/x:TABLE"; - } - - protected function queryDescription() - { - return $this->queryTable()."/x:DESCRIPTION"; - } - - protected function queryFields() - { - return $this->queryTable()."/x:FIELD"; - } - - protected function queryField($field_id) - { - return $this->queryFields()."[@ID='".$field_id."']"; - } - - protected function queryFieldByName($field_id) - { - return $this->queryFields()."[@name='".$field_id."']"; - } - protected function queryFieldDescription($field_id) - { - return $this->queryField($field_id)."/x:DESCRIPTION"; - } - - protected function queryData() - { - return $this->queryTable()."/x:DATA"; - } - - protected function queryTableData() - { - return $this->queryData()."/x:TABLEDATA"; - } - - protected function queryTR() - { - return $this->queryTableData()."/x:TR"; - } + function isValidSchema() + { + if (!$this->xml) + return FALSE; + + $infos = $this->xp->query($this->queryResourceInfo()); + foreach($infos as $info) { + if($info->getAttribute('value') == 'ERROR') { + $this->addLog("There is an error on the VOTable: " . $info->textContent); + return FALSE; + } + } + + //ToDo - BRE - add validation!! + return TRUE; + + if (DEBUG_MODE) + libxml_use_internal_errors(true); + + $vers = $this->getVersion(); + + $this->addLog("VOTable version : ".$vers."\n"); + + $result = FALSE; + + switch ($vers) + { + case '1.2' : + $result = $this->xml->schemaValidate(XMLPATH.'VOTable-1.2.xsd'); + case '1.0' : + $result = $this->xml->schemaValidate(XMLPATH.'VOTable-1.0.xsd'); + default : + $result = $this->xml->schemaValidate(XMLPATH.'VOTable-1.1.xsd'); + } + + if (DEBUG_MODE) + { + $errors = libxml_get_errors(); + + foreach ($errors as $error) + { + $msg = ''; + + switch ($error->level) + { + case LIBXML_ERR_WARNING: + $msg .= ("WARNING ".$error->code.": "); + break; + case LIBXML_ERR_ERROR: + $msg .= ("ERROR ".$error->code.": "); + break; + case LIBXML_ERR_FATAL: + $msg .= ("FATAL ".$error->code.": "); + break; + } + $msg .= ($error->message." - In line : ".$error->line." - Of file : ".$error->file."\n"); + + $this->addLog($msg); + } + + libxml_use_internal_errors(false); + } + + return $result; + } + + protected function queryResource() + { + return "//x:RESOURCE"; + } + + protected function queryResourceInfo() + { + return $this->queryResource()."/x:INFO"; + } + + protected function queryTable() + { + return $this->queryResource()."/x:TABLE"; + } + + protected function queryDescription() + { + return $this->queryTable()."/x:DESCRIPTION"; + } + + protected function queryFields() + { + return $this->queryTable()."/x:FIELD"; + } + + protected function queryField($field_id) + { + return $this->queryFields()."[@ID='".$field_id."']"; + } + + protected function queryFieldByName($field_id) + { + return $this->queryFields()."[@name='".$field_id."']"; + } + protected function queryFieldDescription($field_id) + { + return $this->queryField($field_id)."/x:DESCRIPTION"; + } + + protected function queryData() + { + return $this->queryTable()."/x:DATA"; + } + + protected function queryTableData() + { + return $this->queryData()."/x:TABLEDATA"; + } + + protected function queryTR() + { + return $this->queryTableData()."/x:TR"; + } protected function queryBinaryData() { return $this->queryData()."/x:BINARY"; @@ -175,448 +190,532 @@ class VOTableMgr { } - public function getVersion() - { - if (!$this->xml) - return ''; - $root = $this->xml->documentElement; + public function getVersion() + { + if (!$this->xml) + return ''; + $root = $this->xml->documentElement; - return $root->getAttribute('version'); - } + return $root->getAttribute('version'); + } - public function getDescription() - { - if (!$this->xp) - return ''; + public function getDescription() + { + if (!$this->xp) + return ''; - $desc = $this->xp->query($this->queryDescription()); + $desc = $this->xp->query($this->queryDescription()); - if ($desc->length < 1) - return ''; + if ($desc->length < 1) + return ''; - return $desc->item(0)->nodeValue; - } + return $desc->item(0)->nodeValue; + } + + private function get_block_size($data_type) { + switch($data_type) { + case 'boolean': + case 'unsignedByte': + case 'char': + $block_size = 1; + break; + case 'unicodeChar': + case 'short': + $block_size = 2; + break; + case 'int': + case 'float': + $block_size = 4; + break; + case 'long': + case 'double': + case 'float_complex': + $block_size = 8; + break; + case 'double_complex': + $block_size = 8; + break; + default: + $block_size = 0; + break; + } + return $block_size; + } + + private function get_row_size($field_node) { + $datatype = $field_node->getAttribute("datatype"); + $block_size = $this->get_block_size($datatype); + if($field_node->getAttribute("arraysize") == NULL) { + $array_size = $block_size; + } else if("*" == $field_node->getAttribute("arraysize")) { + // echo "substr: " . json_encode(substr($this->stream, $this->c, 4)) . "\n"; + $array_size = unpack("Ns", substr($this->stream, $this->c, 4))["s"] * $block_size; + // echo "array_size: $array_size\n"; + $this->c+=4; + } else { + $array_size = (int)($field_node->getAttribute("arraysize")) * $block_size; + } + return $array_size; + } /** Get the VOTable stream content.*/ - // TODO: faire une fonction générique avec le curseur qui se déplace et tout et qui renvoie un dictionnaire - public function getStream() { - $fields = array(); - $stream = $this->xp->query($this->queryStream())->item(0)->textContent; - $ar = unpack("C*", base64_decode($stream)); - $c = 0; // cursor - foreach ($this->xp->query($this->queryFields()) as $field) { - $datatype = $field->getAttribute("datatype"); - $id = $field->getAttribute("ID"); // column name - switch ($datatype) { - case 'char': - $str_length = ($ar[1]<<24) + ($ar[2]<<16) + ($ar[3]<<8) + $ar[4]; - $res = ""; - for($i=0 ; $i<$str_length ; $i++) { - $res = $res . chr($ar[$i+5]); - } - break; - case 'int': - $res = ($ar[1]<<24) + ($ar[2]<<16) + ($ar[3]<<8) + $ar[4]; - break; - case 'double': - $this->addLog("Parsing double"); - $res = "Float parsing not implemented yet.";//($ar[1]<<24) + ($ar[2]<<16) + ($ar[3]<<8) + $ar[4]; - break; - - default: - break; + public function parseStream() { + $data = Array(); + $fields = $this->xp->query($this->queryFields()); + $nb_columns = $fields->length; + $row = Array(); + $n_value = 0; // index of current value + $this->c = 0; // initialize cursor position. + $query_stream = $this->xp->query($this->queryStream())->item(0); + if($query_stream == NULL) + return NULL; + $this->stream = base64_decode($query_stream->textContent); + // echo "stream: " . json_encode($this->stream) . "\n"; + $stream_len = strlen($this->stream); + if($stream_len == 0) + return NULL; + while($this->c < strlen($this->stream)) { + $col_id = $n_value % $nb_columns; + $field_node = $fields[$col_id]; + + // echo "c=$this->c, n_value=$n_value, nb_columns=$nb_columns, col_id=$col_id, column_name=" . $field_node->getAttribute("ID") . "\n"; + + if($col_id == 0) { + $row = Array(); + } + $row[$field_node->getAttribute("ID")] = $this->process_datablock($field_node); + if($col_id == $nb_columns-1) { + array_push($data, $row); } - $this->addLog($id . "=" . $res); - $fields[$id] = $res; + $n_value+=1; + // echo "Char pos: $this->c\n"; } + return $data; + } - return $fields; - // return ($ar[1]<<24) + ($ar[2]<<16) + ($ar[3]<<8) + $ar[4]; + private function process_datablock($field_node) { + $data_type = $field_node->getAttribute("datatype"); + $row_size = $this->get_row_size($field_node); + // echo "datatype: " . $field_node->getAttribute("datatype") . "\n"; + // echo "Row size: $row_size\n"; + switch ($data_type) { + case 'boolean': + case 'unsignedByte': + $res = $this->stream[$this->c] == "T" || $this->stream[$this->c] == "t" || $this->stream[$this->c] == "1"; + break; + case 'char': + case 'unicodeChar': + $res = $row_size !=0 ? substr($this->stream, $this->c, $row_size) : NULL; + break; + case 'short': + $res = unpack("ss", substr($this->stream, $this->c, 2))["s"]; + break; + case 'int': + $res = unpack("Ns", substr($this->stream, $this->c, 4))["s"]; + break; + case 'long': + $res = unpack("Js", substr($this->stream, $this->c, 8))["s"]; // /!\ J -> PHP 5.6 only + break; + case 'float': + $res = unpack("fs", substr($this->stream, $this->c, 4))["s"]; + break; + case 'double': + $res = unpack("ds", substr($this->stream, $this->c, 8))["s"]; + break; + default: + $res = NULL; + $this->addLog("Unknown character: $data_type"); + break; + } + $this->c+=$row_size; + // echo $field_node->getAttribute("ID") . "($data_type $row_size) = " . json_encode($res) . "\n"; + return $res; } - public function getFirstTR() - { - if (!$this->xp) - return NULL; - /*$trs = $this->xp->query($this->queryTR()); + public function getFirstTR() + { + if (!$this->xp) + return NULL; - if ($trs->length < 1) - return NULL; + /*$trs = $this->xp->query($this->queryTR()); - return $trs->item(0);*/ + if ($trs->length < 1) + return NULL; - $tabledatas = $this->xp->query($this->queryTableData()); - if ($tabledatas->length < 1) - return NULL; + return $trs->item(0);*/ - $tabledata = $tabledatas->item(0); + $tabledatas = $this->xp->query($this->queryTableData()); + if ($tabledatas->length < 1) + return NULL; - $node = $tabledata->firstChild; + $tabledata = $tabledatas->item(0); - while($node && ($node->nodeType != 1) && ($node->nodeName != "TR")) - $node = $node->nextSibling; + $node = $tabledata->firstChild; - return $node; - } + while($node && ($node->nodeType != 1) && ($node->nodeName != "TR")) + $node = $node->nextSibling; - public function getNextTR($tr) - { - if (!$this->xp) - return NULL; + return $node; + } + + public function getNextTR($tr) + { + if (!$this->xp) + return NULL; - while($tr->nextSibling && ($tr->nextSibling->nodeType != 1) && ($node->nodeName != "TR")) - $tr = $tr->nextSibling; + while($tr->nextSibling && ($tr->nextSibling->nodeType != 1) && ($node->nodeName != "TR")) + $tr = $tr->nextSibling; return $tr->nextSibling; - } + } - public function getTDValueByFieldIndex($tr,$field_index) - { - if (!$this->xp) - return NULL; + public function getTDValueByFieldIndex($tr,$field_index) + { + if (!$this->xp) + return NULL; - $tds = $tr->getElementsByTagName("TD"); + $tds = $tr->getElementsByTagName("TD"); - if (($tds->length < 1) || ($field_index >= $tds->length)) - return NULL; + if (($tds->length < 1) || ($field_index >= $tds->length)) + return NULL; - return $tds->item($field_index)->nodeValue; - } + return $tds->item($field_index)->nodeValue; + } - protected function isTimeField($field) - { - if (!$this->xp) - return FALSE; + protected function isTimeField($field) + { + if (!$this->xp) + return FALSE; - return (($field->getAttribute("ucd") == "time.epoch") && ($field->getAttribute("xtype") == "dateTime")); - } + return (($field->getAttribute("ucd") == "time.epoch") && ($field->getAttribute("xtype") == "dateTime")); + } - public function getTimeFieldIndex() - { - if (!$this->xp) - return -1; + public function getTimeFieldIndex() + { + if (!$this->xp) + return -1; - $fields = $this->xp->query($this->queryFields()); + $fields = $this->xp->query($this->queryFields()); - if ($fields->length < 1) - return -1; + if ($fields->length < 1) + return -1; - for ($i = 0; $i < $fields->length; $i++) - if ($this->isTimeField($fields->item($i))) - return $i; + for ($i = 0; $i < $fields->length; $i++) + if ($this->isTimeField($fields->item($i))) + return $i; - return -1; - } + return -1; + } - protected function getFieldByID($field_id) - { - if (!$this->xp) - return NULL; + protected function getFieldByID($field_id) + { + if (!$this->xp) + return NULL; - $fields = $this->xp->query($this->queryFields()); + $fields = $this->xp->query($this->queryFields()); - if ($fields->length < 1) - return NULL; + if ($fields->length < 1) + return NULL; - foreach ($fields as $field) - if ($field->getAttribute("ID") == $field_id) - return $field; + foreach ($fields as $field) + if ($field->getAttribute("ID") == $field_id) + return $field; - return NULL; - } + return NULL; + } - protected function getFieldByName($field_id) - { - if (!$this->xp) - return NULL; + protected function getFieldByName($field_id) + { + if (!$this->xp) + return NULL; - $fields = $this->xp->query($this->queryFieldByName($field_id)); + $fields = $this->xp->query($this->queryFieldByName($field_id)); - if ($fields->length < 1) - return NULL; + if ($fields->length < 1) + return NULL; - foreach ($fields as $field) - if ($field->getAttribute("name") == $field_id) - return $field; + foreach ($fields as $field) + if ($field->getAttribute("name") == $field_id) + return $field; - return NULL; - } + return NULL; + } - protected function checkIDAttribute(){ + protected function checkIDAttribute(){ - $fields = $this->xml->getElementsByTagName('FIELD'); - $i = 0; - foreach ($fields as $field){ + $fields = $this->xml->getElementsByTagName('FIELD'); + $i = 0; + foreach ($fields as $field){ $i++; if (!$field->hasAttribute("ID")){ - $field->setAttribute("ID", "col".$i); - } - } - $this->xml->saveXML(); - - } - - public function getFieldIndexByID($field_id) - { - if (!$this->xp) - return -1; - - $fields = $this->xp->query($this->queryFields()); - - if ($fields->length < 1) - return -1; - - for ($i = 0; $i < $fields->length; $i++) - if ($fields->item($i)->getAttribute("ID") == $field_id) - return $i; - - return -1; - } - - public function getStartStop() - { - if (!$this->xp) - return '0 0'; - - $timeIndex = $this->getTimeFieldIndex(); - if ($timeIndex < 0) - return '0 0'; - - $tr = $this->getFirstTR(); - - if (!$tr) - return '0 0'; - - $start = $this->getTDValueByFieldIndex($tr,$timeIndex); - - $stop = $start; - while ($tr) - { - $stop = $this->getTDValueByFieldIndex($tr,$timeIndex); - $tr = $this->getNextTR($tr); - } - - if (!$start) - $start = 0; - else - $start = strtotime($start); - - if (!$stop) - $stop = 0; - else - $stop = strtotime($stop); - - return $start." ".$stop; - } - - public function getFieldInfoByID($field_id) - { - if (!$this->xp) - return array("id" => $field_id, - "error" => "No file loaded"); - - $field = $this->getFieldByID($field_id); - - if (!$field) - $field = $this->getFieldByName($field_id); - - if (!$field) - return array("id" => $field_id, - "error" => "This field doesn't exist"); - return $this->getFieldInfo($field); - } - - - public function getFieldInfo($field) - { - if (!$this->xp) - return array("id" => $field_id, - "error" => "No file loaded"); - $description = ''; - $desc = $field->getElementsByTagName("DESCRIPTION"); - if ($desc->length >= 1) - $description = $desc->item(0)->nodeValue; - - $size = $field->getAttribute("arraysize"); - if ($size == '') - $size = 1; - else - $size = intval($size); - - switch ($field->getAttribute("datatype")) - { - case "short" : - $type = "SHORT"; - break; - case "int" : - $type = "INTEGER"; - break; - case "long" : - case "double" : - $type = "DOUBLE"; - break; - default : - $type = "FLOAT"; - } + $field->setAttribute("ID", "col".$i); + } + } + $this->xml->saveXML(); + + } + + public function getFieldIndexByID($field_id) + { + if (!$this->xp) + return -1; + + $fields = $this->xp->query($this->queryFields()); + + if ($fields->length < 1) + return -1; + + for ($i = 0; $i < $fields->length; $i++) + if ($fields->item($i)->getAttribute("ID") == $field_id) + return $i; + + return -1; + } + + public function getStartStop() + { + if (!$this->xp) + return '0 0'; + + $timeIndex = $this->getTimeFieldIndex(); + if ($timeIndex < 0) + return '0 0'; + + $tr = $this->getFirstTR(); + + if (!$tr) + return '0 0'; + + $start = $this->getTDValueByFieldIndex($tr,$timeIndex); + + $stop = $start; + while ($tr) + { + $stop = $this->getTDValueByFieldIndex($tr,$timeIndex); + $tr = $this->getNextTR($tr); + } + + if (!$start) + $start = 0; + else + $start = strtotime($start); + + if (!$stop) + $stop = 0; + else + $stop = strtotime($stop); + + return $start." ".$stop; + } + + public function getFieldInfoByID($field_id) + { + if (!$this->xp) + return array("id" => $field_id, + "error" => "No file loaded"); + + $field = $this->getFieldByID($field_id); + + if (!$field) + $field = $this->getFieldByName($field_id); + + if (!$field) + return array("id" => $field_id, + "error" => "This field doesn't exist"); + return $this->getFieldInfo($field); + } + + + public function getFieldInfo($field) + { + if (!$this->xp) + return array("id" => $field_id, + "error" => "No file loaded"); + $description = ''; + $desc = $field->getElementsByTagName("DESCRIPTION"); + if ($desc->length >= 1) + $description = $desc->item(0)->nodeValue; + + $size = $field->getAttribute("arraysize"); + if ($size == '') + $size = 1; + else + $size = intval($size); + + switch ($field->getAttribute("datatype")) + { + case "short" : + $type = "SHORT"; + break; + case "int" : + $type = "INTEGER"; + break; + case "long" : + case "double" : + $type = "DOUBLE"; + break; + default : + $type = "FLOAT"; + } if (!$field->getAttribute("ID")) - $id = "col".$n; + $id = "col".$n; else $id = $field->getAttribute("ID"); - return array("id" => $field->getAttribute("ID"), - "type" => $type, - "name" => $field->getAttribute("name"), - "ucd" => $field->getAttribute("ucd"), - "unit" => $field->getAttribute("unit"), - "size" => $size, - "description" => $description - ); - } - - public function getFieldsInfo() - { - if (!$this->xp) - return array("error" => "No file loaded"); + return array("id" => $field->getAttribute("ID"), + "type" => $type, + "name" => $field->getAttribute("name"), + "ucd" => $field->getAttribute("ucd"), + "unit" => $field->getAttribute("unit"), + "size" => $size, + "description" => $description + ); + } - $fields_info = array(); + public function getFieldsInfo() + { + if (!$this->xp) + return array("error" => "No file loaded"); - $fields = $this->xp->query($this->queryFields()); + $fields_info = array(); - if ($fields->length < 1) - return $fields_info; + $fields = $this->xp->query($this->queryFields()); - foreach ($fields as $field) - { - if ($this->isTimeField($field)) - continue; + if ($fields->length < 1) + return $fields_info; - array_push($fields_info,$this->getFieldInfo($field)); - } + foreach ($fields as $field) + { + if ($this->isTimeField($field)) + continue; - return $fields_info; - } + array_push($fields_info,$this->getFieldInfo($field)); + } - public function getSamplings() - { - if (!$this->xp) - return array("minSampling" => 0, - "maxSampling" => 0); + return $fields_info; + } - $timeIndex = $this->getTimeFieldIndex(); - if ($timeIndex < 0) - return array("minSampling" => 0, - "maxSampling" => 0); + public function getSamplings() + { + if (!$this->xp) + return array("minSampling" => 0, + "maxSampling" => 0); - $tr = $this->getFirstTR(); + $timeIndex = $this->getTimeFieldIndex(); + if ($timeIndex < 0) + return array("minSampling" => 0, + "maxSampling" => 0); - if (!$tr) - return array("minSampling" => 0, - "maxSampling" => 0); + $tr = $this->getFirstTR(); - $prevTime = 0; - while ($tr) - { - $time = $this->getTDValueByFieldIndex($tr,$timeIndex); + if (!$tr) + return array("minSampling" => 0, + "maxSampling" => 0); - if ($time) - { - $time = strtotime($time); - if (($prevTime > 0) && ($time-$prevTime > 0)) - $deltaT[$time-$prevTime]++; - $prevTime = $time; - } + $prevTime = 0; + while ($tr) + { + $time = $this->getTDValueByFieldIndex($tr,$timeIndex); + + if ($time) + { + $time = strtotime($time); + if (($prevTime > 0) && ($time-$prevTime > 0)) + $deltaT[$time-$prevTime]++; + $prevTime = $time; + } - $tr = $this->getNextTR($tr); - } + $tr = $this->getNextTR($tr); + } - $minSampling = +1.e31; - $maxSampling = 0.0; + $minSampling = +1.e31; + $maxSampling = 0.0; - foreach ($deltaT as $key => $value) - { + foreach ($deltaT as $key => $value) + { - if ($value/count($deltaT) < 0.10) - continue; + if ($value/count($deltaT) < 0.10) + continue; - if ($key < $minSampling) $minSampling = $key; - if ($key > $maxSampling) $maxSampling = $key; - } + if ($key < $minSampling) $minSampling = $key; + if ($key > $maxSampling) $maxSampling = $key; + } - return array("minSampling" => $minSampling, - "maxSampling" => $maxSampling); - } + return array("minSampling" => $minSampling, + "maxSampling" => $maxSampling); + } - public function args2vector($file, $paramID){ + public function args2vector($file, $paramID){ - $argsArr = explode('_', $paramID); + $argsArr = explode('_', $paramID); - $dom = new DOMDocument(); - $dom->load($file); - $fields = $dom->getElementsByTagName('FIELD'); - $table = $dom->getElementsByTagName('TABLE')->item(0); - $i=0; - foreach ($fields as $field){ - if ($field->getAttribute('name') == $argsArr[0]){ + $dom = new DOMDocument(); + $dom->load($file); + $fields = $dom->getElementsByTagName('FIELD'); + $table = $dom->getElementsByTagName('TABLE')->item(0); + $i=0; + foreach ($fields as $field){ + if ($field->getAttribute('name') == $argsArr[0]){ $unit = $field->getAttribute('unit'); - $ucd = $field->getAttribute('ucd'); - $datatype = $field->getAttribute('datatype'); + $ucd = $field->getAttribute('ucd'); + $datatype = $field->getAttribute('datatype'); $firstTD = $i; - } - $i++; - } - if ($firstTD > 0){ - $table->removeChild($fields->item($firstTD + 2)); - $table->removeChild($fields->item($firstTD + 1)); - $table->removeChild($fields->item($firstTD)); - - $i = 0; - foreach ($fields as $field){ + } + $i++; + } + if ($firstTD > 0){ + $table->removeChild($fields->item($firstTD + 2)); + $table->removeChild($fields->item($firstTD + 1)); + $table->removeChild($fields->item($firstTD)); + + $i = 0; + foreach ($fields as $field){ $i++; if (strpos($field->getAttribute('ID'),'col') !== FALSE){ - $field->setAttribute('ID', 'col'.$i); - $dom->saveXML(); - } - } - - $group = $dom->createElement('GROUP'); - $group->appendChild(new DOMAttr('ID', 'info_'.$paramID)); - $table->appendChild($group); - - $param = $dom->createElement('PARAM'); - $param->appendChild(new DOMAttr('ID', 'components_'.$paramID)); - $param->appendChild(new DOMAttr('name', 'components_'.$paramID)); - $param->appendChild(new DOMAttr('datatype', 'char')); - $param->appendChild(new DOMAttr('arraysize', '*')); - $param->appendChild(new DOMAttr('value', $argsArr[0].' '.$argsArr[1].' '.$argsArr[2] )); - $group->appendChild($param); - - $new_field = $dom->createElement('FIELD'); - $new_field->appendChild(new DOMAttr('ID', $paramID)); - $new_field->appendChild(new DOMAttr('name', $paramID)); - $new_field->appendChild(new DOMAttr('datatype', $datatype)); - $new_field->appendChild(new DOMAttr('arraysize', '3')); - $new_field->appendChild(new DOMAttr('unit', $unit)); - $new_field->appendChild(new DOMAttr('ucd', $ucd)); - $new_field->appendChild(new DOMAttr('ref', 'info_'.$paramID)); - $table->appendChild($new_field); - - $trs = $dom->getElementsByTagName('TR'); - foreach($trs as $tr){ - $tds = $tr->getElementsByTagName('TD'); - $value = trim($tds->item($firstTD)->nodeValue).' '.trim($tds->item($firstTD + 1)->nodeValue).' '.trim($tds->item($firstTD + 2)->nodeValue); - $toRemote = $tds->item($firstTD); - $tr->removeChild($toRemote); - $toRemote = $tds->item($firstTD); - $tr->removeChild($toRemote); - $toRemote = $tds->item($firstTD); - $tr->removeChild($toRemote); - - $td = $dom->createElement('TD', $value); - $tr->appendChild($td); - } - - $dom->save($file); - } - } + $field->setAttribute('ID', 'col'.$i); + $dom->saveXML(); + } + } + + $group = $dom->createElement('GROUP'); + $group->appendChild(new DOMAttr('ID', 'info_'.$paramID)); + $table->appendChild($group); + + $param = $dom->createElement('PARAM'); + $param->appendChild(new DOMAttr('ID', 'components_'.$paramID)); + $param->appendChild(new DOMAttr('name', 'components_'.$paramID)); + $param->appendChild(new DOMAttr('datatype', 'char')); + $param->appendChild(new DOMAttr('arraysize', '*')); + $param->appendChild(new DOMAttr('value', $argsArr[0].' '.$argsArr[1].' '.$argsArr[2] )); + $group->appendChild($param); + + $new_field = $dom->createElement('FIELD'); + $new_field->appendChild(new DOMAttr('ID', $paramID)); + $new_field->appendChild(new DOMAttr('name', $paramID)); + $new_field->appendChild(new DOMAttr('datatype', $datatype)); + $new_field->appendChild(new DOMAttr('arraysize', '3')); + $new_field->appendChild(new DOMAttr('unit', $unit)); + $new_field->appendChild(new DOMAttr('ucd', $ucd)); + $new_field->appendChild(new DOMAttr('ref', 'info_'.$paramID)); + $table->appendChild($new_field); + + $trs = $dom->getElementsByTagName('TR'); + foreach($trs as $tr){ + $tds = $tr->getElementsByTagName('TD'); + $value = trim($tds->item($firstTD)->nodeValue).' '.trim($tds->item($firstTD + 1)->nodeValue).' '.trim($tds->item($firstTD + 2)->nodeValue); + $toRemote = $tds->item($firstTD); + $tr->removeChild($toRemote); + $toRemote = $tds->item($firstTD); + $tr->removeChild($toRemote); + $toRemote = $tds->item($firstTD); + $tr->removeChild($toRemote); + + $td = $dom->createElement('TD', $value); + $tr->appendChild($td); + } + + $dom->save($file); + } + } } -- libgit2 0.21.2