<?php
session_start();
if( !defined('IN') ) die('bad request!');
include_once( AROOT . 'controller' . DS . 'app.class.php');
header("Content-Type: text/html; charset=utf-8");

class indexController extends appController
{
	public function __construct(){
		parent::__construct();
	}

	//发送错误结果集
	public function send_error($number,$msg)
	{
		$obj = array();
		$obj['code'] = intval($number);
		$obj['result'] = $msg;

		if( g('API_EMBED_MODE') == 1 ){
			return json_encode($obj);
		}else{
			header("Content-Type: application/json");
			die(json_encode($obj));
		}
	}

	//发送结果集
	public function send_result($data)
	{
		$obj = array();
		$obj['code'] = 0;
		$obj['result'] = 'success';
		$obj['data'] = $data;

		if( g('API_EMBED_MODE') == 1 ){
			return json_encode($obj);
		}else{
			header("Content-Type: application/json");
			die(json_encode($obj));
		}
	}

	/*
	*  返回登录界面
	*  
	*/ 
	public function index()
	{

		render(null, 'web', 'login'); 
	
	}


	/*
	*	返回首页
	*
	*/
	public function returnHomePage()
	{

		render(null, 'web', 'index');
		
	}

	
	/*
	*	页面浏览日志	
	*
	*/
	public function recordOperationLog()
	{
		$token = $_SESSION['token'];

		// 通过token获取user_id
		$sql = prepare("select id from opm_ds_user where token = ?s limit 1",array($token));
		$user_id = get_var($sql);

		return $user_id;
	}

	public function test()
	{

		$result['time'] = ['09-13','09-14','09-15','09-16','09-17','09-18','09-19','09-20','09-21','09-22'];
		$result['res'][0] = array("name"=>'辐射异常报警',"data"=>[1,4,7,3,8,2,1,8,4,3]);
		$result['res'][1] = array("name"=>'设备离线报警',"data"=>[4,7,9,5,7,9,0,5,7,8]);

		return self::send_result($result);
	}

	public function test1()
	{
		$result = [31,21,45];

		return self::send_result($result);
	}

	public function test2()
	{
		$result = [31,21,45];

		return self::send_result($result);
	}
}	
?>
