<?php   
  session_start();
  include "include.php";
  include_jquery();

		echo "<h3>Phone Details</h3>";

echo "<div id='phones-images'>";

//include "Step1-c.php";
$gbrand = $_GET["Brand"];
$priority = $_GET["Priority"];
$arrays = stripslashes($_GET["arrays"]); 

$settings = json_decode($arrays);
	
	//Depending on the number passed  retrieve the appropriate array of phones
	
	if ($priority == '!'){
		$PhoneArray = $_SESSION['Phones'];
	}
		
	if ($priority == '1')
		$PhoneArray = $_SESSION['Most'];
		
	if ($priority == '2')
		$PhoneArray = $_SESSION['Well'];
		
	if ($priority == '3')
		$PhoneArray = $_SESSION['Suit'];
		
		if ($priority == '1b')
		$PhoneArray = $_SESSION['FinalMost'];
		
	if ($priority == '2b')
		$PhoneArray = $_SESSION['FinalWell'];
		
	if ($priority == '3b')
		$PhoneArray = $_SESSION['FinalSuit'];
		

if (count($settings->impairments)==0) {
	$PhoneArray = $_SESSION['Phones'];
}

$con = get_database_connection();

$count = 0;
foreach($PhoneArray as $array_value){ 
$sql = "SELECT Model, ImagePath, PhoneID, Brand FROM `Phone`  WHERE PhoneID =".$array_value;
$result = mysqli_query($con, $sql);

//echo $sql;

while($row = mysqli_fetch_array($result)){
$phoneid = $row['PhoneID'];
$model = $row['Model'];
$path = $row['ImagePath'];
$brand = $row['Brand'];

//print the item if it's the same brand
if (!strcasecmp($gbrand, $brand)){
	if ($count ==0)
		echo "<h3>".$brand."</h3>";
	if ($count % 3 == 0){
		if ($count > 0)
			echo "</div>";
		echo "<div class='phone-row'>\n";
	}
	 echo "<div class='phone-item'><a href='phonedetails.php?PhoneID=".$phoneid."&arrays=".$arrays."' target='_blank'><img src='".$path."' alt='".$model."'  height='50' class='phone-pic'><div class='phone-name'>".$model."</div></a></div>\n";
	 $count++;
	 
	}
		
}	
}
echo "</div>";

?>
</div></div>

