<?php
require_once(dirname(__FILE__)."/admin_inc.php");
/*******************************************************************************************
' Software name: DJCMS Content Management System
' Version:3.0
' Web: http://www.djcms.net
' Author: 心情(qq:1130731)
' Copyright (C) 2009-2010 DJCMS官方 版权所有
' 法律申明：DJCMS程序所有代码100%原创、未引入任何网上代码,对一切抄袭行为、坚决严肃追究法律责任
'*******************************************************************************************/
viewHead("新闻管理"."-" .$menuList[1][0]);
$action = getForm("action", "get");
switch ($action) {
	case "add":addNews();break;
	case "moverecycle":delAll(getForm("m_id","both"),"recycle");alertMsg("",getRefer());break;
	case "delall":delAll(getForm("m_id","post"),"del");alertMsg("",getRefer());break;
	case "del":delNews(getForm("id","get"),"del");alertMsg("",getRefer());break;
	case "restore":restoreNews();break;
	case "edit":editNews();break;
	case "save":saveNews();break;
	case "psettopic":pSetTopic();break;
	case "psettype":pSetType();break;
	case "deltypedata":delTypeData();break;
	case "single":CheckNews();break;
	case "recycle":main();break;
	default:main();popUpdatePic();break;
}
viewFoot();

function main() {
	global $action,$menuList;
	$number= 30;
	$star = getForm("star", "get");
	$order = getForm("order", "get");
	if (empty($order)) $order = "m_addtime";
	$orderStr = " ORDER BY {$order} DESC";
	$keyword = getForm("keyword", "both");$playfrom = getForm("playfrom", "both");
	$page = getForm("page", "get");
	$vtype = getForm("type", "both");
	$wherestr=" WHERE m_recycle=".ifthen($action == "recycle",1,0);
	$m_commend = getForm("m_commend", "get");
	if ($m_commend == "ok" && empty($star)) $wherestr .= " AND m_commend>0";
	if (!empty($star)) $wherestr .= " AND m_commend=$star";
	if ($action=="nullpic") $wherestr .= " AND m_pic=''";
	$repeat = getForm("repeat", "get");
	if ($repeat == "ok") {
		$dis_names = '';
        $rows = db::SELECT("SELECT m_title FROM ".DB::table('news')." GROUP BY m_title HAVING COUNT(*)>1");
        foreach ($rows as $row) {
			$dis_names .= "'".$row['m_title']."',";
        }
		$dis_names = rtrim($dis_names, ",");
		if (!empty($dis_names)) {
		    $wherestr .= " AND m_title IN({$dis_names})";
		} else {
		    $wherestr .= " 1=2";
		}
    }
	if (!empty($vtype)) $wherestr .= " AND `m_type` in(".getNewsTypeIdOnCache($vtype).")";
    if (!empty($keyword)) $wherestr .= " AND m_title LIKE '%".$keyword."%' OR m_keyword LIKE '%".$keyword."%' ";
    if (!empty($playfrom)) $wherestr .= " AND m_from LIKE '%".$playfrom."$$%' ";
	$sqlStr = replaceStr(replaceStr("SELECT m_id,m_title,m_hit,m_vid,m_type,m_commend,m_addtime,m_note,m_entitle,m_datetime FROM ".DB::table('news')." $wherestr$orderStr","WHERE AND","WHERE"),"WHERE ORDER","ORDER");
	$allRecordset = db::getCount($sqlStr);
	$tpagecount = ceil($allRecordset / $number);
	if ($page > $tpagecount) $page = $tpagecount;
?>
<div class="container" id="cpcontainer">
<table class="tb">
<tr class="thead"><th colspan="15"><?php if ($action != "recycle"){?>新闻管理(<a class="red" onclick="location.href='admin_datarelate.php?action=downpic&downtype=all&table=news';return false;" href="#">下载所有网络图片到本地</a>)<?php }else{ echo "新闻回收站";}?></th></tr>	
<tr><td align="left" colspan="10">  
<form action="?" method="get">
<input type="hidden" name="action" value="<?=$action?>">
关键字<input  name="keyword" type="text" id="keyword" size="20">
<select name="type" id="type" ><option value="">请选择文章分类</option>
    <?=makenewsTypeOption(0, "&nbsp;|&nbsp;&nbsp;")?>
	</select>
<input type="submit" name="SELECTBtn" value="查 询..." class="btn" />&nbsp;
<select  onchange="self.location.href='?action=<?=$action?>&type='+this.options[this.SELECTedIndex].value+'&m_commend=<?=$m_commend?>'">
<option value="">按文章分类查看</option>
    <?=makenewsTypeOptionSELECTed(0, "&nbsp;|&nbsp;&nbsp;",$type)?>
</select>
<select name="star" id="star" onChange="self.location.href='?action=<?=$action?>&star='+this.options[this.SELECTedIndex].value">
	<option value=''>按星级查看</option>
	<?php
    for ($i = 1;$i <= 5;$i++) {
	    if ($star == $i) {
		    echo "<option value='".$i."' SELECTed>".$i."星级</option>";
	    } else {
		    echo "<option value='".$i."'>".$i."星级</option>";
	    }
	}
	?>
</select>
</form>
</td>
</tr>
<?php
    if($allRecordset == 0) {
	    if (!empty($keyword))  echo "<tr align='center'><td>关键字  <font color=red>\"".$keyword."\"</font>   没有记录</td></tr>"; 
    } else {
	    if (!empty($keyword)) {
?>
  <tr ><td colspan="10">关键字  <font color=red> <?=$keyword?> </font>   的记录如下</td></tr>
<?php
    }
?>
  <tr bgcolor="#f5fafe">
	<td width="60">ID<a href="?action=<?=$action?>&order=m_id&type=<?=$type?>&page=<?=$page?>&m_commend=<?=$m_commend?>"><img src="imgs/minus.gif" title="按ID排序" /></a></td>
	<td>标题</td>
	<td width="35">人气<a href="?action=<?=$action?>&order=m_hit&type=<?=$type?>&page=<?=$page?>&m_commend=<?=$m_commend?>"><img src="imgs/minus.gif" title="按人气排序" /></a></td>
	<td width="72">数据类别</td>
	<td width="84">推荐星级<a href="?action=<?=$action?>&order=m_commend&type=<?=$type?>&page=<?=$page?>&m_commend=<?=$m_commend?>"><img src="imgs/minus.gif" title="按推荐星级排序" /></a></td>
	<td width="66">时间<a href="?action=<?=$action?>&order=m_addtime&type=<?=$type?>&page=<?=$page?>&m_commend=<?=$m_commend?>"><img src="imgs/minus.gif" title="按时间排序" /></a></td>
	<?php if (newsrunMode == "static" && $action != "recycle"){?><td width="30">生成</td><?php }?>
	<td width="118" align="center">操作</td>
  </tr><form method="post" name="newslistform">
<?php
$page = max(intval($page), 1);
$offset = $number*($page-1);
$query = DB::query("$sqlStr limit $offset, $number");
while($row = DB::fetch($query)) {
    $m_id = $row['m_id'];
    $contentUrl = getNewsArticleLink($row['m_type'], $row['m_id'],$row['m_entitle'],$row['m_datetime'], "");
?>
  <tr bgcolor="#f5fafe">
	<td><input type="checkbox" value="<?=$m_id?>" name="m_id[]"  class="checkbox" /><?=$m_id?></td>
	<td><a href="<?=$contentUrl?>" target="_blank"><?=$row['m_title']?></a> <?=parseNewsNote($row['m_note'])?></td>
	<td><?=$row['m_hit']?></td>
	<td><a href="?action=<?=$action?>&type=<?=$row['m_type']?>&order=<?=$order?>"><?=viewDataType($row['m_type'])?></a></td>
	<td id="star<?=$m_id?>"><script>starView(<?=$row['m_commend']?>,<?=$m_id?>)</script></td>
	<td><span title="<?=date('Y-m-d H:i:s',$row['m_addtime'])?>"><?=isCurrentDay($row['m_addtime'])?></span></td>
   <?php if (newsrunMode=="static" && $action!="recycle"){?><td align="center"><?php isVideoMake($m_id,$contentUrl)?></td><?php }?>
	<td><a href="?action=edit&id=<?=$m_id?>">编辑</a> <a href="?action=del&id=<?=$m_id?>" onClick="return confirm('确定要删除吗')">删除</a>
 <?php if ($action == "recycle"){?>
 <a href="?action=restore&m_id=<?=$m_id?>">还原</a>
<?php }else{?>
 <a href="?action=moverecycle&m_id=<?=$m_id?>">隐藏</a>
<?php } ?></td>
</tr>
<?php 
}
?>
<tr><td colspan="8"><div class="cuspages"><div class="pages">全选<input type="checkbox" name="chkall" id="chkall" class="checkbox" onclick="checkAll(this.checked,'input','m_id[]')" />反选<input type="checkbox" name="chkothers" id="chkothers" class="checkbox" onclick="checkOthers('input','m_id[]')" />
<?php if ($action=="recycle"){?>
	<input type="submit" value="数据还原" class="btn" onclick="newslistform.action='?action=restore';"> <input type="submit" value="永久删除" onclick="if(confirm('一但删除将无法恢复')){newslistform.action='?action=delall';}else{return false}" class="btn">
<?php }else{?>
	<input type="submit" value="批量删除" class="btn" onclick="if(confirm('确定要删除吗')){newslistform.action='?action=delall';}else{return false}"> <input type="submit" value="批量生成" class="btn" onclick="newslistform.action='admin_makehtml.php?action=newsSELECTed'" />
<?php }?>
	<select name="movetype" id="movetype"><option value="">请选择目标分类</option>
		<?=makenewsTypeOption(0,"&nbsp;|&nbsp;&nbsp;")?>
		</select>
	<input type="submit" value="批量移动" class="btn" onclick="if($('movetype').value==''){alert('请选择目标分类');return false;};if(confirm('确定要批量移动数据吗')){newslistform.action='?action=psettype'}else{return false;}"/>
<?php if ($action!="recycle"){?>
	<input type="submit" style="width:90px" value="删除分类数据" class="btn" onclick="if($('movetype').value==''){alert('请选择目标分类');return false;};if(confirm('谨慎操作，数据不可恢复\n确定要删除此分类的所有数据吗')){newslistform.action='?action=deltypedata'}else{return false;}"/>
<?php }?>
</div></div></td>
</tr>
</form>
<tr><td colspan="8" align="center"><?=fPageCount($allRecordset, $number, $page)?></td>
</tr>
<?php
}
?>
</table>
</div>
<script type="text/javascript">
window.commendVideo=function commendNews(vid,commendid){
	ajax.get(
		"admin_ajax.php?id="+vid+"&commendid="+commendid+"&action=commendnews", 
		function(obj){
			if(obj.responseText == "submitok"){
				starView(commendid,vid);
			}else{
				set($("star"+vid),"<font color='red'>发生错误</font>");		
			}
		}
	);
}
if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页&nbsp;&raquo;&nbsp;<?=$menuList[1][0]?>&nbsp;&raquo;&nbsp;数据列表';
</script>
<?php
}

