<?php
$FILENAME=time();
$FILENAME1=time()."s";

// 生成图片的宽度
$RESIZEWIDTH=200;
$RESIZEWIDTH1=100;

// 生成图片的高度
$RESIZEHEIGHT=150;
$RESIZEHEIGHT1=75;
//生成图片的路径
$uploaddir="../../userfiles/";

function ResizeImage($im,$maxwidth,$maxheight,$name){
global $uploaddir;
$width = imagesx($im);
$height = imagesy($im);
if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
if($maxwidth && $width > $maxwidth){
$widthratio = $maxwidth/$width;
$RESIZEWIDTH=true;
}
if($maxheight && $height > $maxheight){
$heightratio = $maxheight/$height;
$RESIZEHEIGHT=true;
}
if($RESIZEWIDTH && $RESIZEHEIGHT){
if($widthratio < $heightratio){
$ratio = $widthratio;
}else{
$ratio = $heightratio;
}
}elseif($RESIZEWIDTH){
$ratio = $widthratio;
}elseif($RESIZEHEIGHT){
$ratio = $heightratio;
}
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
if(function_exists("imagecopyresampled")){
$newim = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}else{
$newim = imagecreate($newwidth, $newheight);
imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
imagejpeg ($newim,$uploaddir.$name . ".jpg");
imagedestroy ($newim);
}else{
imagejpeg ($im,$uploaddir.$name . ".jpg");
}
}

function ResizeImage1($im,$maxwidth,$maxheight,$name){
global $uploaddir;
$width = imagesx($im);
$height = imagesy($im);
if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
if($maxwidth && $width > $maxwidth){
$widthratio = $maxwidth/$width;
$RESIZEWIDTH=true;
}
if($maxheight && $height > $maxheight){
$heightratio = $maxheight/$height;
$RESIZEHEIGHT=true;
}
if($RESIZEWIDTH && $RESIZEHEIGHT){
if($widthratio < $heightratio){
$ratio = $widthratio;
}else{
$ratio = $heightratio;
}
}elseif($RESIZEWIDTH){
$ratio = $widthratio;
}elseif($RESIZEHEIGHT){
$ratio = $heightratio;
}
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
if(function_exists("imagecopyresampled")){
$newim = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}else{
$newim = imagecreate($newwidth, $newheight);
imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
imagejpeg ($newim,$uploaddir.$name . ".jpg");
imagedestroy ($newim);
}else{
imagejpeg ($im,$uploaddir.$name . ".jpg");
}
}


if($_FILES['image']['size']){
if($_FILES['image']['type'] == "image/pjpeg"){
$im = imagecreatefromjpeg($_FILES['image']['tmp_name']);
}elseif($_FILES['image']['type'] == "image/x-png"){
$im = imagecreatefrompng($_FILES['image']['tmp_name']);
}elseif($_FILES['image']['type'] == "image/gif"){
$im = imagecreatefromgif($_FILES['image']['tmp_name']);
}
if($im){
if(file_exists("$FILENAME.jpg")){
unlink("$FILENAME.jpg");
}
ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$FILENAME);
ResizeImage1($im,$RESIZEWIDTH1,$RESIZEHEIGHT1,$FILENAME1);
imagedestroy ($im);
}
}
if($_FILES['image']['size'])
{
$photo_small="userfiles/".$FILENAME.".jpg";
$photo_small1="userfiles/".$FILENAME."s.jpg";
}
else
{
$photo_small="";
$photo_small1="";
}

$action=_get('action');
if($action=="")
$action=_post('action');
$id=_get('id');
if($id=="")
$id=_post('id');

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);
}
 if($action=="del")
 {
$COUT=count($_POST[ChkKindId]); 
$action=_post('action');
for($i=0;$i<$COUT;$i++)
    {
$RECORD_ID=$ChkKindId[$i];
$exec="delete from news_art where id=".$RECORD_ID;
mysql_query($exec);
    }
 echo "<script>location.href='art.php';</script>";
 exit();
 }
