<?php
!defined('P_W') && exit('Forbidden');
require_once MODE . '/base/admincontroller.php';
class CommentController extends AdminController {
	var $_commentHelper ;
	var $_perpage = 20;
	
	function _before() {
		parent::_before();
		$this->_commentHelper = DP::loadClass('commenthelper', 'helper');
		$this->_viewer->baseUrl = $this->_getGlobal('basename');
		return true;
	}
	
	/**
	 * 评论管理-默认执行的方法获得评论列表
	 */
	function run() {
		$arr = array();
		list($arr['startdate'], $arr['enddate'], $v, $page) = $this->_gp(array('startdate', 'enddate', 'v', 'page'));
		if($v == "comment1" && $this->_isPost()) {
			list($keyword, $type) = $this->_gp(array('act_title', 'type'));
			(!empty($keyword)) && ($type == 1) ? $arr['content'] = $keyword : $arr['username'] = $keyword;
		} else {
			list($arr['content'], $arr['username']) = $this->_gp(array('content','username'));
			$keyword = ($arr['content']) ? $arr['content'] : $arr['username'];
			($arr['username']) ? $type= 2 : $type = 1;
		}
		$page = (!$page) ? 1 : intval($page);
		list($count, $arr['page'], $totalpage, $commentList) = $this->_commentHelper->getAdminCommentList($arr, $page, $this->_perpage);
		$Url = $this->_getGlobal('basename') . '&action=run';
		$pageurl = $this->_commentHelper->getPageUrl($arr);
		$this->_viewer->search = $arr;
		$this->_viewer->keyword = $keyword;
		$this->_viewer->type[$type] = "checked='checked'";
		$this->_viewer->startdate = $arr['startdate'];		
		$this->_viewer->enddate = $arr['enddate'];
		$this->_viewer->backUrl = $this->_viewer->baseUrl . '&' . $pageurl . '&page=' . $arr['page'];
		$this->_viewer->pager = numofpage($count,$arr['page'],$totalpage,"$Url&$pageurl&#x_comment_list");
		$this->_viewer->comments = $commentList;
	}
	
	/**
	 * 评论管理-删除评论
	 */
	function deleteComment() {
		list($id) = $this->_gp(array('commentid'));
		$arr = array();
		list($arr['content'], $arr['username'], $arr['page'], $arr['startdate'] , $arr['enddate']) = $this->_gp(array('content','username' ,'page','startdate', 'enddate'));
		$pageurl = $this->_commentHelper->getPageUrl($arr);
		(empty($id)) && Error::showError("请选择需要删除的评论!", $this->_viewer->baseUrl . '&action=run&page=' . $arr['page'] . '&' . $pageurl);
		list($flag, $message) = $this->_commentHelper->delCommentForAdmin($id);
		Error::showError($message, $this->_viewer->baseUrl . '&action=run&page=' . $arr['page'] . '&' . $pageurl);
	}
	
	/**
	 * 评论管理-删除多条评论
	 */
	function deleteComments() {
		list($ids) = $this->_gp(array('commentid'));
		$arr = array();
		list($arr['content'], $arr['username'], $arr['page'], $arr['startdate'] , $arr['enddate'], $po) = $this->_gp(array('content','username' ,'page','startdate', 'enddate', 'po'));
		$pageurl = $this->_commentHelper->getPageUrl($arr);
		(empty($ids)) && Error::showError("请选择需要删除的评论!", $this->_viewer->baseUrl . '&action=run&page=' . $arr['page'] . '&' . $pageurl);
		if($po == 'listv2' && $this->_isPost()) {
			list($flag, $message) = $this->_commentHelper->delCommentsForAdmin($ids);
			Error::showError($message, $this->_viewer->baseUrl . '&action=run&page=' . $arr['page'] . '&' . $pageurl);
		}
		$this->_setTemplate($this->_commentHelper->_buildTemplate($this->_controller, 'run'));
	}
}
?>