<!--<?php
require($this->getSegmentFile('config.nav'));
print <<<EOT
-->
<h2 class="h1">行业管理</h2>
<script language="JavaScript" src="js/global.js"></script>
<script language="JavaScript" src="js/pw_ajax.js"></script>
<script type="text/javascript">
var categories = {
	//后台分类管理@author L.IuHu.I@2010/8/27
	hidden : function(id){
		if(id.split("_")[1]){
			this.display(id,'none');
			return false;
		}
		this.display('c_'+id,'none');
	},
	show : function(id){
		if(id.split("_")[1]){
			this.display(id,'');
			return false;
		}
		this.display('c_'+id,'');
	},
	edit : function(id){
		this.display('name_'+id,'none');
		this.display('name_input_'+id,'');
	},
	remove : function(url,child,count){
		if(count > 0) {
			alert('该分类下已有店铺组，不能删除，请先删除店铺再删除该分类！');
			return false;
		}
		if(child > 0) {
			alert('该行业下有存在分类，请先转移或者删除分类，再删除行业');
		} else {
			if(confirm('你确定要删除吗?')) {
				setTimeout(function(){
					window.location.href = url;
				},100);
			}
		}
		return false;
	},
	display : function(id,isshow){
		var obj = getObj(id);
		if(!obj) return false;
		obj.style.display = isshow;
	},
	addParent : function(){
		var s = getObj('parentmode').firstChild.cloneNode(true);
		getObj('parentbody').appendChild(s);
	},
	addChild : function(currentObj){
		var id = currentObj.parentNode.parentNode.parentNode.id;
		if(!id) return false;
		var categoryid = id.split("_")[1];
		var s = getObj("childmode_"+categoryid).firstChild.cloneNode(true);
		getObj(id).appendChild(s);
	}
};
</script>
<form action="{$_viewer->baseUrl}&action=addcategory" method="post">
<div class="admin_table">
	<table width="100%">
	<tr class="tr2">
		<td>（排序）分类名称</td>
		<td>店铺统计</td>
		<td>操作</td>
	</tr>
