Blame view

php/classes/AmdaClient.php 25.7 KB
16035364   Benjamin Renard   First commit
1
2
3
<?php

/**  @class AmdaClient
aa94fd24   elena   Merge with last svn
4
 *    @version $Id: AmdaClient.php 2888 2015-04-29 15:25:42Z elena $
16035364   Benjamin Renard   First commit
5
6
7
8
9
 *    @brief Client of DD Web Server
 *
 */

  ini_set("soap.wsdl_cache_enabled", "0");
6d5dcc15   Myriam Bouchemit   IP address of man...
10
  ini_set('soap.wsdl_cache_ttl',0);
16035364   Benjamin Renard   First commit
11
12
13
14
15
16
17
18
19
20

class AmdaClient {

	public $client;
        public $updateOnly;
	 
	function __construct($updateOnly){
		 
                $this->updateOnly = $updateOnly;

ba5ca383   Benjamin Renard   Cleanup old confi...
21
        /*   wsdl location depends on DDServer AMDA is connected to
16035364   Benjamin Renard   First commit
22
23
		 *    DDServer is defined in DD.res
		 */
ba5ca383   Benjamin Renard   Cleanup old confi...
24
		$SERVER  = file(DDRES_DIR."/DD.res");
16035364   Benjamin Renard   First commit
25
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
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
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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
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
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
		if (!file_exists(DATAPATH."wsdl.location")) {
			$msg = "No WSDL location file -> Nothing done".PHP_EOL;
			error_log($msg, 1, email);
			exit($msg);
		}

		/* Get WSDL  Location  */

		$WsdlSources = file(DATAPATH."wsdl.location");
		$isHOST = false;
		for ($i = 0; $i < count($WsdlSources); $i++)
		{
			list($HOST,$WSDL) = sscanf($WsdlSources[$i],"%s %s");
			 
			if ($HOST.PHP_EOL == $SERVER[0]) {
				$isHOST = true;
				break;
			}
		}

		if (!$isHOST) {
			$msg = "No WSDL location for ".$SERVER[0].PHP_EOL;
			error_log($msg, 1, email);
			exit($msg);
		}

		try {
			$this->client = new SoapClient($WSDL);
		}
		catch  (SoapFault $exception) {
			$msg = $exception->faultstring.PHP_EOL;
			error_log($msg, 1, email);
			exit($msg);
		}
		// reset log file
	 if (file_exists(log)) unlink(log);

	 date_default_timezone_set('UTC');
	}

	/* Just copy URL to Info/Bases.xml */
	 
	public function getAvailableExternalBases() {

		try {
			$extBases = $this->client->getAvailableExternalBases();
		}
		catch  (SoapFault $exception) {
			$msg = $exception->faultstring.PHP_EOL;
			error_log($msg, 1, email);
			exit($msg);
		}

		if ($extBases === "NOEXTERNALBASES") {
			if (!$this->updateOnly) error_log($extBases.PHP_EOL, 1, email);
			return $extBases;
		}

		$extBasesDom = new DomDocument("1.0");
		if (!$extBasesDom->load($extBases)) {
			$msg = "Can't load Bases.xml".PHP_EOL;
			if (!$this->updateOnly) error_log($msg, 1, email);
			exit($msg);
		}

		$External = $extBasesDom->getElementsByTagName("External")->item(0);
		if ($External == NULL) {
			$msg = "no External Tag found in Bases.xml".PHP_EOL;
			if (!$this->updateOnly) error_log($msg, 1, email);
			exit($msg);
		}

		$extBasesNames = $External->getElementsByTagName("CenterID");
		if ($extBasesNames->length === 0) {
			$msg = "no external bases found in Bases.xml".PHP_EOL;
			if (!$this->updateOnly) error_log($msg, 1, email);
			exit($msg);
		}

		if (!$this->updateOnly) {
                        if (!is_dir(RemoteData)) mkdir(RemoteData, 0775, true);
                        chgrp(RemoteData, APACHE_USER);                
                        chmod(RemoteData, 0775);
                        if (!is_dir(RemoteData.'PARAMS')) mkdir(RemoteData.'PARAMS', 0775, true);
                        chgrp(RemoteData.'PARAMS', APACHE_USER);                
                        chmod(RemoteData.'PARAMS', 0775);
                        
                        $xsl = new DOMDocument("1.0");
                        $xsl->load(XMLPATH."basesRaw2bases.xsl");

                        $xslt = new XSLTProcessor();
                        $xslt->importStylesheet($xsl);

                        if (!$xslt->transformToDoc($extBasesDom)->save(RemoteData."Bases.xml")){
                                $msg = "problem while transforming Bases.xml".PHP_EOL;
                                error_log($msg, 1, email);
                                exit($msg);
                        }
                }
		return $extBasesNames;
		 
	}

