<?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]);
$back = getRefer();
$action = getForm("action", "get");
switch ($action) {
	case "add" : addVideo();popDiv();break;
	case "moverecycle":delAll(getForm("m_id","both"),"recycle");alertMsg("",$back);break;
	case "delall":delAll(getForm("m_id","post"),"del");alertMsg("",$back);break;
	case "del":delVideo(getForm("id","get"),"del");alertMsg("",$back);break;
	case "restore":restoreVideo();break;
	case "edit" : editVideo();popDiv();break;
	case "save" : saveVideo();break;
	case "psettopic" : pSetTopic();break;
	case "psettype" : pSetType();break;
	case "deltypedata" : delTypeData();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");
	$pTopic = getForm("topic", "get");
	$whereStr=" WHERE m_recycle=".ifthen($action == "recycle",1,0);
	$m_state = getForm("m_state", "get");$m_commend = getForm("m_commend", "get");
    if ($m_state == "ok") $whereStr .= " AND m_state>0";
    if ($m_commend == "ok") $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") {
		$rlen = getForm("rlen", "get");
		$dis_names = '';
		if (!is_numeric($rlen)) $rlen=5; else $rlen=intval($rlen);
		$query = DB::query("SELECT m_name FROM ".DB::table('data')." GROUP BY LEFT(m_name, $rlen) HAVING COUNT(*)>1");
        while($row = DB::fetch($query)) {
			$dis_names .= "'".$row['m_name']."',";
        }
		$dis_names = rtrim($dis_names, ",");
		if (!empty($dis_names)) {
		    $whereStr .= " AND LEFT(m_name, $rlen) IN({$dis_names})";
		} else {
		    $whereStr .= " AND 1=2";
		}
    }
    if (!empty($vtype)) $whereStr .= " AND m_type IN(".getTypeIdOnCache($vtype).")";
    if (!empty($pTopic)) $whereStr .= " AND m_topic =".$pTopic;
    if (!empty($keyword)) $whereStr .= " AND m_name LIKE '%".$keyword."%' OR `m_actor` LIKE '%".$keyword."%' ";
    if (!empty($playfrom)) $whereStr .= " AND m_playdata LIKE '%".$playfrom."$$%' ";
	$sqlStr = replaceStr(replaceStr("SELECT m_id,m_name,m_hit,m_enname,m_state,m_type,m_topic,m_addtime,m_commend,m_playdata,m_datetime FROM ".DB::table('data')." $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">
<script type="text/JavaScript">if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页&nbsp;&raquo;&nbsp;<?=$menuList[1][0]?>&nbsp;&raquo;&nbsp;数据列表';</script>
<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';return false;" href="#">下载所有网络图片到本地</a>)<?php }else{ echo "数据回收站";}?></th></tr>	
<tr><td align="left" colspan="10">  
<form action="?" method="get" >
关键字<input  name="keyword" type="text" id="keyword" size="20">
<select name="type" id="type"  ><option value="">请选择数据分类</option>
	<?=makeTypeOption(0, "&nbsp;|&nbsp;")?>
	</select>
<input type="submit" name="selectBtn"  value="查 询..." class="btn" />&nbsp;
<select  onchange="self.location.href='?type='+this.options[this.selectedIndex].value+'&m_state=<?=$m_state?>&m_commend=<?=$m_commend?>&repeat=<?=$repeat?>'">
<option value="">按数据分类查看</option>
	<?=makeTypeOption(0, "&nbsp;|&nbsp;")?>
</select>
<select name="topic" id="topic" onChange="self.location.href='?topic='+this.options[this.selectedIndex].value">
	<option value=''>按专题查看</option>
	<?=makeTopicOptions("未选择专题")?>
</select> 
<select id='m_playfrom' name='m_playfrom' style="width:120px" onChange="self.location.href='?playfrom='+this.options[this.selectedIndex].value">
	 <option value=''>按视频来源查看</option>
	  <?=makePlayerSelect("")?>
</select>
<select name="star" id="star" onChange="self.location.href='?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="?order=m_id&type=<?=$type?>&page=<?=$page?>&m_state=<?=$m_state?>&m_commend=<?=$m_commend?>&repeat=<?=$repeat?>"><img src="imgs/minus.gif" title="按ID排序" /></a></td>
	<td>标题</td>
	<td width="35">人气<a href="?order=m_hit&type=<?=$type?>&page=<?=$page?>&m_state=<?=$m_state?>&m_commend=<?=$m_commend?>&repeat=<?=$repeat?>"><img src="imgs/minus.gif" title="按人气排序" /></a></td>
	<td width="80">来源</td>
	<td width="72">数据类别</td>
	<td width="28">专题</td>
	<td width="70">推荐星级<a href="?order=m_commend&type=<?=$type?>&page=<?=$page?>&m_state=<?=$m_state?>&m_commend=<?=$m_commend?>&repeat=<?=$repeat?>"><img src="imgs/minus.gif" title="按推荐星级排序" /></a></td>
	<td width="66">时间<a href="?order=m_addtime&type=<?=$type?>&page=<?=$page?>&m_state=<?=$m_state?>&m_commend=<?=$m_commend?>&repeat=<?=$repeat?>"><img src="imgs/minus.gif" title="按时间排序" /></a></td>
	<?php if(runMode == 'static' && $action!="recycle"){?><td width="30">生成</td><?php }?>
	<td width="100" align="center">操作</td>
  </tr><form method="post" name="videolistform">
<?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 = getContentLink($row['m_type'], $row['m_id'],$row['m_enname'],$row['m_datetime'], "");
    $fromstr = getFromStr($row['m_playdata']);
?>
  <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_name']?></a><span id="state<?=$m_id?>"><?php $vstate = $row['m_state']; if($vstate==0){echo "<img src=\"imgs/icon_01.gif\"  title='设置连载状态' style=\"cursor:pointer\" onclick=\"setVideoState($m_id)\"/>";}else{echo "<sup style='color:#ff0000;font-weight:bold;cursor:pointer;' onclick=\"setVideoState($m_id)\" title='修改连载状态'>($vstate)</sup>";}?></span></td>
	<td><?=$row['m_hit']?></td>
	<td><?php if(empty($fromstr)) echo "&nbsp;"; else echo $fromstr;?></td>
	<td><a href="?type=<?=$row['m_type']?>&order=<?=$order?>"><?=viewDataType($row['m_type'])?></a></td>
	<td id="topic<?=$m_id?>" align="center"><?php $m_topic = $row['m_topic']; if($m_topic==0){ echo "<img src=\"imgs/icon_l01.gif\"  title='设置专题' style=\"cursor:pointer\"  onclick=\"setVideoTopic($m_id,'')\"/>";}else{ echo "<img src=\"imgs/icon_l02.gif\" title='修改专题' style=\"cursor:pointer;\" onclick=\"setVideoTopic($m_id,$m_topic)\"/>";}?></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(runMode=='static'){?><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="11"><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="videolistform.action='?action=restore';"> <input type="submit" value="永久删除" onclick="if(confirm('一但删除将无法恢复')){videolistform.action='?action=delall';}else{return false}" class="btn">
<?php }else{?>
	<input type="submit" value="批量删除" class="btn" onclick="if(confirm('确定要永久删除吗')){videolistform.action='?action=delall';}else{return false}"> <input type="submit" value="批量生成" class="btn" onclick="videolistform.action='admin_makehtml.php?action=selected'" />
<?php }?>
<select name="ptopic"  id="ptopic"  style="width:90px" >
<option value='0'>取 消 专 题</option>
<?php echo makeTopicOptions("")?>
</select><input type="submit"  style="width:90px" value="批量操作专题"  class="btn" onclick="if($('ptopic').value==''){alert('请选择专题');return false;};videolistform.action='?action=psettopic'" /> 
<select name="movetype" id="movetype"  ><option value="">请选择目标分类</option>
	<?php makeTypeOption(0, "&nbsp;|&nbsp;")?>
	</select>
<input type="submit"   value="批量移动" class="btn" onclick="if($('movetype').value==''){alert('请选择目标分类');return false;};if(confirm('确定要批量移动数据吗')){videolistform.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确定要删除此分类的所有数据吗')){videolistform.action='?action=deltypedata'}else{return false;}"/>
<?php }?>
</div></div></td>
</tr>
</form>
<tr><td colspan="11" align="center"><?=fPageCount($allRecordset, $number, $page)?></td>
</tr>
<?php
}
?>
</table>
</div>
<?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 popDiv() {
?>
<div id="gathervideo" style="top:100px; display:none;" class="popdiv">
<div class="poptitie"><img src="../pic/btn_close.gif" alt="关闭" onClick="$('gathervideo').style.display='none';selectTogg()" />WEB采集助手</div>
	<div class="popbody"><div>
	<table ><tr><td><input name='areaid' id='areaid' type='hidden' value=""><input type="text" name="gatherurl" id="gatherurl" size="60" /> <input type="button" onclick="gather()"   class="btn" value="分   析"/><span id="loading" style="display:none"><img src="imgs/loading2.gif" width="16" height="16"><font color="#FF0000">分析数据中</font></span></td></tr>
	<tr><td><textarea id="gathercontent" cols="72" rows="9"></textarea></td></tr>
	<tr><td><input type="button" onclick="insertResult(1);selectTogg()"   class="btn" value="添  加"/> <input type="button" value="倒 序" style="margin-left:30px;margin-right:10px" onclick="reverseOrder()" class="btn"   />将<input type="text" size="10" id='replace1' />替换成<input type="text" id='replace2' size="10" />&nbsp;
	<input type="button" value="替 换"  onclick="replaceStr()" class="btn" /></td></tr>
	</table>	
	 </div></div>
</div>
<script type="text/javascript" src="imgs/drag.js"></script>
<?php
}

