Blame view

php/classes/AmdaAction.php 38.9 KB
16035364   Benjamin Renard   First commit
1
2
3
<?php
/**
 * @class AmdaAction
aa94fd24   elena   Merge with last svn
4
 * @version $Id: AmdaAction.php 2976 2015-07-01 15:05:40Z benjamin $
16035364   Benjamin Renard   First commit
5
6
7
8
 *
 */


735c653b   Elena.Budnik   rank at observato...
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class AmdaAction 
{
	private $xmlFiles  = array('localParam' => 'LocalParams.xml', 'remoteParam' => 'RemoteParams.xml', 
										'remoteSimuParam' => 'RemoteParams.xml', 'derivedParam' => 'WsParams.xml', 'myDataParam' => 'WsParams.xml',
										'timeTable' => 'Tt.xml', 'catalog' => 'Tt.xml', 'alias' => 'Alias.xml',	 
										'myData' => 'Files.xml', 
										'request' => 'Request.xml', 'condition' => 'Request.xml',
										'bkgWorks' => 'jobs.xml');

	private $user, $amdaStat;

	public function __construct() 
	{                 
		$dd = new UserMgr();
		$this->user = $dd->user;
		if (!defined('NEWKERNEL_DEBUG') || !NEWKERNEL_DEBUG)
					$this->amdaStat = new AmdaStats($dd->user);
	}
16035364   Benjamin Renard   First commit
27

735c653b   Elena.Budnik   rank at observato...
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
	private function getUrlDirs($url) 
	{
		//TODO replace by ftp php class methods: ftp_nlist() etc
		require_once "simple_html_dom.php";
			
		$url = html_entity_decode($url);        
		$trimmed_url = trim($url);
		if (strrpos($trimmed_url, "/") == strlen($trimmed_url) - 1) 
		{
			if (file_exists("temp.html")) unlink("temp.html"); 
			exec("wget -O temp.html ".$url);
			
			$html = file_get_html('temp.html');
			$dirs = $html->find('a[href]');
			foreach ($dirs as $dir) 
			{
6acb8d2a   Elena.Budnik   checkRequest in R...
44
45
46
				$name =  $dir->innertext; //$dir->href;
				$isLeaf = strrpos($name, "/") !== strlen($name) - 1;
				$childrenToReturn[] = array('text' => $name, 'id' => $trimmed_url.$name, 'nodeType' => 'url', 'leaf' => $isLeaf); 
735c653b   Elena.Budnik   rank at observato...
47
48
49
50
51
52
53
54
			}
			
		}
		
		return $childrenToReturn; 
	
	}
	
16035364   Benjamin Renard   First commit
55
56
57
58
/*****************************************************************
*                           PUBLIC FUNCTIONS
*****************************************************************/ 
 
735c653b   Elena.Budnik   rank at observato...
59
60
61
62
	/*
	*   $obj = { id: node.id,  nodeType: node.nodeType }
	*/
	public function getTree($obj) {
16035364   Benjamin Renard   First commit
63

735c653b   Elena.Budnik   rank at observato...
64
65
66
67
68
69
70
		$node = $obj->node;
		
		// to correct 'restricted' parameters  
		if (strpos($node, restricted) !== false) 
		{
			$node = str_replace(restricted,"",$node);
		}
16035364   Benjamin Renard   First commit
71

735c653b   Elena.Budnik   rank at observato...
72
73
74
		$nodeType = $obj->nodeType;
		$remoteBase = false;
		$isRemoteDataSet = false;
16035364   Benjamin Renard   First commit
75

735c653b   Elena.Budnik   rank at observato...
76
77
78
79
80
		if ($nodeType == 'url') 
		{
			$url = $node == 'root' ? $obj->baseId : $node;		   
			return  $this->getUrlDirs($url);
		}
16035364   Benjamin Renard   First commit
81

735c653b   Elena.Budnik   rank at observato...
82
		if ($obj->baseId) $remoteBase = true;
16035364   Benjamin Renard   First commit
83

735c653b   Elena.Budnik   rank at observato...
84
		if ($node == 'root' && $remoteBase)  $node = $obj->baseId;
16035364   Benjamin Renard   First commit
85

735c653b   Elena.Budnik   rank at observato...
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
		if ($node == 'root' && !$remoteBase)  
		{ 
			$json_o = json_decode(file_get_contents(DATAPATH.$nodeType.'.json'));
			$childrenToReturn = $json_o->nodes;	      
		}         
		else 
		{
			$Dom = new DomDocument("1.0");

			switch ($nodeType) 
			{
				case 'sharedtimeTable':
				case 'sharedcatalog':
					$xmlName = SHAREDPATH.'/SharedObjectTree.xml';
					break;
				case 'bkgWorks': 
					$xmlName = USERJOBDIR.$this->xmlFiles[$nodeType];
					break;
				case 'source':
					$xmlName = DATAPATH.'RemoteData/'.$obj->baseId.'/base.xml';		    
					break;
				case 'destination': 
					$xmlName = USERWSDIR.'RemoteParams.xml';		   
					break; 
				default:
					$xmlName = USERWSDIR.$this->xmlFiles[$nodeType];
			}
16035364   Benjamin Renard   First commit
113

735c653b   Elena.Budnik   rank at observato...
114
115
116
117
			if ($remoteBase)  
			{               
				$nodeType = 'remoteParam';
			} 		 
16035364   Benjamin Renard   First commit
118
           
735c653b   Elena.Budnik   rank at observato...
119
			$Dom->load($xmlName);
16035364   Benjamin Renard   First commit
120
             
735c653b   Elena.Budnik   rank at observato...
121
122
			if ($node == "myRemoteSimuData-treeRootNode") 
				$node = "myRemoteData-treeRootNode";
169f14d2   Benjamin Renard   Add shared object...
123
	    
735c653b   Elena.Budnik   rank at observato...
124
125
			$nodeToOpen = $Dom->getElementById($node);
			$children = $nodeToOpen->childNodes;
16035364   Benjamin Renard   First commit
126

735c653b   Elena.Budnik   rank at observato...
127
128
129
130
			foreach ($children as $child)  
				if ($child->nodeType == XML_ELEMENT_NODE) 
				{
					$isLeaf = true;
16035364   Benjamin Renard   First commit
131
	  
735c653b   Elena.Budnik   rank at observato...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
					if ($child->hasChildNodes())
						foreach ($child->childNodes as $grandChild)  
							if ($grandChild -> nodeType == XML_ELEMENT_NODE)  
							{
									$isLeaf = false;
									break;
							}
					if ($child->tagName == 'folder')  $isLeaf = false;

					//TODO MAKE PROPERLY  as function of nodetype !!!!    
					$info = ''; 
					$id =  $child->getAttribute('xml:id');
					$name = $child->getAttribute('name');                
					$help = $child->getAttribute('att');
					if ($child->hasAttribute('dataStart')) $dataStart = $child->getAttribute('dataStart');
					if ($child->hasAttribute('dataStop')) $dataStop = $child->getAttribute('dataStop');

					$specialNode = false;
					$isParameter = false;
					$isAddable =  false;
					$isSimulation = false;
					$rank = null;

					switch ($nodeType) 
					{
						case 'bkgWorks': 
							$specialNode = true;
							$status = $child->getAttribute('status');
							//     if ($status == 'done') continue;				 
							$childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType, 'leaf' => $isLeaf,
									'pid' => $child->getAttribute('pid'), 'status' => $status, 
									'jobType' => $child->getAttribute('jobType'), 'info' => $child->getAttribute('info'));
						break;

						case 'condition':
							$objectMgr = new RequestMgr();
							$info = $objectMgr->getObject($id)->expression;  
						break; 

						case 'request':						
						$objectMgr = new RequestMgr();
						$objplot = $objectMgr->getObject($id); 
						for ($i=0; $i < count($objplot->children); $i++) 
						{ 
							for ($j=0; $j < count($objplot->children[$i]->children); $j++) 
							{
								$info = $info.' '.$objplot->children[$i]->children[$j]->name;
							}
						}
						break; 

						case 'alias': 
							$info = $id;
							$id = 'alias_'.$id;
							if ($isLeaf) $isParameter = true;  
						break;

						case 'timeTable':
						case 'catalog':                   
							if ($isLeaf) $info = $child->getAttribute('intervals').' intervals';
						break;
						
						case 'sharedtimeTable':
						case 'sharedcatalog':
							if ($isLeaf) 
							{
								$info = '<b>Nb intervals:</b> '.$child->getAttribute('nbIntervals').'<br/>';
								$info .= '<b>Shared by:</b> '.$child->getAttribute('sharedBy').' ('.$child->getAttribute('sharedDate').')<br/>';
								$info .= '<b>Description:</b> '.$child->getAttribute('description');
							}
						break;
						case 'derivedParam':
							$info = $child->getAttribute('buildchain');
							if ($isLeaf) $isParameter = true;
						break;

						case 'localParam':

							$globalStart = null;
							$globalStop = null;
							$timeRestriction = false;
							$specialNode = true;
							$isParameter = false;
							$needsArgs = false;
							$isSpectra = false;                         
							$isStack = false;

							if ($child->hasAttribute('desc')) 
							{                        
								$info = $child->getAttribute('desc');
								
								if ($child->hasAttribute('dataStart') && $child->hasAttribute('dataStop')) 
								{				
									$info .= "<br/>Time Range: ".$child->getAttribute('dataStart')."-".$child->getAttribute('dataStop');                                
								}
								
								if ($child->getAttribute('dataStart') == 'depending on mission')
								{
									$info .= "<br/>Time Range: ".$child->getAttribute('dataStart');
								}                             
								
								if ($child->getAttribute('restriction') > 1) 
								{
									$restricted  = $child->getAttribute('restriction');
									$info .= "<br/><b>Time Restriction</b>: -$restricted days";
								}
							}
                                                  
							if ($child->hasAttribute('units')) $info = $child->getAttribute('units');

							if ($child->tagName == 'parameter') 
							{
								$isParameter = true;
								$isScatter = true;

								if ($child->parentNode->hasAttribute('dataStart'))
								{
									$globalStart = $child->parentNode->getAttribute('dataStart');
									$globalStop = $child->parentNode->getAttribute('dataStop');  
								}

								if ($child->parentNode->getAttribute('restriction') > 1 )
								{
									$timeRestriction = true;
										
								}					
								/*------------------- to show not tested parameters ------*/      
								if ($child->getAttribute('tbd'))
									$info .= "<br/><b>Not tested yet</b>";				
								/*------------------- --------------------------------------*/    				 	                                                                    
							}
aec5ba13   Elena.Budnik   not tested param ...
263
                        
735c653b   Elena.Budnik   rank at observato...
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
							$component_info = array();
							if ($child->tagName == 'component')
							{
								$isParameter = true;
								$isScatter = true;

								if ($child->parentNode->parentNode->hasAttribute('dataStart'))
								{
									$globalStart = $child->parentNode->parentNode->getAttribute('dataStart');
									$globalStop = $child->parentNode->parentNode->getAttribute('dataStop');  
								} 

								if ($child->parentNode->parentNode->getAttribute('restriction') > 1)
								{
									$timeRestriction = true;								
								} 

								if ($child->hasAttribute("index1"))
									$component_info["index1"] = $child->getAttribute('index1');
								if ($child->hasAttribute("index2"))
									$component_info["index2"] = $child->getAttribute('index2');
								
								$component_info["parentId"] = $child->parentNode->getAttribute('xml:id');
							}
16035364   Benjamin Renard   First commit
288
                      
735c653b   Elena.Budnik   rank at observato...
289
							if ($child->tagName == 'parameter' && $child->hasChildNodes()) $isScatter = false;
16035364   Benjamin Renard   First commit
290
                                                                                   
735c653b   Elena.Budnik   rank at observato...
291
292
293
294
295
296
297
298
299
300
301
302
303
304
							if ($child->tagName == 'parameter' && $child->hasAttribute('display_type')) 
							{
								if ($child->getAttribute('display_type') == 'spectrogram') 
								{
										$needsArgs = true;                                     
										$isSpectra = true; 
										$isScatter = false;
								}
								elseif ($child->getAttribute('display_type') == 'stackplot') 
								{                                    
										$isStack = true;
										$isScatter = false;
								}
							}  
16035364   Benjamin Renard   First commit
305
                
735c653b   Elena.Budnik   rank at observato...
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
							if ($isParameter) 
							{
								if ($child->tagName == 'parameter' && $child->childNodes->length == 1)
								{ 
									$needsArgs = true;                               
								}                                          
								if (substr($id,0,4) == 'bt96' || substr($id,0,6) == 'ba2000'|| substr($id,0,5) == 'bcain' || substr($id,0,7) == 'bmorsch' ) 
								{                              
									$needsArgs = true;
								}
							
								$objectMgr = new AliasMgr();
								$alias = $objectMgr->getAlias($id);
								
								$childrenToReturn[] = array('text' => $name,'alias' => $alias, 
									'id' => $id,'nodeType' => $nodeType, 'info' => $info, "component_info" => $component_info,
									'globalStart' => $globalStart, 'globalStop' => $globalStop, 'timeRestriction' => $timeRestriction,
									'leaf' => $isLeaf, 'isParameter' => $isParameter, 'isScatter' => $isScatter,
									'isSpectra' => $isSpectra,'isStack' => $isStack, 'needsArgs' => $needsArgs, 'help' => $help, 'notyet' => $not_yet);
							}
							else 
							{
								if ($child->tagName == 'mission' || $child->tagName == 'observatory') 
								{
									$disable = $child->hasAttribute('restriction');
									$rank = $child->getAttribute('rank');
								}
								else
								{
									$disable = $child->hasAttribute('restriction');
								}
								
								if ($disable)
								{
									if ($disable == 1) {
abda054b   Elena.Budnik   correct message
341
										$info .=  "<br/><b>Sorry ! Not finished yet...</b>";
735c653b   Elena.Budnik   rank at observato...
342
343
344
345
346
347
348
349
350
351
352
353
									}
									else {                                   
										$disable = false;                                     
									}
								}

								$childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType,  'info' => $info, 
									'leaf' => false, 'help' => $help, 'disable' => $disable, 'rank' => $rank);                               				    			 			   
							}
						break;

						case 'remoteSimuParam' :
bf74fc2d   Elena.Budnik   IMPEX
354
355
								
							$globalStart = null;
6657f68b   Elena.Budnik   monitor impex ser...
356
							$service_down = false;
735c653b   Elena.Budnik   rank at observato...
357
							$isSimulation = true;
bf74fc2d   Elena.Budnik   IMPEX
358
			           
6657f68b   Elena.Budnik   monitor impex ser...
359
			            if ($child->getAttribute('isAddable')) // 'spase://IMPEX/SimulationModel/FMI/GUMICS'							
735c653b   Elena.Budnik   rank at observato...
360
361
362
363
364
365
366
							{
								$isLeaf = false;
								$isAddable = true;
							}
			
							if ($child->tagName == 'dataCenter') 
							{
6657f68b   Elena.Budnik   monitor impex ser...
367
368
369
370
371
								if ($child->getAttribute('isSimulation')) 								
								{
									$service_down = !($child->getAttribute('available'));								
									break;									
								}
735c653b   Elena.Budnik   rank at observato...
372
373
374
375
376
377
378
379
380
381
382
								else 
								{
									$skip = true;
									break;
								}
							}
			
							if ($child->hasAttribute('rank')) 
							{
								$rank = $child->getAttribute('rank');
							}
bf74fc2d   Elena.Budnik   IMPEX
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
							
							if ( $child->tagName == 'parameter')
							{
								if ($child->parentNode->hasAttribute('globalStart'))
									{
										$globalStart = $child->parentNode->getAttribute('globalStart');
										$globalStop = $child->parentNode->getAttribute('globalStop');  
									}
							}
							
							if ( $child->tagName == 'component')
							{
								if ($child->parentNode->parentNode->hasAttribute('dataStart'))
									{
										$globalStart = $child->parentNode->parentNode->getAttribute('dataStart');
										$globalStop = $child->parentNode->parentNode->getAttribute('dataStop');  
									}
							}
							
735c653b   Elena.Budnik   rank at observato...
402
						case 'remoteParam' :
16035364   Benjamin Renard   First commit
403
                         
735c653b   Elena.Budnik   rank at observato...
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
							if ($child->getAttribute('isSimulation') && $child->tagName == 'dataCenter') 
							{
								$skip = true;
								break;
							}

							$isDeletable = $child->hasAttribute('isDeletable');
							$specialNode = true;
							$isParameter = false; 
							
							$isSpectra = false; 
		
							switch ($id)  
							{
								case 'CDAWEB'  : 
								case 'OMNIWEB' :  
									$isLeaf = false;
									break;
								case 'THEMIS' :
									$rank = 5;
									break;
								case 'MAPSKP' :
									$rank = 9;
									break;					
								default:
							}
16035364   Benjamin Renard   First commit
430
 
735c653b   Elena.Budnik   rank at observato...
431
432
433
434
435
							$info = $child->getAttribute('desc');

							if ($info && !$isSimulation) 
							{ 
								$info = str_replace(';', "<br/>Time Range: ", $info);
6657f68b   Elena.Budnik   monitor impex ser...
436
							}													
16035364   Benjamin Renard   First commit
437
			
735c653b   Elena.Budnik   rank at observato...
438
439
440
441
442
							if (($child->tagName == 'parameter') || ($child->tagName == 'component')) 
							{
								$isParameter = true;
								$isScatter = true;					   
							}
16035364   Benjamin Renard   First commit
443
			
9a63b7f6   Elena.Budnik   needsArgs to Simu...
444
							$needsArgs =  $child->getAttribute('needsArgs');
735c653b   Elena.Budnik   rank at observato...
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464

							if (($child->tagName == 'parameter' && $child->hasChildNodes()) || $needsArgs) $isScatter = false;
							
							if ($remoteBase) 
							{
								if ($child->tagName == 'dataset') $isRemoteDataSet = true; 
							}

							if ($isParameter) 
							{
								$disable = $child->parentNode->getAttribute('disabled');			   			  
								$objectMgr = new AliasMgr();
								$alias = $objectMgr->getAlias($id);

								if ($child->hasAttribute('display_type') && $child->getAttribute('display_type') == 'spectrogram')
								{
									$needsArgs = true; 
									$isScatter = false;
									$isSpectra = true;
								}       
bf74fc2d   Elena.Budnik   IMPEX
465
466
467
468
469
470
471
472
473
474
								if ($globalStart)
								 $childrenToReturn[] = array('text' => $name,'alias' => $alias, 
										'id' => $id,'nodeType' => $nodeType,  'info' => $info, 'help' => $help,  'globalStart' => $globalStart,
										'globalStop' => $globalStop, 'leaf' => $isLeaf, 'disable' => $disable, 'isParameter' => $isParameter, 
										'isScatter' => $isScatter, 'isSpectra' => $isSpectra, 'needsArgs' => $needsArgs, "component_info" => $component_info);
								else
									$childrenToReturn[] = array('text' => $name,'alias' => $alias, 
										'id' => $id,'nodeType' => $nodeType,  'info' => $info, 'help' => $help,
										'leaf' => $isLeaf, 'disable' => $disable, 'isParameter' => $isParameter, 
										'isScatter' => $isScatter, 'isSpectra' => $isSpectra, 'needsArgs' => $needsArgs, "component_info" => $component_info);
735c653b   Elena.Budnik   rank at observato...
475
476
477
							}
							else 
							{ 
6657f68b   Elena.Budnik   monitor impex ser...
478
479
480
481
482
483
484
// 								if ($child->tagName == 'dataCenter')   
// 								{
// 									$restricted = ($child->getAttribute('available') != "1");									
// 								}
// 								else
// 									$restricted = false;
// 									
6acb8d2a   Elena.Budnik   checkRequest in R...
485
486
								if ($id == 'CDAWEB' || $id == 'THEMIS'|| $id == 'MAPSKP') 
									$restricted = FALSE;																
6657f68b   Elena.Budnik   monitor impex ser...
487
							
735c653b   Elena.Budnik   rank at observato...
488
								if ($child->tagName == 'dataset')
6657f68b   Elena.Budnik   monitor impex ser...
489
								{
735c653b   Elena.Budnik   rank at observato...
490
									$nonavailable = ($child->getAttribute('disabled'));
6657f68b   Elena.Budnik   monitor impex ser...
491
								}
735c653b   Elena.Budnik   rank at observato...
492
								else
6657f68b   Elena.Budnik   monitor impex ser...
493
								{
735c653b   Elena.Budnik   rank at observato...
494
									$nonavailable = false;
6657f68b   Elena.Budnik   monitor impex ser...
495
								}
735c653b   Elena.Budnik   rank at observato...
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
								
								if ($nonavailable)
									$info .= "<br/><b>Not available yet</b>";

								if ($child->getAttribute('url'))
									$info .= "<br/>".$child->getAttribute('url');

								if ($child->hasAttribute('obsolete')) 
								{
									$info = $child->getAttribute('desc');
									$obsolete = true;
								}
								else
									$obsolete = false;

								$disable = $restricted || $nonavailable || $obsolete;
													
								$childrenToReturn[] = array('text' => $name, 'id' => $id,'nodeType' => $nodeType,  'isAddable' => $isAddable,
								'info' => $info, 'leaf' => false, 'isRemoteDataSet' => $isRemoteDataSet, 'disable' => $disable, 
								'isSimulation' => $isSimulation, 'rank' => $rank, 'isDeletable' => $isDeletable, 'help' => $help);				    			 			   
							}			
						break;
						
						case 'myData' :  
							$info = $child->hasAttribute('info') ? $child->getAttribute('info') : $child->nodeValue;			 
						break;

						case 'myDataParam' :

							$globalStart = null;
							$globalStop = null;
							$specialNode = true;
							$size = $child->getAttribute('size');
							$isScatter = $size == 1;
							$mask = $child->getAttribute('mask');
							$isSpectra = false;
16035364   Benjamin Renard   First commit
532
                        
735c653b   Elena.Budnik   rank at observato...
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
							if ($isLeaf) 
							{
									$isParameter = true;
									$info = "Size: ".$size."<br/>".$child->getAttribute('desc')."<br/> Mask: ".$mask;
									$isSpectra = $child->getAttribute('plottype') === 'Spectra';
							}

							if ($child->hasAttribute('desc')) 
							{
									$globalStart = substr($child->getAttribute('desc'), 0, 19);
									$globalStop =  substr($child->getAttribute('desc'), 20);
							}

							$childrenToReturn[] = array('text' => $name, 'size' =>  $size, 'id' => $id,  
								'globalStart' => $globalStart, 'globalStop' => $globalStop,
								'nodeType' => $nodeType, 'info' => $info, 'isScatter' => $isScatter, 'leaf' => $isLeaf, 
								'isParameter' => $isParameter, 'linkedMask' => $mask, 'isSpectra' => $isSpectra);

						break;
						default: 
					}
16035364   Benjamin Renard   First commit
554
	
735c653b   Elena.Budnik   rank at observato...
555
556
					if (!$specialNode && !$skip) 
					{
6657f68b   Elena.Budnik   monitor impex ser...
557
						if ($child->hasAttribute('desc')) 
735c653b   Elena.Budnik   rank at observato...
558
							$info = $child->getAttribute('desc');
6657f68b   Elena.Budnik   monitor impex ser...
559
560
561
562
563
564
						
						if ($isSimulation && $service_down)					
						{
							$info = "<b>Service is currently down</b>";
						}
											
735c653b   Elena.Budnik   rank at observato...
565
						$childrenToReturn[] = array('text' => $name, 'id' => $id, 'nodeType' => $nodeType, 'info' => $info, 
6657f68b   Elena.Budnik   monitor impex ser...
566
													'help' => $help, 'leaf' => $isLeaf, 'isParameter' => $isParameter);
735c653b   Elena.Budnik   rank at observato...
567
568
569
570
571
572
573
574
					}
				}
				// if $childrenToReturn we have to return []
				if ($childrenToReturn == null) 
				{			
					$childrenToReturn = array('nodeType' => $nodeType, 'text' => null);
				}
			}
