Blame view

php/classes/AmdaAction.php 46.6 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
9
10
11
12
13
14
15
16
17
18
 *
 */


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;
aa94fd24   elena   Merge with last svn
19

16035364   Benjamin Renard   First commit
20
    public function __construct() 
aa94fd24   elena   Merge with last svn
21
22
23
24
25
    {                 
        $dd = new UserMgr();
        $this->user = $dd->user;
        if (!defined('NEWKERNEL_DEBUG') || !NEWKERNEL_DEBUG)
                 $this->amdaStat = new AmdaStats($dd->user);
16035364   Benjamin Renard   First commit
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
    }

    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) {
                $name =  $dir->innertext; //$dir->href;
                $isLeaf = strrpos($name, "/") !== strlen($name) - 1;
                $childrenToReturn[] = array('text' => $name, 'id' => $trimmed_url.$name,
                                    'nodeType' => 'url', 'leaf' => $isLeaf); 
            }
            
        }
      return $childrenToReturn;  
    }
      
/*****************************************************************
*                           PUBLIC FUNCTIONS
*****************************************************************/ 
 
    /*
    *   $obj = { id: node.id,  nodeType: node.nodeType }
    */
    public function getTree($obj) {
  
       $node = $obj->node;
       
    // to correct 'restricted' parameters  
        if (strpos($node, restricted) !== false) {
            $node = str_replace(restricted,"",$node);
        }

       $nodeType = $obj->nodeType;
       $remoteBase = false;
       $isRemoteDataSet = false;

        if ($nodeType == 'url') 
        {
            $url = $node == 'root' ? $obj->baseId : $node;		   
            return  $this->getUrlDirs($url);
        }

        if ($obj->baseId) $remoteBase = true;

        if ($node == 'root' && $remoteBase)  $node = $obj->baseId;

        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':
169f14d2   Benjamin Renard   Add shared object...
93
94
95
                case 'sharedcatalog':
                		$xmlName = SHAREDPATH.'/SharedObjectTree.xml';
                           break;
16035364   Benjamin Renard   First commit
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
                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];
            }

	    if ($remoteBase)  
            {               
                 $nodeType = 'remoteParam';
	    } 		 
           
	    $Dom->load($xmlName);
             
	    if ($node == "myRemoteSimuData-treeRootNode") 
169f14d2   Benjamin Renard   Add shared object...
117
118
			$node = "myRemoteData-treeRootNode";
	    
16035364   Benjamin Renard   First commit
119
120
121
122
123
124
125
126
127
128
129
130
131
	    $nodeToOpen = $Dom->getElementById($node);
	    $children = $nodeToOpen->childNodes;

	    foreach ($children as $child)  
	      if ($child->nodeType == XML_ELEMENT_NODE) {
		  $isLeaf = true;
	  
                if ($child->hasChildNodes())
                    foreach ($child->childNodes as $grandChild)  
                    if ($grandChild -> nodeType == XML_ELEMENT_NODE)  {
                            $isLeaf = false;
                            break;
                        }
16035364   Benjamin Renard   First commit
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
                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;
                $skip = 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':
bdac8820   elena   show size for cat...
184
                    case 'catalog':                   
16035364   Benjamin Renard   First commit
185
186
                        if ($isLeaf) $info = $child->getAttribute('intervals').' intervals';
                    break;
169f14d2   Benjamin Renard   Add shared object...
187
188
189
190
191
192
193
194
                    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;
16035364   Benjamin Renard   First commit
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
                    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('sampling')) 
                        {
                            $info =  "Sampling: ".$child->getAttribute('sampling')."<br/>";
                            if ($child->getAttribute('dataStart') == 'depending on mission')
                            {
                                $info .= "Time Range: ".$child->getAttribute('dataStart')."<br/>";
                            }                             
                            else 
                            {                                
                                $info .= "Time Range: ".$child->getAttribute('dataStart')."-".$child->getAttribute('dataStop')."<br/>";                                
                            }  
                            
                            if ($child->getAttribute('restricted') > 1) {
                                $restricted  = $child->getAttribute('restricted');
                                $info .= "<b>Time Restriction</b>: -$restricted days<br/>";
                            }
                       
                            $info .= "Source: ".$child->getAttribute('dataSource');
                        }
                            
                        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('restricted') > 1 )
                                {
                                    $timeRestriction = true;
                                     
aec5ba13   Elena.Budnik   not tested param ...
250
251
252
253
254
255
256
257
258
                                }
                                
                                /*------------------- to show not tested parameters ------*/      
				 
                                 if ($child->getAttribute('tbd'))
                                            $info .= "<br/><b>Not tested yet</b>";
				 
				    /*------------------- --------------------------------------*/    				 	                                    
                                
