Commit 8f6112a77e12e04cdeb211176f04abfbb1a89bdb

Authored by Nathanael Jourdane
1 parent 70880168

Reformat webserver

Showing 1 changed file with 913 additions and 920 deletions   Show diff stats
php/classes/WebServer.php
1 <?php 1 <?php
2 -/**  
3 -* @file WebServer.php  
4 -* @brief Web services AMDA  
5 -*  
6 -* @version $Id: WebServer.php 2968 2015-06-29 13:17:00Z natacha $  
7 -*/ 2 +/**
  3 + * @file WebServer.php
  4 + * @brief Web services AMDA
  5 + *
  6 + * @version $Id: WebServer.php 2968 2015-06-29 13:17:00Z natacha $
  7 + */
8 8
9 class WebResultMgr 9 class WebResultMgr
10 { 10 {
11 - private $resDOM;  
12 - private $rootEl;  
13 - private $resXP;  
14 - private $requestManager = null;  
15 - private $paramLoader = null;  
16 -  
17 - function __construct()  
18 - {  
19 - if (!is_dir(WSRESULT))  
20 - mkdir(WSRESULT);  
21 - chmod(WSRESULT,0775);  
22 -  
23 - $this->resDOM = new DOMDocument("1.0");  
24 - $this->resDOM->formatOutput = TRUE;  
25 - $this->resDOM->preserveWhiteSpace = FALSE;  
26 -  
27 - if (!file_exists(wsResultsXml)) 11 + private $resDOM;
  12 + private $rootEl;
  13 + private $resXP;
  14 + private $requestManager = null;
  15 + private $paramLoader = null;
  16 +
  17 + function __construct()
28 { 18 {
29 - $this->rootEl = $this->resDOM->createElement('wsresults');  
30 - $this->resDOM->appendChild($this->rootEl);  
31 - $this->resDOM->save(wsResultsXml); 19 + if (!is_dir(WSRESULT))
  20 + mkdir(WSRESULT);
  21 + chmod(WSRESULT, 0775);
  22 +
  23 + $this->resDOM = new DOMDocument("1.0");
  24 + $this->resDOM->formatOutput = TRUE;
  25 + $this->resDOM->preserveWhiteSpace = FALSE;
  26 +
  27 + if (!file_exists(wsResultsXml)) {
  28 + $this->rootEl = $this->resDOM->createElement('wsresults');
  29 + $this->resDOM->appendChild($this->rootEl);
  30 + $this->resDOM->save(wsResultsXml);
  31 + }
  32 +
  33 + $this->resDOM->load(wsResultsXml);
  34 +
  35 + $this->resXP = new DOMXPath($this->resDOM);
  36 +
  37 + $this->rootEl = $this->resDOM->documentElement;
32 } 38 }
33 -  
34 - $this->resDOM->load(wsResultsXml);  
35 -  
36 - $this->resXP = new DOMXPath($this->resDOM);  
37 -  
38 - $this->rootEl = $this->resDOM->documentElement;  
39 - }  
40 -  
41 - public function addResult($function_name,$vars,$user,$IP,$output){  
42 - $nodes = $this->rootEl->getElementsByTagName($function_name);  
43 - if($nodes->length < 1){  
44 - $funcNode = $this->resDOM->createElement($function_name);  
45 - $this->rootEl->appendChild($funcNode);  
46 - }  
47 - else  
48 - $funcNode = $nodes->item(0);  
49 -  
50 - $oldOutput = $this->resXP->query('//'.$function_name.'/result[@output="'.$output.'"]');  
51 - if ($oldOutput->length > 0)  
52 - $funcNode->removeChild($oldOutput->item(0));  
53 -  
54 - $resNode = $this->resDOM->createElement('result');  
55 - $resNode->setAttribute('date',time());  
56 - $resNode->setAttribute('user',$user); 39 +
  40 + public function addResult($function_name, $vars, $user, $IP, $output)
  41 + {
  42 + $nodes = $this->rootEl->getElementsByTagName($function_name);
  43 + if ($nodes->length < 1) {
  44 + $funcNode = $this->resDOM->createElement($function_name);
  45 + $this->rootEl->appendChild($funcNode);
  46 + } else
  47 + $funcNode = $nodes->item(0);
  48 +
  49 + $oldOutput = $this->resXP->query('//' . $function_name . '/result[@output="' . $output . '"]');
  50 + if ($oldOutput->length > 0)
  51 + $funcNode->removeChild($oldOutput->item(0));
  52 +
  53 + $resNode = $this->resDOM->createElement('result');
  54 + $resNode->setAttribute('date', time());
  55 + $resNode->setAttribute('user', $user);
57 // $resNode->setAttribute('IP',$IP); 56 // $resNode->setAttribute('IP',$IP);
58 - $resNode->setAttribute('input',json_encode($vars));  
59 - $resNode->setAttribute('output',$output);  
60 - $funcNode->appendChild($resNode);  
61 -  
62 - $this->resDOM->save(wsResultsXml);  
63 -  
64 - return $resNode;  
65 - }  
66 -  
67 - public function getResOutputName($function_name,$user,$suffixe,$extension)  
68 - {  
69 - $outputFile = WSRESULT.$function_name."_".$user;  
70 - if (isset($suffixe))  
71 - $outputFile .= ("_".$suffixe);  
72 - if (isset($extension))  
73 - $outputFile .= (".".$extension);  
74 - else  
75 - $outputFile .= ".xml";  
76 - return $outputFile;  
77 - } 57 + $resNode->setAttribute('input', json_encode($vars));
  58 + $resNode->setAttribute('output', $output);
  59 + $funcNode->appendChild($resNode);
  60 +
  61 + $this->resDOM->save(wsResultsXml);
  62 +
  63 + return $resNode;
  64 + }
  65 +
  66 + public function getResOutputName($function_name, $user, $suffixe, $extension)
  67 + {
  68 + $outputFile = WSRESULT . $function_name . "_" . $user;
  69 + if (isset($suffixe))
  70 + $outputFile .= ("_" . $suffixe);
  71 + if (isset($extension))
  72 + $outputFile .= ("." . $extension);
  73 + else
  74 + $outputFile .= ".xml";
  75 + return $outputFile;
  76 + }
78 } 77 }
79 78
80 class WebServer 79 class WebServer
81 { 80 {
82 - private $isSoap = false;  
83 - private $userID, $userPWD, $sessionID;  
84 - private $wsUserMgr;  
85 - private $resultMgr, $myParamsInfoMgr;  
86 - private $dataFileName;  
87 -  
88 - function __construct() {  
89 - $this->userID = 'impex';  
90 - $this->userPWD = 'impexfp7';  
91 - $this->sessionID = $this->userID;  
92 - $this->myParamsInfoMgr = new ParamsInfoMgr();  
93 - $this->resultMgr = new WebResultMgr();  
94 - }  
95 -  
96 - protected function init($data) {  
97 - if(is_object($data)) 81 + private $isSoap = false;
  82 + private $userID, $userPWD, $sessionID;
  83 + private $wsUserMgr;
  84 + private $resultMgr, $myParamsInfoMgr;
  85 + private $dataFileName;
  86 +
  87 + function __construct()
98 { 88 {
99 - $vars = get_object_vars($data);  
100 - $this->isSoap = true; 89 + $this->userID = 'impex';
  90 + $this->userPWD = 'impexfp7';
  91 + $this->sessionID = $this->userID;
  92 + $this->myParamsInfoMgr = new ParamsInfoMgr();
  93 + $this->resultMgr = new WebResultMgr();
101 } 94 }
102 - else  
103 - $vars = $data;  
104 95
105 - if (isset($vars['userID'])) 96 + protected function init($data)
106 { 97 {
107 - $this->userID = $vars['userID'];  
108 - $this->sessionID = $this->userID; 98 + if (is_object($data)) {
  99 + $vars = get_object_vars($data);
  100 + $this->isSoap = true;
  101 + } else
  102 + $vars = $data;
  103 +
  104 + if (isset($vars['userID'])) {
  105 + $this->userID = $vars['userID'];
  106 + $this->sessionID = $this->userID;
  107 + } else {
  108 + $this->userID = 'impex';
  109 + $this->sessionID = $this->userID;
  110 + }
  111 + if (isset($vars['password']))
  112 + $this->userPWD = $vars['password'];
  113 + else
  114 + $this->userPWD = 'impexfp7';
  115 + return array('success' => true, 'vars' => $vars);
109 } 116 }
110 - else {  
111 - $this->userID = 'impex';  
112 - $this->sessionID = $this->userID; 117 +
  118 + private function setID()
  119 + {
  120 +
  121 + $nb_min = 10000;
  122 + $nb_max = 99999;
  123 + $nombre = mt_rand($nb_min, $nb_max);
  124 +
  125 + $this->IP = $this->getIPclient();
  126 +
  127 + return "PP" . $nombre;
113 } 128 }
114 - if (isset($vars['password']))  
115 - $this->userPWD = $vars['password'];  
116 - else  
117 - $this->userPWD = 'impexfp7';  
118 - return array('success' => true, 'vars' => $vars);  
119 - }  
120 129
121 - private function setID(){ 130 + /**
  131 + * Function getIPclient return the IP client sent a request for needs DD scripts (DDHtmlLogin, DDCheckUser, DD_Search)
  132 + *
  133 + * @param void
  134 + * @return string
  135 + */
  136 + private function getIPclient()
  137 + {
122 138
123 - $nb_min = 10000;  
124 - $nb_max = 99999;  
125 - $nombre = mt_rand($nb_min,$nb_max); 139 + if (getenv('REMOTE_ADDR')) {
  140 + $realIP = getenv('REMOTE_ADDR');
  141 + } else {
  142 + //get local IP
  143 + $command = "hostname -i";
  144 + $realIP = exec($command);
  145 + }
126 146
127 - $this->IP = $this->getIPclient(); 147 + return $realIP;
  148 + }
128 149
129 - return "PP".$nombre;  
130 - } 150 + private function timeInterval2Days($TimeInterval)
  151 + {
131 152
132 -/**  
133 - * Function getIPclient return the IP client sent a request for needs DD scripts (DDHtmlLogin, DDCheckUser, DD_Search)  
134 - *  
135 - * @param void  
136 - * @return string  
137 - */  
138 - private function getIPclient(){  
139 -  
140 - if (getenv('REMOTE_ADDR')) {  
141 - $realIP = getenv('REMOTE_ADDR');  
142 - }  
143 - else {  
144 - //get local IP  
145 - $command="hostname -i";  
146 - $realIP = exec($command);  
147 - }  
148 -  
149 - return $realIP;  
150 - }  
151 -  
152 - private function timeInterval2Days($TimeInterval){  
153 -  
154 - $divDays = 60*60*24; 153 + $divDays = 60 * 60 * 24;
155 $nbDays = floor($TimeInterval / $divDays); 154 $nbDays = floor($TimeInterval / $divDays);
156 - $divHours = 60*60;  
157 - $nbHours = floor(($TimeInterval - $divDays*$nbDays)/$divHours);  
158 - $nbMin = floor(($TimeInterval - $divDays*$nbDays - $divHours*$nbHours)/60);  
159 - $nbSec = $TimeInterval - $divDays*$nbDays - $divHours*$nbHours - $nbMin*60; 155 + $divHours = 60 * 60;
  156 + $nbHours = floor(($TimeInterval - $divDays * $nbDays) / $divHours);
  157 + $nbMin = floor(($TimeInterval - $divDays * $nbDays - $divHours * $nbHours) / 60);
  158 + $nbSec = $TimeInterval - $divDays * $nbDays - $divHours * $nbHours - $nbMin * 60;
160 159
161 - $DD = sprintf("%03d", $nbDays); // format ex. 005 not 5  
162 - $HH = sprintf("%02d", $nbHours); // format ex. 25  
163 - $MM = sprintf("%02d", $nbMin); // format ex. 03 not 3  
164 - $SS = sprintf("%02d", $nbSec); // format ex. 02 not 2 160 + $DD = sprintf("%03d", $nbDays); // format ex. 005 not 5
  161 + $HH = sprintf("%02d", $nbHours); // format ex. 25
  162 + $MM = sprintf("%02d", $nbMin); // format ex. 03 not 3
  163 + $SS = sprintf("%02d", $nbSec); // format ex. 02 not 2
165 164
166 - return $DD.':'.$HH.':'.$MM.':'.$SS; 165 + return $DD . ':' . $HH . ':' . $MM . ':' . $SS;
167 166
168 } 167 }
169 168
170 -/* Start Time into AMDA format YYYY:DOY-1:HH:MM:SS */  
171 - private function startTime2Days($startTime){ 169 + /* Start Time into AMDA format YYYY:DOY-1:HH:MM:SS */
  170 + private function startTime2Days($startTime)
  171 + {
172 172
173 - $ddStart = getdate($startTime);  
174 - $date_start = sprintf("%04d",$ddStart["year"]).":".sprintf("%03d", $ddStart["yday"]).":"  
175 - .sprintf("%02d",$ddStart["hours"]).":".sprintf("%02d",$ddStart["minutes"]).":"  
176 - .sprintf("%02d",$ddStart["seconds"]); 173 + $ddStart = getdate($startTime);
  174 + $date_start = sprintf("%04d", $ddStart["year"]) . ":" . sprintf("%03d", $ddStart["yday"]) . ":"
  175 + . sprintf("%02d", $ddStart["hours"]) . ":" . sprintf("%02d", $ddStart["minutes"]) . ":"
  176 + . sprintf("%02d", $ddStart["seconds"]);
177 return $date_start; 177 return $date_start;
178 } 178 }
179 179
180 - private function rrmdir($dir){  
181 - if (is_dir($dir)) {  
182 - $objects = scandir($dir);  
183 -  
184 - foreach ($objects as $object) { // Recursively delete a directory that is not empty and directorys in directory  
185 - if ($object != "." && $object != "..") { // If object isn't a directory recall recursively this function  
186 - if (filetype($dir."/".$object) == "dir")  
187 - $this->rrmdir($dir."/".$object);  
188 - else  
189 - unlink($dir."/".$object);  
190 - } 180 + private function rrmdir($dir)
  181 + {
  182 + if (is_dir($dir)) {
  183 + $objects = scandir($dir);
  184 +
  185 + foreach ($objects as $object) { // Recursively delete a directory that is not empty and directorys in directory
  186 + if ($object != "." && $object != "..") { // If object isn't a directory recall recursively this function
  187 + if (filetype($dir . "/" . $object) == "dir")
  188 + $this->rrmdir($dir . "/" . $object);
  189 + else
  190 + unlink($dir . "/" . $object);
  191 + }
  192 + }
  193 + reset($objects);
  194 + rmdir($dir);
191 } 195 }
192 - reset($objects);  
193 - rmdir($dir);  
194 - }  
195 } 196 }
196 197
197 - protected function initUserMgr() {  
198 - if (isset($this->wsUserMgr))  
199 - return array('success' => true);  
200 - $this->wsUserMgr = new WSUserMgr();  
201 - $this->wsUserMgr->init($this->userID,$this->userPWD,$this->sessionID, $this->isSoap);  
202 -  
203 - return array('success' => true);  
204 - }  
205 -  
206 - public function getTimeTablesList($data) {  
207 - if(is_object($data)) 198 + protected function initUserMgr()
208 { 199 {
209 - $vars = get_object_vars($data);  
210 - $this->isSoap = true;  
211 - }  
212 - else  
213 - $vars = $data;  
214 - if (isset($vars['userID']) && $vars['userID'] == 'impex'){  
215 - if ($this->isSoap) throw new SoapFault("server00","Server Error: AMDA Login procedure failed");  
216 - else return array("error" => "Server Error: AMDA Login procedure failed");  
217 - }  
218 -  
219 -  
220 - $res = $this->init($data);  
221 - $vars = $res['vars'];  
222 -  
223 - $ttListWSresult = $this->resultMgr->getResOutputName(__FUNCTION__,$this->userID);  
224 -  
225 - $dom = new DOMDocument("1.0");  
226 - if ($this->userID == 'impex') {  
227 - $sharedObjMgr = new SharedObjectsMgr();  
228 - $loadDom = $dom->load($sharedObjMgr->getTreeFilePath());  
229 - }  
230 - else  
231 - $loadDom = $dom->load(USERPATH.$this->userID.'/WS/Tt.xml');  
232 -  
233 - if ($loadDom == FALSE){  
234 - if ($this->isSoap) throw new SoapFault("server00","Server Error: AMDA Login procedure failed");  
235 - else return array("error" => "Server Error: AMDA Login procedure failed");  
236 - }  
237 -  
238 - $timetabNode = $dom->documentElement->getElementsByTagName('timetabList'); 200 + if (isset($this->wsUserMgr))
  201 + return array('success' => true);
  202 + $this->wsUserMgr = new WSUserMgr();
  203 + $this->wsUserMgr->init($this->userID, $this->userPWD, $this->sessionID, $this->isSoap);
239 204
240 - if ($timetabNode->length < 1){  
241 - if ($this->isSoap) throw new SoapFault("server03","Cannot reach TT list");  
242 - else return array('success' => false, 'message' => "Server Error: Cannot reach TT list"); 205 + return array('success' => true);
243 } 206 }
244 - $outDOM = new DOMDocument("1.0");  
245 - $outDOM->formatOutput = TRUE;  
246 - $outDOM->preserveWhiteSpace = FALSE;  
247 -  
248 - $newNode = $outDOM->importNode($timetabNode->item(0),TRUE);  
249 - $outDOM->appendChild($newNode);  
250 -  
251 207
252 - $outXP = new domxpath($outDOM);  
253 - $ttNodes = $outXP->query('//timetab'); 208 + public function getTimeTablesList($data)
  209 + {
  210 + if (is_object($data)) {
  211 + $vars = get_object_vars($data);
  212 + $this->isSoap = true;
  213 + } else
  214 + $vars = $data;
  215 + if (isset($vars['userID']) && $vars['userID'] == 'impex') {
  216 + if ($this->isSoap) throw new SoapFault("server00", "Server Error: AMDA Login procedure failed");
  217 + else return array("error" => "Server Error: AMDA Login procedure failed");
  218 + }
254 219
255 - $outDOM->save($ttListWSresult);  
256 220
257 - $wsres = $this->resultMgr->addResult(__FUNCTION__,$vars,$this->userID,$ttListWSresult); 221 + $res = $this->init($data);
  222 + $vars = $res['vars'];
258 223
259 - $ttListResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$ttListWSresult); 224 + $ttListWSresult = $this->resultMgr->getResOutputName(__FUNCTION__, $this->userID);
260 225
261 - $timeTablesList = array('success' => true, 'TimeTablesList' => $ttListResult); 226 + $dom = new DOMDocument("1.0");
  227 + if ($this->userID == 'impex') {
  228 + $sharedObjMgr = new SharedObjectsMgr();
  229 + $loadDom = $dom->load($sharedObjMgr->getTreeFilePath());
  230 + } else
  231 + $loadDom = $dom->load(USERPATH . $this->userID . '/WS/Tt.xml');
262 232
263 - return $timeTablesList; 233 + if ($loadDom == FALSE) {
  234 + if ($this->isSoap) throw new SoapFault("server00", "Server Error: AMDA Login procedure failed");
  235 + else return array("error" => "Server Error: AMDA Login procedure failed");
  236 + }
264 237
265 - } 238 + $timetabNode = $dom->documentElement->getElementsByTagName('timetabList');
266 239
267 - public function getTimeTable($data) {  
268 - $res = $this->init($data); 240 + if ($timetabNode->length < 1) {
  241 + if ($this->isSoap) throw new SoapFault("server03", "Cannot reach TT list");
  242 + else return array('success' => false, 'message' => "Server Error: Cannot reach TT list");
  243 + }
  244 + $outDOM = new DOMDocument("1.0");
  245 + $outDOM->formatOutput = TRUE;
  246 + $outDOM->preserveWhiteSpace = FALSE;
269 247
270 - $vars = $res['vars'];  
271 - $ttID = $vars['ttID']; 248 + $newNode = $outDOM->importNode($timetabNode->item(0), TRUE);
  249 + $outDOM->appendChild($newNode);
272 250
273 - if ($this->userID == 'impex') {  
274 - $sharedObjMgr = new SharedObjectsMgr();  
275 - $ttSrc = $sharedObjMgr->getDataFilePath('timeTable', $ttID);  
276 - }  
277 - else  
278 - $ttSrc = USERPATH.$this->userID.'/TT/'.$ttID.'.xml';  
279 251
280 - if (!file_exists($ttSrc)) {  
281 - if ($this->isSoap) throw new SoapFault("server03","Cannot reach time table");  
282 - else return array('success' => false, 'message' => "Cannot reach time table"); 252 + $outXP = new domxpath($outDOM);
  253 + $ttNodes = $outXP->query('//timetab');
  254 +
  255 + $outDOM->save($ttListWSresult);
  256 +
  257 + $wsres = $this->resultMgr->addResult(__FUNCTION__, $vars, $this->userID, $ttListWSresult);
  258 +
  259 + $ttListResult = 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $ttListWSresult);
  260 +
  261 + $timeTablesList = array('success' => true, 'TimeTablesList' => $ttListResult);
  262 +
  263 + return $timeTablesList;
  264 +
283 } 265 }
284 266
285 - $ttWSresult = $this->resultMgr->getResOutputName(__FUNCTION__,$this->userID,$ttID); 267 + public function getTimeTable($data)
  268 + {
  269 + $res = $this->init($data);
  270 +
  271 + $vars = $res['vars'];
  272 + $ttID = $vars['ttID'];
  273 +
  274 + if ($this->userID == 'impex') {
  275 + $sharedObjMgr = new SharedObjectsMgr();
  276 + $ttSrc = $sharedObjMgr->getDataFilePath('timeTable', $ttID);
  277 + } else
  278 + $ttSrc = USERPATH . $this->userID . '/TT/' . $ttID . '.xml';
  279 +
  280 + if (!file_exists($ttSrc)) {
  281 + if ($this->isSoap) throw new SoapFault("server03", "Cannot reach time table");
  282 + else return array('success' => false, 'message' => "Cannot reach time table");
  283 + }
  284 +
  285 + $ttWSresult = $this->resultMgr->getResOutputName(__FUNCTION__, $this->userID, $ttID);
  286 +
  287 + if (!copy($ttSrc, $ttWSresult)) {
  288 + if ($this->isSoap) throw new SoapFault("server04", "Cannot copy time table");
  289 + else return array('success' => false, 'message' => "Cannot copy time table");
  290 + }
  291 +
  292 + $wsres = $this->resultMgr->addResult(__FUNCTION__, $vars, $this->userID, $ttWSresult);
  293 +
  294 + $myTimeTableMgr = new TimeTableMgr($this->userID);
  295 + $ttWSresultVot = $myTimeTableMgr->xsl2vot($ttWSresult);
  296 + if (file_exists($ttWSresultVot)) {
  297 + copy($ttWSresultVot, $ttWSresult);
  298 + unlink($ttWSresultVot);
  299 + }
  300 + return array('success' => true, 'ttFileURL' => 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $ttWSresult));
286 301
287 - if (!copy($ttSrc,$ttWSresult)){  
288 - if ($this->isSoap) throw new SoapFault("server04","Cannot copy time table");  
289 - else return array('success' => false, 'message' => "Cannot copy time table");  
290 } 302 }
291 -  
292 - $wsres = $this->resultMgr->addResult(__FUNCTION__,$vars,$this->userID, $ttWSresult);  
293 -  
294 - $myTimeTableMgr = new TimeTableMgr($this->userID);  
295 - $ttWSresultVot = $myTimeTableMgr->xsl2vot($ttWSresult);  
296 - if( file_exists ( $ttWSresultVot)){  
297 - copy($ttWSresultVot, $ttWSresult);  
298 - unlink( $ttWSresultVot ) ; 303 +
  304 +
  305 + public function isAlive()
  306 + {
  307 + $res = $this->init($data);
  308 + return true;
299 } 309 }
300 - return array('success' => true, 'ttFileURL' => 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$ttWSresult));  
301 -  
302 - }  
303 -  
304 -  
305 - public function isAlive(){  
306 - $res = $this->init($data);  
307 - return true;  
308 - }  
309 -  
310 -  
311 - public function getObsDataTree() {  
312 -  
313 - $res = $this->init();  
314 -  
315 - $resMgr = $this->initUserMgr();  
316 -  
317 - $vars = $res['vars'];  
318 -  
319 - $locParamSrc = USERPATH.$this->userID.'/WS/LocalParams.xml'; 310 +
  311 +
  312 + public function getObsDataTree()
  313 + {
  314 +
  315 + $res = $this->init();
  316 +
  317 + $resMgr = $this->initUserMgr();
  318 +
  319 + $vars = $res['vars'];
  320 +
  321 + $locParamSrc = USERPATH . $this->userID . '/WS/LocalParams.xml';
320 // $remoteParamSrc = USERPATH.$this->userID.'/WS/RemoteParams.xml'; 322 // $remoteParamSrc = USERPATH.$this->userID.'/WS/RemoteParams.xml';
321 - $wsParamSrc = USERPATH.$this->userID.'/WS/WsParams.xml';  
322 - $locParamResult = $this->resultMgr->getResOutputName(__FUNCTION__,$this->userID.'_'.'LocalParams'); 323 + $wsParamSrc = USERPATH . $this->userID . '/WS/WsParams.xml';
  324 + $locParamResult = $this->resultMgr->getResOutputName(__FUNCTION__, $this->userID . '_' . 'LocalParams');
323 // $remoteParamResult = $this->resultMgr->getResOutputName(__FUNCTION__,'RemoteParams'); 325 // $remoteParamResult = $this->resultMgr->getResOutputName(__FUNCTION__,'RemoteParams');
324 - $wsParamResult = $this->resultMgr->getResOutputName(__FUNCTION__,$this->userID.'_'.'WsParams');  
325 -  
326 - if (!copy($locParamSrc,$locParamResult))  
327 - $locParamResult = '';  
328 - else {  
329 - $piBase = new DomDocument("1.0");  
330 - $piBase->formatOutput = true;  
331 - $piBase->preserveWhiteSpace = false;  
332 -  
333 - $dom = new DomDocument("1.0");  
334 - $dom->load($locParamResult);  
335 -  
336 - $xsl = new DomDocument("1.0");  
337 - $xsl->load(XMLPATH.'dd2WStree.xsl');  
338 -  
339 - $xslt = new XSLTProcessor();  
340 - $xslt->importStylesheet($xsl);  
341 -  
342 - $dom->loadXML($xslt->transformToXML($dom));  
343 -  
344 - $dom->formatOutput = true;  
345 - $dom->preserveWhiteSpace = false;  
346 - $chum_ger = $dom->getElementById("Rosetta@C-G : Plot Only!");  
347 - if ($chum_ger != NULL) $chum_ger->setAttribute("target","Churyumov-Gerasimenko");  
348 -  
349 - $dom->save($locParamResult);  
350 - } 326 + $wsParamResult = $this->resultMgr->getResOutputName(__FUNCTION__, $this->userID . '_' . 'WsParams');
  327 +
  328 + if (!copy($locParamSrc, $locParamResult))
  329 + $locParamResult = '';
  330 + else {
  331 + $piBase = new DomDocument("1.0");
  332 + $piBase->formatOutput = true;
  333 + $piBase->preserveWhiteSpace = false;
  334 +
  335 + $dom = new DomDocument("1.0");
  336 + $dom->load($locParamResult);
  337 +
  338 + $xsl = new DomDocument("1.0");
  339 + $xsl->load(XMLPATH . 'dd2WStree.xsl');
  340 +
  341 + $xslt = new XSLTProcessor();
  342 + $xslt->importStylesheet($xsl);
  343 +
  344 + $dom->loadXML($xslt->transformToXML($dom));
  345 +
  346 + $dom->formatOutput = true;
  347 + $dom->preserveWhiteSpace = false;
  348 + $chum_ger = $dom->getElementById("Rosetta@C-G : Plot Only!");
  349 + if ($chum_ger != NULL) $chum_ger->setAttribute("target", "Churyumov-Gerasimenko");
  350 +
  351 + $dom->save($locParamResult);
  352 + }
351 // if (!copy($remoteParamSrc,$remoteParamResult)) 353 // if (!copy($remoteParamSrc,$remoteParamResult))
352 // $remoteParamResult = ''; 354 // $remoteParamResult = '';
353 - if (!copy($wsParamSrc,$wsParamResult))  
354 - $wsParamResult = '';  
355 -  
356 - if ($locParamResult !='') $locParamResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$locParamResult); 355 + if (!copy($wsParamSrc, $wsParamResult))
  356 + $wsParamResult = '';
  357 +
  358 + if ($locParamResult != '') $locParamResult = 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $locParamResult);
