<?php

/*
'**************************************************************************************************
' 程序名称: CCTVAI开源音乐管理系统
' 官方网站: http://www.cctvai.com
' 联系 Q Q: 1542367792
' QQ交流群：136687984
' 版本：(终结版)
' 备注：未经书面授权，不得向任何第三方提供本软件系统！
' 功能，模板，插件，扩展，定制请联系QQ：1542367792
'**************************************************************************************************
*/
error_reporting(0);
include "../../include/cctvai.conn.php";
require_once("../../include/cctvai.label.php");
include "../function_common.php";
admincheck(10);
echo "<style type='text/css'><!--body,td,th {background-color: #FFFFFF;font-size: 9pt;}a {font-size: 9pt;}a:link {text-decoration: none;color:#3F628C;}a:visited {text-decoration: none;color:#3F628C;}a:hover {text-decoration: none;color:#3F628C;}a:active {text-decoration: none;color:#3F628C;}--></style>";
@set_time_limit(0);
if(cd_webhtml==1 or cd_webhtml==3) {
	die('<font color=red>当前网站为动态模式，不能生成！</font>');
}
$Sel=SafeRequest('sel', 'get');
if($Sel=='single') {
	$ID=SafeRequest('id', 'get');
	$ClassID=SafeRequest('cid', 'get');
	$Mark_Text=SpansingerPlay($ID);
	$spanurl=LinkUrl('singer', $ClassID, 1, $ID);
	$spanurl=substr($spanurl, strlen(cd_webpath));
	spandir($spanurl);
	fwrite(fopen('../../' . $spanurl, 'wb'), $Mark_Text);
	die("<script>window.location='" . $_SERVER['HTTP_REFERER'] . "'</script>");
}
if($Sel=='today' or $Sel=='sday') {
	if(file_exists(_cctvai_root_ . cd_templateurl . 'singer.html')) {
		if($Sel=='sday') {
			$sday=SafeRequest('sdayv', 'auto');
			$cd_title=$sday . '天前更新的歌手';
			$sql='select * from ' . tname('singer') . " where CD_Passed=0 and CD_ClassID<>0 and DATEDIFF(DATE(CD_AddTime),'" . date('Y-m-d') . "')>=-$sday order by CD_ID desc";
		} else {
			$sday=1;
			$cd_title='今天更新的歌手';
			$sql='select * from ' . tname('singer') . " where CD_Passed=0 and CD_ClassID<>0 and DATEDIFF(DATE(CD_AddTime),'" . date('Y-m-d') . "')=0 order by CD_ID desc";
		}
		$Arr=spanhtmlpage($sql, cd_createpre);
		echo ("<div style='width:100%; background: #FAFBF7; border-top:1px solid #ddd; border-bottom:1px solid #ddd;color:#668E1B; font-size:10pt; height:30px; line-height:30px;font-weight:bold; margin:0 auto;'>&nbsp;正在开始生成<font style='color:red; font-size:14px;'>" . $cd_title . "</font>第<font style='color:red; font-size:16px; font-style:italic'>" . $Arr[5] . "</font>页数据，共<font style='color:red; font-size:16px; font-style:italic'>" . $Arr[6] . '</font>页</div><br/>');
		$result=$db->query($Arr[2]);
		if($result) {
			while($row=$db->fetch_array($result)) {
				$Mark_Text=SpansingerPlay($row['CD_ID']);
				$spanurl=LinkUrl('singer', $row['CD_ClassID'], 1, $row['CD_ID']);
				$spanurl=substr($spanurl, strlen(cd_webpath));
				spandir($spanurl);
				fwrite(fopen('../../' . $spanurl, 'wb'), $Mark_Text);
				echo '&nbsp;<font style=font-size:10pt;>生成歌手：<font color=red>' . $row['CD_Name'] . '</font>&nbsp;成功&nbsp;&nbsp;<a href=' . cd_webpath . $spanurl . ' target=_blank>' . cd_webpath . $spanurl . '</a></font><br/>';
			}
			if($Arr[5]<$Arr[6]) {
		echo "<script language=\"javascript\" type=\"text/javascript\"> \n";
		echo "var i = " . cd_stoptime . "; \n";
		echo "var intervalid; \n";
		echo "intervalid = setInterval(\"fun()\", 1000); \n";
		echo "function fun() { \n";
		echo "if (i == 0) { \n";
		echo "window.location.href = \"?sel=" . $Sel . '&sdayv=' . $sday . '&pages=' . ($Arr[5]+1) . "\"; \n";
		echo "clearInterval(intervalid); \n";
		echo "} \n";
		echo "document.getElementById(\"mes\").innerHTML = i; \n";
		echo "i--; \n";
		echo "} \n";
		echo "</script> \n";
		echo '<br/>&nbsp;<font style=font-size:10pt;><b><font color=red>为了节约系统资源，将暂停 <span id="mes">' . cd_stoptime . '</span> 秒后继续生成，请不要关闭或刷新...</b></font>';
			} else {
				echo "<br/>&nbsp;<font style=font-size:10pt;><b>恭喜您，" . $cd_title . "已全部生成完毕！<script language='javascript'>parent.form1.document.getElementById('StopTime').innerHTML='恭喜您，" . $cd_title . "已全部生成完毕！';</script></b></font><script language='javascript'>alert('恭喜您，" . $cd_title . "已全部生成完毕！');</script>";
			}
		}
	} else {
		die('出错了，模板文件不存在！');
	}
	die();
}
$ClassID=SafeRequest('ClassIDs', 'post');
if($ClassID=='') {
	$ClassID=SafeRequest('ClassIDs', 'get');
}
if(!IsNum($ClassID)) {
	die('参数错误!');
}
if($ClassID=='0') {
	if(file_exists(_cctvai_root_ . cd_templateurl . 'singer.html')) {
		$sql='select * from ' . tname('singer') . ' where CD_Passed=0 and CD_ClassID<>0';
		$Arr=spanhtmlpage($sql, cd_createpre);
		echo ("<div style='width:100%; background: #FAFBF7; border-top:1px solid #ddd; border-bottom:1px solid #dddC;color:#668E1B; font-size:10pt; height:30px; line-height:30px;font-weight:bold; margin:0 auto;'>&nbsp;正在开始生成第<font style='color:red; font-size:16px; font-style:italic'>" . $Arr[5] . "</font>页数据，共<font style='color:red; font-size:16px; font-style:italic'>" . $Arr[6] . '</font>页</div><br/>');
		$result=$db->query($Arr[2]);
		if($result) {
			while($row=$db->fetch_array($result)) {
				$Mark_Text=SpansingerPlay($row['CD_ID']);
				$spanurl=LinkUrl('singer', $row['CD_ClassID'], 1, $row['CD_ID']);
				$spanurl=substr($spanurl, strlen(cd_webpath));
				spandir($spanurl);
				fwrite(fopen('../../' . $spanurl, 'wb'), $Mark_Text);
				echo '&nbsp;<font style=font-size:10pt;>生成歌手：<font color=red>' . $row['CD_Name'] . '</font>&nbsp;成功&nbsp;&nbsp;<a href=' . cd_webpath . $spanurl . ' target=_blank>' . cd_webpath . $spanurl . '</a></font><br/>';
			}
			if($Arr[5]<$Arr[6]) {
		echo "<script language=\"javascript\" type=\"text/javascript\"> \n";
		echo "var i = " . cd_stoptime . "; \n";
		echo "var intervalid; \n";
		echo "intervalid = setInterval(\"fun()\", 1000); \n";
		echo "function fun() { \n";
		echo "if (i == 0) { \n";
		echo "window.location.href = \"?ClassIDs=0&pages=" . ($Arr[5]+1) . "\"; \n";
		echo "clearInterval(intervalid); \n";
		echo "} \n";
		echo "document.getElementById(\"mes\").innerHTML = i; \n";
		echo "i--; \n";
		echo "} \n";
		echo "</script> \n";
		echo '<br/>&nbsp;<font style=font-size:10pt;><b><font color=red>为了节约系统资源，将暂停 <span id="mes">' . cd_stoptime . '</span> 秒后继续生成，请不要关闭或刷新...</b></font>';
			} else {
				echo "<br/>&nbsp;<font style=font-size:10pt;><b>恭喜您，全部歌手页生成完毕！<script language='javascript'>parent.form1.document.getElementById('StopTime').innerHTML='恭喜您，全部歌手页生成完毕！';</script></b></font><script language='javascript'>alert('恭喜您，全部歌手页生成完毕！');</script>";
			}
		}
	} else {
		die('出错了，模板文件不存在！');
	}
} else {
	if(file_exists(_cctvai_root_ . cd_templateurl . 'singer.html')) {
		$sqlstr='select CD_Name from ' . tname('singerclass') . ' where CD_ID=' . $ClassID . '';
		$res=$db->getrow($sqlstr);
		$sql='select * from ' . tname('singer') . ' where CD_Passed=0 and CD_ClassID=' . $ClassID . '';
		$Arr=spanhtmlpage($sql, cd_createpre);
		echo ("<div style='width:100%; background: #FAFBF7; border-top:1px solid #ddd; border-bottom:1px solid #ddd;color:#668E1B; font-size:10pt; height:30px; line-height:30px;font-weight:bold; margin:0 auto;'>&nbsp;正在开始生成<font style='color:red; font-size:14px;'>" . $res['CD_Name'] . "</font>栏目的第<font style='color:red; font-size:16px; font-style:italic'>" . $Arr[5] . "</font>页数据，共<font style='color:red; font-size:16px; font-style:italic'>" . $Arr[6] . '</font>页</div><br/>');
		$result=$db->query($Arr[2]);
		if($result) {
			while($row=$db->fetch_array($result)) {
				$Mark_Text=SpansingerPlay($row['CD_ID']);
				$spanurl=LinkUrl('singer', $row['CD_ClassID'], 1, $row['CD_ID']);
				$spanurl=substr($spanurl, strlen(cd_webpath));
				spandir($spanurl);
				fwrite(fopen('../../' . $spanurl, 'wb'), $Mark_Text);
				echo '&nbsp;<font style=font-size:10pt;>生成歌手：<font color=red>' . $row['CD_Name'] . '</font>&nbsp;成功&nbsp;&nbsp;<a href=' . cd_webpath . $spanurl . ' target=_blank>' . cd_webpath . $spanurl . '</a></font><br/>';
			}
			if($Arr[5]<$Arr[6]) {
		echo "<script language=\"javascript\" type=\"text/javascript\"> \n";
		echo "var i = " . cd_stoptime . "; \n";
		echo "var intervalid; \n";
		echo "intervalid = setInterval(\"fun()\", 1000); \n";
		echo "function fun() { \n";
		echo "if (i == 0) { \n";
		echo "window.location.href = \"?ClassIDs=" . $ClassID . '&pages=' . ($Arr[5]+1) . "\"; \n";
		echo "clearInterval(intervalid); \n";
		echo "} \n";
		echo "document.getElementById(\"mes\").innerHTML = i; \n";
		echo "i--; \n";
		echo "} \n";
		echo "</script> \n";
		echo '<br/>&nbsp;<font style=font-size:10pt;><b><font color=red>为了节约系统资源，将暂停 <span id="mes">' . cd_stoptime . '</span> 秒后继续生成，请不要关闭或刷新...</b></font>';
			} else {
				echo "<br/>&nbsp;<font style=font-size:10pt;><b>恭喜您，全部歌手页生成完毕！<script language='javascript'>parent.form1.document.getElementById('StopTime').innerHTML='恭喜您，全部歌手页生成完毕！';</script></b></font><script language='javascript'>alert('恭喜您，全部歌手页生成完毕！');</script>";
			}
		}
	} else {
		die('出错了，模板文件不存在！');
	}
}
?>