<?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('about',$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="about.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>

<script language="javascript">
   function checkform()
   {
         if(document.pageform.title.value==""){alert("标题不能为空!");document.pageform.title.focus();return false;}
		 if(document.pageform.filename.value==""){alert("文件名称不能为空!");document.pageform.filename.focus();return false;}
   }
</script>
<?php
$action=$_GET["action"];
switch ($action)
{
    case "saveform":
    saveform();
    break;

    case "addform":
	addform($action);
	break;
	
	case "modify":
	addform($action);
	break;

	case "del":
	     $about_id=intval($_GET["about_id"]);
		 $db->query("delete from ve123_about where about_id='".$about_id."'");
	break;
}	
if($action==""){	
?>
<table class="tb tb2 ">
  <tr class="header">
    <th></th>
    <th>单页标题</th>
    <th>文件名称</th>
    <th>是否显示</th>
    <th>地址</th>
    <th>操作</th>
  </tr>
<?php
  $sql="select * from ve123_about".$where;
  $result=$db->query($sql);
  $total=$db->num_rows($result);//记录总数
  $pagesize=30;//每页显示数
  $totalpage=ceil($total/$pagesize);
  $page=intval($_GET["page"]);
  if($page<=0){$page=1;}
  $offset=($page-1)*$pagesize;
  
  $result=$db->query($sql." order by about_id desc limit $offset,$pagesize");
  while ($rs=$db->fetch_array($result))
  {
  ?>
   <tr>
    <td height="26" align="center"><?php echo $rs["about_id"];?></td>
    <td><?php echo stripslashes($rs["title"]);?></td>
    <td><?php echo $rs["filename"];?></td>
    <td><?php if($rs["is_show"]){echo "√";}else{echo "<font color=\"red\">×</font>";}?></td>
    <td><?php echo "<a target=\"_blank\" href=\"".$site["url"]."/a/".$rs["filename"].".html\" title=\"查看".$rs["title"]."\">".$rs["filename"].".html";?></a></td>
    <td><a href="?action=modify&amp;about_id=<?php echo $rs["about_id"]?>">修改</a>
	<a href="?action=del&about_id=<?php echo $rs["about_id"];?>" onclick="if(!confirm('确认删除码?')) return false;">删除</a>	</td>
  </tr>
  <?php
}
?>
 <tr><td colspan="15"><?php echo pageshow($page,$totalpage,$total,"?");?></td></tr>
</table>
  <?php
}
?>


<?php
function addform($do_action)
{
global $db;
  if ($do_action=="modify")
  {
      $about_id=$_GET["about_id"];
	  $sql="select * from ve123_about where about_id='$about_id'";
	  $rs=$db->get_one($sql);
	  $title=$rs["title"];
	  $content=$rs["content"];
	  $filename=$rs["filename"];
	  $url=$rs["url"];
	  $sortid=$rs["sortid"];
	  $is_show=$rs["is_show"];
	  $btn_txt="确定修改";
  }
  else
  {
     $btn_txt="确定提交";
  }
?>
<table class="tb tb2 ">
<form id="pageform" name="pageform" method="post" action="?action=saveform" onsubmit="return checkform()">
  <tr>
    <td width="120" align="right">单页标题:</td>
    <td>
      <input name="title" type="text" value="<?php echo $title?>" class="txt" style="width:200px;"/>    </td>
  </tr>
  <tr>
    <td align="right">文件名称:</td>
    <td><input type="text" name="filename" value="<?php echo $filename;?>" class="txt" style="width:200px;"/></td>
  </tr>
  <tr>
    <td align="right">URL:</td>
    <td><input name="url" type="text"  value="<?php echo $url;?>" class="txt" style="width:200px;"/> (如果要跳向URL网址,请输入网址,否则请留空)</td>
  </tr>
  <tr>
    <td align="right">排序:</td>
    <td><input type="text" name="sortid" value="<?php echo $sortid?>" class="txt"/></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" id="content" cols="50" rows="15" style="width:100%;"><?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="about_id" value="<?php echo $about_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,$config;
   $title=addslashes(HtmlReplace(trim($_POST["title"])));
   $content=trim($_POST["content"]);
   $filename=HtmlReplace(trim($_POST["filename"]));
   $url=HtmlReplace(trim($_POST["url"]));
   $sortid=intval($_POST["sortid"]);
   $about_id=intval($_POST["about_id"]);
   $do_action=HtmlReplace($_POST["do_action"]);
   $is_show=$_POST["is_show"];
ob_start();
require "inc/abouttemp.php";
$str=ob_get_contents();
ob_end_clean();
$str=stripslashes($str);
file_put_contents("../a/".$filename.".html", $str);
   if ($do_action=="modify")
   {
     $array=array('title'=>$title,'content'=>$content,'url'=>$url,'filename'=>$filename,'sortid'=>$sortid,'is_show'=>$is_show);
	 $db->update("ve123_about",$array,"about_id='$about_id'");
	 jsalert("修改成功");
   }
   else
   {
     $array=array('title'=>$title,'content'=>$content,'url'=>$url,'filename'=>$filename,'sortid'=>$sortid,'is_show'=>$is_show);
	 $db->insert("ve123_about",$array);
     jsalert("提交成功");
   }
}
?>

</div>
</body>
</html>