16035364   Benjamin Renard   First commit
575
      return  $childrenToReturn;
735c653b   Elena.Budnik   rank at observato...
576
	}
16035364   Benjamin Renard   First commit
577

735c653b   Elena.Budnik   rank at observato...
578
579
580
581
582
	public  function saveTree($obj) 
	{
		$paramMgr = new ParamMgr();
		return $paramMgr->saveTree($obj);            
	}
16035364   Benjamin Renard   First commit
583

9a63b7f6   Elena.Budnik   needsArgs to Simu...
584
585
586
587
588
	public  function doNothing($obj) 
	{	    
		return array("res" => 'ok');
		
	}
16035364   Benjamin Renard   First commit
589

9a63b7f6   Elena.Budnik   needsArgs to Simu...
590
591
592
593
594
	public  function deleteFromTree($obj) 
	{    
		$paramMgr = new ParamMgr();
		return $paramMgr->deleteFromTree($obj);		
	}
16035364   Benjamin Renard   First commit
595
596
597
598

/*
*  temporary object fromUpload
*/ 
9a63b7f6   Elena.Budnik   needsArgs to Simu...
599
600
601
602
603
604
605
606
607
608
	public  function getUploadedObject($name, $format, $nodeType)
	{  
		switch ($nodeType) 
		{
			case 'timeTable' : 
				$objectMgr = new TimeTableMgr();		  
				break;
			case 'myDataParam' : 
				$objectMgr = new FilesMgr();			  	  
				break;
901ba3f3   Elena.Budnik   upload catalog
609
610
611
			case 'catalog' : 
				$objectMgr = new CatalogMgr();		  
				break;	
9a63b7f6   Elena.Budnik   needsArgs to Simu...
612
613
614
			default:
				return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
		}
901ba3f3   Elena.Budnik   upload catalog
615
		 
bf74fc2d   Elena.Budnik   IMPEX
616
		return  $objectMgr->getUploadedObject($name, $format, true);
9a63b7f6   Elena.Budnik   needsArgs to Simu...
617
618

	}	
