<?php 
require_once(dirname(__FILE__)."/config.php");
CheckPurview('sys_User');
require_once(dirname(__FILE__)."/../include/pub_datalist.php");
setcookie("ENV_GOBACK_URL",$dedeNowurl,time()+3600,"/");


if(empty($rank)) $rank="";
else $rank = " where #@__admin.usertype='$rank' ";
$dsql = new DedeSql(false);
$dsql->SetQuery("select rank,typename From #@__admintype");
$dsql->Execute();
while($row = $dsql->GetObject()){
	$adminRanks[$row->rank] = $row->typename;
}

function GetUserType($trank)
{
	global $adminRanks;
	if(isset($adminRanks[$trank])) return $adminRanks[$trank];
	else return "错误类型";
}

function GetChannel($c)
{
	if($c==""||$c==0) return "所有频道";
	else return $c;
}

$ntime = time();

function TjMonth($uid){
	global $dsql,$ntime;
	$y = strftime("%Y",$ntime);
	$m = strftime("%m",$ntime);
	$stime = GetMkTime("{$y}-{$m}-01");
	$row = $dsql->GetOne("Select count(ID) as dd From #@__archives where adminid='$uid' And senddate>=$stime; ");
	return $row['dd'];
}

function TjQuar($uid){
	global $dsql,$ntime;
	$y = strftime("%Y",$ntime);
	$m = strftime("%m",$ntime);
	$j = floor($m%3)+1;
	$m = ($j * 3) - 2;
	$stime = GetMkTime("{$y}-{$m}-01");
	$row = $dsql->GetOne("Select count(ID) as dd From #@__archives where adminid='$uid' And senddate>=$stime; ");
	return $row['dd'];
}

function TjYear($uid){
	global $dsql,$ntime;
	$y = strftime("%Y",$ntime);
	$stime = GetMkTime("{$y}-01-01");
	$row = $dsql->GetOne("Select count(ID) as dd From #@__archives where adminid='$uid' And senddate>=$stime; ");
	return $row['dd'];
}

function TjAll($uid){
	global $dsql,$ntime;
	$row = $dsql->GetOne("Select count(ID) as dd From #@__archives where adminid='$uid'; ");
	return $row['dd'];
}

function SumMonth($uid){
	global $dsql,$ntime;
	$y = strftime("%Y",$ntime);
	$m = strftime("%m",$ntime);
	$stime = GetMkTime("{$y}-{$m}-01");
	$row = $dsql->GetOne("Select sum(click) as dd From #@__archives where adminid='$uid' And senddate>=$stime; ");
	return $row['dd'];
}

function SumQuar($uid){
	global $dsql,$ntime;
	$y = strftime("%Y",$ntime);
	$m = strftime("%m",$ntime);
	$j = floor($m%3)+1;
	$m = ($j * 3) - 2;
	$stime = GetMkTime("{$y}-{$m}-01");
	$row = $dsql->GetOne("Select sum(click) as dd From #@__archives where adminid='$uid' And senddate>=$stime; ");
	return $row['dd'];
}

function SumYear($uid){
	global $dsql,$ntime;
	$y = strftime("%Y",$ntime);
	$stime = GetMkTime("{$y}-01-01");
	$row = $dsql->GetOne("Select sum(click) as dd From #@__archives where adminid='$uid' And senddate>=$stime; ");
	return $row['dd'];
}

function SumAll($uid){
	global $dsql,$ntime;
	$row = $dsql->GetOne("Select sum(click) as dd From #@__archives where adminid='$uid'; ");
	return $row['dd'];
}

$query = "Select #@__admin.*,#@__arctype.typename From #@__admin left join #@__arctype on #@__admin.typeid=#@__arctype.ID $rank ";
$dlist = new DataList();
$dlist->SetTemplet(dirname(__FILE__)."/templets/sys_admin_user.htm");
$dlist->SetSource($query);
$dlist->Display();
$dlist->Close();
$dsql->Close();
?>