elseif($action=="tj")
 {
$COUT=count($_POST[ChkKindId]); 
$action=_post('action');
for($i=0;$i<$COUT;$i++)
    {
$RECORD_ID=$ChkKindId[$i];
$exec="update news_art set tj=1,show1=1 where id=".$RECORD_ID;
mysql_query($exec);
    }
 echo "<script>location.href='art.php';</script>";
 exit();
 }
elseif($action=="utj")
 {
$COUT=count($_POST[ChkKindId]); 
$action=_post('action');
for($i=0;$i<$COUT;$i++)
    {
$RECORD_ID=$ChkKindId[$i];
$exec="update news_art set tj=0 where id=".$RECORD_ID;
mysql_query($exec);
    }
 echo "<script>location.href='art.php';</script>";
 exit();
 }
elseif($action=="sh")
 {
$COUT=count($_POST[ChkKindId]); 
$action=_post('action');
for($i=0;$i<$COUT;$i++)
    {
$RECORD_ID=$ChkKindId[$i];
$exec="update news_art set show1=1 where id=".$RECORD_ID;
mysql_query($exec);
    }
 echo "<script>location.href='art.php';</script>";
 exit();
 }
elseif($action=="ush")
 {
$COUT=count($_POST[ChkKindId]); 
$action=_post('action');
for($i=0;$i<$COUT;$i++)
    {
$RECORD_ID=$ChkKindId[$i];
$exec="update news_art set show1=0 where id=".$RECORD_ID;
mysql_query($exec);
    }
 echo "<script>location.href='art.php';</script>";
 exit();
 }
elseif($action=="add")
{
$title=_post('title');
$incont=$_POST[incont];
$name=_post('name');
$cont=_post('cont');
$uid=0;
$aid=$_POST[aid];
$aid1=$_POST[aid1];
$tid=$_POST[tid];
$date=$_POST[date];
mysql_query("insert into news_art(title,cont,date,uid,incont,name,aid,img,imgs,tid,aid1) values('$title','$cont','$date','$uid','$incont','$name','$aid','$photo_small','$photo_small1','$tid','$aid1')");
echo "<script>location.href='ahtml.php?id=".mysql_insert_id()."';</script>";
exit();
}
elseif($action=="edit")
{
$title=_post('title');
$incont=$_POST[incont];
$name=_post('name');
$cont=_post('cont');
$aid=$_POST[aid];
$aid1=$_POST[aid1];
$tid=$_POST[tid];
$date=$_POST[date];
if($photo_small<>"")
mysql_query("update news_art set title='$title',cont='$cont',aid='$aid',aid1='$aid1',tid='$tid',incont='$incont',img='$photo_small',imgs='$photo_small1',date='$date' where id='$id'");
else
mysql_query("update news_art set title='$title',cont='$cont',aid='$aid',aid1='$aid1',tid='$tid',incont='$incont',date='$date' where id='$id'");
echo "<script>location.href='ahtml.php?id=".$id."';</script>";
exit();
}
?>
<!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=gb2312" />
<LINK href="images/index.css" type=text/css rel=stylesheet />
</head>

<body>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0 
            CALLPADDING="0">
              <TBODY>
			                <TR BORDER="0" WIDTH="100%">
                <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left width="100%" bgColor=#ffffff height=20>
				  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="85%"><img src="images/url_01.gif" width="7" height="10" />&nbsp;<?php if($id=="") echo "<strong>添加文章</strong>";else echo "<strong>编辑文章</strong>";?></td>
                    <td width="15%">&nbsp;</td>
                  </tr>
                </table>				 </TD>
              </TR>
