<?php

namespace Admin\Controller;

use Common\Controller\AdminbaseController;

/*
*IP屏蔽控制器
*/

class IpshieldingController extends AdminbaseController{

	public function index(){

		$count=M("ip_shielding")->count();

		$page       = new \Think\Page($count,20);//实例化分页类 传入总记录数和每页显示的记录数

		$lists=M('ip_shielding')

		->limit($page->firstRow . ',' . $page->listRows)

		->select();

		$this->assign('lists',$lists);

		$this->assign("page", $page->show());

		$this->display();

	}

	public function add(){

		if(IS_POST){

			$IP=M('ip_shielding');

			$rules = array(
				array('ip','require','IP必须！'), 

				array('ip','','IP已存在！',0,'unique',1), 

				array('ip','/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/ ','IP格式错误！',1 , 'regex' ,1),
				);

			if (!$IP->validate($rules)->create()){

				$this->error($IP->getError());

			}else{

				$IP->add();

				$this->success('增加成功');

			}

		}else{

			$this->display();

		}


	}

	public function delete(){

		$id=I('id');

		if(M('ip_shielding')->where(array("id"=>$id))->delete()){

			$this->success('删除成功！');

		}else{

			$this->error('删除失败！');

		}

	}

}