<?php

class plus_langMod extends commonMod
{
    public function __construct()
    {
        parent::__construct();
    }

    // 管理
    public function index()
    {
        $list = $this->model->table('lang')->select();
        $this->assign('list', $list);
        $this->display();
    }
    // 添加
    public function add()
    {
        if (empty($_POST['psot_do'])) {
            $this->display();
            return;
        }
        $data = array();
		$data['name'] = in($_POST['name']);
        $data['lang'] = in($_POST['lang']);

        if (empty($data['name'])) {
            $this->jserror('名称不能为空！');
            return;
        }
        if (empty($data['lang'])) {
            $this->jserror('标识不能为空！');
            return;
        }

        $condition['lang'] = $data['lang'];
        $info = $this->model->table('lang')->where($condition)->find();
        if ($info['lang'] == $data['lang']) {
            $this->jserror('语言不能重复！');
            return;
        }

        // 数据库操作
        $this->model->table('lang')->data($data)->insert();
        $this->jssuccess('语言添加成功！');
    }
    // 修改
    public function edit()
    {
        if (empty($_POST['psot_do'])) {
            $id = intval($_GET[0]); //获取ID
            if (empty($id)) {
                $this->error('参数传递错误！');
                return;
            }
            $condition['id'] = $id;
            $info = $this->model->table('lang')->where($condition)->find(); //获取当前页面信息
            if (empty($info)) {
                $this->error('该语言不存在！');
                return;

            }

            $this->assign('info', $info);
            $this->display();
            return;
        }
        
        $data = array();
        $data['name'] = in($_POST['name']);
        $data['lang'] = in($_POST['lang']);


        if (empty($data['name'])) {
            $this->jserror('名称不能为空！');
            return;
        }
        if (empty($data['lang'])) {
            $this->jserror('标识不能为空！');
            return;
        }


        // 数据库操作
        $condition2['id'] = intval($_POST['id']);
        $this->model->table('lang')->data($data)->where($condition2)->update();
        $this->jssuccess('语言修改成功！');
    }

    // 删除
    public function del()
    {
        $id = intval($_GET[0]);
        if (empty($id)) {
            $this->jserror('参数传递错误！');
            return;
        }
        
        $condition['id'] = $id;
        $this->model->table('lang')->where($condition)->delete();
        $this->jssuccess('语言删除成功！');

    }

}

?>