<?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');
	
	$ls=$_GET['ls'];
	$id=$_GET['id'];
	$selectcate=$_GET['selectcate'];
	$modiid=$_POST['modiid'];
	$userName=trim($_POST['userName']);
	$userCate=trim($_POST['userCate']);
	$userRealName=$_POST['userRealName'];
	$userPwd=$_POST['userPwd'];
	$userEmail=strtolower(trim($_POST['userEmail']));
	$userMemo=$_POST['userMemo'];	
	$userTime=$_POST['userTime'];
	$userNum=$_POST['userNum'];
	$userMSN=strtolower(trim($_POST['userMSN']));
	$userChannel=$_POST['userChannel'];
	$userWBAgentNo=$_POST['userWBAgentNo'];
	$userWBno=$_POST['userWBno'];
	$userAddress=$_POST['userAddress'];
	$userFax=$_POST['userFax'];
	$userMobile=$_POST['userMobile'];
	$userTel=$_POST['userTel'];
	$userQQ=$_POST['userQQ'];
	$userLicence=$_POST['userLicence'];
	$userOwner=$_POST['userOwner'];
	$userIDCard=$_POST['userIDCard'];

	$nowusernum=$_GET['userNum'];

	$ls_msg="代理商管理操作";
	
	
	
	
	switch ($ls)
	{
		case "up":
			$down=$nowusernum-1;
			$down_sql="update ls_agents set userNum=".$nowusernum." where userNum=".$down." ";
			$down_sql2="update ls_agents set userNum=userNum-1 where id=".$id." ";
			//echo $down_sql;
			$down_query=$opendb->query($down_sql);
			$down_query=$opendb->query($down_sql2);
			$ls_msg="上移操作成功！";
			break;
		case "down":
			$up=$nowusernum+1;
			$up_sql="update ls_agents set userNum=".$nowusernum." where userNum=".$up."  ";
			$up_sql2="update ls_agents set userNum=userNum+1 where id=".$id." ";
			
			//echo $up_sql;
			$up_query=$opendb->query($up_sql);
			$up_query=$opendb->query($up_sql2);

			$ls_msg="下移操作成功！";

			break;
		case "insert":
			$select_sql2="select * from ls_agents where userName='".$userName."' ";
			$select_query2=$opendb->query($select_sql2);
			$select_rows2=mysql_num_rows($select_query2); //总数
			if($select_rows2>0)
			{ $ls_msg="用户名已经存在，请重新选择";}
			else{

				$select_sql2="select * from ls_agents ";
				$select_query2=$opendb->query($select_sql2);
				$select_rows2=mysql_num_rows($select_query2); //总数

				$insert_sql="insert into ls_agents(userName,userCate,userRealName,userPwd,userEmail,userMSN,userTime,userMemo,userNum,enable,userChannel,	userAddress,	userFax, userQQ, userLicence, userOwner, userIDCard,userMobile) values ('".$userName."','".$userCate."','".$userRealName."','".$userPwd."','".$userEmail."','".$userMSN."','".date('Y-m-d')."','".$userMemo."',".($select_rows2+1).",1,'".$userChannel."','".$userAddress."','".$userFax."','".$userQQ."','". $userLicence."','". $userOwner."','". $userIDCard."','".$userMobile."')";
				//echo $insert_sql;
				$insert_query=$opendb->query($insert_sql);
				$ls_msg="添加操作成功！";
			}
			break;
		case "modi":
			$modi_sql="update ls_agents set userName='".$userName."', userRealName='".$userRealName."', userPwd='".$userPwd."', userEmail='".$userEmail."', userMSN='".$userMSN."', userMemo='".$userMemo."',userTime='".$userTime."', userNum='".$userNum."',userChannel='".$userChannel."',userAddress='".$userAddress."',userFax='".	$userFax."',userQQ='". $userQQ."',userLicence='". $userLicence."',userOwner='". $userOwner."',userIDCard='".$userIDCard."',userCate='". $userCate."',userMobile='". $userMobile."',userTel='".$userTel."' where id=".$modiid." ";
			//echo $modi_sql;
			$modi_query=$opendb->query($modi_sql);
			$ls_msg="修改操作成功！";
			break;
		case "del":
			$user_sql2="select * from ls_agents where id=".$id." ";
			$user_query2=$opendb->query($user_sql2);
			$user_rows2=mysql_fetch_assoc($user_query2);
			$num_sql2="update ls_agents set userNum=userNum-1 where userNum>".$user_rows2['userNum']." ";//all order number-1
			$down_query=$opendb->query($num_sql2);
		
			$del_sql="delete from ls_agents where id=".$id." ";
			//echo $del_sql;
			$del_query=$opendb->query($del_sql);
			$ls_msg="删除操作成功！";
			break;
		case "unenable":
			$unenable_sql="update ls_agents set enable=0 where id=".$id." ";
			//echo $unenable_sql;
			$unenable_query=$opendb->query($unenable_sql);
			$ls_msg="禁止操作成功！";
			
			break;
		case "enable":
			$enable_sql="update ls_agents set enable=1 where id=".$id." ";
			//echo $enable_sql;
			$enable_query=$opendb->query($enable_sql);
			$ls_msg="允许操作成功！";
			
			break;
	}
	if($selectcate<>''&&$selectcate<>'全部'){	$user_sql="select * from ls_agents where userCate='".$selectcate."' order by userNum asc";}
	else
	{	$user_sql="select * from ls_agents order by userNum asc";	}
	$user_query=$opendb->query($user_sql);
	$user_num=mysql_num_rows($user_query);	
	
