<?php
/*
 +----------------------------------------------------------------------
 | TEMMOKUMVC [ NO BEST, ONLY BETTER ]
 +----------------------------------------------------------------------
 | Copyright (c) 2018~2019 https://www.temmoku.cn All rights reserved.
 +----------------------------------------------------------------------
 | Author: 张宗强 Email:webmaster@temmoku.cn QQ:158726877 516669373 TEL:17895221001 微信:temmokumvc
 +---------------------------------------------------------------------- 
*/
namespace news\admin\controller;
use \temmoku\db;
use \temmoku\controller;
use \temmoku\lib\pages;
use news\public_class\comment AS comment_class;
use \news\init;
class comment extends controller{
	
	public function index(){
		!isset($_GET['page']) && $_GET['page']=1;
		$rows='20';
		
		if($_GET['state']==='-1' || $_GET['state']==='1'){
			if ($_GET['state']==='-1' ) $_GET['state']=0;
			$WHERE="state = '$_GET[state]'";
			$url='state_'.$_GET['state'].'/';
		}else{
			$WHERE="1";
		}
		$listdb=db::select('*')->from(init::$table."comment")->where($WHERE)->orderByDESC(['id'])->setPaging($rows)->page($_GET['page'])->query();
		$Get_Page=(new Pages)->Pages(init::$table."comment",$WHERE,admin_module_url."/comment/index/{$url}",$rows,$_GET['page']);
		$this->assign('listdb', $listdb);
    	$this->assign('Get_Page', $Get_Page);
    	$this->display(tpl('comment/index'));
	}
	
	public function state(){
		if(is_array($_POST['iddb'])){
			foreach($_POST['iddb'] AS $id){
				db::update(init::$table."comment")->cols(['state'=>$_POST['state']])->where("id='$id'")->query();
			}
			$this->Success('操作成功', FromUrl);
		}else{
			db::update(init::$table."comment")->cols(['state'=>$_POST['state']])->where("id='$_POST[id]'")->query();
			echo json_encode(['Result'=>'1','content'=>'操作成功']);
		}
	}
	
	public function del(){
		if(is_array($_POST['iddb'])){
			foreach($_POST['iddb'] AS $key=>$id){
				hook_listen('news_comment_del_begin',['id'=>$id]);
				(new comment_class)->comment_del($id);
				hook_listen('news_comment_del_end',['id'=>$id]);
			}
			$this->Success('删除成功', FromUrl);
		}else{
			hook_listen('news_comment_del_begin',['id'=>$_POST['id']]);
			echo (new comment_class)->comment_del($_POST['id']);
			hook_listen('news_comment_del_begin',['id'=>$_POST['id']]);
		}
	}
}
?>
