<?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[3][0]);
$playerJsPath = "../js/play.js";
$action = getForm("action", "get");
switch ($action) {
	case "edit" : editPlayerConfig();break;
	case "modifyalert":modifyAlertWinValue();break;
	case "boardsource":boardsource();break;
	case "modifysource":modifysource();break;
	case "modifysourceban":modifysourceban();break;
	default : main();break;
} 
viewFoot();

function main() {
	global $playerJsPath,$menuList;
	$configStr = file_get_contents($playerJsPath);
	$playerw = getrulevalue($configStr, "playerw='", "';");
	$playerh = getrulevalue($configStr, "playerh='", "';");
	$autoPlay = getrulevalue($configStr, "autoPlay=\"", "\";");
	$showPlay = getrulevalue($configStr, "showPlay=\"", "\";");
	$openMenu = getrulevalue($configStr, "openMenu=\"", "\";");
	$adsPage = getrulevalue($configStr, "adsPage=\"", "\";");
	$adsTime = getrulevalue($configStr, "adsTime=", ";");
?>
<div class="container" id="cpcontainer">
<!--当前导航-->
<script type="text/JavaScript">if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页&nbsp;&raquo;&nbsp;<?=$menuList[8][0]?>&nbsp;&raquo;&nbsp;站点配置';</script>
<form method="post" action="?action=edit">
<table class="tb">
<tr class="thead"><td colspan="2">播放器相关配置</td></tr>
<tr><td width="169" >播放器宽度：</td>
<td width="813" ><input type="text" name="playerw" size="10" value="<?=$playerw?>" />(px)</td></tr>
<tr><td >播放器高度：</td><td><input type="text" name="playerh" size="10" value="<?=$playerh?>" />(px)</td>
</tr>
<tr><td>默认播放列表：</td><td>打开：<input type="radio" name="showPlay" value="1" <?php if ($showPlay==1) echo "checked";?>/> &nbsp;&nbsp;收缩：<input type="radio" name="showPlay" value="0" <?php if ($showPlay==0) echo "checked";?>/> 打开播放器列表,看连续剧更方便；关闭播放列表、加载速度更快</td></tr>
<tr><td>默认列表位置：</td><td>右边：<input type="radio" name="openMenu" value="1" <?php if ($openMenu==1) echo "checked";?>/> &nbsp;&nbsp;左边：<input type="radio" name="openMenu" value="0" <?php if ($openMenu==0) echo "checked";?>/> 选择播放列表位置.</td></tr>
<tr><td>默认自动播放：</td><td>打开：<input type="radio" name="autoPlay" value="1" <?php if ($autoPlay==1) echo "checked";?>/> &nbsp;&nbsp;关闭：<input type="radio" name="autoPlay" value="0" <?php if ($autoPlay==0) echo "checked";?>/> 打开自动播放,支持的都会自动开始播放.</td></tr>
<tr><td>播放前广告及<br>
qvod加载广告：</td><td><input type="text" name="adsPage" size="60" value="<?=$adsPage?>" />
<span>位于根目录的js文件夹下</span></td>
</tr>
<tr><td></td><td><input type="submit" value="确认更新" class="btn" />&nbsp;<input type="button" value="返   回" class="btn" onClick="javascript:history.go(-1)" /></td></tr>
</table>
</form>
<?php
}