16035364   Benjamin Renard   First commit
259
                        }
aec5ba13   Elena.Budnik   not tested param ...
260
                        
16035364   Benjamin Renard   First commit
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289

                        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('restricted') > 1)
                                {
                                    $timeRestriction = true;
                                     
                                }  
         
                        }
                      
                       if ($child->tagName == 'parameter' && $child->hasChildNodes()) $isScatter = false;
                                                                                   
                        if ($child->tagName == 'parameter' && $child->hasAttribute('display_type')) {

                              if ($child->getAttribute('display_type') == 'spectrogram') {
                                    $needsArgs = true;                                     
                                    $isSpectra = true; 
                                    $isScatter = false;
                               }
73fd2e71   Elena.Budnik   stackplot
290
                               else if ($child->getAttribute('display_type') == 'stackplot') {                                    
16035364   Benjamin Renard   First commit
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
                                     $isStack = true;
                                     $isScatter = false;
                               }
                        }  
                
                        if ($isParameter) 
                        {
                            if ($child->tagName == 'parameter' && $child->childNodes->length == 1)
                            { 
                                $needsArgs = true;                               
                            }                                          
                             if (substr($id,0,4) == 'bt96' || substr($id,0,6) == 'ba2000'|| substr($id,0,5) == 'bcain' || substr($id,0,7) == 'bmorsch' ) 
                             {                              
                                 $needsArgs = true;
                             }
                            
                            if ($id == 'mex_n_sw' || $id == 'mex_v_sw') 
                             {
                                  $not_yet = true;
                                 
                             }

aa94fd24   elena   Merge with last svn
313
                            //TODO proper conditions
16035364   Benjamin Renard   First commit
314
315
316
                            if (substr($id,0,3) == 'ros') 
                             {
                                if ( !(strpos($id,'_r_') || strpos($id,'_xyz_') || strpos($id,'_cg_')
aa94fd24   elena   Merge with last svn
317
318
                                     || strpos($id,'_sc_') || strpos($id,'_aux_') || strpos($id,'_sw_') 
                                     || strpos($id,'_tao_') )) 
16035364   Benjamin Renard   First commit
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
                                {                                 
                                   $not_yet = true;
                                } 
                             }

                            $objectMgr = new AliasMgr();
                            $alias = $objectMgr->getAlias($id);
                            
                            $childrenToReturn[] = array('text' => $name,'alias' => $alias, 
                                'id' => $id,'nodeType' => $nodeType, 'info' => $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') 
                            {
                                $disable = ($child->getAttribute('available') != "1");
                                $rank = $child->getAttribute('rank');
                            }
                            else
                            {
                                $disable = $child->getAttribute('restricted');
                            }
                            
                            if ($disable)
                            {
                                if ($disable == 1) {
                                    $info .=  "<br/><b>Restricted access</b>";
                                }
                                else {                                   
                                    $disable = false;                                     
                                }
                            }

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

                    case 'remoteSimuParam' :

                        $isSimulation = true;
  			if ($id == 'spase://IMPEX/SimulationModel/FMI/GUMICS' ) {
                                        $isLeaf = false;
                                        $isAddable = true;
                        }
                        if ($child->tagName == 'dataCenter') {
                                if ($child->getAttribute('isSimulation')) break;
                                else {
                                    $skip = true;
                                    break;
                                }
                        }
                        if ($child->tagName == 'simulationRegion') 
                            {
                                 $rank = $child->getAttribute('rank');
                            }
 		    case 'remoteParam' :
                         
                        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;
                            case 'VEXGRAZ' :
                                            $rank = 2;
                                            break;
                            default:
                        }
 
                        $info = $child->getAttribute('desc');

// 			if ($info && !$isSimulation) { 
			       $info = str_replace(';', "<br/>Time Range: ", $info);
// 			}
			if ($child->tagName == 'dataset') {
			    /*if ($child->hasAttribute('dataStart') && $child->hasAttribute('dataStop')) 
			      $info .= "Time Range: ".$child->getAttribute('dataStart')."-".$child->getAttribute('dataStop')."<br/>";  */     
// 			      $info .= "Time Range: ".$dataStart"-".$dataStop."<br/>";
                        }
			if (($child->tagName == 'parameter') || ($child->tagName == 'component')) {
				    $isParameter = true;
				    $isScatter = true;					   
			}
			
			$needsArgs =  $child->hasAttribute('needsArgs');

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

			if ($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;
                        }       

			    $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);
			  }
			  else { 
                            if ($child->tagName == 'dataCenter')   
                                $restricted = ($child->getAttribute('available') != "1");                                                        
                            else
                                $restricted = false;
                                 
                            if ($id == 'CDAWEB' || $id == 'THEMIS'|| $id == 'MAPSKP' || $id == 'VEXGRAZ') 
                                                                                     $restricted = FALSE;
                            if ($restricted)
                                $info .= "<br/><b>Open soon !</b>";                                                             
                            
                            if ($child->tagName == 'dataset')
                                $nonavailable = ($child->getAttribute('disabled'));
                            else
                                $nonavailable = false;
                            
                            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;
			  //  $info = str_replace("\n","<br/>",$info);
			    break;

                    case 'myDataParam' :

                        $globalStart = null;
                        $globalStop = null;
                        $specialNode = true;
                        $size = $child->getAttribute('size');
                        $isScatter = $size == 1;
                        $mask = $child->getAttribute('mask');
                        $isSpectra = false;

                        
                        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(str_replace('-','/',$child->getAttribute('desc')), 0, 16);
                            $globalStop =  substr(str_replace( '-','/',$child->getAttribute('desc')), 17, 22);
                        }

                        $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: 
		}
	
		if (!$specialNode && !$skip) {
		       if ($child->hasAttribute('desc')) 
			    $info = $child->getAttribute('desc');
			$childrenToReturn[] = array('text' => $name, 'id' => $id, 'nodeType' => $nodeType, 'info' => $info, 
                                                    'help' => $help, 'leaf' => $isLeaf, 'isParameter' => $isParameter);
		}
	      }
		// if $childrenToReturn we have to return []
		 if ($childrenToReturn == null) {			
			$childrenToReturn = array('nodeType' => $nodeType, 'text' => null);
		 }
        }

      return  $childrenToReturn;
 }

    public  function saveTree($obj) 
    {
            $paramMgr = new ParamMgr();
            return $paramMgr->saveTree($obj);            
    }

    public  function doNothing($obj) 
    {	    
        return array("res" => 'ok');
        
    }

    public  function deleteFromTree($obj) 
    {    
        $paramMgr = new ParamMgr();
        return $paramMgr->deleteFromTree($obj);
        
    }

