<?php
/**
 * @version $Id: check.inc.php v2.0 $
 * @package PBDigg
 * @copyright Copyright (C) 2007 - 2008 PBDigg.com. All Rights Reserved.
 * @license PBDigg is free software and use is subject to license terms
 */

if(!defined('IN_ADMIN') || !isset($_PBDEV['PHP_SELF']) || !preg_match('/[\/\\\\]admincp\.php$/i', $_PBDEV['PHP_SELF']))
{
	exit('Access Denied');
}
define('PB_CSCRIPT', 'check');
allowdo('setcheck');
$baseurl = 'admincp.php?action=check&type=';
require_once (PBDIGG_ROOT.'include/article.func.php');

if ($type == 'article' || empty($type))
{
	if ($submitted)
	{
		if (empty ($tid))
		{
			showMsg($a_message['parameter_error'], $actionurl);
		}
		if ($checktype == 'pass')
		{
			positiveInteger($tid);
			$tid = implode(',', $tid);
			$DB->db_query("UPDATE {$db_prefix}threads SET ifcheck = 1 WHERE tid IN ($tid)");
			redirect($a_message['check_success'], $actionurl);
		}
		elseif ($checktype == 'del')
		{
			delArticle($tid);
			redirect($a_message['del_success'], $actionurl);
		}
	}
	else
	{
		//list uncheck article
		$pagesize = 30;
		$rs = $DB->db_fetch_one_array("SELECT COUNT(*) num FROM {$db_prefix}threads WHERE ifcheck = 0");
		$totalRecords = (int)$rs['num'];
		$page = !isPage($page) ? 1 : $page;
		$start_limit = ($page -1) * $pagesize;
		$mult = multLink($page, $totalRecords, 'admincp.php?action=check&type=article&', $pagesize);
		$DB->db_query("SELECT tid, subject, author, postdate FROM {$db_prefix}threads WHERE ifcheck = 0 LIMIT $start_limit, $pagesize");
		$article = array();
		while ($rs = $DB->db_fetch_array())
		{
			if (!$rs['author'])
			{
				if ($pb_anonnick)
				{
					$rs['author'] = $pb_anonnick;
				}
				else
				{
					$rs['author'] = $pb_sitename.$cp_message['net_friend'];
				}
			}
			$rs['postdate'] = gdate($rs['postdate'], 'Y-m-d H:i');
			$article[] = $rs;
		}
		$type = 'article';
		$TPL->assign('article', $article);
		$TPL->assign('mult', $mult);
		$TPL->assign('total_records', $totalRecords);
	}
}
elseif ($type == 'comment')
{
	if ($submitted)
	{
		if (empty ($rid))
		{
			showMsg($a_message['parameter_error'], $actionurl);
		}
		if ($checktype == 'pass')
		{
			positiveInteger($rid);
			$rid = implode(',', $rid);
			$DB->db_query("UPDATE {$db_prefix}comments SET ifcheck = 1 WHERE rid IN ($rid)");
			redirect($a_message['check_success'], $actionurl);
		}
		elseif ($checktype == 'del')
		{
			delComment($rid);
			redirect($a_message['del_success'], $actionurl);
		}
	}
	else
	{
		//list uncheck comments
		$pagesize = 30;
		$rs = $DB->db_fetch_one_array("SELECT COUNT(*) num FROM {$db_prefix}comments WHERE ifcheck = 0");
		$totalRecords = (int)$rs['num'];
		$page = !isPage($page) ? 1 : $page;
		$start_limit = ($page -1) * $pagesize;
		$mult = multLink($page, $totalRecords, 'admincp.php?action=check&type=comment&', $pagesize);
		$DB->db_query("SELECT cm.rid, cm.content, cm.author, cm.postdate FROM {$db_prefix}comments cm WHERE cm.ifcheck = 0 LIMIT $start_limit, $pagesize");
		$comment = array();
		while ($rs = $DB->db_fetch_array())
		{
			if (!$rs['author'])
			{
				if ($pb_anonnick)
				{
					$rs['author'] = $pb_anonnick;
				}
				else
				{
					$rs['author'] = $pb_sitename.$cp_message['net_friend'];
				}
			}
			$rs['postdate'] = gdate($rs['postdate'], 'Y-m-d H:i');
			$rs['content'] = PBSubstr($rs['content'], 35);
			$comment[] = $rs;
		}
		$type = 'comment';
		$TPL->assign('comment', $comment);
		$TPL->assign('mult', $mult);
		$TPL->assign('total_records', $totalRecords);
	}
}
else
{
	redirect($a_message['unknow_operate'], 'admincp.php?action=main');
}

$TPL->assign('menu', $m_check);
?>
