<?php
/*********************************************************      
 程序说明：         
    功能说明：分级显示该目录下的所有文件，用递归方法
              
    调用关系：调用: header.inc    
              被调用:        
 
    变量说明：

    作者：     
      
修改注释：      
NO.1      
Name: Lilong
Date: 2004-4-6
Description: 
	1. Change website format: only for download.
	2. Add alarm log download.
	3. Add add operation log download.
*********************************************************/
require("../../inc/header.inc");
$helpId = "4.6"; 
$ThisPage="$strLog&nbsp;>&nbsp;$strCdrDdownload";
$blank4 .="&nbsp;&nbsp;&nbsp;&nbsp;";

$db = 'OMC_PUB';
$elementTable='elementExistConf';

/**********    FUNCTION START::TREEOLD  *************/
function treeOld($directory,$blank,$sys_name) 
{ 	
	$DEBUG=0;
	global	$strDownload,$strDelete;
	$dateList=array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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;
			//echo "<tr><td colspan=\"4\">$blank<img border=\"0\" src=\"../../images/open.gif\">&nbsp;&nbsp;<b>$file</b></td></tr>\n"; 
			//tree("$directory/$file",$blank); 
		}elseif($file =="." || $file ==".."){
			continue;
		}else{
			if ($sys_name == 'MSC'){
				if (strstr($file,'SMSC')!=NULL) continue;
			}		
			if (strstr($file,$sys_name) == NULL) continue;
			if (strstr($file,"csv") == 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>";
			$fileList[$k] ="<tr><td width=\"50%\">$blank $type_image <a href=\"./output_file.php?directory=$directory&filename=$file\" >$file</a></td>";
			$k++;
			//if($k == sizeof($dateList)) break;
		}
		
	}//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;

	$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();
	}
	$k=0;
	while($file=$mydir->read()){ 
		if((is_dir("$directory/$file")) AND ($file!=".") AND ($file!="..")){
			continue;
		}elseif($file =="." || $file ==".."){
			continue;
		}else{
			if ($sys_name == 'MSC'){
				if (strstr($file,'SMSC')!=NULL) continue;
			}		
			if (strstr($file,$sys_name) == NULL) continue;
			if (strstr($file,"csv") == NULL) continue;
			$piecesArray1	= explode(".",$file);
			if($piecesArray1[1] != 'csv') continue;
			$piecesArray2	= explode("_",$piecesArray1[0]);
			$exsitFlag["$piecesArray2[3]"]["$piecesArray2[4]"]	= 1;
			if($DEBUG){
				echo "exsitFlag[$piecesArray2[3]][$piecesArray2[4]]=";
				echo $exsitFlag["$piecesArray2[3]"]["$piecesArray2[4]"];
				echo "<br>";
			}
			$k++;
		}
	}//end of while
	$mydir->close();

	/****	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']	= "cdrFrom".$sys_name."_".$strYear."_".$strMon."_".$strDay;

		echo "<TR><TD>";
		echo $blank4;
		echo $blank4;
		echo "<img border=\"0\" src=\"../../images/csv_file.gif\">";
		echo $strYD['$strDay'];
		$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"]	= "cdrFrom".$sys_name."_".$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>";
				echo "<a href=\"./output_file.php?directory=$directory&filename=$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     *************/

function listCDRFile($directory,$sys_name)
{
	$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();
	}
	
	while($file=$mydir->read())
	{
		$condition="cdrFrom{$sys_name}_";
		if(strstr($file,$condition))
		{
			echo "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			echo "<a href=\"./output_file.php?directory=$directory&filename=$file\" ><font size=1>$file&nbsp;</font></a>";
			echo "</td></tr>";
		}
	}
	$mydir->close();
}
?>

<body leftmargin="15" rightmargin="10" onload="javascript:adjust();" onresize="javascript:adjust();" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">

<?php 
adjust_head();
adjust_title_head();
echo "<TABLE id=\"table_up\" border=\"0\" width=\"100%\">";
echo "<TR>";
echo "<TD width=\"50%\">";
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='';

$GenerateCDRFileInterval=getPubVar("GenerateCDRFileInterval");
if ($thisOmcType == 10){
	$blank="<img border=\"0\" src=\"../../images/blank.gif\">";
	echo "<TR><TD colspan=\"4\">$blank<img border=\"0\" src=\"../../images/open.gif\">&nbsp;&nbsp;<b>SN CDR</b></TD></TR>\n"; 
	if($GenerateCDRFileInterval == 60)
		tree("../../../db_backup/cdr",$blank,"SN");	
	else
		listCDRFile("../../../db_backup/cdr","SN");
}
else{
/*	//display operation log
	$blank="<img border=\"0\" src=\"../../images/blank.gif\">";
	echo "<TR><TD colspan=\"4\">$blank<img border=\"0\" src=\"../../images/open.gif\">&nbsp;&nbsp;<b>Operation log</b></TD></TR>\n"; 
	treeOld("../../../db_backup/operLog",$blank,"operLog");
	
	//display alarm log
	$blank="<img border=\"0\" src=\"../../images/blank.gif\">";
	echo "<TR><TD colspan=\"4\">$blank<img border=\"0\" src=\"../../images/open.gif\">&nbsp;&nbsp;<b>Alarm log</b></TD></TR>\n"; 
	treeOld("../../../db_backup/alarmLog",$blank,"alarmLog");
*/
$tmpSql = " SELECT * FROM elementExistConf WHERE  elementName='MSC' 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>MSC CDR</b></TD></TR>\n"; 
	if($GenerateCDRFileInterval == 60)
		tree("../../../db_backup/cdr",$blank,"MSC");
	else
		listCDRFile("../../../db_backup/cdr","MSC");
}	

$tmpSql = " SELECT * FROM elementExistConf WHERE  elementName='PPS' 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>PPS CDR</b></TD></TR>\n"; 
	if($GenerateCDRFileInterval == 60)
		tree("../../../db_backup/cdr",$blank,"PPS");		
	else
		listCDRFile("../../../db_backup/cdr","PPS");
}
$tmpSql = " SELECT * FROM elementExistConf WHERE  elementName='SMSC' 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>SMSC CDR</b></TD></TR>\n"; 
	if($GenerateCDRFileInterval == 60)
		tree("../../../db_backup/cdr",$blank,"SMSC");
	else
		listCDRFile("../../../db_backup/cdr","SMSC");
	$blank="<img border=\"0\" src=\"../../images/blank.gif\">";
	echo "<TR><TD colspan=\"4\">$blank<img border=\"0\" src=\"../../images/open.gif\">&nbsp;&nbsp;<b>SMLOG</b></TD></TR>\n"; 
	if($GenerateCDRFileInterval == 60)
		tree("../../../db_backup/cdr",$blank,"SMLOG");
	else
		listCDRFile("../../../db_backup/cdr","SMLOG");
}
}
//just template user can see the follow files
$highest=sizeof($oper_type) - 1;
echo "</TABLE>";
adjust_content_tail();
/****************    TABLE END:: DISPLAY DETAILS    ************************/
?>
</body>
</html>
