<?php
/*
'**************************************************************************************************
' 程序名称: CCTVAI开源音乐管理系统
' 官方网站: http://www.cctvai.com
' 联系 Q Q: 1542367792
' QQ交流群：136687984
' 版本：(终结版)
' 备注：未经书面授权，不得向任何第三方提供本软件系统！
' 功能，模板，插件，扩展，定制请联系QQ：1542367792
'**************************************************************************************************
*/
error_reporting(0); 
include "../include/cctvai.conn.php";
if(cd_mobile=="no"){header("Location:".cd_webpath."");exit();}
if(cd_mobilepc=="no"){if (!isMobile()){header("Location:".cd_webpath."");exit();}}
@header('Cache-control: private');
$key=str_checkhtml(SafeRequest('key', 'get'));
$ac=str_checkhtml(SafeRequest('ac', 'get'));
$p=SafeRequest("pages", "get");
if (empty($key) || empty($ac)) {echo'<meta charset="gbk" />';exit("<script>alert('请输入查询的关键字');history.go(-1);</script>");}
$error="您访问的Url页面不存在，请检查Url是否正确或包含非法字符！";
if(!IsNumID($p)) {exit(include _cctvai_root_ . "/include/error/content_error.php");}
?>
<!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=gbk" /> 
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" /> 
  <meta name="apple-mobile-web-app-capable" content="yes" /> 
  <meta name="apple-mobile-web-app-status-bar-style" content="black" /> 
  <meta name="format-detection" content="telephone=no" /> 
  <title><?php echo $key;?>搜索-<?php echo cd_webname?>手机版</title> 
  <meta name="keywords" content="<?php echo $key;?>搜索,<?php echo cd_webname?>手机版" /> 
  <meta name="description" content="<?php echo $key;?>搜索,<?php echo cd_webname?>手机版" /> 
  <link rel="stylesheet" href="css/style.css" type="text/css" />
  <link rel="stylesheet" href="css/so.css" type="text/css" />
  <link rel="stylesheet" href="css/list.css" type="text/css" />
 </head> 
 <body> 
<?php include "nav.php";?>
  <div class="x5_wap"> 
<?php include "head.php";?>
   <div class="so"> 
	<form action="so_list.php" method="get"> 
	<div id="search">
	<input type="hidden" name="ac" value="<?php echo $ac?>" /> 
    <input type="text" name="key">
    <input class="button" type="submit" value="搜索">
	</div>
	</form> 
    <div class="class"> 
     <li <?php if($ac=="dj"){echo 'class="current"';}?>><a href="?ac=dj&key=<?php echo $key?>">音乐</a></li> 
     <li <?php if($ac=="malbum"){echo 'class="current"';}?>><a href="?ac=malbum&key=<?php echo $key?>">歌单</a></li> 
     <li <?php if($ac=="video"){echo 'class="current"';}?>><a href="?ac=video&key=<?php echo $key?>">视频</a></li> 
     <li <?php if($ac=="valbum"){echo 'class="current"';}?>><a href="?ac=valbum&key=<?php echo $key?>">视频集</a></li> 
     <li <?php if($ac=="singer"){echo 'class="current"';}?>><a href="?ac=singer&key=<?php echo $key?>">歌手</a></li> 
    </div> 
   </div> 