function popUpdatePic() {
	global $action;
?>
<?php if ($action=="else"){?><div id='updatepic' class='divbox' style='width:300px;right:0px;display:none;'><div class='divboxtitle'><span onclick="hide('updatepic');"><img src='../pic/btn_close.gif'/></span>资源库图片下载</div><div  class='divboxbody'>注意:已检测到<span id='updatepicnum' style='color:#FF0000'><img src='../pic/loading2.gif' border=0></span>个数据含有资源库图片地址,图片在资源库暂存两周，为防止失效，请下载到本地<br><font color='#FF0000'>下载前，请先备份数据库</font><input type='button' class='btn' value='备份数据库' onclick="location.href='admin_database.php'" /><br><input type='button' class='btn'  value='下载资源库图片到本地' onclick="location.href='admin_datarelate.php?action=downpic'" /></div><div class='divboxbottom'>Power By DjCms2.0</div></div><script type='text/javascript'>alertUpdatePic();</script><?php }?>
<?php
}

function addNews() {
	global $menuList,$vid;
?>
<script type="text/JavaScript">if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页&nbsp;&raquo;&nbsp;<?=$menuList[1][0]?>&nbsp;&raquo;&nbsp;添加数据';</script>
<div class="container" id="cpcontainer">
<form action="?action=save&acttype=add" method="post" name="addform" id="addform">
<input type="hidden" id="m_commend" name="m_commend" value="0">
<input type="hidden" id="m_vid" name="m_vid" value="<?=$vid?>">
<table class="tb">
<tr class="thead"><th colspan="2">添加文章(<font color='red'>＊</font>为必填,其它选填)</th></tr>
	<tr>
	  <td align="right" height="1" width="70"></td><td></td>
	</tr>
	<tr>
	  <td align="right" height="22">标 题：</td>
	  <td><input type="text" size="23" id="m_title" name="m_title" autocomplete="off">&nbsp;<font color='red'>＊</font>颜色：
		<select name="m_color">
		<option value="" SELECTed>标题颜色</option>
		<option style="background-color:#FF0000;color: #FF0000" value="#FF0000">红色</option> 
		<option style="background-color:#FF33CC;color: #FF33CC" value="#FF33CC">粉红</option>  
		<option style="background-color:#00FF00;color: #00FF00" value="#00FF00">绿色</option>
		<option style="background-color:#0000CC;color: #0000CC" value="#0000CC">深蓝</option>
		<option style="background-color:#FFFF00;color: #FFFF00" value="#FFFF00">黄色</option>
		<option style="background-color:#660099;color: #660099" value="#660099">紫色</option>
		<option style="" value="">无色</option>
	</select>
	
	类 型：<select name="m_type" id="m_type" ><option value="">请选择数据分类</option><?=makeNewsTypeOption(0,"&nbsp;|&nbsp;&nbsp;")?></select>	</td>
	</tr>
	<tr> 
		<td height="22" align="right">图片地址：</td>
		<td><input type="text" size="30" name="m_pic" id="m_pic">&nbsp;←<input size="10" value="清除" type="button" onClick="javascript:document.addform.m_pic.value=''" class="btn" />&nbsp;<iframe src="fckeditor/upload.htm?isnews=1" scrolling="no" topmargin="0" width="300" height="24" marginwidth="0" marginheight="0" frameborder="0" align="center"></iframe></td>
  </tr>
	<tr>
	  <td align="right" height="22">作&nbsp;&nbsp;者：</td>
	  <td><input type="text" size="30" name="m_author">&nbsp;&nbsp;来&nbsp;&nbsp;&nbsp;源：<input type="text" size="10" name="m_from">&nbsp;星级：<span id="star0" style="width:85px;display:inline-block"><script>starView(0,0)</script></span></td>
	</tr>
	<tr>
	  <td align="right" height="22">关键词：</td>
	  <td><input type="text" name="keyword" size="30">&nbsp;&nbsp;点击率：<input type="text" size="10" name="m_hit" id="m_hit" maxlength="9" value="0">&nbsp;属性：<input type="checkbox" name="m_note" class="checkbox" value="64">[图]&nbsp;<input type="checkbox" class="checkbox" name="m_note" value="128">[荐]</td>
	</tr>
	<tr>
	  <td align="right" height="22">简&nbsp;&nbsp;述：</td>
	  <td><textarea name="m_outline" rows="3" cols="70" maxlength="100"></textarea></td>
	</tr>
	<tr>
	  <td align="right" height="22">内&nbsp;&nbsp;容：</td>
	   <td>
		<?php
        GetEditor('m_content', "");
	?>
	   </td>
	</tr>
	 <tr>
   <td></td> <td class="forumRow"><input type="submit" class="btn" value="确认保存" name="submit" onClick="if($('m_title').value.length==0){alert('请填写标题');return false;};if($('m_type').value.length==0){alert('请选择分类');return false;}">&nbsp;<input type="reset" class="btn" value="清 除">&nbsp;<input type="button" class="btn" value="返　回" onClick="javascript:history.go(-1);"></td>
  </tr>
</table>
</form>
</div>
<script type="text/javascript">
window.commendVideo=function (id,n){
	$('m_commend').value=n;
	starView(n,id);
}
$('addform').m_title.focus();
</script>
<?php
}