<?php 			  
if($action=="" and $id=="")
{
?>
<form id="join" name="join" method="post" action="art_w.php" enctype="multipart/form-data">
			<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">文章标题：
                                  <input name="title" type="text" id="title" style="width:300px;" />
			                      </span>&nbsp;
              &nbsp;</TD>
    </TR>
<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">文章作者：
                                  <input name="name" type="text" id="name" style="width:300px;" />
			                      </span>&nbsp;
      &nbsp;</TD>
    </TR>
<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">文章来源：
                                  <select name="incont" id="incont">
                                    <?php 
		  $sql="select * from art_in order by id asc";
		  $rsql=mysql_query($sql);
		  while($rst=mysql_fetch_object($rsql))
		  {
			?>
                                    <option value="<?php echo $rst->id;?>"><?php echo $rst->title;?></option>
                                    <?php
			 }
			 ?>
                                  </select>
      </span>&nbsp;</TD>
    </TR>
<TR BORDER="0" WIDTH="100%">
<TD height="20">
<span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">
发布日期:
<input name="date" type="text" id="date" value="<?php echo date('Y-m-d');?>" /> 
<span class="post_date">请参照此日期格式真写,否则不能入库</span></span></TD>
 </TR>
<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">顶级栏目：
<select name="aid" id="aid"  onChange="changelocation(document.join.aid.options[document.join.aid.selectedIndex].value)" size="1">
<OPTION selected value="0">顶级栏目</OPTION>
		    <?php 
		  $sql="select * from news_class where topid=0 order by px asc";
		  $rsql=mysql_query($sql);
		  while($rst=mysql_fetch_object($rsql))
		  {
			?>
            <option value="<?php echo $rst->id;?>"><?php echo $rst->title;?></option>
			<?php
			 }
			 ?>
          </select>
			<SELECT name="aid1" >
<OPTION selected value="0">二级栏目</OPTION>
</SELECT>                      </span>
      </TD>
    </TR>
<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">所属标签：
			                      <select name="tid" id="tid">
			<option value="0">请选择标签,没有请留空</option>
		    <?php 
		  $sql="select * from news_tag order by id asc";
		  $rsql=mysql_query($sql);
		  while($rst=mysql_fetch_object($rsql))
		  {
			?>
            <option value="<?php echo $rst->id;?>"><?php echo $rst->name;?></option>
			<?php
			 }
			 ?>
          </select>
			                      </span>
      </TD>
    </TR>
<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">文章内容：
                                  
          </span><span style="background:#F0F0F0">          </span></TD>
    </TR>
<TR BORDER="0" WIDTH="100%">
          <TD height="20">
<?php
	include_once('../../fckeditor/fckeditor.php'); 
	$editor = new FCKeditor("cont");
    $editor->BasePath   = '../../fckeditor/';
    $editor->ToolbarSet = 'Default';
    $editor->Width      = '100%';
    $editor->Height     = '250';
    $editor->Value      = '';
    $FCKeditor = $editor->Create(); 
?>		 </TD>
    </TR>
<TR BORDER="0" WIDTH="100%">
      <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left bgColor=#ffffff height=20>
				
			    图片展示：
			      <input name="image" type="file" id="image" />
      <span class="post_date">（宽300*高200,没有图片请留空）</span></p>			  </TD>
    </TR>
			<TR BORDER="0" WIDTH="100%">
                <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left bgColor=#ffffff height=20><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.title.value=="")
  {
  alert("文章标题不能为空！");
  theform.title.focus();
  return false;
  }
if(theform.aid1.value==0)
  {
  alert("请填写分类!!");
  theform.aid1.focus();
  return false;
  }
return true;
}
</script>
 <?php 
 }
