<?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";
$playerKindsfile = DJ_ROOT."inc/playerKinds.inc";
$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);
	$playerWidth = getrulevalue($configStr, "playerw='", "';");
	$playerHeight = getrulevalue($configStr, "playerh='", "';");
	$playerSkin = getrulevalue($configStr, "skinColor=\"", "\";");
	$playerType = getrulevalue($configStr, "autoPlay=\"", "\";");
	$playerList = getrulevalue($configStr, "openMenu=\"", "\";");
	$viewFull = getrulevalue($configStr, "showFullBtn=\"", "\";");
	$alertWinValue = isAlertWin;
	$isRefresh = getrulevalue($configStr, "rehref=\"", "\";");
	$playerLogo = getrulevalue($configStr, "logoURL=\"", "\";");
	$playerBeforeAdUrl = getrulevalue($configStr, "adsPage=\"/\"\+sitePath\+\"js/", "\";");
	$playerBeforeTime = getrulevalue($configStr, "adsTime=", ";");
	$playerFont = getrulevalue($configStr, "btnName=\"", "\";");
	$playerset = getrulevalue($configStr, "max_Player_File=\"", "\";");
	if ($playerset == "") $playerset = "play.swf";
	$pipizzid = getrulevalue($configStr, "zzid=", ";");
?>
<script>
var ColorHex=new Array('00','33','66','99','CC','FF')
var SpColorHex=new Array('FF0000','00FF00','0000FF','FFFF00','00FFFF','FF00FF')
var current=null
var targetElement = null;
function intocolor(){
	var colorTable=''
	for (i=0;i<2;i++){
	for (j=0;j<6;j++){
		colorTable=colorTable+'<tr height=12>'
		colorTable=colorTable+'<td width=11 style="background-color:#000000">'
		if (i==0){
			colorTable=colorTable+'<td width=11 style="background-color:#'+ColorHex[j]+ColorHex[j]+ColorHex[j]+'">'
		}else{
			colorTable=colorTable+'<td width=11 style="background-color:#'+SpColorHex[j]+'">'
		}
		colorTable=colorTable+'<td width=11 style="background-color:#000000">'
		for (k=0;k<3;k++)
		{
			for (l=0;l<6;l++){colorTable=colorTable+'<td width=11 style="background-color:#'+ColorHex[k+i*3]+ColorHex[l]+ColorHex[j]+'">'}
		}
	}
}
colorTable='<table width=253 border="0" cellspacing="0" cellpadding="0" style="border:1px #000000 solid;border-bottom:none;border-collapse: collapse" bordercolor="000000">'
		   +'<tr height=30><td colspan=21 bgcolor=#cccccc>'
		   +'<table cellpadding="0" cellspacing="1" border="0" style="border-collapse: collapse">'
		   +'<tr><td width="3"><td><input type="text" name="DisColor" size="6" disabled style="border:solid 1px #000000;background-color:#ffff00"></td>'
		   +'<td width="3"><td><input type="text" name="HexColor" size="7" style="border:inset 1px;font-family:Arial;" value="#000000"></td></tr></table></td></table>'
		   +'<table border="1" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="000000" onmouseover="doOver()" onmouseout="doOut()" onclick="doclick()" style="cursor:hand;">'
		   +colorTable+'</table>';
colorpanel.innerHTML=colorTable
}

function doOver() {
	  if ((event.srcElement.tagName=="TD") && (current!=event.srcElement)) {
		if (current!=null){current.style.backgroundColor = current._background}
		event.srcElement._background = event.srcElement.style.backgroundColor
		DisColor.style.backgroundColor = event.srcElement.style.backgroundColor
		HexColor.value = event.srcElement.style.backgroundColor.toUpperCase();
		event.srcElement.style.backgroundColor = "white"
		current = event.srcElement
	  }
}

function doOut() {
	if (current!=null) current.style.backgroundColor = current._background.toUpperCase();
}

