<?
if ($Submit=="提交" && $cookiename){
include "config.php";
if ($cookiename != $adname | $cookiepass != $adpass){
echo "密码或管理员名错误";
exit;}
if (!$newsbiaoti){echo 标题未填写;exit;}
if (!$newsneirong){echo 内容未填写;exit;}
if (!$tupian){echo 图片选项未填写;exit;}
$time = getdate();
$getdate = "(".$time[year]."-".$time[mon]."-".$time[mday]." ".$time[hours].":".$time[minutes].")";
if (strlen($time[mon]) <2){$time[mon] = "0".$time[mon];}
if (strlen($time[mday]) <2){$time[mday] = "0".$time[mday];}
$gettime = $time[year].$time[mon].$time[mday];
$get = mysql_query("SELECT MAX(id) AS id FROM $table",$connect);
$getdata = mysql_fetch_array($get);
if (substr($getdata[id],0,8) != $gettime){
$writetime=$gettime."001";}else{
$writetime=$getdata[id]+1;}
$writetime = (string) $writetime;
if (!$newslaiyuan){$newslaiyuan ="本站报道";}
$dirname=$htmlpath.$gettime;
$picname=$htmlpath.$gettime."/img";
if (!file_exists($dirname)) {
mkdir($dirname, 0777);
mkdir($picname, 0777);
}
chmod($picname,0777);
chmod($dirname,0777);
$htmlfile = substr($writetime,8,3);
switch($listkey){
case "果城新闻":
$elist="guocheng";
break;
case "国内新闻";
$elist="guonei";
break;
case "国际新闻";
$elist="guoji";
break;
case "经济新闻";
$elist="jingji";
break;
case "娱乐新闻";
$elist="yule";
break;}
$newsbiaoti =str_replace(" "," ",$newsbiaoti);
$newsneirong =str_replace('"',"'",$newsneirong);
if ($tupian == "2"){
$inputdata = "insert into $table (id,newsname,newsdate,newstype,newsphoto)
values ('$writetime','$newsbiaoti','$getdate','$listkey','1')";
$putdata = mysql_query($inputdata,$connect);
if ($putdata){echo "<center>数据库写入成功</center><br>";
}else{echo 数据库写入失败;exit;}
include "model.php";
$writename =$dirname."/".$htmlfile.".htm";
$fp=fopen($writename,"w");
$ww=fputs($fp,$model);
if ($ww){echo "<center>文件写入成功</center>";
}else{echo 文件写入失败;exit;}
echo "<meta http-equiv="refresh" content="2;URL=news.php?action=main">";
exit;
}elseif ($tupian =="1"){
$inputdata = "insert into $table (id,newsname,newsdate,newstype,newsphoto)
values ('$writetime','$newsbiaoti','$getdate','$listkey','2')";
$putdata = mysql_query($inputdata,$connect);
if (!$putdata){echo 数据库写入失败;exit;}
$writename =$dirname."/".$htmlfile.".htm";
setcookie("newsbiaoti",$newsbiaoti);
setcookie("newslaiyuan",$newslaiyuan);
setcookie("getdate",$getdate);
setcookie("picname",$picname);
setcookie("elist",$elist);
setcookie("writename",$writename);
$fp=fopen($htmlpath."temp.txt","w");
$ww = fputs($fp,$newsneirong);
if (!$ww){echo 文件写入错误;exit;}
echo"<html>
<head>
<title>图片处理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF">
<div align="center">
<p>图片链接或上传</p>
<form method="post" action="">
<p>链接</p>
<p>
<input type="text" name="picurl">
<input type="submit" name="Submit1" value="提交">
</p>
</form>
<p> </p>
<form method="post" action="" enctype="multipart/form-data">
<p>上传</p>
<p>
<input type="file" name="file">
<input type="submit" name="Submit2" value="上传">
</p>
</form>
<p> </p>
</div>
</body>
</html>";
exit;
}}
if ($Sunmit2 == "上传" && $cookiename){
include "config.php";
if ($cookiename != $adname | $cookiepass != $adpass){
echo "密码或管理员名错误";
exit;}
$fp=fopen($htmlpath."temp.txt","r+");
$newsneirong =fread($fp,filesize($htmlpath."temp.txt"));
exec("cp $file $picname/$file_name");
$newsimage = "<img src=".$$htmlurl."/img/".$file_name.">";
include "model.php";
$fp=fopen($writename,"w");
$ww=fputs($fp,$model);
setcookie("newsbiaoti");
setcookie("newslaiyuan");
setcookie("getdate");
setcookie("picname");
setcookie("elist");
setcookie("writename");
if ($ww){echo "<center>文件写入成功</center>";
}else{echo 文件写入失败;exit;}
echo "<meta http-equiv="refresh" content="2;URL=news.php?action=main">";
exit;}
if ($Submit1 =="提交" && $cookiename){
include "config.php";
if ($cookiename != $adname | $cookiepass != $adpass){
echo "密码或管理员名错误";
exit;}
$fp=fopen($htmlpath."temp.txt","r+");
$newsneirong =fread($fp,filesize($htmlpath."temp.txt"));
$newsimage = "<img src=".$picurl.">";
include "model.php";
$fp=fopen($writename,"w");
$ww=fputs($fp,$model);
setcookie("newsbiaoti");
setcookie("newslaiyuan");
setcookie("getdate");
setcookie("picname");
setcookie("elist");
setcookie("writename");
if ($ww){echo "<center>文件写入成功</center>";
}else{echo 文件写入失败;exit;}
echo "<meta http-equiv="refresh" content="2;URL=news.php?action=main">";
exit;}
if ($action == "makejs" && $cookiename){
include "config.php";
if ($cookiename != $adname | $cookiepass != $adpass){
echo "密码或管理员名错误";
exit;}
echo "<html>
<head>
<title>JS创建</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF">
<div align="center">
<p>创建JS选项<br>
<a href=news.php?action=main>main</a></p>
<form method="post" action="add.php">
<p>
<input type="radio" name="checkbox" value="1">
首页新闻JS</p>
<p>
<input type="radio" name="checkbox" value="2">
果城新闻JS</p>
<p>
<input type="radio" name="checkbox" value="3">
国际新闻JS</p>
<p>
<input type="radio" name="checkbox" value="4">
国内新闻JS</p>
<p>
<input type="radio" name="checkbox" value="5">
娱乐新闻JS</p>
<p>
<input type="radio" name="checkbox" value="6">
经济新闻JS</p>
<p>
<input type="submit" name="Submit" value="建立">
</p>
</form>
</div>
</body>
</html>";
exit;
}
if ($Submit == "建立" && $cookiename){
include "config.php";
if ($cookiename != $adname | $cookiepass != $adpass){
echo "密码或管理员名错误";
exit;}
switch($checkbox){
case 1:
$getjs[1]="select * from $table where newstype='果城新闻' order by id desc limit 0,2";
$getjs[2]="select * from $table where newstype='国内新闻' order by id desc limit 0,2";
$getjs[3]="select * from $table where newstype='国际新闻' order by id desc limit 0,2";
$getjs[4]="select * from $table where newstype='娱乐新闻' order by id desc limit 0,2";
$getjs[5]="select * from $table where newstype='经济新闻' order by id desc limit 0,2";
$jsname =$newspath."index.js";
$writeurl="document.write('";
$fp=fopen($jsname,"w");
$ww=fputs($fp,$writeurl);
if ($ww){echo "<center>首页新闻JS文件头写入成功</center><br>";
}else{echo 首页新闻JS文件头写入失败;exit;}
for ($i=1;$i<=5;$i++){
$get=mysql_query($getjs[$i]);
while($getdata=mysql_fetch_array($get)){
if ($getdata[newsphoto]=="1"){
$showpic ="";}elseif($getdata[newsphoto]=="2"){
$showpic ="<img src =".$newsurl."pic/news_icon.gif>";}
$showhtml ="<a href=".$htmlurl.substr($getdata[id],0,8)."/".substr($getdata[id],8,3).".htm target=_blank>".$getdata[newsname]."</a>";
$writeurl="<img src=".$newsurl."pic/t.gif>".$showhtml.$showpic.$getdata[newsdate]."[".$getdata[newstype]."]<br>";
$fp=fopen($jsname,"a");
$ww=fputs($fp,$writeurl);
if (!$ww){echo 首页新闻JS文件头写入失败;exit;}
}
}
$writeurl="<div align=right><a href=".$prourl."show.php?listkey=index>更多新闻...</a> </div>');";
$fp=fopen($jsname,"a");
$ww=fputs($fp,$writeurl);
if ($ww){echo "<center>首页新闻JS文件尾写入成功</center><br>";
}else{echo 首页新闻JS文件尾写入失败;exit;}
break;
case 2;
$jsname =$newspath."guocheng.js";
$writeurl="document.write('<div align=center>果城新闻</div><br>";
$fp=fopen($jsname,"w");
$ww=fputs($fp,$writeurl);
if ($ww){echo "<center>果城新闻JS文件头写入成功</center><br>";
}else{echo 果城新闻JS文件头写入失败;exit;}
$getjs="select * from $table where newstype='果城新闻' order by id desc limit 0,10";
$get=mysql_query($getjs);
while($getdata=mysql_fetch_array($get)){
if ($getdata[newsphoto]=="1"){
$showpic ="";}elseif($getdata[newsphoto]=="2"){
$showpic ="<img src =".$newsurl."pic/news_icon.gif>";}
$showhtml ="<a href=".$htmlurl.substr($getdata[id],0,8)."/".substr($getdata[id],8,3).".htm target=_blank>".$getdata[newsname]."</a>";
$writeurl="<img src=".$newsurl."pic/t.gif>".$showhtml.$showpic.$getdata[newsdate]."<br>";
$fp=fopen($jsname,"a");
$ww=fputs($fp,$writeurl);
if (!$ww){echo 果城新闻JS文件头写入失败;exit;}
}
$writeurl="');";
$fp=fopen($jsname,"a");
$ww=fputs($fp,$writeurl);
if ($ww){echo "<center>果城新闻JS文件尾写入成功</center><br>";
}else{echo 果城新闻JS文件尾写入失败;exit;}
break;
case 3;
$jsname =$newspath."guoji.js";
$writeurl="document.write('<div align=center>国际新闻</div><br>";
$fp=fopen($jsname,"w");
$ww=fputs($fp,$writeurl);
if ($ww){echo "<center>国际新闻JS文件头写入成功</center><br>";
}else{echo 国际新闻JS文件头写入失败;exit;}
$getjs="select * from $table where newstype='国际新闻' order by id desc limit 0,10";
$get=mysql_query($getjs);
while($getdata=mysql_fetch_array($get)){
if ($getdata[newsphoto]=="1"){
$showpic ="";}elseif($getdata[newsphoto]=="2"){
$showpic ="<img src =".$newsurl."pic/news_icon.gif>";}
$showhtml ="<a href=".$htmlurl.substr($getdata[id],0,8)."/".substr($getdata[id],8,3).".htm target=_blank>".$getdata[newsname]."</a>";
$writeurl="<img src=".$newsurl."pic/t.gif>".$showhtml.$showpic.$getdata[newsdate]."<br>";
$fp=fopen($jsname,"a");
$ww=fputs($fp,$writeurl);
if (!$ww){echo 国际新闻JS文件头写入失败;exit;}
}
$writeurl="');";
$fp=fopen($jsname,"a");
$ww=fputs($fp,$writeurl);
if ($ww){echo "<center>国际新闻JS文件尾写入成功</center><br>";
}else{echo 国际新闻JS文件尾写入失败;exit;}
break;
case 4;
$jsname =$newspath."guonei.js";
$writeurl="document.write('<div align=center>国内新闻</div><br>";
$fp=fopen($jsname,"w");
$ww=fputs($fp,$writeurl);
if ($ww){echo "<center>国内新闻JS文件头写入成功</center><br>";
}else{echo 国内新闻JS文件头写入失败;exit;}
$getjs="select * from $table where newstype='国内新闻' order by id desc limit 0,10";
$get=mysql_query($getjs);
while($getdata=mysql_fetch_array($get)){
if ($getdata[newsphoto]=="1"){
$showpic ="";}elseif($getdata[newsphoto]=="2"){
$showpic ="<img src =".$newsurl."pic/news_icon.gif>";}
$showhtml ="<a href=".$htmlurl.substr($getdata[id],0,8)."/".substr($getdata[id],8,3).".htm target=_blank>".$getdata[newsname]."</a>";
$writeurl="<img src=".$newsurl."pic/t.gif>".$showhtml.$showpic.$getdata[newsdate]."<br>";
$fp=fopen($jsname,"a");
$ww=fputs($fp,$writeurl);
if (!$ww){echo 国内新闻JS文件头写入失败;exit;}
}
$writeurl="');";
$fp=fopen($jsname,"a");
$ww=fputs($fp,$writeurl);
if ($ww){echo "<center>国内新闻JS文件尾写入成功</center><br>";
}else{echo 国内新闻JS文件尾写入失败;exit;}
break;
case 5;
$jsname =$newspath."yule.js";
$writeurl="document.write('<div align=center>娱乐新闻</div><br>";
$fp=fopen($jsname,"w");
$ww=fputs($fp,$writeurl);
if ($ww){echo "<center>娱乐新闻JS文件头写入成功</center><br>";
}else{echo 娱乐新闻JS文件头写入失败;exit;}
$getjs="select * from $table where newstype='娱乐新闻' order by id desc limit 0,10";
$get=mysql_query($getjs);
while($getdata=mysql_fetch_array($get)){
if ($getdata[newsphoto]=="1"){
$showpic ="";}elseif($getdata[newsphoto]=="2"){
$showpic ="<img src =".$newsurl."pic/news_icon.gif>";}
$showhtml ="<a href=".$htmlurl.substr($getdata[id],0,8)."/".substr($getdata[id],8,3).".htm target=_blank>".$getdata[newsname]."</a>";
$writeurl="<img src=".$newsurl."pic/t.gif>".$showhtml.$showpic.$getdata[newsdate]."<br>";
$fp=fopen($jsname,"a");
$ww=fputs($fp,$writeurl);
if (!$ww){echo 娱乐新闻JS文件头写入失败;exit;}
}
$writeurl="');";
$fp=fopen($jsname,"a");
$ww=fputs($fp,$writeurl);
if ($ww){echo "<center>娱乐新闻JS文件尾写入成功</center><br>";
}else{echo 娱乐新闻JS文件尾写入失败;exit;}
$jsname =$newspath."yule2.js";
$writeurl="document.write('";
$fp=fopen($jsname,"w");
$ww=fputs($fp,$writeurl);
if ($ww){echo "<center>娱乐新闻2JS文件头写入成功</center><br>";
}else{echo 娱乐新闻2JS文件头写入失败;exit;}
$getjs="select * from $table where newstype='娱乐新闻' order by id desc limit 0,10";
$get=mysql_query($getjs);
while($getdata=mysql_fetch_array($get)){
if ($getdata[newsphoto]=="1"){
$showpic ="";}elseif($getdata[newsphoto]=="2"){
$showpic ="<img src =".$newsurl."pic/news_icon.gif>";}
$showhtml ="<a href=".$htmlurl.substr($getdata[id],0,8)."/".substr($getdata[id],8,3).".htm target=_blank>".$getdata[newsname]."</a>";
$writeurl="<img src=".$newsurl."pic/t.gif>".$showhtml.$showpic.$getdata[newsdate]."<br>";
$fp=fopen($jsname,"a");
$ww=fputs($fp,$writeurl);
if (!$ww){echo 娱乐新闻2JS文件头写入失败;exit;}
}
$writeurl="');";
$fp=fopen($jsname,"a");
$ww=fputs($fp,$writeurl);
if ($ww){echo "<center>娱乐新闻2JS文件尾写入成功</center><br>";
}else{echo 娱乐新闻2JS文件尾写入失败;exit;}
break;
case 6;
$jsname =$newspath."jingji.js";
$writeurl="document.write('<div align=center>经济新闻</div><br>";
$fp=fopen($jsname,"w");
$ww=fputs($fp,$writeurl);
if ($ww){echo "<center>经济新闻JS文件头写入成功</center><br>";
}else{echo 经济新闻JS文件头写入失败;exit;}
$getjs="select * from $table where newstype='经济新闻' order by id desc limit 0,10";
$get=mysql_query($getjs);
while($getdata=mysql_fetch_array($get)){
if ($getdata[newsphoto]=="1"){
$showpic ="";}elseif($getdata[newsphoto]=="2"){
$showpic ="<img src =".$newsurl."pic/news_icon.gif>";}
$showhtml ="<a href=".$htmlurl.substr($getdata[id],0,8)."/".substr($getdata[id],8,3).".htm target=_blank>".$getdata[newsname]."</a>";
$writeurl="<img src=".$newsurl."pic/t.gif>".$showhtml.$showpic.$getdata[newsdate]."<br>";
$fp=fopen($jsname,"a");
$ww=fputs($fp,$writeurl);
if (!$ww){echo 经济新闻JS文件头写入失败;exit;}
}
$writeurl="');";
$fp=fopen($jsname,"a");
$ww=fputs($fp,$writeurl);
if ($ww){echo "<center>经济新闻JS文件尾写入成功</center><br>";
}else{echo 经济新闻JS文件尾写入失败;exit;}
}
echo "<meta http-equiv="refresh" content="2;URL=add.php?action=makejs">";
}
?>
这是第一版,写的有点粗糙,而且没有按照模块方式写!但能很好的工作!
|