<?php
/*********************************************************      
 程序说明：         
    功能说明：树状显示数据库中可下载、上传的数据文件。
              
    调用关系：调用: header.inc    
              被调用:        
 
    变量说明：

    作者：      
      
修改注释：      
NO.1      
姓名：            
时间：      
修改说明：      
*********************************************************/
require("../../inc/header.inc");
$helpId = isset($helpId)?$helpId:'5.1.1';
$sel_name=$_REQUEST['sel_name'];
$data_type="strDATA$sel_name";
$ThisPage="$strMaintenance&nbsp;>&nbsp;$strBackupRestore&nbsp;>&nbsp;"."${$data_type}";
$DEBUG = 0;
$db=$omc_db;
?>
<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%\" 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();
?>
<br>&nbsp;
<table border="1" width="100%"  cellpadding="2" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF" >
<?php
echo"<tr  bgcolor=\"#E6E6E6\"><td valign=\"middle\" width=\"40%\">$strCSVDataFile</td>";
echo "<td width=\"20%\" align=\"center\"> $strLastDownloadTime </td>";
echo "<td width=\"10%\" align=\"center\"> $strDownload </td>";
echo "<td width=\"20%\" align=\"center\"> $strLastUploadTime </td>";
echo "<td width=\"10%\" align=\"center\"> $strUpload</td>";   
echo "</tr></table>";
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
echo "<tr ><td colspan=\"5\" ><img src=\"../../images/line.gif\"></td></tr>";

/************************从数据库取出菜单结构的数据，并按顺序导入到数组中**************************/  

//----------------------选择语言版本----------------------
if($selectedLanguage == 'eng'){
	$show_menu_name=menu_name_2; //语种2
}elseif($selectedLanguage == 'chn'){
	$show_menu_name=menu_name; //语种1
}

$level_num=4;
$menu_list = "level_0,level_1,level_2,level_3";
if ($DEBUG) echo "<br>sel_name=$sel_name<br>";
if ($sel_name == "network"){
	$sel_db_name = "'%OBJ%'";
	$where = "WHERE db_name LIKE $sel_db_name AND table_name LIKE 'param\_%' AND if_enable=1 ";
}elseif($sel_name == "account"){
	$sel_db_name = "('HLR_DB','VLR_DB','PPS_DB','AUC_DB','EIR_DB','VMS_DB','MNP_DB','OPR_DB','iPALIM_DB')";
	$exclude_db_name = "('CSTA_DB')";
	$table_name = "('daily_report')";
	$where = "WHERE db_name IN $sel_db_name AND table_name NOT IN $table_name AND if_enable=1 ";
}elseif ($sel_name == "performance"){
	//$sel_db_name = "('CSTA_DB')";
	$exclude_db_name = "''";
	$table_name = "('daily_report','sysOperLog','sysAlarmLog')";
	//$where = "WHERE db_name IN $sel_db_name OR table_name IN $table_name";
	$where = "WHERE table_name IN $table_name AND if_enable=1 ";
}elseif ($sel_name == "define"){
	$sel_db_name = "'%OBJ%'";
	$where = "WHERE (db_name LIKE $sel_db_name AND if_enable=1 AND(table_name LIKE 'paramC%' OR table_name LIKE 'subsParamConf%' OR table_name LIKE 'logAttrDef%')) OR (table_name LIKE 'sysInfo') OR (table_name LIKE 'sysMenuConf')";
}
else
	$where = "where(1)";