357 // if ($remoteParamResult !='') $remoteParamResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$remoteParamResult); 359 // if ($remoteParamResult !='') $remoteParamResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$remoteParamResult);
358 - if ($wsParamResult !='') $wsParamResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$wsParamResult);  
359 -  
360 - if (($locParamResult =='') && ($remoteParamResult =='') && ($wsParamResult =='')){  
361 - if ($this->isSoap) throw new SoapFault("server05","No params descriptions .xml files for ".$this->userID." user");  
362 - else return array('success' => false, 'message' => "No params descriptions .xml files for ".$this->userID." user");  
363 - }  
364 -  
365 - $wsres = $this->resultMgr->addResult(__FUNCTION__,$vars,$this->userID,$wsParamResult.";".$locParamResult.";".$remoteParamResult);  
366 -  
367 - return array('success' => true,'WorkSpace' => array("LocalDataBaseParameters"=>$locParamResult, "RemoteDataBaseParameters"=>$remoteParamResult));  
368 - }  
369 -  
370 - public function getPlot($data) {  
371 -  
372 - $res = $this->init($data);  
373 - $resMgr = $this->initUserMgr();  
374 -  
375 - $vars = $res['vars'];  
376 - $mission = $vars["missionID"];  
377 -  
378 - $ID = $this->setID(); // unique JobID  
379 - $resDirName = WSRESULT.$ID; // Define a temporary directory for results  
380 -  
381 - if (is_dir($resDirName))  
382 - $this->rrmdir($resDirName);  
383 - mkdir($resDirName);  
384 - chmod($resDirName,0775);  
385 -  
386 - $dom = new DomDocument("1.0");  
387 - $dom->load(plotsXml);  
388 -  
389 - $missionTag = $dom->getElementById($mission);  
390 - $params = $missionTag->getElementsByTagName('param');  
391 -  
392 - $paramsList = array();  
393 - foreach ($params as $param)  
394 - $paramsList[] = $param->getAttribute('name');  
395 -  
396 - $requestObject = (Object) array(  
397 - "nodeType" => "request",  
398 - "file-format" => "PNG",  
399 - "file-output" => "WS",  
400 - "ws-result-file" => $resDirName."/request.list.png",  
401 - "last-plotted-tab" => 1,  
402 - "timesrc" => "Interval",  
403 - "startDate" => $vars["startTime"],  
404 - "stopDate" => $vars["stopTime"],  
405 - "tabs" => array()  
406 - );  
407 -  
408 - $pageObject = (Object) array(  
409 - "id" => 1,  
410 - "multi-plot-linked" => true,  
411 - "page-margins-activated" => true,  
412 - "page-margin-x" => 5,  
413 - "page-margin-y" => 5,  
414 - "page-orientation" => "portrait",  
415 - "page-dimension" => "ISO A4",  
416 - "page-layout-type" => "vertical",  
417 - "page-layout-object" => (Object) array(  
418 - "layout-panel-height" => 0.25,  
419 - "layout-panel-spacing" => 0,  
420 - "layout-expand" => false  
421 - ),  
422 - "panels" => array()  
423 - );  
424 -  
425 - foreach ($paramsList as $paramToPlot)  
426 - {  
427 - $panelObject = (Object) array(  
428 - "panel-plot-type" => "timePlot",  
429 - "axes" => array(),  
430 - "params" => array()  
431 - );  
432 -  
433 - $timeAxisObject = (Object) array(  
434 - "id" => "time",  
435 - "axis-type" => "time",  
436 - "axis-range-extend" => true  
437 - );  
438 - $panelObject->{"axes"}[] = $timeAxisObject;  
439 -  
440 - $yAxisObject = (Object) array(  
441 - "id" => "y-left",  
442 - "axis-type" => "y-left",  
443 - "axis-range-extend" => true  
444 - );  
445 - $panelObject->{"axes"}[] = $yAxisObject;  
446 -  
447 - $paramObject = (Object) array(  
448 - "id" => 1,  
449 - "param-id" => $paramToPlot,  
450 - "param-drawing-type" => "serie",  
451 - "param-drawing-object" => (Object) array(  
452 - "serie-yaxis" => "y-left",  
453 - "serie-lines-activated" => true  
454 - )  
455 - );  
456 - $panelObject->{"params"}[] = $paramObject;  
457 -  
458 - $pageObject->{"panels"}[] = $panelObject; 360 + if ($wsParamResult != '') $wsParamResult = 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $wsParamResult);
  361 +
  362 + if (($locParamResult == '') && ($remoteParamResult == '') && ($wsParamResult == '')) {
  363 + if ($this->isSoap) throw new SoapFault("server05", "No params descriptions .xml files for " . $this->userID . " user");
  364 + else return array('success' => false, 'message' => "No params descriptions .xml files for " . $this->userID . " user");
  365 + }
  366 +
  367 + $wsres = $this->resultMgr->addResult(__FUNCTION__, $vars, $this->userID, $wsParamResult . ";" . $locParamResult . ";" . $remoteParamResult);
  368 +
  369 + return array('success' => true, 'WorkSpace' => array("LocalDataBaseParameters" => $locParamResult, "RemoteDataBaseParameters" => $remoteParamResult));
459 } 370 }
460 -  
461 - $requestObject->{"tabs"}[] = $pageObject;  
462 -  
463 - require_once(INTEGRATION_SRC_DIR."RequestManager.php");  
464 - if (!isset($this->requestManager))  
465 - $this->requestManager = new RequestManagerClass();  
466 -  
467 - try {  
468 - $plotResult = $this->requestManager->runIHMRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PARAMS, $requestObject);  
469 - } catch (Exception $e) {  
470 - if ($this->isSoap) throw new SoapFault("plot01", 'Exception detected : '.$e->getMessage());  
471 - else return array('success' => false, 'message' => 'Exception detected : '.$e->getMessage()); 371 +
  372 + public function getPlot($data)
  373 + {
  374 +
  375 + $res = $this->init($data);
  376 + $resMgr = $this->initUserMgr();
  377 +
  378 + $vars = $res['vars'];
  379 + $mission = $vars["missionID"];
  380 +
  381 + $ID = $this->setID(); // unique JobID
  382 + $resDirName = WSRESULT . $ID; // Define a temporary directory for results
  383 +
  384 + if (is_dir($resDirName))
  385 + $this->rrmdir($resDirName);
  386 + mkdir($resDirName);
  387 + chmod($resDirName, 0775);
  388 +
  389 + $dom = new DomDocument("1.0");
  390 + $dom->load(plotsXml);
  391 +
  392 + $missionTag = $dom->getElementById($mission);
  393 + $params = $missionTag->getElementsByTagName('param');
  394 +
  395 + $paramsList = array();
  396 + foreach ($params as $param)
  397 + $paramsList[] = $param->getAttribute('name');
  398 +
  399 + $requestObject = (Object)array(
  400 + "nodeType" => "request",
  401 + "file-format" => "PNG",
  402 + "file-output" => "WS",
  403 + "ws-result-file" => $resDirName . "/request.list.png",
  404 + "last-plotted-tab" => 1,
  405 + "timesrc" => "Interval",
  406 + "startDate" => $vars["startTime"],
  407 + "stopDate" => $vars["stopTime"],
  408 + "tabs" => array()
  409 + );
  410 +
  411 + $pageObject = (Object)array(
  412 + "id" => 1,
  413 + "multi-plot-linked" => true,
  414 + "page-margins-activated" => true,
  415 + "page-margin-x" => 5,
  416 + "page-margin-y" => 5,
  417 + "page-orientation" => "portrait",
  418 + "page-dimension" => "ISO A4",
  419 + "page-layout-type" => "vertical",
  420 + "page-layout-object" => (Object)array(
  421 + "layout-panel-height" => 0.25,
  422 + "layout-panel-spacing" => 0,
  423 + "layout-expand" => false
  424 + ),
  425 + "panels" => array()
  426 + );
  427 +
  428 + foreach ($paramsList as $paramToPlot) {
  429 + $panelObject = (Object)array(
  430 + "panel-plot-type" => "timePlot",
  431 + "axes" => array(),
  432 + "params" => array()
  433 + );
  434 +
  435 + $timeAxisObject = (Object)array(
  436 + "id" => "time",
  437 + "axis-type" => "time",
  438 + "axis-range-extend" => true
  439 + );
  440 + $panelObject->{"axes"}[] = $timeAxisObject;
  441 +
  442 + $yAxisObject = (Object)array(
  443 + "id" => "y-left",
  444 + "axis-type" => "y-left",
  445 + "axis-range-extend" => true
  446 + );
  447 + $panelObject->{"axes"}[] = $yAxisObject;
  448 +
  449 + $paramObject = (Object)array(
  450 + "id" => 1,
  451 + "param-id" => $paramToPlot,
  452 + "param-drawing-type" => "serie",
  453 + "param-drawing-object" => (Object)array(
  454 + "serie-yaxis" => "y-left",
  455 + "serie-lines-activated" => true
  456 + )
  457 + );
  458 + $panelObject->{"params"}[] = $paramObject;
  459 +
  460 + $pageObject->{"panels"}[] = $panelObject;
  461 + }
  462 +
  463 + $requestObject->{"tabs"}[] = $pageObject;
  464 +
  465 + require_once(INTEGRATION_SRC_DIR . "RequestManager.php");
  466 + if (!isset($this->requestManager))
  467 + $this->requestManager = new RequestManagerClass();
  468 +
  469 + try {
  470 + $plotResult = $this->requestManager->runIHMRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PARAMS, $requestObject);
  471 + } catch (Exception $e) {
  472 + if ($this->isSoap) throw new SoapFault("plot01", 'Exception detected : ' . $e->getMessage());
  473 + else return array('success' => false, 'message' => 'Exception detected : ' . $e->getMessage());
  474 + }
  475 +
  476 + return array('success' => true, 'plotDirectoryURL' => $ID);
472 } 477 }
473 478
474 - return array('success' => true, 'plotDirectoryURL' => $ID);  
475 - }  
476 -  
477 - public function getResultPlot($data) {  
478 -  
479 - $res = $this->init($data);  
480 - $vars = $res['vars'];  
481 - $ID = $vars["plotDirectoryURL"];  
482 - $filename = WSRESULT.$ID."/request.list.png";  
483 - if (file_exists($filename)) {  
484 - $plotWSresult=WSRESULT.$ID."/request.list.png";  
485 - return array('success' => true, 'plotFileURL' => 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$plotWSresult)); 479 + public function getResultPlot($data)
  480 + {
  481 +
  482 + $res = $this->init($data);
  483 + $vars = $res['vars'];
  484 + $ID = $vars["plotDirectoryURL"];
  485 + $filename = WSRESULT . $ID . "/request.list.png";
  486 + if (file_exists($filename)) {
  487 + $plotWSresult = WSRESULT . $ID . "/request.list.png";
  488 + return array('success' => true, 'plotFileURL' => 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $plotWSresult));
  489 + } else
  490 + return array('success' => false);
  491 +
486 } 492 }
487 - else  
488 - return array('success' => false);  
489 493
490 - }  
491 494
  495 + public function getParameterList($data)
  496 + {
  497 +
  498 + $res = $this->init($data);
492 499
493 - public function getParameterList($data) {  
494 -  
495 - $res = $this->init($data);  
496 -  
497 - $resMgr = $this->initUserMgr(); 500 + $resMgr = $this->initUserMgr();
498 501
499 - $vars = $res['vars']; 502 + $vars = $res['vars'];
500 503
501 - $locParamSrc = USERPATH.$this->userID.'/WS/LocalParams.xml'; 504 + $locParamSrc = USERPATH . $this->userID . '/WS/LocalParams.xml';
502 // $remoteParamSrc = USERPATH.$this->userID.'/WS/RemoteParams.xml'; 505 // $remoteParamSrc = USERPATH.$this->userID.'/WS/RemoteParams.xml';
503 - $wsParamSrc = USERPATH.$this->userID.'/WS/WsParams.xml';  
504 - $locParamResult = $this->resultMgr->getResOutputName(__FUNCTION__,$this->userID.'_'.'LocalParams'); 506 + $wsParamSrc = USERPATH . $this->userID . '/WS/WsParams.xml';
  507 + $locParamResult = $this->resultMgr->getResOutputName(__FUNCTION__, $this->userID . '_' . 'LocalParams');
505 // $remoteParamResult = $this->resultMgr->getResOutputName(__FUNCTION__,'RemoteParams'); 508 // $remoteParamResult = $this->resultMgr->getResOutputName(__FUNCTION__,'RemoteParams');
506 - $wsParamResult = $this->resultMgr->getResOutputName(__FUNCTION__,$this->userID.'_'.'WsParams');  
507 -  
508 - if (!copy($locParamSrc,$locParamResult))  
509 - $locParamResult = '';  
510 - else {  
511 - $piBase = new DomDocument("1.0");  
512 - $piBase->formatOutput = true;  
513 - $piBase->preserveWhiteSpace = false;  
514 -  
515 - $dom = new DomDocument("1.0");  
516 - $dom->load($locParamResult);  
517 -  
518 - $xsl = new DomDocument("1.0");  
519 - $xsl->load(XMLPATH.'dd2WStree.xsl');  
520 -  
521 - $xslt = new XSLTProcessor();  
522 - $xslt->importStylesheet($xsl);  
523 -  
524 - $dom->loadXML($xslt->transformToXML($dom));  
525 -  
526 - $dom->formatOutput = true;  
527 - $dom->preserveWhiteSpace = false;  
528 - $chum_ger = $dom->getElementById("Rosetta@C-G : Plot Only!");  
529 - if ($chum_ger != NULL) $chum_ger->setAttribute("target","Churyumov-Gerasimenko");  
530 - $dom->save($locParamResult);  
531 - } 509 + $wsParamResult = $this->resultMgr->getResOutputName(__FUNCTION__, $this->userID . '_' . 'WsParams');
  510 +
  511 + if (!copy($locParamSrc, $locParamResult))
  512 + $locParamResult = '';
  513 + else {
  514 + $piBase = new DomDocument("1.0");
  515 + $piBase->formatOutput = true;
  516 + $piBase->preserveWhiteSpace = false;
  517 +
  518 + $dom = new DomDocument("1.0");
  519 + $dom->load($locParamResult);
  520 +
  521 + $xsl = new DomDocument("1.0");
  522 + $xsl->load(XMLPATH . 'dd2WStree.xsl');
  523 +
  524 + $xslt = new XSLTProcessor();
  525 + $xslt->importStylesheet($xsl);
  526 +
  527 + $dom->loadXML($xslt->transformToXML($dom));
  528 +
  529 + $dom->formatOutput = true;
  530 + $dom->preserveWhiteSpace = false;
  531 + $chum_ger = $dom->getElementById("Rosetta@C-G : Plot Only!");
  532 + if ($chum_ger != NULL) $chum_ger->setAttribute("target", "Churyumov-Gerasimenko");
  533 + $dom->save($locParamResult);
  534 + }
532 // if (!copy($remoteParamSrc,$remoteParamResult)) 535 // if (!copy($remoteParamSrc,$remoteParamResult))
533 // $remoteParamResult = ''; 536 // $remoteParamResult = '';
534 - if (!copy($wsParamSrc,$wsParamResult))  
535 - $wsParamResult = '';  
536 -  
537 - if ($locParamResult !='') $locParamResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$locParamResult); 537 + if (!copy($wsParamSrc, $wsParamResult))
  538 + $wsParamResult = '';
  539 +
  540 + if ($locParamResult != '') $locParamResult = 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $locParamResult);