	/* Get list of available local missions for a given user*/
	public function getUserAvailableMissions($user)
	{
		try {
			$localmissions = $this->client->getUserAvailableLocalMissions($user);
			$externalmissions = $this->client->getUserAvailableExternalMissions($user);
		}
		catch  (SoapFault $exception) {
			 
			/*$log = fopen(DATAPATH."mylog","w");
			 fprintf($log,$exception->faultstring."\n");
			  
			 $functions = $this->client->__getFunctions ();
			 foreach ($functions as $function)
			 fprintf($log,$function."\n");*/
			return array('success' => false,'message' => $exception->faultstring);
		}
		 
		return array('success' => true,'local' => $localmissions,'external' => $externalmissions);
	}
	 
	/* Just copy URL to LocalData/Amda_Users.xml */
	 
	public function getUserGroups() {
		try {
			$group_info = $this->client->getUserGroups();
		}
		catch  (SoapFault $exception) {
			exit("Problems with DD Web Services".PHP_EOL);
		}
		if ($group_info === "NOUSERGROUPSSPECIFIED") return false;
		 
		if (!file_exists(LocalData)) mkdir(LocalData, 0755, true);
		if (!copy($group_info,LocalData."AMDA_Users.xml"))
		exit("problem with copying AMDA_Users info".PHP_EOL);

		return true;
		 
	}
        /* Get Time Restriction from VI in DDBASE */
         
        public function getTimeRestriction($dataSet) {
                try {
                        $restrictions = $this->client->getTimeRestriction($dataSet);
                }
                catch  (SoapFault $exception) {                     
                        error_log($exception->faultstring.PHP_EOL, 1, email);
                    return FALSE;
                }
                if ($restrictions['success'] === FALSE) {
                        error_log('TimeRestriction: '.$dataSet.' '.$restrictions['days'], 1, email);
                    return FALSE;
                }
                                  
                return $restrictions;
                 
        }
	/* Just copy URL to LocalData/Missions.xml */
	 
	public function getAvailableMissions() {

		try {
			$localMissions = $this->client->getAvailableMissions();
		}
		catch  (SoapFault $exception) {
			$msg = $exception->faultstring.PHP_EOL;
			if (!$this->updateOnly) error_log($msg, 1, email);
			exit($msg);
		}

		if ($localMissions === "NOLOCALDATA") {
			if (!$this->updateOnly) error_log($localMissions.PHP_EOL, 1, email);
			return $localMissions;
		}
		 
		$locBasesDom = new DomDocument("1.0");
		$locBasesDom->load($localMissions);
		$local = $locBasesDom->getElementsByTagName("Local")->item(0);

		if (!$local) {
			$msg = "no local data found in Missions.xml".PHP_EOL;
			if (!$this->updateOnly) error_log($msg, 1, email);
			exit($msg);
		}

		$locBasesNames = $local->getElementsByTagName("MissionID");
		if ($locBasesNames->length === 0) {
			$msg = "no missions found in Missions.xml".PHP_EOL;
			error_log($msg, 1, email);
			exit($msg);
		}

		if (!is_dir(LocalData)) mkdir(LocalData, 0775, true);
                if (!is_dir(LocalDataParam)) mkdir(LocalDataParam, 0775, true);
                if (!is_dir(LocalDataTemplate)) mkdir(LocalDataTemplate, 0775, true);

                chgrp(LocalData,APACHE_USER);
                chgrp(LocalDataParam,APACHE_USER);
                chgrp(LocalDataTemplate,APACHE_USER);
 
                chmod(LocalData, 0775);
                chmod(LocalDataParam, 0775);
                chmod(LocalDataTemplate, 0775);

		if (!copy($localMissions,LocalData."Missions.xml")) {
			$msg = "problem with copying AMDA Local Missions info".PHP_EOL;
			if (!$this->updateOnly) error_log($msg, 1, email);
			exit($msgL);
		}
		 
		return $locBasesNames;
		 
	}
	 
