<?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('tg_keyadmin',$authoritys,$rank);
?>
<!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="keywords.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
$action=trim(HtmlReplace($_REQUEST["action"]));
switch ($action)
{
    case "saveform":
    saveform();
    break;

    case "addform":
	addform($action);
	break;
	
	case "modify":
	addform($action);
	break;
	
    case "checks":
	     $link_id=intval($_GET["link_id"]);
		 $array=array('is_show'=>1);
	     $db->update("ve123_keyword_pay",$array,"link_id='$link_id'");
		 jsalert("审核成功");
	break;
	
	case "del":
     	$db->query("delete from ve123_keyword_pay where link_id='".intval($_GET["link_id"])."'");
	    jsalert("删除成功");
	break;
}	

if($action==""){?>
<table class="tb tb2 ">
  <tr class="header">
    <th style="text-align: center">ID</th>
    <th>关键词</th>
    <th>网页标题</th>
    <th>URL 地址</th>
    <th>竟价</th>
    <th>状态</th>
    <th>用户ID</th>
    <th>操作</th>
  </tr>
   <?php
  $sql="select * from ve123_keyword_pay";
  $result=$db->query($sql);
  $total=$db->num_rows($result);//记录总数
  $pagesize=20;//每页显示数
  $totalpage=ceil($total/$pagesize);
  $page=intval($_GET["page"]);
  if($page<=0){$page=1;}
  $offset=($page-1)*$pagesize;
  $result=$db->query($sql." order by link_id desc limit $offset,$pagesize");
  while ($rs=$db->fetch_array($result))
  {
  ?>
  <tr>
    <td align="center"><?php echo $rs["link_id"]?></td>
    <td><?php echo $rs["keywords"];?></td>
    <td><?php echo $rs["title"];?></td>
    <td><?php echo "<a target=\"_blank\" href=\"".$rs["url"]."\">".$rs["url"]."</a>";?></td>
    <td><?php echo $rs["price"];?></td>
    <td><?php echo OpenShow($rs["is_show"]);?></td>
    <td><?php echo $rs["user_id"];?></td>
    <td>
    <a href="?action=checks&link_id=<?php echo $rs["link_id"];?>">审核</a>&nbsp;&nbsp;
    <a href="?action=modify&link_id=<?php echo $rs["link_id"];?>">修改</a>&nbsp;&nbsp;
    <a href="?action=del&link_id=<?php echo $rs["link_id"];?>" onClick="if(!confirm('确定删除吗?')) return false;">删除</a>
    </td>
  </tr>
  <?php
  }
  ?>
   <tr>
    <td height="36" colspan="10" align="center" bgcolor="#F9FCEF">
       <?php  echo pageshow($page,$totalpage,$total,"?action=".$action."&kw=".$kw."&");?>
    </td>
  </tr>
  </table>
<?php
}
function addform($do_action)
{
global $db,$p_cid;
  if ($do_action=="modify")
  {
      $link_id=intval($_GET["link_id"]);
	  $sql="select * from ve123_keyword_pay where link_id='$link_id'";
	  $rs=$db->get_one($sql);
	  $keywords=$rs["keywords"];
	  $title=$rs["title"];
	  $url=$rs["url"];
	  $description=$rs["description"];
	  $jscode=$rs["jscode"];
	  $price=$rs["price"];
	  $pic=$rs["pic"];
	  $sort_id=$rs["sort_id"];
	  $btn_txt="确定修改";
  }
  else
  {
     $btn_txt="确定添加";
  }
?>
<table class="tb tb2 ">
<form id="form1" name="form1" method="post" action="?action=saveform">
  <tr>
    <td align="right">关键词:</td>
    <td>
      <input name="keywords" type="text" value="<?php echo $keywords?>" size="50" /></td>
  </tr>
  <tr>
    <td align="right">网页标题:</td>
    <td><input name="title" type="text" value="<?php echo $title?>" size="50" /></td>
  </tr>
  <tr>
    <td align="right">URL 地址:</td>
    <td><input name="url" type="text" value="<?php echo $url?>" size="50" /></td>
  </tr>
  <tr>
    <td align="right">网页描述:</td>
    <td><textarea name="description" cols="80" rows="8"><?php echo $description?></textarea></td>
  </tr>
  <tr>
    <td align="right">推广信息客服代码:</td>
    <td><textarea name="jscode" cols="80" rows="8"><?php echo $jscode?></textarea></td>
  </tr>
  <tr>
    <td align="right">图片:</td>
    <td><input name="pic" type="text" size="80" value="<?php echo $pic;?>"/>
      <span class="STYLE1">图片必须为：500*150像素 （支持：gif/jpg/png/swf）</span></td>
  </tr>
  <tr>
    <td align="right">竟价:</td>
    <td><input name="price" type="text" size="50"  value="<?php echo $price?>"/></td>
  </tr>
  <tr>
    <td align="right">状态:</td>
    <td><input type="radio" name="is_show" value="1" <?php if($rs['is_show']>0){echo 'checked="checked"';}?> />已审核<input type="radio" name="is_show" value="0" <?php if($rs['is_show']==0){echo 'checked="checked"';}?> />未审核</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>
	<input type="hidden" name="link_id" value="<?php echo $link_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;
   $keywords=trim(HtmlReplace($_POST["keywords"]));
   $title=trim(HtmlReplace($_POST["title"]));
   $url=trim(HtmlReplace($_POST["url"]));
   $description=trim(HtmlReplace($_POST["description"]));
   $jscode=my_addslashes(trim($_POST["jscode"]));
   $price=trim(HtmlReplace($_POST["price"]));
   $pic=trim(HtmlReplace($_POST["pic"]));
   $link_id=intval($_POST["link_id"]);
   $is_show=intval($_POST["is_show"]);
   $do_action=HtmlReplace($_POST["do_action"]);
   if ($do_action=="modify")
   {
	 $array=array('keywords'=>$keywords,'title'=>$title,'url'=>$url,'description'=>$description,'jscode'=>$jscode,'price'=>$price,'pic'=>$pic,'is_show'=>$is_show);
	 $db->update("ve123_keyword_pay",$array,"link_id='$link_id'");
	 jsalert("修改成功");
   }
   else
   {     
             $array=array('keywords'=>$keywords,'title'=>$title,'url'=>$url,'description'=>$description,'jscode'=>$jscode,'price'=>$price,'pic'=>$pic);
	         $db->insert("ve123_keyword_pay",$array);  
			 jsalert("提交成功");
   }
}
?>
</div>
</body>
</html>