function doclick()
{
	if (event.srcElement.tagName == "TD")
	{
		var clr = event.srcElement._background;
		clr = clr.toUpperCase();
		if (targetElement)
		{
			targetElement.value = clr.replace(/#/g,'');
		}
		DisplayClrDlg(false);
		return clr;
	}
}

function OnDocumentClick()
{
	var srcElement = event.srcElement;
	if (typeof(srcElement.title) != "undefined"&&srcElement.title.indexOf('clrDlg')==0){
		targetElement = event.srcElement;
		DisplayClrDlg(true);
	}
	else
	{
		while (srcElement && srcElement.id!="colorpanel")
		{
			srcElement = srcElement.parentElement;
		}
		if (!srcElement)
		{
			DisplayClrDlg(false);
		}
	}
}

function DisplayClrDlg(display)
{
	var clrPanel = document.getElementById("colorpanel");
	if (display)
	{
		var left = document.body.scrollLeft + event.clientX;
		var top = document.body.scrollTop + event.clientY;
		if (event.clientX+clrPanel.style.pixelWidth > document.body.clientWidth)
		{
			left -= clrPanel.style.pixelWidth;
		}
		if (event.clientY+clrPanel.style.pixelHeight > document.body.clientHeight)
		{
			top -= clrPanel.style.pixelHeight;
		}

		clrPanel.style.pixelLeft = left;
		clrPanel.style.pixelTop = top;
		clrPanel.style.display = "block";
	}
	else
	{
		clrPanel.style.display = "none";
	}
}
</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 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="playerwidth" size="10" value="<?php echo $playerWidth;?>" />(px)</td></tr>
<tr><td >播放器高度：</td><td><input type="text" name="playerheight" size="10" value="<?php echo $playerHeight;?>" />(px)</td>
</tr>
<tr><td>播放器款式：</td><td><select name="playerset"> <option  value="play.swf"  <?php if ($playerset=="play.swf") echo "selected";?>>水晶透明款式</option> <option value="play2.swf"  <?php if ($playerset=="play2.swf") echo "selected";?>>简洁平板款式</option></select> 不断增加更多的播放器款式</td>
</tr>
<tr><td>播放器皮肤：<br />
(皮肤1为默认皮肤)</td>
<td>
<div id="playerskindiv">
<?php
$skinArray = explode("|",$playerSkin);$skinArrayLen = count($skinArray);
for ($skinI = 0;$skinI < $skinArrayLen;$skinI++) {
    $skinAy = explode(",",$skinArray[$skinI]);
?>
皮肤<?=($skinI+1)?> :背景颜色 #<input type='text' name='playerbgcolor[]'  title='clrDlg0<?=$skinI?>' value="<?=$skinAy[0]?>" /> 文字颜色 #<input type='text' name='playerfontcolor[]'  title='clrDlg1<?=$skinI?>' value="<?=$skinAy[1]?>"/><br>
<?php if ($skinI+1 == $skinArrayLen) {?>
<div id='addplayerskin<?=$skinI?>'><img  src='imgs/btn_add.gif' onclick='expendPlayerSkin(<?=$skinI+1?>)'  style='cursor:pointer'/></div>
<?php }?>
<?php
}
?>
</div>

</td>
</tr>
<tr><td  >播放器选择：</td><td><input type="hidden" value="<?=$alertWinValue?>" name="alertwin"/>站内：<input type="radio" name="innerplayer" value="1" <?php if($playerType == 1) echo "checked";?> /> &nbsp;&nbsp;站外：<input type="radio" name="innerplayer"  value="0" <?php if($playerType == 0) echo "checked";?>/> 
站内播放器可自动播放，可连播、全屏,站外播放器则不能 </td>
</tr>


<tr><td>默认播放列表：</td><td>打开：<input type="radio" name="openlist" value="1" <?php if ($playerList==1) echo "checked";?>/> &nbsp;&nbsp;收缩：<input type="radio" name="openlist" value="0" <?php if ($playerList==0) echo "checked";?>/> &nbsp;&nbsp;关闭：<input type="radio" name="openlist" value="2" <?php if ($playerList == 2) echo "checked";?>/>	打开播放器列表,看连续剧更方便；关闭播放列表、加载速度更快</td></tr>

<tr><td>全屏按钮开关：</td><td>显示：<input type="radio" name="viewfull" value="1" <?php if ($viewFull==1) echo "checked";?>/> &nbsp;&nbsp;隐藏：<input type="radio" name="viewfull" value="0" <?php if ($viewFull==0) echo "checked";?>/> 支持全屏观看,体验更好</td></tr>

<tr><td>是否刷新播放页：</td><td>刷新：<input type="radio" name="isrefresh" value="1" <?php if ($isRefresh==1) echo "checked";?>/> &nbsp;&nbsp;不刷新：<input type="radio" name="isrefresh" value="0" <?php if ($isRefresh==0) echo "checked";?>/> 不刷新播放页,直接在播放器内切换播放,获得绝佳的播放体验,但减少播放页PV</td>
</tr>

<tr ><td>播放器logo：</td><td><input type="text" name="logourl"  size="60" value="<?php echo $playerLogo;?>" />
位于<span >根目录的js文件夹下或使用绝对地址</span></td>
</tr>
<tr><td>播放前广告及<br>
qvod加载广告：</td><td><input type="text" name="adbeforeplay" size="60" value="<?php echo $playerBeforeAdUrl;?>" />
<span>位于根目录的js文件夹下</span></td>
</tr>
<tr><td>播放前广告时间：</td><td><input type="text" name="adtimebeforeplay" size="15" value="<?php echo $playerBeforeTime;?>" />秒 设置FLV播放器的片头广告时间,P2P播放器以加载时间为准</td>
</tr>
<tr><td>播放器文字设置：</td><td><input type="text" name="playfont" value="<?php echo $playerFont;?>" />
  设置播放器底部文字显示</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>
<div id="colorpanel" style="position:absolute;display:none;width:253px;height:177px;"></div>
<script type="text/javascript" language="javascript">document.body.onclick = OnDocumentClick;document.body.onload = intocolor;</script>
<?php
}