538 // if ($remoteParamResult !='') $remoteParamResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$remoteParamResult); 541 // if ($remoteParamResult !='') $remoteParamResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$remoteParamResult);
539 - if ($wsParamResult !='') $wsParamResult = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$wsParamResult); 542 + if ($wsParamResult != '') $wsParamResult = 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $wsParamResult);
540 543
541 - if (($locParamResult =='') && ($remoteParamResult =='') && ($wsParamResult =='')){  
542 - if ($this->isSoap) throw new SoapFault("server05","No params descriptions .xml files for ".$this->userID." user");  
543 - else return array('success' => false, 'message' => "No params descriptions .xml files for ".$this->userID." user");  
544 - } 544 + if (($locParamResult == '') && ($remoteParamResult == '') && ($wsParamResult == '')) {
  545 + if ($this->isSoap) throw new SoapFault("server05", "No params descriptions .xml files for " . $this->userID . " user");
  546 + else return array('success' => false, 'message' => "No params descriptions .xml files for " . $this->userID . " user");
  547 + }
545 548
546 - $wsres = $this->resultMgr->addResult(__FUNCTION__,$vars,$this->userID,$wsParamResult.";".$locParamResult.";".$remoteParamResult); 549 + $wsres = $this->resultMgr->addResult(__FUNCTION__, $vars, $this->userID, $wsParamResult . ";" . $locParamResult . ";" . $remoteParamResult);
547 550
548 - return array('success' => true,'ParameterList' => array("UserDefinedParameters"=>$wsParamResult, "LocalDataBaseParameters"=>$locParamResult, "RemoteDataBaseParameters"=>$remoteParamResult));  
549 - } 551 + return array('success' => true, 'ParameterList' => array("UserDefinedParameters" => $wsParamResult, "LocalDataBaseParameters" => $locParamResult, "RemoteDataBaseParameters" => $remoteParamResult));
  552 + }