16035364   Benjamin Renard   First commit
619
620
621
622

/*
*  fill ascii file into grid 
*/ 
735c653b   Elena.Budnik   rank at observato...
623
624
625
	public  function getAsciiFile($obj) 
	{  
		$objectMgr = new FilesMgr();			  	  			
bf74fc2d   Elena.Budnik   IMPEX
626
		return  $objectMgr->getAsciiFile($obj->fileName);
735c653b   Elena.Budnik   rank at observato...
627
	}
16035364   Benjamin Renard   First commit
628
	
bf74fc2d   Elena.Budnik   IMPEX
629
	public function getMyParamInfo($object) 
735c653b   Elena.Budnik   rank at observato...
630
631
	{   	     
		$objectMgr = new FilesMgr();			  	   	 
bf74fc2d   Elena.Budnik   IMPEX
632
		return  $objectMgr->getParamInfo($object);
735c653b   Elena.Budnik   rank at observato...
633
	}	
16035364   Benjamin Renard   First commit
634
635
636
637

/*
*  temporary object from Search 
*/ 
735c653b   Elena.Budnik   rank at observato...
638
639
640
641
642
643
	public  function getTmpObject($folderId, $name, $nodeType) 
	{   
		switch ($nodeType) 
		{
			case 'timeTable' : 
				$objectMgr = new TimeTableMgr();		  
fdf1413b   Elena.Budnik   TT download
644
			break; 
735c653b   Elena.Budnik   rank at observato...
645
646
647
648
649
650
			case 'catalog' :
				$objectMgr = new CatalogMgr();		  
			break; 	   
			default:
				return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
		}
bf74fc2d   Elena.Budnik   IMPEX
651
		return  $objectMgr->getTmpObject($folderId, $name, true);
fdf1413b   Elena.Budnik   TT download
652
	}