?>
<!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>
		<style type="text/css">
<!--
.STYLE1 {
	color: #FFFFFF;
	font-weight: bold;
	font-size: 14px;
}
-->
		</style>
</head>

	<body>
	<table width="99%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#6396d6">
	  <tr>
		<td height="33" background="images/admin_bg.gif"><div align="center" class="STYLE1">代理商管理</div></td>
	  </tr>
	  <tr>
		<td height="213" valign="top" bgcolor="#dee7ff"><br>
			<table border="0" width="97%" align="center">
			  <tr>
				<td width="69%">提示:<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
				<td width="31%"><span style="padding-left:20px;"> 分类显示:
				  <select name="select2" id="select2"  onChange="window.open('?selectcate='+this.value,'right','');">
						<option value="0">请选择一个类别:</option>
						<option value="全部">全部</option>
						<?
			$web_sql="SELECT cates FROM ls_agentcates  order by cates";//count the error by searchtype
			$web_query=$opendb->query($web_sql);
			while($web_rows2=mysql_fetch_assoc($web_query))
		  	{
				echo "<option value=".$web_rows2['cates'].">".$web_rows2['cates']."</option>";
			}

			?>
			    </select>
				</span></td>
			  </tr>
			</table>
		  <table width="99%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#FFFFFF">
