makeOrbitsInfo.php 2.53 KB
<?php
/*
*   
*/
	function days2MonthDay($date)
	{
			list($year, $day, $hour, $min, $sec) = sscanf($date, "%04d%03d%02d%02d%02d");
			
			$newDate = date("Y-m-d\TH:i:s\Z",strtotime("+$day days",strtotime("$year-01-01 $hour:$min:$sec")));

			return $newDate;
	} 
    
	$AMDA_IHM = getenv('AMDA_IHM');
	//TBD should be one dir with AmdaUpdate [install] and config
 //  define('WSDL','http://amda-dev.irap.omp.eu/BASE/DDService/dd.wsdl'); 
   
	require_once $AMDA_IHM."/php/config.php";

	if (!file_exists(SimuTargetsXml))
		exit("ERROR : NO TargetsSimu FILE !!! Run makeProxy.php".PHP_EOL);
	
	$tr = array('_' => ':');
	
	try {
		$client = new SoapClient(DD_WSDL);
	}
	catch  (SoapFault $exception) {
		$msg = $exception->faultstring.PHP_EOL;                           
		exit($msg);
	}	
	  // Transform to HTML
	$xsl = new DomDocument("1.0");
	$xsl->load(XMLPATH.'orbitsInfo.xsl');

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

	$targets = $targetXml->Target;
	
	foreach ($targets as $target) 
	{			
		if (!file_exists(RemoteData."$target.json"))
			exit("ERROR : NO $target.json FILE !!! Run makeOrbitsArgs.php".PHP_EOL);
		
		$infoFileName = "simu$target";
		$infoDom = new DomDocument("1.0");
		
		$root = $infoDom->createElement('target');
		$root->setAttribute('name', $target);
		$infoDom->appendChild($root);
		
		$orbits = json_decode(file_get_contents(RemoteData.$target.'.json'), true);
		
		foreach ($orbits as $missionGroup => $missions)
		{
			$missionGrpNode = $infoDom->createElement('missionGroup'); 
			$missionGrpNode->setAttribute('name', $missionGroup);
			$root->appendChild($missionGrpNode);
			
			foreach ($missions as $missionName => $mission)
			{			 
				$missionNode = $infoDom->createElement('mission');
				$missionNode->setAttribute('name', $missionName);
				$missionGrpNode->appendChild($missionNode);
				
				foreach ($mission as $ds => $param)
				{
					try {
						$res = $client->getStartStop(strtr($ds,$tr));
						$Time = explode("-",$res);
						$StartTime = days2MonthDay($Time[0]);
						$StopTime = days2MonthDay($Time[1]);
						$missionNode->appendChild($infoDom->createElement('start',$StartTime));
						$missionNode->appendChild($infoDom->createElement('stop',$StopTime));
					}
					catch  (SoapFault $exception) {
						$msg = $exception->faultstring.PHP_EOL;                           
						exit($msg);
					}				
				}		 
			}
		}
		// $infoDom->save($infoFileName.".xml");	
		$xslt->transformToURI($infoDom, 'file://'.HELPPATH.'simu/'.$infoFileName);
	}	
?>