<?php

/*
	[SupeSite/X-Space] (C)2001-2006 Comsenz Inc.
	信息管理

	$RCSfile: batch.manage.php,v $
	$Revision: 1.11 $
	$Date: 2006/10/27 01:24:52 $
*/

include_once('./include/main.inc.php');

$itemid = empty($_GET['itemid'])?0:intval($_GET['itemid']);
if(empty($itemid)) exit('Access Denied');
$action = empty($_GET['action'])?'':$_GET['action'];

$theurl = S_URL.'/batch.manage.php?itemid='.$itemid;
$siteurl = S_URL;
getcookie(1);

if(empty($_SGLOBAL['supe_uid'])) {
	setcookie('_refer', rawurlencode($theurl));
	messagebox('error', 'no_permission', geturl('action/login'));
}

$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('spaceitems')." WHERE itemid='$itemid'");
$item = $_SGLOBAL['db']->fetch_array($query);
if(empty($item)) messagebox('error', 'no_permission');
if($_SGLOBAL['group']['groupid'] != 1 && $item['uid'] != $_SGLOBAL['supe_uid']) messagebox('error', 'no_permission');

include_once(S_ROOT.'./include/common.inc.php');
include_once(S_ROOT.'./function/spacecp.func.php');

$type = $item['type'];
$categoryarr = getcategory($type);
arraytolist($uplistarr, $categoryarr, 0, 0);
$catarr = $cat2arr = array();
foreach ($uplistarr as $key => $value) {
	$value['pre'] = str_replace($_SGLOBAL['_tmp_arraytolistpre1'], '', $value['pre']);
	$value['pre'] = str_replace($_SGLOBAL['_tmp_arraytolistpre0'], '&nbsp;&nbsp;&nbsp;&gt;&gt;&nbsp;', $value['pre']);
	$catarr[$value['catid']] = $value['name'];
	$cat2arr[$value['catid']] = $value['pre'].$value['name'];
}

$actiontype = gettypetablename($item['type']);

if(submitcheck('catidsubmit')) {
	
	updatetable('spaceitems', array('catid'=>intval($_POST['catid'])), array('itemid'=>$itemid));
	messagebox('ok', 'succeed', $theurl);
	
} elseif (submitcheck('foldersubmit')) {
	
	$htmlfile = gethtmlfile(array('uid'=>$item['uid'], 'action'=>'viewspace', 'itemid'=>$itemid));
	@unlink($htmlfile['path']);
	
	updatetable('spaceitems', array('folder'=>intval($_POST['folder'])), array('itemid'=>$itemid));
	messagebox('ok', 'succeed', $theurl);
	
} elseif (submitcheck('gradesubmit')) {
	
	updatetable('spaceitems', array('grade'=>intval($_POST['grade'])), array('itemid'=>$itemid));
	messagebox('ok', 'succeed', $theurl);
	
} elseif (submitcheck('locksubmit')) {
	
	updatetable('userspaces', array('islock'=>intval($_POST['islock'])), array('uid'=>$item['uid']));
	if(!empty($_POST['islock'])) {
		updatetable('spaceitems', array('folder'=>'3'), array('uid'=>$item['uid']));
	}
	messagebox('ok', 'succeed', $theurl);
	
} elseif (submitcheck('starsubmit')) {
	
	updatetable('userspaces', array('isstar'=>intval($_POST['isstar'])), array('uid'=>$item['uid']));
	messagebox('ok', 'succeed', $theurl);
	
}

$iteminf = array();
$space = array();

$title = '管理《'.$item['subject'].'》';

include template('site_header');

if($_SGLOBAL['group']['groupid'] == 1) {
	
	$query = $_SGLOBAL['db']->query('SELECT * FROM '.tname($actiontype).' WHERE itemid=\''.$itemid.'\'');
	$iteminf = $_SGLOBAL['db']->fetch_array($query);
	$space = getuserspace($item['uid']);

	$catstr = getselectstr('catid', $cat2arr, $item['catid']);
	$folderstr = getselectstr('folder', array('1'=>'正常發佈', '3'=>'刪除回收'), $item['folder']);
	
	$gradearr = array(
		'0' => '初始狀態',
		'1' => '一等級',
		'2' => '二等級',
		'3' => '三等級',
		'4' => '四等級',
		'5' => '五等級',
		'-1' => '屏蔽狀態'
	);
	if(!empty($_SCONFIG['checkgrade'])) {
		$newgradearr = explode("\t", $_SCONFIG['checkgrade']);
		for($i=0; $i<5; $i++) {
			if(!empty($newgradearr[$i])) $gradearr[$i+1] = $newgradearr[$i];
		}
	}
	
	$gradestr = getselectstr('grade', $gradearr, $item['grade']);
	$lockstr = getselectstr('islock', array('0'=>'正常使用', '1'=>'鎖定'), $space['islock']);
	$startr = getselectstr('isstar', array('0'=>'-----', '1'=>'空間之星'), $space['isstar']);
	
	print<<<END
	<script>
	function unbtn(btn) {
		for(i=0;i<btn.length;i++){
			document.getElementById(btn[i]).disabled=true;
		}
		return true;
	}
	</script>
	
<div id="navigation" class="simplepage">
	<p>您的位置：
		<a href="$siteurl" target="_self">首頁</a>
		&gt;&gt; $title
	</p>
	<h2>管理員管理操作</h2>
</div>
  
	<h4>管理員管理操作</h4>
	<form id="theform" action="$theurl" method="post">
	<input name="itemid" type="hidden" value="$itemid" />
	<ul>
		<li style="margin: 2px 0;"><strong>$catstr</strong><button type="submit" name="catidsubmit" class="submit" value="true" onclick="unbtn(['foldersubmit','gradesubmit','locksubmit','starsubmit'])">重新分類</button></li>
		<li style="margin: 2px 0;"><strong>$folderstr</strong><button type="submit" name="foldersubmit" class="submit" value="true" onclick="unbtn(['catidsubmit','gradesubmit','locksubmit','starsubmit'])">改變狀態</button></li>
		<li style="margin: 2px 0;"><strong>$gradestr</strong><button type="submit" name="gradesubmit" class="submit" value="true" onclick="unbtn(['foldersubmit','catidsubmit','locksubmit','starsubmit'])">審核等級</button></li>
		<li style="margin: 2px 0;"><strong>$lockstr</strong><button type="submit" name="locksubmit" class="submit" value="true" onclick="unbtn(['foldersubmit','gradesubmit','catidsubmit','starsubmit'])">空間狀態</button></li>
		<li style="margin: 2px 0;"><strong>$startr</strong><button type="submit" name="starsubmit" class="submit" value="true" onclick="unbtn(['foldersubmit','gradesubmit','locksubmit','catidsubmit'])">空間之星</button></li>
	</ul>
	</form>
END;

}

