print_iso.php 9.31 KB
<?php
session_start();
	
		if($_GET['lang'] != ""){
			$_SESSION['languge'] = $_GET['lang'];
			include('lang/'.$_SESSION['languge'].".php");
		}elseif($_SESSION['languge'] == ''){
			$_SESSION['languge'] = "tn";
			include("lang/tn.php");
		}else{
			include('lang/'.$_SESSION['languge'].".php");
		}


?>
<!DOCTYPE html>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="images/logo.png">
<!-- Styles -->
		<script src="assets/plugins/jquery/jquery-2.2.0.min.js"></script>
<style>
	table {  
		color: #333; /* Lighten up font color */
		font-family: Helvetica, Arial, sans-serif; /* Nicer font */
		width: 100%; 
		border-collapse: 
		collapse; border-spacing: 0; 
	}

	td, th { border: 1px solid #CCC; height: 30px; } /* Make cells a bit taller */

	th {  
		background: #F3F3F3; /* Light grey background */
		font-weight: bold; /* Make sure they're bold */
	}

	td {  
		background: #FAFAFA; /* Lighter grey background */
		text-align: center; /* Center our text */
	}
</style>
<?php 
	$path = "/home/pi/Desktop/vAlert/rec/".$_GET['details'];
	$datetime = substr($_GET['details'],12,2)." ".substr($_GET['details'],14,2)." ".substr($_GET['details'],8,4);
	
	
	//水平、垂直最大限值rms to db
	$db_1 = array('77.147','80');
	$db_2 = array('82.923','86.021');
	$db_3 = array('80','82.923');
	$db_4 = array('88.943','92.041');
	$db_5 = array('95.269','98.062');
	
	$db_1_a = array('73.979','71.126');
	$db_2_a = array('80','77.025');
	$db_3_a = array('76.901','73.979');
	$db_4_a = array('86.020','82.922');
	$db_5_a = array('92.041','89.247');
	
	//水平、垂直最大限值gal
	$gal_1 = array('0.072','0.10');
	$gal_2 = array('0.14','0.20');
	$gal_3 = array('0.10','0.14');
	$gal_4 = array('0.28','0.40');
	$gal_5 = array('0.58','0.80');
	
	$gal_1_a = array('0.050','0.036');
	$gal_2_a = array('0.100','0.071');
	$gal_3_a = array('0.070','0.050');
	$gal_4_a = array('0.200','0.140');
	$gal_5_a = array('0.400','0.290');
	
	

	if($_GET['rules'] != ""){
		if($_GET['Axis'] == 1){
			$text = 'db_'.$_GET['rules'];
			$text1 = 'db_'.$_GET['rules']."_a";
			$rules = $$text;
			$rules1 = $$text1;
		}else{
			$text = 'gal_'.$_GET['rules'];
			$text1 = 'gal_'.$_GET['rules']."_a";
			$rules = $$text;
			$rules1 = $$text1;
		}
	}else{
		$rules = $db_2;
		$rules1 = $db_2_a;
	}
	
	$max_1 = 0;
	$max_2 = 0;
	$max_3 = 0;
	$max_4 = 0;
	if (($handle = fopen($path, "r")) !== FALSE) {
		$i = 0;
		$interval = ($_GET['duration'] == "") ? "60":$_GET['duration'];
		if ($handle) {
			while (!feof($handle)) {
					$buffer[] = fgets($handle, 4096);
			}
			fclose($handle);
		}
	}	
	$j=0;
	for($i=1;$i<=count($buffer);$i++){
		$data = explode(",",$buffer[$i]);

		if($data[1] >= $max_1){
			$max_1 = $data[1];
			$label = $datetime." ".$data[0];
		}
		
		if($data[2] >= $max_2){
			$max_2 = $data[2];
		}
		if($data[3] >= $max_3){
			$max_3 = $data[3];
			$label = $datetime." ".$data[0];
		}
		if($data[4] >= $max_4){
			$max_4 = $data[4];
		}
		
		
		$num = $j % $interval;
		if($num == 0){	
			if($_GET["Axis"] == 2){
			//GAL
				$data1[] = "{x: new Date('".$label."'), y: ".($max_1*0.01)."}";
				$data2[] = "{x: new Date('".$label."'), y: ".($max_3*0.01)."}";
			}else{
			//DB
				$data1[] = "{x: new Date('".$label."'), y: ".$max_2."}";
				$data2[] = "{x: new Date('".$label."'), y: ".$max_4."}";
			}
			$max_1 = 0;
			$max_2 = 0;
			$max_3 = 0;
			$max_4 = 0;
		}
		$j++;
	
	}
	
	$value = "{type: 'spline', 
        showInLegend: true,
        name: 'Horizontal',
        markerSize: 0,  
		xValueFormatString:'H:m:s',
        dataPoints: [".implode(",",$data1)."]}";

	$value2 = "{type: 'spline', 
        showInLegend: true,
        name: 'Vertical',
        markerSize: 0,  
		xValueFormatString:'H:m:s',
        dataPoints: [".implode(",",$data2)."]}"; 
		
	
?>
		<?
			$str = explode("_",$_GET['details']);
			$datetime = date("Y-m-d",strtotime($str['1']));
			$id = explode('.',$str['2']);
		?>