function editNews() {
	global $menuList;
	$id = intval(getForm("id","get"));
	$row = DB::fetch_first("SELECT * FROM ".DB::table('news')." WHERE m_id=$id");
	$m_color = $row['m_color'];
	$vtype = $row['m_type'];
?>
<div class="container" id="cpcontainer">
<form action="?action=save&acttype=edit" method="post" name="editform" id="editform">
<input type="hidden" id="m_commend" name="m_commend" value="<?=$row['m_commend']?>">
<input type="hidden" id="m_vid" name="m_vid" value="<?=$row['m_vid']?>">
<table class="tb">
<tr class="thead"><th colspan="2">修改文章(<font color='red'>＊</font>为必填,其它选填)</th></tr>
	<tr>
	  <td align="right" height="1" width="70"></td><td></td>
	</tr>
	<tr>
	  <td align="right" height="22">标 题：</td>
		<td><input type="text" size="23" id="m_title" name="m_title" autocomplete="off" value="<?=$row['m_title']?>"/>&nbsp;<font color='red'>＊</font>颜色：
		<select name="m_color" >
		<?php if ($m_color==""){?>
		 <option style="" value="">无色</option> 
		<?php }else{?> 
		<option style="background-color:<?=$m_color?>;color: <?=$m_color?>" value="<?=$m_color?>"><?=$m_color?></option>
		<?php }?>
		<option style="background-color:#FF0000;color: #FF0000" value="#FF0000">红色</option> 
		<option style="background-color:#FF33CC;color: #FF33CC" value="#FF33CC">粉红</option>  
		<option style="background-color:#00FF00;color: #00FF00" value="#00FF00">绿色</option>
		<option style="background-color:#0000CC;color: #0000CC" value="#0000CC">深蓝</option>
		<option style="background-color:#FFFF00;color: #FFFF00" value="#FFFF00">黄色</option>
		<option style="background-color:#660099;color: #660099" value="#660099">紫色</option>
		<option style="" value="">无色</option> 
		</select>
类 型：<select name="m_type" id="m_type"><option value="">请选择数据分类</option>
    <?php makenewsTypeOptionselected(0,"&nbsp;|&nbsp;&nbsp;","",$vtype)?>
	</select>&nbsp;&nbsp;<font color='red'>＊</font>&nbsp;<input type="checkbox" name="isupdatetime" value="1" checked class="checkbox" />更新时间</td>
	</tr>
	<tr> 
		<td height="22" align="right">图片地址：</td>
		<td><input type="text" size="30" name="m_pic" id="m_pic" value="<?=$row['m_pic']?>">&nbsp;←<input type="button" size="10" value="清除" onClick="javascript:document.editform.m_pic.value=''" class="btn">&nbsp;<iframe src="fckeditor/upload.htm?isnews=1" scrolling="no" topmargin="0" width="300" height="24" marginwidth="0" marginheight="0" frameborder="0" align="center"></iframe></td>
  </tr>

	<tr>
	 <td align="right" height="22">作&nbsp;&nbsp;者：</td>
	 <td><input type="text" size="30" name="m_author" value="<?=$row['m_author']?>">&nbsp;&nbsp;来&nbsp;&nbsp;&nbsp;源：<input type="text" size="10" name="m_from" value="<?=$row['m_from']?>">&nbsp;星级：<span id="star0" style="width:85px;display:inline-block"><script>starView(<?=$row['m_commend']?>,0)</script></span></td>
	</tr>
	<tr>
		<td align="right" height="22">关键词：</td>
	  <td><input type="text" name="keyword" size="30" value="<?=$row['m_keyword']?>">&nbsp;&nbsp;点击率：<input type="text" size="10" name="m_hit" id="m_hit" maxlength="9" value="<?=$row['m_hit']?>">&nbsp;属性：<input type="checkbox" class="checkbox" name="m_note" value="64"<?=ifthen($row['m_note']==64," checked","")?>>[荐]&nbsp;<input type="checkbox" name="m_note" class="checkbox" value="128"<?=ifthen($row['m_note']==128," checked","")?>>[图]&nbsp;<input type="checkbox" class="checkbox" name="m_note" value="32"<?=ifthen($row['m_note']==32," checked","")?>>[视]</td>
	</tr>
	<tr>
		<td align="right" height="22">简&nbsp;&nbsp;述：</td>
		<td><textarea name="m_outline" rows="3" cols="70" maxlength="100"><?=$row['m_outline']?></textarea></td>
	</tr>
	<tr>
		<td align="right" height="22">内&nbsp;&nbsp;容：</td>
		<td>
        <?php
        GetEditor('m_content', $row['m_content']);
	?>
  		</td>
	</tr>
	<tr><input type="hidden" name="m_id" value="<?=$id?>"><input type="hidden" name="m_back" value="<?=getRefer()?>" />
	<td></td><td class="forumRow"><input type="submit" name="submit" class="btn" value="确认保存" onClick="if($('m_title').value.length==0){alert('请填写标题');return false;};if($('m_type').value.length==0){alert('请选择分类');return false;}">&nbsp;<input type="reset" class="btn" value="清 除">&nbsp;<input type="button" class="btn" value="返　回" onClick="javascript:history.go(-1);"></td>
  </tr>
</table>
</form>
<script type="text/javascript">
window.commendVideo=function (id,n){
	$('m_commend').value=n;
	starView(n,id);
}
$('editform').m_title.focus();</script>
</div>

<?php
}