735c653b   Elena.Budnik   rank at observato...
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
 

	public  function getObject($id, $nodeType) 
	{  	
		switch ($nodeType) 
		{
			case 'myDataParam':
			case 'derivedParam' : 
				$objectMgr = new DerivedParamMgr($nodeType);			   
				break;
			case 'timeTable' : 
			case 'sharedtimeTable' :
				$objectMgr = new TimeTableMgr();			  
				break;  
			case 'catalog' :
			case 'sharedcatalog' :
				$objectMgr = new CatalogMgr();			  
				break; 
			case 'condition' : 		  
			case 'request' :
				$objectMgr = new RequestMgr($nodeType);			  
				break; 
			case 'bkgWorks' :
bf74fc2d   Elena.Budnik   IMPEX
676
 				require_once(INTEGRATION_SRC_DIR."RequestManager.php");
735c653b   Elena.Budnik   rank at observato...
677
678
679
680
681
682
683
684
				return $this->executeRequest($id, FunctionTypeEnumClass::PROCESSGETINFO);
				break;
			case 'myData' :
				$objectMgr = new FilesMgr();			  
				break;
			default:		
				return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
		}
bf74fc2d   Elena.Budnik   IMPEX
685
		return  $objectMgr->getObject($id, $nodeType);
fdf1413b   Elena.Budnik   TT download
686
	}
735c653b   Elena.Budnik   rank at observato...
687
	
16035364   Benjamin Renard   First commit
688
689
690
/*
*   $obj = { id: node.id, leaf: node.leaf, nodeType: node.nodeType }
*/
735c653b   Elena.Budnik   rank at observato...
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
	public  function deleteObject($obj) 
	{   
		switch ($obj->nodeType) 
		{  		
			case 'myDataParam' : 
			case 'derivedParam' : 
				$objectMgr = new DerivedParamMgr($obj->nodeType);			   
				break;
			case 'timeTable' : 
				$objectMgr = new TimeTableMgr();			  
				break; 
			case 'catalog' : 
				$objectMgr = new CatalogMgr();			  
				break;
			case 'condition' : 		  
			case 'request' :
				$objectMgr = new RequestMgr($obj->nodeType);			  
				break;
			case 'alias' :
				$objectMgr = new AliasMgr();
				$obj->id = substr($obj->id,strlen('alias_'));
				break;   
			case 'bkgWorks' :
bf74fc2d   Elena.Budnik   IMPEX
714
 				require_once(INTEGRATION_SRC_DIR."RequestManager.php");
735c653b   Elena.Budnik   rank at observato...
715
716
717
				return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSDELETE);

			case 'myData' :
16035364   Benjamin Renard   First commit
718
				$objectMgr = new FilesMgr();
735c653b   Elena.Budnik   rank at observato...
719
720
721
722
723
724
				break;
			default:
					return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
		}
		return  $objectMgr -> deleteObject($obj);
	}
16035364   Benjamin Renard   First commit
725
726
727
728

/*
*   $obj = { id: node.id, old_name: node.text, name: value,  parent : node.parentNode.id, leaf: node.leaf, nodeType: node.nodeType }
*/
735c653b   Elena.Budnik   rank at observato...
729
730
731
732
	public  function renameObject($obj) 
	{   
		switch ($obj->nodeType) 
		{
16035364   Benjamin Renard   First commit
733
734
735
736
737
738
739
		  
		  case 'myDataParam' :
		  case 'derivedParam' : 
			   $objectMgr = new DerivedParamMgr($obj->nodeType);			   
			   break;
		  case 'timeTable' : 
			   $objectMgr = new TimeTableMgr();			  
d18b535d   elena   catalog draft + c...
740
741
			   break;
		  case 'catalog' : 
255e4546   elena   bug in cat rename
742
			   $objectMgr = new CatalogMgr();			  
16035364   Benjamin Renard   First commit
743
744
745
746
747
748
749
750
751
752
			   break;		  
		  case 'condition' : 
		  case 'request' : 
			   $objectMgr = new RequestMgr($obj->nodeType);			  
			   break;
		  case 'alias' :
		  	   $objectMgr = new AliasMgr();  
		  	   break;   
		  default:
			    return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
735c653b   Elena.Budnik   rank at observato...
753
		}
16035364   Benjamin Renard   First commit
754

735c653b   Elena.Budnik   rank at observato...
755
756
		return  $objectMgr -> renameObject($obj);
	}