550 553
551 - public function getNewToken() {  
552 - $timeStamp = (new DateTime())->getTimestamp();  
553 - // generate token from timeStamp and some salt  
554 - $newToken = md5(1321 * (int)($timeStamp/timeLimitQuery));  
555 - return array('success' => true, 'token' => $newToken);  
556 - } 554 + public function getNewToken()
  555 + {
  556 + $timeStamp = (new DateTime())->getTimestamp();
  557 + // generate token from timeStamp and some salt
  558 + $newToken = md5(1321 * (int)($timeStamp / timeLimitQuery));
  559 + return array('success' => true, 'token' => $newToken);
  560 + }
557 561
558 ///////////////////////////////////////START GET DATASET /////////////////////////////// 562 ///////////////////////////////////////START GET DATASET ///////////////////////////////
559 - public function getParameter($data) { 563 + public function getParameter($data)
  564 + {
560 565
561 - $multiParam = false; 566 + $multiParam = false;
562 567
563 - $res = $this->init($data);  
564 - $resMgr = $this->initUserMgr(); 568 + $res = $this->init($data);
  569 + $resMgr = $this->initUserMgr();
565 570
566 - if (!$res['success']){  
567 - if ($this->isSoap) throw new SoapFault("server01","Cannot init user manager");  
568 - else return array('success' => false, 'message' => "Cannot init user manager");  
569 - } 571 + if (!$res['success']) {
  572 + if ($this->isSoap) throw new SoapFault("server01", "Cannot init user manager");
  573 + else return array('success' => false, 'message' => "Cannot init user manager");
  574 + }
570 575
571 - $vars = $res['vars']; 576 + $vars = $res['vars'];
572 577
573 - if ((strtotime($vars["stopTime"]) - strtotime($vars["startTime"])) < 0){  
574 - if ($this->isSoap) throw new SoapFault("request01","Start time must be higher than stop time");  
575 - else return array('success' => false, 'message' => "Start time must be higher than stop time");  
576 - }  
577 - elseif ((strtotime($vars["stopTime"]) - strtotime($vars["startTime"])) == 0){  
578 - if ($this->isSoap) throw new SoapFault("request02","You time interval equal 0 start is ".$vars["stopTime"]." stop is ".$vars["startTime"]);  
579 - else return array('success' => false, 'message' => "You time interval equal 0");  
580 - }  
581 -  
582 - $dataFileName = $this->getDataFileName($vars, $multiParam); 578 + if ((strtotime($vars["stopTime"]) - strtotime($vars["startTime"])) < 0) {
  579 + if ($this->isSoap) throw new SoapFault("request01", "Start time must be higher than stop time");
  580 + else return array('success' => false, 'message' => "Start time must be higher than stop time");
  581 + } elseif ((strtotime($vars["stopTime"]) - strtotime($vars["startTime"])) == 0) {
  582 + if ($this->isSoap) throw new SoapFault("request02", "You time interval equal 0 start is " . $vars["stopTime"] . " stop is " . $vars["startTime"]);
  583 + else return array('success' => false, 'message' => "You time interval equal 0");
  584 + }
583 585
584 - if ($dataFileName['success']) $this->dataFileName = $dataFileName['fileName'];  
585 - else {  
586 - if ($this->isSoap) throw new SoapFault("request03",$dataFileName['message']);  
587 - else return array('success' => false, 'message' => $dataFileName['message']);  
588 - } 586 + $dataFileName = $this->getDataFileName($vars, $multiParam);
  587 +
  588 + if ($dataFileName['success']) $this->dataFileName = $dataFileName['fileName'];
  589 + else {
  590 + if ($this->isSoap) throw new SoapFault("request03", $dataFileName['message']);
  591 + else return array('success' => false, 'message' => $dataFileName['message']);
  592 + }
589 593
590 594
591 - $paramId = array();  
592 - array_push($paramId, $vars["parameterID"]); 595 + $paramId = array();
  596 + array_push($paramId, $vars["parameterID"]);
593 // $paramId[] = $vars["parameterID"]; 597 // $paramId[] = $vars["parameterID"];
594 598
595 - if (!$vars["timeFormat"])  
596 - $timeFormat = "ISO8601";  
597 - else  
598 - $timeFormat = $vars["timeFormat"];  
599 -  
600 - if (!$vars["gzip"])  
601 - $gzip = 0;  
602 - else  
603 - $gzip = $vars["gzip"];  
604 -/*  
605 - if (!$vars["stream"])  
606 - $stream = 0;  
607 - else  
608 - $stream = $vars["stream"];*/  
609 -  
610 - $res = $this->doDownloadRequest(  
611 - array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $vars["sampling"]),  
612 - array("params" => $paramId),  
613 - array("userName" => $this->userID, "userPwd" => $this->userPWD, "sessionID" => $this->sessionID),  
614 - array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream),  
615 - $dataFileName);  
616 -  
617 -  
618 - if ($res['success']) return $res;  
619 - else {  
620 - if ($this->isSoap) throw new SoapFault("request03",$res['message']);  
621 - else return array('success' => false, 'message' => $res['message']); 599 + if (!$vars["timeFormat"])
  600 + $timeFormat = "ISO8601";
  601 + else
  602 + $timeFormat = $vars["timeFormat"];
  603 +
  604 + if (!$vars["gzip"])
  605 + $gzip = 0;
  606 + else
  607 + $gzip = $vars["gzip"];
  608 + /*
  609 + if (!$vars["stream"])
  610 + $stream = 0;
  611 + else
  612 + $stream = $vars["stream"];*/
  613 +
  614 + $res = $this->doDownloadRequest(
  615 + array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $vars["sampling"]),
  616 + array("params" => $paramId),
  617 + array("userName" => $this->userID, "userPwd" => $this->userPWD, "sessionID" => $this->sessionID),
  618 + array("format" => $vars["outputFormat"], "timeFormat" => $timeFormat, "gzip" => $gzip, "stream" => $stream),
  619 + $dataFileName);
  620 +
  621 +
  622 + if ($res['success']) return $res;
  623 + else {
  624 + if ($this->isSoap) throw new SoapFault("request03", $res['message']);
  625 + else return array('success' => false, 'message' => $res['message']);
  626 + }