function replaceSpecial($str){
	return replaceStr($str, "'", "".chr(34).chr(34)."");
}

function saveNews(){
	$actType = getForm("acttype","get");
	$x = 0;
	$m_id = getForm("m_id","post");if (!is_numeric($m_id)) $m_id=0;
	$m_vid = getForm("m_vid","post");if (!is_numeric($m_vid)) $m_vid=0;
	$m_title = getForm("m_title","post");
	$m_keyword = replaceStr(replaceStr(getForm("keyword","post"),chr(13),""),chr(10),"");
	$isuppingyin = getForm("isuppingyin","post")=="1";
	$m_entitle = getForm("m_entitle","post");if (empty($m_entitle)) $m_entitle = MoviePinYin($m_title);
	$m_hit = getForm("m_hit","post");if (!is_numeric($m_hit)) $m_hit=0;
	$m_back = getForm("m_back","post");
	$m_color = getForm("m_color","post");
	$m_type = getForm("m_type","post");if (empty($m_type)){ echoMsgAndGo("请选择分类",3,false);die("");}
	$m_pic = getForm("m_pic","post");
	$m_author = getForm("m_author","post");
	$m_outline = getForm("m_outline","post");
	$m_content = replaceSpecial(getForm("m_content","post"));
	$m_addtime = getForm("m_addtime","post");
	$m_note = getForm("m_note","post");
	$m_from = getForm("m_from","post");
	$m_commend = getForm("m_commend","post");if (is_numeric($m_commend)) $m_commend=intval($m_commend);else $m_commend=0;
	$isupdatetime = getForm("isupdatetime","post");
	$feedarr = array(
	    'm_keyword' => $m_keyword,
		'm_hit' => $m_hit,
		'm_letter' => msubstr($m_enname,1),
		'm_title' => $m_title,
		'm_color' => $m_color,
		'm_type' => $m_type,
		'm_pic' => $m_pic,
		'm_author' => $m_author,
		'm_outline' => $m_outline,
		'm_content' => $m_content,
		'm_from' => $m_from,
		'm_entitle' => $m_entitle,
		'm_commend' => $m_commend,
		'm_note' => $m_note
	);
	switch (trim($actType)) {
		case "edit":
			if (!empty($isupdatetime)){ DB::update('news', array('m_addtime' => time()), array('m_id' => $m_id));}
			DB::update('news', $feedarr, array('m_id' => $m_id));
			if (newsrunMode == "static") {
				$trow = DB::result_first("SELECT m_hide FROM ".DB::table('type')." WHERE m_id=".$m_type);
				if ($trow['m_hide'] == 1) {
					$row = DB::fetch_first("SELECT m_type,m_enname,m_datetime from ".DB::table('news')." WHERE m_id=$m_id");
					delNewsArticleFile($m_type, $m_id, $row['m_enname'], $row['m_datetime']);
					alertMsg("", $m_back);
				} else { 
					alertMsg("", "admin_makehtml.php?action=newssingle&id=$m_id&from=$m_back");
				}
			} else { 
				alertMsg("", $m_back);
			}
		break;
		case "add": 
			$feedarr['m_vid'] = $m_vid;
			$feedarr['m_addtime'] = time();
			$feedarr['m_datetime'] = time();
			DB::insert('news', $feedarr);clearNewsTypeCache();
			if (empty($m_back)) $m_back = "admin_news.php?action=add";
			selectMsg("添加成功,是否继续添加",$m_back,"admin_news.php");
		break;
	}
}

