<?php
include("require.php");
if(!isset($_GET['barname']) && !isset($_POST['barname']))
  Header("Location: index.php");
else
{
  if(!isset($_GET['barname']))
    $_GET['barname']=$_POST['barname'];
  $_GET['barname']=submitfilter(2,$_GET['barname']);
  $phpcolor->table=$core_mysql_prefix."bar";
  $phpcolor->field="*";
  $phpcolor->where="barname = '".$_GET['barname']."'";
  if($barid=$phpcolor->exist(1))
  {
    if($core_rewrite=="1")
	  Header("Location: list-".$barid['id']."-0.html");
	else
	  Header("Location: list.php?bid=".$barid['id']);
  }
  elseif($core_createopen==0)
    Header("Location: error.php?id=3");
  elseif($core_createopen==1 && !isset($_COOKIE["core_user_name"]))
    Header("Location: login.php?action=login&last=".$last);
  elseif(isset($_GET['action']) and $_GET['action'] == "submit")
  {
    if($_POST['present']=="" or $_POST['barname']=="")
      die("0");
	elseif($core_verifyopen==1 && $_POST['verify'] != $_SESSION['auth'])
	  die("1");
    else
    {
	  if($core_createaudit==1)
	    $state=2;
	  else
	    $state=1;
	  $_POST['barname']=bn_replace($_POST['barname']);
	  $_POST['present']=html_replace(autolink($_POST['present']));
      $phpcolor->field="barname, introduction, usernc, state";
      $phpcolor->where="'".$_POST['barname']."', '".$_POST['present']."', '会员', '".$state."'";
      $phpcolor->write();
	  die("2");
    }
  }
  else
  {
    $_GET['barname']=bn_replace($_GET['barname']);
    $tpl -> assign("core_verifyopen", $core_verifyopen);
    $tpl -> assign("barname", $_GET['barname']);
    $tpl -> assign("core_header_title", "创建贴吧 - ");
    $tpl -> display("$core_style/create.htm");
  }
}
?>