<?php

class modelAction extends CommonAction{
	function __construct(){
			parent::__construct();
			$this->model=new modelModel();

		}

    function mod() {
    	$model = $this->model->findAll(array("id","model_name","type","version","sumary","readonly"),0, 0,"","id");
    	$this->assign("model",$model);
    	$this->display("admin/public/modelmod.html");
    }

    function field_edit(){
    	$row = $this->model->find($_REQUEST['id']);
//   	print_r($row);
    	$this->assign("mid",$_REQUEST['id']);
    	if($_REQUEST['do']=='add'){
    		$this->assign("fieldform","true");
    	}
    	$this->assign('fields',unserialize($row[fieldset]));

		$this->display("admin/public/field_list.html");
    }



    function add(){
    	$this->display("admin/public/model.html");
    }


    function updoad_model(){
    	$upload = new upload(array('filepath'=>'./tmp','allowType'=>array('zip')));
		if($upload->uploadFile('upfile')){
			echo $upload->getNewFileName();
		}else{
			echo $upload->getErrorMsg();
		}

    }


    function field_add(){
    	if($this->model->validate()){
			if(preg_match('/^(select|radio|checkbox)$/',$_POST[dtype]))
				{
					if(!preg_match('/\,/',$_POST[vdefault]))
					{
					$this->showMsg("字段为 {$_POST[dtype]} 类型，必须在默认值中指定元素列表，如：'a,b,c' ","-1");

					}
				}
			if(!$this->model->field_add()){
				$this->showMsg("字段为 {$_POST[dtype]}增加失败","-1");
			}else{
				$this->showMsg("字段为 {$_POST[dtype]}增加成功","admin.php?m=model&a=field_edit&id=".$_REQUEST['id']."");
			}


    	}else{
    		$this->showMsg($this->model->getMessList(),"admin.php?m=model&a=field_edit&id=".$_REQUEST['id']."&do=add");
    	}

    }

	function field_del(){

			if(!$this->model->field_del()){
				$this->showMsg("字段为 {$_REQUEST[fieldname]}册除失败","-1");
			}else{
				$this->showMsg("字段为 {$_REQUEST[fieldname]}册除成功","-1");
			}
	}



}
?>
