<?php
	session_start(); 
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/ls_syscode.php');
	require_once('inc/check.php');
	
	$opendb=new mydb();
	require_once('inc/char_set.php');
	
	//Cache & preprocess catalogy data
	$grandcatesql="select * from ls_products where cateName is not null";
	$grandcatequery=$opendb->query($grandcatesql);
	while($grandcate=mysql_fetch_assoc($grandcatequery))
	{
		$catecache[$grandcate['cateName']]['name']=$grandcate['cateName'];
		$catecache[$grandcate['cateName']]['id']=$grandcate['ID'];
		$catecache[$grandcate['cateName']]['need']=1;
		$checkprosql="select * from ls_products where productID={$grandcate['ID']}";
		$checkproq=$opendb->query($checkprosql);
		if(mysql_num_rows($checkproq)>0)
		{
			$catecache[$grandcate['cateName']]['provide']=0;
		}
		else
		{
			$catecache[$grandcate['cateName']]['provide']=2;
		}
		$searchmidcatesql="select * from ls_products where midcateID='{$grandcate['ID']}'";
		$searchmidcatequery=$opendb->query($searchmidcatesql);
		if(mysql_num_rows($searchmidcatequery)>0)//如果下面有小类
		{
			$catecache[$grandcate['cateName']]['need']++;
		}
		while($midcate=mysql_fetch_assoc($searchmidcatequery))
		{
			$catecache[$grandcate['cateName']][$midcate['midcateName']]['name']=$midcate['midcateName'];
			$catecache[$grandcate['cateName']][$midcate['midcateName']]['id']=$midcate['ID'];
			$catecache[$grandcate['cateName']][$midcate['midcateName']]['need']=1;
			$checkprosql="select * from ls_products where productID={$midcate['ID']}";
			$checkproq=$opendb->query($checkprosql);
			if(mysql_num_rows($checkproq)>0)
			{
				$catecache[$grandcate['cateName']][$midcate['midcateName']]['provide']=0;
			}
			else
			{
				$catecache[$grandcate['cateName']][$midcate['midcateName']]['provide']=1;
			}
			$catecache[$grandcate['cateName']][$midcate['midcateName']]['exclusive']=$catecache[$grandcate['cateName']]['id'];
			$searchsubcatesql="select * from ls_products where subcateID={$midcate['ID']}";
			$searchsubcatequery=$opendb->query($searchsubcatesql);
			if(mysql_num_rows($searchsubcatequery)>0)
			{
				if($catecache[$grandcate['cateName']]['need']<3)
				{
					$catecache[$grandcate['cateName']]['need']++;
				}
				if($catecache[$grandcate['cateName']][$midcate['midcateName']]['need']<2)
				{
					$catecache[$grandcate['cateName']][$midcate['midcateName']]['need']++;
				}
			}
			while($subcate=mysql_fetch_assoc($searchsubcatequery))
			{
				$catecache[$grandcate['cateName']][$midcate['midcateName']][$subcate['subcateName']]['name']=$subcate['subcateName'];
				$catecache[$grandcate['cateName']][$midcate['midcateName']][$subcate['subcateName']]['id']=$subcate['ID'];
				$catecache[$grandcate['cateName']][$midcate['midcateName']][$subcate['subcateName']]['need']=1;
				$catecache[$grandcate['cateName']][$midcate['midcateName']][$subcate['subcateName']]['little']=1;
				$catecache[$grandcate['cateName']][$midcate['midcateName']][$subcate['subcateName']]['provide']=0;
				$catecache[$grandcate['cateName']][$midcate['midcateName']][$subcate['subcateName']]['exclusive']=$catecache[$grandcate['cateName']][$midcate['midcateName']]['id'];
			}
		}
	}
	//print_r($catecache);
	//Do NOT touch this array, or function will fall.
	$falsearray=array('id','need','name','provide','exclusive');	


		
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<link href="css/admin.css" rel="stylesheet" type="text/css">
		<script language="JavaScript" src="js/ls.js"></script>
		<title>无标题文档</title>
	</head>
<script language="javascript" src="js/catetransfer.js"></script>
<style type="text/css">
.none{
	display:none;
	}
.show{
	display:;
	}

