<?php
require '../../fly2/fly3.php';
require 'config.php';

$app->action('api/save', function (&$view) {
	$a = $_REQUEST;
	$r = query("insert metatree (treedata) values(:treedata)", $a);
	$no = $r[lastInsertId];
	query("update metatree set version=$no where no=$no");
	echo "ok";
});

$app->action('api/load', function (&$view) {
	$a = $_REQUEST;
	if ($a[version])
		$version = " and version='$a[version]' ";
	$rows = query("select * from metatree where true $version order by no desc limit 1");
	//print_r($rows);
	echo $rows[0][treedata];
});

$app->action('test', function (&$view) {
	$r = trim(file_get_contents("http://serviceapi.modtv.co.kr/skeleton/hello"));
	modtest($r, 'Hello, World!');

	$r = trim(file_get_contents("http://serviceapi.modtv.co.kr/skeleton/a"));
	modtest($r, 'api [a] has been executed.');

	$r = trim(file_get_contents("http://serviceapi.modtv.co.kr/skeleton/b"));
	modtest($r, 'api [b] has been executed.');
	
	echo "all tests are ok";
});

$app->action('index', function (&$view) {
	$view = 'index';	
	//return array(all=>$all, hospital=>$app->getHospital());
});

?>
