<?php
/**
*	获取数据
*	访问地址如：http://127.0.0.1/app/rockoffice/api.php?m=opendata
*/
class opendataClassAction extends openapiAction
{
	
	
	public function indexAction()
	{
		$table 	= $this->get('table','agent');
		$farr  	= $this->db->getallfields($table);
		$start	= (int)$this->get('start','0');
		$limit	= (int)$this->get('limit','10');
		$totalCount = $this->db->rows('`[Q]'.$table.'`','1=1');
		$sort	= $this->get('sort','id');
		$dir	= $this->get('dir','desc');
		$sql 	= 'select * from `[Q]'.$table.'` order by `'.$sort.'` '.$dir.' limit '.$start.','.$limit.'';
		$rows  	= $this->db->getall($sql);
		
		return array(
			'rows' => $rows,
			'totalCount' => $totalCount,
			'farr' => $farr,
		);
	}
	
	/**
	*	删除数据
	*/
	public function delAction()
	{
		$table 	= $this->get('table');
		$id 	= $this->get('id');
		if(!$table || !$id)return;
		m($table)->delete("`id` in($id)");
		
		return returnsuccess('delok');
	}
	
	/**
	*	保存编辑
	*/
	public function savecellAction()
	{
		$table 	= $this->get('table');
		$id 	= (int)$this->get('id','0');
		if(!$table || !$id)return;
		$fieldname 	= $this->post('fieldname');
		$value 	= $this->post('value');
		$uarr[$fieldname] = $value;
		
		m($table)->update($uarr,"`id` =$id");
		
		return returnsuccess('saveok');
	}
}	