<tr bgcolor="#DFF0EA">
				<td  height="28" align="center">序号</td>
		  <td  height="28" align="center">代理类别</td>
		  <td  height="28" align="center">用户名</td>
		  <td  align="center">联系人</td>
		  <td height="28" align="center">身份证号</td>
		  <td  align="center"  >手机</td>
		  <td align="center">email</td>
		  <td  align="center">MSN</td>
		  <td  align="center">QQ</td>
		 
   		 <td colspan="2"align="center">排序</td>
		 <td  align="center" width="30">操作</td>
		  <td  align="center" width="30">删除</td>
  <td align="center" width="30">允许</td>
			</tr>
			  <?php 
					 $i=1;
					  while ($user_rows=mysql_fetch_assoc($user_query))
					  {
						echo "<tbody id='ZH_".$user_rows['ID']."' >";	
						echo "<tr bgcolor='#f4f4f4'";
						echo "onMouseOver=";
						echo " 	this.style.backgroundColor='#CCFFCC' ";
						echo "onMouseOut=";
						echo " 	this.style.backgroundColor='#f4f4f4' ";
						echo ">";	
						echo "	<td align='left' style='padding-left:10px;' height='25' >";
					  	echo 		$user_rows['userNum'];
						echo "	</td>";
						echo "	<td align='left' style='padding-left:10px;' height='25' >";
					  	echo 		$user_rows['userCate'];
						echo "	</td>";
						echo "	<td align='left' style='padding-left:10px;' height='25' >";
					  	echo 		$user_rows['userName'];
						echo "	</td>";
						
						
						echo "	<td align='left' style='padding-left:10px;' height='25'>";
					  	echo 		$user_rows['userRealName'];
						echo "	</td>";
						echo "	<td align='left' style='padding-left:10px;' height='25' >";
					  	echo 		$user_rows['userIDCard'];
						echo "	</td>";
						echo "	<td align='left' style='padding-left:10px;' height='25'>";
					  	echo 		$user_rows['userMobile'];
						echo "	</td>";
						echo "	<td align='left' style='padding-left:10px;' height='25'>";
					  	echo "		<a href=\"mailto:".$user_rows['userEmail']."\">".$user_rows['userEmail']."</a>\n";
						echo "	</td>";
						echo "	<td align='left' style='padding-left:10px;' height='25'>";
					  	echo "		<a href=\"msnto:".$user_rows['userMSN']."\">".$user_rows['userMSN']."</a>\n";
						echo "	</td>";
						echo "	<td align='left' style='padding-left:10px;' height='25'>";
					  	echo 		$user_rows['userQQ'];
						echo "	</td>";


						echo "	<td align='center' width='30'> ";
						if($i!=1)// not start up
						{						
							echo "	<a href='?page=$page&id=".$user_rows['ID']."&userNum=".$user_rows['userNum']."&ls=up' title='向上移动'><img src='images/up.gif' border='0'></a>";
						}
						echo "  </td>";
						echo "	<td align='center' width='30'> ";
						if($i!=$user_num)// not end down
						{
							echo "	 <a href='?page=$page&id=".$user_rows['ID']."&userNum=".$user_rows['userNum']."&ls=down' title='向下移动'><img src='images/down.gif' border='0'></a>";
						}
						echo "  </td>";
						echo "	<td align='center'> ";
						echo "	<a href='javascript:secBoard(".$user_rows['ID'].")' title='编辑'><img src='images/b_edit.png' border='0'></a>";
						echo "  </td>";
						echo "	<td align='center'> ";
						if($user_rows['userAdmin']==1)
						{
							echo "	<img src='images/b_undrop.png' border='0'>";
						}
						if($user_rows['userAdmin']==0)
						{
							echo "		<a href='?page=$page&id=".$user_rows['ID']."&ls=del' onclick='return ConfirmDel();' title='删除'><img src='images/b_drop.png' border='0'></a>";
						}
						echo "  </td>";
						echo "	<td align='center'>";
						  
						  if($user_rows['enable']==1)
							{
								echo "<a href='?page=$page&id=".$user_rows['ID']."&ls=unenable' title='显示'><img src='images/enable.gif' border='0'></a>";
							}
						  if($user_rows['enable']==0)
						  	{
								echo "<a href='?page=$page&id=".$user_rows['ID']."&ls=enable' title='不显示'><img src='images/unenable.gif' border='0'></a>";
							}
													
						echo "	</td>";
						echo "</tr>";
						echo "</tbody>";
						
						echo "<tbody id='Z_".$user_rows['ID']."' style='display:none;'>";
						echo " <form name='fm_user' action='?ls=modi' method='post'> ";
						echo "	<tr bgcolor='#CCCCCC'>";
						echo "	<td align='left' style='padding-left:3px;' height='25' ><input type='hidden' value='".$user_rows['userNum']."' name='userNum'> ";
					  	echo 		$user_rows['userNum'];
						echo "	</td>";
						echo "	<td align='left' style='padding-left:3px;' height='25'>";
						echo " 目前状态:</br> <input name=\"userCate\" type=\"text\" size=\"14\" readonly value=\"".$user_rows['userCate']."\"></br></br>";
						echo "代理选择: </br> <select name=\"select\" id=\"select\"  onChange=\"this.form.userCate.value=this.value;\">
								 <option value=\"0\">请选择类别:</option>";
								 
							 mysql_data_seek($web_query,0);
			while($web_rows2=mysql_fetch_assoc($web_query))
		  	{
				echo "<option value=".$web_rows2['cates'].">".$web_rows2['cates']."</option>";
			}

			
					   echo "		</select>";
	
						echo "	</td>";
						echo "	<td align='left' style='padding-left:3px;' height='25'  size='5'>";
						echo " 用户名:</br><input type='text' value='".$user_rows['userName']."' name='userName' class='inp' size='8'></br></br>";
						
						echo " 密码:</br><input type='password' value='".$user_rows['userPwd']."' name='userPwd' class='inp' size='8'> ";

						echo " 		</td>";
						echo "	<td align='left' style='padding-left:3px;' height='25' size='5'>";
					  	echo " 联系人:</br><input type='text' value='".trim($user_rows['userRealName'])."' name='userRealName' class='inp' size='6'> </br>";
					  	echo  "	法人:</br><input type='text' value='".$user_rows['userOwner']."' name='userOwner' class='inp' size='6'> ";
						echo "	</td>";
						echo "	<td align='left' style='padding-left:3px;' height='25' size='16'>";
					  	echo  "	身份证号:</br><input type='text' value='".$user_rows['userIDCard']."' name='userIDCard' class='inp'  size='18'> </br></br>";
					  	echo  "	营业执照号:</br><input type='text' value='".$user_rows['userLicence']."' name='userLicence' class='inp' size='18'> ";
						
						echo "	</td>";
						
						echo "	<td align='left' style='padding-left:3px;' height='25' size='16'> ";
					  	echo " 手机:</br><input type='text' value='".trim($user_rows['userMobile'])."' name='userMobile' class='inp'size='11'></br></br>";
					  	echo  " 电话:</br><input type='text' value='".$user_rows['userTel']."' name='userTel' class='inp' size='11'> ";
						echo "	</td>";
						echo "	<td align='left' style='padding-left:3px;' height='25' size='7'>";
					  	echo  "	Email:</br><input type='text' value='".$user_rows['userEmail']."' name='userEmail' class='inp'  size='13'></br> </br>";
					  	echo  " 传真:</br><input type='text' value='".$user_rows['userFax']."' name='userFax' class='inp'  size='13'> ";
						echo "	</td>";
						echo "	<td align='left' style='padding-left:3px;' height='25' size='16' >";
					  	echo  "	MSN:</br><input type='text' value='".$user_rows['userMSN']."' name='userMSN' class='inp' size='29'></br> </br>";
					  	echo  "	地址:</br><input type='text' value='".$user_rows['userAddress']."' name='userAddress' class='inp' size='29'> ";
						echo "	</td>";
						echo "	<td align='left' colspan='4' style='padding-left:3px;' height='25' size='20'>";
					  	echo  "	QQ:</br><input type='text' value='".$user_rows['userQQ']."' name='userQQ' class='inp' size='29'> </br>";
					  	echo  "	销售渠道:</br><input type='text' value='".$user_rows['userChannel']."' name='userChannel' class='inp' size='29'> ";
						echo "	</td>";

						echo "		<td colspan='2' align='center'>";
						echo "			<input value='".$user_rows['ID']."' name='modiid' type='hidden'>";
						echo "			<input type='submit' value='确定修改'> &nbsp; ";
						echo "			<input type='button' onclick='javascript:secBoard2(".$user_rows['ID'].")' value='放弃修改'>";
						echo " 		</td>";
						echo "	</tr>";
						echo " </form>";
						echo "</tbody>";
						$i++;
					  }
					 ?>
		  </table>
		  <br />
