<?php
/*********************************************************      
 程序说明：         
    功能说明：提供各模块CSTA分时下载。
              
    调用关系：调用: header.inc    
              被调用:        
 
    变量说明：

    作者：lilong    2004-8-27
      
修改注释：      
NO.1      
Name:Cui Ticun 
Date: 2004-9-6
Description: 
*********************************************************/
require("../../inc/header.inc");
?>
<body leftmargin="15" rightmargin="10" onload="javascript:adjust();" onresize="javascript:adjust();" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">

<?php
adjust_head();
$DEBUG = 0;
global $pubConn;

$pub_db	= "OMC_PUB";
$elementTable='elementExistConf';

$helpId = "4.9"; 
$ThisPage="$strLog&nbsp;>&nbsp;CSTA download";
$blank4 .="&nbsp;&nbsp;&nbsp;&nbsp;";

//select module name from sysInfo.
$selSql = "SELECT sysTypeName FROM sysConf WHERE needCSTA=1 OR needFlow=1 ORDER BY sysTypeNo";
$selRes = @mysqli_query($pubConn,$selSql);
$num = @mysqli_num_rows($selRes);
for($i=0; $i<$num; $i++){
	$rows = @mysqli_fetch_array($selRes);
	$name[$i] = $rows[sysTypeName];
	if($DEBUG){
		echo "name[$i] = {$name[$i]}";
		echo "<br>";
	}
}

/**********    FUNCTION START::TREEOLD  *************/
function treeOld($directory,$blank,$sys_name) 
{ 	
	$DEBUG=0;
	$mydir=@dir($directory);
	if(!$mydir){
		echo "<br><br><font size=\"3\" color=\"#FF0000\"><b>Error: can't open this directory:  \"$directory\" .It's not exist!</b></font>";
		exit();
	}
	$blank .="<img border=\"0\" src=\"../../images/blank.gif\">"; //用一个空白图片表示每层目录间的间隔
	$k=0;
	while($file=$mydir->read()){ 
		if((is_dir("$directory/$file")) AND ($file!=".") AND ($file!="..")){
			continue;
		}elseif($file =="." || $file ==".."){
			continue;
		}else{
			if (strstr($file,"Detail") == NULL) continue;
			if (strstr($file,$sys_name) == NULL) continue;
			if ($sys_name == "pps" && $file[0]=="o") continue;
			if (strstr($file,"csv") == NULL) continue;
			if (($sys_name=="msc")AND(strstr($file,"smsc") != NULL))
				continue;			
			if(substr("$directory/$file",-2) == 'gz'){
				$type_image="<img border=\"0\" src=\"../../images/zip_file.gif\">";
			}elseif(substr("$directory/$file",-3) == 'csv'){
				$type_image="<img border=\"0\" src=\"../../images/csv_file.gif\">";
			}else{
				$type_image="<img border=\"0\" src=\"../../images/unknown_file.gif\">";
			}

			//$fileList[$k] ="<tr><td width=\"50%\">$blank $type_image <a href=\"$directory/$file\" >$file</a></td>";
			//target=\"_blank\"
			$fileList[$k] ="<tr><td width=\"50%\">$blank $type_image <a href=\"./output_file.php?directory=$directory&filename=$file\" >$file</a></td>";
			$k++;
		}
		
	}//end of while

	$mydir->close();
	for($h=0;$h<sizeof($fileList);$h++){
		echo "{$fileList[$h]}";
	}
} //end the program 
/**********    FUNCTION END:: TREEOLD     *************/


