<?php
/**
 * @version        Somao_Search X1.0 9:23 2012-1-1 Somao $
 * @package        Somao_Search.Site
 * @copyright      Copyright (c) 2009 - 2012, Somao, Inc.
 * @license        http://www.somao123.com/
 * @link           http://www.somao.cc/
**/
require "global.php";
CheckPurview('ad_admin',$authoritys,$rank);
$action=$_GET["action"];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<meta http-equiv="x-ua-compatible" content="ie=7" />
<link href="css/admincp.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container">
  <div class="floattop">
    <div class="itemtitle"><h3>广告管理</h3>
      <ul class="tab1">
        <li class="current"><a href="ad.php"><span>广告列表</span></a></li>
        <li><a href="?action=addform"><span>添加广告</span></a></li>
      </ul>
     </div>
   </div>
 <div class="floattopempty"></div>
<table class="tb tb2 " id="tips">
<tr><th  class="partition">提示</th></tr>
<tr><td class="tipsblock" s="1"><ul id="tipslis"><li>广告管理。</li></ul></td></tr>
</table>
<?php 
switch ($action)
{
    case "saveform":
    saveform();
    break;

    case "addform":
	addform($action);
	break;
	
	case "modify":
	addform($action);
	break;
	
	case "del":
	     $ad_id=intval($_GET["ad_id"]);
		 $db->query("delete from ve123_ad where ad_id='".$ad_id."'");
	break;
}
if($action==""){
?>
<table class="tb tb2 ">
  <tr class="header">
    <th>ID</th>
    <th>网站名称</th>
    <th>广告类型</th>
    <th>链接地址</th>
    <th>是否显示</th>
    <th>排序</th>
    <th>操作</th>
  </tr>
  <?php
  $sql="select * from ve123_ad";
  $result=$db->query($sql);
  $total=$db->num_rows($result);//记录总数
  $pagesize=10;//每页显示数
  $totalpage=ceil($total/$pagesize);
  $page=intval($_GET["page"]);
  if($page<=0){$page=1;}
  $offset=($page-1)*$pagesize;
  $result=$db->query($sql." order by sortid desc limit $offset,$pagesize");
  while ($rs=$db->fetch_array($result))
  {
  ?>
  <tr>
    <td><?php echo $rs["ad_id"]?></td>
    <td><?php echo $rs["title"]?></td>
    <td><?php echo $rs["type"]?></td>
    <td><?php echo "<a href=\"".$rs["siteurl"]."\" target=\"_blank\">".$rs["siteurl"]."</a>";?></td>
    <td>
	<?php
	  if($rs["is_show"])
	  {
	    echo "√";
	  }
	  else
	  {
	    echo "<font color=\"red\">×</font>";
	  }
	?>
	</td>
    <td><?php echo $rs["sortid"];?></td>
    <td><a href="?action=modify&amp;ad_id=<?php echo $rs["ad_id"]?>&type=<?php echo $rs["type"];?>">修改</a>
	<a href="?action=del&ad_id=<?php echo $rs["ad_id"];?>" onclick="if(!confirm('确认删除码?')) return false;">删除</a>	</td>
  </tr>
  <?php
  }
  ?>
 <tr><td colspan="15"><?php echo pageshow($page,$totalpage,$total,"?");?></td></tr>
</table>


<?php
}
function addform($do_action)
{
global $db,$type;
  if ($do_action=="modify")
  {
      $ad_id=$_GET["ad_id"];
	  $sql="select * from ve123_ad where ad_id='$ad_id'";
	  $rs=$db->get_one($sql);
	  $title=$rs["title"];
	  $siteurl=$rs["siteurl"];
	  $type=$rs["type"];
	  $content=$rs["content"];
	  $sortid=$rs["sortid"];
	  $is_show=$rs["is_show"];
	  $type=$rs["type"];
	  $btn_txt="确定修改";
  }
  else
  {
     $btn_txt="确定提交";
	 $is_show=1;
  }
?>
<table class="tb tb2 ">
<form id="form1" name="form1" method="post" action="?action=saveform">
  <tr>
    <td width="100" align="right">网站名称:</td>
    <td>
      <input name="title" type="text" value="<?php echo $title?>" size="80"/>    </td>
  </tr>
  <tr>
    <td align="right">链接地址:</td>
    <td><input name="siteurl" type="text" value="<?php echo $siteurl?>" size="80" /></td>
  </tr>
  <tr>
    <td align="right">显示类型:</td>
    <td><input name="type" type="radio" value="1" <?php if($type==1) echo "checked=\"checked\"";?> />
    搜索页右侧
      <input type="radio" name="type" value="2" <?php if($type==2) echo "checked=\"checked\"";?>/>
      搜索页右侧(有说明显示)
	   <input type="radio" name="type" value="3" <?php if($type==3) echo "checked=\"checked\"";?>/>
      首页广告位	  </td>
  </tr>
  <tr>
    <td  align="right">排序ID:</td>
    <td><input type="text" name="sortid"  value="<?php echo $sortid?>"/></td>
  </tr>
  <tr>
    <td align="right">是否显示:</td>
    <td><input name="is_show" type="checkbox" value="1" <?php if($is_show){echo "checked=\"checked\"";}?> /></td>
  </tr>
  <tr>
    <td align="right">详细说明:</td>
    <td><textarea name="content" cols="80" rows="8"><?php echo $content;?></textarea><script type="text/javascript">//<![CDATA[
window.CKEDITOR_BASEPATH='/include/ckeditor/';
//]]></script>
<script type="text/javascript" src="/include/ckeditor/ckeditor.js?t=B8DJ5M3"></script>
<script type="text/javascript">//<![CDATA[
CKEDITOR.replace('content', {"extraPlugins":"dedepage,multipic,addon","toolbar":[["Source","-","Templates"],["Cut","Copy","Paste","PasteText","PasteFromWord","-","Print"],["Undo","Redo","-","Find","Replace","-","SelectAll","RemoveFormat"],["ShowBlocks"],["Image","Flash","Addon"],["Maximize"],"\/",["Bold","Italic","Underline","Strike","-"],["NumberedList","BulletedList","-","Outdent","Indent","Blockquote"],["JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock"],["Table","HorizontalRule","Smiley","SpecialChar"],["Link","Unlink","Anchor"],"\/",["Styles","Format","Font","FontSize"],["TextColor","BGColor","MyPage","MultiPic"]],"height":350,"skin":"kama"});
//]]></script></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>
	<input type="hidden" name="ad_id" value="<?php echo $ad_id?>">
	<input type="hidden" name="do_action" value="<?php echo $do_action?>">
	<input type="submit" name="Submit" value="<?php echo $btn_txt?>" />	</td>
  </tr>
  </form>
</table>
<?php
}
?>

<?php
function saveform()
{
global $db;
   $title=trim($_POST["title"]);
   $siteurl=trim($_POST["siteurl"]);
   $type=trim($_POST["type"]);
   $content=trim($_POST["content"]);
   $ad_id=$_POST["ad_id"];
   $sortid=intval($_POST["sortid"]);
   $is_show=intval($_POST["is_show"]);
   $do_action=$_POST["do_action"];
   if ($do_action=="modify")
   {
     $array=array('title'=>$title,'siteurl'=>$siteurl,'type'=>$type,'content'=>$content,'sortid'=>$sortid,'is_show'=>$is_show);
	 $db->update("ve123_ad",$array,"ad_id='$ad_id'");
	 jsalert("修改成功","ad.php");
   }
   else
   {
     $array=array('title'=>$title,'siteurl'=>$siteurl,'type'=>$type,'content'=>$content,'sortid'=>$sortid,'is_show'=>$is_show);
	 $db->insert("ve123_ad",$array);
     jsalert("提交成功","ad.php");
   }
}
?>
</div>
</body>
</html>