<?php
include("require.php");
if(!isset($_COOKIE['core_user_name']) or !isset($_GET['action']))
  jump("index.php");
if($_GET['action']=="xinqingfabu")
{
  $phpcolor->table="qiandao";
  if($_POST['content']=="")
    die("0");
  if(strlen($_POST['content'])>280)
    die("2");
  $_POST['content']=iconv("UTF-8", "gbk", $_POST['content']);
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*60*60);
  $phpcolor->field="biaoqing,content,published,belong,type";
  $phpcolor->where="'0','".$_POST['content']."','".$time."','".$userv['id']."','2'";
  $phpcolor->write();
  $rsid=mysql_insert_id();
  $phpcolor->newswrite($rsid,$time,$userv['id'],3);
  die("1");
}
if($_GET['action']=="applysubmit")
{
  $phpcolor->table="apply_user";
  $phpcolor->field="*";
  $phpcolor->where="username='".$_COOKIE['core_user_name']."' and object='".$_GET['un']."' and type='2'";
  if(!isset($_COOKIE["core_user_name"]) || $_COOKIE["core_user_name"]==$_GET['un'])
    jump("index.php");
  if($phpcolor->exist(2))
    jump("error.php?id=9&last=index.php"); 
  $phpcolor->table="user";
  $phpcolor->field="id";
  $phpcolor->where="username = '".$_GET['un']."'";
  $rs=$phpcolor->exist(1);
  $phpcolor->table="user_friends";
  $phpcolor->field="*";
  $phpcolor->where="uid = '".$userv['id']."' and did = '".$rs['id']."'";
  if($phpcolor->exist(2))
    jump("error.php?id=14&last=space.php?pages=info&id=".$rs['id']); 
  $phpcolor->table="apply_user";
  $phpcolor->field="username, object, why, type";
  $phpcolor->where="'".$_COOKIE["core_user_name"]."', '".$_GET['un']."', '".$_POST['reason']."', '2'";
  $phpcolor->write();
  jump("space.php?un=".$_GET['un']);
}
if($_GET['action']=="ycdt")
{
  submitfilter($_GET['id']);
  $phpcolor->table="new";
  $phpcolor->field="belong";
  $phpcolor->where="id = '".$_GET['id']."'";
  $rs = $phpcolor->exist(1);
  if($rs['belong']!=$userv["id"])
    jump("index.php");
  $phpcolor->field="ishide = '1'";
  $phpcolor->upgrade();
  jump("space.php");
}
if($_GET['action']=="xsdt")
{
  submitfilter($_GET['id']);
  $phpcolor->table="new";
  $phpcolor->field="belong";
  $phpcolor->where="id = '".$_GET['id']."'";
  $rs = $phpcolor->exist(1);
  if($rs['belong']!=$userv["id"])
    jump("index.php");
  $phpcolor->field="ishide = '0'";
  $phpcolor->upgrade();
  jump("space.php");
}
if($_GET['action']=="xinqingdel")
{
  submitfilter($_GET['id']);
  $phpcolor->table="qiandao";
  $phpcolor->field="belong";
  $phpcolor->where="id = '".$_GET['id']."'";
  $rs = $phpcolor->exist(1);
  if($rs['belong']!=$userv["id"])
    jump("index.php");
  $phpcolor->delete();
  jump("space.php?pages=mood");
}
if($_GET['action']=="addalbum")
{
  if($_POST['name']=="")
    jump("error.php?id=1&last=space.php?pages=album=and=action=addalbum");
  $phpcolor->table="album";
  $phpcolor->field="name, introduction, belong, type, passwd";
  $phpcolor->where="'".$_POST['name']."', '".$_POST['introduction']."', '".$userv["id"]."', '".$_POST['type']."', '".$_POST['passwd']."'";
  $phpcolor->write();
  jump("space.php?pages=album");
}
if($_GET['action']=="editalbumdo")
{
  submitfilter($_GET['aid']);
  $phpcolor->table="album";
  $phpcolor->field="belong";
  $phpcolor->where="id = '".$_GET['aid']."'";
  $rs = $phpcolor->exist(1);
  if($rs['belong']!=$userv["id"])
    jump("error.php?id=2");
  if($_POST['name']=="")
    jump("error.php?id=1&last=space.php?pages=album");
  $phpcolor->field="name = '".$_POST['name']."',introduction = '".$_POST['introduction']."',type = '".$_POST['type']."',passwd = '".$_POST['passwd']."'";
  $phpcolor->upgrade();
  jump("space.php?pages=album");
}
if($_GET['action']=="delalbum")
{
  submitfilter($_GET['aid']);
  $phpcolor->table="album";
  $phpcolor->field="belong";
  $phpcolor->where="id = '".$_GET['aid']."'";
  $rs = $phpcolor->exist(1);
  if($rs['belong']==$userv["id"])
  {
    $phpcolor->delete();
    $phpcolor->table="picture";
    $phpcolor->where="belong = '".$_GET['aid']."'";
    $phpcolor->delete();
    if(is_dir("upload/album/".$userv["id"]."/".$_GET['aid']))
    {
      $handle = openDir("upload/album/".$userv["id"]."/".$_GET['aid']);
      while(($file_name = readdir($handle))!==false)
      {
        if($file_name!="." && $file_name!="..")
	    {
          $file_path = "upload/album/".$userv["id"]."/".$_GET['aid']."/".$file_name;
          unlink($file_path);
        }
      }
      closedir($handle);
      rmdir("upload/album/".$userv["id"]."/".$_GET['aid']);
	}
    jump("space.php?pages=album");
  }
  jump("error.php?id=2");
}
if($_GET['action']=="editpicdo")
{
  submitfilter($_GET['pid']);
  $phpcolor->table="picture";
  $phpcolor->field="uid,belong";
  $phpcolor->where="id = '".$_GET['pid']."'";
  $rs = $phpcolor->exist(1);
  if($rs['uid']!=$userv["id"])
    jump("error.php?id=2");
  if($_POST['name']=="")
    jump("error.php?id=1&last=space.php?pages=album=and=pid=".$_GET['pid']."=and=action=editpic");
  $phpcolor->field="name = '".$_POST['name']."',introduction = '".$_POST['introduction']."'";
  $phpcolor->upgrade();
  jump("space.php?pages=album&aid=".$rs['belong']."&action=albumpic");
}
if($_GET['action']=="delpic")
{
  submitfilter($_GET['pid']);
  $phpcolor->table="picture";
  $phpcolor->field="uid,belong";
  $phpcolor->where="id = '".$_GET['pid']."'";
  $rs = $phpcolor->exist(1);
  if($rs['uid']==$userv["id"])
  {
    $phpcolor->delete();
    if(is_dir("upload/album/".$userv["id"]."/".$rs['belong']))
    {
      $file_path = "upload/album/".$userv["id"]."/".$rs['belong']."/".$file_name;
      unlink($file_path);
    }
    jump("space.php?pages=album&aid=".$rs['belong']."&action=albumpic");
  }
  jump("error.php?id=2");
}
if($_GET['action']=="attest")
{
  if($_POST['attest']=="" or $_POST['info']=="")
    jump("error.php?id=1&last=space.php?pages=info");
  if(strlen($_POST['attest'])>200 or strlen($_POST['info'])>20000)
    jump("error.php?id=17&last=space.php?pages=info");
  $phpcolor->table="attest";
  $phpcolor->field="*";
  $phpcolor->where="uid = '".$userv['id']."'";
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*60*60);
  $_POST['attest']=bn_replace($_POST['attest']);
  if($phpcolor->exist(2))
  {
    $phpcolor->field="attest = '".$_POST['attest']."',info = '".$_POST['info']."',time = '".$time."',type = '0'";
    $phpcolor->upgrade();
    jump("space.php?pages=info");
  }
  $phpcolor->field="uid, attest, info, time, type";
  $phpcolor->where="'".$userv['id']."','".$_POST['attest']."','".$_POST['info']."','".$time."','0'";
  $phpcolor->write();
  jump("space.php?pages=info");
}
if($_GET['action']=="attestyes")
{
  $phpcolor->table="attest";
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*60*60);
  $phpcolor->field="time = '".$time."',type = '0'";
  $phpcolor->where="uid = '".$userv['id']."'";
  $phpcolor->upgrade();
  jump("space.php?pages=info");
}
if($_GET['action']=="attestno")
{
  $phpcolor->table="attest";
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*60*60);
  $phpcolor->field="time = '".$time."',type = '2'";
  $phpcolor->where="uid = '".$userv['id']."'";
  $phpcolor->upgrade();
  jump("space.php?pages=info");
}
?>