function addVideo() {
	global $menuList;
	$makePlayerSelectStr = str_replace("'","\'",makePlayerSelect(""));
	$makeDownSelectStr = str_replace("'","\'",makeDownSelect(""));
?>
<div class="container" id="cpcontainer">
<script type="text/JavaScript">if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页&nbsp;&raquo;&nbsp;<?=$menuList[1][0]?>&nbsp;&raquo;&nbsp;添加数据';</script>
<form action="?action=save&acttype=add" method="post" name="addform" id="addform">
<input type="hidden" id="m_commend" name="m_commend" value="0">
<table class="tb">
<tr class="thead"><th colspan="2">添加数据(<font color='red'>＊</font>为必填,其它选填)</th></tr>
	<tr>
	  <td align="right" height="22" width="73">名称：</td>
	  <td><input id="m_name" name="m_name" size="23" autocomplete="off" onChange="checkRepeat();" value="" />&nbsp;<font color='red'>＊</font><span id="m_name_ok"></span><label>连载？<input type="checkbox" onclick="isViewState()"  id="m_statebox" class="checkbox" /></label><span id="m_statespan" style="display:none">到第<input name="m_state" id="m_state" type="text" size="5" />集</span> 颜色：
	<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><?=makeTypeOption(0,"&nbsp;|&nbsp;&nbsp;")?></select>	</td>
	</tr>
	<tr> 
		<td height="22" align="right">图片地址：</td>
		<td><input name="m_pic" id="m_pic" type="text" size="30" value="">&nbsp;←<input size="10" value="清除" type="button" onClick="javascript:document.addform.m_pic.value=''" class="btn" />&nbsp;<iframe src="fckeditor/upload.htm" 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_actor">&nbsp;&nbsp;导&nbsp;&nbsp;&nbsp;演：<input type="text" size="10" name="m_director">&nbsp;星级：<span id="star0" style="width:85px;display:inline-block"><script>starView(0,0)</script></span>&nbsp;&nbsp;&nbsp;&nbsp;主演、导演用逗号或空格隔开</td>
	</tr>
	<tr>
	  <td align="right" height="22">备 注：</td>
	  <td><input type="text" name="m_note" size="30">&nbsp;&nbsp;关键词：<input type="text" name="keyword" size="30">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;备注如：高清,无水印 (配合标题一起显示)</td>
	</tr>
    <tr>
	  <td align="right" height="22">发行年份：</td>
	  <td><input type="text" size="10" name="m_publishyear">&nbsp;语言：<input type="text" size="10" name="m_lang">&nbsp;&nbsp;地&nbsp;&nbsp;&nbsp;区：<?=getAreaSelect("m_publisharea","选择地区","")?>&nbsp;&nbsp;专题：<?=makeTopicSelect("m_topic","选择专题","")?>&nbsp;&nbsp;&nbsp;&nbsp;点击率：<input type="text" size="5" name="m_hit" id="m_hit" maxlength="9" value="0"></td>
	</tr>
	<tr>
	  <td colspan="2" style="padding:0;" class="noborder"><div style="" id="m_playarea"></div></td></tr> 
	<tr><td colspan='2'>&nbsp;<img onclick="expendPlayArea(2,escape('<?=$makePlayerSelectStr?>>'),0
    )"  src='imgs/btn_add.gif' class='pointer' align='absmiddle'/>&nbsp;&nbsp;<font color="red">您可以单击前面的按钮添加一组播放来源</font></td></tr>
    
    <tr><td colspan="2" style="padding:0" class="noborder"><div style="" id="m_downarea"></div></td></tr>
	<tr><td colspan='2'>&nbsp;<img onclick="expendDownArea(2,escape('<?=$makeDownSelectStr?>'),0)"  src='imgs/btn_add.gif' class='pointer' align='absmiddle'/>&nbsp;&nbsp;<font color="red">您可以单击前面的按钮添加一组下载来源</font></td></tr>
	  <td align="right" height="22"></td>
	  <td>说明:程序默认每行为一个播放地址，多集请分行，不能有空行</td>
	</tr>
	<tr>
	  <td align="right" height="22">相关介绍：</td>
	   <td>
 <?php
        GetEditor('m_des', "");
	?>
	   </td>
	</tr>

	 <tr>
   <td></td> <td class="forumRow" ><input type="submit" name="submit" class="btn" value="确认保存" onClick="return chform();">&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);
}
function chform(){
	if($('m_name').value.length==0){
		alert('请填写名称');
		return false;
	};
	if($('m_type').value.length==0){
		alert('请选择分类');
		return false;
	};
	if($('m_publishyear').value.length>0){
		if(isNaN($('m_publishyear').value)){
			alert('年份请填写数字');
			return false;
		}
	}
	var c=document.getElementsByName("m_playfrom"),
	ct=document.getElementsByName("m_playurl"),
	d=document.getElementsByName("m_downfrom"),
	dt=document.getElementsByName("m_downurl");
	for(var i=0;i<c.length;i++){
		if(c[i].selectedIndex==0 && ct[i].value!=''){
			alert('请选择每个播放来源');c[i].focus();
			return false;
		}
	}
	for(var i=0;i<d.length;i++){
		if(d[i].selectedIndex==0 && dt[i].value!=''){
			alert('请选择每个下载来源');d[i].focus();
			return false;
		}
	}
	return true;
}
$('addform').m_name.focus();
expendPlayArea(1,"<?=$makePlayerSelectStr?>",1);expendDownArea(1,"<?=$makeDownSelectStr?>",1);
</script>
<?php
}