</style>

 <body>
	<table width="96%" align="center" cellpadding="1" cellspacing="1" bgcolor="#6396d6">
			<tr>
				<td height="18" background="images/admin_bg.gif"><div align="center"><font color="#ffffff"><strong>产品类别迁移助手</strong></font></div>
				</td>
			</tr>
            
            
            
			<tr>
				<td height="213" valign="center" align="center" bgcolor="#dee7ff">
				<form id="transform" name="transform" action="catetransact.php?ls=trans" method="post">
				  <table width="90%" border="0">
				  <tr height="10px">
				  <td colspan="3">&nbsp;</td>
				  </tr>
					<tr align="center">
					  <td>
					  <fieldset>
					  <legend>选择要迁移的类别</legend>
					  <span class="spanovercate">
					  <select id="origincate" name="origincate"  size="30" class="origincate" onChange="javascript:originchange();">
					  <?php 
					  	foreach($catecache as $catekey=>$grandcate)
						{
							if(in_array($catekey,$falsearray))
							{
								continue;
							}
							echo "<option  value='{$grandcate['id']}' needlevel='{$grandcate['need']}' exclusion='-1'>{$grandcate['name']}</option>\n";
							if(is_array($grandcate))
							{
								foreach($grandcate as $midkey=>$midcate)
								{
									if(in_array($midkey,$falsearray))
									{
										continue;
									}
									echo "<option value='{$midcate['id']}' needlevel='{$midcate['need']}' exclusion='{$midcate['exclusive']}'>&nbsp;&nbsp;&nbsp;{$midcate['name']}</option>\n";
									if(is_array($midcate))
									{
										foreach($midcate as $subkey=>$subcate)
										{
											if(in_array($subkey,$falsearray))
											{
												continue;
											}
											echo "<option value='{$subcate['id']}' needlevel='{$subcate['need']}' exclusion='{$subcate['exclusive']}'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$subcate['name']}</option>\n";
										}
									}
								}
							}
						}					  	
					  ?>
					  </select>
					  </span>
					  </fieldset>
					  </td>
					  <td style="width:150px;" valign="middle">
                      <div style="margin:40px;">
                        <select name="type" onchange="check1(this.value);">
                          <option value="1" >类别迁移</option>
                          <option value="2" >类别合并</option>
                        </select>
                      </div>
                      <div id="qianyi"><img id="arrowimg" height="37px" width="47px" src="images/transferblue.png" onMouseOver="javascript:overimg();" onMouseOut="javascript:leaveimg();" onMouseDown="javascript:downimg();" onMouseUp="javascript:upimg(this);" style="cursor:hand;" /><br /><span id="news" style="color:#F00"></span></div>
                      
                       <div id="hebing" class="none"><img id="arrowimg1" height="37px" width="47px" src="images/transferblue.png" onMouseOver="javascript:overimg();" onMouseOut="javascript:leaveimg();" onMouseDown="javascript:downimg();" onMouseUp="javascript:upimg(this);" style="cursor:hand;" /><br /><span id="news1" style="color:#F00"></span></div>
                      
                      </td>
					  <td>
					  <fieldset>
					  <legend>选择要迁移至的目标类别</legend>
					  <span class="spanovercate">
					  <select id="destcate" name="destcate" size="30" class="destcate" onChange="javascript:originchange();">
					  	<option value="-1" providelevel="3">根分类</option>
						<?php
						foreach($catecache as $catekey=>$grandcate)
						{
							if(in_array($catekey,$falsearray))
							{
								continue;
							}
							echo "<option value='{$grandcate['id']}' needlevel='{$grandcate['need']}' needlevel2='{$grandcate['little']}' providelevel='{$grandcate['provide']}'>&nbsp;&nbsp;&nbsp;{$grandcate['name']}</option>\n";
							if(is_array($grandcate))
							{
								foreach($grandcate as $midkey=>$midcate)
								{
									if(in_array($midkey,$falsearray))
									{
										continue;
									}
									echo "<option value='{$midcate['id']}' needlevel='{$midcate['need']}'  needlevel2='{$$midcate['little']}' providelevel='{$midcate['provide']}'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$midcate['name']}</option>\n";
									if(is_array($midcate))
									{
										foreach($midcate as $subkey=>$subcate)
										{
											if(in_array($subkey,$falsearray))
											{
												continue;
											}
											echo "<option value='{$subcate['id']}' needlevel='{$subcate['need']}'  needlevel2='{$subcate['little']}'  providelevel='0'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$subcate['name']}</option>\n";
										}
									}
								}
							}
						}
						?>
					  </select>
					  </span>
					  </fieldset>
					  </td>
					</tr>
				</table>
				</form>
				</td>
			</tr>
	</table>
	<br>
	<table width="96%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#6396d6">
			<tr>
				<td height="18" background="images/admin_bg.gif"><div align="center"><font color="#ffffff"><strong>操作说明</strong></font></div>
				</td>
			</tr>
			<tr>
				<td valign="top" bgcolor="#dee7ff"><br>
				  <ul>
				  	<li>
						先从左侧选择要迁移的产品类别。然后在右侧选择要迁移到的产品类别，然后点击中间的箭头按钮执行迁移操作。
						</li>
					<li>
						当类别可以被迁移到右侧目标类别下的时候，中间的箭头按钮呈绿色。当类别不能被迁移到右侧目标类别下的时候，中间的箭头按钮呈红色，这时，请重新选择目标类别。
						</li>
					<li><font color="#FF0000">
						警告：由于大类中所存储的信息远多于中类及小类，因此，对大类的降级操作将导致大类中所存储的富余信息被丢弃，而由中类或小类升级来的大类将产生信息的空缺。请注意在类别迁移后进行调整与补足。
						</font></li>
					<li>
						类别迁移将自动扫描并纠正类别序列错误的情况，请在迁移后检查
                        
                        
                        
                        
                        
						</li>
				  </ul>
				</td>
			</tr>
	</table>
						
 </body>
</html>