/*
elseif ($sel_name == "cdr"){
	$sel_db_name = "'%CDR%'";
	$where = "WHERE db_name LIKE $sel_db_name";
}
*/
//AND if_enable!='0'
$menu_sql = "SELECT * FROM $syscsvconf_table $where ORDER BY ".$menu_list;
//echo "<br>menu_sql=$menu_sql<br>";
$menu_result = @mysqli_query($pubConn,$menu_sql);
$menu_rows = @mysqli_fetch_array($menu_result);
echo mysqli_error($pubConn);
$n=0;
do{
	//从第i层开始划分层次，第i层之前不参与显示算法
	for($i=0; $i < $level_num; $i++){
		$menu_num = 'level_'.$i;
		$menu_arr[$n][$i]=$menu_rows[$menu_num];
	}
	$menu_arr[$n][show_name]    =$menu_rows[$show_menu_name];
	$menu_arr[$n][can_download] =$menu_rows[can_download];
	$menu_arr[$n][can_upload]   =$menu_rows[can_upload];
	$menu_arr[$n][last_download]=$menu_rows[last_download];
	$menu_arr[$n][last_upload]  =$menu_rows[last_upload];
	$menu_arr[$n][key_menu_id]  =$menu_rows[key_menu_id];
	$menu_arr[$n][db_name]		=$menu_rows[db_name];
	$menu_arr[$n][table_name]	=$menu_rows[table_name];
	//echo "<br>{$menu_arr[$n][show_name]}";
	//echo "$show_menu_name<br>";
	//echo "n = $n, db_name = $menu_arr[$n][6] , table name = $menu_rows[table_name]<br>";
	if((($menu_arr[$n][table_name]=='sysOperLog')||($menu_arr[$n][table_name]=='sysAlarmLog'))&&($menu_arr[$n][can_download]=='1')){
		$tmpMenuArr=explode('_',$menu_arr[$n][show_name]);
		$day=date("m-d",mktime(0,0,0,date("m"),date("d")-($tmpMenuArr[1]),date("Y")));
		$menu_arr[$n][show_name]=$tmpMenuArr[0].'_'.$day;
	}		
	$n++;
}while($menu_rows = mysqli_fetch_array($menu_result));
//exit();
/*************************************下面是顺序显示菜单程序***************************************/     

 for($i=0 ; $i < sizeof($menu_arr); $i++)  //从上到下 ---> 级
    {
   $show_name = $menu_arr[$i][show_name];
   $can_download =$menu_arr[$i][can_download];
   $can_upload   =$menu_arr[$i][can_upload];
   $key_menu_id=$menu_arr[$i][key_menu_id];
   $db_name	= $menu_arr[$i][db_name];
   $table_name	= $menu_arr[$i][table_name];
   $show_value = "key_menu_id=$key_menu_id"; 
       
   $show = "&nbsp;$show_name";
   $show_1 = "\n<img align=absBottom border=0 src=../../images/midminus.gif><img align=absBottom border=0 src=../../images/open.gif>$show";
   $show_2 = "\n<img align=absBottom border=0 src=../../images/midblk.gif><img align=absBottom border=0 src=../../images/csv_file.gif> $show";  
   $show_4 = "\n<img align=absBottom border=0 src=../../images/lastblk.gif><img align=absBottom border=0 src=../../images/csv_file.gif> $show";
   $show_3 = "\n<img align=absBottom border=0 src=../../images/line.gif>";
   $show_5 = "\n<img align=absBottom border=0 src=../../images/blank.gif>";
   //$bgcolor=$i%2?'#ffffff':'#f4f4f4';
   $bgcolor='';
   echo"<tr onMouseOver=\"this.bgColor='#FFFF44'\" onMouseOut=\"this.bgColor=''\" bgcolor=$bgcolor><td valign=\"middle\" width=\"40%\" >";
   echo "<nobr>";
   for($j=0;$j < $level_num;$j++)  //从左到右 ---> 层
    {   
        if($menu_arr[$i][$j] > 0) //如果该节点大于零
              {                       
           if($menu_arr[$i+1][$j] > $menu_arr[$i][$j] ) //如果下面有树枝或页子与本节点（树枝或叶子）相连，即下面有兄弟节点
   	     {
		      if($menu_arr[$i][$j+1] > 0) //如果是树枝
		          {
			     echo "$show_3";  //show_3
			  }
			else  //叶子
			  {
                                 echo "$show_2";  //show_2
			  }
             }
	  else //如果下面的节点号不大于本节点号
	     {
	        if($menu_arr[$i][$j+1] > 0) //如果本节点不是叶子
		   {  
		      $is_line =0;   //标志位，用于标志同一树枝下面是否还有分支，或是直接连在本枝上的叶子。
		      for($p=$i+1;$p < sizeof($menu_arr) && $menu_arr[$p][$j-1] == $menu_arr[$i][$j-1];$p++) //顺着上一层目录，向下查找
		         {
			     if($menu_arr[$p][$j] > $menu_arr[$i][$j])  //找到了！！！
			        { 
				    $is_line = 1;
				    break;
				}
			  } 
			  
			  if($is_line == 1)  //下面还有分支，或是直接连在本枝上的叶子
			       {
			          echo "$show_3";  //show_3
			       }
		            else    //同一树枝下没有分支，或是连在本枝上的叶子
		               {
			          echo "$show_5";  //show_5
			       }
			     
		   }
                     else //本节点是叶子
		   {
		       if($menu_arr[$i+1][$j+1] > 0 )  //本节点有分叉，即有起点在本节点的子树
		          {
			      echo "$show_1";  //show_1
		          }
                           else      //本节点是该树枝上最末一片页子
		          {
			      echo "$show_4";   //show_4
			  }
		   }
	     }  //end  else of if($menu_arr[$i+1][$j] > $menu_arr[$i][$j] ) 
	   }  //end if($menu_arr[$i][$j] > 0)
      }    //end for($j=0;$j < $level_num;$j++)
   echo "</nobr></td>";

   if($can_download > 0){
	echo "<td width=\"20%\" align=\"center\"> {$menu_arr[$i][last_download]}</td>";
	echo "<td width=\"10%\" align=\"center\"><a href=\"./load_out_csv.php?$show_value&sel_name=$sel_name\" TARGET=\"_blank\">$strDownload </a></td>";
   }else{
	echo "<td width=\"20%\" align=\"center\"> --- </td>";
	echo "<td width=\"10%\" align=\"center\"> --- </td>";
   }

   if($can_upload > 0){
		echo "<td width=\"20%\" align=\"center\"> {$menu_arr[$i][last_upload]}</td>";
	    //echo "db_name=$db_name,tabel_name=$table_name<br>";
		if (($db_name == 'HLR_DB')&&($table_name=='subscriberData')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=330&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'VLR_DB')&&($table_name=='subscriberData')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=325&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'PPS_DB')&&($table_name=='user_info')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=360&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'AUC_DB')&&($table_name=='AUC_Dyn_data')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=340&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'EIR_DB')&&($table_name=='BlackGrayIMEI')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=380&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'VMS_DB')&&($table_name=='subscriberData_0')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=390_0_0&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'VMS_DB')&&($table_name=='subscriberData_1')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=390_1_0&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'VMS_DB')&&($table_name=='subscriberData_2')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=390_2_0&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'VMS_DB')&&($table_name=='subscriberData_3')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=390_3_0&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'VMS_DB')&&($table_name=='subscriberData_4')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=390_4_0&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'VMS_DB')&&($table_name=='subscriberData_5')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=390_5_0&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'VMS_DB')&&($table_name=='subscriberData_6')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=390_6_0&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'VMS_DB')&&($table_name=='subscriberData_7')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=390_7_0&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'VMS_DB')&&($table_name=='subscriberData_8')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=390_8_0&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'VMS_DB')&&($table_name=='subscriberData_9')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=390_9_0&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'VMS_DB')&&($table_name=='subscriberData_10')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=390_10_0&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'VMS_DB')&&($table_name=='subscriberData_11')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=390_11_0&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'VMS_DB')&&($table_name=='subscriberData_12')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=390_12_0&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'VMS_DB')&&($table_name=='subscriberData_13')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=390_13_0&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'VMS_DB')&&($table_name=='subscriberData_14')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=390_14_0&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'VMS_DB')&&($table_name=='subscriberData_15')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=390_15_0&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif ($db_name == 'SN_DB'){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=253&dataTypeNo=0\"> $strUpload </a></td>";
		}
		elseif (($db_name == 'MNP_DB')&&($table_name=='subscriberData')){
			echo "<td width=\"10%\" align=\"center\"><a href=\"../../account/pubSubsImport/subscriberImportIndex.php?sysId=370&dataTypeNo=0\"> $strUpload </a></td>";
		}
		else{
			echo "<td width=\"20%\" align=\"center\"><a href=\"./load_in_csv.php?$show_value&sel_name=$sel_name\"> $strUpload </a></td>";
		}	
   }else{
	echo "<td width=\"20%\" align=\"center\"> --- </td>";
	echo "<td width=\"10%\" align=\"center\"> --- </td>";
   }
   echo "</tr>";
}   //end  for($i=0 ; $i < $n ; $i++)

?>
</table>
<?php
adjust_content_tail();
?>
</body>
</html>
