<?php
 
$ch = curl_init();
$urlempresa="sistemex.com";
curl_setopt($ch, CURLOPT_URL,"https://quiz.sistemex.com/seopanel/pagespeed.php");

curl_setopt($ch, CURLOPT_POST, TRUE);

curl_setopt($ch, CURLOPT_POSTFIELDS, "website_urls=$urlempresa");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$remote_server_output = curl_exec ($ch);
 
curl_close ($ch);

$json=json_decode($remote_server_output, true);	



?>

<html>
<head></head>    

<body>
   

<div id='subcontent'>
<div class="speed_details">

	
	<?php 
	foreach ($json as $deviceType => $deviceInfo) {
		$divStyle = ($deviceType == 'desktop') ? "display: block;" : "";
		
		// chekc speed rule
		if ($deviceInfo['speed_score'] < 50) {
			$style = "color: #DD4B3E";
		} else if ($deviceInfo['speed_score'] < 85) {
			$style = "color: #FDA100";
		} else {
			$style = "color: #009A2D";
		}
		
		// check usability rule
		if ($deviceInfo['usability_score'] < 50) {
			$usabilityStyle = "color: #DD4B3E";
		} else if ($deviceInfo['usability_score'] < 85) {
			$usabilityStyle = "color: #FDA100";
		} else {
			$usabilityStyle = "color: #009A2D";
		}
		
		?>
		<div id="<?php echo $deviceType;?>" class="tabcontent" style="<?php echo $divStyle; ?>">
		<h1><?php echo strtoupper($deviceType); ?></h1>
			<div class="score">
				<h2>Score</h2>
				<div class="score_val" style="<?php echo $style?>"><b>
				    Speed:</b> <?php echo $deviceInfo['speed_score']?> / 100</div>	
				
				<?php if ($deviceType == 'mobile') {?>
					<div class="score_val" style="<?php echo $usabilityStyle?>"><b>Usability:</b> <?php echo $deviceInfo['usability_score']?> / 100</div>
				<?php }?>
			</div>
			
			<?php 
			foreach ($deviceInfo['details'] as $ruleType => $ruleInfo) {

				// chekc rule impact
				if ($ruleInfo['ruleImpact']) {
					$style = "color: #FDA100;";
				} else {
					$style = "color: #009A2D;";
				}
				?>
				<h3 style="<?php echo $style?> padding-top: 8px; border-top: 1px solid #ccc;">>> <?php echo $ruleInfo['localizedRuleName']?></h3>
				<div class="imapct_area"><b>Impact:</b> <?php echo $ruleInfo['impactGroup']?></div>
				<div><?php echo $ruleInfo['summary']?></div>
				<?php 
				foreach ($ruleInfo['urlBlocks'] as $urlBlockInfo) {
					?>
					<h4><?php echo $urlBlockInfo['header']?></h4>
					<?php
					foreach ($urlBlockInfo['urls'] as $url) {
						?>
						<div class="url_area"><?php echo $url?></div>
						<?php
					}
				}
				?>
				<div style="clear: both;">&nbsp;</div>
				<?php
			}
			?>
		</div>
		<?php
	}
	?>
</div>
</div>

</body>    
</html>


