<style type="text/css">
.tab tr {
	height: 40px;
}
.tab th {
	text-align:left;
	width:100px;
}
</style>

<script type="text/javascript">
<!--
function addMedal(self) {
	var html = '<tr><td><?php echo CHtml::checkBox('medals[available][]');?></td><td><?php echo CHtml::textField('medals[name][]');?></td><td><?php echo CHtml::textField('medals[image][]');?></td><td><?php echo CHtml::textField('medals[type][]');?> [<?php echo CHtml::link('-','javascript:void(0);',array('onclick'=>'delMedal(this)'));?>]</td></tr>';
	$(self).parent().parent().parent().append(html);
}

function delMedal(self) {
	$(self).parent().parent().remove();
}
//-->
</script>
<h2>勋章管理</h2>
<div class="form">
	<fieldset>
    	<legend>使用帮助</legend>
		勋章图片中请填写图片文件名，并将相应图片文件上传到 images/bbs/medals 目录中。
		<br/>
		注意，图片必须先传到相应目录，然后再添加，否则系统找不到相应图片时会添加失败
	</fieldset>
</div>
<?php echo CHtml::beginForm();?>
<div class="form">
<?php foreach ($list as $key => $item):?>
	<fieldset>
		<legend><?php echo $key;?></legend>
		<table class="tab">
		<?php foreach ($item as $value):?>
		<tr>
			<td><?php echo CHtml::checkBox('medals['.$value->medalid.'][available]',$value->available,array('value'=>$value->available));?></td>
			<td><?php echo CHtml::textField('medals['.$value->medalid.'][name]',$value->name);?></td>
			<td><?php echo CHtml::textField('medals['.$value->medalid.'][image]',$value->image);?></td>
			<td><?php echo CHtml::image($value->getImageUrl(),$value->name);?></td>
			<td><?php echo CHtml::textField('medals['.$value->medalid.'][type]',$value->type);?></td>
			<td>[<?php echo CHtml::link('删除',array('/admin/medals/deleteitem','id'=>$value->medalid),array('confirm'=>'确定要删除吗？'));?>]</td>
		</tr>
		<?php endforeach;?>
	</table>
	</fieldset>
<?php endforeach;?>
	<?php echo CHtml::submitButton('提交');?>
</div>
<?php echo CHtml::endForm();?>

<?php echo CHtml::beginForm(array('additem'));?>
<div class="form">
	<fieldset>
    	<legend>添加新勋章</legend>
		<table>
			<thead>
				<tr>
					<th>可用</th>
					<th>名字</th>
					<th>图片</th>
					<th>分类</th>
				</tr>
			</thead>
			<tbody>
			<tr>
				<td><?php echo CHtml::checkBox('medals[available][]');?></td>
				<td><?php echo CHtml::textField('medals[name][]');?></td>
				<td><?php echo CHtml::textField('medals[image][]');?></td>
				<td><?php echo CHtml::textField('medals[type][]');?>[<?php echo CHtml::link('+','javascript:void(0)',array('onclick'=>'addMedal(this);'));?>]</td>
			</tr>
			</tbody>
		</table>
		<?php echo CHtml::submitButton('提交');?>
	</fieldset>
</div>
<?php echo CHtml::endForm();?>