<?php
/*
　* @$Id
　* @
　* @Ver: 1.0
　* @Create: 2009-04-01 8:10
　* @Modify: 
　* @Author: CPWEB http://www.zilaiye.org
　* @Copyright (C) 2008 www.zilaiye.org. All Rights Reserved.
　* @License CPWEB is free software and use is subject to license terms
　*/
class ModelAction extends GlobalAction 
{
	public function index(){
		$ModelView = D('ModelView');
		$map['t_c_values'] = 'model';
		$modelview = $ModelView->where($map)->findall();
		$this->assign('models',$modelview);
		$this->assign('db_prefix',C('DB_PREFIX'));
		$this->display();
	}
	public function search()
	{
		$id=intval($_GET["id"]);
		if (!$id) $this->error(L('CPWEB_SELECT_NOT_EXIST'));
		$Cpweb=D("CpwebView");
		$map['Cpweb.id']=$id;
		$cpweb=$Cpweb->where($map)->find();
		if (!$cpweb) $this->error(L('CPWEB_SELECT_NOT_EXIST'));
		$ModelView = D('ModelView');
		$model_map['t_c_values'] = 'model';
		$modelview = $ModelView->where($model_map)->findall();
		$db_prefix = C('DB_PREFIX');
		$Settings=D("Settings");
		$map_1["type_values"]='xt_set';
		$type=M('Type')->where($map_1)->find();
		$set_map["type_id"]=$type['id'];
		$set_map["title"]='cpfunction';
		$settings=$Settings->where($set_map)->find();
		if($settings){
			$CpFunction=A('CpFunction');
			$cpfunction=unserialize($settings['set_values']);
			$this->assign('cp_fun',$cpfunction->model);
		}
		$this->assign('models',$modelview);
		$this->assign('db_prefix',$db_prefix);
		$this->assign('cpweb',$cpweb);
		$this->display();
	}
	public function searchs(){
		$data=$_POST;
		$CpFunction=A('CpFunction');
		foreach ($data['data'] AS $key=>$value ){
			$CpFunction->set($key,$value);
		}
		$cp=serialize($CpFunction);
		$Settings=D("Settings");
		$map_1["type_values"]='xt_set';
		$type=M('Type')->where($map_1)->find();
		$map["type_id"]=$type['id'];
		$map["title"]='cpfunction';
		$settings=$Settings->where($map)->find();
		if($settings){
			$settings["set_values"]=$cp;
			if($Settings->save($settings)){
				$this->assign('jumpUrl',__APP__.'/Cpweb');
				$this->success(L('CPWEB_SUCCESS_EDIT'));
			}else{
				$this->error(L('CPWEB_ERROR_EDIT'));
			}
		}else{
			$map["set_values"]=$cp;
			if($Settings->add($map)){
				$this->assign('jumpUrl',__APP__.'/Cpweb');
				$this->success(L('CPWEB_SUCCESS_EDIT'));
			}else{
				$this->error(L('CPWEB_ERROR_EDIT'));
			}
		}
	}
}
?>