<?
	include_once("config.php");
	class Mail extends Fly5 {
		function execute(&$view, $path, $args)
		{
			$a = $_REQUEST;
			switch($path) {
			case "Mail/api/fetch":
				$result = $this->fetch($a);
				break;
			case "Mail/api/done":
				$result = $this->done($a);
				break;
			default:
				$view = "$path.pug";
				return;
			}
			reply_json($result);
		}
		function fetch($a)
		{
			if($a[limit])
				$limit = "limit $a[limit]";
			/*
			print_r($a);
			echo "Select * from mail where 
				hid=:hid and room=:room and bedno=:bedno 
				and done=0 
				$limit";
			*/
			$rows = query("Select * from mail where 
				hid=:hid and room=:room and bedno=:bedno 
				and done=0 
				$limit", $a);
			return $rows;
		}
		function done($a)
		{
			$r = query("update mail set done=1 where no=:mailno and hid=:hid", $a);
			return $r;
		}
	}