	public function isMulti($baseNode){
		$multi = $baseNode->getAttribute("missions");
		if ($multi == "") return false;
		$nameArr = explode(";",$multi);
		if (count($nameArr) < 2) return false;
		 
		return $nameArr;
	}


	public function makeMulti($locbase, $multiNames){

		$templatename = LocalDataTemplate."DD_".$locbase->nodeValue.".template";
		$paramtemplate = LocalDataTemplate.$locbase->nodeValue.".template";

		$suffix = array();
		foreach ($multiNames as $item) {
			$temp = explode("-",$item);
			if (count($temp) > 1) {
		  $suffix[] = $temp[1];
			}
			else {
		  $suffix[] = substr($item,-1);
			}
		}
		 
		$template = new DomDocument("1.0");
		$status = $template->load($templatename);
		if (!$status) {
			print_r("Cannot load ".$templatename.PHP_EOL);
			if (!$this->updateOnly) error_log("Cannot load ".$templatename.PHP_EOL,1,email);
		}
	  
		$paramdom = new DomDocument("1.0");
		$status = $paramdom->load($paramtemplate);
		if (!$status) {
			print_r("Cannot load ".$paramtemplate.PHP_EOL);
			if (!$this->updateOnly) error_log("Cannot load ".$paramtemplate.PHP_EOL,1,email);
		}

		// Create DD_Mission.xml
		$locbasename =  LocalData."DD_".$locbase->nodeValue.".xml";
		$locbasedom = new DomDocument("1.0");
		$root = $locbasedom->importNode($template->documentElement);
		$amda = $locbasedom->importNode($template->getElementsByTagName("dataCenter")->item(0));
                $missionMain = $locbasedom->importNode($template->getElementsByTagName("mission")->item(0)); 

		$mission = $locbasedom->importNode($template->getElementsByTagName("mission")->item(0), true);

                $targets = $mission->getElementsByTagName("target"); 
                $targetNames = array();
                foreach ($targets as $target)
                        if ($target->parentNode->tagName == 'mission')  // mission only targets
                                    $targetNames[] = $target->nodeValue;

                $observatory = $mission->getElementsByTagName("observatory")->item(0);
                $instruments = $observatory->getElementsByTagName("instrument");
		 
		// create param descriptor  Mission.xml
		$parambasename =  LocalDataParam.$locbase->nodeValue.".xml";
		$parambasedom = new DomDocument("1.0");
		$paramroot = $parambasedom->importNode($paramdom->documentElement);
	  
		$instrumentNon = array();
		foreach ($instruments as $instrument) {
			// absent instriments processing
			if ($instrument->hasAttribute("absent")) {
				$absent = $instrument->getAttribute("absent");
				$absentArray = explode(";",$absent);
				$tempArr = array();

				if (count($absentArray) > 1) {
					for ($i = 0; $i < count($suffix); $i++) $tempArr[$i] = false;
					for ($j = 0; $j < count($absentArray); $j++) {
						$temp = array_search($absentArray[$j], $suffix, true);
						$tempArr[$temp] = true;
					}
						
				}
				else {
			  for ($i = 0; $i < count($suffix); $i++) {
			  	$tempArr[$i] = $absent == $suffix[$i];
			  }
				}
				$instrumentNon[$instrument->getAttribute("name")] = $tempArr;
			}
		}
		 
                foreach ($targetNames as $targetName) {
                        $missionMain->appendChild($locbasedom->createElement("target",$targetName));
                }

		for ($index = 0; $index < count($suffix); $index++) {

                        $missionArr[$index] = $observatory->cloneNode();
			$missionArr[$index]->setAttribute("name", str_replace("XXX", $suffix[$index], $missionArr[$index]->getAttribute("name")));
                        $missionArr[$index]->setAttribute("xml:id", str_replace("XXX", $suffix[$index], $missionArr[$index]->getAttribute("name")));
                        $instruments = $observatory->getElementsByTagName("instrument");
                        
			foreach ($instruments as $instrumentReal){
				if (!$instrumentNon[$instrumentReal->getAttribute("name")] || !$instrumentNon[$instrumentReal->getAttribute("name")][$index])  {
					$instrument = $instrumentReal->cloneNode(true);
					$instrument->setAttribute("desc",str_replace("XXX", $suffix[$index], $instrument->getAttribute("desc")));
					$instrument->setAttribute("xml:id",str_replace("XXX", $suffix[$index], $instrument->getAttribute("xml:id")));
					$tags = array("dataset", "parameter", "component");

					foreach ($tags as $tag) {
						$all = $instrument->getElementsByTagName($tag);
						foreach ($all as $one) {
							if ($tag == 'parameter') {
								$id = $one->getAttribute("xml:id");
								// create param tag in param XML descriptor
								$param = $paramdom->getElementById($id);
								if ($param){
									$paramAdd = $parambasedom->importNode($param, true);
									$paramAdd->setAttribute("xml:id",str_replace("XXX", strtolower($suffix[$index]), $id));
									$paramAdd->setAttribute("vi",str_replace("XXX", strtolower($suffix[$index]), $paramAdd->getAttribute("vi")));
									$yTitle = $paramAdd->getElementsByTagName("YTITLE");
									if ($yTitle->length > 0) {
										$value =  $yTitle->item(0)->nodeValue;
										$yTitle->item(0)->nodeValue = str_replace("XXX", $suffix[$index], $value);
									}
									$paramroot->appendChild($paramAdd);
								}
							}
							$one->setAttribute("xml:id",str_replace("XXX", strtolower($suffix[$index]), $one->getAttribute("xml:id")));
							if ($tag == 'dataset' && $one->hasAttribute("vi"))
							$one->setAttribute("vi",str_replace("XXX", strtolower($suffix[$index]), $one->getAttribute("vi")));
						}
					}
					
					//apply to new tags included for EPNResources
					$all = $instrument->getElementsByTagName("alternateName");
					foreach ($all as $one)
					  $one->nodeValue = str_replace("XXX", strtolower($suffix[$index]), $one->nodeValue);
					
					$datasets = $instrument->getElementsByTagName("dataset");
					foreach ($datasets as $dataset)
					{
						 $info = $dataset->getElementsByTagName("info");
						 if ($info->length > 0)
						 {
						 	 $info = $info->item(0);
						 	 
						 	 $title = $info->getElementsByTagName("title");
						 	 if ($title->length > 0)
						   {
						 	   $title = $title->item(0);
						 	   $title->nodeValue = str_replace("XXX", strtolower($suffix[$index]), $title->nodeValue);
						   }
						   
						   $desc = $info->getElementsByTagName("description");
						 	 if ($desc->length > 0)
						   {
						 	   $desc = $desc->item(0);
						 	   $desc->nodeValue = str_replace("XXX", strtolower($suffix[$index]), $desc->nodeValue);
						   }
						   
						   $targets = $info->getElementsByTagName("target");
						 	 foreach ($targets as $target)
						 	   $target->nodeValue = str_replace("XXX", strtolower($suffix[$index]), $target->nodeValue);
						 }
					}
					 
					$missionArr[$index]->appendChild($instrument);
				}
			}
			  $missionMain->appendChild($missionArr[$index]);
		}

                $amda->appendChild($missionMain);
		$root->appendChild($amda);
		$locbasedom->appendChild($root);
		$status = $locbasedom->save($locbasename);
		if (!$status) {
			print_r("Cannot save ".$locbasename.PHP_EOL);
			error_log("Cannot save ".$locbasename.PHP_EOL,3,log);
		}
		$parambasedom->appendChild($paramroot);
		$status = $parambasedom->save($parambasename);
		if (!$status) {
			print_r("Cannot save ".$parambasename.PHP_EOL);
			error_log("Cannot save ".$parambasename.PHP_EOL,3,log);
		}
	}

