<?php
include("qs.php");
require( '../data/config.php');
$conn=mysql_connect($db_host,$db_user,$db_pass);
mysql_query("set names 'utf8'");
mysql_select_db($db_name);
if (PHP_VERSION >= '5.1' && !empty($timezone))
{
    date_default_timezone_set($timezone);
}
$action=_get('action');
if($action=="")
$action=_post('action');
$id=_get('id');
if($id=="")
$id=_post('id');
$qs=explode(",",$_SESSION["tm_qs"]);
if($qs[1]==0)
   {
   echo "<script>location.href='main.php';</script>";
   exit();
   }
$uid=$_SESSION["tm_id"];
?>
<!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=UTF-8" />
<META http-equiv="Pragma" content="no-cache" />
<LINK href="css/general.css" rel="stylesheet" type="text/css" />
<LINK href="css/main.css" rel="stylesheet" type="text/css" />
<script>
var xmlHttp = false;
try {
xmlHttp = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
xmlHttp = false;
}
}
}
if (!xmlHttp){
alert("无法创建 XMLHttpRequest 对象！");
} 

function getInfo(id) {
var url = "cjin.php?id=" + id + "&ku=tm_art_class";
xmlHttp.open("GET", url, true);//这里的true代表是异步请求
xmlHttp.onreadystatechange = updatePage;
xmlHttp.send(null);
} 

function updatePage(){
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
var a=response.split(","); 
if(a[0]==0)
   document.getElementById("jin"+a[1]).src =a[2];
else
   document.getElementById("btop"+a[1]).src =a[2];
}
}
</script>
</HEAD><BODY>
<?php 
if($action=="del")
{
if(isset($_POST['chkkindid']) && is_array($_POST['chkkindid'])){
foreach($_POST['chkkindid'] as $tempid){
$sql="select tm_art.*,tm_art_class.filename from tm_art left join tm_art_class on tm_art.art_class=tm_art_class.art_id where tm_art.art_id=".$tempid;
$rs=mysql_fetch_object(mysql_query($sql));
if($rs)
   {
    if(file_exists("../".$rs->filename."/".substr(ereg_replace('-',"",$rs->art_date),0,6)."/".ereg_replace('-',"",$rs->art_date).$rs->art_id.".html"))
    $del=unlink("../".$rs->filename."/".substr(ereg_replace('-',"",$rs->art_date),0,6)."/".ereg_replace('-',"",$rs->art_date).$rs->art_id.".html");
   }
$exec="delete from tm_art where art_id=".$tempid;
mysql_query($exec);
mysql_query("delete from tm_art_re where re_artid=".$tempid);
}
}
 echo "<script>location.href='art.php';</script>";
 exit();
 }
elseif($action=="tj")
 {
if(isset($_POST['chkkindid']) && is_array($_POST['chkkindid'])){
foreach($_POST['chkkindid'] as $tempid){
$exec="update tm_art set show1=1 where art_id=".$tempid;
mysql_query($exec);
}
}
 echo "<script>location.href='art.php';</script>";
 exit();
 }
elseif($action=="utj")
 {
if(isset($_POST['chkkindid']) && is_array($_POST['chkkindid'])){
foreach($_POST['chkkindid'] as $tempid){
$exec="update tm_art set show1=0 where art_id=".$tempid;
mysql_query($exec);
}
}
 echo "<script>location.href='art.php';</script>";
 exit();
 }