16035364   Benjamin Renard   First commit
757
758
759
760

/*   
*   $obj = { name: obj.name, obj.nodeType, obj.leaf (??), OBJ DEPENDENT ATTRIBUTES }
*/
9a63b7f6   Elena.Budnik   needsArgs to Simu...
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
	public  function createObject($obj, $folder) 
	{   
		switch ($obj->nodeType) 
		{
			case 'myDataParam' :                           
			case 'derivedParam' :
				if ($obj->nodeType == 'derivedParam' &&  $this->amdaStat->success) 
						$this->amdaStat->addTask('create', $this->user, null);
				$objectMgr = new DerivedParamMgr($obj->nodeType);			   
				break;		  
			case 'timeTable' : 
				$objectMgr = new TimeTableMgr();			  
				break; 
			case 'catalog' : 
				$objectMgr = new CatalogMgr();			  
16035364   Benjamin Renard   First commit
776
			   break;
9a63b7f6   Elena.Budnik   needsArgs to Simu...
777
778
779
780
781
782
783
784
785
786
787
788
			case 'condition' :
			case 'request' : 
				$objectMgr = new RequestMgr($obj->nodeType);			  
				break;		
			case 'alias' :
				$objectMgr = new AliasMgr();  
				break;   
			default:
				return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
		}
		return  $objectMgr -> createObject($obj, $folder);
	}
16035364   Benjamin Renard   First commit
789
790
791
792

/*   
*   $obj = { id:obj.id, name: obj.name, obj.nodeType, obj.leaf (??), OBJ DEPENDENT ATTRIBUTES }
*/
9a63b7f6   Elena.Budnik   needsArgs to Simu...
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
	public  function modifyObject($obj) 
	{
		switch ($obj->nodeType) 
		{  
			case 'myDataParam' : 
			case 'derivedParam' : 
				$objectMgr = new DerivedParamMgr($obj->nodeType);			   
				break;
			case 'timeTable' : 
				$objectMgr = new TimeTableMgr();			  
				break;
			case 'catalog' : 
				$objectMgr = new CatalogMgr();			  
				break;  	   
			case 'condition' : 
			case 'request' :
				$objectMgr = new RequestMgr($obj->nodeType);			  
				break;
			default:
				return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
		}
		return  $objectMgr -> modifyObject($obj);
	}   
16035364   Benjamin Renard   First commit
816
817
818
819
820
821
822
823
824
825
/*
 * {obj.name, obj.nodeType, obj.leaf}
 */
    public function validNameObject($obj) {
		switch ($obj->nodeType) {
			case 'myDataParam' :
			case 'derivedParam' :
				$objectMgr = new DerivedParamMgr($obj->nodeType);
				break;
			case 'timeTable' :
d18b535d   elena   catalog draft + c...
826
			case 'sharedtimeTable' :
16035364   Benjamin Renard   First commit
827
828
				$objectMgr = new TimeTableMgr();
				break;
d18b535d   elena   catalog draft + c...
829
			case 'catalog' :
169f14d2   Benjamin Renard   Add shared object...
830
			case 'sharedcatalog' :
d18b535d   elena   catalog draft + c...
831
832
				$objectMgr = new CatalogMgr();
				break;
16035364   Benjamin Renard   First commit
833
834
835
836
837
838
839
840
841
842
843
844
845
846
			case 'condition' :
			case 'request' :
				$objectMgr = new RequestMgr($obj->nodeType);
				break;
			default:
				return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
		}

		return  $objectMgr -> validNameObject($obj);
    }

/*
*   Get Jobs en cours
*/
6acb8d2a   Elena.Budnik   checkRequest in R...
847
848
849
850
851
	public  function getJobs()
	{
		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
		return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSRUNNINGINFO);  
	}
16035364   Benjamin Renard   First commit
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866


	/* AKKA-KERNEL-INT
	Move user check from RequestMgr.php to AmdaAction.php
	*/
	private function checkUser($obj)
	{
		if (defined('NEWKERNEL_DEBUG') && NEWKERNEL_DEBUG)
		{
			$this->user = NEWKERNEL_DEBUG_USER;
			return array('success' => true);
		}
			
		
		if (isset($obj->username) && isset($obj->password) && isset($obj->sessionID))
735c653b   Elena.Budnik   rank at observato...
867
		{
16035364   Benjamin Renard   First commit
868
869
870
			//$dd = new WSUserMgr();
            //$dd->init($obj->username,$obj->password,$obj->sessionID);
			return array('success' => false, "message" => "AKKA-KERNEL-INT - WS support not implemented");
735c653b   Elena.Budnik   rank at observato...
871
872
		}
		else
16035364   Benjamin Renard   First commit
873
874
			$dd = new UserMgr();
			
735c653b   Elena.Budnik   rank at observato...
875
876
		//TODO error handling 
		if (($res = $dd -> ddCheckUser()) != 0)
16035364   Benjamin Renard   First commit
877
878
		{
			if ($res == 156) 
6acb8d2a   Elena.Budnik   checkRequest in R...
879
				return array('success' => false, 'message' => 'Your AMDA session is expired.<br/> Login please!');
16035364   Benjamin Renard   First commit
880

735c653b   Elena.Budnik   rank at observato...
881
882
			return array('success' => false, 'message' => 'ddLogin error: '.$res);
		}
16035364   Benjamin Renard   First commit
883

6acb8d2a   Elena.Budnik   checkRequest in R...
884
		if ($dd->user == 'impex')
16035364   Benjamin Renard   First commit
885
886
887
888
		{
			//if ($dd->getWsSize() > DISK_QUOTA * 100)
			//	error_log('Natacha! It is time to CLEAN UP IMPEX WS!',1,'nbourrel@irap.omp.eu');
			return array('success' => false, "message" => "AKKA-KERNEL-INT - WS support for IMPEx not implemented");
6acb8d2a   Elena.Budnik   checkRequest in R...
889
890
		}
		else
16035364   Benjamin Renard   First commit
891
		{
6acb8d2a   Elena.Budnik   checkRequest in R...
892
893
		// check disk space
			if ($dd->getWsSize() > DISK_QUOTA)
16035364   Benjamin Renard   First commit
894
				return array('success' => false, 'message' => 'Please clean up your workspace.<br/>No more space is available');
735c653b   Elena.Budnik   rank at observato...
895
		}
16035364   Benjamin Renard   First commit
896
		
735c653b   Elena.Budnik   rank at observato...
897
		$this->user = $dd->user;
16035364   Benjamin Renard   First commit
898
899
900
901
        
		return array('success' => true, 'userHost' => $dd -> getIPclient());
	}
	
6acb8d2a   Elena.Budnik   checkRequest in R...
902
903
904
905
	private function executeRequest($obj, $function)
	{		
		$res = $this->checkUser($obj);		
		if (!$res['success']) return $res;
fdf1413b   Elena.Budnik   TT download
906
	
16035364   Benjamin Renard   First commit
907
908
		$requestManager = new RequestManagerClass();
		
6acb8d2a   Elena.Budnik   checkRequest in R...
909
910
		try 
		{
16035364   Benjamin Renard   First commit
911
			$res = $requestManager->runIHMRequest($this->user, $res['userHost'], $function, $obj);
6acb8d2a   Elena.Budnik   checkRequest in R...
912
913
		} catch (Exception $e) 
		{
16035364   Benjamin Renard   First commit
914
			return array('success' => false, 'message' => 'Exception detected : '.$e->getMessage());
6acb8d2a   Elena.Budnik   checkRequest in R...
915
		}		
16035364   Benjamin Renard   First commit
916
917
918
919
920
921
		return $res;
	}
	