function editVideo() {
	global $menuList;
	$id = intval(getForm("id","get"));
	$makePlayerSelectStr = str_replace("'","\'",makePlayerSelect(""));
	$makeDownSelectStr = str_replace("'","\'",makeDownSelect(""));
	$vrow = DB::fetch_first("SELECT * FROM ".DB::table('data')." WHERE m_id='$id'");
	if (!is_array($vrow)) { die("没找到记录");}
	$m_color = $vrow['m_color'];
	$m_type = $vrow['m_type'];
?>
<div class="container" id="cpcontainer">
<script type="text/JavaScript">if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页&nbsp;&raquo;&nbsp;<?=$menuList[1][0]?>&nbsp;&raquo;&nbsp;修改数据';</script>
<form action="?action=save&acttype=edit" method="post" name="editform" id="editform" >
<input type="hidden" id="m_commend" name="m_commend" value="<?=$vrow['m_commend']?>">
<table class="tb">
<tr class="thead"><th colspan="2">修改数据(<font color='red'>＊</font>为必填,其它选填)</th></tr>
	<tr>
		<td align="right" height="22" width="73">名称：</td>
		<td><input id="m_name" name="m_name" size="23" autocomplete="off" value="<?=$vrow['m_name']?>"/>&nbsp;<font color='red'>＊</font><label>连载？<input type="checkbox" onclick="isViewState()" class="checkbox"  id="m_statebox"  <?=$vrow['m_state'] != 0 ? 'checked' : ''?>/></label><span id="m_statespan" <?=$vrow['m_state'] == 0 ? "style=\"display:none\"" : ''?>>到第<input name="m_state" id="m_state" value="<?php echo $vrow['m_state'];?>" type="text" size="5" />集</span>
		<span id="m_name_ok"></span>颜色：
		<select name="m_color" >
		<?php 
		if($m_color)
		{
		?>
         <option style="background-color:<?=$m_color;?>;color: <?=$m_color;?>" value="<?=$m_color;?>"><?=$m_color;?></option>
		<?php 
		}
		else
		{
		?>
		<option style="" value="">无色</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 makeTypeOptionSelected(0,"&nbsp;|&nbsp;&nbsp;","",$vrow['m_type'])?>
	</select>&nbsp;&nbsp;<font color='red'>＊</font></td>
	</tr>
	<tr> 
		<td height="22" align="right">图片地址：</td>
		<td><input name="m_pic" id="m_pic" type="text" size="40" value="<?=$vrow['m_pic']?>">&nbsp;←<input size="10" value="清除" type="button" onClick="javascript:document.editform.m_pic.value=''" class="btn" />&nbsp;<iframe src="fckeditor/upload.htm" 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">主 演：</td>
	 <td><input type="text" size="30" name="m_actor" value="<?=$vrow['m_actor']?>">&nbsp;&nbsp;导&nbsp;&nbsp;&nbsp;演：<input type="text" size="10" name="m_director" value="<?=$vrow['m_director']?>">&nbsp;星级：<span id="star0" style="width:85px;display:inline-block"><script>starView(<?=$vrow['m_commend']?>,0)</script></span>&nbsp;&nbsp;&nbsp;&nbsp;主演、导演用逗号或空格隔开</td>
	</tr>
    
    <tr>
		<td align="right" height="22">备 注：</td>
		<td><input type="text" size="30" name="m_note" value="<?php if (!empty($vrow['m_note'])) echo decodeHtml($vrow['m_note']);?>">&nbsp;&nbsp;关键词：<input type="text" size="30" name="keyword" value="<?=$vrow['m_keyword']?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;备注如：高清,无水印 (配合标题一起显示)</td>
	</tr>
	<tr>
		<td align="right" height="22">发行年份：</td>
		<td><input size="5" name="m_publishyear" id="m_publishyear" value="<?=$vrow['m_publishyear']?>"  />年&nbsp;&nbsp;语言：<input type="text" size="10" name="m_lang" value="<?=$vrow['m_lang']?>">&nbsp;&nbsp;地&nbsp;&nbsp;&nbsp;区：<?php echo getAreaSelect("m_publisharea","选择地区",$vrow["m_publisharea"]);?>&nbsp;&nbsp;专题：<?=makeTopicSelect("m_topic", "选择专题", $vrow["m_topic"])?>  &nbsp;&nbsp;点击率：<input type="text" name="m_hit" id="m_hit" maxlength="9"  value="<?=$vrow['m_hit']?>"/>&nbsp;<input type="checkbox" name="isupdatetime" value="1" checked class="checkbox" />更新时间</td>
	</tr>
	<tr><td colspan="2" style="padding:0" class="noborder"><div style="" id="m_playarea"><?php
	$playArray=getPlayurlArray($vrow['m_playdata']);
	$playTypeCount=count($playArray);$m=0;
	if($vrow['m_playdata'] != "") {
		for ($i = 0;$i < $playTypeCount;$i++) {
			$m=$i+1;
			$playStr=$playArray[$i];
			$playArray2=explode("$$",$playStr) ; $playfrom=$playArray2[0];
			$playUrl=replaceStr($playArray2[1],chr(10),"");
			$playUrl=replaceStr($playUrl,"#",chr(13));
		?>
        <table width='100%' id='playfb<?=$m?>'><tr><td align='right' height='22'  width='70'>播放来源<?=$m?>：</td><td>
		<select id='m_playfrom<?=$m?>' name='m_playfrom[<?=$m?>]'>
		<option value=''>暂没有数据<?=$m?></option>
	   <?=makePlayerSelect($playfrom)?>
		</select>
		<input type='button' class='btn' value='WEB采集' onclick='viewGatherWin(<?=$m?>);selectTogg();'/>&nbsp;&nbsp;<img onclick="var tb=$('playfb<?=$m?>');tb.parentNode.removeChild(tb);" src='imgs/btn_dec.gif' class='pointer' alt="删除播放来源<?=$m?>" align="absmiddle"/>&nbsp;&nbsp;<font color='red'>＊</font>&nbsp;&nbsp;<a href="javascript:moveTableUp($('playfb<?=$m?>'))">上移</a>&nbsp;&nbsp;<a href="javascript:moveTableDown($('playfb<?=$m?>'))">下移</a></td></tr><tr><td align='right' height='22'>数据地址<?=$m?>：<br/><input type='button' value='校正' title='校正右侧文本框中的数据格式' class='btn' onclick='repairUrl(<?=$m?>)' /></td><td><textarea id='m_playurl<?=$m?>' name='m_playurl[<?=$m?>]' rows='8' cols='100'><?=$playUrl;?></textarea>&nbsp;&nbsp;<font color='red'>＊</font></td></tr>
		</table>
		<?php
    }
}
?>
	</div></td></tr>
	<tr><td colspan='2'>&nbsp;<img onclick="expendPlayArea(<?=$m+1?>,escape('<?=$makePlayerSelectStr?>'),0)" src='imgs/btn_add.gif' class='pointer' align="absmiddle"/>&nbsp;&nbsp;<font color="red">您可以单击前面的按钮添加一组播放来源</font></td></tr>
    <tr><td colspan="2" style="padding:0" class="noborder"><div style="" id="m_downarea">
    <?php
	$downArray=getPlayurlArray($vrow['m_downdata']);
	$downTypeCount=count($downArray);$n=0;
	if($vrow['m_downdata'] != "") {
	    for($j = 0;$j < $downTypeCount;$j++){
			$n=$j+1;
			$downStr=$downArray[$j];
			$downArray2=explode("$$", $downStr) ; $downfrom=$downArray2[0];
			$downUrl=replaceStr($downArray2[1],chr(10),"") ; $downUrl=replaceStr($downUrl,"#",chr(13));
		?>
		<table width="100%" id='downfb<?=$n?>'><tr><td align='right' height='22'  width='70'>下载来源<?=$n?>：</td><td>
		<select id='m_downfrom<?=$n?>' name='m_downfrom[<?=$n?>]'>
		<option value=''>暂无数据<?=$n?></option>
        <?=makeDownSelect($downfrom)?>
		</select>
		&nbsp;&nbsp;<img onclick="var tb=$('downfb<?=$n?>');tb.parentNode.removeChild(tb);" src='imgs/btn_dec.gif' class='pointer' alt="删除下载来源<?=$n?>" align="absmiddle"/>&nbsp;&nbsp;
		</td></tr><tr><td align='right' height='22'>下载地址<?=$n?>：</td><td><textarea id='m_downurl<?=$n?>' name='m_downurl[<?=$n;?>]' rows='8' cols='100'><?=$downUrl;?></textarea></td></tr>
		</table>
		<?php
         }
	}
	?>
	</div></td></tr> 
	<tr><td colspan='2'>&nbsp;<img onclick="expendDownArea(<?=$n+1?>,escape('<?=$makeDownSelectStr?>'),0)" src='imgs/btn_add.gif' class='pointer' align="absmiddle"/>&nbsp;&nbsp;<font color="red">您可以单击前面的按钮添加一组下载来源</font></td></tr>
    <tr>
		<td align="right" height="22"></td>
		<td>说明:程序默认每行为一个播放地址，多集请分行，不能有空行</td>
	</tr>
	<tr>
		<td align="right" height="22">相关介绍：</td>
		<td>
  <?php
        GetEditor('m_des', $vrow['m_des']);
	?>
  		</td>
	</tr>

	<tr><input type="hidden" name="m_id" value="<?=$id?>"><input type="hidden" name="m_back" value="<?=$_SERVER['HTTP_REFERER']?>" />
	<td></td><td class="forumRow"><input type="submit" name="submit" class="btn" value="确认保存" onClick="return chform();">&nbsp;<input type=reset name=Submit2 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);
}
function chform(){
	if($('m_name').value.length==0){
		alert('请填写名称');
		return false;
	};
	if($('m_type').value.length==0){
		alert('请选择分类');
		return false;
	};
	if($('m_publishyear').value.length>0){
		if(isNaN($('m_publishyear').value)){
			alert('年份请填写数字');
			return false;
		}
	}
	var c=document.getElementsByName("m_playfrom"),
	ct=document.getElementsByName("m_playurl"),
	d=document.getElementsByName("m_downfrom"),
	dt=document.getElementsByName("m_downurl");
	for(var i=0;i<c.length;i++){
		if(c[i].selectedIndex==0 && ct[i].value!=''){
			alert('请选择每个播放来源');c[i].focus();
			return false;
		}
	}
	for(var i=0;i<d.length;i++){
		if(d[i].selectedIndex==0 && dt[i].value!=''){
			alert('请选择每个下载来源');d[i].focus();
			return false;
		}
	}
	return true;
}
$('editform').m_name.focus();</script>
</div>
<?php
}

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

