Commit 5de62950a7c5add8bd980928630db73fd35d9535

Authored by Nathanael Jourdane
1 parent 01e0bff1

Improve the VOTable parser.

.gitignore
... ... @@ -8,5 +8,9 @@ generic_data/newKernelDDBase/
8 8 generic_data/ParamInfo/*.xml
9 9 js/lib/ext
10 10 help/simu/simu*
  11 +desktop.php
  12 +php/my_config.php
  13 +DD.res
  14 +logs/*
11 15 *~
12   -
  16 +generic_data/EpnTapData/services.json
... ...
cron_scripts/get_services.php 0 → 100755
... ... @@ -0,0 +1,42 @@
  1 +<?php
  2 +include(realpath(dirname(__FILE__) . "/../php/config.php"));
  3 +include(BASE_PATH . "/php/classes/EpnTapMgr.php");
  4 +
  5 +$EpnTapMgr = new EpnTapMgr;
  6 +$services = json_decode(file_get_contents(EpnTapDataPath . "/EpnTapServices.json"), TRUE);
  7 +
  8 +$services_content = Array();
  9 +
  10 +foreach($services as $s) {
  11 + $query = "SELECT dataproduct_type as dp_type,
  12 + target_class as t_class,
  13 + target_name as t_name,
  14 + COUNT(granule_uid) as nb_res,
  15 + MIN(time_min) as time_min,
  16 + MAX(time_max) as time_max
  17 + FROM " . $s["schema"] . ".epn_core GROUP BY dp_type, t_class, t_name";
  18 +
  19 + $rows = $EpnTapMgr->request($s["accessurl"], $query);
  20 + if($rows == NULL)
  21 + continue;
  22 +
  23 + foreach ($rows as $r) {
  24 + $r['dp_type'] = $r['dp_type'];
  25 + $r['t_class'] = $r['t_class'];
  26 + $r['t_name'] = $r['t_name'];
  27 +
  28 + if(!isset($services_content[$r['dp_type']]))
  29 + $services_content[$r['dp_type']] = Array();
  30 +
  31 + if(!isset($services_content[$r['dp_type']][$r['t_class']]))
  32 + $services_content[$r['dp_type']][$r['t_class']] = Array();
  33 +
  34 + if(!isset($services_content[$r['dp_type']][$r['t_class']][$r['t_name']]))
  35 + $services_content[$r['dp_type']][$r['t_class']][$r['t_name']] = Array();
  36 +
  37 + $services_content[$r['dp_type']][$r['t_class']][$r['t_name']][$s["schema"]] = [$r['nb_res'], $r['time_min'], $r['time_max']];
  38 + }
  39 +}
  40 +
  41 +fwrite(fopen(EpnTapDataPath . "services.json", "w+"), json_encode($services_content, JSON_PRETTY_PRINT));
  42 +?>
... ...
php/classes/AmdaAction.php
... ... @@ -8,17 +8,17 @@
8 8  
9 9 class AmdaAction {
10 10  
11   - private $xmlFiles = array('localParam' => 'LocalParams.xml', 'remoteParam' => 'RemoteParams.xml',
  11 + private $xmlFiles = array('localParam' => 'LocalParams.xml', 'remoteParam' => 'RemoteParams.xml',
12 12 'remoteSimuParam' => 'RemoteParams.xml', 'derivedParam' => 'WsParams.xml', 'myDataParam' => 'WsParams.xml',
13   - 'timeTable' => 'Tt.xml', 'catalog' => 'Tt.xml', 'alias' => 'Alias.xml',
14   - 'myData' => 'Files.xml',
  13 + 'timeTable' => 'Tt.xml', 'catalog' => 'Tt.xml', 'alias' => 'Alias.xml',
  14 + 'myData' => 'Files.xml',
15 15 'request' => 'Request.xml', 'condition' => 'Request.xml',
16 16 'bkgWorks' => 'jobs.xml');
17 17  
18 18 private $user, $amdaStat;
19 19  
20   - public function __construct()
21   - {
  20 + public function __construct()
  21 + {
22 22 $dd = new UserMgr();
23 23 $this->user = $dd->user;
24 24 if (!defined('NEWKERNEL_DEBUG') || !NEWKERNEL_DEBUG)
... ... @@ -28,38 +28,38 @@ class AmdaAction {
28 28 private function getUrlDirs($url) {
29 29 //TODO replace by ftp php class methods: ftp_nlist() etc
30 30 require_once "simple_html_dom.php";
31   -
32   - $url = html_entity_decode($url);
  31 +
  32 + $url = html_entity_decode($url);
33 33 $trimmed_url = trim($url);
34 34 if (strrpos($trimmed_url, "/") == strlen($trimmed_url) - 1) {
35   - if (file_exists("temp.html")) unlink("temp.html");
  35 + if (file_exists("temp.html")) unlink("temp.html");
36 36 exec("wget -O temp.html ".$url);
37   -
  37 +
38 38 $html = file_get_html('temp.html');
39 39 $dirs = $html->find('a[href]');
40 40 foreach ($dirs as $dir) {
41 41 $name = $dir->innertext; //$dir->href;
42 42 $isLeaf = strrpos($name, "/") !== strlen($name) - 1;
43 43 $childrenToReturn[] = array('text' => $name, 'id' => $trimmed_url.$name,
44   - 'nodeType' => 'url', 'leaf' => $isLeaf);
  44 + 'nodeType' => 'url', 'leaf' => $isLeaf);
45 45 }
46   -
  46 +
47 47 }
48   - return $childrenToReturn;
  48 + return $childrenToReturn;
49 49 }
50   -
  50 +
51 51 /*****************************************************************
52 52 * PUBLIC FUNCTIONS
53   -*****************************************************************/
54   -
  53 +*****************************************************************/
  54 +
