<?php
/**
 * @version        Somao_Search X1.0 9:23 2012-1-1 Somao $
 * @package        Somao_Search.Site
 * @copyright      Copyright (c) 2009 - 2012, Somao, Inc.
 * @license        http://www.somao123.com/
 * @link           http://www.somao.cc/
 */
require("global.php");
include '../uc_client/client.php';
$action=trim(HtmlReplace($_REQUEST["action"]));
switch($action)
{
    case "login":
	         $user_name=trim(HtmlReplace($_POST["entered_login"]));
             $password=trim(HtmlReplace($_POST["entered_password"]));
             $imagecode=trim(HtmlReplace($_POST["entered_imagecode"]));
	         if($_SESSION['randcode']!=$imagecode){
	         jsalert ("验证码错误!");
	         exit(); 
             }
			 #api{{
              if(constant('UC_OFF')==1)
               {  
			         //通过接口判断登录帐号的正确性，返回值为数组
	                 list($uid, $username, $password, $email) = uc_user_login($user_name, $password);
	                 if($uid > 0) {
		                //用户登陆成功，设置 Cookie，加密直接用 uc_authcode 函数，用户使用自己的函数
		                 setcookie('Example_auth', uc_authcode($uid."\t".$username, 'ENCODE'));
		                //生成同步登录的代码
	        	        $ucsynlogin = uc_user_synlogin($uid);
						$check=$db->get_one("select * from ve123_member where user_name='".$user_name."' and password='".md5($password)."'");
	                    if(empty($check)){
						  $array=array('user_name'=>$user_name,'password'=>md5($password),'email'=>$email,'reg_ip'=>ip(),'reg_time'=>time(),'points'=>$config["zs_points"]);
		                  $db->insert("ve123_member",$array);
						  $_SESSION["user_name"]=$user_name;
						  header("location:./");
		         	    }else{
						  $_SESSION["user_name"]=$user_name;
						  header("location:./");	
						}
	                } elseif($uid == -1) {
						$check=$db->get_one("select * from ve123_member where user_name='".$user_name."' and password='".md5($password)."'");
	                    if(!empty($check)){
			              $email=$check["email"];
						  uc_user_register($user_name, $password, $email);
						  $_SESSION["user_name"]=$user_name;
						  header("location:./");
		         	    }else{
							jsalert ("用户不存在,或者被删除!");
		                    exit(); 
						}
	                } elseif($uid == -2) {
						 jsalert ("密码错误!");
		                 exit(); 
	                }else{
						 jsalert ("未知错误!");
		                 exit(); 
					}
			  }else{
				    $check=$db->get_one("select * from ve123_member where user_name='".$user_name."' and password='".md5($password)."'");
	                if(empty($check)){
						 jsalert ("用户名或密码错误!");
		                 exit(); 
			        }else{
			             $_SESSION["user_name"]=$user_name;
		                 header("location:./");
		         	}
			  }
              #/aip}}
	break;
	case "logou":
	      unset($_SESSION["user_name"]);
		  setcookie('Example_auth', '', -86400);
          //生成同步退出的代码
          $ucsynlogout = uc_user_synlogout();
	break;
}
?>
<!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=gb2312" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title><?php echo $config["name"];?>推广服务</title>
<script type="text/javascript"> if (top.location != self.location) top.location = self.location;
    function Login()
    {
    if(document.getElementById("entered_login").value ==""){ alert("帐号不能为空！");return false ;}
    if(document.getElementById("entered_password").value ==""){ alert("密码不能为空！");return false ;}
    if(document.getElementById("entered_imagecode").value ==""){ alert("验证码不能为空！");return false ;}
    }

</script>
<link href="css/style.css" rel="stylesheet" type="text/css" /></head>
<body>
<div id="wrapper" class="area">
  <div id="head"><img src="css/logo2.png" alt="" width="180" height="55" border="0"></div>
  <div id="logArea">
    <div class="loginCard">
      <div class="passportc">
        <form name="form1" method="post" action="login.php" id="form1"> 
        <input type="hidden" name="action" value="login">
          <div class="pptitle"></div>
          <div class="ppcontent">
            <ul class="card">
              <li class="np">
                <label for="entered_login">用户名：</label>
                <input name="entered_login" type="text" id="entered_login" class="ppinput" />
              </li>
              <li class="np">
                <label for="password">密 &nbsp;码：</label>
                <input name="entered_password" type="password" id="entered_password" class="ppinput" />
              </li>
              <li class="np">
                <label for="entered_imagecode">验证码：</label>
                <p>
                  <input name="entered_imagecode" type="text" id="entered_imagecode" class="ppinput" style="width:70px" />
                </p>
                <p style="margin-left:3px"><img src="/include/vdimgck.php" onclick="this.src='/include/vdimgck.php?'+Date()" style="cursor:pointer; height:28px" /></p>
              </li>
              <li>
                <input type="submit" name="Button1" value="登录" onclick="return Login();" id="Button1" class="sign" />
              </li>
              <li><a href="getpwd.php">忘记密码?</a></li>
            </ul>
            <div class="line"></div>
            <ul>
              <li>还没有注册推广帐号？</li>
              <li><a class="loginBtn1" href="reg.php">立即注册</a></li>
            </ul>
          </div>
        </form>
      </div>
    </div>
    <div class="regPro">
      <div class="fpic"><img src="css/655x330.jpg" width="655" height="330" alt="泽许搜索" /></div>
      <div class="log"><strong>我们在努力建设：</strong><span>[2014]</span>泽许搜索...</div>
    </div>
  </div>
</div>