<!--music-->
<?php
if($ac=="dj") {
	$singername=$db->getrow("select CD_ID from " . tname('singer') . " where CD_Name='" . $key . "'");
	if($singername) {$addsql="or CD_Singer='" . $singername['CD_ID'] . "'";}
	$sqlstr='select CD_User,CD_ID,CD_Name from ' . tname('dj') . " where CD_Deleted=0 and CD_ClassID<>0 and CD_Name like '%" . $key . "%' $addsql or CD_Tag like '%" . $key . "%' order by CD_AddTime desc";
?>
   <div class="dance-list"> 
   <div class="head"><strong>音乐搜索:<?php echo $key?></strong></div> 
    <ul class="musicList" style="margin-top: 5px;"> 
<?php
$Arr=getuserpage($sqlstr, 20); //sql,每页显示条数
$result=$db->query($Arr[2]);
$num=$db->num_rows($result);
if($num==0) {
		echo '<center>No.music</center>';
} else {
	if($result) {
		while($dj=$db->fetch_array($result)) {
echo '<li> <span class="t-i"><img src="'.linkuserphoto(GetAlias("cctvai_user", "cd_id", "cd_name", $dj['CD_User']), 48).'" /></span> <span class="t-t"><strong><a href="play_p.php?id='.$dj['CD_ID'].'">'.$dj['CD_Name'].'</a></strong><em>'.GetAlias("cctvai_user", "cd_nicheng", "cd_name", $dj['CD_User']).'</em></span> <a href="play_p.php?id='.$dj['CD_ID'].'"><span class="t-z"></span></a> </li>';
}
} 
}
?>
    </ul> 
	<div style="text-align: center;"><?php echo $Arr[0];?></div>
   </div> 
<!--music end-->
   
<!--malbum-->
<?php
} elseif($ac=="malbum") {
	$singername=$db->getrow("select CD_ID from " . tname('singer') . " where CD_Name='" . $key . "'");
	if($singername) {$addsql="or CD_Singer='" . $singername['CD_ID'] . "'";}
	$sqlstr='select CD_ID,CD_Pic,CD_Name,CD_GongSi,CD_YuYan from ' . tname('malbum') . " where CD_ClassID<>0 and CD_Name like '%" . $key . "%' $addsql or CD_GongSi like '%" . $key . "%' or CD_YuYan like '%" . $key . "%' order by CD_AddTime desc";
?>
   <div class="valbum-list" style="margin-bottom: 5px;"> 
    <div class="head"><strong>歌单搜索:<?php echo $key?></strong></div> 
   </div> 
<?php 
$Arr=getuserpage($sqlstr, 20); //sql,每页显示条数
$result=$db->query($Arr[2]);
$num=$db->num_rows($result);
if($num==0) {
		echo '<center>No.album</center>';
} else {
	if($result) {
		while($malbum=$db->fetch_array($result)) {
echo '   <div class="singer" style="margin-top: 10px;"> 
    <ul class="list_con" id="yc_list_tj"> 
     <li> 
	 <a href="malbum_p.php?id='.$malbum['CD_ID'].'" class="m_head"><img alt="" src="'.LinkPicUrl($malbum['CD_Pic'],"malbum").'" width="60" height="60" /></a> 
	 <a href="malbum_p.php?id='.$malbum['CD_ID'].'" style="padding: 10px 0px;"> <h4 style="font-size: 14px;">'.$malbum['CD_Name'].'</h4> <p><span>语言&nbsp;:&nbsp;'.$malbum['CD_YuYan'].'</span><span>发行&nbsp;:&nbsp;'.$malbum['CD_GongSi'].'</span></p> </a> </li> 
    </ul> 
    <div> 
    </div> 
   </div>';
}
} 
} 
?>
	<div style="text-align: center;margin-top: 10px;"><?php echo $Arr[0];?></div>
   </div> 
<!--malbum end-->

<!--video-->
<?php
} elseif($ac=="video") {
	$singername=$db->getrow("select CD_ID from " . tname('singer') . " where CD_Name='" . $key . "'");
	if($singername) {$addsql="or CD_Singer='" . $singername['CD_ID'] . "'";}
	$sqlstr='select CD_Hits,CD_Pic,CD_ID,CD_Name,CD_LastHitTime from ' . tname('video') . " where CD_Deleted=0 and CD_ClassID<>0 and CD_Name like '%" . $key . "%' $addsql or CD_Tag like '%" . $key . "%' order by CD_AddTime desc";
?>
   <div class="video-list" style="margin-top: 10px;"> 
    <div class="head"><strong>视频搜索:<?php echo $key?></strong></div> 
<?php 
$Arr=getuserpage($sqlstr, 20); //sql,每页显示条数
$result=$db->query($Arr[2]);
$num=$db->num_rows($result);
if($num==0) {
		echo '<center>No.video</center>';
} else {
	if($result) {
		while($video=$db->fetch_array($result)) {
echo '    <div class="videoMv" onclick="window.open(\'video_p.php?id='.$video['CD_ID'].'\',\'_self\')">
     <p class="videoMvImg"><img src="'.LinkPicUrl($video['CD_Pic'],"video").'" width="100%" height="75" /></p>
     <p class="videoRiTex"><span class="videoRiName">'.$video['CD_Name'].'</span><span class="videoRiHits">人气：'.$video['CD_Hits'].'</span><span class="videoRiHits">推荐时间：'.datetime($video['CD_LastHitTime']).'</span></p>
    </div> ';
}
} 
} 
?>
	<div style="text-align: center;margin-top: 10px;"><?php echo $Arr[0];?></div>
   </div> 
<!--video end-->

<!--valbum-->
<?php
} elseif($ac=="valbum") {
	$singername=$db->getrow("select CD_ID from " . tname('singer') . " where CD_Name='" . $key . "'");
	if($singername) {$addsql="or CD_Singer='" . $singername['CD_ID'] . "'";}
	$sqlstr='select CD_ID,CD_Pic,CD_Name,CD_GongSi,CD_YuYan from ' . tname('valbum') . " where CD_ClassID<>0 and CD_Name like '%" . $key . "%' $addsql or CD_GongSi like '%" . $key . "%' or CD_YuYan like '%" . $key . "%' order by CD_AddTime desc";
?>
   <div class="valbum-list" style="margin-bottom: 5px;"> 
    <div class="head"><strong>视频集搜索:<?php echo $key?></strong></div> 
   </div> 
<?php 
$Arr=getuserpage($sqlstr, 20); //sql,每页显示条数
$result=$db->query($Arr[2]);
$num=$db->num_rows($result);
if($num==0) {
		echo '<center>No.album</center>';
} else {
	if($result) {
		while($valbum=$db->fetch_array($result)) {
echo '   <div class="singer" style="margin-top: 10px;"> 
    <ul class="list_con" id="yc_list_tj"> 
     <li> 
	 <a href="valbum_p.php?id='.$valbum['CD_ID'].'" class="m_head"><img alt="" src="'.LinkPicUrl($valbum['CD_Pic'],"valbum").'" width="60" height="60" /></a> 
	 <a href="valbum_p.php?id='.$valbum['CD_ID'].'" style="padding: 10px 0px;"> <h4 style="font-size: 14px;">'.$valbum['CD_Name'].'</h4> <p><span>语言&nbsp;:&nbsp;'.$valbum['CD_YuYan'].'</span><span>发行&nbsp;:&nbsp;'.$valbum['CD_GongSi'].'</span></p> </a> </li> 
    </ul> 
    <div> 
    </div> 
   </div>';
}
} 
} 
?>
	<div style="text-align: center;margin-top: 10px;"><?php echo $Arr[0];?></div>
   </div> 
<!--valbum end-->

<!--singer-->
<?php
} elseif($ac=="singer") {
	$sqlstr='select CD_Pic,CD_ID,CD_Name,CD_Birthday,CD_Birth from ' . tname('singer') . " where CD_Name like '%" . $key . "%' order by CD_AddTime desc";
?>
   <div class="dance-list" style="margin-bottom: 10px;"> 
   <div class="head"><strong>歌手搜索:<?php echo $key?></strong></div> 
   </div> 
<?php 
$Arr=getuserpage($sqlstr, 20); //sql,每页显示条数
$result=$db->query($Arr[2]);
$num=$db->num_rows($result);
if($num==0) {
		echo '<center>No.singer</center>';
} else {
	if($result) {
		while($singer=$db->fetch_array($result)) {
echo '   <div class="singer" style="margin-top: 10px;"> 
    <ul class="list_con" id="yc_list_tj"> 
     <li> 
	 <a href="artist_p.php?id='.$singer['CD_ID'].'" class="m_head"><img alt="" src="'.LinkPicUrl($singer['CD_Pic'],"singer").'" width="60" height="60" /></a> 
	 <a href="artist_p.php?id='.$singer['CD_ID'].'" style="padding: 10px 0px;"> <h4 style="font-size: 14px;">'.$singer['CD_Name'].'</h4> <p><span>生日&nbsp;:&nbsp;'.$singer['CD_Birthday'].'</span><span>地区&nbsp;:&nbsp;'.$singer['CD_Birth'].'</span></p> </a> </li> 
    </ul> 
    <div> 
    </div> 
   </div>';
}
} 
} 
?>
	<div style="text-align: center;margin-top: 10px;"><?php echo $Arr[0];?></div>
<!--singer end-->

<?php }	?>
	
  </div> 