if($action=="" and $id<>"")
{
$sql="select * from news_art where id='$id'";
$rsql=mysql_query($sql);
$rs=mysql_fetch_object($rsql);
 ?>
 <form id="join" name="join" method="post" action="art_w.php" enctype="multipart/form-data">
			<TR BORDER="0" WIDTH="100%">
              <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">文章标题：
<input name="title" type="text" id="title" style="width:300px;" value="<?php echo $rs->title;?>" />
			                      </span></TD>
    </TR>
<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">文章作者：
                                  <input name="name" type="text" id="name" style="width:300px;" value="<?php echo $rs->name;?>" />
			                      </span>&nbsp;
		                      &nbsp;</TD>
    </TR>
<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">文章来源：
                                  <select name="incont" id="incont">
                                    <?php 
		  $sql="select * from art_in order by id asc";
		  $rsql=mysql_query($sql);
		  while($rst=mysql_fetch_object($rsql))
		  {
			?>
                                    <option value="<?php echo $rst->id;?>" <?php if($rst->id==$rs->incont) echo 'selected="selected"';?>><?php echo $rst->title;?></option>
                                    <?php
			 }
			 ?>
                                  </select>
		                      </span>&nbsp;</TD>
    </TR>
<TR BORDER="0" WIDTH="100%">
<TD height="20">
<span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">
发布日期:
<input name="date" type="text" id="date" value="<?php echo $rs->date;?>" /> 
<span class="post_date">请参照此日期格式真写,否则不能入库</span></span></TD>
 </TR>
<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">所属栏目：
<select name="aid" id="aid" onChange="changelocation(document.join.aid.options[document.join.aid.selectedIndex].value)" size="1">
<OPTION selected value="0">顶级栏目</OPTION>
		    <?php 
		  $sql="select * from news_class where topid=0 order by px desc";
		  $rsql=mysql_query($sql);
		  while($rst=mysql_fetch_object($rsql))
		  {
			?>
            <option value="<?php echo $rst->id;?>" <?php if($rs->aid==$rst->id) echo 'selected="selected"';?>><?php echo $rst->title;?></option>
			<?php
			 }
			 ?>
          </select>&nbsp;
<SELECT name="aid1" >
<OPTION selected value="0">二级栏目</OPTION>
 <?php 
		  $sql="select * from news_class where topid=".$rs->aid." order by px desc";
		  $rsql=mysql_query($sql);
		  while($rst=mysql_fetch_object($rsql))
		  {
			?>
<option value="<?php echo $rst->id;?>" <?php if($rs->aid1==$rst->id) echo 'selected="selected"';?>><?php echo $rst->title;?></option>			
<?php
			 }
			 ?>
</SELECT>
			                      </span>
		                      </TD>
    </TR>
<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">所属标签：
			                      <select name="tid" id="tid">
			<option value="0">请选择标签,没有请留空</option>
		    <?php 
		  $sql="select * from news_tag order by id desc";
		  $rsql=mysql_query($sql);
		  while($rst=mysql_fetch_object($rsql))
		  {
			?>
            <option value="<?php echo $rst->id;?>" <?php if($rs->tid==$rst->id) echo 'selected="selected"';?>><?php echo $rst->name;?></option>
			<?php
			 }
			 ?>
          </select>
			                      </span>
		                      </TD>
    </TR>
<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><span style="PADDING-LEFT: 8px; PADDING-TOP: 8px">文章内容：
          </span></TD>
    </TR>
<TR BORDER="0" WIDTH="100%">
			                  <TD height="20"><?php
	include_once('../../fckeditor/fckeditor.php'); 
	$editor = new FCKeditor("cont");
    $editor->BasePath   = '../../fckeditor/';
    $editor->ToolbarSet = 'Default';
    $editor->Width      = '100%';
    $editor->Height     = '250';
    $editor->Value      = $rs->cont;
    $FCKeditor = $editor->Create(); 
?></TD>
    </TR>
<TR BORDER="0" WIDTH="100%">
                <TD style="PADDING-LEFT: 3px; PADDING-TOP: 3px; background:#FFFFFF;" vAlign=top align=left height=30>
				<?php if($rs->img<>"") 
				echo '<p><img src="../../'.$rs->imgs.'" />';
				?>&nbsp;
			    形像图片：
			    <input name="image" type="file" id="image" />
                <span class="post_date">（宽300*高200图片不变动请留空无需上传）</span></p>			  </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.title.value=="")
  {
  alert("文章标题不能为空！");
  theform.title.focus();
  return false;
  }
if(theform.aid1.value==0)
  {
  alert("请填写分类!!");
  theform.aid1.focus();
  return false;
  }
return true;
}
</script>
 <?PHP }
 ?>
</TABLE>
</BODY></HTML>
<?php include("arca.php");?>