<?php
@session_start();
include('inc/conn.php');
include('loadingdata.php');

$name=$_POST['username'];
$password=$_POST['password'];

$sql2="select * from chat_user where username='".$name."' and password='".md5($password)."'";
$sql3="select * from etw_user where username='".$name."' and password='".$password."'";

$result2=mysql_query($sql2)or die("error");
$result3=mysql_query($sql3)or die("error");

$online=mysql_fetch_array($result2);
$company=mysql_fetch_array($result3);

  if(count($company[0])==1){
     $vote="father";
	 loadingdate($company['userid']);
  }elseif(count($online[0])==1){
     $vote="child";
  }else{
  echo "<script type=\"text/javascript\">alert('用户名或密码不正确，请重新输入！'); window.location.href=\"index.php\";</script>";
  }

  switch($vote){
     case "father":	 
                  $ins="insert into etw_loginlog(userid,loginname,logintime,ip) value(".$company['userid'].",'".$name."','".time()."','".get_client_ip()."')";
                  mysql_query($ins);
				  $_SESSION['vote']=$vote;
				  $_SESSION['guestid']=$company['userid'];
                  $_SESSION['etwcustomer']=$name;
                echo "<script type=\"text/javascript\"> window.location.href=\"manage.php\";</script>";
                echo "<center>please <a href='manage.php'>CLICK here Enter</a></center>"; 
				  break;
				  
     case "child":
                  $ins="insert into etw_loginlog(userid,loginname,logintime,ip) value(".$online[userid].",'".$name."','".time()."','".get_client_ip()."')";
                  mysql_query($ins);
				  $_SESSION['vote']=$vote;
				  $_SESSION['guestid']=$online['userid'];
                  $_SESSION['etwcustomer']=$name;
                //在线洽谈初始数据
			      $count=sql_select("select count(*) from chat_message where username='".$name."'");
	              $_SESSION["username"]=$name;
	              $_SESSION["mycounts"]=$count[0][0];
                //在线洽谈初始数据结束   
				  echo "<script type=\"text/javascript\"> window.location.href=\"manage.php\";</script>"; 
				  break;
	}
mysql_close();
 ?>