	public function getDDLocalParamsFiles($locBases)
	{
		if (!$this->updateOnly)
		{
			//remove old DD_*.xml files (install mode)			 
			foreach (glob(LocalData."DD_*.xml") as $file)
			unlink($file);
			//remove old local parameters files			 
			foreach (glob(LocalDataParam."*.xml")  as $file)
			unlink($file);			 
                        //remove old template (install mode)                          
                        foreach (glob(LocalDataTemplate."*.template") as $file)
                        unlink($file);

                        if (file_exists(spectraXml)) unlink(spectraXml); 
                        //remove old targets file
                        if (file_exists(targetsXml)) unlink(targetsXml);                     

			//if (!is_dir(LocalDataTemplate)) mkdir(LocalDataTemplate);
		}

		foreach ($locBases as $locbase)
		{
                        $ddfilename = "DD_".$locbase->nodeValue.".xml";
                        $ddparamfilename = $locbase->nodeValue.".xml";
                        $ddtemplate = "DD_".$locbase->nodeValue.".template";
                        $ddparamtemplate = $locbase->nodeValue.".template";

                    //get DD_*.xml or DD_*template file
                        $multiNames = $this->isMulti($locbase);

                        if (!$this->updateOnly || !file_exists(LocalData.$ddfilename)) {
                            if ($multiNames)
                            system("svn export ".SVN_TEMPLATES.$ddtemplate." ".LocalDataTemplate.$ddtemplate);
                            else
                                system("svn export ".SVN_DDMISSIONSINFO.$ddfilename." ".LocalData.$ddfilename);
                        }
                        //get local params for this mission
                        if (!$this->updateOnly || !file_exists(LocalDataParam.$ddparamfilename)) {
                            if ($multiNames)
                            system("svn export ".SVN_TEMPLATES.$ddparamtemplate." ".LocalDataTemplate.$ddparamtemplate);
                            else
                            system("svn export ".SVN_LOCALPARAMSINFO.$ddparamfilename." ".LocalDataParam.$ddparamfilename);
                        }
                
                        if ($multiNames && !$this->updateOnly) $this->makeMulti($locbase, $multiNames);
                    }

               
		//get SpectraParamList.xml
		if (!$this->updateOnly) {                  
                    system("svn export ".SVN_DDMISSIONSINFO."SpectraParamList.xml ".spectraXml);
		 }
		//get targets.xml
		if (!$this->updateOnly) {                    
                    system("svn export ".SVN_DDMISSIONSINFO."targets.xml ".targetsXml);
                }
		 
		//merge local params for each missions in LocalParams.xml + generate LocalParamsList.xml
		if (!$this->updateOnly)
		{
			$paramsDom = new DomDocument("1.0");
			$paramsDom->formatOutput = true;
			$paramsDom->preserveWhiteSpace = false;
			$paramsRoot = $paramsDom->createElement('LOCAL');
			$paramsDom->appendChild($paramsRoot);
			 
			$listDom = new DomDocument("1.0");
			$listDom->formatOutput = true;
			$listDom->preserveWhiteSpace = false;
			$listRoot = $listDom->createElement('LOCAL');
			$listDom->appendChild($listRoot);
			$dom = new DomDocument("1.0");

			foreach ($locBases as $locbase)
			{
				$ddparamfilename = $locbase->nodeValue.".xml";				
				$dom->load(LocalDataParam.$ddparamfilename);
				 
				$params = $dom->getElementsByTagName('PARAM');
				 
				foreach ($params as $param)
				{
					$node = $paramsDom->importNode($param,TRUE);
					$paramsRoot->appendChild($node);
					 
					$id = $param->getAttribute('xml:id');
					$node = $listDom->createElement('PARAM',$id);
					$listRoot->appendChild($node);
				}
			}

			$paramsDom->save(paramXml);
			$listDom->save(paramListXml);
		}
		 
	}

