<?php

/**
 * 本类放置通道增、删、改、查等操作
 *
 * @author 杨金球
 */
class PassagewayAction extends CommonAction {

    public function index() {
        $way = M('passageway');
        
        $way_list = $way->order('type DESC')->select();
        
        $this->assign('way', $way_list);
        $this->display();
    }

    //开启镜像
    public function open_way() {
        $map['id'] = $_GET['id'];
        $map['status'] = 1;

        $way = M('passageway');

        if (!$way->save($map)) {
            $this->ajaxReturn('', '', 0);
        } else {
            $this->ajaxReturn('', '', 1);
        }
    }

    //禁用镜像
    public function forbidden_way() {
        $map['id'] = $_GET['id'];
        $map['status'] = 0;

        $way = M('passageway');

        if (!$way->save($map)) {
            $this->ajaxReturn('', '', 0);
        } else {
            $this->ajaxReturn('', '', 1);
        }
    }

    //批量镜像
    public function forbidden_ways() {
        $map['id'] = array('in', $_GET['id']);
        $map['status'] = 0;

        $way = M('passageway');

        if (!$way->save($map)) {
            $this->ajaxReturn('', '', 0);
        } else {
            $this->ajaxReturn('', '', 1);
        }
    }

    //删除镜像
    public function del_way() {
        $map['id'] = $_GET['id'];

        $way = M('passageway');

        if (!$way->where($map)->delete()) {
            $this->ajaxReturn('', '', 0);
        } else {
            $this->ajaxReturn('', '', 1);
        }
    }

    //新增镜像
    public function add_passageway() {
        $this->display();
    }

    //新增镜像保存
    public function add_passageway_save() {
        $map['name'] = $_POST['name'];
        $map['url'] = $_POST['url'];
        $map['type'] = $_POST['type'];
        $map['status'] = 1;

        $way = M('passageway');

        if (!$way->add($map)) {
            $this->ajaxReturn('', '', 0);
        } else {
            $this->ajaxReturn('', '', 1);
        }
    }

    //编辑镜像
    public function edit_passageway() {
        $map['id'] = $_GET['id'];

        $way = M('passageway');

        $way_msg = $way->where($map)->find();

        $this->assign('way', $way_msg);
        $this->display();
    }

    //编辑镜像保存
    public function edit_passageway_save() {
        $map['id'] = $_GET['id'];
        $map['name'] = $_POST['name'];
        $map['url'] = $_POST['url'];
        $map['type'] = $_POST['type'];

        $way = M('passageway');

        if (!$way->save($map)) {
            $this->ajaxReturn('', '', 0);
        } else {
            $this->ajaxReturn('', '', 1);
        }
    }

}

?>
