<?php
/*
		[FuShow.cn] (C) 2013-2014 HXWY Inc.
		FuShow Friend V3.0				Id: usadmin_live.php
		Email <service@fushow.cn>		http://fushow.cn/
*/
if(!defined('IN_FUSHOW') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}
//权限
if(!$allowmanage = checkperm('manageblog')) {
	$_GET['uid'] = $_SGLOBAL['supe_uid'];//只能操作本人的
	$_GET['username'] = '';
}
if(submitcheck('batchsubmit')) {
	include_once(S_ROOT.'./source/function_delete.php');
	if(!empty($_POST['ids']) && deletelives($_POST['ids'])) {
		cpmessage('do_success', $_POST['mpurl']);
	} else {
		cpmessage('the_correct_choice_to_delete_the_log');
	}
}
$mpurl = 'usadmin.php?ac=live';
//处理搜索
$intkeys = array('uid', 'friend', 'liveid','collated','living');
$strkeys = array('username','work');
$randkeys = array(array('sstrtotime','dateline','starttime','endtime'), array('intval','viewnum'), array('intval','replynum'), array('intval','hot'));
$likekeys = array('subject');
$results = getwheres($intkeys, $strkeys, $randkeys, $likekeys, 'l.');
$wherearr = $results['wherearr'];
$mpurl .= '&'.implode('&', $results['urls']);
//限制条件2
$intkeys = array();
$strkeys = array('postip');
$randkeys = array();
$likekeys = array('message');
$results = getwheres($intkeys, $strkeys, $randkeys, $likekeys, 'bf.');
$wherearr2 = $results['wherearr'];
$mpurl .= '&'.implode('&', $results['urls']);
$wheresql = empty($wherearr)?'1':implode(' AND ', $wherearr);
$wheresql2 = empty($wherearr2)?'':implode(' AND ', $wherearr2);
//排序
$orders = getorders(array('dateline','addtime','starttime','endtime', 'viewnum', 'replynum', 'hot'), 'liveid', 'l.');
$ordersql = $orders['sql'];
if($orders['urls']) $mpurl .= '&'.implode('&', $orders['urls']);
$orderby = array($_GET['orderby']=>' selected');
$ordersc = array($_GET['ordersc']=>' selected');
$perpage = empty($_GET['perpage'])?0:intval($_GET['perpage']);
if(!in_array($perpage, array(20,50,100,1000))) $perpage = 20;
$page = empty($_GET['page'])?1:intval($_GET['page']);
if($page<1) $page = 1;
$start = ($page-1)*$perpage;
//检查开始数
ckstart($start, $perpage);
//显示分页
if($perpage > 100) {
	$count = 1;
	$selectsql = 'b.blogid';
} else {
	if($wheresql2) {
		$csql = "SELECT COUNT(*) FROM ".tname('live')." l, ".tname('livefield')." bf WHERE $wheresql AND bf.liveid=l.liveid AND $wheresql2";
	} else {
		$csql = "SELECT COUNT(*) FROM ".tname('live')." l WHERE $wheresql";
	}
	$count = $_SGLOBAL['db']->result($_SGLOBAL['db']->query($csql), 0);
	$selectsql = '*';
}
$mpurl .= '&perpage='.$perpage;
$perpages = array($perpage => ' selected');
$managebatch = checkperm('managebatch');
$allowbatch = true;
$list = array();
$multi = '';
if($wheresql2) {
	$qsql = "SELECT $selectsql FROM ".tname('live')." l, ".tname('livefield')." bf WHERE $wheresql AND bf.liveid=l.liveid AND $wheresql2 ORDER BY l.liveid DESC LIMIT $start,$perpage";
} else {
	$qsql = "SELECT $selectsql FROM ".tname('live')." l WHERE $wheresql $ordersql LIMIT $start,$perpage";
}
if($count) {
	$query = $_SGLOBAL['db']->query($qsql);
	while ($value = $_SGLOBAL['db']->fetch_array($query)) {
		if(!$managebatch && $value['uid'] != $_SGLOBAL['supe_uid']) {
			$allowbatch = false;
		}
		$list[] = $value;
	}
	$multi = multi($count, $perpage, $page, $mpurl);
}
$works = array();
$wsql = "SELECT * FROM ".tname('major_manager')."";
$wquery = $_SGLOBAL['db']->query($wsql);
while ($value = $_SGLOBAL['db']->fetch_array($wquery)) {
		$works[] = $value;
}
//显示分页
if($perpage > 100) {
	$count = count($list);
}
if($_GET['op'] == 'collate') {
	$managename = checkperm('managename');
	$managespacegroup = checkperm('managespacegroup');
	$managespaceinfo = checkperm('managespaceinfo');
	$managespacecredit = checkperm('managespacecredit');
	$managespacenote = checkperm('managespacenote');
	$manageconfig = checkperm('manageconfig');
	$managedelspace = checkperm('managedelspace');
	$noprivilege = !$managename && !$managespacegroup && !$managespaceinfo && !$managespacecredit && !$managespacenote && !$managedelspace;
	if($noprivilege) {
		cpmessage('no_authority_management_operation');
	}

	$liveid = $_GET['liveid'];
	$value = array();
	$sql = "SELECT l.*, bl.message, bl.postip FROM ".tname('live')." l LEFT JOIN ".tname(livefield)." bl ON l.liveid=bl.liveid WHERE l.liveid=$liveid";
	$query = $_SGLOBAL['db']->query($sql);
	$value = $_SGLOBAL['db']->fetch_array($query);
	include_once template('usadmin/tpl/live_collate');
	exit();
}elseif($_GET['op'] == 'collating') {
	$managename = checkperm('managename');
	$managespacegroup = checkperm('managespacegroup');
	$managespaceinfo = checkperm('managespaceinfo');
	$managespacecredit = checkperm('managespacecredit');
	$managespacenote = checkperm('managespacenote');
	$manageconfig = checkperm('manageconfig');
	$managedelspace = checkperm('managedelspace');
	$noprivilege = !$managename && !$managespacegroup && !$managespaceinfo && !$managespacecredit && !$managespacenote && !$managedelspace;
	if($noprivilege) {
		cpmessage('no_authority_management_operation');
	}
	$liveid = intval($_GET['liveid']);
	$collated = intval($_POST['collated']);
	$collateMes = getstr($_POST['collateMes'], 100, 1, 1);
	$setarr = array(
		'liveid' => $liveid,
		'collated' => $collated,
		'collateMes' => $collateMes
	);
	updatetable('live', $setarr, array('liveid'=>$liveid));
	$url = "usadmin.php?ac=live";
	cpmessage("恭喜，审核操作已成功",$url);
}
?>