	/* Just copy URL to DATA/$BaseID/base.xml */
	 
	public function getAvailableExternalData($BaseID) {

		try {
			$extData = $this->client->getAvailableExternalData($BaseID);
		}
		catch  (SoapFault $exception) {
			$msg = $exception->faultstring.PHP_EOL;
			if (!$this->updateOnly) error_log($msg, 1, email);
			exit($msg);
		}

		if ($extData === "NOEXTERNALDATA") return false;
//drwxrwxr-x
                if (!$this->updateOnly) {
                    if (!file_exists(RemoteData.$BaseID)) mkdir(RemoteData.$BaseID, 0775, true);
                    chgrp(RemoteData.$BaseID, APACHE_USER);                
                    chmod(RemoteData.$BaseID, 0775);
                }

		if (!copy($extData,RemoteData.$BaseID."/base.xml"))  {
			$msg = "problem with copying base.xml for ".$BaseID.PHP_EOL;
			if (!$this->updateOnly) error_log($msg, 1, email);
			exit($msg);
		}
    
		return true;
		 
	}

	function days2MonthDay($oldDate, $addDay)
	{
		list($year, $day, $hour, $min, $sec) = sscanf($oldDate, "%04d%03d%02d%02d%02d");

                if ($addDay) $day++;
 
                $newDate = date("Y/m/d",strtotime("+$day days",strtotime("$year-01-01 $hour:$min:$sec")));

		return $newDate;
	}

