<?php
/****************优客365网址导航系统 商业版********************/
/*                                                            */
/*  Youke365.com (C)2017 Youke365 Inc.                        */
/*  This is NOT a freeware, use is subject to license terms   */
/*  优客365网址导航系统是商业软件,使用于商业用途请购买授权    */
/*  V1.0 2017                                                 */
/*  技术支持：1513773524@qq.com                               */
/*  官方网址：http://www.youke365.com                         */
/*  官方论坛：http://bbs.youke365.com                         */                           
/**************************************************************/


require('common.php');

$fileurl = 'comment.php';
$tplfile = 'comment.html';
$table = $DB->table('comments');

if (empty($action)) $action = 'list';


/** list */
if ($action == 'list') {
	$pagetitle = '站点列表';
	$status = I($_GET['status'],-1,'intval');
	$smarty->assign('status', $status);
	if($status){
		$pageurl = $fileurl.'?status='.$status;	
	}


	$where = '';
	 $sql = "SELECT a.comment_id,a.module,a.pageid, a.nick, a.email, a.content, a.ip, a.status, a.time, b.web_name, b.web_url FROM $table a LEFT JOIN ".$DB->table('website')." b ON a.pageid=b.web_id WHERE";
	
	switch ($status) {
		case 0 :
			$where .= " a.status=0";
			break;
		case 1 :
			$where .= " a.status=1";
			break;
		default :
			$where .= " a.status>-1";
			break;
	}
	$sql .= $where." ORDER BY a.comment_id DESC LIMIT $start, $pagesize";
	$query = $DB->query($sql);
	
	$comments = array();
	while ($row = $DB->fetch_array($query)) {
       $row['web_name'] = '<a  href="'.format_url($row[web_url]).'?mod='.$row[module].'&wid='.$row[pageid].'"    target="_blank">'.$row['web_name'].'</a>';

		$row['ip'] = long2ip($row['ip']);
		switch ($row['status']) {
			case 0 :
				$status = '<font color="#ff3300">待审核</font>';
				break;
			case 1 :
				$status = '<font color="#008800">已审核</font>';
				break;
		}
		$row['attr'] = $status;
		$row['time'] = date('Y-m-d H:i:s', $row['time']);
		$row['oper'] = '<a href="'.$fileurl.'?act=del&comment_id='.$row['comment_id'].'" onClick="return confirm(\'确认删除此内容吗？\');">删除</a>';
		$comments[] = $row;
	}
	$DB->free_result($query);
	
	$total = $DB->get_count($table.' a', $where);
	$showpage = showpage($pageurl, $total, $curpage, $pagesize);
	
	$smarty->assign('comments', $comments);
	$smarty->assign('showpage', $showpage);
}

/** del */
if ($action == 'del') {
	$ids = I($_POST['id'],$_GET['id']);

	$DB->delete($table, 'comment_id IN ('.dimplode($ids).')');
	
	alert('评论删除成功！', $fileurl);
}

/** passed */
if ($action == 'passed') {
	$ids = I($_POST['id'],$_GET['id']);
	
	$DB->update($table, array('status' => 1), 'comment_id IN ('.dimplode($ids).')');
	
	alert('评论审核成功！', $fileurl);
}

/** cancel */
if ($action == 'cancel') {
	$ids = I($_POST['id'],$_GET['id']);
	
	$DB->update($table, array('status' => 0), 'comment_id IN ('.dimplode($ids).')');
	
	alert('评论取消审核成功！', $fileurl);
}

smarty_output($tplfile);
?>