<?php

$GLOBALS['WEATHER_DATA'] = '../../';
  @ require ('../../inc/set/set.php');
  @ require ('../../inc/set/set_sql.php');


//输出错误
function err($text = '', $src = 'i') {
  echo '<!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" />
<title></title>
<link id="my_style" rel="stylesheet" type="text/css" href="../../inc/css/'.$web['sitemode'].'/style.css">
<style type="text/css">
<!--
.wherego { margin:10px auto; border:1px #DDDDDD solid; background-color:#EFEFEF; }
.wherego td { width:50%; word-wrap:break-word; word-break:break-all; }
.wherego td.whereyou { text-align:right; }
-->
</style>
<script type="text/javascript" language="javaScript" src="../../inc/js/main.js"></script>
</head>
<body>
  <div class="output">
    <img src="../../inc/images/'.$src.'.gif" /> '.$text.'
    
  </div>
</body>
</html>';
  die;
}


function s_rand($l) {
  $rand = '';
  $c = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ-abcdefghijklmnopqrstuvwxyz_0123456789';
  $n = strlen($c) - 1;
  for ($i = 0; $i < $l; $i++) {
    $rand .= $c[mt_rand(0, $n)];
  }
  return $rand;
}

function show_login($username, $bar) {
  return '<script language="javascript" type="text/javascript">
<!--

if(opener){
  var o_index=opener.document.getElementById(\'session\');
  if(o_index!=null){
    o_index.innerHTML=\'<img src="inc/images/'.$bar.'.png" width="16" height="16" /><b>'.$username.'</b> | <a href="member.php">用户中心</a> | <a href="member.php?post=login&act=logout&m=1" onclick="return logoutM(this);">退出</a>\';
  }

    var pl=opener.document.getElementById("location");

    if(pl!=null){
      var goUrl=pl.value.replace(/^http\:\/\/.+\//i, \'\');
      if(goUrl!="" && goUrl!="./" && !goUrl.match(/(login|reg)?\.php/i)){
        opener.location.href=opener.location.href.replace(/[^\/]+$/,"")+goUrl;
      }else{
        opener.location.href=opener.location.href.replace(/[^\/]+$/,"");
      }
    }else{
      opener.location.href=opener.location.href.replace(/[^\/]+$/,"");
    }

}else{
  opener.top.location.href=opener.location.href.replace(/[^\/]+$/,"");
}

setTimeout("try{window.close();}catch(e){}",3000);

-->
</script>';
}

?>
<?php

$date = gmdate("Y-m-d H:i:s", time() + (floatval($web["time_pos"]) * 3600));
$cookie_time = time() + floatval($web['time_pos']) * 3600 + 31536000;

if (!isset($sql['db_err'])) {
  db_conn();
}
if ($sql['db_err'] != '') {
  err($sql['db_err']);
}

$result = @mysql_query('SELECT * FROM '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' WHERE login_key_'.$bar.'="'.$key1.$key2.'" LIMIT 1', $db);
$row = @mysql_fetch_assoc($result);
@mysql_free_result($result);
if (is_array($row) && count($row) > 0) {
  if ($row['check_reg'] == '1') {
    err('您的注册尚未通过审批！无法登陆。');
  }
  if ($row['check_reg'] == '2') {
    err('您的帐户已被管理员移除至<a href="list_member.php?act=punished" target="_blank">黑名单</a>。');
  }
  if ($row['power'] != 'm' && substr($row['thisdate'], 0, 10) != substr($date, 0, 10)) {
    $row_point = 'point=point+'.abs($web['loginadd']).',';
    $row['point'] = $row['point'] + abs($web['loginadd']);
  }

  $you = array(
          'name'  => $row['username'],
	      'key'   => $date.'|'.s_rand(16),
          'point' => $row['point'],
          'power' => $row['power'],
  );
  if (@mysql_query('UPDATE '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' SET '.$row_point.'thisdate="'.$date.'",session_key="'.$you['key'].'" WHERE username="'.$row['username'].'"', $db)) {
    setcookie('usercookie', ''.@implode('|', $you).'|'.$cookie_time.'||'.$web['path'], time() + floatval($web["time_pos"]) * 3600 + 31536000, '/', '.'.$web['root']);
    setcookie('usercookie', ''.@implode('|', $you).'|'.$cookie_time.'||'.$web['path'], time() + floatval($web["time_pos"]) * 3600 + 31536000, '/');
    if ($you['name'] == $web['manager']) {
      @ require ('../../inc/function/write_file.php');
      if (!file_exists('../../__temp__/temp')) {
	    if (!@mkdir('../../__temp__/temp')) {
          err('上载目录../../__temp__/temp不存在或创建失败！请稍候重新登陆再试。');
        }
      }
      write_file('../../__temp__/temp/'.urlencode($you['name']).'.php', '<?php die(); ?>'.$you['key'].''); //登陆密钥记录
    }
  }

        $yougourl = '<table width="100%" border="0" cellspacing="10" cellpadding="0" class="wherego"><tr>';
        if ($you['power'] == 'm') {
          $yougourl .= '<td class="whereyou">您是管理员，您可以选择去向：</td><td align="left"><ul><li><a href="javascript:void(0);" onclick="window.open(\'../../\');window.close();">首页</a></li><li><a href="javascript:void(0);" onclick="window.open(\'../../webmaster_central.php\');window.close();">管理后台</a></li><li><a href="javascript:void(0);" onclick="window.open(\'../../member.php\');window.close();">用户中心</a></li><li><a href="javascript:void(0);" onclick="window.open(\'../../write.php\');window.close();">发布文章</a></li></ul></td>';
        } elseif (preg_match('/^(\(\d+\-\d+\))+$/', $you['power'])) {
          $yougourl .= '<td class="whereyou">您是版主，您可以选择去向：</td><td align="left"><ul><li><a href="javascript:void(0);" onclick="window.open(\'../../\');window.close();">首页</a></li><li><a href="javascript:void(0);" onclick="window.open(\'../../webmaster_central.php\');window.close();">管理后台</a></li><li><a href="javascript:void(0);" onclick="window.open(\'../../member.php\');window.close();">用户中心</a></li><li><a href="javascript:void(0);" onclick="window.open(\'../../write.php\');window.close();">发布文章</a></li></ul></td>';
        } else {
          $yougourl .= '<td class="whereyou">您可以选择去向：</td><td align="left"><ul><li><a href="javascript:void(0);" onclick="window.open(\'../../\');window.close();">首页</a></li><li><a href="javascript:void(0);" onclick="window.open(\'../../member.php\');window.close();">用户中心</a></li><li><a href="javascript:void(0);" onclick="window.open(\'../../write.php\');window.close();">发布文章</a></li></ul></td>';
        }
        $yougourl .= '</tr>
</table>';
        $yougourl .= empty($row['company']) ? '<div class="redword">提示：您还没有添加商号！建议你到用户中心完善</div>' : '';


        err('登陆成功！欢迎您 '.$you['name'].'。'.$yougourl.'。<br />
<span style="color:#CCC">正在关闭此窗口</span>'.show_login($you['name'], '162100'), 'ok');
      




} else {
  setcookie('usercookie', ''.$bar_name.'|'.$date.'||0|||'.$bar.'|'.$web['path'], time() + floatval($web["time_pos"]) * 3600, '/', '.'.$web['root']);
  setcookie('usercookie', ''.$bar_name.'|'.$date.'||0|||'.$bar.'|'.$web['path'], time() + floatval($web["time_pos"]) * 3600, '/');
  err('用<img src="../../inc/images/'.$bar.'.png" width="16" height="16" title="'.$bar.'" />帐号登陆成功！欢迎您：<br /><center><img src="'.$bar_face.'" /> '.$bar_name.'</center><br />
<span style="color:#CCC">正在关闭此窗口</span>'.show_login($bar_name, $bar), 'ok');
}
@mysql_close();

?>