/*
*  temporary object fromUpload
*/ 
    public  function getUploadedObject($name, $format, $nodeType)
    {  
            switch ($nodeType) 
            {
                case 'timeTable' : 
                        $objectMgr = new TimeTableMgr();		  
                        break;
                case 'myDataParam' : 
                        $objectMgr = new FilesMgr();			  	  
                        break;
                default:
                        return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
            }
            return  $objectMgr -> getUploadedObject($name, $format, true);
aa94fd24   elena   Merge with last svn
573

16035364   Benjamin Renard   First commit
574
575
576
577
578
579
580
581
582
583
584
    }	

/*
*  fill ascii file into grid 
*/ 
    public  function getAsciiFile($obj) 
    {  
            $objectMgr = new FilesMgr();			  	  			
            return  $objectMgr -> getAsciiFile($obj->fileName);
    }
	
7ac3ce50   Benjamin Renard   First implementat...
585
    public  function getMyParamInfo($object) 
16035364   Benjamin Renard   First commit
586
587
588
589
590
591
592
593
594
    {   	     
            $objectMgr = new FilesMgr();			  	   	 
            return  $objectMgr -> getParamInfo($object);
    }	

/*
*  temporary object from Search 
*/ 
    public  function getTmpObject($folderId, $name, $nodeType) {  
aa94fd24   elena   Merge with last svn
595

16035364   Benjamin Renard   First commit
596
597
598
599
 
	    switch ($nodeType) {
		  case 'timeTable' : 
			   $objectMgr = new TimeTableMgr();		  
d18b535d   elena   catalog draft + c...
600
601
602
603
			   break; 
		 case 'catalog' :
			   $objectMgr = new CatalogMgr();		  
			   break; 	   
16035364   Benjamin Renard   First commit
604
605
606
607
		  default:
			    return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
              }
	      return  $objectMgr -> getTmpObject($folderId, $name, true);
aa94fd24   elena   Merge with last svn
608

16035364   Benjamin Renard   First commit
609
610
611
612
613
614
615
616
617
618
619
620
621
    }
 

    public  function getObject($id, $nodeType) {  
 
	    switch ($nodeType) {
		  case 'myDataParam':
		  case 'derivedParam' : 
			   $objectMgr = new DerivedParamMgr($nodeType);			   
			   break;
		  case 'timeTable' : 
		  case 'sharedtimeTable' :
			   $objectMgr = new TimeTableMgr();			  
048b4d77   elena   catalogs +
622
623
			   break;  
		  case 'catalog' :
169f14d2   Benjamin Renard   Add shared object...
624
          case 'sharedcatalog' :
048b4d77   elena   catalogs +
625
			   $objectMgr = new CatalogMgr();			  
16035364   Benjamin Renard   First commit
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
			   break; 
		  case 'condition' : 		  
		  case 'request' :
			   $objectMgr = new RequestMgr($nodeType);			  
			   break; 
		  case 'bkgWorks' :
		  	require_once(INTEGRATION_SRC_DIR."RequestManager.php");
		  	return $this->executeRequest($id, FunctionTypeEnumClass::PROCESSGETINFO);
			   break;
		  case 'myData' :
			   $objectMgr = new FilesMgr();			  
			   break;
		  default:
			    return array("error" => $nodeType." NOT_IMPLEMENTED_YET");
              }

	    return  $objectMgr -> getObject($id, $nodeType);
    }