55 55 /*
56 56 * $obj = { id: node.id, nodeType: node.nodeType }
57 57 */
58 58 public function getTree($obj) {
59   -
  59 +
60 60 $node = $obj->node;
61   -
62   - // to correct 'restricted' parameters
  61 +
  62 + // to correct 'restricted' parameters
63 63 if (strpos($node, restricted) !== false) {
64 64 $node = str_replace(restricted,"",$node);
65 65 }
... ... @@ -68,9 +68,9 @@ class AmdaAction {
68 68 $remoteBase = false;
69 69 $isRemoteDataSet = false;
70 70  
71   - if ($nodeType == 'url')
  71 + if ($nodeType == 'url')
72 72 {
73   - $url = $node == 'root' ? $obj->baseId : $node;
  73 + $url = $node == 'root' ? $obj->baseId : $node;
74 74 return $this->getUrlDirs($url);
75 75 }
76 76  
... ... @@ -78,63 +78,63 @@ class AmdaAction {
78 78  
79 79 if ($node == 'root' && $remoteBase) $node = $obj->baseId;
80 80  
81   - if ($node == 'root' && !$remoteBase)
82   - {
  81 + if ($node == 'root' && !$remoteBase)
  82 + {
83 83 $json_o = json_decode(file_get_contents(DATAPATH.$nodeType.'.json'));
84   - $childrenToReturn = $json_o->nodes;
85   - }
86   - else
  84 + $childrenToReturn = $json_o->nodes;
  85 + }
  86 + else
87 87 {
88 88 $Dom = new DomDocument("1.0");
89 89  
90   - switch ($nodeType)
  90 + switch ($nodeType)
91 91 {
92 92 case 'sharedtimeTable':
93 93 case 'sharedcatalog':
94 94 $xmlName = SHAREDPATH.'/SharedObjectTree.xml';
95 95 break;
96   - case 'bkgWorks':
  96 + case 'bkgWorks':
97 97 $xmlName = USERJOBDIR.$this->xmlFiles[$nodeType];
98 98 break;
99 99 case 'source':
100   - $xmlName = DATAPATH.'RemoteData/'.$obj->baseId.'/base.xml';
  100 + $xmlName = DATAPATH.'RemoteData/'.$obj->baseId.'/base.xml';
  101 + break;
  102 + case 'destination':
  103 + $xmlName = USERWSDIR.'RemoteParams.xml';
101 104 break;
102   - case 'destination':
103   - $xmlName = USERWSDIR.'RemoteParams.xml';
104   - break;
105 105 default:
106 106 $xmlName = USERWSDIR.$this->xmlFiles[$nodeType];
107 107 }
108 108  
109   - if ($remoteBase)
110   - {
  109 + if ($remoteBase)
  110 + {
111 111 $nodeType = 'remoteParam';
112   - }
113   -
  112 + }
  113 +
114 114 $Dom->load($xmlName);
115   -
116   - if ($node == "myRemoteSimuData-treeRootNode")
  115 +
  116 + if ($node == "myRemoteSimuData-treeRootNode")
117 117 $node = "myRemoteData-treeRootNode";
118   -
  118 +
119 119 $nodeToOpen = $Dom->getElementById($node);
120 120 $children = $nodeToOpen->childNodes;
121 121  
122   - foreach ($children as $child)
  122 + foreach ($children as $child)
123 123 if ($child->nodeType == XML_ELEMENT_NODE) {
124 124 $isLeaf = true;
125   -
  125 +
126 126 if ($child->hasChildNodes())
127   - foreach ($child->childNodes as $grandChild)
  127 + foreach ($child->childNodes as $grandChild)
128 128 if ($grandChild -> nodeType == XML_ELEMENT_NODE) {
129 129 $isLeaf = false;
130 130 break;
131 131 }
132 132 if ($child->tagName == 'folder') $isLeaf = false;
133 133  
134   - //TODO MAKE PROPERLY as function of nodetype !!!!
135   - $info = '';
  134 + //TODO MAKE PROPERLY as function of nodetype !!!!
  135 + $info = '';
136 136 $id = $child->getAttribute('xml:id');
137   - $name = $child->getAttribute('name');
  137 + $name = $child->getAttribute('name');
138 138 $help = $child->getAttribute('att');
139 139 if ($child->hasAttribute('dataStart')) $dataStart = $child->getAttribute('dataStart');
140 140 if ($child->hasAttribute('dataStop')) $dataStop = $child->getAttribute('dataStop');
... ... @@ -146,42 +146,42 @@ class AmdaAction {
146 146 $isSimulation = false;
147 147 $rank = null;
148 148  
149   - switch ($nodeType)
  149 + switch ($nodeType)
150 150 {
151   - case 'bkgWorks':
  151 + case 'bkgWorks':
152 152 $specialNode = true;
153 153 $status = $child->getAttribute('status');
154   - // if ($status == 'done') continue;
  154 + // if ($status == 'done') continue;
155 155 $childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType, 'leaf' => $isLeaf,
156   - 'pid' => $child->getAttribute('pid'), 'status' => $status,
  156 + 'pid' => $child->getAttribute('pid'), 'status' => $status,
157 157 'jobType' => $child->getAttribute('jobType'), 'info' => $child->getAttribute('info'));
158 158 break;
159 159  
160 160 case 'condition':
161 161 $objectMgr = new RequestMgr();
162   - $info = $objectMgr->getObject($id)->expression;
163   - break;
  162 + $info = $objectMgr->getObject($id)->expression;
  163 + break;
164 164  
165 165 case 'request':
166   -
  166 +
167 167 $objectMgr = new RequestMgr();
168   - $objplot = $objectMgr->getObject($id);
169   - for ($i=0; $i < count($objplot->children); $i++) {
  168 + $objplot = $objectMgr->getObject($id);
  169 + for ($i=0; $i < count($objplot->children); $i++) {
170 170 for ($j=0; $j < count($objplot->children[$i]->children); $j++) {
171 171 $info = $info.' '.$objplot->children[$i]->children[$j]->name;
172 172 }
173 173 }
174   -
175   - break;
176 174  
177   - case 'alias':
  175 + break;
  176 +
  177 + case 'alias':
178 178 $info = $id;
179 179 $id = 'alias_'.$id;
180   - if ($isLeaf) $isParameter = true;
  180 + if ($isLeaf) $isParameter = true;
181 181 break;
182 182  
183 183 case 'timeTable':
184   - case 'catalog':
  184 + case 'catalog':
185 185 if ($isLeaf) $info = $child->getAttribute('intervals').' intervals';
186 186 break;
187 187 case 'sharedtimeTable':
... ... @@ -205,34 +205,34 @@ class AmdaAction {
205 205 $specialNode = true;
206 206 $isParameter = false;
207 207 $needsArgs = false;
208   - $isSpectra = false;
  208 + $isSpectra = false;
209 209 $isStack = false;
210 210  
211 211 if ($child->hasAttribute('desc')) $info = $child->getAttribute('desc');
212 212  
213   - if ($child->hasAttribute('sampling'))
  213 + if ($child->hasAttribute('sampling'))
214 214 {
215 215 $info = "Sampling: ".$child->getAttribute('sampling')."<br/>";
216 216 if ($child->getAttribute('dataStart') == 'depending on mission')
217 217 {
218 218 $info .= "Time Range: ".$child->getAttribute('dataStart')."<br/>";
219   - }
220   - else
221   - {
222   - $info .= "Time Range: ".$child->getAttribute('dataStart')."-".$child->getAttribute('dataStop')."<br/>";
223   - }
224   -
  219 + }
  220 + else
  221 + {
  222 + $info .= "Time Range: ".$child->getAttribute('dataStart')."-".$child->getAttribute('dataStop')."<br/>";
  223 + }
  224 +
225 225 if ($child->getAttribute('restricted') > 1) {
226 226 $restricted = $child->getAttribute('restricted');
227 227 $info .= "<b>Time Restriction</b>: -$restricted days<br/>";
228 228 }
229   -
  229 +
230 230 $info .= "Source: ".$child->getAttribute('dataSource');
231 231 }
232   -
  232 +
233 233 if ($child->hasAttribute('units')) $info = $child->getAttribute('units');
234 234  
235   - if ($child->tagName == 'parameter')
  235 + if ($child->tagName == 'parameter')
236 236 {
237 237 $isParameter = true;
238 238 $isScatter = true;
... ... @@ -240,24 +240,24 @@ class AmdaAction {
240 240 if ($child->parentNode->hasAttribute('dataStart'))
241 241 {
242 242 $globalStart = $child->parentNode->getAttribute('dataStart');
243   - $globalStop = $child->parentNode->getAttribute('dataStop');
  243 + $globalStop = $child->parentNode->getAttribute('dataStop');
244 244 }
245 245  
246 246 if ($child->parentNode->getAttribute('restricted') > 1 )
247 247 {
248 248 $timeRestriction = true;
249   -
  249 +
250 250 }
251   -
252   - /*------------------- to show not tested parameters ------*/
253   -
  251 +
  252 + /*------------------- to show not tested parameters ------*/
  253 +
254 254 if ($child->getAttribute('tbd'))
255 255 $info .= "<br/><b>Not tested yet</b>";
256   -
257   - /*------------------- --------------------------------------*/
258   -
  256 +
  257 + /*------------------- --------------------------------------*/
  258 +
259 259 }
260   -
  260 +
261 261  
262 262 $component_info = array();
263 263 if ($child->tagName == 'component')
... ... @@ -268,78 +268,78 @@ class AmdaAction {
268 268 if ($child->parentNode->parentNode->hasAttribute('dataStart'))
269 269 {
270 270 $globalStart = $child->parentNode->parentNode->getAttribute('dataStart');
271   - $globalStop = $child->parentNode->parentNode->getAttribute('dataStop');
272   - }
  271 + $globalStop = $child->parentNode->parentNode->getAttribute('dataStop');
  272 + }
273 273  
274 274 if ($child->parentNode->parentNode->getAttribute('restricted') > 1)
275 275 {
276 276 $timeRestriction = true;
277   -
278   - }
  277 +
  278 + }
279 279  
280 280 if ($child->hasAttribute("index1"))
281 281 $component_info["index1"] = $child->getAttribute('index1');
282 282 if ($child->hasAttribute("index2"))
283 283 $component_info["index2"] = $child->getAttribute('index2');
284   -
  284 +
285 285 $component_info["parentId"] = $child->parentNode->getAttribute('xml:id');
286 286 }
287   -
  287 +
288 288 if ($child->tagName == 'parameter' && $child->hasChildNodes()) $isScatter = false;
289   -
  289 +
290 290 if ($child->tagName == 'parameter' && $child->hasAttribute('display_type')) {
291 291  
292 292 if ($child->getAttribute('display_type') == 'spectrogram') {
293   - $needsArgs = true;
294   - $isSpectra = true;
  293 + $needsArgs = true;
  294 + $isSpectra = true;
295 295 $isScatter = false;
296 296 }
297   - else if ($child->getAttribute('display_type') == 'stackplot') {
  297 + else if ($child->getAttribute('display_type') == 'stackplot') {
298 298 $isStack = true;
299 299 $isScatter = false;
300 300 }
301   - }
302   -
303   - if ($isParameter)
  301 + }
  302 +
  303 + if ($isParameter)
304 304 {
305 305 if ($child->tagName == 'parameter' && $child->childNodes->length == 1)
306   - {
307   - $needsArgs = true;
308   - }
309   - if (substr($id,0,4) == 'bt96' || substr($id,0,6) == 'ba2000'|| substr($id,0,5) == 'bcain' || substr($id,0,7) == 'bmorsch' )
310   - {
  306 + {
  307 + $needsArgs = true;
  308 + }
  309 + if (substr($id,0,4) == 'bt96' || substr($id,0,6) == 'ba2000'|| substr($id,0,5) == 'bcain' || substr($id,0,7) == 'bmorsch' )
  310 + {
311 311 $needsArgs = true;
312 312 }
313   -
314   - if ($id == 'mex_n_sw' || $id == 'mex_v_sw')
  313 +
  314 + if ($id == 'mex_n_sw' || $id == 'mex_v_sw')
315 315 {
316 316 $not_yet = true;
317   -
  317 +
318 318 }
319 319  
320 320 //TODO proper conditions
321   - if (substr($id,0,3) == 'ros')
  321 + if (substr($id,0,3) == 'ros')
322 322 {
323 323 if ( !(strpos($id,'_r_') || strpos($id,'_xyz_') || strpos($id,'_cg_')
324   - || strpos($id,'_sc_') || strpos($id,'_aux_') || strpos($id,'_sw_')
325   - || strpos($id,'_tao_') ))
326   - {
  324 + || strpos($id,'_sc_') || strpos($id,'_aux_') || strpos($id,'_sw_')
  325 + || strpos($id,'_tao_') ))
  326 + {
327 327 $not_yet = true;
328   - }
  328 + }
329 329 }
330 330  
331 331 $objectMgr = new AliasMgr();
332 332 $alias = $objectMgr->getAlias($id);
333   -
334   - $childrenToReturn[] = array('text' => $name,'alias' => $alias,
  333 +
  334 + $childrenToReturn[] = array('text' => $name,'alias' => $alias,
335 335 'id' => $id,'nodeType' => $nodeType, 'info' => $info, "component_info" => $component_info,
336 336 'globalStart' => $globalStart, 'globalStop' => $globalStop, 'timeRestriction' => $timeRestriction,
337 337 'leaf' => $isLeaf, 'isParameter' => $isParameter, 'isScatter' => $isScatter,
338 338 'isSpectra' => $isSpectra,'isStack' => $isStack, 'needsArgs' => $needsArgs, 'help' => $help, 'notyet' => $not_yet);
339 339 }
340   - else
  340 + else
341 341 {
342   - if ($child->tagName == 'mission')
  342 + if ($child->tagName == 'mission')
343 343 {
344 344 $disable = ($child->getAttribute('available') != "1");
345 345 $rank = $child->getAttribute('rank');
... ... @@ -348,19 +348,19 @@ class AmdaAction {
348 348 {
349 349 $disable = $child->getAttribute('restricted');
350 350 }
351   -
  351 +
352 352 if ($disable)
353 353 {
354 354 if ($disable == 1) {
355 355 $info .= "<br/><b>Restricted access</b>";
356 356 }
357   - else {
358   - $disable = false;
  357 + else {
  358 + $disable = false;
359 359 }
360 360 }
361 361  
362   - $childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType, 'info' => $info,
363   - 'leaf' => false, 'help' => $help, 'disable' => $disable, 'rank' => $rank);
  362 + $childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType, 'info' => $info,
  363 + 'leaf' => false, 'help' => $help, 'disable' => $disable, 'rank' => $rank);
364 364 }
365 365 break;
366 366  
... ... @@ -378,12 +378,12 @@ class AmdaAction {
378 378 break;
379 379 }
380 380 }
381   - if ($child->tagName == 'simulationRegion')
  381 + if ($child->tagName == 'simulationRegion')
382 382 {
383 383 $rank = $child->getAttribute('rank');
384 384 }
385 385 case 'remoteParam' :
386   -
  386 +
387 387 if ($child->getAttribute('isSimulation') && $child->tagName == 'dataCenter') {
388 388 $skip = true;
389 389 break;
... ... @@ -391,13 +391,13 @@ class AmdaAction {
391 391  
392 392 $isDeletable = $child->hasAttribute('isDeletable');
393 393 $specialNode = true;
394   - $isParameter = false;
395   - $isSpectra = false;
396   -
397   - switch ($id)
  394 + $isParameter = false;
  395 + $isSpectra = false;
  396 +
  397 + switch ($id)
398 398 {
399   - case 'CDAWEB' :
400   - case 'OMNIWEB' :
  399 + case 'CDAWEB' :
  400 + case 'OMNIWEB' :
401 401 $isLeaf = false;
402 402 break;
403 403 case 'THEMIS' :
... ... @@ -411,64 +411,64 @@ class AmdaAction {
411 411 break;
412 412 default:
413 413 }
414   -
  414 +
415 415 $info = $child->getAttribute('desc');
416 416  
417   -// if ($info && !$isSimulation) {
  417 +// if ($info && !$isSimulation) {
418 418 $info = str_replace(';', "<br/>Time Range: ", $info);
419 419 // }
420 420 if ($child->tagName == 'dataset') {
421   - /*if ($child->hasAttribute('dataStart') && $child->hasAttribute('dataStop'))
422   - $info .= "Time Range: ".$child->getAttribute('dataStart')."-".$child->getAttribute('dataStop')."<br/>"; */
  421 + /*if ($child->hasAttribute('dataStart') && $child->hasAttribute('dataStop'))
  422 + $info .= "Time Range: ".$child->getAttribute('dataStart')."-".$child->getAttribute('dataStop')."<br/>"; */
423 423 // $info .= "Time Range: ".$dataStart"-".$dataStop."<br/>";
424 424 }
425 425 if (($child->tagName == 'parameter') || ($child->tagName == 'component')) {
426 426 $isParameter = true;
427   - $isScatter = true;
  427 + $isScatter = true;
428 428 }
429   -
  429 +
430 430 $needsArgs = $child->hasAttribute('needsArgs');
431 431  
432 432 if (($child->tagName == 'parameter' && $child->hasChildNodes()) || $needsArgs) $isScatter = false;
433   -
  433 +
434 434 if ($remoteBase) {
435   - if ($child->tagName == 'dataset') $isRemoteDataSet = true;
  435 + if ($child->tagName == 'dataset') $isRemoteDataSet = true;
436 436 }
437 437  
438 438 if ($isParameter) {
439   - $disable = $child->parentNode->getAttribute('disabled');
  439 + $disable = $child->parentNode->getAttribute('disabled');
440 440 $objectMgr = new AliasMgr();
441 441 $alias = $objectMgr->getAlias($id);
442 442  
443 443  
444   - if ($child->hasAttribute('display_type')
  444 + if ($child->hasAttribute('display_type')
445 445 && $child->getAttribute('display_type') == 'spectrogram'){
446   - $needsArgs = true;
  446 + $needsArgs = true;
447 447 $isScatter = false;
448 448 $isSpectra = true;
449   - }
  449 + }
450 450  
451   - $childrenToReturn[] = array('text' => $name,'alias' => $alias,
  451 + $childrenToReturn[] = array('text' => $name,'alias' => $alias,
452 452 'id' => $id,'nodeType' => $nodeType, 'info' => $info, 'help' => $help,
453   - 'leaf' => $isLeaf, 'disable' => $disable, 'isParameter' => $isParameter,
  453 + 'leaf' => $isLeaf, 'disable' => $disable, 'isParameter' => $isParameter,
454 454 'isScatter' => $isScatter, 'isSpectra' => $isSpectra, 'needsArgs' => $needsArgs, "component_info" => $component_info);
455 455 }
456   - else {
457   - if ($child->tagName == 'dataCenter')
458   - $restricted = ($child->getAttribute('available') != "1");
  456 + else {
  457 + if ($child->tagName == 'dataCenter')
  458 + $restricted = ($child->getAttribute('available') != "1");
459 459 else
460 460 $restricted = false;
461   -
462   - if ($id == 'CDAWEB' || $id == 'THEMIS'|| $id == 'MAPSKP' || $id == 'VEXGRAZ')
  461 +
  462 + if ($id == 'CDAWEB' || $id == 'THEMIS'|| $id == 'MAPSKP' || $id == 'VEXGRAZ')
463 463 $restricted = FALSE;
464 464 if ($restricted)
465   - $info .= "<br/><b>Open soon !</b>";
466   -
  465 + $info .= "<br/><b>Open soon !</b>";
  466 +
467 467 if ($child->tagName == 'dataset')
468 468 $nonavailable = ($child->getAttribute('disabled'));
469 469 else
470 470 $nonavailable = false;
471   -
  471 +
472 472 if ($nonavailable)
473 473 $info .= "<br/><b>Not available yet</b>";
474 474  
... ... @@ -484,12 +484,12 @@ class AmdaAction {
484 484  
485 485 $disable = $restricted || $nonavailable || $obsolete;
486 486 $childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType, 'isAddable' => $isAddable,
487   - 'info' => $info, 'leaf' => false, 'isRemoteDataSet' => $isRemoteDataSet, 'disable' => $disable,
488   - 'isSimulation' => $isSimulation, 'rank' => $rank, 'isDeletable' => $isDeletable, 'help' => $help);
  487 + 'info' => $info, 'leaf' => false, 'isRemoteDataSet' => $isRemoteDataSet, 'disable' => $disable,
  488 + 'isSimulation' => $isSimulation, 'rank' => $rank, 'isDeletable' => $isDeletable, 'help' => $help);
489 489 }
490   -
  490 +
491 491 break;
492   - case 'myData' :
  492 + case 'myData' :
493 493 $info = $child->hasAttribute('info') ? $child->getAttribute('info') : $child->nodeValue;
494 494 // $info = str_replace("\n","<br/>",$info);
495 495 break;
... ... @@ -504,7 +504,7 @@ class AmdaAction {
504 504 $mask = $child->getAttribute('mask');
505 505 $isSpectra = false;
506 506  
507   -
  507 +
508 508 if ($isLeaf) {
509 509 $isParameter = true;
510 510 $info = "Size: ".$size."<br/>".$child->getAttribute('desc')."<br/> Mask: ".$mask;
... ... @@ -516,24 +516,24 @@ class AmdaAction {
516 516 $globalStop = substr(str_replace( '-','/',$child->getAttribute('desc')), 17, 22);
517 517 }
518 518  
519   - $childrenToReturn[] = array('text' => $name, 'size' => $size, 'id' => $id,
  519 + $childrenToReturn[] = array('text' => $name, 'size' => $size, 'id' => $id,
520 520 'globalStart' => $globalStart, 'globalStop' => $globalStop,
521   - 'nodeType' => $nodeType, 'info' => $info, 'isScatter' => $isScatter, 'leaf' => $isLeaf,
  521 + 'nodeType' => $nodeType, 'info' => $info, 'isScatter' => $isScatter, 'leaf' => $isLeaf,
522 522 'isParameter' => $isParameter, 'linkedMask' => $mask, 'isSpectra' => $isSpectra);
523 523  
524 524 break;
525   - default:
  525 + default:
526 526 }
527   -
  527 +
528 528 if (!$specialNode && !$skip) {
529   - if ($child->hasAttribute('desc'))
  529 + if ($child->hasAttribute('desc'))
530 530 $info = $child->getAttribute('desc');
531   - $childrenToReturn[] = array('text' => $name, 'id' => $id, 'nodeType' => $nodeType, 'info' => $info,
  531 + $childrenToReturn[] = array('text' => $name, 'id' => $id, 'nodeType' => $nodeType, 'info' => $info,
532 532 'help' => $help, 'leaf' => $isLeaf, 'isParameter' => $isParameter);
533 533 }
534 534 }
535 535 // if $childrenToReturn we have to return []
536   - if ($childrenToReturn == null) {
  536 + if ($childrenToReturn == null) {
537 537 $childrenToReturn = array('nodeType' => $nodeType, 'text' => null);
538 538 }
539 539 }
... ... @@ -541,106 +541,106 @@ class AmdaAction {
541 541 return $childrenToReturn;
542 542 }
543 543  
544   - public function saveTree($obj)
  544 + public function saveTree($obj)
545 545 {
546 546 $paramMgr = new ParamMgr();
547   - return $paramMgr->saveTree($obj);
  547 + return $paramMgr->saveTree($obj);
548 548 }
549 549  
550   - public function doNothing($obj)
551   - {
  550 + public function doNothing($obj)
  551 + {
552 552 return array("res" => 'ok');
553   -
  553 +
554 554 }
555 555  
556   - public function deleteFromTree($obj)
557   - {
  556 + public function deleteFromTree($obj)
  557 + {
558 558 $paramMgr = new ParamMgr();
559 559 return $paramMgr->deleteFromTree($obj);
560   -
  560 +
561 561 }
562 562  
563 563 /*
564 564 * temporary object fromUpload
565   -*/
  565 +*/
566 566 public function getUploadedObject($name, $format, $nodeType)
567   - {
568   - switch ($nodeType)
  567 + {
  568 + switch ($nodeType)
569 569 {
570   - case 'timeTable' :
571   - $objectMgr = new TimeTableMgr();
  570 + case 'timeTable' :
  571 + $objectMgr = new TimeTableMgr();
572 572 break;
573   - case 'myDataParam' :
574   - $objectMgr = new FilesMgr();
  573 + case 'myDataParam' :
  574 + $objectMgr = new FilesMgr();
575 575 break;
576 576 default:
577 577 return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
578 578 }
579 579 return $objectMgr -> getUploadedObject($name, $format, true);
580 580  
581   - }
  581 + }
582 582  
583 583 /*
584   -* fill ascii file into grid
585   -*/
586   - public function getAsciiFile($obj)
587   - {
588   - $objectMgr = new FilesMgr();
  584 +* fill ascii file into grid
  585 +*/
  586 + public function getAsciiFile($obj)
  587 + {
  588 + $objectMgr = new FilesMgr();
589 589 return $objectMgr -> getAsciiFile($obj->fileName);
590 590 }
591   -
592   - public function getMyParamInfo($object)
593   - {
594   - $objectMgr = new FilesMgr();
  591 +
  592 + public function getMyParamInfo($object)
  593 + {
  594 + $objectMgr = new FilesMgr();
595 595 return $objectMgr -> getParamInfo($object);
596   - }
  596 + }
597 597  
598 598 /*
599   -* temporary object from Search
600   -*/
601   - public function getTmpObject($folderId, $name, $nodeType) {
  599 +* temporary object from Search
  600 +*/
  601 + public function getTmpObject($folderId, $name, $nodeType) {
  602 +
602 603  
603   -
604 604 switch ($nodeType) {
605   - case 'timeTable' :
606   - $objectMgr = new TimeTableMgr();
607   - break;
  605 + case 'timeTable' :
  606 + $objectMgr = new TimeTableMgr();
  607 + break;
608 608 case 'catalog' :
609   - $objectMgr = new CatalogMgr();
610   - break;
  609 + $objectMgr = new CatalogMgr();
  610 + break;
611 611 default:
612 612 return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
613 613 }
614 614 return $objectMgr -> getTmpObject($folderId, $name, true);
615 615  
616 616 }
617   -
618 617  
619   - public function getObject($id, $nodeType) {
620   -
  618 +
  619 + public function getObject($id, $nodeType) {
  620 +
621 621 switch ($nodeType) {
622 622 case 'myDataParam':
623   - case 'derivedParam' :
624   - $objectMgr = new DerivedParamMgr($nodeType);
  623 + case 'derivedParam' :
  624 + $objectMgr = new DerivedParamMgr($nodeType);
625 625 break;
626   - case 'timeTable' :
  626 + case 'timeTable' :
627 627 case 'sharedtimeTable' :
628   - $objectMgr = new TimeTableMgr();
629   - break;
  628 + $objectMgr = new TimeTableMgr();
  629 + break;
630 630 case 'catalog' :
631 631 case 'sharedcatalog' :
632   - $objectMgr = new CatalogMgr();
633   - break;
634   - case 'condition' :
  632 + $objectMgr = new CatalogMgr();
  633 + break;
  634 + case 'condition' :
635 635 case 'request' :
636   - $objectMgr = new RequestMgr($nodeType);
637   - break;
  636 + $objectMgr = new RequestMgr($nodeType);
  637 + break;
638 638 case 'bkgWorks' :
639 639 require_once(INTEGRATION_SRC_DIR."RequestManager.php");
640 640 return $this->executeRequest($id, FunctionTypeEnumClass::PROCESSGETINFO);
641 641 break;
642 642 case 'myData' :
643   - $objectMgr = new FilesMgr();
  643 + $objectMgr = new FilesMgr();
644 644 break;
645 645 default:
646 646 return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
... ... @@ -651,28 +651,28 @@ class AmdaAction {
651 651 /*
652 652 * $obj = { id: node.id, leaf: node.leaf, nodeType: node.nodeType }
653 653 */
654   - public function deleteObject($obj) {
655   -
656   - switch ($obj->nodeType) {
657   -
658   - case 'myDataParam' :
659   - case 'derivedParam' :
660   - $objectMgr = new DerivedParamMgr($obj->nodeType);
  654 + public function deleteObject($obj) {
  655 +
  656 + switch ($obj->nodeType) {
  657 +
  658 + case 'myDataParam' :
  659 + case 'derivedParam' :
  660 + $objectMgr = new DerivedParamMgr($obj->nodeType);
661 661 break;
662   - case 'timeTable' :
663   - $objectMgr = new TimeTableMgr();
664   - break;
665   - case 'catalog' :
666   - $objectMgr = new CatalogMgr();
  662 + case 'timeTable' :
  663 + $objectMgr = new TimeTableMgr();
667 664 break;
668   - case 'condition' :
  665 + case 'catalog' :
  666 + $objectMgr = new CatalogMgr();
  667 + break;
  668 + case 'condition' :
669 669 case 'request' :
670   - $objectMgr = new RequestMgr($obj->nodeType);
  670 + $objectMgr = new RequestMgr($obj->nodeType);
671 671 break;
672 672 case 'alias' :
673 673 $objectMgr = new AliasMgr();
674 674 $obj->id = substr($obj->id,strlen('alias_'));
675   - break;
  675 + break;
676 676 case 'bkgWorks' :
677 677 require_once(INTEGRATION_SRC_DIR."RequestManager.php");
678 678 return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSDELETE);
... ... @@ -690,27 +690,27 @@ class AmdaAction {
690 690 /*
691 691 * $obj = { id: node.id, old_name: node.text, name: value, parent : node.parentNode.id, leaf: node.leaf, nodeType: node.nodeType }
692 692 */
693   - public function renameObject($obj) {
694   -
  693 + public function renameObject($obj) {
  694 +
695 695 switch ($obj->nodeType) {
696   -
  696 +
697 697 case 'myDataParam' :
698   - case 'derivedParam' :
699   - $objectMgr = new DerivedParamMgr($obj->nodeType);
  698 + case 'derivedParam' :
  699 + $objectMgr = new DerivedParamMgr($obj->nodeType);
700 700 break;
701   - case 'timeTable' :
702   - $objectMgr = new TimeTableMgr();
  701 + case 'timeTable' :
  702 + $objectMgr = new TimeTableMgr();
703 703 break;
704   - case 'catalog' :
705   - $objectMgr = new CatalogMgr();
706   - break;
707   - case 'condition' :
708   - case 'request' :
709   - $objectMgr = new RequestMgr($obj->nodeType);
  704 + case 'catalog' :
  705 + $objectMgr = new CatalogMgr();
  706 + break;
  707 + case 'condition' :
  708 + case 'request' :
  709 + $objectMgr = new RequestMgr($obj->nodeType);
710 710 break;
711 711 case 'alias' :
712   - $objectMgr = new AliasMgr();
713   - break;
  712 + $objectMgr = new AliasMgr();
  713 + break;
714 714 default:
715 715 return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
716 716 }
... ... @@ -718,33 +718,33 @@ class AmdaAction {
718 718 return $objectMgr -> renameObject($obj);
719 719 }
720 720  
721   -/*
  721 +/*
722 722 * $obj = { name: obj.name, obj.nodeType, obj.leaf (??), OBJ DEPENDENT ATTRIBUTES }
723 723 */
724   - public function createObject($obj, $folder) {
725   -
  724 + public function createObject($obj, $folder) {
  725 +
726 726 switch ($obj->nodeType) {
727 727  
728   - case 'myDataParam' :
  728 + case 'myDataParam' :
729 729 case 'derivedParam' :
730   - if ($obj->nodeType == 'derivedParam' && $this->amdaStat->success)
  730 + if ($obj->nodeType == 'derivedParam' && $this->amdaStat->success)
731 731 $this->amdaStat->addTask('create', $this->user, null);
732 732  
733   - $objectMgr = new DerivedParamMgr($obj->nodeType);
734   - break;
735   - case 'timeTable' :
736   - $objectMgr = new TimeTableMgr();
737   - break;
738   - case 'catalog' :
739   - $objectMgr = new CatalogMgr();
  733 + $objectMgr = new DerivedParamMgr($obj->nodeType);
  734 + break;
  735 + case 'timeTable' :
  736 + $objectMgr = new TimeTableMgr();
  737 + break;
  738 + case 'catalog' :
  739 + $objectMgr = new CatalogMgr();
740 740 break;
741 741 case 'condition' :
742   - case 'request' :
743   - $objectMgr = new RequestMgr($obj->nodeType);
744   - break;
  742 + case 'request' :
  743 + $objectMgr = new RequestMgr($obj->nodeType);
  744 + break;
745 745 case 'alias' :
746   - $objectMgr = new AliasMgr();
747   - break;
  746 + $objectMgr = new AliasMgr();
  747 + break;
748 748 default:
749 749 return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
750 750 }
... ... @@ -752,33 +752,33 @@ class AmdaAction {
752 752 return $objectMgr -> createObject($obj, $folder);
753 753 }
754 754  
755   -/*
  755 +/*
756 756 * $obj = { id:obj.id, name: obj.name, obj.nodeType, obj.leaf (??), OBJ DEPENDENT ATTRIBUTES }
757 757 */
758 758 public function modifyObject($obj) {
759   -
760   - switch ($obj->nodeType) {
761 759  
762   - case 'myDataParam' :
763   - case 'derivedParam' :
764   - $objectMgr = new DerivedParamMgr($obj->nodeType);
  760 + switch ($obj->nodeType) {
  761 +
  762 + case 'myDataParam' :
  763 + case 'derivedParam' :
  764 + $objectMgr = new DerivedParamMgr($obj->nodeType);
  765 + break;
  766 + case 'timeTable' :
  767 + $objectMgr = new TimeTableMgr();
765 768 break;
766   - case 'timeTable' :
767   - $objectMgr = new TimeTableMgr();
  769 + case 'catalog' :
  770 + $objectMgr = new CatalogMgr();
768 771 break;
769   - case 'catalog' :
770   - $objectMgr = new CatalogMgr();
771   - break;
772   - case 'condition' :
  772 + case 'condition' :
773 773 case 'request' :
774   - $objectMgr = new RequestMgr($obj->nodeType);
  774 + $objectMgr = new RequestMgr($obj->nodeType);
775 775 break;
776 776 default:
777 777 return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
778 778 }
779 779  
780 780 return $objectMgr -> modifyObject($obj);
781   - }
  781 + }
782 782 /*
783 783 * {obj.name, obj.nodeType, obj.leaf}
784 784 */
... ... @@ -814,7 +814,7 @@ class AmdaAction {
814 814 public function getJobs()
815 815 {
816 816 require_once(INTEGRATION_SRC_DIR."RequestManager.php");
817   - return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSRUNNINGINFO);
  817 + return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSRUNNINGINFO);
818 818 }
819 819  
820 820  
... ... @@ -828,8 +828,8 @@ class AmdaAction {
828 828 $this->user = NEWKERNEL_DEBUG_USER;
829 829 return array('success' => true);
830 830 }
831   -
832   -
  831 +
  832 +
833 833 if (isset($obj->username) && isset($obj->password) && isset($obj->sessionID))
834 834 {
835 835 //$dd = new WSUserMgr();
... ... @@ -838,11 +838,11 @@ class AmdaAction {
838 838 }
839 839 else
840 840 $dd = new UserMgr();
841   -
842   - //TODO error handling
  841 +
  842 + //TODO error handling
843 843 if (($res = $dd -> ddCheckUser()) != 0)
844 844 {
845   - if ($res == 156)
  845 + if ($res == 156)
846 846 return array('success' => false, 'message' => 'Your AMDA session is expired.<br/> Login please!');
847 847  
848 848 return array('success' => false, 'message' => 'ddLogin error: '.$res);
... ... @@ -860,42 +860,42 @@ class AmdaAction {
860 860 if ($dd->getWsSize() > DISK_QUOTA)
861 861 return array('success' => false, 'message' => 'Please clean up your workspace.<br/>No more space is available');
862 862 }
863   -
  863 +
864 864 $this->user = $dd->user;
865   -
  865 +
866 866 return array('success' => true, 'userHost' => $dd -> getIPclient());
867 867 }
868   -
  868 +
869 869 private function executeRequest($obj, $function)
870 870 {
871 871 $res = $this->checkUser($obj);
872   -
  872 +
873 873 if (!$res['success'])
874 874 return $res;
875   -
  875 +
876 876 $requestManager = new RequestManagerClass();
877   -
  877 +
878 878 try {
879 879 $res = $requestManager->runIHMRequest($this->user, $res['userHost'], $function, $obj);
880 880 } catch (Exception $e) {
881 881 return array('success' => false, 'message' => 'Exception detected : '.$e->getMessage());
882 882 }
883   -
  883 +
884 884 return $res;
885 885 }
886   -
887   -/*
888   -* Main EXECUTE PROCEDURE
  886 +
  887 +/*
  888 +* Main EXECUTE PROCEDURE
889 889 */
890 890 public function execute($node, $obj)
891   - {
  891 + {
892 892 require_once(INTEGRATION_SRC_DIR."RequestManager.php");
893 893 if (isset($obj->action))
894 894 return $this->executeRequest($obj, FunctionTypeEnumClass::ACTION);
895 895 else
896 896 return $this->executeRequest($obj, FunctionTypeEnumClass::PARAMS);
897 897 }
898   -
  898 +
899 899 /*
900 900 * Generate derived parameter compilation
901 901 */
... ... @@ -912,23 +912,23 @@ class AmdaAction {
912 912 {
913 913 require_once(INTEGRATION_SRC_DIR."RequestManager.php");
914 914 $res = $this->checkUser($obj);
915   -
  915 +
916 916 if (!$res['success'])
917 917 return $res;
918   -
  918 +
919 919 IHMConfigClass::setUserName($this->user);
920 920 $libParamPath = IHMConfigClass::getCompilationPath()."lib/".$obj->paramId.".so";
921 921 if (file_exists($libParamPath))
922 922 unlink($libParamPath);
923 923 return array("success" => true);
924 924 }
925   -
  925 +
926 926 /*
927 927 * kill plot process
928 928 */
929   -
  929 +
930 930 public function killPlotRequest()
931   - {
  931 + {
932 932 require_once(INTEGRATION_SRC_DIR."RequestManager.php");
933 933 return $this->executeRequest((object) array('nodeType' => 'killplot'), FunctionTypeEnumClass::PARAMS);
934 934 }
... ... @@ -940,14 +940,14 @@ class AmdaAction {
940 940  
941 941 if ($this->amdaStat->success)
942 942 $this->amdaStat->addTask('ttoper', $this->user, null);
943   -
  943 +
944 944 $objectMgr = new TimeTableMgr();
945 945  
946 946 return $objectMgr -> merge($obj);
947 947  
948 948 }
949 949  
950   -
  950 +
951 951 /*
952 952 * intersect time tables
953 953 */
... ... @@ -961,117 +961,117 @@ class AmdaAction {
961 961  
962 962 return $result;
963 963 }
964   -
  964 +
965 965 public function initTTCache($isCatalog = false, $nparams)
966 966 {
967 967 if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr();
968 968 else $cacheMgr = new CatalogCacheMgr();
969   -
  969 +
970 970 return $cacheMgr->initTTCache($nparams);
971 971 }
972   -
973   -
  972 +
  973 +
974 974 public function initTTCacheFromTT($id, $type)
975 975 {
976 976 if ($type == 'catalog' || $type == 'sharedcatalog') $cacheMgr = new CatalogCacheMgr();
977 977 else $cacheMgr = new TimeTableCacheMgr();
978   -
  978 +
979 979 return $cacheMgr->initFromTT($id, $type);
980 980 }
981   -
  981 +
982 982 public function initForChart($id, $name, $isTmpObject, $type)
983 983 {
984 984 if ($type == 'catalog' || $type == 'sharedcatalog') $objMgr = new CatalogMgr();
985   -
  985 +
986 986 return $objMgr->initForChart($id, $name, $isTmpObject, $type);
987 987 }
988   -
  988 +
989 989 public function initTTCacheFromTmpObject($folderId, $name, $isCatalog = false)
990 990 {
991 991 if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr();
992   -
  992 +
993 993 else $cacheMgr = new CatalogCacheMgr();
994   -
995   -
996   -
  994 +
  995 +
  996 +
997 997 return $cacheMgr->initFromTmpObject($folderId, $name);
998 998 }
999   -
  999 +
1000 1000 public function initTTCacheFromUploadedFile($name, $format)
1001 1001 {
1002 1002 $cacheMgr = new TimeTableCacheMgr();
1003 1003 return $cacheMgr->initFromUploadedFile($name, $format);
1004 1004 }
1005   -
  1005 +
1006 1006 public function readTTCacheIntervals($o)
1007 1007 {
1008 1008 if ($o->typeTT == 'catalog' || $type == 'sharedcatalog') $cacheMgr = new CatalogCacheMgr();
1009 1009 else $cacheMgr = new TimeTableCacheMgr();
1010   -
  1010 +
1011 1011 return $cacheMgr->getIntervals($o->start,$o->limit,$o->sort,$o->filter);
1012 1012 }
1013   -
  1013 +
1014 1014 public function readIntervalsForChart($o)
1015 1015 {
1016 1016 if ($o->typeTT == 'catalog' || $type == 'sharedcatalog') $objMgr = new CatalogMgr();
1017   -
1018   -
  1017 +
  1018 +
1019 1019 return $objMgr->getIntervalsForChart($o->id, $o->name, $o->fromPlugin, $o->typeTT);
1020 1020 }
1021   -
  1021 +
1022 1022 public function saveTTCacheIntervalsInTT($o)
1023 1023 {
1024 1024 $cacheMgr = new TimeTableCacheMgr();
1025 1025 return $cacheMgr->saveInTT($o->ttId,$o->action,$o->cacheToken);
1026 1026 }
1027   -
  1027 +
1028 1028 public function addTTCacheInterval($o)
1029 1029 {
1030 1030 if ($o->isCatalog) $cacheMgr = new CatalogCacheMgr();
1031 1031 else $cacheMgr = new TimeTableCacheMgr();
1032   -
  1032 +
1033 1033 return $cacheMgr->addInterval($o->index, $o->start, $o->stop);
1034 1034 }
1035   -
  1035 +
1036 1036 public function removeTTCacheIntervalFromId($id, $isCatalog = false)
1037 1037 {
1038 1038 if ($isCatalog) $cacheMgr = new CatalogCacheMgr();
1039 1039 else $cacheMgr = new TimeTableCacheMgr();
1040   -
  1040 +
1041 1041 return $cacheMgr->removeIntervalFromId($id);
1042 1042 }
1043   -
  1043 +
1044 1044 public function modifyTTCacheInterval($o)
1045 1045 {
1046 1046 if ($o->isCatalog) {
1047   -
  1047 +
1048 1048 $cacheMgr = new CatalogCacheMgr();
1049 1049 return $cacheMgr->modifyIntervalFromId($o);
1050   -
  1050 +
1051 1051 }
1052 1052 else $cacheMgr = new TimeTableCacheMgr();
1053   -
  1053 +
1054 1054 return $cacheMgr->modifyIntervalFromId($o->cacheId, $o->start, $o->stop);
1055 1055 }
1056   -
  1056 +
1057 1057 public function operationTTCacheIntervals($extendTime, $shiftTime)
1058 1058 {
1059 1059 $cacheMgr = new TimeTableCacheMgr();
1060 1060 return $cacheMgr->operationIntervals($extendTime, $shiftTime);
1061 1061 }
1062   -
  1062 +
1063 1063 public function mergeTTCacheIntervals()
1064 1064 {
1065 1065 $cacheMgr = new TimeTableCacheMgr();
1066 1066 return $cacheMgr->mergeIntervals();
1067 1067 }
1068   -
  1068 +
1069 1069 public function getTTCacheStatistics()
1070 1070 {
1071 1071 $cacheMgr = new TimeTableCacheMgr();
1072 1072 return $cacheMgr->getStatistics();
1073 1073 }
1074   -
  1074 +
1075 1075 public function getTTCacheStatus()
1076 1076 {
1077 1077 $cacheMgr = new TimeTableCacheMgr();
... ... @@ -1080,39 +1080,39 @@ class AmdaAction {
1080 1080  
1081 1081 /*
1082 1082 * Send a feedback
1083   - *
  1083 + *
1084 1084 */
1085 1085 public function sendFeedback($feed)
1086 1086 {
1087 1087 $feedMgr = new FeedbackMgr();
1088 1088 return $feedMgr->addFeedback($feed->user, $feed->interface, $feed->subject, $feed->userText, $feed->userAgent, $feed->attach);
1089 1089 }
1090   -
  1090 +
1091 1091 /*
1092 1092 * Save state
1093   - *
  1093 + *
1094 1094 */
1095 1095 public function saveState($datas)
1096 1096 {
1097 1097 $myStateMgr = new StateMgr();
1098 1098 return $myStateMgr->saveState($datas);
1099 1099 }
1100   -
  1100 +
1101 1101 /*
1102 1102 * Load state
1103   - *
1104   - */
  1103 + *
  1104 + */
1105 1105 public function loadState($o)
1106   - {
  1106 + {
1107 1107 $myStateMgr = new StateMgr();
1108 1108 return $myStateMgr->loadState();
1109 1109 }
1110   -
1111   -/*
  1110 +
  1111 +/*
1112 1112 * SAMP
1113 1113 */
1114 1114 public function sendToSAMP($o)
1115   - {
  1115 + {
1116 1116 if ($this->amdaStat->success)
1117 1117 $this->amdaStat->addTask('samp', $this->user, null);
1118 1118  
... ... @@ -1125,7 +1125,7 @@ class AmdaAction {
1125 1125 }
1126 1126 return $res;
1127 1127 }
1128   -
  1128 +
1129 1129 /*
1130 1130 * HST Images
1131 1131 */
... ... @@ -1133,30 +1133,30 @@ class AmdaAction {
1133 1133 {
1134 1134 if ($this->amdaStat->success)
1135 1135 $this->amdaStat->addTask('images', $this->user, null);
1136   -
  1136 +
1137 1137 $myHstMgr = new HstMgr();
1138 1138 $res = $myHstMgr->getImagesUrl($o->startTime, $o->stopTime, $o->planet);
1139 1139 //if ($domRes->length <= 0)
1140 1140 // return array('success' => false, 'message' => 'Cannot find HST Images for this request.');
1141 1141 return array('success' => true, 'result' => $res);
1142 1142 }
1143   -
  1143 +
1144 1144 public function getAPISImagesUrl($o)
1145 1145 {
1146   - if ($this->amdaStat->success)
  1146 + if ($this->amdaStat->success)
1147 1147 $this->amdaStat->addTask('images', $this->user, null);
1148   -
  1148 +
1149 1149 $apisMgr = new APISMgr();
1150 1150 $res = $apisMgr->get($o->target, $o->startTime, $o->stopTime, $o->datasets);
1151 1151  
1152 1152 return $res;
1153   - }
  1153 + }
1154 1154 /*
1155 1155 * Filters
1156 1156 */
1157 1157 public function loadFilterList($o)
1158 1158 {
1159   - $filtersMgr = new FiltersMgr();
  1159 + $filtersMgr = new FiltersMgr();
1160 1160 $res = $filtersMgr->loadList();
1161 1161 return $res;
1162 1162 }
... ... @@ -1170,52 +1170,52 @@ class AmdaAction {
1170 1170 $res = $filtersMgr->loadAll();
1171 1171 return $res;
1172 1172 }
1173   -
  1173 +
1174 1174 public function saveFilter($o)
1175 1175 {
1176   - $filtersMgr = new FiltersMgr();
  1176 + $filtersMgr = new FiltersMgr();
1177 1177 return $filtersMgr->save($o);
1178 1178 }
1179   -
  1179 +
1180 1180 public function createFilter($o)
1181 1181 {
1182   - $filtersMgr = new FiltersMgr();
  1182 + $filtersMgr = new FiltersMgr();
1183 1183 return $filtersMgr->create($o);
1184 1184 }
1185   -
  1185 +
1186 1186 public function destroyFilter($o)
1187 1187 {
1188 1188 $filtersMgr = new FiltersMgr();
1189 1189 $res = $filtersMgr->delete($o);
1190 1190 return;
1191 1191 }
1192   -
  1192 +
1193 1193 public function getCrtFilterId()
1194 1194 {
1195 1195 $filtersMgr = new FiltersMgr();
1196 1196 $res = $filtersMgr->getCrtId();
1197 1197 return $res;
1198 1198 }
1199   -
  1199 +
1200 1200 public function getCrtFilterResult()
1201 1201 {
1202   - $filtersMgr = new FiltersMgr();
  1202 + $filtersMgr = new FiltersMgr();
1203 1203 return $filtersMgr->getCrtResult();
1204 1204 }
1205   -
  1205 +
1206 1206 public function setCrtFilterId($o)
1207 1207 {
1208   - $filtersMgr = new FiltersMgr();
  1208 + $filtersMgr = new FiltersMgr();
1209 1209 return $filtersMgr->setCrtId($o->id);
1210 1210 }
1211   -
  1211 +
1212 1212 public function resetFilter()
1213 1213 {
1214 1214 $filtersMgr = new FiltersMgr();
1215 1215 $res = $filtersMgr->reset();
1216 1216 return $res;
1217 1217 }
1218   -
  1218 +
1219 1219 public function logout($isGuest)
1220 1220 {
1221 1221 if ($isGuest) {
... ... @@ -1224,25 +1224,25 @@ class AmdaAction {
1224 1224 }
1225 1225 else {
1226 1226 $myBaseMgr = new BaseManager();
1227   - $myBaseMgr->delSimuFiles('mysimudata');
1228   - $myBaseMgr->delSimuFiles('mywsrdata');
1229   -
  1227 + $myBaseMgr->delSimuFiles('mysimudata');
  1228 + $myBaseMgr->delSimuFiles('mywsrdata');
  1229 +
1230 1230 $this->cleanUserWS();
1231   - }
  1231 + }
1232 1232 return;
1233   - }
  1233 + }
1234 1234  
1235 1235 public function getInfo($obj)
1236 1236 {
1237   - if (file_exists(HELPPATH.$obj->name))
  1237 + if (file_exists(HELPPATH.$obj->name))
1238 1238 {
1239   - $content = file_get_contents(HELPPATH.$obj->name);
  1239 + $content = file_get_contents(HELPPATH.$obj->name);
1240 1240 return array('success' => true, 'result' => $content);
1241 1241 }
1242 1242 return array('success' => false);
1243   -
1244   - }
1245   -
  1243 +
  1244 + }
  1245 +
1246 1246 public function getUserInfo()
1247 1247 {
1248 1248 $dd = new UserMgr();
... ... @@ -1262,11 +1262,11 @@ class AmdaAction {
1262 1262  
1263 1263 $myBestRunsMgr = new BestRunsMgr();
1264 1264 $res = $myBestRunsMgr->getRun($obj);
1265   -
1266   - return $res;
  1265 +
  1266 + return $res;
1267 1267 }
1268   -
1269   - //$obj = array of IDs
  1268 +
  1269 + //$obj = array of IDs
1270 1270 public function addRun($obj)
1271 1271 {
1272 1272 $myBestRunsMgr = new BestRunsMgr();
... ... @@ -1275,7 +1275,7 @@ class AmdaAction {
1275 1275  
1276 1276 $res = array('success' => true,'addedRuns' => $obj);
1277 1277 return $res;
1278   - }
  1278 + }
1279 1279 //AKKA - New action to clean user WS
1280 1280 public function cleanUserWS()
1281 1281 {
... ... @@ -1285,11 +1285,11 @@ class AmdaAction {
1285 1285  
1286 1286 public function deleteSpecialInfo($name)
1287 1287 {
1288   - if (file_exists(USERDIR.$name))
  1288 + if (file_exists(USERDIR.$name))
1289 1289 unlink(USERDIR.$name);
1290 1290 return array('success' => true);
1291 1291 }
1292   -
  1292 +
1293 1293 public function interactivePlot($obj, $multiPlotState)
1294 1294 {
1295 1295 require_once(INTEGRATION_SRC_DIR."RequestManager.php");
... ... @@ -1299,7 +1299,7 @@ class AmdaAction {
1299 1299 );
1300 1300 return $this->executeRequest($inputobj, FunctionTypeEnumClass::ACTION);
1301 1301 }
1302   -
  1302 +
1303 1303 public function getParamPlotInit($obj)
1304 1304 {
1305 1305 require_once(INTEGRATION_SRC_DIR."RequestManager.php");
... ... @@ -1309,7 +1309,7 @@ class AmdaAction {
1309 1309 );
1310 1310 return $this->executeRequest($inputobj, FunctionTypeEnumClass::PARAMINFO);
1311 1311 }
1312   -
  1312 +
1313 1313 public function getParamInfo($obj)
1314 1314 {
1315 1315 require_once(INTEGRATION_SRC_DIR."RequestManager.php");
... ... @@ -1319,14 +1319,14 @@ class AmdaAction {
1319 1319 );
1320 1320 return $this->executeRequest($inputobj, FunctionTypeEnumClass::PARAMINFO);
1321 1321 }
1322   -
  1322 +
1323 1323 public function getSharedObjectFolders($obj)
1324 1324 {
1325 1325 $mgr = new SharedObjectsMgr();
1326 1326 $folders = $mgr->getFolders($obj->type);
1327 1327 return array('success' => true, 'folders' => $folders);
1328 1328 }
1329   -
  1329 +
1330 1330 public function shareObjects($obj)
1331 1331 {
1332 1332 $mgr = new SharedObjectsMgr();
... ... @@ -1335,19 +1335,19 @@ class AmdaAction {
1335 1335 case 'catalog' :
1336 1336 $src_object_path = USERTTDIR.$obj->object->id.".xml";
1337 1337 break;
1338   -
  1338 +
1339 1339 default:
1340 1340 return array('success' => false, 'message' => 'Unknown object type');
1341 1341 }
1342   -
  1342 +
1343 1343 $result = $mgr->add($obj->type, $obj->name, $obj->folder, $src_object_path, $obj->description, $this->user);
1344 1344 if (!$result['success'])
1345 1345 return $result;
1346   -
  1346 +
1347 1347 $mgr->updateTree();
1348 1348 return $result;
1349 1349 }
1350   -
  1350 +
1351 1351 public function isSharedObjectNameAlreadyUsed($obj)
1352 1352 {
1353 1353 $mgr = new SharedObjectsMgr();
... ... @@ -1360,4 +1360,3 @@ class AmdaAction {
1360 1360 }
1361 1361 }
1362 1362 ?>
1363   -
... ...
php/classes/EpnTapMgr.php
... ... @@ -8,13 +8,13 @@ class EpnTapMgr {
8 8  
9 9 function __construct()
10 10 {
11   - $this->logEpnTap = fopen(USERDATADIR."logEpnTap", "a");
  11 + $this->logEpnTap = fopen(LOG_DIR . "epnTap.log", "a");
12 12 $this->addLog("\n---\n");
13 13 }
14 14  
15 15 function addLog($msg)
16 16 {
17   - fwrite($this->logEpnTap, date("h:i:s A") . $msg . "\n");
  17 + fwrite($this->logEpnTap, date("h:i:s A") . ": " . $msg . "\n");
18 18 }
19 19  
20 20 public function call($function_name, $args) {
... ... @@ -45,8 +45,7 @@ class EpnTapMgr {
45 45 $monthp = $month;
46 46 }
47 47  
48   - # this checks where we are in relation to October 15, 1582, the beginning
49   - # of the Gregorian calendar.
  48 + # this checks where we are in relation to October 15, 1582, the beginning of the Gregorian calendar.
50 49 if (($year < 1582) ||
51 50 ($year == 1582 && $month < 10) ||
52 51 ($year == 1582 && $month == 10 && $day < 15))
... ... @@ -60,53 +59,34 @@ class EpnTapMgr {
60 59 return $j_day;
61 60 }
62 61  
63   - private function getServiceNbResults($table_name, $access_url, $target_name, $dataproduct_type, $time_min, $time_max) {
64   - // $this->addLog("getServiceNbResults(" . $table_name .", ". $access_url .", ". $target_name .", ". $dataproduct_type .", ". $time_min .", ". $time_max . ")");
  62 + public function createFilter($target_name, $dataproduct_type, $time_min, $time_max) {
65 63 $filter = array();
66 64 if($target_name)
67 65 array_push($filter, "target_name = '$target_name'");
68 66 if($dataproduct_type)
69 67 array_push($filter, "dataproduct_type = '$dataproduct_type'");
70 68 if($time_min)
71   - array_push($filter, "time_min >= " . $this->date2JD($time_min));
  69 + array_push($filter, "time_min <= " . $this->date2JD($time_min));
72 70 if($time_max)
73 71 array_push($filter, "time_max >= " . $this->date2JD($time_max));
74 72  
75   - $query = "SELECT COUNT(granule_uid) AS nb_results FROM $table_name.epn_core"
76   - . (count($filter) > 0 ? ' WHERE '.join(' AND ', $filter) : '');
77   -
78   - $this->addLog("query: " . $query);
  73 + return (count($filter) > 0 ? ' WHERE '.join(' AND ', $filter) : '');
  74 + }
79 75  
  76 + public function request($access_url, $query) {
80 77 $votMgr = new VOTableMgr;
81 78 $params = 'FORMAT=votable&LANG=ADQL&REQUEST=doQuery';
82 79 $url = $access_url . '/sync?' . $params . '&QUERY=' . urlencode($query);
83   - $this->addLog("URL: " . $url);
  80 + $this->addLog("Query URL: " . $url);
84 81 $votMgr->load($url);
85   - $res = $votMgr->isValidSchema() ? $votMgr->getStream() : "-";
86   - return $res["nb_results"];
  82 + $result = $votMgr->isValidSchema() ? $votMgr->parseStream() : NULL;
  83 + return $result;
87 84 }
88 85  
89 86 private function getGranules($table_name, $access_url, $target_name, $dataproduct_type, $time_min, $time_max) {
90   - $this->addLog("getGranules(" . $table_name .", ". $access_url .", ". $target_name .", ". $dataproduct_type .", ". $time_min .", ". $time_max . ")");
91   - $filter = array();
92   - if($target_name)
93   - array_push($filter, "target_name = '$target_name'");
94   - if($dataproduct_type)
95   - array_push($filter, "dataproduct_type = '$dataproduct_type'");
96   - if($time_min)
97   - array_push($filter, "time_min >= " . $this->date2JD($time_min));
98   - if($time_max)
99   - array_push($filter, "time_max >= " . $this->date2JD($time_max));
100   -
101   - $query = "SELECT dataproduct_type, target_name, time_min, time_max FROM $table_name.epn_core"
102   - . ($filter.length > 0 ? ' WHERE ' . join(' AND ', $filter) : '');
103   -
104   - $votMgr = new VOTableMgr;
105   - $params = 'FORMAT=votable&LANG=ADQL&REQUEST=doQuery';
106   - $url = $access_url . '/sync?' . $params . '&QUERY=' . urlencode($query);
107   - $votMgr->load($url);
108   - $res = $votMgr->isValidSchema() ? $votMgr->getStream() : "-";
109   - return $res;
  87 + $filter = $this->createFilter($target_name, $dataproduct_type, $time_min, $time_max);
  88 + $query = "SELECT dataproduct_type, target_name, time_min, time_max FROM $table_name.epn_core" . $filter;
  89 + return $this->request($access_url, $query);
110 90 }
111 91 }
112 92 ?>
... ...
php/classes/VOTableMgr.php
... ... @@ -9,20 +9,22 @@ define(&quot;DEBUG_MODE&quot;, TRUE);
9 9  
10 10  
11 11 class VOTableMgr {
12   - private $xml, $xp;
13   - private $log;
14   -
15   - function __construct()
16   - {
17   - if (DEBUG_MODE)
18   - $this->log = fopen(USERDATADIR."logVOTable", "a");
19   - }
  12 + private $xml, $xp;
  13 + private $logVotable; // The log file.
  14 + private $stream; // The stream in the VOTable
  15 + private $c; // Current character position on the stream
  16 +
  17 + function __construct()
  18 + {
  19 + if (DEBUG_MODE)
  20 + $this->logVotable = fopen(LOG_DIR . "VOTable.log", "a");
  21 + }
20 22  
21   - function addLog($msg)
22   - {
23   - if (DEBUG_MODE)
24   - fprintf($this->log, $msg."\n");
25   - }
  23 + function addLog($msg)
  24 + {
  25 + if (DEBUG_MODE)
  26 + fwrite($this->logVotable, date("h:i:s A") . ": " . $msg . "\n");
  27 + }
26 28  
27 29 function load($fileName) {
28 30 $this->addLog("File name" . $fileName);
... ... @@ -35,10 +37,11 @@ class VOTableMgr {
35 37 libxml_set_streams_context($context);
36 38  
37 39 $this->xml = new DomDocument();
38   - if (!$this->xml->load($fileName))
39   - {
40   - $this->xml = false;
41   - return FALSE;
  40 + $res = $this->xml->load($fileName);
  41 +
  42 + if(!$res) {
  43 + $this->addLog("Can not load VOTAble.");
  44 + return false;
42 45 }
43 46  
44 47 $this->checkIDAttribute();
... ... @@ -58,113 +61,125 @@ class VOTableMgr {
58 61 return true;
59 62 }
60 63  
61   - function isValidSchema()
62   - {
63   - if (!$this->xml)
64   - return FALSE;
65   -
66   -
67   - //ToDo - BRE - add validation!!
68   - return TRUE;
69   -
70   - if (DEBUG_MODE)
71   - libxml_use_internal_errors(true);
72   -
73   - $vers = $this->getVersion();
74   -
75   - $this->addLog("VOTable version : ".$vers."\n");
76   -
77   - $result = FALSE;
78   -
79   - switch ($vers)
80   - {
81   - case '1.2' :
82   - $result = $this->xml->schemaValidate(XMLPATH.'VOTable-1.2.xsd');
83   - case '1.0' :
84   - $result = $this->xml->schemaValidate(XMLPATH.'VOTable-1.0.xsd');
85   - default :
86   - $result = $this->xml->schemaValidate(XMLPATH.'VOTable-1.1.xsd');
87   - }
88   -
89   - if (DEBUG_MODE)
90   - {
91   - $errors = libxml_get_errors();
92   -
93   - foreach ($errors as $error)
94   - {
95   - $msg = '';
96   -
97   - switch ($error->level)
98   - {
99   - case LIBXML_ERR_WARNING:
100   - $msg .= ("WARNING ".$error->code.": ");
101   - break;
102   - case LIBXML_ERR_ERROR:
103   - $msg .= ("ERROR ".$error->code.": ");
104   - break;
105   - case LIBXML_ERR_FATAL:
106   - $msg .= ("FATAL ".$error->code.": ");
107   - break;
108   - }
109   - $msg .= ($error->message." - In line : ".$error->line." - Of file : ".$error->file."\n");
110   -
111   - $this->addLog($msg);
112   - }
113   -
114   - libxml_use_internal_errors(false);
115   - }
116   -
117   - return $result;
118   - }
119   -
120   - protected function queryResource()
121   - {
122   - return "//x:RESOURCE";
123   - }
124   -
125   - protected function queryTable()
126   - {
127   - return $this->queryResource()."/x:TABLE";
128   - }
129   -
130   - protected function queryDescription()
131   - {
132   - return $this->queryTable()."/x:DESCRIPTION";
133   - }
134   -
135   - protected function queryFields()
136   - {
137   - return $this->queryTable()."/x:FIELD";
138   - }
139   -
140   - protected function queryField($field_id)
141   - {
142   - return $this->queryFields()."[@ID='".$field_id."']";
143   - }
144   -
145   - protected function queryFieldByName($field_id)
146   - {
147   - return $this->queryFields()."[@name='".$field_id."']";
148   - }
149   - protected function queryFieldDescription($field_id)
150   - {
151   - return $this->queryField($field_id)."/x:DESCRIPTION";
152   - }
153   -
154   - protected function queryData()
155   - {
156   - return $this->queryTable()."/x:DATA";
157   - }
158   -
159   - protected function queryTableData()
160   - {
161   - return $this->queryData()."/x:TABLEDATA";
162   - }
163   -
164   - protected function queryTR()
165   - {
166   - return $this->queryTableData()."/x:TR";
167   - }
  64 + function isValidSchema()
  65 + {
  66 + if (!$this->xml)
  67 + return FALSE;
  68 +
  69 + $infos = $this->xp->query($this->queryResourceInfo());
  70 + foreach($infos as $info) {
  71 + if($info->getAttribute('value') == 'ERROR') {
  72 + $this->addLog("There is an error on the VOTable: " . $info->textContent);
  73 + return FALSE;
  74 + }
  75 + }
  76 +
  77 + //ToDo - BRE - add validation!!
  78 + return TRUE;
  79 +
  80 + if (DEBUG_MODE)
  81 + libxml_use_internal_errors(true);
  82 +
  83 + $vers = $this->getVersion();
  84 +
  85 + $this->addLog("VOTable version : ".$vers."\n");
  86 +
  87 + $result = FALSE;
  88 +
  89 + switch ($vers)
  90 + {
  91 + case '1.2' :
  92 + $result = $this->xml->schemaValidate(XMLPATH.'VOTable-1.2.xsd');
  93 + case '1.0' :
  94 + $result = $this->xml->schemaValidate(XMLPATH.'VOTable-1.0.xsd');
  95 + default :
  96 + $result = $this->xml->schemaValidate(XMLPATH.'VOTable-1.1.xsd');
  97 + }
  98 +
  99 + if (DEBUG_MODE)
  100 + {
  101 + $errors = libxml_get_errors();
  102 +
  103 + foreach ($errors as $error)
  104 + {
  105 + $msg = '';
  106 +
  107 + switch ($error->level)
  108 + {
  109 + case LIBXML_ERR_WARNING:
  110 + $msg .= ("WARNING ".$error->code.": ");
  111 + break;
  112 + case LIBXML_ERR_ERROR:
  113 + $msg .= ("ERROR ".$error->code.": ");
  114 + break;
  115 + case LIBXML_ERR_FATAL:
  116 + $msg .= ("FATAL ".$error->code.": ");
  117 + break;
  118 + }
  119 + $msg .= ($error->message." - In line : ".$error->line." - Of file : ".$error->file."\n");
  120 +
  121 + $this->addLog($msg);
  122 + }
  123 +
  124 + libxml_use_internal_errors(false);
  125 + }
  126 +
  127 + return $result;
  128 + }
  129 +
  130 + protected function queryResource()
  131 + {
  132 + return "//x:RESOURCE";
  133 + }
  134 +
  135 + protected function queryResourceInfo()
  136 + {
  137 + return $this->queryResource()."/x:INFO";
  138 + }
  139 +
  140 + protected function queryTable()
  141 + {
  142 + return $this->queryResource()."/x:TABLE";
  143 + }
  144 +
  145 + protected function queryDescription()
  146 + {
  147 + return $this->queryTable()."/x:DESCRIPTION";
  148 + }
  149 +
  150 + protected function queryFields()
  151 + {
  152 + return $this->queryTable()."/x:FIELD";
  153 + }
  154 +
  155 + protected function queryField($field_id)
  156 + {
  157 + return $this->queryFields()."[@ID='".$field_id."']";
  158 + }
  159 +
  160 + protected function queryFieldByName($field_id)
  161 + {
  162 + return $this->queryFields()."[@name='".$field_id."']";
  163 + }
  164 + protected function queryFieldDescription($field_id)
  165 + {
  166 + return $this->queryField($field_id)."/x:DESCRIPTION";
  167 + }
  168 +
  169 + protected function queryData()
  170 + {
  171 + return $this->queryTable()."/x:DATA";
  172 + }
  173 +
  174 + protected function queryTableData()
  175 + {
  176 + return $this->queryData()."/x:TABLEDATA";
  177 + }
  178 +
  179 + protected function queryTR()
  180 + {
  181 + return $this->queryTableData()."/x:TR";
  182 + }
168 183  
169 184 protected function queryBinaryData() {
170 185 return $this->queryData()."/x:BINARY";
... ... @@ -175,448 +190,532 @@ class VOTableMgr {
175 190 }
176 191  
177 192  
178   - public function getVersion()
179   - {
180   - if (!$this->xml)
181   - return '';
182   - $root = $this->xml->documentElement;
  193 + public function getVersion()
  194 + {
  195 + if (!$this->xml)
  196 + return '';
  197 + $root = $this->xml->documentElement;
183 198  
184   - return $root->getAttribute('version');
185   - }
  199 + return $root->getAttribute('version');
  200 + }
186 201  
187   - public function getDescription()
188   - {
189   - if (!$this->xp)
190   - return '';
  202 + public function getDescription()
  203 + {
  204 + if (!$this->xp)
  205 + return '';
191 206  
192   - $desc = $this->xp->query($this->queryDescription());
  207 + $desc = $this->xp->query($this->queryDescription());
193 208  
194   - if ($desc->length < 1)
195   - return '';
  209 + if ($desc->length < 1)
  210 + return '';
196 211  
197   - return $desc->item(0)->nodeValue;
198   - }
  212 + return $desc->item(0)->nodeValue;
  213 + }
  214 +
  215 + private function get_block_size($data_type) {
  216 + switch($data_type) {
  217 + case 'boolean':
  218 + case 'unsignedByte':
  219 + case 'char':
  220 + $block_size = 1;
  221 + break;
  222 + case 'unicodeChar':
  223 + case 'short':
  224 + $block_size = 2;
  225 + break;
  226 + case 'int':
  227 + case 'float':
  228 + $block_size = 4;
  229 + break;
  230 + case 'long':
  231 + case 'double':
  232 + case 'float_complex':
  233 + $block_size = 8;
  234 + break;
  235 + case 'double_complex':
  236 + $block_size = 8;
  237 + break;
  238 + default:
  239 + $block_size = 0;
  240 + break;
  241 + }
  242 + return $block_size;
  243 + }
  244 +
  245 + private function get_row_size($field_node) {
  246 + $datatype = $field_node->getAttribute("datatype");
  247 + $block_size = $this->get_block_size($datatype);
  248 + if($field_node->getAttribute("arraysize") == NULL) {
  249 + $array_size = $block_size;
  250 + } else if("*" == $field_node->getAttribute("arraysize")) {
  251 + // echo "substr: " . json_encode(substr($this->stream, $this->c, 4)) . "\n";
  252 + $array_size = unpack("Ns", substr($this->stream, $this->c, 4))["s"] * $block_size;
  253 + // echo "array_size: $array_size\n";
  254 + $this->c+=4;
  255 + } else {
  256 + $array_size = (int)($field_node->getAttribute("arraysize")) * $block_size;
  257 + }
  258 + return $array_size;
  259 + }
199 260  
200 261 /** Get the VOTable stream content.*/
201   - // TODO: faire une fonction générique avec le curseur qui se déplace et tout et qui renvoie un dictionnaire
202   - public function getStream() {
203   - $fields = array();
204   - $stream = $this->xp->query($this->queryStream())->item(0)->textContent;
205   - $ar = unpack("C*", base64_decode($stream));
206   - $c = 0; // cursor
207   - foreach ($this->xp->query($this->queryFields()) as $field) {
208   - $datatype = $field->getAttribute("datatype");
209   - $id = $field->getAttribute("ID"); // column name
210   - switch ($datatype) {
211   - case 'char':
212   - $str_length = ($ar[1]<<24) + ($ar[2]<<16) + ($ar[3]<<8) + $ar[4];
213   - $res = "";
214   - for($i=0 ; $i<$str_length ; $i++) {
215   - $res = $res . chr($ar[$i+5]);
216   - }
217   - break;
218   - case 'int':
219   - $res = ($ar[1]<<24) + ($ar[2]<<16) + ($ar[3]<<8) + $ar[4];
220   - break;
221   - case 'double':
222   - $this->addLog("Parsing double");
223   - $res = "Float parsing not implemented yet.";//($ar[1]<<24) + ($ar[2]<<16) + ($ar[3]<<8) + $ar[4];
224   - break;
225   -
226   - default:
227   - break;
  262 + public function parseStream() {
  263 + $data = Array();
  264 + $fields = $this->xp->query($this->queryFields());
  265 + $nb_columns = $fields->length;
  266 + $row = Array();
  267 + $n_value = 0; // index of current value
  268 + $this->c = 0; // initialize cursor position.
  269 + $query_stream = $this->xp->query($this->queryStream())->item(0);
  270 + if($query_stream == NULL)
  271 + return NULL;
  272 + $this->stream = base64_decode($query_stream->textContent);
  273 + // echo "stream: " . json_encode($this->stream) . "\n";
  274 + $stream_len = strlen($this->stream);
  275 + if($stream_len == 0)
  276 + return NULL;
  277 + while($this->c < strlen($this->stream)) {
  278 + $col_id = $n_value % $nb_columns;
  279 + $field_node = $fields[$col_id];
  280 +
  281 + // echo "c=$this->c, n_value=$n_value, nb_columns=$nb_columns, col_id=$col_id, column_name=" . $field_node->getAttribute("ID") . "\n";
  282 +
  283 + if($col_id == 0) {
  284 + $row = Array();
  285 + }
  286 + $row[$field_node->getAttribute("ID")] = $this->process_datablock($field_node);
  287 + if($col_id == $nb_columns-1) {
  288 + array_push($data, $row);
228 289 }
229   - $this->addLog($id . "=" . $res);
230   - $fields[$id] = $res;
  290 + $n_value+=1;
  291 + // echo "Char pos: $this->c\n";
231 292 }
  293 + return $data;
  294 + }
232 295  
233   - return $fields;
234   - // return ($ar[1]<<24) + ($ar[2]<<16) + ($ar[3]<<8) + $ar[4];
  296 + private function process_datablock($field_node) {
  297 + $data_type = $field_node->getAttribute("datatype");
  298 + $row_size = $this->get_row_size($field_node);
  299 + // echo "datatype: " . $field_node->getAttribute("datatype") . "\n";
  300 + // echo "Row size: $row_size\n";
  301 + switch ($data_type) {
  302 + case 'boolean':
  303 + case 'unsignedByte':
  304 + $res = $this->stream[$this->c] == "T" || $this->stream[$this->c] == "t" || $this->stream[$this->c] == "1";
  305 + break;
  306 + case 'char':
  307 + case 'unicodeChar':
  308 + $res = $row_size !=0 ? substr($this->stream, $this->c, $row_size) : NULL;
  309 + break;
  310 + case 'short':
  311 + $res = unpack("ss", substr($this->stream, $this->c, 2))["s"];
  312 + break;
  313 + case 'int':
  314 + $res = unpack("Ns", substr($this->stream, $this->c, 4))["s"];
  315 + break;
  316 + case 'long':
  317 + $res = unpack("Js", substr($this->stream, $this->c, 8))["s"]; // /!\ J -> PHP 5.6 only
  318 + break;
  319 + case 'float':
  320 + $res = unpack("fs", substr($this->stream, $this->c, 4))["s"];
  321 + break;
  322 + case 'double':
  323 + $res = unpack("ds", substr($this->stream, $this->c, 8))["s"];
  324 + break;
  325 + default:
  326 + $res = NULL;
  327 + $this->addLog("Unknown character: $data_type");
  328 + break;
  329 + }
  330 + $this->c+=$row_size;
  331 + // echo $field_node->getAttribute("ID") . "($data_type $row_size) = " . json_encode($res) . "\n";
  332 + return $res;
235 333 }
236 334  
237   - public function getFirstTR()
238   - {
239   - if (!$this->xp)
240   - return NULL;
241 335  
242   - /*$trs = $this->xp->query($this->queryTR());
  336 + public function getFirstTR()
  337 + {
  338 + if (!$this->xp)
  339 + return NULL;
243 340  
244   - if ($trs->length < 1)
245   - return NULL;
  341 + /*$trs = $this->xp->query($this->queryTR());
246 342  
247   - return $trs->item(0);*/
  343 + if ($trs->length < 1)
  344 + return NULL;
248 345  
249   - $tabledatas = $this->xp->query($this->queryTableData());
250   - if ($tabledatas->length < 1)
251   - return NULL;
  346 + return $trs->item(0);*/
252 347  
253   - $tabledata = $tabledatas->item(0);
  348 + $tabledatas = $this->xp->query($this->queryTableData());
  349 + if ($tabledatas->length < 1)
  350 + return NULL;
254 351  
255   - $node = $tabledata->firstChild;
  352 + $tabledata = $tabledatas->item(0);
256 353  
257   - while($node && ($node->nodeType != 1) && ($node->nodeName != "TR"))
258   - $node = $node->nextSibling;
  354 + $node = $tabledata->firstChild;
259 355  
260   - return $node;
261   - }
  356 + while($node && ($node->nodeType != 1) && ($node->nodeName != "TR"))
  357 + $node = $node->nextSibling;
262 358  
263   - public function getNextTR($tr)
264   - {
265   - if (!$this->xp)
266   - return NULL;
  359 + return $node;
  360 + }
  361 +
  362 + public function getNextTR($tr)
  363 + {
  364 + if (!$this->xp)
  365 + return NULL;
267 366  
268   - while($tr->nextSibling && ($tr->nextSibling->nodeType != 1) && ($node->nodeName != "TR"))
269   - $tr = $tr->nextSibling;
  367 + while($tr->nextSibling && ($tr->nextSibling->nodeType != 1) && ($node->nodeName != "TR"))
  368 + $tr = $tr->nextSibling;
270 369 return $tr->nextSibling;
271   - }
  370 + }
272 371  
273   - public function getTDValueByFieldIndex($tr,$field_index)
274   - {
275   - if (!$this->xp)
276   - return NULL;
  372 + public function getTDValueByFieldIndex($tr,$field_index)
  373 + {
  374 + if (!$this->xp)
  375 + return NULL;
277 376  
278   - $tds = $tr->getElementsByTagName("TD");
  377 + $tds = $tr->getElementsByTagName("TD");
279 378  
280   - if (($tds->length < 1) || ($field_index >= $tds->length))
281   - return NULL;
  379 + if (($tds->length < 1) || ($field_index >= $tds->length))
  380 + return NULL;
282 381  
283   - return $tds->item($field_index)->nodeValue;
284   - }
  382 + return $tds->item($field_index)->nodeValue;
  383 + }
285 384  
286   - protected function isTimeField($field)
287   - {
288   - if (!$this->xp)
289   - return FALSE;
  385 + protected function isTimeField($field)
  386 + {
  387 + if (!$this->xp)
  388 + return FALSE;
290 389  
291   - return (($field->getAttribute("ucd") == "time.epoch") && ($field->getAttribute("xtype") == "dateTime"));
292   - }
  390 + return (($field->getAttribute("ucd") == "time.epoch") && ($field->getAttribute("xtype") == "dateTime"));
  391 + }
293 392  
294   - public function getTimeFieldIndex()
295   - {
296   - if (!$this->xp)
297   - return -1;
  393 + public function getTimeFieldIndex()
  394 + {
  395 + if (!$this->xp)
  396 + return -1;
298 397  
299   - $fields = $this->xp->query($this->queryFields());
  398 + $fields = $this->xp->query($this->queryFields());
300 399  
301   - if ($fields->length < 1)
302   - return -1;
  400 + if ($fields->length < 1)
  401 + return -1;
303 402  
304   - for ($i = 0; $i < $fields->length; $i++)
305   - if ($this->isTimeField($fields->item($i)))
306   - return $i;
  403 + for ($i = 0; $i < $fields->length; $i++)
  404 + if ($this->isTimeField($fields->item($i)))
  405 + return $i;
307 406  
308   - return -1;
309   - }
  407 + return -1;
  408 + }
310 409  
311   - protected function getFieldByID($field_id)
312   - {
313   - if (!$this->xp)
314   - return NULL;
  410 + protected function getFieldByID($field_id)
  411 + {
  412 + if (!$this->xp)
  413 + return NULL;
315 414  
316   - $fields = $this->xp->query($this->queryFields());
  415 + $fields = $this->xp->query($this->queryFields());
317 416  
318   - if ($fields->length < 1)
319   - return NULL;
  417 + if ($fields->length < 1)
  418 + return NULL;
320 419  
321   - foreach ($fields as $field)
322   - if ($field->getAttribute("ID") == $field_id)
323   - return $field;
  420 + foreach ($fields as $field)
  421 + if ($field->getAttribute("ID") == $field_id)
  422 + return $field;
324 423  
325   - return NULL;
326   - }
  424 + return NULL;
  425 + }
327 426  
328   - protected function getFieldByName($field_id)
329   - {
330   - if (!$this->xp)
331   - return NULL;
  427 + protected function getFieldByName($field_id)
  428 + {
  429 + if (!$this->xp)
  430 + return NULL;
332 431  
333   - $fields = $this->xp->query($this->queryFieldByName($field_id));
  432 + $fields = $this->xp->query($this->queryFieldByName($field_id));
334 433  
335   - if ($fields->length < 1)
336   - return NULL;
  434 + if ($fields->length < 1)
  435 + return NULL;
337 436  
338   - foreach ($fields as $field)
339   - if ($field->getAttribute("name") == $field_id)
340   - return $field;
  437 + foreach ($fields as $field)
  438 + if ($field->getAttribute("name") == $field_id)
  439 + return $field;
341 440  
342   - return NULL;
343   - }
  441 + return NULL;
  442 + }
344 443  
345   - protected function checkIDAttribute(){
  444 + protected function checkIDAttribute(){
346 445  
347   - $fields = $this->xml->getElementsByTagName('FIELD');
348   - $i = 0;
349   - foreach ($fields as $field){
  446 + $fields = $this->xml->getElementsByTagName('FIELD');
  447 + $i = 0;
  448 + foreach ($fields as $field){
350 449 $i++;
351 450 if (!$field->hasAttribute("ID")){
352   - $field->setAttribute("ID", "col".$i);
353   - }
354   - }
355   - $this->xml->saveXML();
356   -
357   - }
358   -
359   - public function getFieldIndexByID($field_id)
360   - {
361   - if (!$this->xp)
362   - return -1;
363   -
364   - $fields = $this->xp->query($this->queryFields());
365   -
366   - if ($fields->length < 1)
367   - return -1;
368   -
369   - for ($i = 0; $i < $fields->length; $i++)
370   - if ($fields->item($i)->getAttribute("ID") == $field_id)
371   - return $i;
372   -
373   - return -1;
374   - }
375   -
376   - public function getStartStop()
377   - {
378   - if (!$this->xp)
379   - return '0 0';
380   -
381   - $timeIndex = $this->getTimeFieldIndex();
382   - if ($timeIndex < 0)
383   - return '0 0';
384   -
385   - $tr = $this->getFirstTR();
386   -
387   - if (!$tr)
388   - return '0 0';
389   -
390   - $start = $this->getTDValueByFieldIndex($tr,$timeIndex);
391   -
392   - $stop = $start;
393   - while ($tr)
394   - {
395   - $stop = $this->getTDValueByFieldIndex($tr,$timeIndex);
396   - $tr = $this->getNextTR($tr);
397   - }
398   -
399   - if (!$start)
400   - $start = 0;
401   - else
402   - $start = strtotime($start);
403   -
404   - if (!$stop)
405   - $stop = 0;
406   - else
407   - $stop = strtotime($stop);
408   -
409   - return $start." ".$stop;
410   - }
411   -
412   - public function getFieldInfoByID($field_id)
413   - {
414   - if (!$this->xp)
415   - return array("id" => $field_id,
416   - "error" => "No file loaded");
417   -
418   - $field = $this->getFieldByID($field_id);
419   -
420   - if (!$field)
421   - $field = $this->getFieldByName($field_id);
422   -
423   - if (!$field)
424   - return array("id" => $field_id,
425   - "error" => "This field doesn't exist");
426   - return $this->getFieldInfo($field);
427   - }
428   -
429   -
430   - public function getFieldInfo($field)
431   - {
432   - if (!$this->xp)
433   - return array("id" => $field_id,
434   - "error" => "No file loaded");
435   - $description = '';
436   - $desc = $field->getElementsByTagName("DESCRIPTION");
437   - if ($desc->length >= 1)
438   - $description = $desc->item(0)->nodeValue;
439   -
440   - $size = $field->getAttribute("arraysize");
441   - if ($size == '')
442   - $size = 1;
443   - else
444   - $size = intval($size);
445   -
446   - switch ($field->getAttribute("datatype"))
447   - {
448   - case "short" :
449   - $type = "SHORT";
450   - break;
451   - case "int" :
452   - $type = "INTEGER";
453   - break;
454   - case "long" :
455   - case "double" :
456   - $type = "DOUBLE";
457   - break;
458   - default :
459   - $type = "FLOAT";
460   - }
  451 + $field->setAttribute("ID", "col".$i);
  452 + }
  453 + }
  454 + $this->xml->saveXML();
  455 +
  456 + }
  457 +
  458 + public function getFieldIndexByID($field_id)
  459 + {
  460 + if (!$this->xp)
  461 + return -1;
  462 +
  463 + $fields = $this->xp->query($this->queryFields());
  464 +
  465 + if ($fields->length < 1)
  466 + return -1;
  467 +
  468 + for ($i = 0; $i < $fields->length; $i++)
  469 + if ($fields->item($i)->getAttribute("ID") == $field_id)
  470 + return $i;
  471 +
  472 + return -1;
  473 + }
  474 +
  475 + public function getStartStop()
  476 + {
  477 + if (!$this->xp)
  478 + return '0 0';
  479 +
  480 + $timeIndex = $this->getTimeFieldIndex();
  481 + if ($timeIndex < 0)
  482 + return '0 0';
  483 +
  484 + $tr = $this->getFirstTR();
  485 +
  486 + if (!$tr)
  487 + return '0 0';
  488 +
  489 + $start = $this->getTDValueByFieldIndex($tr,$timeIndex);
  490 +
  491 + $stop = $start;
  492 + while ($tr)
  493 + {
  494 + $stop = $this->getTDValueByFieldIndex($tr,$timeIndex);
  495 + $tr = $this->getNextTR($tr);
  496 + }
  497 +
  498 + if (!$start)
  499 + $start = 0;
  500 + else
  501 + $start = strtotime($start);
  502 +
  503 + if (!$stop)
  504 + $stop = 0;
  505 + else
  506 + $stop = strtotime($stop);
  507 +
  508 + return $start." ".$stop;
  509 + }
  510 +
  511 + public function getFieldInfoByID($field_id)
  512 + {
  513 + if (!$this->xp)
  514 + return array("id" => $field_id,
  515 + "error" => "No file loaded");
  516 +
  517 + $field = $this->getFieldByID($field_id);
  518 +
  519 + if (!$field)
  520 + $field = $this->getFieldByName($field_id);
  521 +
  522 + if (!$field)
  523 + return array("id" => $field_id,
  524 + "error" => "This field doesn't exist");
  525 + return $this->getFieldInfo($field);
  526 + }
  527 +
  528 +
  529 + public function getFieldInfo($field)
  530 + {
  531 + if (!$this->xp)
  532 + return array("id" => $field_id,
  533 + "error" => "No file loaded");
  534 + $description = '';
  535 + $desc = $field->getElementsByTagName("DESCRIPTION");
  536 + if ($desc->length >= 1)
  537 + $description = $desc->item(0)->nodeValue;
  538 +
  539 + $size = $field->getAttribute("arraysize");
  540 + if ($size == '')
  541 + $size = 1;
  542 + else
  543 + $size = intval($size);
  544 +
  545 + switch ($field->getAttribute("datatype"))
  546 + {
  547 + case "short" :
  548 + $type = "SHORT";
  549 + break;
  550 + case "int" :
  551 + $type = "INTEGER";
  552 + break;
  553 + case "long" :
  554 + case "double" :
  555 + $type = "DOUBLE";
  556 + break;
  557 + default :
  558 + $type = "FLOAT";
  559 + }
461 560 if (!$field->getAttribute("ID"))
462   - $id = "col".$n;
  561 + $id = "col".$n;
463 562 else $id = $field->getAttribute("ID");
464 563  
465   - return array("id" => $field->getAttribute("ID"),
466   - "type" => $type,
467   - "name" => $field->getAttribute("name"),
468   - "ucd" => $field->getAttribute("ucd"),
469   - "unit" => $field->getAttribute("unit"),
470   - "size" => $size,
471   - "description" => $description
472   - );
473   - }
474   -
475   - public function getFieldsInfo()
476   - {
477   - if (!$this->xp)
478   - return array("error" => "No file loaded");
  564 + return array("id" => $field->getAttribute("ID"),
  565 + "type" => $type,
  566 + "name" => $field->getAttribute("name"),
  567 + "ucd" => $field->getAttribute("ucd"),
  568 + "unit" => $field->getAttribute("unit"),
  569 + "size" => $size,
  570 + "description" => $description
  571 + );
  572 + }
479 573  
480   - $fields_info = array();
  574 + public function getFieldsInfo()
  575 + {
  576 + if (!$this->xp)
  577 + return array("error" => "No file loaded");
481 578  
482   - $fields = $this->xp->query($this->queryFields());
  579 + $fields_info = array();
483 580  
484   - if ($fields->length < 1)
485   - return $fields_info;
  581 + $fields = $this->xp->query($this->queryFields());
486 582  
487   - foreach ($fields as $field)
488   - {
489   - if ($this->isTimeField($field))
490   - continue;
  583 + if ($fields->length < 1)
  584 + return $fields_info;
491 585  
492   - array_push($fields_info,$this->getFieldInfo($field));
493   - }
  586 + foreach ($fields as $field)
  587 + {
  588 + if ($this->isTimeField($field))
  589 + continue;
494 590  
495   - return $fields_info;
496   - }
  591 + array_push($fields_info,$this->getFieldInfo($field));
  592 + }
497 593  
498   - public function getSamplings()
499   - {
500   - if (!$this->xp)
501   - return array("minSampling" => 0,
502   - "maxSampling" => 0);
  594 + return $fields_info;
  595 + }
503 596  
504   - $timeIndex = $this->getTimeFieldIndex();
505   - if ($timeIndex < 0)
506   - return array("minSampling" => 0,
507   - "maxSampling" => 0);
  597 + public function getSamplings()
  598 + {
  599 + if (!$this->xp)
  600 + return array("minSampling" => 0,
  601 + "maxSampling" => 0);
508 602  
509   - $tr = $this->getFirstTR();
  603 + $timeIndex = $this->getTimeFieldIndex();
  604 + if ($timeIndex < 0)
  605 + return array("minSampling" => 0,
  606 + "maxSampling" => 0);
510 607  
511   - if (!$tr)
512   - return array("minSampling" => 0,
513   - "maxSampling" => 0);
  608 + $tr = $this->getFirstTR();
514 609  
515   - $prevTime = 0;
516   - while ($tr)
517   - {
518   - $time = $this->getTDValueByFieldIndex($tr,$timeIndex);
  610 + if (!$tr)
  611 + return array("minSampling" => 0,
  612 + "maxSampling" => 0);
519 613  
520   - if ($time)
521   - {
522   - $time = strtotime($time);
523   - if (($prevTime > 0) && ($time-$prevTime > 0))
524   - $deltaT[$time-$prevTime]++;
525   - $prevTime = $time;
526   - }
  614 + $prevTime = 0;
  615 + while ($tr)
  616 + {
  617 + $time = $this->getTDValueByFieldIndex($tr,$timeIndex);
  618 +
  619 + if ($time)
  620 + {
  621 + $time = strtotime($time);
  622 + if (($prevTime > 0) && ($time-$prevTime > 0))
  623 + $deltaT[$time-$prevTime]++;
  624 + $prevTime = $time;
  625 + }
527 626  
528   - $tr = $this->getNextTR($tr);
529   - }
  627 + $tr = $this->getNextTR($tr);
  628 + }
530 629  
531   - $minSampling = +1.e31;
532   - $maxSampling = 0.0;
  630 + $minSampling = +1.e31;
  631 + $maxSampling = 0.0;
533 632  
534   - foreach ($deltaT as $key => $value)
535   - {
  633 + foreach ($deltaT as $key => $value)
  634 + {
536 635  
537   - if ($value/count($deltaT) < 0.10)
538   - continue;
  636 + if ($value/count($deltaT) < 0.10)
  637 + continue;
539 638  
540   - if ($key < $minSampling) $minSampling = $key;
541   - if ($key > $maxSampling) $maxSampling = $key;
542   - }
  639 + if ($key < $minSampling) $minSampling = $key;
  640 + if ($key > $maxSampling) $maxSampling = $key;
  641 + }
543 642  
544   - return array("minSampling" => $minSampling,
545   - "maxSampling" => $maxSampling);
546   - }
  643 + return array("minSampling" => $minSampling,
  644 + "maxSampling" => $maxSampling);
  645 + }
547 646  
548   - public function args2vector($file, $paramID){
  647 + public function args2vector($file, $paramID){
549 648  
550   - $argsArr = explode('_', $paramID);
  649 + $argsArr = explode('_', $paramID);
551 650  
552   - $dom = new DOMDocument();
553   - $dom->load($file);
554   - $fields = $dom->getElementsByTagName('FIELD');
555   - $table = $dom->getElementsByTagName('TABLE')->item(0);
556   - $i=0;
557   - foreach ($fields as $field){
558   - if ($field->getAttribute('name') == $argsArr[0]){
  651 + $dom = new DOMDocument();
  652 + $dom->load($file);
  653 + $fields = $dom->getElementsByTagName('FIELD');
  654 + $table = $dom->getElementsByTagName('TABLE')->item(0);
  655 + $i=0;
  656 + foreach ($fields as $field){
  657 + if ($field->getAttribute('name') == $argsArr[0]){
559 658 $unit = $field->getAttribute('unit');
560   - $ucd = $field->getAttribute('ucd');
561   - $datatype = $field->getAttribute('datatype');
  659 + $ucd = $field->getAttribute('ucd');
  660 + $datatype = $field->getAttribute('datatype');
562 661 $firstTD = $i;
563   - }
564   - $i++;
565   - }
566   - if ($firstTD > 0){
567   - $table->removeChild($fields->item($firstTD + 2));
568   - $table->removeChild($fields->item($firstTD + 1));
569   - $table->removeChild($fields->item($firstTD));
570   -
571   - $i = 0;
572   - foreach ($fields as $field){
  662 + }
  663 + $i++;
  664 + }
  665 + if ($firstTD > 0){
  666 + $table->removeChild($fields->item($firstTD + 2));
  667 + $table->removeChild($fields->item($firstTD + 1));
  668 + $table->removeChild($fields->item($firstTD));
  669 +
  670 + $i = 0;
  671 + foreach ($fields as $field){
573 672 $i++;
574 673 if (strpos($field->getAttribute('ID'),'col') !== FALSE){
575   - $field->setAttribute('ID', 'col'.$i);
576   - $dom->saveXML();
577   - }
578   - }
579   -
580   - $group = $dom->createElement('GROUP');
581   - $group->appendChild(new DOMAttr('ID', 'info_'.$paramID));
582   - $table->appendChild($group);
583   -
584   - $param = $dom->createElement('PARAM');
585   - $param->appendChild(new DOMAttr('ID', 'components_'.$paramID));
586   - $param->appendChild(new DOMAttr('name', 'components_'.$paramID));
587   - $param->appendChild(new DOMAttr('datatype', 'char'));
588   - $param->appendChild(new DOMAttr('arraysize', '*'));
589   - $param->appendChild(new DOMAttr('value', $argsArr[0].' '.$argsArr[1].' '.$argsArr[2] ));
590   - $group->appendChild($param);
591   -
592   - $new_field = $dom->createElement('FIELD');
593   - $new_field->appendChild(new DOMAttr('ID', $paramID));
594   - $new_field->appendChild(new DOMAttr('name', $paramID));
595   - $new_field->appendChild(new DOMAttr('datatype', $datatype));
596   - $new_field->appendChild(new DOMAttr('arraysize', '3'));
597   - $new_field->appendChild(new DOMAttr('unit', $unit));
598   - $new_field->appendChild(new DOMAttr('ucd', $ucd));
599   - $new_field->appendChild(new DOMAttr('ref', 'info_'.$paramID));
600   - $table->appendChild($new_field);
601   -
602   - $trs = $dom->getElementsByTagName('TR');
603   - foreach($trs as $tr){
604   - $tds = $tr->getElementsByTagName('TD');
605   - $value = trim($tds->item($firstTD)->nodeValue).' '.trim($tds->item($firstTD + 1)->nodeValue).' '.trim($tds->item($firstTD + 2)->nodeValue);
606   - $toRemote = $tds->item($firstTD);
607   - $tr->removeChild($toRemote);
608   - $toRemote = $tds->item($firstTD);
609   - $tr->removeChild($toRemote);
610   - $toRemote = $tds->item($firstTD);
611   - $tr->removeChild($toRemote);
612   -
613   - $td = $dom->createElement('TD', $value);
614   - $tr->appendChild($td);
615   - }
616   -
617   - $dom->save($file);
618   - }
619   - }
  674 + $field->setAttribute('ID', 'col'.$i);
  675 + $dom->saveXML();
  676 + }
  677 + }
  678 +
  679 + $group = $dom->createElement('GROUP');
  680 + $group->appendChild(new DOMAttr('ID', 'info_'.$paramID));
  681 + $table->appendChild($group);
  682 +
  683 + $param = $dom->createElement('PARAM');
  684 + $param->appendChild(new DOMAttr('ID', 'components_'.$paramID));
  685 + $param->appendChild(new DOMAttr('name', 'components_'.$paramID));
  686 + $param->appendChild(new DOMAttr('datatype', 'char'));
  687 + $param->appendChild(new DOMAttr('arraysize', '*'));
  688 + $param->appendChild(new DOMAttr('value', $argsArr[0].' '.$argsArr[1].' '.$argsArr[2] ));
  689 + $group->appendChild($param);
  690 +
  691 + $new_field = $dom->createElement('FIELD');
  692 + $new_field->appendChild(new DOMAttr('ID', $paramID));
  693 + $new_field->appendChild(new DOMAttr('name', $paramID));
  694 + $new_field->appendChild(new DOMAttr('datatype', $datatype));
  695 + $new_field->appendChild(new DOMAttr('arraysize', '3'));
  696 + $new_field->appendChild(new DOMAttr('unit', $unit));
  697 + $new_field->appendChild(new DOMAttr('ucd', $ucd));
  698 + $new_field->appendChild(new DOMAttr('ref', 'info_'.$paramID));
  699 + $table->appendChild($new_field);
  700 +
  701 + $trs = $dom->getElementsByTagName('TR');
  702 + foreach($trs as $tr){
  703 + $tds = $tr->getElementsByTagName('TD');
  704 + $value = trim($tds->item($firstTD)->nodeValue).' '.trim($tds->item($firstTD + 1)->nodeValue).' '.trim($tds->item($firstTD + 2)->nodeValue);
  705 + $toRemote = $tds->item($firstTD);
  706 + $tr->removeChild($toRemote);
  707 + $toRemote = $tds->item($firstTD);
  708 + $tr->removeChild($toRemote);
  709 + $toRemote = $tds->item($firstTD);
  710 + $tr->removeChild($toRemote);
  711 +
  712 + $td = $dom->createElement('TD', $value);
  713 + $tr->appendChild($td);
  714 + }
  715 +
  716 + $dom->save($file);
  717 + }
  718 + }
620 719  
621 720 }
622 721  
... ...