<?php
	require_once('_approot.php');	
	//Cache & preprocess catalogy data
	$grandcatesql="select * from ls_products where cateName is not null  order by Num asc";
	$grandcatequery=$opendb->query($grandcatesql);
	while($grandcate=mysqli_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(mysqli_num_rows($checkproq)>0)
		{
			$catecache[$grandcate['cateName']]['provide']=0;
		}
		else
		{
			$catecache[$grandcate['cateName']]['provide']=2;
		}
		$searchmidcatesql="select * from ls_products where midcateID='{$grandcate['ID']}'  order by Num asc";
		$searchmidcatequery=$opendb->query($searchmidcatesql);
		if(mysqli_num_rows($searchmidcatequery)>0)//如果下面有小类
		{
			$catecache[$grandcate['cateName']]['need']++;
		}
		while($midcate=mysqli_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(mysqli_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']}  order by Num asc";
			$searchsubcatequery=$opendb->query($searchsubcatesql);
			if(mysqli_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=mysqli_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">
         <link href="css/style2.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="100%" align="center" cellpadding="1" cellspacing="1">
                        <tr>
				<td height="18" style="border-bottom:2px solid #00c0ef; padding-bottom:5px;"><div align="center"><font color="#3c8dbc" style="font-size:16px;">产品类别迁移</font></div>
				</td>
			</tr>
                               <tr bgcolor="#fff">
                        <td colspan="2" height="24" align="center">&nbsp;</td>
                      </tr>
			<tr>
				<td height="213" valign="center" align="center">
				<form id="transform" name="transform" action="catetransact.php?ls=trans" method="post">
                
				  <table width="98%" border="0" style="background-color: #f0f0ee;" >
					<tr align="center" bgcolor="#f0f0ee">
					  <td bgcolor="#f0f0ee">
					  <fieldset>
					  <legend><div style="height:27px;">需要迁移的类别</div></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" bgcolor="#f0f0ee">
                      <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>
                      <p>&nbsp;                        </p>
                      <p>
                        <input name="keepold" type="checkbox" id="keepold" style="margin-left:5px;" value="0" />
                        保留原来的页面
                      </p>
                      <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 bgcolor="#f0f0ee">
					  <fieldset>
					  <legend><div style="height:27px;">迁移到</div></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>
                   <tr bgcolor="#f0f0ee">
                        <td colspan="2" height="24" align="center">&nbsp;</td>
                      </tr>
				</table>
				</form>
				</td>
			</tr>
            <br>
	</table>
	<br>
	<table width="100%" align="center" cellpadding="6" cellspacing="1">
            <tr>
				<td height="18" style="border-bottom:2px solid #00c0ef; padding-bottom:5px;"><div align="center"><font color="#3c8dbc" style="font-size:16px;">操作说明</font></div>
				</td>
			</tr>
			<tr>
				<td height="88" valign="top"> 
				  <ul>
				  	<li>
						先从左侧选择要迁移的类别，右侧选择迁移到的类别，然后点击中间的箭头。</li>
					<li>
						当类别可以被迁移到右侧的时候，中间的箭头按钮呈绿色。当类别不能被迁移的时候，中间的箭头按钮呈红色，这时，请重新选择目标类别。
						</li>
					<li>
						类别迁移将自动扫描并纠正类别序列错误况，请在迁移后检查
                        
                        
                        
                        
                        
						</li>
			    </ul></td>
			</tr>
	</table>
						
 </body>
</html>