<?php
	require_once('_approot.php');	
	$selectcate=$_GET['selectcate'];
	$sort_field = $_GET['sort_field'];
	
	$showstr = "视频";
	if ($_GET['ls_msg']=="")
	{
		$ls_msg=$showstr."管理";
	}	
	else
	{
		$ls_msg=$_GET['ls_msg'];	
	}
	$ls=$_GET['ls'];
	$id=$_GET['id'];

	$searchproductName=($_POST['searchproductName']==""?$_GET['searchproductName']:$_POST['searchproductName']);
	if($searchproductName!="") $ls_msg="包含 $searchproductName 的视频 ";
	if($_POST['gopage']!=""){$gopage =(ctype_digit($_POST['gopage'])?$_POST['gopage']:1);}
	if($gopage!="") $ls_msg="第 $gopage 页的视频 ";

	switch ($ls)
	{
		case "up":
			$up_sql="update ls_video set Num=Num+1 where id=".$id." ";
			//echo $up_sql;
			$up_query=$opendb->query($up_sql);
			$ls_msg="下移操作成功！";
			break;
		case "down":
			$down_sql="update ls_video set Num=Num-1 where id=".$id." ";
			//echo $down_sql;
			$down_query=$opendb->query($down_sql);
			$ls_msg="上移操作成功！";
			break;
	 	case "unenable":
			$unenable_sql="update ls_video set enable=0 where id=".$id." ";
			//echo $unenable_sql;
			$unenable_query=$opendb->query($unenable_sql);
			$ls_msg="不显示操作成功！";
			break;
		case "enable":
			$enable_sql="update ls_video set enable=1 where id=".$id." ";
			//echo $enable_sql;
			$enable_query=$opendb->query($enable_sql);
			$ls_msg="显示操作成功！";
			break;
	  case "del":
	  	$select_sql="select * from ls_video where ID=".$id."";
	  	$select_query=$opendb->query($select_sql);
	  	$select_myrows=mysqli_fetch_assoc($select_query);
 		$Bigpicsrc="../".$videoFolders."/".$select_myrows['videoPic'];
		$Smallpicsrc="../".$videoFolders."/".str_replace(".","_b.",$select_myrows['videoPic']);
		unlink($Bigpicsrc);
 		$videoFile="../".$videoFolders."/".$select_myrows['videoFile'];
		
		if(!unlink($Smallpicsrc)) $ls_msg.=$Smallpicsrc."封面图片删除错误! "; else $ls_msg.=$Smallpicsrc."封面图片已删除! ";
		if(!unlink($videoFile)) $ls_msg.=$videoFile."视频文件删除错误! "; else $ls_msg.=$videoFile."视频文件已删除! ";// 

	  	$del_sql="delete from ls_video where ID=".$id."";
	   	//echo $del_sql;
	   	$del_query=$opendb->query($del_sql);
		$cateName=$select_myrows['cateName'];
		if(strpos($defaultvideo,$cateName)===false){
			$tpl=$cateName.".html";
			$tplshow=str_replace(".","show.",$tpl);
			if(file_exists("../Templates1/".$tpl)) 
				if(!unlink("../Templates1/".$tpl)) $ls_msg.=$tpl."模板删除错误! "; else $ls_msg.=$tpl."模板已删除! ";//复制模板
			if(file_exists("../Templates1/".$tplshow)) 
				if(!unlink("../Templates1/".$tplshow)) $ls_msg.=$tplshow."模板删除错误! "; else $ls_msg.=$tplshow."模板已删除! ";//复制模板
		}
		
	   	$ls_msg="删除操作成功！".$ls_msg;
	  	break;
	  	case "scan":
		
			$scan_sql = "select * from ls_video ORDER BY Num ";
			$scan_query = $opendb->query($scan_sql);
			$scan_num = 0;
			
			while($scan_rows=mysqli_fetch_assoc($scan_query)){
				$scan_num++;
				$modi_sql=sprintf("update ls_video set Num=%s where ID=%s",
							GetSQLValueString($scan_num, "text"),
							GetSQLValueString($scan_rows['ID'], "int")
						);
				//echo $modi_sql;
				$modi_query=$opendb->query($modi_sql);
			}
			
			break;
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<link href="css/admin.css" rel="stylesheet" type="text/css">
         <link rel="stylesheet" href="css/style2.css" />
		<script language="JavaScript" src="js/ls.js"></script>
		<title>无标题文档</title>
        <script src="scripts/swfobject_modified.js" type="text/javascript"></script>
	</head>

 <body>
	<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" >
            <tr>
				<td height="18" style="border-bottom:2px solid #00c0ef; padding-bottom:5px;"><div align="center"><font color="#3c8dbc" style="font-size:16px;"><?=$showstr?>管理</font></div>
				</td>
			</tr>
			<tr>
				<td height="" valign="top"><br>
					<form name="del" method="Post" action="delall.php&page=<?=$page?>&searchproductName=<?=$searchproductName?>" >
					<table border="0" width="98%" align="center">
						<tr>
							<td style="border-bottom:1px solid #FFF;">提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
							<td align="right" style="border-bottom:1px solid #FFF;"><img src="images/shao.gif">&nbsp;<a href="addvideo.php?page=<?=$page?>&searchproductName=<?=$searchproductName?>"><u>添加</u></a> &nbsp; &nbsp; <?php if(!(strpos($_SERVER['HTTP_REFERER'],"managearticle")===false)){ ?> <a href="managearticle.php">返回</a><?php } ?></td>
						</tr>
					</table>
					<?php
					// 获取当前页数
					if( isset($_GET['page']) ){
					   $page = intval( $_GET['page'] );
					}
					else{
					   $page = 1;
					}
					// 每页数量
					$PageSize = $PageNum;
					
					// 获取总数据量
					/********************************************************************************/
						if($searchproductName!=""){ $searhprostr=" where (videoName like '%".$searchproductName."%' or videoText like '%".$searchproductName."%' or date like '%".$searchproductName."%'    ) "; 
						$searhprostr2=" and (videoName like '%".$searchproductName."%' or videoText like '%".$searchproductName."%' or date like '%".$searchproductName."%'    ) "; 
						}
					
						$sql = "select * from ls_video ". $searhprostr." order by ID desc";
						$result=$opendb->query($sql);
					
					/********************************************************************************/
					// 获取总数据量
					
					$row = mysqli_num_rows($result);
					$amount = $row;
					
					// 记算总共有多少页
					if( $amount ){
					   if( $amount < $PageSize ){ $page_count = 1; }               //如果总数据量小于$PageSize，那么只有一页
					   if( $amount % $PageSize ){                                  //取总数据量除以每页数的余数
						   $page_count = (int)($amount / $PageSize) + 1;           //如果有余数，则页数等于总数据量除以每页数的结果取整再加一
					   }else{
						   $page_count = $amount / $PageSize;                      //如果没有余数，则页数等于总数据量除以每页数的结果
					   }
					}
					else{
					   $page_count = 0;
					}
					
					// 翻页链接
					$page_string = '';
						
					if( $page == 1 ){
					   $page_string .= '首页 | 上一页 |';
					}
					else{
					   $page_string .= '<a href=?page=1&searchproductName='.$searchproductName.'><u><font color=\"#0000FF\">首页</font></u></a> | <a href=?page='.($page-1).'&searchproductName='.$searchproductName.'><u><font color=\"#0000FF\">上一页</font></u></a> | ';
					}
					if( ($page == $page_count) || ($page_count == 0) ){
					   $page_string .= ' 下一页 | 尾页';
					}
					else{
					   $page_string .= ' <a href=?page='.($page+1).'&searchproductName='.$searchproductName.'><u><font color=\"#0000FF\">下一页</font></u></a> | <a href=?page='.$page_count.'&searchproductName='.$searchproductName.'><u><font color=\"#0000FF\">尾页</font></u></a>';
					}
						 $page_string .= " &nbsp;&nbsp;页次：<font color='#FF0000'><b>".$page."</b></font>/<b>".$page_count."</b>页";
						 $page_string .= " &nbsp;&nbsp;<b>".$PageSize."</b>个视频每页";
						 
					$ls_msg2=$showstr."管理 >> 所有".$showstr;

					?>
					
        		
   		  <table border="0" width="98%" align="center">
						<tr>
							<td width="20%"><?php echo $ls_msg2; ?></td>
							<td width="60%" align="right">&nbsp;</td>
							<td width="20%" align="right">&nbsp;</td>
						</tr>
						<tr>
						  <td height="30">分类：
                            <?php 							$news_sql="SELECT distinct cateName FROM ls_video  where enable=1 ". $searhprostr2."  order by Num";//count the error by searchtype
						$news_query=$opendb->query($news_sql);
                          while($news_rows2=mysqli_fetch_assoc($news_query))
		  					{
								echo "<a href='?selectcate=".$news_rows2['cateName']."'>".$news_rows2['cateName']."</a> | ";
							}
				 			
						  ?>
                          <a href='?selectcate='> 全部 </a></td>
						  <td align="right">&nbsp;</td>
						  <td align="right">共 <b><?php echo $row; ?></b> 个视频</td>
				  </tr>
					 </table>
					 <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#f0f0ee">
				  <tr height="37">
							<td align="center"  width="29">首页</td>
							<td align="center" width="41">分类</td>
							<td align="center" width="77">封面图</td>
							<td align="center" width="207"><?=$showstr?></td>
							<td align="center" width="145">名称</td>
 							<td align="center" width="283">Title / 简介</td>
							<td align="center" width="53">宽 / 高</td>
                           <td align="center" width="46">时间 / 结束</td>
							<td align="center" colspan="2">排序</td>
							<td align="center" colspan="2">操作</td>
							<td align="center" width="61">显示</td>
						</tr>
						<?php
						if($selectcate<>''&&$selectcate<>'全部'){	
						//$sql="select * from ls_news where cate='".$selectcate."' order by Num desc ";
						$sql="select * from ls_video  where  cateName='".$selectcate."'  ". $searhprostr2."  ";
					}else{	
						//$sql="select * from ls_news where cate='news' order by Num desc ";
						$sql="select * from ls_video  ". $searhprostr."   ";
					}
							$news_sql=$sql."  order by Num desc limit ". ($page-1)*$PageSize .",".$PageSize." ";	
							$news_query=$opendb->query($news_sql);

							$i=1;
							while($news_rows=mysqli_fetch_assoc($news_query))
							 { ?>
							<tr bgcolor='#f9f9f9' height='37'
						onMouseOver=
							 	this.style.backgroundColor='#e5e5e5' 
							onMouseOut=
							 	this.style.backgroundColor='#f9f9f9' 
							>
								<td align='center'><?php 							if($news_rows['videoBool']!=1){
								$videoBool = "";
							}else{
								$videoBool = "checked";
							}?>
									<input name='select_id<?=$news_rows['ID']?>' type='checkbox' <?=$videoBool?> onclick="unselectall()" id="select_id" value='<?=$news_rows['ID']?>'>
								</td>
								<td style='padding-left:10px;'><?=$news_rows['cateName']?></td>
								<td style='padding-left:10px;'> 
								 <img src='<?=$news_rows['videoPic']==""?"":"../".$videoFolders."/".$news_rows['videoPic']?>' width='' height='70' border='0' name='pic' /> 
								</td>
						  	<td style='padding-left:10px;'>
						 <?php  if($news_rows['code'] == NULL|| $news_rows['code'] == ""){ ?>
						  	<video src='../video/<?=$news_rows['videoFile']?>'   width='200' controls preload='auto'/>
						 <?php }else{ ?>
							  <a href='<?=$news_rows['code']?>' title='视频链接 <?=$news_rows['code']?>'  /><?=substr($news_rows['code'],0,30)?></>  
						<?php }?>
						  	</td>
						  	<td style='padding-left:10px;'>
						  <?=$news_rows['videoName']?> </td>
						  	<td style='padding-left:10px;'>
						      <p>
						        <?=$news_rows['newsTitle']?>
					          </p>
						      <?=$news_rows['videoText']==""?"":"简介：".$news_rows['videoText']?></td>
						  	<td style='padding-left:10px;'>
						  宽<?=$news_rows['videoW']?><br /><br />
						  宽<?=$news_rows['videoH']?>
						  	</td>
						  	<td align='center'>
						  <?=$news_rows['date']?>
                         <?=$news_rows['endtime']==""?"":" - ".$news_rows['endtime']?>
						  	</td>
						  	<td width="14" align='center'> 
								<a href='?id=<?=$news_rows['ID']?>&ls=up&page=<?=$page?>&searchproductName=<?=$searchproductName?>' title='向上移动'><img src='images/up.gif' border='0'></a>
							  </td>
								<td width="14" align='center'> 
								 <a href='?id=<?=$news_rows['ID']?>&ls=down&page=<?=$page?>&searchproductName=<?=$searchproductName?>' title='向下移动'><img src='images/down.gif' border='0'></a>
							  </td>
								<td width="16" align='center'> 
									<a href='modivideo.php?id=<?=$news_rows['ID']?>&page=<?=$page?>&searchproductName=<?=$searchproductName?>' title='编辑'><img src='images/b_edit.png' border='0'></a>
							  </td>
								<td width="16" align='center'> 
									<a href='?id=<?=$news_rows['ID']?>&ls=del&page=<?=$page?>&searchproductName=<?=$searchproductName?>' onclick='return ConfirmDelSubCate();' title='删除'><img src='images/b_drop.png' border='0'></a>
							  </td>
								<td align='center'>
					  
							 <?php  if($news_rows['enable']==1)
								{?>
									<a href='?id=<?=$news_rows['ID']?>&ls=unenable&page=<?=$page?>&searchproductName=<?=$searchproductName?>' title='显示'><img src='images/enable.gif' border='0'></a>
							 <?php }
							  if($news_rows['enable']==0)
								{ ?>
									<a href='?id=<?=$news_rows['ID']?>&ls=enable&page=<?=$page?>&searchproductName=<?=$searchproductName?>' title='不显示'><img src='images/unenable.gif' border='0'></a>
								<?php }?>
														
								</td>
						  </tr>
						  
						 <?php  $i++;
						 } ?>
					 
					</table>
					<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#f0f0ee">
<tr height="47">
							<td width="20%" height="" style="padding-left:6px;">
                            <input name="chkAll" type="checkbox" id="chkAll" onclick=CheckAll(this.form) value="checkbox">
                             所有
                            <button name="submit" type='submit' value='首页显示视频'>首页显示视频</button>
                            <input name="Action" type="hidden" id="Action" value="divioDel">
                            </td>
							<td align="center" style="padding-left:6px;"><?=$page_string?></td>
						</tr>
					</table>
				</form>
				</td>
			</tr>
	</table>
     <form name="searcharticle" method="Post" action="?selectcate=<?=$selectcate?>&selectfunctionName=<?=$selectfunctionName?>" >
			  <table align="center"  cellpadding="4px;" style="width:98%; background-color:#f0f0ee"><tr>
						<td width="57%" align="right"><div align="left"><span style="padding-left:6px;"><span style="padding-left:10px;">模板文件名与类别名相同，如不存在，使用 video.html 和 videoshow.html</span></span></div></td>
						<td width="43%" align="right"><span style="padding-left:6px;">
						  <input type="text" name="searchproductName" size="16" maxlength="50"  value="" />
                          <input type='submit'    value="查询" style="height:24px;"    />
                        </span> <span style="padding-left:26px;">
                        <input name="gopage" id="gopage" type="text" size="3" />
页
<input type='submit'    value="GO"  style="height:24px;"   />
                        </span></td>
						</tr>
			      </table>
				</form>
 </body>
</html>