<?php
/*
'**************************************************************************************************
' 软件名称: 盘锦DJ舞曲网CMS Content Management PjRen.Net
' 版本编号: Version 2.5
' 盘锦舞曲: http://www.pj57.com
' 官方网站: http://www.pjren.net
' 小说网站: http://www.hx39.com
' 0427DJ网: http://www.0427dj.net
' 官方论坛: http://www.tianjiazhen.com
' 版权所有: 盘锦舞曲开发团队    盘锦人(QQ:814006710)
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、盘锦网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
header("Content-type: text/html;charset=gb2312");
include "../../include/conn.php";
include "../../include/function.php";
include "../admin_version.php";
$action=SafeRequest("action","get");
switch($action){
		case 'topic':
			TopicSelect();
			break;
		case 'topicsave':
			TopicSave();
			break;
		case 'editreco':
			EditReco();
			break;
		case 'chgclasslist':
			ChgClassList();
			break;
		case 'savecls':
			SaveCls();
			break;
		case 'getpicnum':
			GetPicNum();
			break;
		case 'getdjnum':
			GetDjNum();
			break;
		case 'remark':
			Remark();
			break;
		case 'getver':
			getVer();
			break;
		case 'checkupdate':
			checkUpdate();
			break;
		case 'cache':
			cacheUpdate();
			break;
		case 'spanjs':
			spanjs();
			break;
		case 'getrenum':
			getRenum();
			break;
	}

function getRenum(){
	global $db;
	$tabel=SafeRequest("tabel","get");
	$numresult=$db->query("select S_ID from `$tabel`");
	$numrows=$db->num_rows($numresult);
	mysql_free_result($numresult); 
	echo $numrows;
	}

function spanjs(){
	global $db;
	$id=SafeRequest("id","get");
	if(!file_exists("../../js/adjs")){
		mkdir("../../js/adjs",0777);
		}
	$sql="select S_TheAdrJs,S_ID,S_IsUse from s_adsense where S_ID=$id";
	$row=$db->getrow($sql);
	if($row){
		if($row['S_IsUse']==0){
			fwrite(fopen("../../js/adjs/".$row['S_ID'].".js","wb"),$row['S_TheAdrJs']);
			}
		else{
			fwrite(fopen("../../js/adjs/".$row['S_ID'].".js","wb"),"document.write(\"广告未启用!\");");
			}	
		 
		}
	die("ok");	
	}

function cacheUpdate(){
	$d=_CHSHDJ_ROOT_.S_CacheFolder;
	if (is_dir($d)) {
	  	$dh=opendir($d);//打开目录
 		 while (false !== ( $file = readdir ($dh))) {
   			if($file!="." && $file!="..") { 
      			$fullpath=$d."/".$file;
      			if(!is_dir($fullpath)) {
         		 	unlink($fullpath);//删除目录中的所有文件
     				 } 
				}
   		 	}
   		 closedir($dh);
		}
	die("ok");
	}

function checkUpdate(){
	for($uu=0;$uu<3;$uu++){
		$UpdateContent=@file_get_contents("http://www.pjren.net/pjren_net_vip/update.xml");
		if($UpdateContent) break;
	}
	if(!IsNul($UpdateContent)){
		$UpdateContent=geturl("http://www.pjren.net/pjren_net_vip/update.xml");
		}
	if(!file_exists("../backup/log.txt")){
		fwrite(fopen("../backup/log.txt","wb"),"");
	}
	$Local=@file_get_contents("../backup/log.txt");
	$FileInfoArr=explode(chr(13),$UpdateContent);
	$infos="<font color=green>当前没有新的文件需要更新!</font>";
	for($i=0;$i<count($FileInfoArr);$i++){
		$FileArr=explode('|',$FileInfoArr[$i]);		
		$FileArr[0]=trim($FileArr[0]);
		$FileArr[0]=ReplaceStr($FileArr[0],".xml",".php");
		$FileArr[2]=trim($FileArr[2]);
		$FileInfo=$FileArr[0].'|'.$FileArr[2];
		if(stristr(strtolower($Local),strtolower($FileInfo))==false){
			$infos="".$FileArr[0]."&nbsp;文件未更新!&nbsp;&nbsp;&nbsp;<a href=admin_update.php>点击更新文件</a>";
			die($infos);
			}	
		}
	die($infos);	
}

function getVer(){
	global $S_Version;
		$version=getXmlVersion();
		if(strtolower(trim($version))!=strtolower(trim($S_Version))){
			$version=$version."&nbsp;<a href=http://www.pjren.net target=_blank>[点击升级]</a>";
			}	
		echo $version;
	}

function GetPicNum(){
	global $db;
	$SID=SafeRequest("sid","get");
	if($SID==1){
		$sql="Select * from s_video where Lower(Left(S_Pic,7))='http://'  order by S_ID desc";
		}
	else{
		$sql="Select * from s_article where Lower(Left(S_Pic,7))='http://'  order by S_ID desc";
		}
	$num=$db->num_rows($db->query($sql));	
	echo $num;
	}

function GetDjNum(){
	global $db;
		$sql="Select * from s_video where Lower(Left(S_Vdata,7))='http://' and Lower(Left(S_Vdata,18))<>'http://www.rayfile' order by S_ID desc";
	$num=$db->num_rows($db->query($sql));	
	echo $num;
	}

function ChgClassList(){
	global $db;
	$S_ID=SafeRequest("id","get");
	$S_ClassID=SafeRequest("cid","get");
	$S_SysID=SafeRequest("sid","get");
	if($S_SysID==1){
		$sql="select S_Name,S_ID from s_class where S_SystemID=1";
		}
	elseif($S_SysID==2){
		$sql="select S_Name,S_ID from s_class where S_SystemID=2";
		}
	elseif($S_SysID==3){
		$sql="select S_Name,S_ID from s_huodong";
		}
	elseif($S_SysID==4){
		$sql="select S_Name,S_ID from s_form";
		}
	
	$str="<select onchange=\"savechgclass(this.value,".$S_ID.")\">\r\n";
	$result=$db->query($sql);
	if($result){
		while($row=$db->fetch_array($result)){
			if($S_ClassID==$row['S_ID']){
				$isselect="selected";
				}
			else{
				$isselect="";
				}	
		$str.="<option value=\"".$row['S_ID']."\"  ".$isselect.">".$row['S_Name']."</option>\r\n";
			}
		}
	$str.="</select>\r\n";
	echo $str;
	}

function SaveCls(){
	global $db;
	$S_ID=SafeRequest("id","get");
	$S_ClassID=SafeRequest("cid","get");
	$S_SycID=SafeRequest("sid","get");
	if($S_SycID==1){
		$sql="update s_video set S_ClassID=".$S_ClassID." where S_ID=".$S_ID."";
		}
	elseif($S_SycID==2){
		$sql="update s_article set S_ClassID=".$S_ClassID." where S_ID=".$S_ID."";
		}
	elseif($S_SycID==3){
		$sql="update s_huodongall set S_IID=".$S_ClassID." where S_ID=".$S_ID."";
		}
	elseif($S_SycID==4){
		$sql="update s_formall set S_IID=".$S_ClassID." where S_ID=".$S_ID."";
		}
	if($db->query($sql)){
		echo "<font color=green>修改成功</font>";
		}
	else{
		echo "<font color=red>修改出错</font>";
		}	
	}	

function TopicSave(){
		global $db;
		$S_ID=SafeRequest("id","get");
		$TopicID=SafeRequest("tid","get");
		$Types=SafeRequest("types","get");
		if(!IsNum($TopicID)){$TopicID==0;}
		if(!IsNum($Types)){$Types==1;}
		if($Types==1){
			$sql="update s_video set S_Topic=".$TopicID." where S_ID=".$S_ID."";
			if($db->query($sql)){
				echo "ok";
				}
			}
		else{
			$sql="update s_article set  S_Topic=".$TopicID."  where S_ID=".$S_ID."";
			if($db->query($sql)){
				echo "ok";
				}
			}	
		
	}

function TopicSelect(){
		global $db;
		$S_ID=SafeRequest("s_id","get");
		$TopicID=SafeRequest("tid","get");
		$Types=SafeRequest("types","get");
		if($Types==1){
			echo "<select name='TopicID' id='videotopicid'><option value='0'>默认无专题</option>";			
			$sql="select * from s_topic where S_SystemID=1";
			$result=$db->query($sql);
			if($result){
					while ($row=$db->fetch_array($result)){
						if($row['S_ID']==$TopicID){
							echo "<option value='".$row['S_ID']."' selected='selected'>".$row['S_Name']."</option>";
							}
						else{
							echo "<option value='".$row['S_ID']."'>".$row['S_Name']."</option>";
							}	
					}
				}
			echo "</select>";	
		}
		else{
			echo "<select name='TopicID' id='videotopicid'><option value='0'>默认无专题</option>";	
			$sql="select * from s_topic where S_SystemID=2";
			$result=$db->query($sql);
			if($result){
					while ($row=$db->fetch_array($result)){
						if($row['S_ID']==$TopicID){
							echo "<option value='".$row['S_ID']."' selected='selected'>".$row['S_Name']."</option>";
							}
						else{
							echo "<option value='".$row['S_ID']."'>".$row['S_Name']."</option>";
							}	
					}
				}
			echo "</select>";	
		}

		echo "&nbsp;<input type='button' value='确定'  onclick='ctopic(".$S_ID.")'  class='rb1' /> <input type='button' value='取消' id='topicclose'  class='rb1' onclick='closet()'/>";
	

	}

function EditReco(){
		global $db;
		$S_ID=SafeRequest("id","get");
		$Level=SafeRequest("level","get");
		$S_Type=SafeRequest("types","get");
		if(!IsNum($S_Type)){$S_Type==0;}
		if($S_Type==0){
			$table="s_video";
			}
		elseif($S_Type==2){
			$table="s_topic";
			}
		elseif($S_Type==3){
			$table="s_huodongall";
			}
		elseif($S_Type==4){
			$table="s_form";
			}
		else{
			$table="s_article";
			}	
		$sql="update ".$table." set S_Reco=".$Level." where S_ID=".$S_ID."";
		if($db->query($sql)){
			echo "ok";
			}
			
		

	}
	
function getXmlVersion(){
	$doc = new DOMDocument();
	$cc=$doc->load('http://www.pjren.net/pjren_net_vip/version_dj.xml');
	$ver = $doc->getElementsByTagName("zhuangbi");	
	foreach( $ver as $v )
	{
		$ver = $v->getElementsByTagName( "nb" );
		if(function_exists("mb_convert_encoding")){
			$version =  mb_convert_encoding($ver->item(0)->nodeValue,"GBK","UTF-8");  
			}
		else{
			$version = iconv( "UTF-8",  "GBK//IGNORE" , $ver->item(0)->nodeValue);
			}
	}
	return $version;
}	
?>