function boardsource() {
	$PlayerArray=getBoardSources();
?>
<script type="text/javascript">
function upformone(i){
	$('id').value=i,$('sort').value=$('sort'+i).value,$('info').value=$('info'+i).value;
	$('form1').submit();
}
</script>
<div class="container" id="cpcontainer">
<script type="text/JavaScript">if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页&nbsp;&raquo;&nbsp;<%=menuList(8,0)%>&nbsp;&raquo;&nbsp;播放来源管理';</script>
<form id="form1" name="form1" method="post" action="?action=modifysource" target="hiddensubmit">
<input type="hidden" name="id" id="id" value="" />
<input type="hidden" name="sort" id="sort" value="" />
<input type="hidden" name="info" id="info" value="" />
</form>

<form id="form2" name="form2" method="post" action="?action=modifysource&method=all">
<table class="tb">
	<tr class="thead"><td colspan="4">播放来源管理<font style=" font-weight:200; color:#FF0000" >(播放来源的排序值越大、在前台播放列表中位置越排前)</font></td></tr>
	<tr align="center" bgcolor="#f5fafe">
		<td  align="left" width="106">来源名称</td>
		<td width="225">排序</td>
		<td width="693">来源简介</td>
		<td width="196">操作</td>
	</tr>
<?php
	$l = count($PlayerArray[0]);
	for ($i = 0;$i < $l;$i++) {
?>
	<tr align="center"  bgcolor="#f5fafe">
		<td  align="left" ><input type="checkbox" class="checkbox" id="id<?=$i?>" name="id[]" value="<?=$i?>"  checked="checked"/><?=$PlayerArray[0][$i]?></td>
		<td><input type="text" id="sort<?=$i?>" name="sort<?=$i?>" value="<?=$PlayerArray[2][$i]?>" style="width:50px;" maxlength="6" onkeyup="this.value=this.value.replace(/[^\d]/g,'');" onchange="this.onkeyup();"/></td>
		<td><textarea id="info<?=$i?>" name="info<?=$i?>" cols="80" rows="2"><?=$PlayerArray[3][$i]?></textarea></td>
		<td><a href="?action=modifysourceban&id=<?=$i?>" title="隐藏或显示&#13;所有数据中的 "<?=$PlayerArray[0][$i]?>" 播放地址"><?php if ($PlayerArray[1][$i]=="1") echo "隐藏";else echo "<font color=red >显示</font>";?></a>&nbsp;&nbsp;<a href="javascript://" onclick="upformone(<?=$i?>)">修改</a>
		</td>
	</tr>
<?php
	}
?>
	<tr class="thead"><td colspan="4"><input type="checkbox" class="checkbox" id="chkall" onclick="checkAll(this.checked,'input','id[]')"/>全选 <input type="submit" name="submit" value="修改选中项" class="btn" /></td></tr>
</table>
</form>
<iframe src="about:blank" name="hiddensubmit" width="0" height="0" frameborder="0"scrolling="no" style="display:none"></iframe>
</div>
<?php
}
function getBoardSources(){
	$ret = $nodes = array();
	$xml = file_get_contents(DJ_ROOT."inc/playerKinds.xml");
	$xml = StrSlice($xml,'<playerkinds>','</playerkinds>');
	$nodes = getruleval($xml,'player');
	foreach($nodes as $f=>$v){
		$ret[0][$f] = StrSlice($v,'flag="','"');
		$ret[1][$f] = StrSlice($v,'open="','"');
		$ret[2][$f] = StrSlice($v,'sort="','"');
		$ret[2][$f]= ifthen(is_numeric($ret[2][$f]),$ret[2][$f],0);
		$ret[3][$f] = StrSlice($v,'<intro><![CDATA[',']]></intro>');
		$ret[4][$f] = StrSlice($v,'des="','"');
	}
	for ($i = 0;$i < $f;$i++) {
		for ($j = ($i+1);$j < $f;$j++) {
			if ($ret[2][$i] < $ret[2][$j]){
				$tmp=$ret[0][$j];$ret[0][$j]=$ret[0][$i];$ret[0][$i]=$tmp;
				$tmp=$ret[1][$j];$ret[1][$j]=$ret[1][$i];$ret[1][$i]=$tmp;
				$tmp=$ret[2][$j];$ret[2][$j]=$ret[2][$i];$ret[2][$i]=$tmp;
				$tmp=$ret[3][$j];$ret[3][$j]=$ret[3][$i];$ret[3][$i]=$tmp;
				$tmp=$ret[4][$j];$ret[4][$j]=$ret[4][$i];$ret[4][$i]=$tmp;
			}
		}
	}
	return $ret;
}