/*
*   $obj = { id: node.id, leaf: node.leaf, nodeType: node.nodeType }
*/
    public  function deleteObject($obj) {  
 
	    switch ($obj->nodeType) {  
		  
		  case 'myDataParam' : 
		  case 'derivedParam' : 
			   $objectMgr = new DerivedParamMgr($obj->nodeType);			   
			   break;
		  case 'timeTable' : 
			   $objectMgr = new TimeTableMgr();			  
d18b535d   elena   catalog draft + c...
657
658
659
			   break; 
		  case 'catalog' : 
			   $objectMgr = new CatalogMgr();			  
16035364   Benjamin Renard   First commit
660
661
662
663
664
665
666
667
668
669
670
671
			   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' :
		  	   require_once(INTEGRATION_SRC_DIR."RequestManager.php");
		  	   return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSDELETE);
aa94fd24   elena   Merge with last svn
672

16035364   Benjamin Renard   First commit
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
		  case 'myData' :
				$objectMgr = new FilesMgr();
			   break;
		  default:
			    return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
              }

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

/*
*   $obj = { id: node.id, old_name: node.text, name: value,  parent : node.parentNode.id, leaf: node.leaf, nodeType: node.nodeType }
*/
    public  function renameObject($obj) {  
 
	    switch ($obj->nodeType) {
		  
		  case 'myDataParam' :
		  case 'derivedParam' : 
			   $objectMgr = new DerivedParamMgr($obj->nodeType);			   
			   break;
		  case 'timeTable' : 
			   $objectMgr = new TimeTableMgr();			  
d18b535d   elena   catalog draft + c...
696
697
			   break;
		  case 'catalog' : 
255e4546   elena   bug in cat rename
698
			   $objectMgr = new CatalogMgr();			  
16035364   Benjamin Renard   First commit
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
			   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");
              }

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

/*   
*   $obj = { name: obj.name, obj.nodeType, obj.leaf (??), OBJ DEPENDENT ATTRIBUTES }
*/
    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();			  
d18b535d   elena   catalog draft + c...
730
731
732
			   break; 
		  case 'catalog' : 
                        $objectMgr = new CatalogMgr();			  
16035364   Benjamin Renard   First commit
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
			   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");
              }

	    return  $objectMgr -> createObject($obj, $folder);
    }

/*   
*   $obj = { id:obj.id, name: obj.name, obj.nodeType, obj.leaf (??), OBJ DEPENDENT ATTRIBUTES }
*/
    public  function modifyObject($obj) {
 
	    switch ($obj->nodeType) {  

		  case 'myDataParam' : 
		  case 'derivedParam' : 
			   $objectMgr = new DerivedParamMgr($obj->nodeType);			   
			   break;
		  case 'timeTable' : 
			   $objectMgr = new TimeTableMgr();			  
d18b535d   elena   catalog draft + c...
761
762
763
764
			   break;
		  case 'catalog' : 
			   $objectMgr = new CatalogMgr();			  
			   break;  	   
16035364   Benjamin Renard   First commit
765
766
767
768
769
770
771
772
773
		  case 'condition' : 
		  case 'request' :
			   $objectMgr = new RequestMgr($obj->nodeType);			  
			   break;
		  default:
			    return array("error" => $obj->nodeType." NOT_IMPLEMENTED_YET");
              }

	    return  $objectMgr -> modifyObject($obj);
aa94fd24   elena   Merge with last svn
774
    }   