function delNewsArticleFile($vType,$id,$enname,$vDate) {
	if (runMode == "static") {
		$x=getNewsArticleLink($vType,$id,$enname,$vDate,"link");
		switch (newsMakeMode) {
			case "dir1":
				if (isExistFolder($x) && $x!="/") delFolder($x);
			break;
			case "dir2":case "dir4":
				if (isExistFile($x)) delFile($x);
			break;
			case "dir3":case "dir5":case "dir7":case "dir6":case "dir8":
				if (isExistFile($x)) delFile($x);
				$x=substr($x,1,strrpos($x,"/"));
				if (isExistFolder($x) && $x!="/") delFolder($x);
			break;
		}
	}
}

function pSetType() {
	$movetype = getForm("movetype","post");
	$back = getRefer();
	$ids = dimplode(getForm("m_id","post"));
	if (empty($ids)) die("请选择需要移动分类的数据");
	DB::update('news', array('m_type' => $movetype),'m_id IN ('.dimplode($ids).')');clearNewsTypeCache();
	alertMsg("", $back);
}

function delTypeData() {
	$movetype = getForm("movetype","post");
	$back = getRefer();
	if (empty($movetype)) alertMsg("", $back);
	DB::update('news', array('m_recycle' => 1),array('m_type' => $movetype));clearNewsTypeCache();
	alertMsg("", $back);
}