/**********    FUNCTION START::TREE   *************/
function tree($directory,$blank,$sys_name){ 	
	$DEBUG=0;
	global $blank4;

	/****	START::define last 7 days hours timestamp    ******/
	for($i=0;$i<7;$i++){
		$strYear	= date("Y",mktime(0,0,0,date("m"),date("j")-$i,date("Y")));
		$strMon		= date("m",mktime(0,0,0,date("m"),date("j")-$i,date("Y")));
		$strDay		= date("d",mktime(0,0,0,date("m"),date("j")-$i,date("Y")));
		$strYD['$strDay']	= strtolower($sys_name)."Detail_".$strYear."_".$strMon."_".$strDay;
		$tbName[$i] = strtolower($sys_name)."Detail_".$strDay;

		/* 判断tbName[$i]是否有记录 */
		$res = mysql_list_tables("CSTA_DB");
		$num = mysqli_num_rows($res);
		/*echo 
		for($j=0; $j<$num; $j++){
			$nameExit[$j]	= mysql_tablename($res,$i);
			echo $nameExit[$j]."<br>";
		}*/

		echo "<TR><TD>";
		echo $blank4;
		echo $blank4;
		echo "<img border=\"0\" src=\"../../images/csv_file.gif\">";
		//echo $strYD['$strDay'];
		echo $tbName[$i];
		/*
		$tgzName = $directory."/".$strYD['$strDay'].".tgz";
		//echo $tgzName;
		if ( true == file_exists($tgzName) ) {
			echo "&nbsp;&nbsp;";
			echo "<a href=\"$tgzName\" ><font size=2>tgz</font></a>";
		}
		*/
		echo "</TD></TR>";
		
		echo "<TR><TD>";
		echo $blank4;
		echo $blank4;
		echo $blank4;
		for($j=0;$j<24;$j++){
			$strHour	= date("H",mktime($j,0,0,date("m"),date("j")-$i,date("Y")));
			$strYDH["$strDay"]["$strHour"]	= strtolower($sys_name)."Detail_".$strYear."_".$strMon."_".$strDay."_".$strHour;
			if($DEBUG){
				echo "strYDH[$strDay][$strHour]=";
				echo $strYDH["$strDay"]["$strHour"];
				echo "<br>";

				echo "exsitFlag[$strDay][$strHour]=";
				echo $exsitFlag["$strDay"]["$strHour"];
				echo "<br>";
			}
			if(1==$exsitFlag["$strDay"]["$strHour"]){
				$fileName	= $strYDH["$strDay"]["$strHour"].".csv";
				echo "<a href=\"$directory/$fileName\" ><font size=2>$j&nbsp;</font></a>";
			}else{
				echo "<font color=gray size=1>$j&nbsp;</font>";
			}
		}
		echo "</TD></TR>";
	}
	/****	END::define last 7 days hours timestamp    ******/
} 
/**********    FUNCTION END:: TREE     *************/

?>


<?php 
adjust_title_head();
echo "<TABLE id=\"table_up\" border=\"0\" width=\"100%\">";
echo "<TR>";
echo "<TD width=\"50%\" align=\"left\">";
echo "$ThisPage"; 
echo "</TD>";
echo "<TD width=\"50%\" align=\"right\" title=\"Help\">";
showHelp($helpId);
echo "</TD>";
echo "</TR>";
echo "</TABLE>";

adjust_title_tail();
adjust_content_head();

/****************    TABLE START:: DISPLAY DETAILS    ************************/
echo "<TABLE width=\"100%\">";
echo "<BR>";
$blank='';

for($i=0; $i<$num; $i++){
	$tmpSql = " SELECT * FROM elementExistConf WHERE  elementName='$name[$i]' AND existFlag='1'";
	if($DEBUG)	
	echo "<br>tmpSql=$tmpSql";
	$tmpRes = mysqli_query($pubConn,$tmpSql);
	if(mysqli_num_rows($tmpRes)>0){
		$blank="<img border=\"0\" src=\"../../images/blank.gif\">";
		echo "<TR><TD colspan=\"4\">$blank<img border=\"0\" src=\"../../images/open.gif\">&nbsp;&nbsp;<b>$name[$i] CSTA</b></TD></TR>\n"; 
		treeold("../../../db_backup/csta",$blank,strtolower($name[$i]));
	}
}

//just template user can see the follow files
$highest=sizeof($oper_type) - 1;
echo "</TABLE>";
adjust_content_tail();
/****************    TABLE END:: DISPLAY DETAILS    ************************/
?>
</body>
</html>