622 } 627 }
623 - } 628 +
624 ///////////////////////////////////////START GET ORBITES /////////////////////////////// 629 ///////////////////////////////////////START GET ORBITES ///////////////////////////////
625 - public function getOrbites($data) { 630 + public function getOrbites($data)
  631 + {
626 632
627 - $multiParam = false; 633 + $multiParam = false;
628 634
629 - $res = $this->init($data); 635 + $res = $this->init($data);
630 636
631 - $resMgr = $this->initUserMgr(); 637 + $resMgr = $this->initUserMgr();
632 638
633 - if (!$resMgr['success']){  
634 - if ($this->isSoap) throw new SoapFault("server01","Cannot init user manager");  
635 - else return array('success' => false, 'message' => "Cannot init user manager");  
636 - } 639 + if (!$resMgr['success']) {
  640 + if ($this->isSoap) throw new SoapFault("server01", "Cannot init user manager");
  641 + else return array('success' => false, 'message' => "Cannot init user manager");
  642 + }
637 643
638 - $vars = $res['vars']; 644 + $vars = $res['vars'];
639 645
640 - if ((strtotime($vars["stopTime"]) - strtotime($vars["startTime"])) < 0){  
641 - if ($this->isSoap) throw new SoapFault("request01","Start time must be higher than stop time");  
642 - else return array('success' => false, 'message' => "Start time must be higher than stop time");  
643 - }  
644 - elseif ((strtotime($vars["stopTime"]) - strtotime($vars["startTime"])) == 0){  
645 - if ($this->isSoap) throw new SoapFault("request02","You time interval equal 0 start is ".$vars["stopTime"]." stop is ".$vars["startTime"]);  
646 - else return array('success' => false, 'message' => "You time interval equal 0");  
647 - }  
648 -  
649 -  
650 -  
651 - $spacecraft = $vars["spacecraft"];  
652 - $coordinateSystem = $vars["coordinateSystem"];  
653 - if ($spacecraft == "GALILEO") $spacecraft = ucfirst(strtolower($spacecraft));  
654 - if (!$vars["units"])  
655 - $units = "km";  
656 - else  
657 - $units = $vars["units"];  
658 -  
659 - $paramId = array();  
660 -  
661 - $orbitRequest = array("startTime" => $vars["startTime"],  
662 - "stopTime" => $vars["stopTime"],  
663 - "spacecraft" => $spacecraft,  
664 - "coordinateSystem" => $coordinateSystem,  
665 - "units" => $units  
666 - );  
667 -  
668 -  
669 - $orbitesParam = $this->getOrbitesParameter($orbitRequest);  
670 - if ($orbitesParam['success']) $orbParam = $orbitesParam['parameterID'];  
671 - else {  
672 - $orbParam = 'successEstfalse';  
673 - if ($this->isSoap) throw new SoapFault("request03",$orbitesParam['message']);  
674 - else return array('success' => false, 'message' => $orbitesParam['message']);  
675 - } 646 + if ((strtotime($vars["stopTime"]) - strtotime($vars["startTime"])) < 0) {
  647 + if ($this->isSoap) throw new SoapFault("request01", "Start time must be higher than stop time");
  648 + else return array('success' => false, 'message' => "Start time must be higher than stop time");
  649 + } elseif ((strtotime($vars["stopTime"]) - strtotime($vars["startTime"])) == 0) {
  650 + if ($this->isSoap) throw new SoapFault("request02", "You time interval equal 0 start is " . $vars["stopTime"] . " stop is " . $vars["startTime"]);
  651 + else return array('success' => false, 'message' => "You time interval equal 0");
  652 + }
676 653
677 -  
678 - $dataFileName = $this->getDataFileName($orbitesParam, $multiParam);  
679 654
680 - if ($dataFileName['success']) $this->dataFileName = $dataFileName['fileName'];  
681 - else {  
682 - if ($this->isSoap) throw new SoapFault("request03",$dataFileName['message']);  
683 - else return array('success' => false, 'message' => $dataFileName['message']);  
684 - }  
685 -  
686 - array_push($paramId, $orbParam); 655 + $spacecraft = $vars["spacecraft"];
  656 + $coordinateSystem = $vars["coordinateSystem"];
  657 + if ($spacecraft == "GALILEO") $spacecraft = ucfirst(strtolower($spacecraft));
  658 + if (!$vars["units"])
  659 + $units = "km";
  660 + else
  661 + $units = $vars["units"];
  662 +
  663 + $paramId = array();
  664 +
  665 + $orbitRequest = array("startTime" => $vars["startTime"],
  666 + "stopTime" => $vars["stopTime"],
  667 + "spacecraft" => $spacecraft,
  668 + "coordinateSystem" => $coordinateSystem,
  669 + "units" => $units
  670 + );
  671 +
  672 +
  673 + $orbitesParam = $this->getOrbitesParameter($orbitRequest);
  674 + if ($orbitesParam['success']) $orbParam = $orbitesParam['parameterID'];
  675 + else {
  676 + $orbParam = 'successEstfalse';
  677 + if ($this->isSoap) throw new SoapFault("request03", $orbitesParam['message']);
  678 + else return array('success' => false, 'message' => $orbitesParam['message']);
  679 + }
  680 +
  681 +
  682 + $dataFileName = $this->getDataFileName($orbitesParam, $multiParam);
  683 +
  684 + if ($dataFileName['success']) $this->dataFileName = $dataFileName['fileName'];
  685 + else {
  686 + if ($this->isSoap) throw new SoapFault("request03", $dataFileName['message']);
  687 + else return array('success' => false, 'message' => $dataFileName['message']);
  688 + }
  689 +
  690 + array_push($paramId, $orbParam);
687 // $paramId[] = $vars["parameterID"]; 691 // $paramId[] = $vars["parameterID"];
688 692
689 - if (!$vars["timeFormat"])  
690 - $timeFormat = "ISO8601";  
691 - else  
692 - $timeFormat = $vars["timeFormat"];  
693 -  
694 - if (!$vars["gzip"])  
695 - $gzip = 0;  
696 - else  
697 - $gzip = $vars["gzip"];  
698 -  
699 - $res = $this->doDownloadRequest(  
700 - array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $vars["sampling"]),  
701 - array("params" => $paramId),  
702 - array("userName" => $this->userID, "userPwd" => $this->userPWD, "sessionID" => $this->sessionID),  
703 - array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream),  
704 - $dataFileName);  
705 -  
706 -  
707 - if ($res['success']) return $res;  
708 - else {  
709 - if ($this->isSoap) throw new SoapFault("request03",$res['message']);  
710 - else return array('success' => false, 'message' => $res['message']); 693 + if (!$vars["timeFormat"])
  694 + $timeFormat = "ISO8601";
  695 + else
  696 + $timeFormat = $vars["timeFormat"];
  697 +
  698 + if (!$vars["gzip"])
  699 + $gzip = 0;
  700 + else
  701 + $gzip = $vars["gzip"];
  702 +
  703 + $res = $this->doDownloadRequest(
  704 + array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $vars["sampling"]),
  705 + array("params" => $paramId),
  706 + array("userName" => $this->userID, "userPwd" => $this->userPWD, "sessionID" => $this->sessionID),
  707 + array("format" => $vars["outputFormat"], "timeFormat" => $timeFormat, "gzip" => $gzip, "stream" => $stream),
  708 + $dataFileName);
  709 +
  710 +
  711 + if ($res['success']) return $res;
  712 + else {
  713 + if ($this->isSoap) throw new SoapFault("request03", $res['message']);
  714 + else return array('success' => false, 'message' => $res['message']);
  715 + }
