<?php
include("require.php");
if(!isset($_GET['id']) and !isset($_GET['un']) and !isset($_COOKIE['core_user_name']))
  Header("Location: login.php?action=login&last=index.php");
else
{
  if(!isset($_GET['id']) and !isset($_GET['un']))
    $_GET['id']=$userv['id'];
  $phpcolor->table=$core_mysql_prefix."user";
  $phpcolor->field="*";
  if(isset($_GET['id']))
  {
    submitfilter(1,$_GET['id']);
    $phpcolor->where="id = '".$_GET['id']."'";
  }
  else
  {
    $_GET['un']=submitfilter(2,$_GET['un']);
    $phpcolor->where="username = '".$_GET['un']."'";
  }
  if(!$user=$phpcolor->exist(1))
    Header("Location: error.php?id=13");
  elseif($_GET['action']=="applysubmit")
  {
    $phpcolor->table=$core_mysql_prefix."apply_user";
	$phpcolor->field="*";
    $phpcolor->where="username='".$_COOKIE['core_user_name']."' and object='".$_GET['un']."' and type='2'";
	$_POST['reason']=submitfilter(2,$_POST['reason']);
	$_GET['un']=submitfilter(2,$_GET['un']);
    if(!isset($_COOKIE["core_user_name"]) || $_COOKIE["core_user_name"]==$_GET['un'])
	  Header("Location: ../index.php");
	elseif($phpcolor->exist(2))
	  Header("Location: ../error.php?id=9&last=index.php"); 
	else
	{
	  $phpcolor->table=$core_mysql_prefix."user";
	  $phpcolor->field="id";
	  $phpcolor->where="username = '".$_GET['un']."'";
	  $rs=$phpcolor->exist(1);
	  $phpcolor->table=$core_mysql_prefix."user_friends";
      $phpcolor->field="*";
      $phpcolor->where="uid = '".$userv['id']."' and did = '".$rs['id']."'";
	  if($phpcolor->exist(2))
	  {
	    Header("Location: ../error.php?id=14&last=info.php?id=".$rs['id']); 
		exit();
	  }
	  $phpcolor->table=$core_mysql_prefix."apply_user";
	  $phpcolor->field="username, object, why, type";
      $phpcolor->where="'".$_COOKIE["core_user_name"]."', '".$_GET['un']."', '".$_POST['reason']."', '2'";
      $phpcolor->write();
	  Header("Location: info.php?un=".$_GET['un']);
	}
  }
  else
  {
    $phpcolor->table=$core_mysql_prefix."user_friends";
    $phpcolor->field="did";
    $phpcolor->where="uid = '".$user['id']."' limit 8";
    $friends=$phpcolor->assignment();
	$phpcolor->table=$core_mysql_prefix."user";
    for($count=0;$count<count($friends);$count++)
    {
      $phpcolor->field="username,picture";
	  $phpcolor->where="id = '".$friends[$count]['did']."'";
	  $rs=$phpcolor->exist(1);
      $friends[$count]['username']=$rs['username'];
	  $friends[$count]['picture']=$rs['picture'];
    }
    $user['introduction']=in_replace(str_replace("&lt;br /&gt;","<br />",$user['introduction']));
    $user['signature'] = str_replace("&lt;br /&gt;","<br />",$user['signature']);
	$phpcolor->table=$core_mysql_prefix."topic";
    $phpcolor->field="id,theme,belong";
    $phpcolor->where="author = '".$user['username']."' and state!='0' and state != '3' order by published desc limit 0,10";
    $post=$phpcolor->assignment();
    $tpl -> assign("core_header_title", $user['username']."的个人信息 - ");
    $tpl -> assign("post", $post);
    $tpl -> assign("user", $user);
    $tpl -> assign("friends", $friends);
	$tpl -> assign("action", $_GET['action']);
    $tpl -> display("$core_style/info.htm");
  }
}
?>