<form name="fmadduser" action="?ls=insert" method="post">
			  <table width="99%" border="0" align="center" cellpadding="1" cellspacing="0" bgcolor="#FFFFFF">
				<tr bgcolor="#B9DAFF">
				  <td height="28" colspan="4" bgcolor="#ACCCBB" style='padding-left:20px;'><div align="center"><span class="STYLE1">增加代理商</span></div></td>
				</tr>
				<tr bgcolor="#B9DAFF">
				  <td width="16%" height="28" bgcolor="#E1F0E9" style='padding-left:20px;'>联系人姓名:*</td>
				  <?
			$web_sql="SELECT cates FROM ls_agentcates  order by ID asc ";//count the error by searchtype
			$web_query=$opendb->query($web_sql);
			$web_rows2=mysql_fetch_assoc($web_query)
			?>
				  <td width="33%" bgcolor="#E1F0E9" style='padding-left:20px;'><input type="text" name="userRealName"></td>
				  <td width="16%" bgcolor="#E1F0E9" style='padding-left:20px;'>身份证号: 
					*</td>
				  <td width="35%" bgcolor="#E1F0E9" style="padding-left:20px;"><input type="text" name="userIDCard"></td>
				</tr>
				<tr bgcolor="#B9DAFF">
				  <td height="28" bgcolor="#E1F0E9" style='padding-left:20px;'>电话 :*</td>
				  <td height="28" bgcolor="#E1F0E9" style='padding-left:20px;'><input type="text" name="userTel"></td>
				  <td bgcolor="#E1F0E9" style='padding-left:20px;'>email:*</td>
				  <td bgcolor="#E1F0E9" style='padding-left:20px;'><input type="text" name="userEmail"></td>
				</tr>
				<tr bgcolor="#B9DAFF">
				  <td height="28" bgcolor="#E1F0E9" style='padding-left:20px;'>传真:						   
					*</td>
				  <td height="28" bgcolor="#E1F0E9" style='padding-left:20px;'><input type="text" name="userFax"></td>
				  <td bgcolor="#E1F0E9" style='padding-left:20px;'>MSN : </td>
				  <td bgcolor="#E1F0E9" style="padding-left:20px;"><input type="text" name="userMSN" onFocus="fmadduser.userMSN.value=fmadduser.userEmail.value"></td>
				</tr>
				<tr bgcolor="#B9DAFF">
				  <td bgcolor="#E1F0E9" style='padding-left:20px;'>手机:						   *</td>
				  <td bgcolor="#E1F0E9" style="padding-left:20px;"><input type="text" name="userChannel"></td>
				  <td bgcolor="#E1F0E9" style='padding-left:20px;'>Q Q : </td>
				  <td bgcolor="#E1F0E9" style='padding-left:20px;'><input type="text" name="userQQ" onFocus="fmadduser.userMSN.value=fmadduser.userEmail.value"></td>
				</tr>
				<tr bgcolor="#B9DAFF">
				  <td height="28" bgcolor="#E1F0E9" style='padding-left:20px;'>地址:
					
					*</td>
				  <td height="28" bgcolor="#E1F0E9" style='padding-left:20px;'><input name="userAddress" type="text" size="50"></td>
				  <td bgcolor="#E1F0E9" style='padding-left:20px;'>备注: </td>
				  <td bgcolor="#E1F0E9"  style="padding-left:20px;">
				  <input type="text" name="userMemo"></td>
				</tr>
				<tr bgcolor="#B9DAFF">
				  <td height="28" colspan="4" bgcolor="#E1F0E9" style='padding-left:20px;'><div align="right">
					<input type="submit" value="添加代理">
				  </div></td>
				</tr>
				<tr bgcolor="#B9DAFF">
				  <td height="28" colspan="2" bgcolor="#E1F0E9" style='padding-left:20px;'><label> 类别:
					<input name="userCate" type="text" size="16" readonly value="<?=$web_rows2['userCate']?>">
						<select name="select" id="select"  onChange="this.form.userCate.value=this.value;">
						  <option value="0">请选择一个类别:</option>
						  <?
							 mysql_data_seek($web_query,0);
			while($web_rows2=mysql_fetch_assoc($web_query))
		  	{
				echo "<option value=".$web_rows2['cates'].">".$web_rows2['cates']."</option>";
			}

			?>
						</select>
				  </label></td>
				  <td bgcolor="#E1F0E9" style='padding-left:20px;'>营销渠道:</td>
				  <td bgcolor="#E1F0E9"  style="padding-left:20px;"><input name="userChannel" type="text" size="50" ></td>
				</tr>
				<tr bgcolor="#B9DAFF">
				  <td height="28" bgcolor="#E1F0E9" style='padding-left:20px;'>营业执照号:
					
					*</td>
				  <td height="28" bgcolor="#E1F0E9" style='padding-left:20px;'><input type="text" name="userLicence"></td>
				  <td bgcolor="#E1F0E9" style='padding-left:20px;'>法人姓名:</td>
				  <td bgcolor="#E1F0E9" style="padding-left:20px;"><input type="text" name="userOwner"></td>
				</tr>
				<tr bgcolor="#B9DAFF">
				  <td height="28" bgcolor="#E1F0E9" style='padding-left:20px;'>用户名:&nbsp;&nbsp;</td>
				  <td height="28" bgcolor="#E1F0E9" style='padding-left:20px;'><input type="text" name="userName2">
					*</td>
				  <td bgcolor="#E1F0E9" style='padding-left:20px;'>密码:&nbsp;</td>
				  <td bgcolor="#E1F0E9" style="padding-left:20px;"><input type="password" name="userPwd2">
					*</td>
				</tr>
				<tr bgcolor="#B9DAFF">
				  <td height="28" colspan="4" bgcolor="#E1F0E9" style='padding-left:20px;'><div align="center">
					<input type="submit" value="添加代理">
				    <input name="重置" type="reset" value="重置" />
				  </div></td>
				</tr>
      </table>
		  </form>
<br /></td>
	  </tr>
	</table>
	</body>
</html>