711 } 716 }
712 - }  
713 - 717 +
714 ///////////////////////////////////////START GET DATASET /////////////////////////////// 718 ///////////////////////////////////////START GET DATASET ///////////////////////////////
715 719
716 720
717 - public function getDataset($data) {  
718 - $multiParam = true; 721 + public function getDataset($data)
  722 + {
  723 + $multiParam = true;
  724 +
  725 + $res = $this->init($data);
719 726
720 - $res = $this->init($data);  
721 -  
722 - $resMgr = $this->initUserMgr(); 727 + $resMgr = $this->initUserMgr();
723 728
724 - $vars = $res['vars']; 729 + $vars = $res['vars'];
725 730
726 - if ((strtotime($vars["stopTime"]) - strtotime($vars["startTime"])) < 0){  
727 - if ($this->isSoap) throw new SoapFault("request01","Start time must be higher than stop time");  
728 - else return array('success' => false, 'message' => "Start time must be higher than stop time");  
729 - }  
730 - elseif ((strtotime($vars["stopTime"]) - strtotime($vars["startTime"])) == 0){  
731 - if ($this->isSoap) throw new SoapFault("request02","You time interval equal 0");  
732 - else return array('success' => false, 'message' => "You time interval equal 0"); 731 + if ((strtotime($vars["stopTime"]) - strtotime($vars["startTime"])) < 0) {
  732 + if ($this->isSoap) throw new SoapFault("request01", "Start time must be higher than stop time");
  733 + else return array('success' => false, 'message' => "Start time must be higher than stop time");
  734 + } elseif ((strtotime($vars["stopTime"]) - strtotime($vars["startTime"])) == 0) {
  735 + if ($this->isSoap) throw new SoapFault("request02", "You time interval equal 0");
  736 + else return array('success' => false, 'message' => "You time interval equal 0");
  737 + }
  738 +
  739 + $dataFileName = $this->getDataFileName($vars, $multiParam);
  740 +
  741 + if ($dataFileName['success']) $this->dataFileName = $dataFileName['fileName'];
  742 + else {
  743 + if ($this->isSoap) throw new SoapFault("request03", $dataFileName['message']);
  744 + else return array('success' => false, 'message' => $dataFileName['message']);
  745 + }
  746 + $paramId = array();
  747 + $localData = simplexml_load_file(USERPATH . $this->userID . '/WS/LocalParams.xml');
  748 +
  749 + if (!$vars["sampling"]) {
  750 + $xpath = "//dataset[@xml:id='" . $vars['datasetID'] . "']/@sampling";
  751 + $tmp = $localData->xpath($xpath);
  752 + $vars["sampling"] = (string)$tmp[0];
  753 +
  754 + $matches = array();
  755 + preg_match("/([a-z])$/", $vars["sampling"], $matches);
  756 +
  757 +
  758 + $dataFileName = $this->getDataFileName($vars, $multiParam);
  759 +
  760 + if ($dataFileName['success']) $this->dataFileName = $dataFileName['fileName'];
  761 + else {
  762 + if ($this->isSoap) throw new SoapFault("request03", $dataFileName['message']);
  763 + else return array('success' => false, 'message' => $dataFileName['message']);
  764 + }
  765 +
  766 + $vars["sampling"] = strtr($vars["sampling"], array($matches[1] => ""));
  767 + switch ($matches[1]) {
  768 + case 's':
  769 + $sampling = floatval($vars["sampling"]);
  770 + break;
  771 + case 'm':
  772 + $sampling = floatval($vars["sampling"]) * 60;
  773 + break;
  774 + case 'h':
  775 + $sampling = floatval($vars["sampling"]) * 60 * 60;
  776 + break;
  777 + default:
  778 + }
  779 + }
  780 +
  781 + $xpath = "//dataset[@xml:id='" . $vars['datasetID'] . "']/parameter/@*[namespace-uri()='http://www.w3.org/XML/1998/namespace' and local-name()='id']";
  782 + $pars = $localData->xpath($xpath);
  783 +
  784 + foreach ($pars as $p)
  785 + $paramId[] = (string)$p[0];
  786 +
  787 + if (!$vars["timeFormat"])
  788 + $timeFormat = "ISO8601";
  789 + else
  790 + $timeFormat = $vars["timeFormat"];
  791 +
  792 + if (!$vars["gzip"])
  793 + $gzip = 0;
  794 + else
  795 + $gzip = $vars["gzip"];
  796 +
  797 + $res = $this->doDownloadRequest(
  798 + array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $sampling),
  799 + array("params" => $paramId),
  800 + array("userName" => $this->userID, "userPwd" => $this->userPWD, "sessionID" => $this->sessionID),
  801 + array("format" => $vars["outputFormat"], "timeFormat" => $timeFormat, "gzip" => $gzip, "stream" => $stream),
  802 + $dataFileName);
  803 +
  804 +
  805 + if ($res['success']) return $res;
  806 + else {
  807 + if ($this->isSoap) throw new SoapFault("request03", $res['message']);
  808 + else return array('success' => false, 'message' => $res['message']);
  809 + }
733 } 810 }
734 -  
735 - $dataFileName = $this->getDataFileName($vars, $multiParam);  
736 811
737 - if ($dataFileName['success']) $this->dataFileName = $dataFileName['fileName'];  
738 - else {  
739 - if ($this->isSoap) throw new SoapFault("request03",$dataFileName['message']);  
740 - else return array('success' => false, 'message' => $dataFileName['message']); 812 +////////////////////////////////////////END GET PARAMETERS /////////////////////////////////
  813 + protected function getOrbitesParameter($orbitRequest)
  814 + {
  815 +
  816 + $orbitesXml = new DomDocument();
  817 +
  818 + if (file_exists(orbitesXml)) {
  819 + $orbitesXml->load(orbitesXml);
  820 + $xpath = new DOMXpath($orbitesXml);
  821 + $path = '//orbites[@mission="' . $orbitRequest['spacecraft'] . '" and @coordinate_system="' . $orbitRequest['coordinateSystem'] . '" and @units="' . $orbitRequest['units'] . '" ] ';
  822 +
  823 + $orbites = $xpath->query($path);
  824 + foreach ($orbites as $orbite) {
  825 + $paramInfo = $this->myParamsInfoMgr->GetDDInfoFromParameterID($orbite->getAttribute('xml:id'));
  826 + $paramStart = $paramInfo['dataset']['starttime'];
  827 + $paramStop = $paramInfo['dataset']['stoptime'];
  828 +
  829 + if ((strtotime($paramStart) <= strtotime($orbitRequest['startTime']) && (strtotime($orbitRequest['stopTime'])) <= strtotime($paramStop))) {
  830 +
  831 + return array('success' => true,
  832 + 'parameterID' => $orbite->getAttribute('xml:id'),
  833 + 'startTime' => $orbitRequest['startTime'],
  834 + 'stopTime' => $orbitRequest['stopTime']
  835 + );
  836 + }
  837 + }
  838 + return array('success' => false,
  839 + 'message' =>
  840 + "Cannot find orbites for " . $orbitRequest['spacecraft'] . " between " . $orbitRequest['startTime'] . " in " . $orbitRequest['units'] . " " . $orbitRequest['coordinateSystem'] . " and " . $orbitRequest['stopTime'] . " ($paramStart - $paramStop) ");
  841 + } else {
  842 + return array('success' => false, 'message' => "Orbits file doesn't exist");
  843 + }
741 } 844 }
742 - $paramId = array();  
743 - $localData = simplexml_load_file(USERPATH.$this->userID.'/WS/LocalParams.xml');  
744 -  
745 - if (!$vars["sampling"]){  
746 -$xpath = "//dataset[@xml:id='".$vars['datasetID']."']/@sampling";  
747 -$tmp = $localData->xpath($xpath);  
748 -$vars["sampling"] = (string)$tmp[0];  
749 845
750 -$matches=array();  
751 -preg_match("/([a-z])$/", $vars["sampling"], $matches);  
752 846
  847 + protected function doDownloadRequest($interval, $paramList, $user, $formatInfo, $dataFileName)
  848 + {
  849 + if ($interval['sampling'])
  850 + $structure = 0;// sampling
  851 + else
  852 + $structure = 2; // not sampling
  853 +
  854 + $fileExtension = "";
  855 + switch ($formatInfo['format']) {
  856 + case 'netCDF' :
  857 + if (!$jobMgr) {
  858 + if ($this->isSoap) throw new SoapFault("server01", "netCDF format not implemented");
  859 + else return array('success' => false, 'message' => "netCDF format not implemented");
  860 + }
  861 + break;
  862 + case 'VOTable' :
  863 + $fileformat = "vot";
  864 + $kernelExtension = ".vot";
  865 + $wsExtension = ".xml";
  866 + break;
  867 + case 'ASCII' :
  868 + default :
  869 + $fileformat = "ASCII";
  870 + $kernelExtension = ".txt";
  871 + $wsExtension = ".txt";
  872 + }
753 873
754 -$dataFileName = $this->getDataFileName($vars, $multiParam); 874 + switch ($formatInfo['timeFormat']) {
  875 + case 'unixtime' :
  876 + $timeformat = 'Timestamp';
  877 + break;
  878 + default :
  879 + $timeformat = 'YYYY-MM-DDThh:mm:ss';
  880 + }
755 881
756 -if ($dataFileName['success']) $this->dataFileName = $dataFileName['fileName'];  
757 -else {  
758 - if ($this->isSoap) throw new SoapFault("request03",$dataFileName['message']);  
759 - else return array('success' => false, 'message' => $dataFileName['message']);  
760 -} 882 + if ($formatInfo['gzip'] == 1) {
  883 + $compression = "gzip";
  884 + $kernelExtension .= ".gz";
  885 + $wsExtension .= ".gz";
  886 + } else
  887 + $compression = "";
  888 +
  889 + require_once(INTEGRATION_SRC_DIR . "RequestManager.php");
  890 + IHMConfigClass::setUserName($this->userID);
  891 + if (!isset($this->paramLoader))
  892 + $this->paramLoader = new IHMUserParamLoaderClass();
  893 +
  894 + //Build parameter list
  895 + $params = array();
  896 +
  897 + //TODO template arguments to implementer ?
  898 + foreach ($paramList['params'] as $paramId) {
  899 + $param = new stdClass;
  900 +
  901 + if (preg_match("#^ws_#", $paramId)) {
  902 + $res = $this->paramLoader->getDerivedParameterNameFromId($paramId);
  903 + if (!$res["success"]) {
  904 + if ($this->isSoap) throw new SoapFault("server02", 'Not available derived parameter ' . $paramId);
  905 + else return array('success' => false, 'message' => 'Not available derived parameter ' . $paramId);
  906 + }
  907 + $param->paramid = "ws_" . $res['name'];
  908 + } else if (preg_match("#^wsd_#", $paramId)) {
  909 + $res = $this->paramLoader->getUploadedParameterNameFromId($paramId);
  910 + if (!$res["success"]) {
  911 + if ($this->isSoap) throw new SoapFault("server02", 'Not available user parameter ' . $paramId);
  912 + else return array('success' => false, 'message' => 'Not available user parameter ' . $paramId);
  913 + }
  914 + $param->paramid = "wsd_" . $res['name'];
  915 + } else {
  916 + $param->paramid = $paramId;
  917 + }
  918 +
  919 + $params[] = $param;
  920 + }
  921 +
  922 + $obj = (object)array(
  923 + "nodeType" => "download",
  924 + "downloadSrc" => "0",
  925 + "structure" => $structure,
  926 + "refparamSampling" => false,
  927 + "sampling" => $interval['sampling'],
  928 + "timesrc" => "Interval",
  929 + "startDate" => $interval['startTime'],
  930 + "stopDate" => $interval['stopTime'],
  931 + "list" => $params,
  932 + "fileformat" => $fileformat,
  933 + "timeformat" => $timeformat,
  934 + "compression" => $compression,
  935 + "disablebatch" => true
  936 + );
  937 +
  938 + if (!isset($this->requestManager))
  939 + $this->requestManager = new RequestManagerClass();
  940 +
  941 + try {
  942 + $downloadResult = $this->requestManager->runIHMRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PARAMS, $obj);
  943 + } catch (Exception $e) {
  944 + if ($this->isSoap) throw new SoapFault("server02", 'Exception detected : ' . $e->getMessage());
  945 + else return array('success' => false, 'message' => 'Exception detected : ' . $e->getMessage());
  946 + }
  947 +
  948 + if (!$downloadResult['success']) {
  949 + if ($this->isSoap) throw new SoapFault("server03", $downloadResult['message']);
  950 + else return array('success' => false, 'message' => $downloadResult['message']);
  951 + }
  952 +
  953 + $resultFile = USERPATH . $this->userID . '/RES/' . $downloadResult['folder'] . '/' . $downloadResult['result'];
  954 + $resultFile .= $kernelExtension;
  955 +
  956 + if (!file_exists($resultFile)) {
  957 + if ($this->isSoap) throw new SoapFault("server04", 'Cannot retrieve result file ' . $resultFile);
  958 + else return array('success' => false, 'message' => 'Cannot retrieve result file');
  959 + }
  960 +
  961 + rename($resultFile, WSRESULT . $this->dataFileName . $wsExtension);
  962 + $outputFile = WSRESULT . $this->dataFileName . $wsExtension;
  963 + chmod($outputFile, 0664);
  964 + $outputFile = 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $outputFile);
  965 +
  966 + $obj = (object)array(
  967 + 'id' => $downloadResult['id']
  968 + );
  969 +
  970 + try {
  971 + $downloadResult = $this->requestManager->runIHMRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PROCESSDELETE, $obj);
  972 + } catch (Exception $e) {
  973 + //Nothing to do
  974 + }
  975 +
  976 + return array('success' => true, 'dataFileURLs' => $outputFile);