function saveVideo(){
	$actType = getForm("acttype","get");
	$m_id = getForm("m_id","post");if (!is_numeric($m_id)) $m_id = 0;
	$m_name = getForm("m_name","post");
	$m_keyword = replaceStr(replaceStr(getForm("keyword","post"),chr(13),""),chr(10),"");
	$isuppingyin = getForm("isuppingyin","post")=="1";
	$m_enname = getForm("m_enname","post");if (empty($m_enname)) $m_enname = MoviePinYin($m_name);
	$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_state = getForm("m_state","post");if (empty($m_state)) $m_state=0;
	$m_type = getForm("m_type","post");if (empty($m_type)){ alertMsg("请选择分类","javascript:history.go(-1);");die("");}
	$m_pic = getForm("m_pic","post");
	$m_actor = getForm("m_actor","post");
	$m_note = replaceSpecial(getForm("m_note","post"));
	$m_des = replaceSpecial(getForm("m_des","post"));
	$m_addtime = getForm("m_addtime","post");
	$m_publishyear = getForm("m_publishyear","post");if (empty($m_publishyear)) $m_publishyear = 0;
	$m_publisharea = getForm("m_publisharea","post");if (empty($m_publisharea)) $m_publisharea = "";
	$m_topic = getForm("m_topic","post");if (empty($m_topic)) $m_topic = 0;
	$m_director = getForm("m_director","post");
	$m_lang = getForm("m_lang","post");
	$m_commend = getForm("m_commend","post");if (is_numeric($m_commend)){ $m_commend = intval($m_commend);}else{;$m_commend = 0;}
	$m_playfrom = getForm("m_playfrom","post");
	$m_score=getForm("m_score","post");;if (empty($m_score)) $m_score = 0;
	$m_playurl = getForm("m_playurl","post");
	if (!empty($m_playurl)){
		$m_playurl = repairUrlForm($m_playurl,$m_playfrom);
    }
	$m_playdata=transferUrl($m_playfrom,$m_playurl);
	$m_downfrom=getForm("m_downfrom","post");
	$m_downurl=getForm("m_downurl","post");
	if (!empty($m_downurl)){
		$m_downurl = repairDownUrl($m_downurl,$m_downfrom);
	}
	$m_downdata=transferUrl($m_downfrom,$m_downurl);
	$isupdatetime=getForm("isupdatetime","post");
	$feedarr = array(
		'm_keyword' => $m_keyword,
		'm_hit' => $m_hit,
		'm_letter' => msubstr($m_enname,1),
		'm_name' => $m_name,
		'm_color' => $m_color,
		'm_state' => $m_state,
		'm_type' => $m_type,
		'm_pic' => $m_pic,
		'm_actor' => $m_actor,
		'm_score' => $m_score,
		'm_note' => $m_note,
		'm_des' => $m_des,
		'm_publishyear' => $m_publishyear,
		'm_publisharea' => $m_publisharea,
		'm_topic' => $m_topic,
		'm_playdata' => $m_playdata,
		'm_downdata' => $m_downdata,
		'm_director' => $m_director,
		'm_lang' => $m_lang,
		'm_enname' => $m_enname,
		'm_commend' => $m_commend,
	);
	switch (trim($actType)) {
		case "edit":
			if (!empty($isupdatetime)){ $feedarr['m_addtime'] = time();}
			DB::update('data', $feedarr, array('m_id' => $m_id));
			if (runMode == "static") {
				$trow = DB::fetch_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('data')." WHERE m_id=$m_id");
					delContentAndPlayFile($m_type, $m_id, $row['m_enname'], $row['m_datetime']);
					alertMsg("", $m_back);
				} else { 
					alertMsg("", "admin_makehtml.php?action=single&id=$m_id&from=$m_back");
				}
			} else { 
				alertMsg("", $m_back);
			}
			break;
		case "add": 
			$feedarr['m_addtime'] = time();
			$feedarr['m_datetime'] = time();
			DB::insert('data', $feedarr);clearTypeCache();
			if (empty($m_back)) $m_back = "admin_video.php?action=add";
			selectMsg("添加成功,是否继续添加", $m_back, "admin_video.php");exit();
	}
}

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