<?php include "bottom.php";?>
 </body>
</html>
<?php
function getuserpage($mysql, $pagesize) {
	global $db;
	$url=$_SERVER["QUERY_STRING"];
	if(stristr($url, '&pages')) {
		$url=preg_replace('/&pages=([\S]+?)$/', '', $url);
	}
	if(stristr($url, 'pages')) {
		$url=preg_replace('/pages=([\S]+?)$/', '', $url);
	}
	if(IsNul($url)) {
		$url.="&";
	}
	$pages=SafeRequest("pages", "get");
	$pagesok=$pagesize; //每页显示记录数
	if(!isset($pages)||$pages==""||!is_numeric($pages)||$pages<=0) {
		$pages=1;
	}
	$sqlstr=$mysql;
	$res=$db->query($sqlstr);
	$nums=$db->num_rows($res);
	if($nums==0) {
		$nums=1;
	}
	$pagejs=ceil($nums/$pagesok); //总页数
	if($pages>$pagejs) {
		$pages=$pagejs;
	}
	$sql=$sqlstr . " LIMIT " . $pagesok*($pages-1) . "," . $pagesok;
	$result=$db->query($sql);
	if($pagejs>1) {
		if($pages>0) {
			$str.="<a href=\"?" . $url . "pages=" . ($pages-1) . "\" target=\"_self\">上一页</a>　　　";
		}
		if($pages<$pagejs) {
			$str.="<a href=\"?" . $url . "pages=" . ($pages+1) . "\" target=\"_self\">下一页</a>";
		}
	}
	while($row=$db->fetch_array($result)) {
	}
	$arr=array(
		$str,
		$result,
		$sql,
		$pagejs
	);
	return $arr;
}
?>