	/* Update Local Bases Start - Stop */

	public function updateStartStop($groups){

		for ($k = 0; $k < $groups->length; $k++)
		{		
                        if (strpos($groups->item($k)->nodeValue, 'Models') !== false ) continue;

                        $domName = LocalData."DD_".$groups->item($k)->nodeValue.".xml";
			$dom = new DomDocument();
			if (!$dom->load($domName))
			{
				$msg = "Cannot load file ".$domName.PHP_EOL;
				print_r($msg);
				if (!$this->updateOnly) error_log($msg,1,email);
				continue;
			}
			 
			$vi = $dom -> getElementsByTagName("dataset");
			if ($vi->length > 0) for ($i = 0; $i < $vi->length; $i++)
			{
				 
                                // PHP sur manunja    $name = $vi->item($i)->getAttribute('id');
				$name = $vi->item($i)->getAttribute('xml:id');

                                $hasVersion = $vi->item($i)->hasAttribute('version');

				if ($vi->item($i)->getAttribute('vi') != '')
				$name = $vi->item($i)->getAttribute('vi');
				if ($name){
                                    try
                                    {
                                        // Call AMDA WebService
                                        $res =  $this->client->getStartStop($name);
                                        $Time = explode("-",$res);
                                        $msg = $name." : ".$res.PHP_EOL;
                                                                               
                                        // New Start  - New Stop
                                        $newStart = $this->days2MonthDay($Time[0]);
                                        $vi->item($i)->getElementsByTagName('dataStart')->item(0)->nodeValue = $newStart;
                                       
                                        $newStop = $this->days2MonthDay($Time[1]);
                                        if ($newStart == $newStop) $newStop  = $this->days2MonthDay($Time[1], true);

                                        $vi->item($i)->getElementsByTagName('dataStop')->item(0)->nodeValue = $newStop;
                                        if ($hasVersion) {
                                            $res =  $this->client->getVersion(str_replace(":", "_", $name));
                                            if ($res) {
                                                $dataSource = explode("//", $vi->item($i)->getElementsByTagName('dataSource')->item(0)->nodeValue);
                                                $vi->item($i)->getElementsByTagName('dataSource')->item(0)->nodeValue = "$dataSource[0]//$res";
                                            }
                                        }
                                        
                                    }
                                    catch  (SoapFault $exception)
                                    {
                                            $msg = $exception->faultstring." : DataSet ".$name." Start-Stop can't be updated".PHP_EOL;
                                            print_r($msg);
                                            if (!$this->updateOnly) error_log($msg,1,email);
                                    }
				}
				else echo "Models SINP not data".PHP_EOL;

			}
			if (!$dom->save($domName)){
				error_log("Cannot save LocalParams.xml".PHP_EOL,1,email);
			}
		}
		return true;
	}