/*   
*    Main EXECUTE PROCEDURE 
*/
735c653b   Elena.Budnik   rank at observato...
922
923
	public  function execute($node, $obj)
	{
16035364   Benjamin Renard   First commit
924
		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
fdf1413b   Elena.Budnik   TT download
925
926
927
928
929
		
		// just convert TT / Catalog
		if ($obj->nodeType == "download" &&  $obj->downloadSrc == "1")
			return $this->executeRequest($obj, FunctionTypeEnumClass::TTCONVERT);
		else if (isset($obj->action))
16035364   Benjamin Renard   First commit
930
			return $this->executeRequest($obj, FunctionTypeEnumClass::ACTION);
6acb8d2a   Elena.Budnik   checkRequest in R...
931
932
933
934
935
		else 
		{		 
			$res = RequestMgr::checkRequest($obj);
			if (!$res['success']) return $res;
				
16035364   Benjamin Renard   First commit
936
			return $this->executeRequest($obj, FunctionTypeEnumClass::PARAMS);
6acb8d2a   Elena.Budnik   checkRequest in R...
937
		}
fdf1413b   Elena.Budnik   TT download
938
	}
16035364   Benjamin Renard   First commit
939
940
    
/*
a0b3d64e   Benjamin Renard   Derived parameter...
941
942
 * Generate derived parameter compilation
 */
735c653b   Elena.Budnik   rank at observato...
943
944
945
946
947
	public function compilParam($obj)
	{
		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
		return $this->executeRequest($obj, FunctionTypeEnumClass::PARAMSGEN);
	}
a0b3d64e   Benjamin Renard   Derived parameter...
948
949
950
951

/*
 * Delete derived parameter compilation
 */
735c653b   Elena.Budnik   rank at observato...
952
953
	public function compilParamDelete($obj)
	{
a0b3d64e   Benjamin Renard   Derived parameter...
954
955
956
957
958
959
960
961
962
963
		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
		$res = $this->checkUser($obj);
		
		if (!$res['success'])
			return $res;
		
		IHMConfigClass::setUserName($this->user);
		$libParamPath = IHMConfigClass::getCompilationPath()."lib/".$obj->paramId.".so";
		if (file_exists($libParamPath))
			unlink($libParamPath);
735c653b   Elena.Budnik   rank at observato...
964
965
966
		return array("success" => true);
	}
	
a0b3d64e   Benjamin Renard   Derived parameter...
967
/*
e6e5b259   Benjamin Renard   Add kill plot req...
968
 * kill plot process
16035364   Benjamin Renard   First commit
969
970
 */
    
735c653b   Elena.Budnik   rank at observato...
971
972
973
974
975
	public function killPlotRequest()
	{   
		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
		return $this->executeRequest((object) array('nodeType' => 'killplot'), FunctionTypeEnumClass::PARAMS);
	}
16035364   Benjamin Renard   First commit
976
977
978
979

/*
 * merge time tables
 */
735c653b   Elena.Budnik   rank at observato...
980
981
982
983
984
985
	public  function merge($obj)   
	{
		if ($this->amdaStat->success)
			$this->amdaStat->addTask('ttoper', $this->user, null);
					
		$objectMgr = new TimeTableMgr();
16035364   Benjamin Renard   First commit
986

735c653b   Elena.Budnik   rank at observato...
987
988
		return  $objectMgr -> merge($obj);
	}
16035364   Benjamin Renard   First commit
989

735c653b   Elena.Budnik   rank at observato...
990
	
16035364   Benjamin Renard   First commit
991
992
993
/*
 * intersect time tables
 */
735c653b   Elena.Budnik   rank at observato...
994
995
996
997
	public  function intersect($obj)   
	{
		if ($this->amdaStat->success)
				$this->amdaStat->addTask('ttoper', $this->user, null);
16035364   Benjamin Renard   First commit
998

735c653b   Elena.Budnik   rank at observato...
999
1000
		$objectMgr = new TimeTableMgr();
		$result = $objectMgr -> intersect($obj);
16035364   Benjamin Renard   First commit
1001

735c653b   Elena.Budnik   rank at observato...
1002
1003
		return  $result;
	}
d18b535d   elena   catalog draft + c...
1004
        
735c653b   Elena.Budnik   rank at observato...
1005
1006
1007
1008
1009
1010
1011
	public function initTTCache($isCatalog = false, $nparams)
	{
		if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr();
		else              $cacheMgr = new CatalogCacheMgr();
		
		return $cacheMgr->initTTCache($nparams);
	}
16035364   Benjamin Renard   First commit
1012
        
86263051   elena   visu second draft
1013
        
735c653b   Elena.Budnik   rank at observato...
1014
1015
1016
1017
	public function initTTCacheFromTT($id, $type)
	{
		if ($type == 'catalog' || $type == 'sharedcatalog') $cacheMgr = new CatalogCacheMgr();
		else $cacheMgr = new TimeTableCacheMgr();
d18b535d   elena   catalog draft + c...
1018
		
735c653b   Elena.Budnik   rank at observato...
1019
1020
		return $cacheMgr->initFromTT($id, $type);
	}
16035364   Benjamin Renard   First commit
1021
        
735c653b   Elena.Budnik   rank at observato...
1022
1023
1024
1025
1026
1027
1028
1029
1030
	public function initForChart($id, $name, $isTmpObject, $type)
	{
		if ($type == 'catalog' || $type == 'sharedcatalog') $objMgr = new CatalogMgr();
									
		return $objMgr->initForChart($id, $name, $isTmpObject, $type);
	}
		
	public function initTTCacheFromTmpObject($folderId, $name, $isCatalog = false)
	{
901ba3f3   Elena.Budnik   upload catalog
1031
		if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr();				
735c653b   Elena.Budnik   rank at observato...
1032
1033
1034
1035
		else  $cacheMgr = new CatalogCacheMgr();

		return $cacheMgr->initFromTmpObject($folderId, $name);
	}
16035364   Benjamin Renard   First commit
1036
        
901ba3f3   Elena.Budnik   upload catalog
1037
	public function initTTCacheFromUploadedFile($name, $format, $isCatalog = false)
735c653b   Elena.Budnik   rank at observato...
1038
	{
901ba3f3   Elena.Budnik   upload catalog
1039
1040
1041
		if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr();
		else  $cacheMgr = new CatalogCacheMgr();
		
735c653b   Elena.Budnik   rank at observato...
1042
1043
		return $cacheMgr->initFromUploadedFile($name, $format);
	}
86263051   elena   visu second draft
1044
        
735c653b   Elena.Budnik   rank at observato...
1045
1046
1047
1048
1049
1050
1051
	public function readTTCacheIntervals($o)
	{
		if ($o->typeTT == 'catalog' || $type == 'sharedcatalog') $cacheMgr = new CatalogCacheMgr();
		else $cacheMgr = new TimeTableCacheMgr();
		
		return $cacheMgr->getIntervals($o->start,$o->limit,$o->sort,$o->filter);
	}
86263051   elena   visu second draft
1052
        
735c653b   Elena.Budnik   rank at observato...
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
	public function readIntervalsForChart($o)
	{
		if ($o->typeTT == 'catalog' || $type == 'sharedcatalog') $objMgr = new CatalogMgr();
					
		return $objMgr->getIntervalsForChart($o->id, $o->name, $o->fromPlugin, $o->typeTT);
	}
		
	public function saveTTCacheIntervalsInTT($o)
	{
		$cacheMgr = new TimeTableCacheMgr();
		return $cacheMgr->saveInTT($o->ttId,$o->action,$o->cacheToken);
	}
16035364   Benjamin Renard   First commit
1065
        
