<?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_once("global.php");
is_login();
$action=trim(HtmlReplace($_REQUEST["action"]));
switch($action)
{
   case "saveaddlinks":
         $do_action=trim(HtmlReplace($_POST["do_action"]));
		 $keywords=trim(HtmlReplace($_POST["keywords"]));
	     $title=trim(HtmlReplace($_POST["title"]));
	     $url=trim(HtmlReplace($_POST["url"]));
		 $pic=trim(HtmlReplace($_POST["pic"]));
	     $description=trim(HtmlReplace($_POST["description"]));
		 $price=trim(HtmlReplace($_POST["price"]));
		 if(empty($price) || ($price<get_qijia($key["keywords"])) || ($price>$user["points"]))
	     {
					jsalert("出价不能低于起价或者你的积分不足以参加竞价！");
				    exit();
				  	break;
		 }
		 else if($do_action=="savemodify")
		 {
		     $link_id=intval($_POST["link_id"]);
		     $array=array('keywords'=>$keywords,'title'=>$title,'url'=>$url,'pic'=>$pic,'description'=>$description,'price'=>$price,'updatetime'=>time(),'is_show'=>0);
		     $db->update("ve123_keyword_pay",$array,"link_id='".$link_id."'");
			 jsalert("修改成功，等待管理员审核");
			 exit();
		 }
		 else
		 {
		     $array=array('keywords'=>$keywords,'title'=>$title,'url'=>$url,'pic'=>$pic,'description'=>$description,'price'=>$price,'updatetime'=>time(),'user_id'=>$user["user_id"],'updatetime'=>time(),'is_show'=>0);
		     $db->insert("ve123_keyword_pay",$array);
			 jsalert("添加成功，等待管理员审核");
			 exit();
		 }
   break;
   case "updateprice":
         $arrPrice=$_POST["arrPrice"];
		 foreach($arrPrice as $link_id=>$price)
		 {
		       $key=$db->get_one("select * from ve123_keyword_pay where link_id='".$link_id."'");
		       if(get_qijia($key["keywords"])>$price)
			   {
				  jsalert("出价不能低于起价！");
				  exit();
			   }
		       $array=array('price'=>$price,'updatetime'=>time());
			   $db->update("ve123_keyword_pay",$array,"link_id='".$link_id."' and user_id='".$user["user_id"]."'");
			   
		 }
		 jsalert("更新成功！！");
		 exit();
   break;
   	case "del":
	     $link_id=intval($_GET["link_id"]);
		 $db->query("delete from ve123_keyword_pay where link_id='".$link_id."' and user_id='".$user["user_id"]."'");
		 jsalert("删除成功！！");
		 exit();
	break;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
		<title>首页--<?php echo $pagetitle;?></title>
       <link href="/css/union.css" rel="stylesheet" type="text/css" />
	</head>
	<body>
<div id="body">
<table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#39867B">
    <tr>
      <td class="title">竞价关键字列表 </td>
    </tr>
    <tr>
      <td valign="top" bgcolor="#EFEFEF">
      
      <table width="95%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#dddddd" class="table">
      <form name="form3" method="post" action="key_manage.php">  
	   <input type="hidden" name="action" value="updateprice">
          <tr>
            <td width="10%" align="center" height="30" bgcolor="#efefef"><h4>序号</h4></td>
            <td width="18%" align="center" bgcolor="#efefef"><h4>关键词</h4></td>
            <td width="20%" align="center" bgcolor="#efefef"><h4>关键词状态</h4></td>
            <td width="8%" align="center" bgcolor="#efefef"><h4>起价</h4></td>
            <td width="8%" align="center" bgcolor="#efefef"><h4>出价</h4></td>
            <td width="10%" align="center" bgcolor="#efefef"><h4>点击次数</h4></td>
            <td width="10%" align="center" bgcolor="#efefef"><h4>消费金额</h4></td>
            <td width="10%" align="center" bgcolor="#efefef"><h4>状态</h4></td>
            <td width="10%" align="center" bgcolor="#efefef"><h4>操作</h4></td>
          </tr>
          <tr>

<?php
  $query=$db->query("select * from ve123_keyword_pay where user_id='".$user["user_id"]."'");
  $j=0;
  while($link=$db->fetch_array($query))
  {
     $j++;
  ?>
  <tr>
    <td align="center" height="28"><?php echo $j;?></td>
    <td><?php echo "<a href=\"?action=modify&link_id=".$link["link_id"]."\">".$link["keywords"]."</a>";?></td>
    <td align="center"><a target="_blank" href="../s?wd=<?php echo urlencode($link["keywords"]);?>">搜索</a></td>
    <td align="center"><?php echo get_qijia($link["keywords"]);?>&nbsp;积分</td>
    <td align="center"><input type="text" name="arrPrice[<?php echo $link["link_id"];?>]" value="<?php echo $link["price"];?>"></td>
    <td align="center"><?php echo $link["stat_click"];?></td>
    <td align="center"><?php echo $link["consumption"];?></td>
    <td align="center"><?php echo OpenShow($link["is_show"]);?></td>
    <td align="center"><a href="?action=del&link_id=<?php echo $link["link_id"]?>" onclick="if(!confirm('确认删除码?')) return false;">删除</a></td>
  </tr>

  <?php
  }
  ?>
      <td colspan="8" align="right"><input type="submit" name="Submit4" value="更新出价"></td>
    </tr>
  </form>
</table>
</td>
</tr>
</table>

<br>
<?php
if($action!="step_2")
{
        if($action=="modify")
		{
		     $link_id=intval($_GET["link_id"]);
			 $do_action="savemodify";
			 $title=$bt_txt="修改关键词";
			 $link=$db->get_one("select * from ve123_keyword_pay where link_id='".$link_id."' and user_id='".$user["user_id"]."'");
		}
		else
		{
		     $action_value="step_2";
		     $title="添加关键词";
			 $bt_txt="提交";
		}
?>

<form name="form1" method="post" action="key_manage.php">
<input type="hidden" name="action" value="saveaddlinks">
<input type="hidden" name="do_action" value="<?php echo $do_action;?>">
<input type="hidden" name="link_id" value="<?php echo $link_id;?>"> 
<table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#39867B">
  <tr>
    <td class="title">添加关键词</td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#EFEFEF">
     <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0" class="table">
      <tr>
        <td width="11%">&nbsp;</td>
        <td width="89%">&nbsp;</td>
      </tr>
      <tr>
        <th colspan="2"><?php echo $title;?></th>
      </tr>
      <tr>
        <td width="100">关 键 词</td>
        <td><input name="keywords" type="text" size="80" value="<?php echo $link["keywords"];?>">
        最多32字</td>
      </tr>
      <tr>
        <td>网页标题</td>
        <td><input name="title" type="text" size="80" value="<?php echo $link["title"];?>">
        最多20字 </td>
      </tr>
      <tr>
        <td>URL 地址</td>
        <td><input name="url" type="text" size="80" value="<?php echo $link["url"];?>">
        最多248字节</td>
      </tr>
      <tr>
        <td>网页描述</td>
        <td><textarea name="description" cols="80" rows="8"><?php echo $link["description"];?></textarea>
        最多100字<?php echo $user["points"];?></td>
      </tr>
      <tr>
        <td>竞价：</td>
        <td><input name="price" type="text" size="10" value="<?php echo $link["price"];?>"></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><input type="submit" name="Submit" value="<?php echo $bt_txt;?>"></td>
      </tr>
    </table></td>
  </tr>
</table>
 </form>
<?php
}
?>

<?php foothtml(); ?>