16035364   Benjamin Renard   First commit
775
776
777
778
779
780
781
782
783
784
/*
 * {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...
785
			case 'sharedtimeTable' :
16035364   Benjamin Renard   First commit
786
787
				$objectMgr = new TimeTableMgr();
				break;
d18b535d   elena   catalog draft + c...
788
			case 'catalog' :
169f14d2   Benjamin Renard   Add shared object...
789
			case 'sharedcatalog' :
d18b535d   elena   catalog draft + c...
790
791
				$objectMgr = new CatalogMgr();
				break;
16035364   Benjamin Renard   First commit
792
793
794
795
796
797
798
799
800
801
802
803
804
805
			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
*/
aa94fd24   elena   Merge with last svn
806

16035364   Benjamin Renard   First commit
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
    public  function getJobs()
    {
    	require_once(INTEGRATION_SRC_DIR."RequestManager.php");
    	return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSRUNNINGINFO);  
    }


	/* 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))
        {
			//$dd = new WSUserMgr();
            //$dd->init($obj->username,$obj->password,$obj->sessionID);
			return array('success' => false, "message" => "AKKA-KERNEL-INT - WS support not implemented");
        }
        else
			$dd = new UserMgr();
			
        //TODO error handling 
        if (($res = $dd -> ddCheckUser()) != 0)
		{
			if ($res == 156) 
				return array('success' => false, 'message' => 'Your AMDA session is expired.<br/> Login please!');

            return array('success' => false, 'message' => 'ddLogin error: '.$res);
        }

        if ($dd->user == 'impex')
		{
			//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");
        }
        else
		{
			// check disk space
            if ($dd->getWsSize() > DISK_QUOTA)
				return array('success' => false, 'message' => 'Please clean up your workspace.<br/>No more space is available');
        }
		
        $this->user = $dd->user;
        
		return array('success' => true, 'userHost' => $dd -> getIPclient());
	}
	
	private function executeRequest($obj, $function)
	{
		$res = $this->checkUser($obj);
		
		if (!$res['success'])
			return $res;
		
		$requestManager = new RequestManagerClass();
		
		try {
			$res = $requestManager->runIHMRequest($this->user, $res['userHost'], $function, $obj);
		} catch (Exception $e) {
			return array('success' => false, 'message' => 'Exception detected : '.$e->getMessage());
		}
		
		return $res;
	}
	
/*   
*    Main EXECUTE PROCEDURE 
*/
    public  function execute($node, $obj)
	{ 
		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
		if (isset($obj->action))
			return $this->executeRequest($obj, FunctionTypeEnumClass::ACTION);
		else
			return $this->executeRequest($obj, FunctionTypeEnumClass::PARAMS);
    }
    
/*
a0b3d64e   Benjamin Renard   Derived parameter...
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
 * Generate derived parameter compilation
 */
    public function compilParam($obj)
    {
    	require_once(INTEGRATION_SRC_DIR."RequestManager.php");
    	return $this->executeRequest($obj, FunctionTypeEnumClass::PARAMSGEN);
    }

/*
 * Delete derived parameter compilation
 */
   public function compilParamDelete($obj)
   {
		require_once(INTEGRATION_SRC_DIR."RequestManager.php");
		$res = $this->checkUser($obj);
		
		if (!$res['success'])
			return $res;
		
		IHMConfigClass::setUserName($this->user);
		$libParamPath = IHMConfigClass::getCompilationPath()."lib/".$obj->paramId.".so";
		if (file_exists($libParamPath))
			unlink($libParamPath);
    	return array("success" => true);
   }
    
/*
e6e5b259   Benjamin Renard   Add kill plot req...
920
 * kill plot process
16035364   Benjamin Renard   First commit
921
922
 */
    
e6e5b259   Benjamin Renard   Add kill plot req...
923
924
925
926
    public function killPlotRequest()
    {   
    	require_once(INTEGRATION_SRC_DIR."RequestManager.php");
    	return $this->executeRequest((object) array('nodeType' => 'killplot'), FunctionTypeEnumClass::PARAMS);
16035364   Benjamin Renard   First commit
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
    }

/*
 * merge time tables
 */
    public  function merge($obj)   {

        if ($this->amdaStat->success)
            $this->amdaStat->addTask('ttoper', $this->user, null);
                
        $objectMgr = new TimeTableMgr();

    return  $objectMgr -> merge($obj);

    }

    
