 <?php
 define('EmpireCMSAdmin','1');
 $action=$_GET[action];
 require ('../e/class/connect.php');
 require ('../e/class/db_sql.php');
 require ('../e/class/functions.php');
 $link=db_connect();
 $empire=new mysqlquery; 
 $add=$_POST;
 $editor='92';
if($action=='save'){
$lur=is_login();

 if($_POST[id]){
 		 $query="update {$dbtbpre}movie_gbook set username='$add[username]',lianxiqq='$add[lianxiqq]',headimg='$add[headimg]',userip='$add[userip]',text='$add[text]',retext='$add[retext]',checked='$add[checked]' where id='$add[id]'";
  }
 else{
   $newstime=time();
   $userip=egetip();
   $query="insert into {$dbtbpre}movie_gbook(username,userip,newstime,headimg,text,retext,checked,lianxiqq) values ('$add[username]','$userip','$newstime','$add[headimg]','$add[text]','$add[retext]','0','$add[lianxiqq]');";

 
  
  
 } $up=$empire->query($query);
   if($up) { printerror2("提交成功!",'gbooklist.php'); } else { printerror2("提交失败!",'gbooklist.php'); }
 
} 


if($action=='useradd'){
	$add[username]=RepPostVar2(trim($add[username]));
	$add[text]=RepPostVar2(trim($add[text]));
	$add[headimg]=(int)(trim($add[headimg]));
	
	
	$add[username]=$add[username]?$add[username]:'匿名';
	$add[username]=unescape($add[username]);
	$add[text]=unescape($add[text]);
	
	$userip=egetip();
	$newstime=time();
	if($add[text]==''){
	echo '2';
	}
	$add[text]=strip_tags($add[text]);
	$add[username]=strip_tags($add[username]);
	$add[lianxiqq]=strip_tags($add[lianxiqq]);
  $query="insert into {$dbtbpre}movie_gbook(username,userip,newstime,headimg,text,checked,lianxiqq) values ('$add[username]','$userip','$newstime','$add[headimg]','$add[text]','0','$add[lianxiqq]');";
     $up=$empire->query($query);
	 if($up){
		 echo '1';
	 }
	 else echo '4';



}



if($action=='del'){

$lur=is_login();
$query="delete from {$dbtbpre}movie_gbook where id='$_GET[id]'";
     $up=$empire->query($query);
   if($up) { printerror2("删除成功!",'gbooklist.php'); } else { printerror2("删除失败!",'gbooklist.php'); }


}
 $empire=NULL;
 db_close();

function unescape($str) {
  $str = rawurldecode($str);
  preg_match_all("/(?:%u.{4})|&#x.{4};|&#\d+;|.+/U",$str,$r);
  $ar = $r[0];

  foreach($ar as $k=>$v) {
    if(substr($v,0,2) == '%u'){
      $ar[$k] = iconv("UCS-2","gbk",pack("H4",substr($v,-4)));
	  if($ar[$k]=='')
	  {
		  $ar[$k]=substr($v,-6);
	  }
	}
    elseif(substr($v,0,3) == "&#x")
      $ar[$k] = iconv("UCS-2","gbk",pack("H4",substr($v,3,-1)));
    elseif(substr($v,0,2) == "&#") {
      $ar[$k] = iconv("UCS-2","gbk",pack("n",substr($v,2,-1)));
    }
  }
  return join("",$ar);
}
?>