<?php
include(dirname(__FILE__)."/require.php");
if($ppurview[29]!=1)
  jump("jump.php?id=25&jump=main.php");
$phpcolor->table="ad";
$phpcolor->where="id = '".$_GET['id']."'";
if(isset($_GET['action']) and $_GET['action'] == "del" and isset($_GET['id']))
{
  $phpcolor->delete();
  jump("jump.php?id=24&jump=ad.php");
}
if(isset($_GET['action']) and $_GET['action'] == "adddo")
{
  if($_POST['name']=="")
    jump("jump.php?id=2&jump=ad.php?action=add");
  $_POST['code']=html_replacef($_POST['code']);
  $_POST['code']=str_replace('"','*h*',$_POST['code']);
  $_POST['code']=str_replace("'",'*d*',$_POST['code']);
  $phpcolor->field="name, site, ranges, rid, pid, code";
  $phpcolor->where="'".$_POST['name']."', '".$_POST['site']."', '".$_POST['ranges']."', '".$_POST['rid']."', '".$_POST['pid']."', '".$_POST['code']."'";
  $phpcolor->write();
  jump("jump.php?id=24&jump=ad.php");
}
if(isset($_GET['action']) and $_GET['action'] == "editdo" and isset($_GET['id']))
{
  if($_POST['name']=="")
    jump("jump.php?id=2&jump=ad.php?action=edit=and=id=".$_GET['id']);
  $_POST['code']=html_replacef($_POST['code']);
  $_POST['code']=str_replace('"','*h*',$_POST['code']);
  $_POST['code']=str_replace("'",'*d*',$_POST['code']);
  $phpcolor->field="name='".$_POST['name']."',site='".$_POST['site']."',ranges='".$_POST['ranges']."',rid='".$_POST['rid']."',pid='".$_POST['pid']."',code='".$_POST['code']."'";
  $phpcolor->upgrade();
  jump("jump.php?id=24&jump=ad.php");
}
if(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);
  $ad['code']=str_replace('*h*','"',$ad['code']);
  $ad['code']=str_replace('*d*',"'",$ad['code']);
  $tpl -> assign("ad", $ad);
  $tpl -> display("ad_edit.htm");
}
else
{
  if(!isset($_GET['page']))
    $_GET['page']=0;
  $phpcolor->field="*";
  $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']="贴子顶部广告";
    elseif($ad[$count]['site']==10)
      $ad[$count]['site']="下载页广告";
	if($ad[$count]['ranges']==1)
      $ad[$count]['ranges']="全局广告(排除：".$ad[$count]['pid'].")";
    elseif($ad[$count]['ranges']==2)
      $ad[$count]['ranges']="分类广告(ID ".$ad[$count]['rid'].")";
    elseif($ad[$count]['ranges']==3)
      $ad[$count]['ranges']="吧广告(ID ".$ad[$count]['rid'].")";
  }
  $tpl -> assign("ad", $ad);
  $tpl -> assign("page", $page);
  $tpl -> display("ad.htm");
}
?>