/*
 * intersect time tables
 */
        public  function intersect($obj)   {

            if ($this->amdaStat->success)
                $this->amdaStat->addTask('ttoper', $this->user, null);

            $objectMgr = new TimeTableMgr();
            $result = $objectMgr -> intersect($obj);

            return  $result;
        }
048b4d77   elena   catalogs +
957
        
f9c8b272   elena   edit catalog
958
        public function initTTCache($isCatalog = false, $nparams)
16035364   Benjamin Renard   First commit
959
        {
048b4d77   elena   catalogs +
960
961
962
        	if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr();
        	else              $cacheMgr = new CatalogCacheMgr();
        	
f9c8b272   elena   edit catalog
963
        	return $cacheMgr->initTTCache($nparams);
16035364   Benjamin Renard   First commit
964
965
        }
        
d18b535d   elena   catalog draft + c...
966
        
16035364   Benjamin Renard   First commit
967
968
        public function initTTCacheFromTT($id, $type)
        {
169f14d2   Benjamin Renard   Add shared object...
969
        	if ($type == 'catalog' || $type == 'sharedcatalog') $cacheMgr = new CatalogCacheMgr();
048b4d77   elena   catalogs +
970
971
        	else $cacheMgr = new TimeTableCacheMgr();
        	
16035364   Benjamin Renard   First commit
972
973
974
        	return $cacheMgr->initFromTT($id, $type);
        }
        
9d412dda   elena   catalog tmp and r...
975
        public function initForChart($id, $name, $isTmpObject, $type)
86263051   elena   visu second draft
976
        {
169f14d2   Benjamin Renard   Add shared object...
977
        	if ($type == 'catalog' || $type == 'sharedcatalog') $objMgr = new CatalogMgr();
9d412dda   elena   catalog tmp and r...
978
979
        	        	         	
        	return $objMgr->initForChart($id, $name, $isTmpObject, $type);
86263051   elena   visu second draft
980
981
        }
        
d18b535d   elena   catalog draft + c...
982
        public function initTTCacheFromTmpObject($folderId, $name, $isCatalog = false)
16035364   Benjamin Renard   First commit
983
        {
d18b535d   elena   catalog draft + c...
984
985
986
987
988
989
			if (!$isCatalog) $cacheMgr = new TimeTableCacheMgr();
				 
			else              $cacheMgr = new CatalogCacheMgr();
					   
			 
		
16035364   Benjamin Renard   First commit
990
991
992
993
994
995
996
997
998
999
1000
        	return $cacheMgr->initFromTmpObject($folderId, $name);
        }
        
        public function initTTCacheFromUploadedFile($name, $format)
        {
        	$cacheMgr = new TimeTableCacheMgr();
        	return $cacheMgr->initFromUploadedFile($name, $format);
        }
        
        public function readTTCacheIntervals($o)
        {
169f14d2   Benjamin Renard   Add shared object...
1001
        	if ($o->typeTT == 'catalog' || $type == 'sharedcatalog') $cacheMgr = new CatalogCacheMgr();
d18b535d   elena   catalog draft + c...
1002
1003
        	else $cacheMgr = new TimeTableCacheMgr();
        	
16035364   Benjamin Renard   First commit
1004
1005
        	return $cacheMgr->getIntervals($o->start,$o->limit,$o->sort,$o->filter);
        }
86263051   elena   visu second draft
1006
1007
1008
        
	 public function readIntervalsForChart($o)
        {
169f14d2   Benjamin Renard   Add shared object...
1009
        	if ($o->typeTT == 'catalog' || $type == 'sharedcatalog') $objMgr = new CatalogMgr();
86263051   elena   visu second draft
1010
1011
        	 
        	
9d412dda   elena   catalog tmp and r...
1012
        	return $objMgr->getIntervalsForChart($o->id, $o->name, $o->fromPlugin, $o->typeTT);
86263051   elena   visu second draft
1013
1014
        }
        
16035364   Benjamin Renard   First commit
1015
1016
1017
1018
1019
1020
1021
1022
        public function saveTTCacheIntervalsInTT($o)
        {
        	$cacheMgr = new TimeTableCacheMgr();
            return $cacheMgr->saveInTT($o->ttId,$o->action,$o->cacheToken);
        }
        
        public function addTTCacheInterval($o)
        {
f9c8b272   elena   edit catalog
1023
1024
1025
          	if ($o->isCatalog) $cacheMgr = new CatalogCacheMgr();
          	else $cacheMgr = new TimeTableCacheMgr();
    	
16035364   Benjamin Renard   First commit
1026
1027
1028
            return $cacheMgr->addInterval($o->index, $o->start, $o->stop);
        }
        