if($item['uid'] == $_SGLOBAL['supe_uid']) {
	
	print<<<END
	
	<div>
	<h4>作者管理操作</h4>
	<ul>
		<li><a href="$siteurl/spacecp.php?action=$actiontype&op=edit&itemid=$itemid">編輯信息</a></li>
		<li><a href="$siteurl/spacecp.php?action=$actiontype&op=delete&itemid=$itemid" onclick="javascript:return confirm('確認刪除選定的信息嗎?');">刪除信息</a></li>
	</ul>
	</div>
END;
}

$item['dateline'] = sgmdate($item['dateline']);
$item['lastpost'] = sgmdate($item['lastpost']);
$item['type'] = $lang[$item['type']];
if(!empty($item['tid'])) {
	$subjectplus = '<a href="'.B_URL.'/viewthread.php?tid='.$item['tid'].'">論壇模式</a>';
} else {
	$subjectplus = '';
}
if($item['folder'] == '1') {
	$item['folder'] = '正常';
} elseif($item['folder'] == '2') {
	$item['folder'] = '暫存';
} elseif($item['folder'] == '3') {
	$item['folder'] = '刪除';
}
$item['url'] = geturl("uid/$item[uid]/action/viewspace/itemid/$itemid");

print<<<END
	<style>
		.table li { line-height: 24px; border-bottom: 1px solid #EEE; list-style: none; overflow: hidden; padding-left: 10em; }
		.table strong {display: block; float: left; width: 10em; margin-left: -10em!important; margin-left: -5em;}
		h4 { font-size: 1em; border-bottom: 1px solid #BBB; }
		button { margin-left: 0.5em; background: #EEE; border-top-color: #EEE; border-right-color: #666; border-bottom-color: #666; border-left-color: #EEE; }
	</style>
	<div class="table">
	<h4>信息概覽</h4>
	<ul>
		<li><strong>標題</strong><a href="$item[url]" target="_blank">$item[subject]</a> $subjectplus</li>
		<li><strong>作者</strong>$item[username]</li>
		<li><strong>類型</strong>$item[type]</li>
		<li><strong>分類</strong>{$catarr[$item['catid']]}</li>
		<li><strong>發佈時間</strong>$item[dateline]</li>
		<li><strong>最後評論</strong>$item[lastpost]</li>
		<li><strong>查看數</strong>$item[viewnum]</li>
		<li><strong>評論數</strong>$item[replynum]</li>
		<li><strong>Trackback數</strong>$item[trackbacknum]</li>
		<li><strong>好評</strong>$item[goodrate]</li>
		<li><strong>差評</strong>$item[badrate]</li>
		<li><strong>審核等級</strong>$item[grade]</li>
		<li><strong>狀態</strong>$item[folder]</li>
	</ul>
	</div>
END;

if(!empty($item)) {

	echo '<div class="table"><h4>主題基本數據</h4><ul>';
	foreach ($item as $key => $value) {
		$value = shtmlspecialchars($value);
		echo "<li><strong>$key</strong>$value</li>";
	}
	echo '</ul></div>';

}

if(!empty($iteminf)) {

	echo '<div class="table"><h4>主題詳細數據</h4><ul>';
	foreach ($iteminf as $key => $value) {
		$value = shtmlspecialchars($value);
		echo "<li><strong>$key</strong>$value</li>";
	}
	echo '</ul></div>';
}

if(!empty($space)) {
	
	$space['dateline'] = sgmdate($space['dateline']);
	$space['lastpost'] = sgmdate($space['lastpost']);

	unset($space['diy']);
	
	echo '<div class="table"><h4>主題作者空間數據</h4><ul>';
	foreach ($space as $key => $value) {
		$value = shtmlspecialchars($value);
		echo "<li><strong>$key</strong>$value</li>";
	}
	echo '</ul></div>';
}

include template('site_footer');

?>