<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Recommended Phone Summary</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
  <?php

		$PhoneID = $_GET["PhoneID"];
// Create connection
include "include.php";
$con=get_database_connection();  
  
   $arrays = json_decode(stripslashes($_GET["arrays"]));
  $NeedsArray = $arrays->needs;
  $ImpairmentsArray = $arrays->impairments;
  $PreferencesArray = $arrays->preferences;

  //Get all the details of the selected phones.
  $result = mysqli_query($con,"SELECT * FROM Phone WHERE PhoneID = '".$PhoneID."'");

  if($row = mysqli_fetch_array($result))
  {
            echo "
			<h1>Recommended Phone Summary</h1>
            <h2>".$row['Model']."</h2>
			<h3>General Information</h3>
            <div class='large-phone-image'><img src='".$row['ImagePath']."'/></div>
            <div class='full-phone-details'>";
            echo "<table width='700px' border='0'>";
			echo "<tr><td><strong>Manufacturer/Importer:</strong> ".$row['Manufacturer']."</td></tr>";
            echo "<tr><td><strong>Brand:</strong> ".$row['Brand']."</td></tr>";
		    echo "<tr><td><strong>Model:</strong> ".$row['Model']."</td></tr>";
		    echo "<tr><td><strong>Website and/or contact:</strong> ".$row['Website']."</td></tr>";
            echo "<tr><td><strong>Operating System:</strong> ".$row['OperatingSystem']."</td></tr>";
		    echo "<tr><td><strong>Standby Time/Talk Time: </strong>".$row['StandbyTime']."</td></tr>";
            echo "<tr><td><strong>Handset Weight: </strong>".$row['HandsetWeight']."</td></tr>";
			echo "<tr><td><strong>Headset - plug type: </strong>".$row['PlugType']."</td></tr>";
			echo "<tr><td><strong>Display Characteristics - Main Display Size: </strong>".$row['MainDisplaySize']."</td></tr>";
			echo "<tr><td><strong>Display Characteristics - Main Display Resolution: </strong>".$row['MainDisplayResolution']."</td></tr>";
			echo "<tr><td><strong>Supports ability to install third party applications or apps: </strong>".$row['AppAbility']."</td></tr>";
			echo "<tr><td><strong>Internet Capability: </strong>";
			if ($row['InternetCapability']=='1')
				echo "Yes";
			else 
				echo "No";
			echo "</td></tr>";
			echo "<tr><td><strong>Smartphone: </strong>";
			if ($row['Smartphone']=='1')
				echo "Yes";
			else 
				echo "No";
			echo "</td></tr>";
			echo "<tr><td><strong>Alternative format User Manual: </strong>";
			if ($row['AfUserManual']=='1')
				echo "Yes";
			else 
				echo "No";
			echo "</td></tr>";
            echo "<tr><td><strong>Optional accessories: </strong>";
			if ($row['Accessories']==1)
				echo "Yes";
			else 
				echo "No";
			echo "</td></tr>";
            echo "</div></table>";
			  
	}
			 if (count($NeedsArray)>0){
			  echo "<h3>Step 1: Selected Needs</h3>";
			  echo "<table width='80%'><tr><td width='400'>NEEDS</td><td>DESCRIPTION</td></tr>";
			  
			  
			  foreach($NeedsArray as $y){
				  $sql = "SELECT Feature.Name as FName, Feature.Description as FDesc, UserRequirement.Name as RName, Value, UserRequirement.Type FROM FeatureRequirement, UserRequirement, Feature, PhoneFeature WHERE FeatureRequirement.RequirementID = '".$y."' AND UserRequirement.RequirementID = FeatureRequirement.RequirementID AND Feature.FeatureID = FeatureRequirement.FeatureID AND PhoneFeature.PhoneID='".$PhoneID."' AND PhoneFeature.FeatureID = Feature.FeatureID";
				//  echo $sql."<br/>";
			    $result2 = mysqli_query($con, $sql);
				  while($row = mysqli_fetch_array($result2)){
					  
					  //Display Name and Description
					  echo "<tr><td>".$row['FName']."</td>";
					  echo "<td>".$row['FDesc']."</td>";
					  echo "</tr>\n";
				  }
			  }
				  echo "</table>";
				  }
				  
				  
				  if (count($ImpairmentsArray)>0){
					 echo "<h3>Step 2: Relevant features for selected impairments</h3>";
					 echo "<table width='80%'><tr><td width='400'>SELECTED IMPAIRMENT/FEATURES</td><td>DESCRIPTION</td></tr>"; 
				  
				  
				  foreach($ImpairmentsArray as $y){	  
					  
					 $sql = "SELECT ExtendedName, Description From UserRequirement WHERE RequirementID = '".$y."'";
				    $resultI = mysqli_query($con,$sql);
					
					
$sql = "SELECT Feature.Name as FName, Feature.Description as FDesc, UserRequirement.Name as RName, Value, UserRequirement.Type FROM FeatureRequirement, UserRequirement, Feature, PhoneFeature WHERE FeatureRequirement.RequirementID = '".$y."' AND UserRequirement.RequirementID = FeatureRequirement.RequirementID AND Feature.FeatureID = FeatureRequirement.FeatureID AND PhoneFeature.PhoneID='".$PhoneID."' AND PhoneFeature.FeatureID = Feature.FeatureID";					$result2 = mysqli_query($con, $sql);
					
				  while($row = mysqli_fetch_array($resultI)){
					  echo "<tr>";
					  echo "<td colspan='3'><strong>".$row['ExtendedName']."</strong></td></tr>";
				  }
	
			  while($row = mysqli_fetch_array($result2)){
				  					  if (!$row['Value']) continue;
					  echo "<tr><td>".$row['FName']."</td>";
					  echo "<td>".$row['FDesc']."</td>";
					  echo "</tr>\n";
				  }
				  
				  }
				echo "</table>";
				  }
				  
	
			
				//Selected Preferences  
			  if (count($PreferencesArray)>0){
			  echo "<h3>Step 3: Selected Preferences</h3><table width='80%'>";
			  echo "<tr><td width='400'>SELECTED PREFERENCES</td><td>DESCRIPTION</td></tr>";
				foreach($PreferencesArray as $y){

					$sql = "SELECT Feature.Name as FName, Feature.Description as FDesc, UserRequirement.Name as RName, Value, UserRequirement.Type FROM FeatureRequirement, UserRequirement, Feature, PhoneFeature WHERE FeatureRequirement.RequirementID = '".$y."' AND UserRequirement.RequirementID = FeatureRequirement.RequirementID AND Feature.FeatureID = FeatureRequirement.FeatureID AND PhoneFeature.PhoneID='".$PhoneID."' AND PhoneFeature.FeatureID = Feature.FeatureID";
					
			    $result = mysqli_query($con,$sql);
				  while($row = mysqli_fetch_array($result)){
					  if (!$row['Value']) continue;
					  echo "<tr><td>".$row['FName']."</td>";
					  echo "<td>".$row['FDesc']."</td>";
						 echo "</tr>\n";
				  }
				
				}
				echo "</table>";
			  }
			  ?>
</div>
</div>
</body>
</html>
