<script type="text/javascript">
<!--
function showAddLink(fid) {
	$('#'+'fid_'+fid).toggle();
}

function editName(fid) {
	var name = $('#name_'+fid).text();
	var formHtml = '<input type="text" id="nName_'+fid+'" value='+name+' /> <input type="button" value="提交" onclick="saveEdit('+fid+');" /> <input type="button" value="取消" onclick="canelEdit('+fid+',\''+name+'\');" />';
	$('#name_'+fid).html(formHtml);
}

function canelEdit(fid, name) {
	$('#name_'+fid).html(name);
}

function saveEdit(fid) {
	var newName = $('#nName_'+fid).val();
	if (newName == '') {
		alert('版块名不能为空');
		return false;
	}
	$.ajax({
		type: 'POST',
		url: '<?php echo $this->createUrl('/admin/forums/editname');?>'+'&fid='+fid,
		data: 'name='+newName,
		success:function(msg) {
			if (msg != '') {
				alert(msg);
			} else {
				$('#name_'+fid).html(newName);
			}
		}
	});
}

function editViewOrder(fid) {
	var view = $('#vieworder_'+fid).val();
	$.ajax({
		type: 'GET',
		url: '<?php echo $this->createUrl('/admin/forums/editorder');?>'+'&fid='+fid+'&view='+view,
    	success:function(msg) {
    		if (msg != '') {
    			alert(msg);
    		}
    	}
	});
}

function editForumAdin(fid) {
	var admin = $('#forumadmin_'+fid).val();
	$.ajax({
		type: 'POST',
		url: '<?php echo $this->createUrl('/admin/forums/editforumadmin');?>'+'&fid='+fid,
		data: 'admin='+admin,
    	success:function(msg) {
    		if (msg != '') {
    			alert(msg);
    		}
    	}
	});
}
//-->
</script>
<?php echo CHtml::form(array('/admin/forums/addcategory'));?>
<div class="form">
	<fieldset>
    	<legend>添加新分类</legend>
    	新分类名：<?php echo CHtml::textField('name');?> <?php echo CHtml::submitButton('提交');?>
    </fieldset>
</div>
<?php echo CHtml::endForm();?>

<div class="form">
	<fieldset>
		版主请填UID，多个用‘,’隔开
		<br/>
		<br/>
		<legend>编辑版块</legend>
		<?php if (!empty($catedb)):?>
    		<?php foreach ($catedb as $cate):?>
    			<span onmouseover="showAddLink(<?php echo $cate->fid;?>);" onmouseout="showAddLink(<?php echo $cate->fid;?>);"><?php echo CHtml::textField('vieworder_'.$cate->fid,$cate->vieworder,array('size'=>2,'onchange'=>'editViewOrder('.$cate->fid.')'));?> <span ondblclick="editName(<?php echo $cate->fid;?>);" id="name_<?php echo $cate->fid;?>" title="双击修改名称"><?php echo $cate->name;?></span> <font style="color:#999999">FID:<?php echo $cate->fid;?></font> <a href="<?php echo $this->createUrl('/admin/forums/addforum',array('fup'=>$cate->fid));?>" id="fid_<?php echo $cate->fid;?>" title="添加新版块" style="display:none;">添加新版块</a></span>&nbsp;&nbsp;&nbsp;&nbsp;版主:<?php echo CHtml::textField('forumadnin_'.$cate->fid,trim($cate->forumadmin,','),array('onchange'=>'editForumAdin('.$cate->fid.')'));?> [<?php echo CHtml::link('编辑',array('/admin/forums/edit','fid'=>$cate->fid));?>] [<?php echo CHtml::link('删除',array('/admin/forums/delete','fid'=>$cate->fid),array('confirm'=>'确定删除吗？'));?>]
    			<br/>
    			<?php if ($threadb[$cate->fid]):?>
    				<?php foreach ($threadb[$cate->fid] as $thread):?>
    					<span onmouseover="showAddLink(<?php echo $thread->fid;?>);" onmouseout="showAddLink(<?php echo $thread->fid;?>);">
    					|--<?php echo $thread->type == 'forum' ? '' : ($thread->type == 'sub' ? '--' : '----');?>
    					<?php echo CHtml::textField('vieworder_'.$thread->fid,$thread->vieworder,array('size'=>2,'onchange'=>'editViewOrder('.$thread->fid.')'));?> <span ondblclick="editName(<?php echo $thread->fid;?>);" id="name_<?php echo $thread->fid;?>" title="双击修改名称"><?php echo $thread->name;?></span> <font style="color:#999999">FID:<?php echo $thread->fid;?></font> <?php if ($thread->type != 'sub2'):?><a href="<?php echo $this->createUrl('/admin/forums/addforum',array('fup'=>$thread->fid));?>" id="fid_<?php echo $thread->fid;?>" title="添加子版块" style="display:none;">添加子版块</a><?php endif;?></span> &nbsp;&nbsp;&nbsp;&nbsp;版主:<?php echo CHtml::textField('forumadmin_'.$thread->fid,trim($thread->forumadmin,','),array('onchange'=>'editForumAdin('.$thread->fid.')'));?> [<?php echo CHtml::link('编辑',array('/admin/forums/edit','fid'=>$thread->fid));?>] [<?php echo CHtml::link('删除',array('/admin/forums/delete','fid'=>$thread->fid),array('confirm'=>'确定要删除吗？'));?>]
    					<br/>
    				<?php endforeach;?>
    			<?php endif;?>
    		<?php endforeach;?>
	    <?php endif;?>
	</fieldset>
</div>