<?php 
require '../../Run.php';

if($admin!=1&&$admin!=2){
	ehtml("权限不足");
	exit;
}
echo head("勋章管理");

if($_GET['type'] == 'add'){
	if(user2('id',$_POST['userid'],WAPID) != NULL){
	$userid = user2('id',$_POST['userid'],WAPID);
	}else{
	die("不存在此会员");
	}
	$sql = 'INSERT INTO `bbs_xunzhang_log` (`bbser_id`, `bbser_userid`, `bbser_siteid`, `bbser_xzid`, `bbser_why`, `bbser_time`) VALUES (NULL, \''.$userid.'\', \''.WAPID.'\', \''.$_POST['xunzhang'].'\', \''.$_POST['why'].'\',\''.time().'\')';
	$res = mysql_query($sql);
	if($res &&  mysql_affected_rows()>0){
		echo '<div class="tip">赋予勋章成功</div>';
	}else{
		echo '<div class="tip">赋予勋章失败</div>';
	}
	}
if($_GET['type'] == 'del'){
if(user2('id',$_GET['id'],WAPID)==NULL){die("用户不存在");}
$sql = 'DELETE FROM bbs_xunzhang_log WHERE bbser_id =\''.$_GET['id'].'\' AND bbser_siteid=\''.WAPID.'\' AND bbser_userid=\''.$_GET['uid'].'\';';
$res = mysql_query($sql);
if($res &&  mysql_affected_rows()>0){
		echo '<div class="tip">摘除勋章成功</div>';
	}else{
		echo '<div class="tip">摘除勋章失败</div>';
	}
}
$sql = 'SELECT * FROM `bbs_xunzhang` WHERE bbser_siteid=\''.WAPID.'\'';
$res = mysql_query($sql);
if($res && mysql_num_rows($res)>0){
	while(list($bbser_id,$bbser_text,$bbser_siteid,$bbser_url,$bbser_buy,$bbser_time) = mysql_fetch_row($res)){
		$list_xunzhang .= '<option value="'.$bbser_id.'">'.$bbser_text.'</option>';
	}
}

echo '<div class="title">勋章列表</div>';
	echo '<form method="POST" action="?action=admin&cid='.$_GET['cid'].'&type=add">
		<text>会员ID:</text><br>';
		echo '<input name="userid" type="text" value="">';
		echo '<br><text>选择勋章:</text><br>';
		echo '<select name="xunzhang">';
		echo $list_xunzhang;
		echo '</select>';
		echo '<br><text>原因:</text><br>';
		echo '<input name="why" type="text" value="">';
		echo '<br>';
		echo '<input type="submit" value="添加勋章">';
		echo '</form>';
echo '<div class="content">';
echo $list;
echo '</div>';
echo '<div class="mylink"><a href="http://'.HTTP_HOST.'/admin/wap_admin.php?">管理后台</a></div>';
echo footer(1);
?>