elseif($action=="add")
{
$zid=_post('zid');
$upay=_post('upay')<>""?_post('upay'):0;
$zt_name=_post('zt_name');
$art_tag=_post('tag');
if($zt_name<>"")
{
$rs=mysql_fetch_object(mysql_query("select * from tm_tag where tag_name='$zt_name'"));
if($rs)
  {
$art_tag=$rs->tag_id;
  }
else
{
$sql="insert into tm_tag(tag_name,tag_show) values('$zt_name','1')";
mysql_query($sql);
$art_tag=mysql_insert_id();
}
}
$art_title=_post('art_title');
$art_name=_post('art_name');
$art_key=_post('art_key');
$art_cont=_post('content');
$art_class=_post('art_class');
if($art_class==0)
   {
   echo "<script>alert('没有选择分类!');history.go(-1);</script>";
   exit();
   }
$show1=1;
$art_date=date('Y-m-d');
$cid=_post('cid');
$sql="insert into tm_art(art_title,art_name,art_key,art_cont,art_class,art_tag,art_date,show1,art_zt,uid) values('$art_title','$art_name','$art_key','$art_cont','$art_class','$art_tag','$art_date','$show1','$zid','$uid')";
mysql_query($sql);
$nid=mysql_insert_id();
echo "<script>location.href='art.php';</script>";
 exit();
}
elseif($action=="edit")
{
$art_title=_post('art_title');
$art_key=_post('art_key');
$art_cont=_post('content');
$art_class=_post('art_class');
$art_tag=_post('tag');
$zid=_post('zid');
$art_name=_post('art_name');
$sql="update tm_art set art_title='$art_title',art_name='$art_name',art_key='$art_key',art_cont='$art_cont',art_class='$art_class',art_tag='$art_tag',art_zt='$zid' where art_id='$id'";
mysql_query($sql);
 echo "<script>location.href='art.php';</script>";
}
?>
<div class="h2">系统管理 >> 日志管理 >> <?php if($id=="") echo "添加";else echo "编辑";?></div>
<div class="list-div">

<table cellspacing='1' cellpadding='3'>
<tr>
  <th align='left'><table width="100" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><div align="left">&nbsp;&nbsp;日志管理</div></td>
        <td width="150">&nbsp;</td>
      </tr>
    </table></th>
</tr>
<tr><td align="left" valign="top" style="background:#F5F5F5;padding-bottom:8px;">
<TABLE cellSpacing=0 cellPadding=0 width="97.5%" border=0 CALLPADDING="0">
<?php 			  
if($action=="" and $id=="")
{
?>
<form id="form1" name="form1" method="post" action="art_w.php">
			<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">标　题：
                                  <input name="art_title" type="text" id="art_title" size="50" />
              </span>			                  </TD>
    </TR>
	<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">作　者：
                                  <input name="art_name" type="text" id="art_name" value="<?php echo $_SESSION["tm_name"];?>" size="50" />
              </span>			                  </TD>
    </TR>
			<TR BORDER="0" WIDTH="100%">
			                  <TD height="20" style="PADDING-LEFT: 8px; PADDING-TOP: 8px"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="50">导　读：</td>
                    <td><?php
	include_once('../fckeditor/fckeditor.php'); 
	$editor1 = new FCKeditor("art_key");
    $editor1->BasePath   = '../fckeditor/';
    $editor1->ToolbarSet = 'Default';
    $editor1->Width      = '100%';
    $editor1->Height     = '170';
    $editor1->Value      = '';
    $FCKeditor = $editor1->Create(); 
?></td>
                  </tr>
                </table></TD>
    </TR>
		<TR BORDER="0" WIDTH="100%">
                <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left height=30><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="50">内　容：</td>
                    <td><?php
	include_once('../fckeditor/fckeditor.php'); 
	$editor = new FCKeditor("content");
    $editor->BasePath   = '../fckeditor/';
    $editor->ToolbarSet = 'Default';
    $editor->Width      = '100%';
    $editor->Height     = '370';
    $editor->Value      = '';
    $FCKeditor = $editor->Create(); 
?></td>
                  </tr>
                </table></TD>
              </TR>
			<TR BORDER="0" WIDTH="100%">
                <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left bgColor=#ffffff height=20>日志分类：
                  <select name="art_class" id="art_class">
				  <option value="0">请选择日志分类</option>
                    <?php
			
		   $sql="select * from tm_art_class order by art_id";
		  $rsql=mysql_query($sql);
		  while($rs=mysql_fetch_object($rsql))
		  {
			  ?>
                    <option value="<?php echo $rs->art_id;?>"><?php echo $rs->art_name;?></option>
                    <?php
			  }
			  ?>
              </select></TD>
    </TR>
       <TR BORDER="0" WIDTH="100%">
              <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left bgColor=#ffffff height=20>文章来源：
                  <select name="zid" id="zid">
                    <?php
			$sql="select * from tm_zt_class order by zt_id";
		  $rsql=mysql_query($sql);
		  while($rs=mysql_fetch_object($rsql))
		  {
			  ?>
                    <option value="<?php echo $rs->zt_name;?>"><?php echo $rs->zt_name;?></option>
                    <?php
			  }
			  ?>
                  </select>
	     &nbsp;&nbsp;</TD>
    </TR>
			<TR BORDER="0" WIDTH="100%">
                <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left bgColor=#ffffff height=20>标签：
                  <select name="tag" id="tag">
                    <option value="0">选择标签</option>
                    <?php
			$sql="select * from tm_tag order by tag_id desc";
		  $rsql=mysql_query($sql);
		  while($rs=mysql_fetch_object($rsql))
		  {
			  ?>
                    <option value="<?php echo $rs->tag_id;?>"><?php echo $rs->tag_name;?></option>
                    <?php
			  }
			  ?>
                  </select>
                  &nbsp;&nbsp;如不存在标签,请添加标签：                  
              <input name="zt_name" type="text" id="zt_name" size="20" /></TD>
    </TR>
			<TR BORDER="0" WIDTH="100%">
                <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left bgColor=#ffffff height=30><span class="help">
                  <input type="image" 
                        src="images/submit.gif" align="absmiddle" border="0" 
                        name="submit" onclick="return checkform(this.form)" />
                  <input name="action" type="hidden" id="action" value="add" />
                </span></TD>
              </TR>
 </form>
 <script language="javascript">
function checkform(theform)
{
if(theform.art_title.value=="")
  {
  alert("文章标题不能为空！");
  theform.art_title.focus();
  return false;
  }
if(theform.art_title.value.length > 100)
	{
		alert("文章标题太长哦!!");
		theform.art_title.focus();
		return false;
	}
if(theform.art_class.value==0)
	{
		alert("日志分类还没有选择哦,如果没有分类请先添加哦!!");
		theform.art_class.focus();
		return false;
	}
return true;
}
</script>
 <?php 
 }
