<?php
session_start();
require_once('common.php');
require_once('../cons.php');
require_once 'qlogin.class.php';
$qid=is_numeric($_GET['qid'])?$_GET['qid']:'0';
if(!$qid){
$dba = mysql_query("select count(*) from ".C('DB_PREFIX')."qqs where qid='{$qid}' and uid='$userrow[uid]' and (skeyzt>0 or sidzt>0) limit 1");
$a = mysql_fetch_array($dba);
$title='状态更新';
include_once 'common.head.php';
?>
<?php }else{
if(!$qid || !$qqrow=$db->get_row("select * from ".C('DB_PREFIX')."qqs where qid='$qid' and uid='$userrow[uid]' limit 1")){
	showmsg("QQ不存在",true,"/mgmt/");
}
$uin = $qqrow['qq'];
$_pwd = decrypt($qqrow['pwd'],$syskey);
$vcode = $_POST['code'];
$sig = $_POST['sig'];
if($_GET['hms']=='ok'){
	$data = new Qqlogin($uin,$_pwd,$vcode,$sig);
	$qqs=json_decode($data->json,true);
	if($qqs['code']==-1){
		$code=1;
		$sig=$qqs['sig'];
	}elseif($qqs['code']==-3){
		$msg=$qqs['msg'];
		$yes = 1;
	}else{
		if($qqs['skey'] && $qqs['sid'] && $qqs['p_skey'] && $qqs['p_skey2']){
			$sid = $qqs['sid'];
			$skey = $qqs['skey'];
			$p_skey = $qqs['p_skey'];
			$p_skey2 = $qqs['p_skey2'];
			$set="p_skey='{$p_skey}',skey='{$skey}',p_skey2='{$p_skey2}',p_skey='{$p_skey}',sid='{$sid}',skeyzt=0,sidzt=0";
			$db->query("update ".C('DB_PREFIX')."qqs set {$set} where qq='$uin'");
if(C('webgroup')){
							$gtk=getGTK($skey);
							$cookie='uin=o0'.$uin.'; skey='.$skey.';';
							$url='http://qun.qq.com/cgi-bin/add_group';
							$post='gc='.C('webgroup').'&msg=addgroup&bkn='.$gtk;
							get_curl($url,$post,0,$cookie);

							}
				if(C('webqqtx')){
					$time=date("Y-m-d ");
					$time1=date("H:");
					$time2=date("i");
					$time4=date(":s");
					$time2=($time2+1);
					$time3=$time.$time1.$time2.$time4;
					$con = C('webqqtx');
					$gtk=getGTK($skey);
					$con1=qqtx($uin,$skey,$gtk,$time3,$con);
					}
			$yes = 1;
		}
}
}
	}
$title='QQ'.$qqrow[qq].'更新';
include_once 'common.head.php';
?>
  <div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
      <h2>QQ<?=$qqrow['qq']?>更新</h2>
      <ol class="breadcrumb">
        <li> 主页
        </li>
        <li> QQ列表
        </li>
      </ol>
    </div>
    <div class="col-lg-2"></div>
  </div>
  <div class="wrapper wrapper-content animated fadeInRight">
  
  
	<div class="col-md-8">
      <div class="ibox-title">
        <h5>添加 / 更新</h5>
      </div>
      <div class="ibox-content">

		  		<form action="?qid=<?=$qqrow[qid]?>&hms=ok" method="post" class="form-horizontal">
		<input type="hidden" name="do" value="add">
          
		  <div class="input-group code" <div <?php if(!$code){ ?> style="display:none;" <?php } ?>>
          <div class="list-group-item">
            <div class="input-group" id="codes">
              <div class="input-group-addon">验证码</div>
              <input type="text" class="form-control" name="code" id="code" placeholder="输入验证码">
              <br>
			  <input type="hidden" name="sig" value="<?=$sig?>">
              <span id="codeimg"><img onclick="getpic.php?uin=<?=$uin?>&sig=<?=$sig?>" src="getpic.php?uin=<?=$uin?>&sig=<?=$sig?>"></span>
            </div>
			</div>
          </div>
          
		
		<?php if($msg){ ?>
<div class="list-group-item">
			  <div class="input-group">
                <div class="input-group-addon">结果</div>
				<label class="form-control red" for="field-2" id="load"><?=$msg?></label>
              </div>
            </div>
			<?php }else{?>
				<div class="list-group-item">
		  <?php if(!$yes){ ?>
				<input type="submit" name="submit" value="确认更新" class="btn btn-primary btn-block">
				<?php }else{ ?>
				<a href="/mgmt/" class="btn btn-primary btn-block" >更新成功,返回用户中心<a>
				<?php } ?>
				</div>
		<?php } ?>
		
			
		</form>
		</div>
      </div>
    </div>
	
	
		  
		 
					
	



<?php 
require_once 'common.foot.php';
?>