function delNews($id,$sel) {
	$id = intval($id);
	$back = getRefer();
	if (empty($id)) alertMsg("",$back);
	$row = DB::fetch_first("SELECT m_type, m_pic, m_entitle, m_datetime FROM ".DB::table('news')." WHERE m_id=$id");
	$vpic=$row['m_pic'];delNewsArticleFile($row['m_type'],$id,$row['m_entitle'],$row['m_datetime']);
	if ($sel=="del"){
		if (substr($vpic, 0, 8) == '/pic') delFile("../".$vpic);
		DB::delete('news', array('m_id' => $id));
	}else{
		DB::update('news', array('m_recycle' => 1),array('m_id' => $id));
	}
	clearNewsTypeCache();
}

function delAll($id,$sel) {
	$back = getRefer();
	if (runMode == "static") {
	    $query = DB::query("SELECT m_id, m_type, m_entitle, m_datetime FROM ".DB::table('news')." WHERE m_id IN (".dimplode($id).")");
		while($row = DB::fetch($query)) {
			delNewsArticleFile($row['m_type'],$row['m_id'],$row['m_entitle'],$row['m_datetime']);
	    }
	}
	if ($sel == "del") {
		DB::delete('news', 'm_id IN ('.dimplode($id).')');
    } else {
		DB::update('news', array('m_recycle' => 1),'m_id IN ('.dimplode($id).')');
    }
	clearNewsTypeCache();
}