70aabdee   elena   catalog draft
1029
        public function removeTTCacheIntervalFromId($id, $isCatalog = false)
16035364   Benjamin Renard   First commit
1030
        {
70aabdee   elena   catalog draft
1031
1032
        	if ($isCatalog) $cacheMgr = new CatalogCacheMgr();
        	else $cacheMgr = new TimeTableCacheMgr();
f9c8b272   elena   edit catalog
1033
  	
16035364   Benjamin Renard   First commit
1034
1035
1036
1037
1038
        	return $cacheMgr->removeIntervalFromId($id);
        }
        
        public function modifyTTCacheInterval($o)
        {
f9c8b272   elena   edit catalog
1039
1040
1041
1042
1043
1044
1045
1046
        	if ($o->isCatalog) {
        	
			$cacheMgr = new CatalogCacheMgr();
		return $cacheMgr->modifyIntervalFromId($o);
		
		}
          	else $cacheMgr = new TimeTableCacheMgr();
          	
16035364   Benjamin Renard   First commit
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
        	return $cacheMgr->modifyIntervalFromId($o->cacheId, $o->start, $o->stop);
        }
        
        public function operationTTCacheIntervals($extendTime, $shiftTime)
        {
        	$cacheMgr = new TimeTableCacheMgr();
        	return $cacheMgr->operationIntervals($extendTime, $shiftTime);
        }
        
        public function mergeTTCacheIntervals()
        {
        	$cacheMgr = new TimeTableCacheMgr();
        	return $cacheMgr->mergeIntervals();
        }
        
        public function getTTCacheStatistics()
        {
        	$cacheMgr = new TimeTableCacheMgr();
        	return $cacheMgr->getStatistics();
        }
        
        public function getTTCacheStatus()
        {
        	$cacheMgr = new TimeTableCacheMgr();
        	return $cacheMgr->getStatus();
        }
aa94fd24   elena   Merge with last svn
1073

16035364   Benjamin Renard   First commit
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
/*
 * Send a feedback
 * 
 */
        public function sendFeedback($feed)
        {
            $feedMgr = new FeedbackMgr();
            return $feedMgr->addFeedback($feed->user, $feed->interface, $feed->subject, $feed->userText, $feed->userAgent, $feed->attach);
        }
    
/*
 * Save state
 * 
 */
        public function saveState($datas)
        {
            $myStateMgr = new StateMgr();
            return $myStateMgr->saveState($datas);
        }
    
/*
 * Load state
 * 
 */    
        public function loadState($o)
        {	
                $myStateMgr = new StateMgr();
                return $myStateMgr->loadState();
        }
	
/* 
 * SAMP
 */
        public function sendToSAMP($o)
        {                
                if ($this->amdaStat->success)
                    $this->amdaStat->addTask('samp', $this->user, null);

                $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;
        }
	
/*
 * HST Images
 */
        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);
        }
	
        public function getAPISImagesUrl($o)
        {
                if ($this->amdaStat->success) 
                    $this->amdaStat->addTask('images', $this->user, null);
                		
                $apisMgr = new APISMgr();
b7796276   Benjamin Renard   Migration to supp...
1143
                $res = $apisMgr->get($o->target, $o->startTime, $o->stopTime, $o->datasets);
16035364   Benjamin Renard   First commit
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222

                return $res;
        }	
