<?php
     $data = json_decode(file_get_contents('php://input'), true);
     //file_put_contents("debug.txt", file_get_contents('php://input'));
     //print_r($data);

     if(count($data) == 0)
          die("data count error");

     if(!isset($data['GridName']))
          die("cant find gridname");

     if(!isset($data['RegionOwnerURL']))
          die("cant find RegionOwnerURL");

     if(!isset($data['RegionOwnerURL']))
          die("cant find RegionOwnerURL");
     
     //Add Grid
     if(isset($data['RegionOwnerURL']['HomeURI']))
          $GridData      = new OSGrid(@$data['GridName'], @$data['RegionOwnerURL']['HomeURI'], @$data['RegionOwnerURL']['AssetServerURI'], @$data['RegionOwnerURL']['IMServerURI']); 

     if(!isset($GridData))
          die("Unknown Error: Grid data not in db.");

     //Add Region
     $RegionData    =   $GridData->addRegion(@$data['RegionName'], @$data['UUID'], @$data['RegionOwnerID'], @$data['UUID'], @$data['Hostname'], @$data['Port']);

     //Add User
     $UserData      =   $GridData->addUser(@$data['RegionOwnerID'], @$data['RegionOwnerName'], @$data['RegionOwnerMail']);
?>