	/* Update Remote Bases Start - Stop */

	public function updateRemoteStartStop($extBaseID){

		$domName = RemoteData.$extBaseID."/base.xml";
		$dom = new DomDocument();
		if (!$dom->load($domName)){
			$msg = "Cannot load file ".$domName.PHP_EOL;
			print_r($msg);
			if (!$this->updateOnly) error_log($msg,1,email);
			return false;;
		}
		 
		$VIs = $dom -> getElementsByTagName("dataset");
		foreach ($VIs as $vi) {
			$name = $vi->getAttribute('xml:id');
			// Call AMDA WebService
			try {
				$res =  $this->client->getRemoteStartStop($extBaseID, $name);
				print_r($name.' : '.$res.PHP_EOL);
				error_log($name.' : '.$res.PHP_EOL,3,log);
				if ($res !== "NOEXTERNALDATA" && $res !== "NODATASET")
				$vi->setAttribute('desc', $res);
			}
			catch  (SoapFault $exception)
			{
				$msg = $exception->faultstring." : DataSet ".$name." Start-Stop can't be updated".PHP_EOL;
				print_r($msg);
				if (!$this->updateOnly) error_log($msg,1,email);
			}
		}
		$dom->save($domName);
		 
		return true;
	}

	/* Check Remote Bases Connection */
	public function checkRemoteConnection($extBaseID){
		try {
			$res =  $this->client->checkRemoteConnection($extBaseID);

		}
		catch  (SoapFault $exception)
		{
			print_r($exception->faultstring.PHP_EOL);
			error_log($exception->faultstring.PHP_EOL,1,email);
			return false;
		}

		return $res;
	}
	 
	/* Get user info from login */
	public function getUserInfo($login) { 
		try {
6d5dcc15   Myriam Bouchemit   IP address of man...
695
			$info = $this->client->getUserInfo($login,md5(DDSERVICE_PRIVATEKEY.$login.'getUserInfo')); //error_log($info,1,email);
16035364   Benjamin Renard   First commit
696
697
698
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
730
731
732
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
761
762
763
764
765
766
767
768
		}
		catch  (SoapFault $exception) {
			return array('success' => false, 'message' => $exception->faultstring);
		}

		 
		return $info;
	}
	/* Get data set  info  */
	public function getInfo($viID, $infoID) {
		try {
			$info = $this->client->getInfo($viID, $infoID);
		}
		catch  (SoapFault $exception) {
			return array('success' => false, 'message' => $exception->faultstring);
	      } 
 
     
     return $info;
   }

   /* Recursively modify rights & grp */
      public   function fsmodify($obj) {
       chgrp($obj, APACHE_USER); 
       chmod($obj, is_dir($obj) ? 0775 : 0664);               
    }


     public function fsmodifyr($dir) 
     {
       if($objs = glob($dir."/*")) {        
           foreach($objs as $obj) {
               $this->fsmodify($obj);
               if(is_dir($obj)) $this->fsmodifyr($obj);
           }
       }
       return $this->fsmodify($dir);
    }

   /* get Spice Kernels from DDBASE/INFO and copy into AMDALIB/spice */
/*    public function updateSpiceKernels() {
        
        $kernels = array('general','stereo');

        $spiceDir = DDHOME."AMDALIB/spice";

        if (!is_dir($spiceDir)) {
                mkdir($spiceDir, 0775, true);
                chgrp($spiceDir, APACHE_USER);                
                chmod($spiceDir, 0775);
        }

        chdir($spiceDir);

        foreach ($kernels as $kernel) {
            try {
                    
                    if (!copy($tarFileURL,$tarFile)){
//
                    }
                    else {                         
                        exec('tar -xf '.$tarFile);
                     } 
            }
            catch  (SoapFault $exception) {
                    $msg = $exception->faultstring.PHP_EOL;
                
                    error_log($msg,1 , email);
            }
        }
    }   
*/ 
}
aa94fd24   elena   Merge with last svn