/*
 * Filters
 */
        public function loadFilterList($o)
        {
                $filtersMgr = new FiltersMgr(); 
                $res = $filtersMgr->loadList();
                return $res;
        }

        public function loadFilters($o)
        {
                $filtersMgr = new FiltersMgr();
                if (isset($o->id))
                    $res = $filtersMgr->loadFilter($o->id);
                else
                    $res = $filtersMgr->loadAll();
                return $res;
        }
	
        public function saveFilter($o)
        {
                $filtersMgr = new FiltersMgr();		
                return $filtersMgr->save($o);
        }
	
        public function createFilter($o)
        {
                $filtersMgr = new FiltersMgr();		
                return $filtersMgr->create($o);
        }
	
        public function destroyFilter($o)
        {
                $filtersMgr = new FiltersMgr();
                $res = $filtersMgr->delete($o);
                return;
        }
	
        public function getCrtFilterId()
        {
                $filtersMgr = new FiltersMgr();
                $res = $filtersMgr->getCrtId();
                return $res;
        }
	
        public function getCrtFilterResult()
        {
                $filtersMgr = new FiltersMgr();		
                return $filtersMgr->getCrtResult();
        }
	
        public function setCrtFilterId($o)
        {
                $filtersMgr = new FiltersMgr();		
                return $filtersMgr->setCrtId($o->id);
        }
	
        public function resetFilter()
        {
                $filtersMgr = new FiltersMgr();
                $res = $filtersMgr->reset();
                return $res;
        }
  
	public function logout($isGuest)
	{
                if ($isGuest) {
                    $guestMgr = new Guest($this->user);
                    $guestMgr->deleteGuest();
                }
                else {
                    $myBaseMgr = new BaseManager();
                    $myBaseMgr->delSimuFiles('mysimudata');   
		    $myBaseMgr->delSimuFiles('mywsrdata');     
                
18d4a11e   Benjamin Renard   Save and load plo...
1223
                    $this->cleanUserWS();
16035364   Benjamin Renard   First commit
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
                 }               
		return;
	} 

        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);
                
        }	
	
        public function getUserInfo()
        {
                    $dd = new UserMgr();
                    return $dd->getUserInfo();
        }

        public function convertWS()
        {
                 $dd = new UserMgr();
                 return $dd->convertWS();
        }

// $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; 
        }
        
    //$obj = array of IDs    
        public function addRun($obj)
        {
            $myBestRunsMgr = new BestRunsMgr();
            $myBestRunsMgr->init();
            $myBestRunsMgr->addRuns($obj);

            $res =  array('success' => true,'addedRuns' => $obj);
        return $res;
aa94fd24   elena   Merge with last svn
1271
        }        
16035364   Benjamin Renard   First commit
1272
1273
1274
        //AKKA - New action to clean user WS
        public function cleanUserWS()
        {
70aabdee   elena   catalog draft
1275
          	require_once(INTEGRATION_SRC_DIR."RequestManager.php");
e82af71b   elena   catalog draft
1276
         	return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSCLEAN);
16035364   Benjamin Renard   First commit
1277
1278
1279
1280
1281
1282
1283
1284
        }

        public function deleteSpecialInfo($name)
        {
             if (file_exists(USERDIR.$name)) 
                                    unlink(USERDIR.$name);
             return array('success' => true);
        }
9f08f4eb   Benjamin Renard   Zoom in interacti...
1285
        
488b1401   Benjamin Renard   Interactive multi...
1286
        public function interactivePlot($obj, $multiPlotState)
9f08f4eb   Benjamin Renard   Zoom in interacti...
1287
1288
        {
        	require_once(INTEGRATION_SRC_DIR."RequestManager.php");
488b1401   Benjamin Renard   Interactive multi...
1289
1290
1291
1292
1293
        	$inputobj = (Object)array(
        		'action' => $obj,
        		'multiPlotState' => $multiPlotState
        	);
        	return $this->executeRequest($inputobj, FunctionTypeEnumClass::ACTION);
9f08f4eb   Benjamin Renard   Zoom in interacti...
1294
        }
ced82260   Benjamin Renard   Get initial plot ...
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
        
        public function getParamPlotInit($obj)
        {
        	require_once(INTEGRATION_SRC_DIR."RequestManager.php");
        	$inputobj = (Object)array(
        			'paramId' => $obj->paramId,
        			'type' => 'plot_init'
        	);
        	return $this->executeRequest($inputobj, FunctionTypeEnumClass::PARAMINFO);
        }
7ac3ce50   Benjamin Renard   First implementat...
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
        
        public function getParamInfo($obj)
        {
        	require_once(INTEGRATION_SRC_DIR."RequestManager.php");
        	$inputobj = (Object)array(
        			'paramId' => $obj->paramId,
        			'type' => 'param_info'
        	);
        	return $this->executeRequest($inputobj, FunctionTypeEnumClass::PARAMINFO);
        }
169f14d2   Benjamin Renard   Add shared object...
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
        
        public function getSharedObjectFolders($obj)
        {
        	$mgr = new SharedObjectsMgr();
        	$folders = $mgr->getFolders($obj->type);
        	return array('success' => true, 'folders' => $folders);
        }
        
        public function shareObjects($obj)
        {
        	$mgr = new SharedObjectsMgr();
        	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);
        }
        
16035364   Benjamin Renard   First commit
1351
1352
}
?>
aa94fd24   elena   Merge with last svn