735c653b   Elena.Budnik   rank at observato...
1066
1067
1068
1069
1070
1071
1072
	public function addTTCacheInterval($o)
	{
		if ($o->isCatalog) $cacheMgr = new CatalogCacheMgr();
		else $cacheMgr = new TimeTableCacheMgr();

		return $cacheMgr->addInterval($o->index, $o->start, $o->stop);
	}
16035364   Benjamin Renard   First commit
1073
        
735c653b   Elena.Budnik   rank at observato...
1074
1075
1076
1077
1078
1079
1080
	public function removeTTCacheIntervalFromId($id, $isCatalog = false)
	{
		if ($isCatalog) $cacheMgr = new CatalogCacheMgr();
		else $cacheMgr = new TimeTableCacheMgr();

		return $cacheMgr->removeIntervalFromId($id);
	}
16035364   Benjamin Renard   First commit
1081
        
735c653b   Elena.Budnik   rank at observato...
1082
1083
1084
1085
	public function modifyTTCacheInterval($o)
	{
		if ($o->isCatalog) 
		{
f9c8b272   elena   edit catalog
1086
			$cacheMgr = new CatalogCacheMgr();
735c653b   Elena.Budnik   rank at observato...
1087
			return $cacheMgr->modifyIntervalFromId($o);
f9c8b272   elena   edit catalog
1088
		}
735c653b   Elena.Budnik   rank at observato...
1089
1090
1091
1092
		else $cacheMgr = new TimeTableCacheMgr();
			
		return $cacheMgr->modifyIntervalFromId($o->cacheId, $o->start, $o->stop);
	}
16035364   Benjamin Renard   First commit
1093
        
735c653b   Elena.Budnik   rank at observato...
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
	public function operationTTCacheIntervals($extendTime, $shiftTime)
	{
		$cacheMgr = new TimeTableCacheMgr();
		return $cacheMgr->operationIntervals($extendTime, $shiftTime);
	}
	
	public function mergeTTCacheIntervals()
	{
		$cacheMgr = new TimeTableCacheMgr();
		return $cacheMgr->mergeIntervals();
	}
	
	public function getTTCacheStatistics()
	{
		$cacheMgr = new TimeTableCacheMgr();
		return $cacheMgr->getStatistics();
	}
		
	public function getTTCacheStatus()
	{
		$cacheMgr = new TimeTableCacheMgr();
		return $cacheMgr->getStatus();
	}
aa94fd24   elena   Merge with last svn
1117

16035364   Benjamin Renard   First commit
1118
1119
1120
1121
/*
 * Send a feedback
 * 
 */
735c653b   Elena.Budnik   rank at observato...
1122
1123
1124
1125
1126
	public function sendFeedback($feed)
	{
		$feedMgr = new FeedbackMgr();
		return $feedMgr->addFeedback($feed->user, $feed->interface, $feed->subject, $feed->userText, $feed->userAgent, $feed->attach);
	}
16035364   Benjamin Renard   First commit
1127
1128
1129
1130
1131
    
/*
 * Save state
 * 
 */
735c653b   Elena.Budnik   rank at observato...
1132
1133
1134
1135
1136
	public function saveState($datas)
	{
		$myStateMgr = new StateMgr();
		return $myStateMgr->saveState($datas);
	}
16035364   Benjamin Renard   First commit
1137
1138
1139
1140
1141
    
/*
 * Load state
 * 
 */    
735c653b   Elena.Budnik   rank at observato...
1142
1143
1144
1145
1146
	public function loadState($o)
	{	
		$myStateMgr = new StateMgr();
		return $myStateMgr->loadState();
	}
16035364   Benjamin Renard   First commit
1147
1148
1149
1150
	
/* 
 * SAMP
 */
735c653b   Elena.Budnik   rank at observato...
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
	public function sendToSAMP($o)
	{                
		if ($this->amdaStat->success)
			$this->amdaStat->addTask('samp', $this->user, null);

		$objectMgr = new RequestMgr();
		$res = $objectMgr->generateVOTableFromDownloadResult($o->folderId, $o->downId,true,true);
		if ($res['success'])
		{
			foreach ($res['files'] as $key => $value)
			$res['files'][$key] = str_replace(BASE_PATH,"",$value);
		}
		return $res;
	}

16035364   Benjamin Renard   First commit
1166
1167
1168
/*
 * HST Images
 */
735c653b   Elena.Budnik   rank at observato...
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
	public function getHstImagesUrl($o)
	{
		if ($this->amdaStat->success)
			$this->amdaStat->addTask('images', $this->user, null);
		
		$myHstMgr = new HstMgr();
		$res = $myHstMgr->getImagesUrl($o->startTime, $o->stopTime, $o->planet);
		//if ($domRes->length <= 0)
		//	return array('success' => false, 'message' => 'Cannot find HST Images for this request.');
		return array('success' => true, 'result' => $res);
	}
16035364   Benjamin Renard   First commit
1180
	
735c653b   Elena.Budnik   rank at observato...
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
	public function getAPISImagesUrl($o)
	{
		if ($this->amdaStat->success) 
			$this->amdaStat->addTask('images', $this->user, null);
			
		$apisMgr = new APISMgr();
		$res = $apisMgr->get($o->target, $o->startTime, $o->stopTime, $o->datasets);

		return $res;
	}	
16035364   Benjamin Renard   First commit
1191
1192
1193
/*
 * Filters
 */
735c653b   Elena.Budnik   rank at observato...
1194
1195
1196
1197
1198
1199
	public function loadFilterList($o)
	{
		$filtersMgr = new FiltersMgr(); 
		$res = $filtersMgr->loadList();
		return $res;
	}
16035364   Benjamin Renard   First commit
1200

735c653b   Elena.Budnik   rank at observato...
1201
1202
1203
1204
1205
1206
1207
1208
1209
	public function loadFilters($o)
	{
		$filtersMgr = new FiltersMgr();
		if (isset($o->id))
			$res = $filtersMgr->loadFilter($o->id);
		else
			$res = $filtersMgr->loadAll();
		return $res;
	}
16035364   Benjamin Renard   First commit
1210
	
735c653b   Elena.Budnik   rank at observato...
1211
1212
1213
1214
1215
	public function saveFilter($o)
	{
		$filtersMgr = new FiltersMgr();		
		return $filtersMgr->save($o);
	}
16035364   Benjamin Renard   First commit
1216
	
735c653b   Elena.Budnik   rank at observato...
1217
1218
1219
1220
1221
	public function createFilter($o)
	{
		$filtersMgr = new FiltersMgr();		
		return $filtersMgr->create($o);
	}
16035364   Benjamin Renard   First commit
1222
	
735c653b   Elena.Budnik   rank at observato...
1223
1224
1225
1226
1227
1228
	public function destroyFilter($o)
	{
		$filtersMgr = new FiltersMgr();
		$res = $filtersMgr->delete($o);
		return;
	}
16035364   Benjamin Renard   First commit
1229
	
735c653b   Elena.Budnik   rank at observato...
1230
1231
1232
1233
1234
1235
1236
	public function getCrtFilterId()
	{
		$filtersMgr = new FiltersMgr();
		$res = $filtersMgr->getCrtId();
		return $res;
	}

fdf1413b   Elena.Budnik   TT download
1237
1238
1239
1240
1241
	public function getCrtFilterResult()
	{
		$filtersMgr = new FiltersMgr();		
		return $filtersMgr->getCrtResult();
	}
16035364   Benjamin Renard   First commit
1242
	
fdf1413b   Elena.Budnik   TT download
1243
1244
1245
1246
1247
	public function setCrtFilterId($o)
	{
		$filtersMgr = new FiltersMgr();		
		return $filtersMgr->setCrtId($o->id);
	}
16035364   Benjamin Renard   First commit
1248
	
fdf1413b   Elena.Budnik   TT download
1249
1250
1251
1252
1253
1254
	public function resetFilter()
	{
		$filtersMgr = new FiltersMgr();
		$res = $filtersMgr->reset();
		return $res;
	}
