<?php

$structure = "";
if (isset($_SESSION['structure']))
	$structure = $_SESSION['structure'];
	
$struct = json_decode($structure);
$updates = $_REQUEST['grid'];
$newstruct = json_decode($updates);

$x = 0;
foreach($newstruct as $ns)
{
	$trend = false;
	if ($ns->style == "line") $trend = true;
	if ($ns->style == "discrete") $trend = true;
	
	if ($trend == false)
	{
		$struct->panels[$ns->id]->x = $ns->x;
		$struct->panels[$ns->id]->y = $ns->y;
		$struct->panels[$ns->id]->w = $ns->w;
		$struct->panels[$ns->id]->h = $ns->h;
	}
	else
	{
		$struct->panels[$ns->id]->hx = $ns->x;
		$struct->panels[$ns->id]->hy = $ns->y;
		$struct->panels[$ns->id]->hw = $ns->w;
		$struct->panels[$ns->id]->hh = $ns->h;
	}
	$struct->panels[$ns->id]->style = $ns->style;
	if (property_exists($ns,'title'))
	{
		$struct->panels[$ns->id]->name = $ns->title; 
	}
	$x++;
}

//$struct->name = $newstruct->name;

$_SESSION['structure'] = json_encode($struct);
//echo $_SESSION['structure'];
?>