<!--
EOT;
if($_viewer->categories){
foreach($_viewer->categories as $category){
$childNum = count($category[children]);
print <<<EOT
-->		
		<tbody id="childbody_{$category[categoryid]}">
		<tr class="tr1 vt" ondblclick="categories.edit('{$category[categoryid]}');" onmouseout="categories.hidden('{$category[categoryid]}');" onmouseover="categories.show('{$category[categoryid]}');">
			<td class="td3"><input name="categories[{$category[categoryid]}][sort]" value="{$category[sort]}" type="text" class="input input_wd mr5" /><span id="name_{$category[categoryid]}">$category[name]</span> <span id="name_input_{$category[categoryid]}" style="display:none"><input name="categories[{$category[categoryid]}][name]" value="{$category[name]}" type="text" class="input input_wa" /></span> <span id="c_{$category[categoryid]}" class="s3 cp" style="display:none;" onclick="categories.addParent();">+添加行业</span></td>
			<td class="td2">&nbsp;</td>
			<td class="td2"><a href="javascript:;" class="mr10" onclick="categories.edit('{$category[categoryid]}');">[编辑]</a><!--<a href="#" class="mr10">[转移]</a>--><a href="javascript:;" onclick="categories.remove('{$_viewer->baseUrl}&action=removecategory&categoryid={$category[categoryid]}', {$childNum}, 0);" class="mr10">[删除]</a></td>
		</tr>
<!--
EOT;
if($category[children]){
foreach($category[children] as $child){
$_count = (int) $_viewer->stats[$child['categoryid']]['total'];
print <<<EOT
-->			
		<tr class="vt tr1" ondblclick="categories.edit('c_{$child[categoryid]}');" onmouseout="categories.hidden('{$child[categoryid]}');" onmouseover="categories.show('{$child[categoryid]}');">
			<td class="td3"><i class="lower"></i><input name="categories[{$child[categoryid]}][sort]" value="{$child[sort]}" type="text" class="input input_wd mr5" /><span id="name_c_{$child[categoryid]}">$child[name]</span> <span id="name_input_c_{$child[categoryid]}" style="display:none"><input name="categories[{$child[categoryid]}][name]" value="{$child[name]}" type="text" class="input input_wa" /></span> <span id="c_{$child[categoryid]}" class="s3 cp" style="display:none;" onclick="categories.addChild(this);">+添加分类</span></td>
			<td class="td2">店铺数：{$_count}</td>
			<td class="td2"><a href="javascript:;" class="mr10" onclick="categories.edit('c_{$child[categoryid]}');">[编辑]</a><a href="javascript:;" onclick="categories.remove('{$_viewer->baseUrl}&action=removecategory&categoryid={$child[categoryid]}', 0, {$_count});" class="mr10" >[删除]</a><a href="javascript:;" onclick="sendmsg('{$_viewer->baseUrl}&action=movecategory&categoryid={$child[categoryid]}','',this.id);" >[转移]</a></td>
		</tr>
<!--
EOT;
}
print <<<EOT
-->	
		
<!--
EOT;
}else{
print <<<EOT
-->		
		<tr class="vt tr1" onmouseout="categories.hidden('default_{$category[categoryid]}');" onmouseover="categories.show('default_{$category[categoryid]}');">
			<td class="td3"><i class="lower"></i><input name="child[{$category[categoryid]}][sort][]" value="1" type="text" class="input input_wd mr5" /><input name="child[{$category[categoryid]}][name][]" value="" type="text" class="input input_wa" /> <span id="default_{$category[categoryid]}" class="s3 cp" style="display:none;" onclick="categories.addChild(this);">+添加分类</span></td>
			<td class="td2"> </td>
			<td class="td2"><!--  <a href="javascript:;" onclick="categories.addChild(this);" class="s3">[添加]</a>--></td>
		</tr>
<!--
EOT;
}
print <<<EOT
-->			
		
		<!-- 子模板 -->
		<tbody id="childmode_{$category[categoryid]}" style="display:none;"><tr class="vt tr1"><td class="td3"><i class="lower"></i><input name="child[{$category[categoryid]}][sort][]" value="1" type="text" class="input input_wd mr5" /><input name="child[{$category[categoryid]}][name][]" value="" type="text" class="input input_wa" /></td><td class="td2"> </td><td class="td2"><!-- <a href="javascript:;" onclick="categories.addChild(this);" class="s3">[添加]</a> --></td></tr></tbody>	
		</tbody>	
<!--
EOT;
}
}else{
print <<<EOT
-->
		<tr class="tr1 vt">
			<td class="td3"><input name="parent[sort][]" value="1" type="text" class="input input_wd mr5" /><input name="parent[name][]" value="" type="text" class="input input_wa" /></td>
			<td class="td2"> </td>
			<td class="td2"><!--<a href="javascript:;" onclick="categories.addParent();" class="s3">[添加]</a>--></td>
		</tr>
<!--
EOT;
}
print <<<EOT
-->		
		<!-- 父容器 -->
		<tbody id="parentbody"></tbody>
		<!-- 父模板 -->
		<tbody id="parentmode" style="display:none;"><tr class="tr1 vt"><td class="td3"><input name="parent[sort][]" value="1" type="text" class="input input_wd mr5" /><input name="parent[name][]" value="" type="text" class="input input_wa" /></td><td class="td2"> </td><td class="td2"><!-- <a href="javascript:;" onclick="categories.addParent();" class="s3">[添加]</a> --></td></tr></tbody>
<!--
EOT;
print <<<EOT
-->
	</table>
	
</div>
<div class="p10 tac"><span class="btn"><span><button type="submit">提 交</button></span></span></div>
</form>
<!--
EOT;
?>