761 977
762 -$vars["sampling"] = strtr($vars["sampling"], array($matches[1] => ""));  
763 - switch ($matches[1]) {  
764 - case 's':  
765 - $sampling = floatval($vars["sampling"]);  
766 - break;  
767 - case 'm':  
768 - $sampling = floatval($vars["sampling"])*60;  
769 - break;  
770 - case 'h':  
771 - $sampling = floatval($vars["sampling"])*60*60;  
772 - break;  
773 - default:  
774 - }  
775 - }  
776 -  
777 - $xpath = "//dataset[@xml:id='".$vars['datasetID']."']/parameter/@*[namespace-uri()='http://www.w3.org/XML/1998/namespace' and local-name()='id']";  
778 - $pars = $localData->xpath($xpath);  
779 -  
780 - foreach ($pars as $p)  
781 - $paramId[] = (string)$p[0];  
782 -  
783 - if (!$vars["timeFormat"])  
784 - $timeFormat = "ISO8601";  
785 - else  
786 - $timeFormat = $vars["timeFormat"];  
787 -  
788 - if (!$vars["gzip"])  
789 - $gzip = 0;  
790 - else  
791 - $gzip = $vars["gzip"];  
792 -  
793 - $res = $this->doDownloadRequest(  
794 - array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $sampling),  
795 - array("params" => $paramId),  
796 - array("userName" => $this->userID, "userPwd" => $this->userPWD, "sessionID" => $this->sessionID),  
797 - array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream),  
798 - $dataFileName);  
799 -  
800 -  
801 - if ($res['success']) return $res;  
802 - else {  
803 - if ($this->isSoap) throw new SoapFault("request03",$res['message']);  
804 - else return array('success' => false, 'message' => $res['message']);  
805 } 978 }
806 - }  
807 979
808 -////////////////////////////////////////END GET PARAMETERS /////////////////////////////////  
809 - protected function getOrbitesParameter($orbitRequest) {  
810 -  
811 - $orbitesXml = new DomDocument();  
812 -  
813 - if (file_exists(orbitesXml)) {  
814 - $orbitesXml -> load(orbitesXml);  
815 - $xpath = new DOMXpath($orbitesXml);  
816 - $path = '//orbites[@mission="'.$orbitRequest['spacecraft'].'" and @coordinate_system="'.$orbitRequest['coordinateSystem'].'" and @units="'.$orbitRequest['units'].'" ] ';  
817 -  
818 - $orbites = $xpath->query($path);  
819 - foreach ($orbites as $orbite){  
820 - $paramInfo = $this->myParamsInfoMgr->GetDDInfoFromParameterID($orbite->getAttribute('xml:id'));  
821 - $paramStart = $paramInfo['dataset']['starttime'];  
822 - $paramStop = $paramInfo['dataset']['stoptime'];  
823 -  
824 - if((strtotime($paramStart) <= strtotime($orbitRequest['startTime']) && (strtotime($orbitRequest['stopTime'])) <= strtotime($paramStop))) {  
825 -  
826 - return array('success' => true,  
827 - 'parameterID' => $orbite->getAttribute('xml:id'),  
828 - 'startTime' => $orbitRequest['startTime'],  
829 - 'stopTime' => $orbitRequest['stopTime'] 980 + protected function timeIntervalToDuration($startTime, $stopTime)
  981 + {
  982 +
  983 + $duration = strtotime($stopTime) - strtotime($startTime);
  984 + $durationDay = intval($duration / (86400));
  985 + $duration = $duration - $durationDay * 86400;
  986 + $durationHour = intval($duration / (3600));
  987 + $duration = $duration - $durationHour * 3600;
  988 + $durationMin = intval($duration / (60));
  989 + $durationSec = $duration - $durationMin * 60;
  990 +
  991 + return array("success" => true, "days" => sprintf("%04s", strval($durationDay)),
  992 + "hours" => sprintf("%02s", strval($durationHour)),
  993 + "mins" => sprintf("%02s", strval($durationMin)),
  994 + "secs" => sprintf("%02s", strval($durationSec))
830 ); 995 );
  996 + }
  997 +
  998 + protected function getDataFileName($vars, $multiParam)
  999 + {
  1000 + if ($vars['startTime'] && $vars['stopTime'] && $vars['parameterID'] && !$multiParam) {
  1001 + $fileName = $vars['parameterID'] . "-" . strtotime($vars['startTime']) . "-" . strtotime($vars['stopTime']);
  1002 + if (isset($vars['sampling']) && $vars['sampling'] != "" && $vars['sampling'] != 0)
  1003 + $fileName .= "-" . $vars['sampling'];
  1004 + return array('success' => true, 'fileName' => $fileName);
  1005 + } else if ($vars['startTime'] && $vars['stopTime'] && $vars['datasetID'] && $multiParam) {
  1006 + $datasetName = strtr($vars["datasetID"], array(":" => "_"));
  1007 + $fileName = $datasetName . "-" . strtotime($vars['startTime']) . "-" . strtotime($vars['stopTime']);
  1008 + if (isset($vars['sampling']) && $vars['sampling'] != "" && $vars['sampling'] != 0)
  1009 + $fileName .= "-" . $vars['sampling'];
  1010 + return array('success' => true, 'fileName' => $fileName);
  1011 + } else {
  1012 + if (!$vars['startTime'])
  1013 + $message = "Start time not specified";
  1014 + if (!$vars['stopTime'])
  1015 + $message = "Stop time not specified";
  1016 + if (!$vars['parameterID'] && !$multiParam)
  1017 + $message = "Parameter not specified";
  1018 + if (!$vars['datasetID'] && $multiParam)
  1019 + $message = "DataSet not specified";
  1020 + return array('success' => false, 'message' => $message);
831 } 1021 }
832 - }  
833 - return array('success' => false,  
834 - 'message' =>  
835 - "Cannot find orbites for ".$orbitRequest['spacecraft']." between ".$orbitRequest['startTime']." in ".$orbitRequest['units']." ".$orbitRequest['coordinateSystem']." and ".$orbitRequest['stopTime']." ($paramStart - $paramStop) ");  
836 } 1022 }
837 - else {  
838 - return array('success' => false, 'message' => "Orbits file doesn't exist");  
839 - }  
840 - }  
841 -  
842 -  
843 - protected function doDownloadRequest($interval,$paramList,$user,$formatInfo,$dataFileName) {  
844 - if ($interval['sampling'])  
845 - $structure = 0;// sampling  
846 - else  
847 - $structure = 2; // not sampling  
848 -  
849 - $fileExtension = "";  
850 - switch ($formatInfo['format'])  
851 - {  
852 - case 'netCDF' :  
853 - if (!$jobMgr){  
854 - if ($this->isSoap) throw new SoapFault("server01","netCDF format not implemented");  
855 - else return array('success' => false, 'message' => "netCDF format not implemented");  
856 - }  
857 - break;  
858 - case 'VOTable' :  
859 - $fileformat = "vot";  
860 - $kernelExtension = ".vot";  
861 - $wsExtension = ".xml";  
862 - break;  
863 - case 'ASCII' :  
864 - default :  
865 - $fileformat = "ASCII";  
866 - $kernelExtension = ".txt";  
867 - $wsExtension = ".txt";  
868 - }  
869 -  
870 - switch ($formatInfo['timeFormat'])  
871 - {  
872 - case 'unixtime' :  
873 - $timeformat = 'Timestamp';  
874 - break;  
875 - default :  
876 - $timeformat = 'YYYY-MM-DDThh:mm:ss';  
877 - }  
878 -  
879 - if ($formatInfo['gzip'] == 1)  
880 - {  
881 - $compression = "gzip";  
882 - $kernelExtension .= ".gz";  
883 - $wsExtension .= ".gz";  
884 - }  
885 - else  
886 - $compression = "";  
887 -  
888 - require_once(INTEGRATION_SRC_DIR."RequestManager.php");  
889 - IHMConfigClass::setUserName($this->userID);  
890 - if (!isset($this->paramLoader))  
891 - $this->paramLoader = new IHMUserParamLoaderClass();  
892 -  
893 - //Build parameter list  
894 - $params = array();  
895 -  
896 - //TODO template arguments to implementer ?  
897 - foreach ($paramList['params'] as $paramId)  
898 - {  
899 - $param = new stdClass;  
900 -  
901 - if (preg_match("#^ws_#",$paramId))  
902 - {  
903 - $res = $this->paramLoader->getDerivedParameterNameFromId($paramId);  
904 - if (!$res["success"])  
905 - {  
906 - if ($this->isSoap) throw new SoapFault("server02", 'Not available derived parameter '.$paramId);  
907 - else return array('success' => false, 'message' => 'Not available derived parameter '.$paramId);  
908 - }  
909 - $param->paramid = "ws_".$res['name'];  
910 - }  
911 - else if (preg_match("#^wsd_#",$paramId))  
912 - {  
913 - $res = $this->paramLoader->getUploadedParameterNameFromId($paramId);  
914 - if (!$res["success"])  
915 - {  
916 - if ($this->isSoap) throw new SoapFault("server02", 'Not available user parameter '.$paramId);  
917 - else return array('success' => false, 'message' => 'Not available user parameter '.$paramId);  
918 - }  
919 - $param->paramid = "wsd_".$res['name'];  
920 - }  
921 - else  
922 - {  
923 - $param->paramid = $paramId;  
924 - }  
925 -  
926 - $params[] = $param;  
927 - }  
928 -  
929 - $obj = (object)array(  
930 - "nodeType" => "download",  
931 - "downloadSrc" => "0",  
932 - "structure" => $structure,  
933 - "refparamSampling" => false,  
934 - "sampling" => $interval['sampling'],  
935 - "timesrc" => "Interval",  
936 - "startDate" => $interval['startTime'],  
937 - "stopDate" => $interval['stopTime'],  
938 - "list" => $params,  
939 - "fileformat" => $fileformat,  
940 - "timeformat" => $timeformat,  
941 - "compression" => $compression,  
942 - "disablebatch" => true  
943 - );  
944 -  
945 - if (!isset($this->requestManager))  
946 - $this->requestManager = new RequestManagerClass();  
947 -  
948 - try {  
949 - $downloadResult = $this->requestManager->runIHMRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PARAMS, $obj);  
950 - } catch (Exception $e) {  
951 - if ($this->isSoap) throw new SoapFault("server02", 'Exception detected : '.$e->getMessage());  
952 - else return array('success' => false, 'message' => 'Exception detected : '.$e->getMessage());  
953 - }  
954 -  
955 - if (!$downloadResult['success'])  
956 - {  
957 - if ($this->isSoap) throw new SoapFault("server03", $downloadResult['message']);  
958 - else return array('success' => false, 'message' => $downloadResult['message']);  
959 - }  
960 -  
961 - $resultFile = USERPATH.$this->userID.'/RES/'.$downloadResult['folder'].'/'.$downloadResult['result'];  
962 - $resultFile .= $kernelExtension;  
963 -  
964 - if (!file_exists($resultFile))  
965 - {  
966 - if ($this->isSoap) throw new SoapFault("server04", 'Cannot retrieve result file '.$resultFile);  
967 - else return array('success' => false, 'message' => 'Cannot retrieve result file');  
968 - }  
969 -  
970 - rename($resultFile, WSRESULT.$this->dataFileName.$wsExtension);  
971 - $outputFile = WSRESULT.$this->dataFileName.$wsExtension;  
972 - chmod ($outputFile, 0664);  
973 - $outputFile = 'http://'.str_replace(BASE_PATH,$_SERVER['SERVER_NAME'].APACHE_ALIAS,$outputFile);  
974 -  
975 - $obj = (object)array(  
976 - 'id' => $downloadResult['id']  
977 - );  
978 -  
979 - try {  
980 - $downloadResult = $this->requestManager->runIHMRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PROCESSDELETE, $obj);  
981 - } catch (Exception $e) {  
982 - //Nothing to do  
983 - }  
984 -  
985 - return array('success' => true, 'dataFileURLs' => $outputFile);  
986 -  
987 - }  
988 -  
989 - protected function timeIntervalToDuration($startTime,$stopTime) {  
990 -  
991 - $duration = strtotime($stopTime) - strtotime($startTime);  
992 - $durationDay = intval($duration/(86400));  
993 - $duration = $duration - $durationDay*86400;  
994 - $durationHour = intval($duration/(3600));  
995 - $duration = $duration - $durationHour*3600;  
996 - $durationMin = intval($duration/(60));  
997 - $durationSec = $duration - $durationMin*60;  
998 -  
999 - return array("success" => true, "days" => sprintf("%04s", strval($durationDay)),  
1000 - "hours" => sprintf("%02s", strval($durationHour)),  
1001 - "mins" => sprintf("%02s", strval($durationMin)),  
1002 - "secs" => sprintf("%02s", strval($durationSec))  
1003 - );  
1004 - }  
1005 -  
1006 - protected function getDataFileName($vars, $multiParam){  
1007 - if ($vars['startTime'] && $vars['stopTime'] && $vars['parameterID'] && !$multiParam){  
1008 - $fileName = $vars['parameterID']."-".strtotime($vars['startTime'])."-".strtotime($vars['stopTime']);  
1009 - if (isset($vars['sampling']) && $vars['sampling'] != "" && $vars['sampling'] != 0)  
1010 - $fileName .= "-".$vars['sampling'];  
1011 - return array('success' => true, 'fileName' => $fileName);  
1012 - }  
1013 - else if ($vars['startTime'] && $vars['stopTime'] && $vars['datasetID'] && $multiParam){  
1014 - $datasetName = strtr($vars["datasetID"], array(":" => "_"));  
1015 - $fileName = $datasetName."-".strtotime($vars['startTime'])."-".strtotime($vars['stopTime']);  
1016 - if (isset($vars['sampling']) && $vars['sampling'] != "" && $vars['sampling'] != 0)  
1017 - $fileName .= "-".$vars['sampling'];  
1018 - return array('success' => true, 'fileName' => $fileName);  
1019 - }  
1020 - else {  
1021 - if (!$vars['startTime'])  
1022 - $message="Start time not specified";  
1023 - if (!$vars['stopTime'])  
1024 - $message="Stop time not specified";  
1025 - if (!$vars['parameterID'] && !$multiParam)  
1026 - $message="Parameter not specified";  
1027 - if (!$vars['datasetID'] && $multiParam)  
1028 - $message="DataSet not specified";  
1029 - return array('success' => false, 'message' => $message);  
1030 - }  
1031 - }  
1032 -  
1033 - private function compress($srcName, $dstName) {  
1034 -  
1035 - $fp = fopen($srcName, "r");  
1036 - $data = fread ($fp, filesize($srcName));  
1037 - fclose($fp);  
1038 -  
1039 - $zp = gzopen($dstName, "w9");  
1040 - gzwrite($zp, $data);  
1041 - gzclose($zp); 1023 +
  1024 + private function compress($srcName, $dstName)
  1025 + {
  1026 +
  1027 + $fp = fopen($srcName, "r");
  1028 + $data = fread($fp, filesize($srcName));
  1029 + fclose($fp);
  1030 +
  1031 + $zp = gzopen($dstName, "w9");
  1032 + gzwrite($zp, $data);
  1033 + gzclose($zp);
1042 } 1034 }
1043 1035
1044 } 1036 }
  1037 +
1045 ?> 1038 ?>
1046 \ No newline at end of file 1039 \ No newline at end of file