<?php
/**
 * 会员等级模块
 * @author  Terry<admin@ivears.com>
 * @date 2013-05-13
 */
class MemberLevelAction extends AdminAction{
    
    public function _initialize() {
        parent::_initialize();
    }
	
	public function index(){
		
        $name = $this->getActionName();
        $action = D($name);
        $ary_get['pageall'] = $this->_get('pageall', 'htmlspecialchars', 10);
        $count = $action->where()->count();
        $obj_page = $this->_Page($count, $ary_get['pageall']);
        $page = $obj_page->newshow();
        $ary_data = $action->where()->limit($obj_page->firstRow, $obj_page->listRows)->order(array('ml_order'=>'asc'))->select();

		
		//print_r($ary_data);
		//exit;
        $this->assign("data", $ary_data);
        $this->assign("page", $page);
		
		$this->display();	
	}
	
	public function addMemberLevel(){
		if($_POST){
				$acname = $this->getActionName();
				$action = D($acname);
				$data=$_POST;
                $data['ml_create_time'] = date("Y-m-d H:i:s");
                $ary_result = $action->add($data);
                if(FALSE !== $ary_result){
                    $this->success("操作成功");
                }else{
                    $this->error("操作失败");
                }		
		}else{
			$this->display();	
		}
	}
	
	
	public function edit(){
		$name = $this->getActionName();
		$action = D($name);
		$ary_get = $this->_get();
		if($_POST){
                $where = array();
				$ary_post = $this->_post();
                $where['ml_id'] = $ary_post['id'];
                unset($ary_post['id']);
                $ary_post['ml_update_time'] = date("Y-m-d H:i:s");
                $ary_result = $action->where($where)->data($ary_post)->save();
                if(FALSE !== $ary_result){
                    $this->success("修改成功");
                }else{
                    $this->error("修改失败");
                }		
		}else{
			$ary_data = $action->where(array('ml_id'=>$ary_get['id']))->find();
			$this->assign("data",$ary_data);
			$this->display();
		}
	}
}
