<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[29]!=1)
{
  Header("Location: jump.php?id=25&jump=main.php");
  exit();
}
$phpcolor->table=$core_mysql_prefix."ad";
$phpcolor->where="id = '".$_GET['id']."'";
if(isset($_GET['action']) and $_GET['action'] == "del" and isset($_GET['id']))
{
  $phpcolor->delete();
  Header("Location: jump.php?id=24&jump=ad.php");
}
elseif(isset($_GET['action']) and $_GET['action'] == "adddo")
{
  if($_POST['name']=="")
    Header("Location: jump.php?id=2&jump=ad.php?action=add");
  else
  {
    $phpcolor->field="name, site, type, theme, picture, link, code";
    $phpcolor->where="'".$_POST['name']."', '".$_POST['site']."', '".$_POST['type']."', '".$_POST['theme']."', '".$_POST['picture']."', '".$_POST['link']."', '".$_POST['code']."'";
    $phpcolor->write();
    Header("Location: jump.php?id=24&jump=ad.php");
  }
}
elseif(isset($_GET['action']) and $_GET['action'] == "editdo" and isset($_GET['id']))
{
  if($_POST['name']=="")
    Header("Location: jump.php?id=2&jump=ad.php?action=edit=and=id=".$_GET['id']);
  else
  {
    $phpcolor->field="name='".$_POST['name']."',site='".$_POST['site']."',type='".$_POST['type']."',theme='".$_POST['theme']."',picture='".$_POST['picture']."',link='".$_POST['link']."',code='".$_POST['code']."'";
    $phpcolor->upgrade();
    Header("Location: jump.php?id=24&jump=ad.php");
  }
}
elseif(isset($_GET['action']) and $_GET['action'] == "add")
  $tpl -> display("ad_add.htm");
elseif(isset($_GET['action']) and $_GET['action'] == "edit" and isset($_GET['id']))
{
  $phpcolor->field="*";
  $ad=$phpcolor->exist(1);
  $tpl -> assign("ad", $ad);
  $tpl -> display("ad_edit.htm");
}
else
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->field="id,name,site,type";
  $phpcolor->where="1=1";
  $count = $phpcolor->exist(2);
  $phpcolor->where="1=1 limit ".($_GET['page']*20).",20";
  $ad=$phpcolor->assignment();
  $page=pages($count,20,$_GET['page'],'ad','','','0');
  for($count=0;$count<count($ad);$count++)
  {
    if($ad[$count]['site']==1)
      $ad[$count]['site']="头部横幅广告";
    elseif($ad[$count]['site']==2)
      $ad[$count]['site']="底部横幅广告";
    elseif($ad[$count]['site']==3)
      $ad[$count]['site']="首页横幅广告";
    elseif($ad[$count]['site']==4)
      $ad[$count]['site']="首页右侧广告";
	elseif($ad[$count]['site']==5)
      $ad[$count]['site']="贴子一楼右侧广告";
	elseif($ad[$count]['site']==6)
      $ad[$count]['site']="贴吧顶部广告";
	elseif($ad[$count]['site']==7)
      $ad[$count]['site']="贴吧右侧广告";
	elseif($ad[$count]['site']==8)
      $ad[$count]['site']="贴子右侧广告";
	elseif($ad[$count]['site']==9)
      $ad[$count]['site']="贴子顶部广告";
    if($ad[$count]['type']==1)
      $ad[$count]['type']="图片广告";
    elseif($ad[$count]['type']==2)
      $ad[$count]['type']="文字广告";
    else
      $ad[$count]['type']="代码广告";
  }
  $tpl -> assign("ad", $ad);
  $tpl -> assign("page", $page);
  $tpl -> display("ad.htm");
}
?>