<?php

$style="";
$date="";
$hour="";
if(isset($_GET['style'])){
	$style = trim($_GET['style']);
//	echo $style;
}
if(isset($_GET['date'])){
	$date = trim($_GET['date']);
//	echo $date;
}
if(isset($_GET['hour'])){
	$hour = trim($_GET['hour']);
//	echo $hour;
}

$key_space = 'png';
$column_family = 'png';
$column_family_date = 'date';

require_once 'Cassandra.php';


// list of seed servers to randomly connect to
// all the parameters are optional and default to given values
$servers = array(
	array(
		'host' => '127.0.0.1',
		'port' => 9160,
		'use-framed-transport' => true,
		'send-timeout-ms' => 1000,
		'receive-timeout-ms' => 1000
	)
);

$cassandra = Cassandra::createInstance($servers);
$cassandra->useKeyspace($key_space);
$cassandra->setMaxCallRetries(5);

$id=$date.$hour;
if ( $id == ""){
	echo "nothing! <br>";
	echo "ex:png_out.php?date=20110817&hour=02";
}else{
	$target = $cassandra->cf($column_family)->get($id);
	if ($target == null){
		echo "no data";
	}else{
		header('Content-Type: image/png');
		echo $target["content"];
		/* 
		// show all , maybe work but exceed 30 secs.
		$target = $cassandra->cf($column_family)->getKeyRange();
		echo 'Schema: <pre>'.print_r($target->getAll(), true).'</pre><hr/>';
		*/
	}
}

?>

