<?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"]));

if($action=="addsave"){
	if($user["points"]<$config['open_point']){
	 jsalert("对不起，您账号余额不足请充值。");
	 exit();
	}
	$keywords=trim(HtmlReplace($_POST["keywords"]));
	$title=trim(HtmlReplace($_POST["title"]));
	$url=trim(HtmlReplace($_POST["url"]));
	$content=my_addslashes($_POST["content"]);
	$enddatetime=time()+60*60*24*31;
	$array=array('keywords'=>$keywords,'title'=>$title,'url'=>$url,'content'=>$content,'user_id'=>$user["user_id"],'updatetime'=>time(),'enddatetime'=>$enddatetime,'is_show'=>0);
	$db->insert("ve123_open",$array);
	
	$points=$user["points"]-$config['open_point'];
	$array=array('points'=>$points);
	$db->update("ve123_member",$array,"user_id='".$user["user_id"]."'");
	jsalert("恭喜您，您成功支付一个月的开放平台时间，等待管理员审核。");
}

if($action=="editsave"){
	$keywords=trim(HtmlReplace($_POST["keywords"]));
	$title=trim(HtmlReplace($_POST["title"]));
	$url=trim(HtmlReplace($_POST["url"]));
	$content=my_addslashes($_POST["content"]);
	$oid=intval($_POST["oid"]);
	if($oid<1)  jsalert("非法操作！");
	$array=array('keywords'=>$keywords,'title'=>$title,'url'=>$url,'content'=>$content,'is_show'=>0);
	$db->update("ve123_open",$array,"oid='".$oid."' and user_id='".$user["user_id"]."' ");
	jsalert("修改成功，等待管理员审核。");
}
if($action=="del"){
	$oid=intval($_GET["oid"]);
	$db->query("delete from ve123_open where oid='".$oid."' and user_id='".$user["user_id"]."'");
	jsalert("删除成功");
}
?>
<!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">

<?php if($action==""){ ?>
  <table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#39867B">
    <tr>
      <td class="title">开放平台列表 <a href="?action=modify">添加</a></td>
    </tr>
    <tr>
      <td valign="top" bgcolor="#EFEFEF">
      
      <table width="90%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#dddddd" class="table">
      <form name="form3" method="post" action="open_manage.php">  
	   <input type="hidden" name="action" value="updateprice">
          <tr>
            <td width="8%" align="center" height="30" bgcolor="#efefef"><h4>序号</h4></td>
            <td width="27%" align="center" bgcolor="#efefef"><h4>关键词</h4></td>
            <td width="20%" align="center" bgcolor="#efefef"><h4>查看效果</h4></td>
            <td width="20%" align="center" bgcolor="#efefef"><h4>到期时间</h4></td>
            <td width="10%" align="center" bgcolor="#efefef"><h4>状态</h4></td>
            <td width="15%" align="center" bgcolor="#efefef"><h4>管理</h4></td>
          </tr>
  <?php
  $query=$db->query("select * from ve123_open where user_id='".$user["user_id"]."' order by enddatetime desc");
  while($link=$db->fetch_array($query))
  { ?>
  <tr>
    <td align="center" height="28"><?php echo $link["oid"];?></td>
    <td align="center"><?php echo "<a href=\"?action=modify&oid=".$link["oid"]."\">".$link["keywords"]."</a>";?></td>
    <td align="center"><a target="_blank" href="../s?wd=<?php echo urlencode($link["keywords"]);?>">搜索</a></td>
    <td align="center" height="28"><?php echo OpenCheck($link["enddatetime"])?></td>
    <td align="center" height="28"><?php echo OpenShow($link["is_show"]);?></td>
    <td align="center"><?php echo "<a href=\"?action=modify&oid=".$link["oid"]."\">修改</a>";?> <a href="?action=del&oid=<?php echo $link["oid"]?>" onclick="if(!confirm('确认删除码?')) return false;">删除</a></td>
  </tr>
  <?php } ?>
  </form>
</table>
</td>
</tr>
</table>
<br>
<?php
}elseif($action=="modify"){
	$oid=intval($_GET["oid"]);
	if($oid>0){
			 $title=$bt_txt="修改关键词";
			 $action="editsave";
			 $link=$db->get_one("select * from ve123_open where oid='".$oid."' and user_id='".$user["user_id"]."'");
	}else{
		if($user["points"]<$config['open_point']){
	    jsalert("对不起，您账号余额不足请充值。");
	    exit();
	    }
			 $title=$bt_txt="添加关键词";
			 $action="addsave";
	}
?>
<form name="form1" method="post" action="open_manage.php">
<input type="hidden" name="action" value="<?php echo $action;?>">
<input type="hidden" name="oid" value="<?php echo $oid;?>">
<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="content" cols="80" rows="8"><?php echo $link["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="submit" name="Submit" value="<?php echo $bt_txt;?>"></td>
      </tr>
    </table></td>
  </tr>
</table>
</form>
<?php
}
?>
<?php foothtml(); ?>