<?php
/**
 * Copy Right IJH.CC
 * Each engineer has a duty to keep the code elegant
 * $Id$
 */
if(!defined('__CORE_DIR')){
    exit("Access Denied");
}
class Ctl_Ucenter_Message extends Ctl_Ucenter
{
    

    public function index()
    {

        $filter = $pager = array();
    	$pager['page'] = max(intval($page), 1);
    	$pager['limit'] = $limit = 20;
        $filter['uid'] = array($this->uid,0);
        $status = $this->GP('arg');
        
        if($status == 1){ //未读
            $filter['is_read'] = 0;
        }else{ //已使用或过期
             $filter['is_read'] = 1;
        }
        if($items = K::M('message/message')->items($filter, null, $page, $limit, $count)){      
        	$pager['count'] = $count;
        	$pager['pagebar'] = $this->mkpage($count, $limit, $page, $this->mklink(null, array('{page}')));
        }
        $this->pagedata['status'] = $status;
        $this->pagedata['items'] = $items;
        $this->pagedata['pager'] = $pager;

        $this->tmpl = 'ucenter/message/index.html';
        
    }
    
    
     public function detail($message_id)
    {
        if(!$message_id = (int)$message_id){
            $this->error(404);
            
        }else if(!$detail = K::M('message/message')->detail($message_id)){
            $this->error(404);
        }else{
            K::M('message/message')->update($message_id,array('is_read'=>1));
            $this->pagedata['detail'] = $detail;
            $this->tmpl = 'ucenter/message/detail.html';
        }  
    }
    
    


    
}