<?php

/*
'**************************************************************************************************
' 程序名称: CCTVAI开源音乐管理系统
' 官方网站: http://www.cctvai.com
' 联系 Q Q: 1542367792
' QQ交流群：136687984
' 版本：(终结版)
' 备注：未经书面授权，不得向任何第三方提供本软件系统！
' 功能，模板，插件，扩展，定制请联系QQ：1542367792
'**************************************************************************************************
*/
error_reporting(0);
include "../../include/cctvai.conn.php";
include "../function_common.php";
admincheck(7);
/*if(Smallfivesolution() == $_SERVER['SERVER_NAME']) {
} else {
    echo Smallfivesq();
    exit();
}*/
$action=SafeRequest("action", "get");
if($action=="add"){
	global $db;
	$CD_Name=SafeRequest("name", "get");
	$CD_Html=SafeRequest("html", "get");
	$CD_Path=SafeRequest("path", "get");
	$CD_TempPath='skin/'.$CD_Path.'/'.$CD_Html.'/';
	$sql="Insert " . tname('mold') . " (CD_Name,CD_tempPath,CD_TheOrder) values ('" . $CD_Name . "','" . $CD_TempPath . "',0)";
	//die($sql);
	//下面开始替换.asp成.php
	if(file_exists("../../" . $CD_TempPath)) {
		$TempArr=array(
			"index.html",
			"head.html",
			"bottom.html",
			"play.html",
			"list.html",
			"search.html"
		);
		for($i=0; $i<count($TempArr); $i++) {
			if(file_exists("../../" . $CD_TempPath . $TempArr[$i])) {
				$Content=file_get_contents("../../" . $CD_TempPath . $TempArr[$i]);
				$Content=ReplaceStr($Content, ".asp", ".php");
				fwrite(fopen("../../" . $CD_TempPath . $TempArr[$i], "wb"), $Content);
			}
		}
		unset($TempArr);
	} else {
		showmessage("出错了，模板文件夹不存在！", "skin_new.php", 1);
	}
	if($db->query($sql)) {
		fwrite(fopen("../../skin/".$CD_Path."/install.lock","wb"),"");
		showmessage("恭喜您，模板安装成功！", "skin.php", 0);
	} else {
		showmessage("出错了，模板安装失败！", "skin_new.php", 1);
	}
}
?>
<!DOCTYPE html>
<html>
 <head> 
  <meta charset="gbk" /> 
  <meta name="renderer" content="webkit" /> 
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> 
  <title>后台管理中心</title> 
  <link href="../css/add.css" rel="stylesheet" /> 
  <style type="text/css">
.table2{width: 100%;max-width: 100%;border-collapse: collapse;border-spacing: 0;}
.table2 td{font-size: 12px;border-top: 1px solid #ddd;padding: 8px;vertical-align: top;}
.table2 tr:hover{text-decoration: none;background-color: #e6f2fb;}
.table2 th{border-bottom: 2px solid #ddd;vertical-align: bottom;padding: 2px;text-align: left;}
.table3{width: 100%;max-width: 100%;border-collapse: collapse;border-spacing: 0;}
.table3 tr:hover{text-decoration: none;background-color: #e6f2fb;}
.table3 td{font-size: 12px;line-height:25px;border-top: 1px solid #ddd;padding: 5px;vertical-align: top;border-right: solid 1px #ddd;}
.table3 th{border-bottom: 2px solid #ddd;vertical-align: bottom;padding: 2px;text-align: left;}
</style> 
 </head> 
 <body> 
<!--新增模板-->
  <div class="contents"> 
   <div class="panel"> 
    <div class="panel-head">
     <strong>未安装模板</strong>
    </div> 
    <table class="table2" id="dellist"> 
     <tbody>
      <tr bgcolor="#FAFBF7">
       <td align="left">模板名称</td>
       <td align="left">开发者</td>
	   <td align="left">联系QQ</td>
	   <td align="left">更新时间</td>
	   <td width="100" align="left">操作</td>
      </tr>
<?php
$directory='../../skin/';
$files=array();
if(is_dir($directory)) {
	if($dh=opendir($directory)) {
		while(($file=readdir($dh))!==false) {
			if($file!='.' && $file!='..' && $file!='index.html') {
				if(!file_exists(_cctvai_root_.'skin/'.$file.'/install.lock')){
					include "../../skin/".$file."/config.php";
					echo'      <tr>
       <td align="left">'.$skin_name.'</td>
       <td align="left"><a href="http://www.cctvai.com/url.php/'.$skin_url.'" target="_blank">'.$skin_by.'</a></td>
	   <td align="left"><a href="http://wpa.qq.com/msgrd?v=3&uin='.$skin_qq.'&site=qq&menu=yes" target="_blank">'.$skin_qq.'</a></td>
	   <td align="left">'.$skin_time.'</td>
	   <td width="100" align="left"><a href="?action=add&name='.$skin_name.'&html='.$skin_html.'&path='.$file.'" class="btn">安装</a></td>
      </tr>';
				}
			}
		}
		closedir($dh);
	}
}
?>
     </tbody>
    </table> 
   </div> 
   </div> 	
 </body>
</html>