function pSetTopic() {
	$topicId = getForm("ptopic","post");
	$back = getRefer();
	$ids = getForm("m_id","post");
	if (empty($ids)) die("请选择需要设置专题的数据");
	DB::update('data', array('m_topic' => $topicId),'m_id IN ('.dimplode($ids).')');
	alertMsg("", $back);
}

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

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

function delVideo($id,$sel) {
	$back = getRefer();
	if (empty($id)) alertMsg("",$back);
	$row = DB::result_first("SELECT m_type,m_pic,m_enname,m_datetime FROM ".DB::table('data')." WHERE m_id=$id");
	$vpic=$row['m_pic'];delContentAndPlayFile($row['m_type'],$id,$row['m_enname'],$row['m_datetime']);
	if ($sel=="del"){
		if (substr($vpic, 0, 8) == '/pic') delFile("../".$vpic);
		DB::delete('data', array('m_id' => $id));
	}else{
		DB::update('data', array('m_recycle' => 1),array('m_id' => $id));
	}
	clearTypeCache();
}

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

function restoreVideo() {
	global $back;
	$ids = dimplode(getForm("m_id","both"));
	DB::update('data', array('m_recycle' => 0),'m_id IN ('.$ids.')');
	if (runMode == "static") {
		echo "数据还原成功,准备重新生成....<form action=\"admin_makehtml.php?action=selected\" 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(",", getTypeNameTemplateArrayOnCache(intval($str)));
	if(empty($viewDataType[0])) $viewDataType[0]="<font color=red >数据分类错误</font>";
	return $viewDataType[0];
}

function clearTypeCache(){
	if (cacheStart==1) memory('rm','array_type_lists_all');
}

function isVideoMake($v_id, $contentUrl) {
	echo "<a href=\"admin_makehtml.php?action=single&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>";
}
?>
