<?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_rightad',$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":
	     $oid=intval($_GET["oid"]);
		 $array=array('is_show'=>1);
	     $db->update("ve123_open",$array,"oid='$oid'");
		 jsalert("审核成功");
	break;
	
	case "del":
	     $oid=intval($_GET["oid"]);
		 $db->query("delete from ve123_open where oid='".$oid."'");
		 jsalert("删除成功");
	break;
}	
if($action==""){?>
<table class="tb tb2 ">
  <tr class="header">
    <th style="text-align: center">ID</th>
    <th>关键词</th>
    <th>地址</th>
    <th>提交时间</th>
    <th>到期时间</th>
    <th>状态</th>
    <th>用户ID</th>
    <th>操作</th>
  </tr>
    <?php
  $sql="select * from ve123_open";
  $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 oid desc limit $offset,$pagesize");
  while ($rs=$db->fetch_array($result))
  {
  ?>
  <tr>
    <td height="28" width="50"  align="center"><?php echo $rs["oid"];?></td>
    <td><?php echo "<a target=\"_blank\" href=\"".$site["keywords"]."/s/?wd=".$rs["keywords"]."\" title=\"查看".$rs["keywords"]."\">".$rs["keywords"]."";?></a></td>
    <td><?php echo $rs["url"];?></td>
    <td><?php echo date("Y-m-d",$rs["updatetime"]);?></td>
    <td><?php echo OpenCheck($rs["enddatetime"]);?></td>
    <td><?php echo OpenShow($rs["is_show"]);?></td>
    <td><?php echo $rs["user_id"];?></td>
    <td><a href="?action=checks&oid=<?php echo $rs["oid"]?>">审核</a>
    <a href="?action=modify&oid=<?php echo $rs["oid"]?>">修改</a>
	<a href="?action=del&oid=<?php echo $rs["oid"];?>" 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,"?");?>
    </td>
  </tr>
  </table>
<?php
}
function addform($do_action)
{
global $db;
  if ($do_action=="modify")
  {
      $oid=$_GET["oid"];
	  $sql="select * from ve123_open where oid='$oid'";
	  $rs=$db->get_one($sql);
	  $btn_txt="确定修改";
  }
  else
  {
     $btn_txt="确定提交";
  }
?>
<table class="tb tb2 ">
<form id="pageform" name="pageform" method="post" action="?action=saveform" onsubmit="return checkform()">
  <tr>
    <td align="right">网站名称:</td>
    <td><input type="text" name="title" value="<?php echo $rs['title'];?>"/></td>
  </tr>
  <tr>
    <td align="right">搜索关键词:</td>
    <td><input type="text" name="keywords" value="<?php echo $rs['keywords'];?>"/></td>
  </tr>
  <tr>
    <td align="right">跳转URL:</td>
    <td><input name="url" type="text" size="80"  value="<?php echo $rs['url'];?>"/>
      (如果要跳向URL网址,请输入网址,否则请留空)</td>
  </tr>
  <tr>
    <td align="right">排序:</td>
    <td><input type="text" name="sortid" value="<?php echo $rs['sortid']?>"/></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 align="right">到期时间:</td>
    <td><input type="text" name="enddatetime" value="<?php echo date("Y-m-d  H:i:s",$rs["enddatetime"]);?>"/></td>
  </tr>
  <tr>
    <td align="right">内容:</td>
    <td>
	<textarea name="content" id="content" cols="50" rows="15" style="width:100%;"><?php echo $rs['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="oid" value="<?php echo $oid?>">
	<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,$config;
   $keywords=trim(HtmlReplace($_POST["keywords"]));
   $title=trim(HtmlReplace($_POST["title"]));
   $url=trim(HtmlReplace($_POST["url"]));
   $content=my_addslashes($_POST["content"]);
   $sortid=intval($_POST["sortid"]);
   $oid=intval($_POST["oid"]);
   $do_action=HtmlReplace($_POST["do_action"]);
   $enddatetime=strtotime(HtmlReplace($_POST["enddatetime"]));   
   $is_show=intval($_POST["is_show"]);
   if ($do_action=="modify")
   {
     $array=array('keywords'=>$keywords,'title'=>$title,'url'=>$url,'content'=>$content,'is_show'=>$is_show,'sortid'=>$sortid,'enddatetime'=>$enddatetime);
	 $db->update("ve123_open",$array,"oid='$oid'");
	 jsalert("修改成功");
   }
   else
   {
     $array=array('keywords'=>$keywords,'title'=>$title,'url'=>$url,'content'=>$content,'is_show'=>$is_show,'sortid'=>$sortid,'enddatetime'=>$enddatetime);
	 $db->insert("ve123_open",$array);
     jsalert("提交成功");
   }
}
?>
</div>
</body>
</html>