function restoreNews() {
	$back = getRefer();
	$ids = dimplode(getForm("m_id","both"));
	DB::update('news', array('m_recycle' => 0),'m_id IN ('.$ids.')');
	if (newsRunMode == "static") {
		echo "数据还原成功,准备重新生成....<form action=\"admin_makehtml.php?action=newsSELECTed\" id=\"makehtml\" method=\"post\"><input type=\"hidden\" name=\"m_id\" value=\"$ids\"><input type=\"hidden\" name=\"REFERER\" value=\"$back\"></form><script type=\"text/javascript\">document.getElementById('makehtml').submit()</script>";
	} else {
		alertMsg("",$back);
	}
}

function viewDataType($str) {
	$viewDataType = explode(",", getNewsTypeNameTemplateArrayOnCache(intval($str)));
	if(empty($viewDataType[0])) $viewDataType[0]="<font color=red >数据分类错误</font>";
	return $viewDataType[0];
}

function clearNewsTypeCache() {
	if (cacheStart == 1) memory('rm','array_newstype_lists_all');
}

function isVideoMake($v_id, $contentUrl) {
	echo "<a href=\"admin_makehtml.php?action=newssingle&id=$v_id\">";
	$path=replaceStr($contentUrl, sitePath, "");
	if (isExistFile(DJ_ROOT.$path)) {
		echo "<img src='imgs/yes.gif' border='0' title='点击生成HTML' />";
	} else {
		echo "<img src='imgs/no.gif' border='0' title='点击生成HTML' />";
	}
	echo "</a>";
}
?>