function boardsource() {
	global $playerKindsfile;
	$fp = fopen($playerKindsfile,'r');
	$allplayerKinds = fread($fp,filesize($playerKindsfile)+1);
	fclose($fp);
?>
<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(3,0)%>&nbsp;&raquo;&nbsp;播放来源管理';</script>
<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" ><ul id="tipslis"><li>请按照格式:播放器名|简介|介绍|是否显示|排序。</li><li>用“|”分隔，排序越高在播放页排序越靠前</li></ul></font></td></tr>
 <form action="?action=save" method="post"  >
    <td><textarea  name="content" style="width:99%;font-family: Arial, Helvetica, sans-serif;font-size: 14px;" rows="20" dataType="Require" msg="请填写幻灯片内容"><?php echo $allplayerKinds;?></textarea></td>
  </tr>
  <tr><td><input type="submit" name="Submit" value="修改播放来源" class="btn" /></td></tr>
  </form>
</table>
</form>
<iframe src="about:blank" name="hiddensubmit" width="0" height="0" frameborder="0"scrolling="no" style="display:none"></iframe>
</div>
<?php
}

function editPlayerConfig() {
	global $playerJsPath;
	$playerWidth = getForm("playerwidth","post");
	$playerHeight = getForm("playerheight","post");
	$playerBgColor = getForm("playerbgcolor","post");
	$playerFontColor = getForm("playerfontcolor","post");
	$playerSkin = handlePlayerSkinParas($playerBgColor,$playerFontColor);
	$playerType = getForm("innerplayer","post");
	$playerList = getForm("openlist","post");
	$viewFull = getForm("viewfull","post");
	$isRefresh = getForm("isrefresh","post");
	$alertWinValue = isAlertWin;
	$playerLogo = getForm("logourl","post");
	$playerBeforeAdUrl = getForm("adbeforeplay","post");
	$playerBeforeTime = getForm("adtimebeforeplay","post");
	$playerFont = getForm("playfont","post");
	$playerSet = getForm("playerset","post");
	$configStr = file_get_contents($playerJsPath);
	$configStr = preg_replace("/playerw='(\d+)';/is", "playerw='".$playerWidth."';", $configStr);
	$configStr = preg_replace("/playerh='(\d+)';/is", "playerh='".$playerHeight."';", $configStr);
	$configStr = preg_replace("/skinColor=\"(.*?)\";/is", "skinColor=\"".$playerSkin."\";", $configStr);
	$configStr = preg_replace("/autoPlay=\"(\d+)\";/is", "autoPlay=\"".$playerType."\";", $configStr);
	$configStr = preg_replace("/openMenu=\"(\d+)\";/is", "openMenu=\"".$playerList."\";", $configStr);
	$configStr = preg_replace("/showFullBtn=\"(\d+)\";/is", "showFullBtn=\"".$viewFull."\";", $configStr);
	$configStr = preg_replace("/rehref=\"(\d+)\";/is", "rehref=\"".$isRefresh."\";", $configStr);
	$configStr = preg_replace("/alertwin=\"(\d+)\";/is", "alertwin=\"".$alertWinValue."\";", $configStr);
	$configStr = preg_replace("/logoURL=\"(.*?)\";/is", "logoURL=\"".$playerLogo."\";", $configStr);
	$configStr = preg_replace("/adsPage=\"(.*?)\";/is", "adsPage=\"/\"+sitePath+\"js/".$playerBeforeAdUrl."\";", $configStr);
	$configStr = preg_replace("/adsTime=(\d+);/is", "adsTime=".$playerBeforeTime.";", $configStr);
	$configStr = preg_replace("/btnName='(\d+)';/is", "btnName='".$playerFont."';", $configStr);
	$configStr = preg_replace("/max_Player_File=\"(.*?)\";/is", "max_Player_File=\"".$playerSet."\";", $configStr);
	createTextFile($configStr, $playerJsPath);
	alertMsg("编辑成功", "admin_player.php");
}

function handlePlayerSkinParas($bgcolor,$fontcolor){
	$len1 = count($bgcolor);$len2 = count($fontcolor);
	if ($len1 != $len2) die("播放器皮肤参数填写不完整");
    $allStr = "";
    foreach ($bgcolor as $k => $v) {
       if (!empty($v) && !empty($fontcolor[$k])) {
          $allStr .= $v.",".$fontcolor[$k]."|";
       }
    }
    $allStr = rtrim($allStr,"|");
	return $allStr;
}

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];
	}
}

function modifysource() {
	global $playerKindsfile;
	$back = getRefer();$content = getForm("content","post");
	fwrite(fopen($playerKindsfile,"w"),stripslashes($content));
	alertMsg("修改成功", $back);
}
?>