function modifysource(){
	$method=getForm("method","both");$back = getRefer();
	$ids=explode(",",dimplode(getForm("id","post")));$il=count($ids);
	if ($il<>'-1'){
		$A=getBoardSources();
		if ($method=="all"){
			for ($i = 0;$i < $il;$i++) {
				if (is_numeric($ids[$i])){
					$A[2][$ids[$i]]=getForm("sort".$ids[$i],"post");
					$A[3][$ids[$i]]=getForm("info".$ids[$i],"post");
				}
			}
			alertMsg("修改成功",$back);
		}else{
			$ids=join("",$ids);
			if (is_numeric($ids)){
				$A[2][$ids]=getForm("sort","post");
				$A[3][$ids]=getForm("info","post");
			}
			echo "<script>alert('修改成功');parent.location.reload();</script>";
        }
		Save2xmlFile($A);
    }else{
		alertMsg("没选择要修改的项目","javascript:history.go(-1);");
    }
}

function modifysourceban(){
	$i=getForm("id","both");$back = getRefer();
	if (is_numeric($i)){
		$A=getBoardSources();
		$A[1][$i]=ifthen(trim($A[1][$i])=="1","0","1");
		Save2xmlFile($A);
    }
	alertMsg("",$back);
}

function Save2xmlFile($aArg){
	$xml="<?xml version=\"1.0\" encoding=\"gbk\" ?>\n<playerkinds>
	<!--
	DJCMS3.0播放器支持格式说明：
	1.player节点为播放器，不可更改
	2.flag属性不能更改，作为来源的标识
	3.open属性表示启用或者关闭该来源，open=\"1\"为开启，open=\"0\"为关闭
	4.intro节点为每个播放器的说明信息，可以自由更改
	5.sort排序属性，值为数字,值越大越排前
	-->\n";
	$l = count($aArg[0]);
	for ($i = 0;$i < $l;$i++) {
		$xml .= "	<player open=\"".$aArg[1][$i]."\" sort=\"".$aArg[2][$i]."\" flag=\"".$aArg[0][$i]."\" des=\"".$aArg[4][$i]."\"><intro><![CDATA[".stripslashes($aArg[3][$i])."]]></intro></player>\n";
	}
	$xml .="</playerkinds>";
	createTextFile($xml,"/inc/playerKinds.xml");
}

function editPlayerConfig() {
	global $playerJsPath;
	$playerw = getForm("playerw","post");
	$playerh = getForm("playerh","post");
	$showPlay = getForm("showPlay","post");
	$autoPlay = getForm("autoPlay","post");
	$openMenu = getForm("openMenu","post");
	$adsPage = getForm("adsPage","post");
	$configStr = file_get_contents($playerJsPath);
	$configStr = preg_replace("/playerw='(\d+)';/is", "playerw='".$playerw."';", $configStr);
	$configStr = preg_replace("/playerh='(\d+)';/is", "playerh='".$playerh."';", $configStr);
	$configStr = preg_replace("/autoPlay=\"(\d+)\";/is", "autoPlay=\"".$autoPlay."\";", $configStr);
	$configStr = preg_replace("/openMenu=\"(\d+)\";/is", "openMenu=\"".$openMenu."\";", $configStr);
	$configStr = preg_replace("/showPlay=\"(\d+)\";/is", "showPlay=\"".$showPlay."\";", $configStr);
	$configStr = preg_replace("/adsPage=\"(.*?)\";/is", "adsPage=\"".$adsPage."\";", $configStr);
	createTextFile($configStr, $playerJsPath);
	alertMsg("编辑成功", "admin_player.php");
}

function getrulevalue($content, $str1, $str2) {
	if (!empty($content) && !empty($str1) && !empty($str2)){
		$labelRule = buildregx($str1."(.*?)".$str2, "is");
		preg_match_all($labelRule,$content,$ar);
		return $ar[1][0];
	}
}
?>