<body>
<main class="mn-inner">
	<div class="row">
		<div class="col s12">
			<div class="page-title" style="font-size:40px;text-align:center;">ISO 2631 Report</div>
			
		</div>
		<div class="row" >
			<form class="col s12">
			<div class="card">
                <div class="card-content">
				<div class="row" >
					<img src="images/sanlien.png"/ style="float:right;margin-top: -70px;margin-bottom: 10px;">
					<span class="card-title" style="font-size:16px"><?=Monitoring_Day?>:<?php echo $datetime;?></span><br>
					<span class="card-title" style="font-size:16px"><?=sequence?>:<?php echo $id[0];?></span>
					
					<table>
					<thead>
						<th><?=Display_unit?></th>
						<th><?=build_type?></th>
						<th><?=Duration?></th>
					</thead>
					<tbody>
						<tr>
							<td>
								<?php echo ($_GET['Axis'] == "" or $_GET['Axis'] == "1") ? "dB":"Gal";?>
							</td>
							<td>
								<?php echo ($_GET['rules'] == 1) ? build_1:"";?>
								<?php echo ($_GET['rules'] == 2 or $_GET['rules'] == "") ? build_2." - 07:00~22:00":"";?>
								<?php echo ($_GET['rules'] == 3) ? build_3." - 22:00~07:00":"";?>
								<?php echo ($_GET['rules'] == 4)  ? build_4:"";?>
								<?php echo ($_GET['rules'] == 5) ? build_5:"";?>
							</td>
							<td>
								<?php echo ( $_GET['duration'] == "") ? '60 seconds':$_GET['duration']." minutes";?>
							</td>
						</tr>
					</tbody>
					</table>
				</div>

				</div>
			</div>
			</form>
		</div>
		<br><br>
		<div class="col s12 m12 l12">
            <div class="card">
                <div class="card-content">
                    <span class="card-title" style="font-size:16px">Sequence Number:<?php echo $id[0];?></span>
					<div id="chartContainer" style="height: 300px; width: 100%;"> </div>
                </div>
            </div>
		</div>
		<div class="col s12 m12 l12">
            <div class="card">
                <div class="card-content">
                    <span class="card-title" style="font-size:16px">Sequence Number:<?php echo $id[0];?></span>
					<div id="chartContainer2" style="height: 300px; width: 100%;"> </div>
                </div>
            </div>
		</div>
		
	</div>
</main>
	</div>
        <div class="left-sidebar-hover"></div>
        
		<!--<script src="js/dataTables.bootstrap.min.js"></script>-->
        <script src="assets/plugins/materialize/js/materialize.min.js"></script>
        <script src="assets/plugins/material-preloader/js/materialPreloader.min.js"></script>
		<script src="assets/js/pages/form_elements.js"></script>
        <script src="assets/js/alpha.js"></script>
		<script src="assets/js/pages/form_elements.js"></script>
		<script type="text/javascript" src="js/canvasjs.min.js"></script>
		<script type="text/javascript">
			window.onload = function() {
				var chart = new CanvasJS.Chart("chartContainer",
					{      
					  title:{
						text: "ISO 2631 - Horizontal"
					  },
					  zoomEnabled: true,
					  axisX :{
						valueFormatString: "H:m:s" ,
						title:"<?=$datetime?>",
						interval: 1000,
					  },
					  axisY :{
						includeZero: false,
						title:"<?php echo ($_GET['Axis'] == 2) ? 'Gal':'dB';?>",
						//maximum: <?php echo ($_GET['Axis'] == 2) ? ($rules[0]+0.03):($rules[0]+10);?>,
						stripLines:[{
							showOnTop: true,
							color:"#FF0000",
							value:<?php echo $rules[0];?>,
							label : "Action: <?php echo $rules[0];?>"
						},{
							showOnTop: true,
							color:"#BBBB00",
							value:<?php echo $rules1[0];?>,
							label : "Warring: <?php echo $rules1[0];?>"
						}]
					  },
					  toolTip: {
						shared: "true"
					  },
					  data: [<?php echo $value; ?>]
					});
				chart.render();
			
				var chart2 = new CanvasJS.Chart("chartContainer2",
					{      
					  title:{
						text: "ISO 2631 - Vertical"
					  },
					  zoomEnabled: true,
					  axisX :{
						valueFormatString: "H:m:s" ,
						title:"<?=$datetime?>",
						interval: 1000,
						
					  },
					  axisY :{
						includeZero: false,
						title:"<?php echo ($_GET['Axis'] == 2) ? 'Gal':'dB';?>",
						//maximum: <?php echo ($_GET['Axis'] == 2) ? ($rules[1]+0.03):($rules[1]+10);?>,
						stripLines:[{
							showOnTop: true,
							color:"#FF0000",
							value:<?php echo $rules[1];?>,
							label : "Action: <?php echo $rules[1];?>"
						},{
							showOnTop: true,
							color:"#BBBB00",
							value:<?php echo $rules1[1];?>,
							label : "Warring: <?php echo $rules1[1];?>"
						}]
					  },
					  toolTip: {
						shared: "true"
					  },
					  data: [<?php echo $value2; ?>]
					});

				chart2.render();
				
				window.print();
				
			}
			
			
			$(".confirm-save").click(function(){
				alert("<?=data_update?>");
				location.href="?item=iso&details=<?php echo $_GET['details'];?>&Axis="+$("input[name='Axis']:checked").val()+"&rules="+$("input[name='rules']:checked").val()+"&duration="+$("#d1").val();
				
			})
			$(".confirm-print").click(function(){
				 window.open("print_iso.php?item=iso&details=<?php echo $_GET['details'];?>&Axis="+$("input[name='Axis']:checked").val()+"&rules="+$("input[name='rules']:checked").val()+"&duration="+$("#d1").val(),'_blank');
				
			});
			
		  </script>
		<div id="chartContainer" style="height: 300px; width: 100%;"></div>
    </body>
</html>