16035364   Benjamin Renard   First commit
1255
1256
1257
  
	public function logout($isGuest)
	{
735c653b   Elena.Budnik   rank at observato...
1258
1259
		if ($isGuest) 
		{
fdf1413b   Elena.Budnik   TT download
1260
1261
1262
			$guestMgr = new Guest($this->user);
			$guestMgr->deleteGuest();
		}
735c653b   Elena.Budnik   rank at observato...
1263
1264
		else 
		{
fdf1413b   Elena.Budnik   TT download
1265
1266
			$this->cleanUserWS();
		}               
16035364   Benjamin Renard   First commit
1267
1268
1269
		return;
	} 

fdf1413b   Elena.Budnik   TT download
1270
1271
1272
1273
1274
1275
1276
1277
1278
	public function getInfo($obj)
	{
		if (file_exists(HELPPATH.$obj->name)) 
		{
			$content = file_get_contents(HELPPATH.$obj->name);		      
			return  array('success' => true, 'result' => $content);
		}
		return array('success' => false);		
	}	
16035364   Benjamin Renard   First commit
1279
	
fdf1413b   Elena.Budnik   TT download
1280
1281
1282
1283
1284
	public function getUserInfo()
	{
		$dd = new UserMgr();
		return $dd->getUserInfo();
	}
16035364   Benjamin Renard   First commit
1285

fdf1413b   Elena.Budnik   TT download
1286
1287
1288
1289
1290
	public function convertWS()
	{
		$dd = new UserMgr();
		return $dd->convertWS();
	}
16035364   Benjamin Renard   First commit
1291

fdf1413b   Elena.Budnik   TT download
1292
1293
1294
1295
1296
1297
1298
1299
1300
	// $obj ={"Object":"Earth","RunCount":"2",
	// "SW_Density_value":"10","SW_Density_weight":"1","SW_Density_scale":"7","SW_Temperature_value":"100", ....}
	public function getRun($obj)
	{
		$myBestRunsMgr = new BestRunsMgr();
		$res = $myBestRunsMgr->getRun($obj);
		
		return  $res; 
	}
16035364   Benjamin Renard   First commit
1301
        
fdf1413b   Elena.Budnik   TT download
1302
1303
1304
1305
	//$obj = array of IDs    
	public function addRun($obj)
	{
		$myBestRunsMgr = new BestRunsMgr();
bf74fc2d   Elena.Budnik   IMPEX
1306
1307
1308
1309
1310
1311
		
		$ok = $myBestRunsMgr->init();
		
		if (!$ok)
			return array('success'=>false,'message'=>'cannot init addRun');
			
fdf1413b   Elena.Budnik   TT download
1312
		$myBestRunsMgr->addRuns($obj);
bf74fc2d   Elena.Budnik   IMPEX
1313
1314
		
		return array('success'=>true,'addedRuns'=>$obj);
fdf1413b   Elena.Budnik   TT download
1315
1316
1317
1318
1319
1320
	} 
	
	//AKKA - New action to clean user WS
	public function cleanUserWS()
	{
		$this->rrmdir(USERDIR.'DOWNLOAD.TEMP');
fdf1413b   Elena.Budnik   TT download
1321
		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
bf74fc2d   Elena.Budnik   IMPEX
1322
1323
1324
1325
1326
1327
		IHMConfigClass::setUserName($this->user);
		
		// delete impex params and data		
		$impexParamMgr = new ImpexParamManager();
		$impexParamMgr->deleteImpexStaff();
			   
fdf1413b   Elena.Budnik   TT download
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
		return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSCLEAN);
	}
	
	public function rrmdir($dir){
		if (is_dir($dir)) {
			$objects = scandir($dir);
			foreach ($objects as $object) { // Recursively delete a directory that is not empty and directorys in directory 
				if ($object != "." && $object != "..") {  // If object isn't a directory recall recursively this function 
					if (filetype($dir."/".$object) == "dir")
						$this->rrmdir($dir."/".$object);
					else
						unlink($dir."/".$object);
				}
			}
			reset($objects);
			rmdir($dir);
		}
	}

	public function deleteSpecialInfo($name)
	{
		if (file_exists(USERDIR.$name)) 
					unlink(USERDIR.$name);
		return array('success' => true);
	}
9f08f4eb   Benjamin Renard   Zoom in interacti...
1353
        
fdf1413b   Elena.Budnik   TT download
1354
1355
1356
1357
1358
1359
1360
1361
1362
	public function interactivePlot($obj, $multiPlotState)
	{
		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
		$inputobj = (Object)array(
			'action' => $obj,
			'multiPlotState' => $multiPlotState
		);
		return $this->executeRequest($inputobj, FunctionTypeEnumClass::ACTION);
	}
ced82260   Benjamin Renard   Get initial plot ...
1363
        
735c653b   Elena.Budnik   rank at observato...
1364
1365
1366
	public function getParamPlotInit($obj)
	{
		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
bf74fc2d   Elena.Budnik   IMPEX
1367
1368
1369
1370
1371
1372
		// IMPEX param
		if (preg_match("#^spase___IMPEX_#",$obj->paramId))
			$type = 'impex_plot_init';
		else
		   $type = 'plot_init';
		
735c653b   Elena.Budnik   rank at observato...
1373
1374
		$inputobj = (Object)array(
				'paramId' => $obj->paramId,
bf74fc2d   Elena.Budnik   IMPEX
1375
				'type' => $type
735c653b   Elena.Budnik   rank at observato...
1376
1377
1378
		);
		return $this->executeRequest($inputobj, FunctionTypeEnumClass::PARAMINFO);
	}
169f14d2   Benjamin Renard   Add shared object...
1379
        
735c653b   Elena.Budnik   rank at observato...
1380
1381
	public function getParamInfo($obj)
	{
bf74fc2d   Elena.Budnik   IMPEX
1382
1383
1384
1385
1386
1387
1388
 		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
		// IMPEX param
		if (preg_match("#^spase___IMPEX_#",$obj->paramId))
			$type = 'impex_param_info';
		else
		   $type = 'param_info';
	
735c653b   Elena.Budnik   rank at observato...
1389
1390
		$inputobj = (Object)array(
				'paramId' => $obj->paramId,
bf74fc2d   Elena.Budnik   IMPEX
1391
				'type' => $type
735c653b   Elena.Budnik   rank at observato...
1392
1393
1394
		);
		return $this->executeRequest($inputobj, FunctionTypeEnumClass::PARAMINFO);
	}
169f14d2   Benjamin Renard   Add shared object...
1395
        
735c653b   Elena.Budnik   rank at observato...
1396
1397
1398
1399
1400
1401
	public function getSharedObjectFolders($obj)
	{
		$mgr = new SharedObjectsMgr();
		$folders = $mgr->getFolders($obj->type);
		return array('success' => true, 'folders' => $folders);
	}
169f14d2   Benjamin Renard   Add shared object...
1402
        
735c653b   Elena.Budnik   rank at observato...
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
	public function shareObjects($obj)
	{
		$mgr = new SharedObjectsMgr();
		switch ($obj->type) 
		{
			case 'timeTable' :
			case 'catalog' :
				$src_object_path = USERTTDIR.$obj->object->id.".xml";
				break;
			
			default:
				return array('success' => false, 'message' => 'Unknown object type');
		}
		
		$result = $mgr->add($obj->type, $obj->name, $obj->folder, $src_object_path, $obj->description, $this->user);
		if (!$result['success'])
			return $result;
		
		$mgr->updateTree();
		return $result;
	}
		
	public function isSharedObjectNameAlreadyUsed($obj)
	{
		$mgr = new SharedObjectsMgr();
		$alreadyUsed = $mgr->isNameAlreadyUsed($obj->type, $obj->name);
		return array('success' => true, 'alreadyUsed' => $alreadyUsed);
	}
169f14d2   Benjamin Renard   Add shared object...
1431
        
16035364   Benjamin Renard   First commit
1432
1433
}
?>
aa94fd24   elena   Merge with last svn