<?php
include("require.php");
if(!isset($_COOKIE["core_user_name"]))
  jump("login.php?action=login&last=user.php");
$phpcolor->table="user";
$phpcolor->field="*";
$phpcolor->where="username = '".$_COOKIE['core_user_name']."'";
$user=$phpcolor->exist(1);
if($_GET['action']=="indext")
{
  submitfilter($_POST['tid']);
  $phpcolor->table="index";
  $phpcolor->where="yid = '".$_POST['tid']."'";
  if($phpcolor->exist(2))
    die("1");
  $phpcolor->table="topic";
  $phpcolor->field="theme";
  $phpcolor->where="id = '".$_POST['tid']."'";
  $rs=$phpcolor->exist(1);
  $phpcolor->table="index";
  $phpcolor->field="type, yid, belong, theme, barname";
  $phpcolor->where="'3','".$_POST['tid']."','1', '".$rs['theme']."', '".$_COOKIE["core_user_name"]."'";
  $phpcolor->write();
  die("2");
}
elseif($_GET['action']=="remindy")
{
  submitfilter($_GET['tid']);
  $phpcolor->table="topic";
  $phpcolor->field="author";
  $phpcolor->where="id = '".$_GET['tid']."'";
  $post=$phpcolor->exist(1);
  if($_COOKIE["core_user_name"]==$post['author'])
  {
    $phpcolor->field="remind='1'";
    $phpcolor->upgrade();
    jump("read.php?id=".$_GET['tid']);
  }
  jump("error.php?id=2");
}
elseif($_GET['action']=="remindn")
{
  submitfilter($_POST['tid']);
  $phpcolor->table="topic";
  $phpcolor->field="author";
  $phpcolor->where="id = '".$_GET['tid']."'";
  $post=$phpcolor->exist(1);
  if($_COOKIE["core_user_name"]==$post['author'])
  {
    $phpcolor->field="remind='0'";
    $phpcolor->upgrade();
    jump("read.php?id=".$_GET['tid']);
  }
  jump("error.php?id=2");
}
elseif($_GET['action']=="basicsubmit")
{
  if(md5(md5($_POST['passwd']).$core_scode) != $_COOKIE["core_user_passwd"])
    die("3");
  if(strlen($_POST['signature']) > $core_signlong)
    die("1");
  $_POST['signature']=autolink(iconv("UTF-8", "gbk", $_POST['signature']));
  $_POST['introduction']=autolink(nl2br(iconv("UTF-8", "gbk", $_POST['introduction'])));
  $_POST['userfrom']=bn_replace(iconv("UTF-8", "gbk", $_POST['userfrom']));
  $_POST['age']=bn_replace(iconv("UTF-8", "gbk", $_POST['age']));
  $_POST['sex']=bn_replace(iconv("UTF-8", "gbk", $_POST['sex']));
  $_POST['birthday']=bn_replace(iconv("UTF-8", "gbk", $_POST['birthday']));
  $_POST['blood']=bn_replace(iconv("UTF-8", "gbk", $_POST['blood']));
  $_POST['zodiac']=bn_replace(iconv("UTF-8", "gbk", $_POST['zodiac']));
  $_POST['constellation']=bn_replace(iconv("UTF-8", "gbk", $_POST['constellation']));
  $_POST['school']=bn_replace(iconv("UTF-8", "gbk", $_POST['school']));
  $_POST['profession']=bn_replace(iconv("UTF-8", "gbk", $_POST['profession']));
  $_POST['qq']=bn_replace(iconv("UTF-8", "gbk", $_POST['qq']));
  $_POST['mobile']=bn_replace(iconv("UTF-8", "gbk", $_POST['mobile']));
  $_POST['phone']=bn_replace(iconv("UTF-8", "gbk", $_POST['phone']));
  $phpcolor->field="userfrom = '".$_POST['userfrom']."',age = '".$_POST['age']."',sex = '".$_POST['sex']."',birthday = '".$_POST['birthday']."',blood = '".$_POST['blood']."',zodiac = '".$_POST['zodiac']."',constellation = '".$_POST['constellation']."',school = '".$_POST['school']."',profession = '".$_POST['profession']."',qq = '".$_POST['qq']."',mobile = '".$_POST['mobile']."',phone = '".$_POST['phone']."',signature = '".$_POST['signature']."',introduction = '".$_POST['introduction']."',userfriendp = '".$_POST['userfriendp']."',istyle = '".$_POST['istyle']."'";
  $phpcolor->upgrade();
  die("2");
}
elseif($_GET['action']=="safetysubmit")
{
  if($_POST['new_email']=="")
    $_POST['new_email']=$user["email"];
  if($_POST['new_question']=="")
    $_POST['new_question']=$user["question"];
  if($_POST['new_answer']=="")
    $_POST['new_answer']=$user["answer"];
  if($_POST['new_passwd']=="")
  {
    $_POST['new_passwd']=$_POST['passwd'];
    $_POST['new_passwdy']=$_POST['passwd'];
  }
  if(md5(md5($_POST['passwd']).$core_scode) != $_COOKIE["core_user_passwd"])
    die("6");
  if($_POST['email'] != $user["email"] or $_POST['answer'] != $user["answer"])
    die("1"); 
  if(strlen($_POST['new_passwd'])<$core_pwdshort or strlen($_POST['new_passwd'])>$core_pwdlong)
    die("2");
  if($_POST['new_passwd']!= $_POST['new_passwdy'])
    die("3");
  if(!ereg("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$_POST['new_email']))
    die("4");
  $new_passwd = md5($_POST['new_passwd']);
  $phpcolor->field="email = '".$_POST['new_email']."',question = '".$_POST['new_question']."',answer = '".$_POST['new_answer']."',passwd='".$new_passwd."'";
  $phpcolor->upgrade();
  die("5");
}
elseif($_GET['action']=="applyok")
{
  submitfilter($_GET['id']);
  $phpcolor->table="apply_user";
  $phpcolor->where="id = '".$_GET['id']."'";
  $friendsapply=$phpcolor->exist(1);
  $phpcolor->delete();
  $phpcolor->table="user";
  $phpcolor->field="id";
  $phpcolor->where="username = '".$friendsapply['username']."'";
  $aid=$phpcolor->exist(1);
  $phpcolor->where="username = '".$friendsapply['object']."'";
  $bid=$phpcolor->exist(1);
  $phpcolor->table="user_friends";
  $phpcolor->field="uid, did";
  $phpcolor->where="'".$aid['id']."','".$bid['id']."'";
  $phpcolor->write();
  $phpcolor->table="user_friends";
  $phpcolor->field="uid, did";
  $phpcolor->where="'".$bid['id']."','".$aid['id']."'";
  $phpcolor->write();
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
  $neirong=$friendsapply['object']."已接受您的好友申请。";
  $phpcolor->message($neirong,$email_addresser,$friendsapply['username'],$time,2);
  jump("user.php?action=friendsapply");
}
elseif($_GET['action']=="applyno")
{
  submitfilter($_GET['id']);
  $phpcolor->table="apply_user";
  $phpcolor->where="id = '".$_GET['id']."'";
  $friendsapply=$phpcolor->exist(1);
  $phpcolor->delete();
  $neirong=$friendsapply['object']."拒绝了您的好友申请。";
  $phpcolor->message($neirong,$email_addresser,$friendsapply['username'],$time,2);
  jump("user.php?action=friendsapply");
}
elseif($_GET['action']=="friendsdel" && isset($_GET['id']))
{
  submitfilter($_GET['id']);
  $phpcolor->table="user_friends";
  $phpcolor->field="*";
  $phpcolor->where="id = '".$_GET['id']."'";
  $rs=$phpcolor->exist(1);
  $phpcolor->delete();
  $phpcolor->where="uid = '".$rs['did']."' and did = '".$rs['uid']."'";
  $phpcolor->delete();
  jump("user.php?action=friends");
}
elseif($_GET['action']=="postfavorite")
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->table="user_postfavorite";
  $phpcolor->field="*";
  $phpcolor->where="uid = '".$user['id']."'";
  $count=$phpcolor->exist(2);
  $page=pages($count,15,$_GET['page'],'user','&action=','postfavorite','0');
  $phpcolor->where="uid = '".$user['id']."' limit ".($_GET['page']*15).",15";
  $postfavorite=$phpcolor->assignment();
  for ($count=0;$count<count($postfavorite);$count++)       
  {
    $phpcolor->table="topic";
    $phpcolor->field="theme";
    $phpcolor->where="id='".$postfavorite[$count]['pid']."'";
    $topic=$phpcolor->exist(1);
    $postfavorite[$count]['theme'] = $topic['theme'];
  }
  $tpl -> assign("postfavorite", $postfavorite); 
  $tpl -> assign("page", $page);
  $tpl -> assign("core_header_title", "我收藏的主题 - ");
}
elseif($_GET['action']=="postfavoriteadd")
{
  submitfilter($_GET['id']);
  $phpcolor->table="user_postfavorite";
  $phpcolor->field="*";
  $phpcolor->where="uid = '".$user['id']."' and pid = '".$_GET['id']."'";
  $barfavorite=$phpcolor->exist(1);
  if(isset($barfavorite['id']))
    jump("error.php?id=20&last=read.php?id=".$_GET['id']);
  $phpcolor->field="pid, uid";
  $phpcolor->where="'".$_GET['id']."','".$user['id']."'";
  $phpcolor->write();
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
  $phpcolor->newswrite($_GET['id'],$time,$user['id'],8);
  jump("read.php?id=".$_GET['id']);
}
elseif($_GET['action']=="postfavoritedel")
{
  submitfilter($_GET['id']);
  $phpcolor->table="user_postfavorite";
  $phpcolor->field="*";
  $phpcolor->where="id = '".$_GET['id']."'";
  $postfavorite=$phpcolor->exist(1);
  if($postfavorite['uid'] == $user['id'])
  {
    $phpcolor->delete();
    jump("user.php?action=postfavorite");
  }
  jump("error.php?id=2");
}
elseif($_GET['action']=="heads" && isset($_GET['fs']))
{
  if($_GET['fs']==1)
    $head=$core_url."images/head/".$_POST['head'];
  elseif($_GET['fs']==2)
    $head=bn_replace($_POST['head']);
  elseif($_GET['fs']==3)
  {
    $oldname=$_FILES["file"]["name"];
    $fileextensionname=strtolower(eregi_replace(".+(\..+)","\\1",$oldname));
    $filename = $user["id"].$fileextensionname;
    if(!preg_match( '/^image\//i ',$_FILES["file"]["type"]) || ($_FILES["file"]["size"]/1024)>2048)
      jump("error.php?id=16");
	if(file_exists("upload/head/".$filename))
      unlink("upload/head/".$filename);
	move_uploaded_file($_FILES["file"]["tmp_name"],"upload/head/".$filename);
    $head=$core_url."upload/head/".$filename;
  }
  $phpcolor->table="user";
  $phpcolor->field="picture='".$head."'";
  $phpcolor->where="id = '".$user['id']."'";
  $phpcolor->upgrade();
  jump("user.php?action=basic");
}
elseif($_GET['action']=="qiandao")
{
  $phpcolor->table="qiandao";
  $yztime=date('Y-m-d',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
  $phpcolor->where="published like '%".$yztime."%' and belong='".$userv['id']."' and type='1'";
  $pd=$phpcolor->exist(2);
  if($_POST['qdtb']=="" or $_POST['qdss']=="" or $pd)
    die("3");
  if(strlen($_POST['qdss'])>280)
    die("2");
  $_POST['qdss']=iconv("UTF-8", "gbk", $_POST['qdss']);
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
  $phpcolor->field="biaoqing,content,published,belong,type";
  $phpcolor->where="'".$_POST['qdtb']."','".$_POST['qdss']."','".$time."','".$user['id']."','1'";
  $phpcolor->write();
  $rsid=mysql_insert_id();
  $phpcolor->newswrite($rsid,$time,$userv['id'],3);
  if($int_uqd>0)
    $phpcolor->upintegral($_COOKIE["core_user_name"],"",$int_uqd,17,$time);
  die("1");
}
elseif ($_GET['action']=="cvmtoi")
{
  submitfilter($_POST['cvmoney']);
  if($user['money']<$_POST['cvmoney'])
    die("1");
  if($int_cvio=="0")
    jump("index.php");
  $phpcolor->table="pay";
  $tradeno=(strtotime(date('Y-m-d H:i:s'))+$core_time*3600).rand(1000,9999);
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
  $phpcolor->field="sid ,username, money, status, type, operatetime, ip";
  $phpcolor->where="'".$tradeno."','".$user['username']."','".$_POST['money']."','0','5','".$time."','".$_SERVER['REMOTE_ADDR']."'";
  $phpcolor->write();
  $phpcolor->table="user";
  $phpcolor->field="money=money-".$_POST['cvmoney'];
  $phpcolor->where="username = '".$user['username']."'";
  $phpcolor->upgrade();
  $int=floor($_POST['cvmoney']/$int_cvim*$int_cvii);
  $phpcolor->upintegral($user["username"],"",$int,16,$time);
  die("2");
}
elseif ($_GET['action']=="cvitom")
{
  submitfilter($_POST['cvint']);
  if($user['integral']<$_POST['cvint'])
    die("1");
  if($int_cvmo=="0")
    jump("index.php");
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
  $phpcolor->upintegral($user["username"],"",$_POST['cvint'],2,$time);
  $phpcolor->table="pay";
  $money=floor($_POST['cvint']/$int_cvmi*$int_cvmm);
  $tradeno=(strtotime(date('Y-m-d H:i:s'))+$core_time*3600).rand(1000,9999);
  $phpcolor->field="sid ,username, money, status, type, operatetime, ip";
  $phpcolor->where="'".$tradeno."','".$user['username']."','".$money."','0','4','".$time."','".$_SERVER['REMOTE_ADDR']."'";
  $phpcolor->write();
  $phpcolor->table="user";
  $phpcolor->field="money=money+".$money;
  $phpcolor->where="username = '".$user['username']."'";
  $phpcolor->upgrade();
  die("2");
}
elseif ($_GET['action']=="safety")
{
  $tpl -> assign("question", $user["question"]);
  $tpl -> assign("core_header_title", "安全信息修改 - ");
}
elseif ($_GET['action']=="friendsapply")
{
  $phpcolor->table="apply_user";
  $phpcolor->field="*";
  $phpcolor->where="object = '".$user['username']."' and type = '2'";
  $friendsapply=$phpcolor->assignment();
  $tpl -> assign("friendsapply", $friendsapply);
  $tpl -> assign("core_header_title", "好友申请管理 - ");
}
elseif ($_GET['action']=="integral")
{
  $phpcolor->table="integral_log";
  $phpcolor->field="*";
  $phpcolor->where="username = '".$user['username']."'";
  $count = $phpcolor->exist(2);
  $phpcolor->where="username = '".$user['username']."' order by operatetime desc";
  $integral=$phpcolor->assignment();
  $page=pages($count,15,$_GET['page'],'user','&action=integral&id=',$_GET['id'],0);
  for($count=0;$count<count($integral);$count++)
  {
    $integrals[$count]=$phpcolor->integralso($integral[$count]['type'],$integral[$count]['integral'],$integral[$count]['objects']);
	$integral[$count]['type']=$integrals[$count]['type'];
	$integral[$count]['integral']=$integrals[$count]['integral'];
  }
  $tpl -> assign("integral", $integral);
  $tpl -> assign("page", $page);
  $tpl -> assign("core_header_title", "积分管理 - ");
}
elseif ($_GET['action']=="friends")
{
  $phpcolor->table="user_friends";
  $phpcolor->field="*";
  $phpcolor->where="uid = '".$user['id']."'";
  $friends=$phpcolor->assignment();
  $phpcolor->table="user";
  $phpcolor->field="username";
  for ($count=0;$count<count($friends);$count++)
  {
    $phpcolor->where="id = '".$friends[$count]['did']."'";
    $rs=$phpcolor->exist(1);
    $friends[$count]['username']=$rs['username'];
  }
  $tpl -> assign("friends", $friends);
  $tpl -> assign("core_header_title", "好友管理 - ");
}
elseif ($_GET['action']=="head")
{
  $handler = opendir('images/head');
  while( ($facename = readdir($handler)) !== false ) 
  {
    if($facename!="." && $facename!="..")
      $head[]=$facename;
  }
  closedir($handler);
  $tpl -> assign("core_userheadup", $core_userheadup);
  $tpl -> assign("head", $head);
  $tpl -> assign("core_header_title", "修改头像 - ");
}
elseif ($_GET['action']=="convert")
{
  $tpl -> assign("int_uqd", $int_uqd);
  $tpl -> assign("int_cvio", $int_cvio);
  $tpl -> assign("int_cvim", $int_cvim);
  $tpl -> assign("int_cvii", $int_cvii);
  $tpl -> assign("int_cvmo", $int_cvmo);
  $tpl -> assign("int_cvmm", $int_cvmm);
  $tpl -> assign("int_cvmi", $int_cvmi);
  $tpl -> assign("int_udl", $int_udl);
  $tpl -> assign("int_ufb", $int_ufb);
  $tpl -> assign("int_ufbt", $int_ufbt);
  $tpl -> assign("int_ufbh", $int_ufbh);
  $tpl -> assign("int_ufbf", $int_ufbf);
  $tpl -> assign("int_utjzy", $int_utjzy);
  $tpl -> assign("int_uspreadf", $int_uspreadf);
  $tpl -> assign("int_uspreadfr", $int_uspreadfr);
  $tpl -> assign("core_header_title", "积分兑换 - ");
}
else
{
  $phpcolor->table="attest";
  $phpcolor->where="uid='".$user['id']."' and type='1'";
  $user['userv']="0";
  if($rs=$phpcolor->exist(1))
  {
    $user['userv']="1";
    $user['uservxx']=$rs['attest'];
  }
  $user['signature'] = str_replace("&lt;br /&gt;","",$user['signature']);
  $user['introduction'] = str_replace("&lt;br /&gt;","",$user['introduction']);
  $tpl -> assign("core_header_title", "基本资料修改 - ");
}
$tpl -> assign("user", $user);
$tpl -> assign("action", $_GET['action']);
$tpl -> display("$core_style/user.htm");
?>