if($action=="" and $id<>"")
{
if($uid==1)
$sql="select * from tm_art where art_id='$id'";
else
$sql="select * from tm_art where art_id='$id' and uid='$uid'";
$rsql=mysql_query($sql);
$rs=mysql_fetch_object($rsql);
if(!$rs)
   {
   echo "<script>alert('无相关文章!');location.href='art.php'</script>";
   exit();
   }
 ?>
 <form id="form1" name="form1" method="post" action="art_w.php">
			<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">标题：
                                  <input name="art_title" type="text" id="art_title" value="<?php echo $rs->art_title;?>" size="50" />
              </span>			                  </TD>
    </TR>
	<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">作者：
                                  <input name="art_name" type="text" id="art_name" value="<?php echo $rs->art_name;?>" size="50" />
              </span>			                  </TD>
    </TR>
			<TR BORDER="0" WIDTH="100%">
			                  <TD height="20">
							  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="50"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">导读：</span></td>
                    <td><?php
	include_once('../fckeditor/fckeditor.php'); 
	$editor1 = new FCKeditor("art_key");
    $editor1->BasePath   = '../fckeditor/';
    $editor1->ToolbarSet = 'Default';
    $editor1->Width      = '100%';
    $editor1->Height     = '170';
    $editor1->Value      = $rs->art_key;;
    $FCKeditor = $editor1->Create(); 
?></td>
                  </tr>
                </table></TD>
    </TR>
		<TR BORDER="0" WIDTH="100%">
                <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left bgColor=#ffffff height=30><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="43">内容：</td>
                    <td><?php
	include_once('../fckeditor/fckeditor.php'); 
	$editor = new FCKeditor("content");
    $editor->BasePath   = '../fckeditor/';
    $editor->ToolbarSet = 'Default';
    $editor->Width      = '100%';
    $editor->Height     = '370';
    $editor->Value      = $rs->art_cont;
    $FCKeditor = $editor->Create(); 
?></td>
                  </tr>
                </table></TD>
    </TR>
			<TR BORDER="0" WIDTH="100%">
                <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left bgColor=#ffffff height=20>日志分类：
                  <select name="art_class" id="art_class">
                    <?php
		  $sql="select * from tm_art_class order by art_id";
		  $rsql=mysql_query($sql);
		  while($rs2=mysql_fetch_object($rsql))
		  {
			  ?>
                    <option value="<?php echo $rs2->art_id;?>" <?php if($rs->art_class==$rs2->art_id) echo "selected";?>><?php echo $rs2->art_name;?></option>
                    <?php
			  }
			  ?>
              </select></TD>
    </TR>
<TR BORDER="0" WIDTH="100%">
                <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left bgColor=#ffffff height=20>
				  文章来源：
                  <select name="zid" id="zid">
                    <?php
			$sql="select * from tm_zt_class order by zt_id";
		  $rsql=mysql_query($sql);
		  while($rst=mysql_fetch_object($rsql))
		  {
			  ?>
                    <option value="<?php echo $rst->zt_name;?>" <?php if($rs->art_zt<>"" and $rs->art_zt==$rst->zt_name) echo 'selected="selected"'; ?>><?php echo $rst->zt_name;?></option>
                    <?php
			  }
			  ?>
                  </select>      </TD>
    </TR>
			<TR BORDER="0" WIDTH="100%">
                <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left bgColor=#ffffff height=20>标签：
                  <select name="tag" id="tag">
                    <option value="0">选择标签</option>
                    <?php
			$sql="select * from tm_tag order by tag_id desc";
		  $rsql=mysql_query($sql);
		  while($rs3=mysql_fetch_object($rsql))
		  {
			  ?>
                    <option value="<?php echo $rs3->tag_id;?>" <?php if($rs->art_tag==$rs3->tag_id) echo "selected";?>><?php echo $rs3->tag_name;?></option>
                    <?php
			  }
			  ?>
                  </select>
              &nbsp;&nbsp;如不分标签无需选择</TD>
    </TR>
			<TR BORDER="0" WIDTH="100%">
                <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left bgColor=#ffffff height=30><span class="help">
                  <input type="image" 
                        src="images/submit.gif" align="absmiddle" border="0" 
                        name="submit" onclick="return checkform(this.form)" />
                  <input name="action" type="hidden" id="action" value="edit" />
                  <input name="id" type="hidden" id="id" value="<?php echo $id;?>" />
                </span></TD>
              </TR>
 </form>
<script language="javascript">
function checkform(theform)
{
if(theform.art_title.value=="")
  {
  alert("文章标题不能为空！");
  theform.art_title.focus();
  return false;
  }
if(theform.art_title.value.length > 100)
	{
		alert("文章标题太长哦!!");
		theform.art_title.focus();
		return false;
	}
return true;
}
</script>
 <?PHP }
 ?>
      </TABLE>
</td>
</tr></table></div>

<?php include "boot.php";?>
</body></html>
<script language="JavaScript" >

function chkform(theForm,msg,action){
	if (confirm(msg)){

		document.forms[theForm].action.value = action;
		document.forms[theForm].submit();
		return true;
	}else{
		return false;
	}
}

// -------- 全選或取消 checkbox 方塊
<!--
function select_all(formName, elementName, selectAllName) {
	if(document.forms[formName].elements[selectAllName].checked) {
		
		if(document.forms[formName].elements[selectAllName].length = 1 &&
		    typeof(document.forms[formName].elements[elementName]) != "undefined" ) {
		
			document.forms[formName].elements[elementName].checked = true;

		    for(var i = 0; i < document.forms[formName].elements[elementName].length; i++)
			document.forms[formName].elements[elementName][i].checked = true;
		}
	}
	else {
		if(document.forms[formName].elements[selectAllName].length = 1 &&
		    typeof(document.forms[formName].elements[elementName]) != "undefined" ) {
			document.forms[formName].elements[elementName].checked = false;

		    for(var i = 0; i < document.forms[formName].elements[elementName].length; i++)
				document.forms[formName].elements[elementName][i].checked = false;
		}
	}
}
//-->
</script>